Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backmerge: #2548 – If name of Superatom matches abbreviation in Custom Templates, then tooltip is shown on hover (#2563) #2565

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
import { FunctionalGroup } from 'ketcher-core'
import { Bond, Struct } from 'ketcher-core'

let showTooltipTimer: ReturnType<typeof setTimeout> | null = null

export const TOOLTIP_DELAY = 300

function makeStruct(editor, sGroup) {
const existingStruct = editor.struct()
const struct = new Struct()
const atomsIdMapping = new Map()

sGroup.atoms.forEach((atomId) => {
const atomIdInTooltip = struct.atoms.add(existingStruct.atoms.get(atomId))
atomsIdMapping.set(atomId, atomIdInTooltip)
})
Array.from(existingStruct.bonds).forEach((value) => {
const [_, bond] = value as [number, Bond]
const clonedBond = bond.clone(atomsIdMapping)
const isInsideSGroup =
sGroup.atoms.includes(bond.begin) || sGroup.atoms.includes(bond.end)
if (isInsideSGroup) {
struct.bonds.add(clonedBond)
}
})

return struct
}

export function showTooltip(editor, infoPanelData) {
editor.event.showInfo.dispatch(null)

Expand All @@ -28,7 +50,8 @@ export function showFunctionalGroupsTooltip(editor) {
const sGroup = editor.struct()?.sgroups.get(closestCollapsibleStructures.id)
if (sGroup && !sGroup.data.expanded && sGroup.hovering) {
const groupName = sGroup.data.name
const groupStruct = FunctionalGroup.getFunctionalGroupByName(groupName)
const groupStruct = makeStruct(editor, sGroup)
groupStruct.name = groupName
infoPanelData = {
groupStruct,
event,
Expand Down
8 changes: 5 additions & 3 deletions packages/ketcher-react/src/script/ui/utils/renderStruct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export class RenderStruct {
options: any = {}
) {
if (el && struct) {
const { cachePrefix = '' } = options
const { cachePrefix = '', needCache = true } = options
const cacheKey = `${cachePrefix}${struct.name}`
if (renderCache.has(cacheKey)) {
if (renderCache.has(cacheKey) && needCache) {
el.innerHTML = renderCache.get(cacheKey)
return
}
Expand All @@ -43,7 +43,9 @@ export class RenderStruct {
})
rnd.setMolecule(preparedStruct)
rnd.update(true, options.viewSz)
renderCache.set(cacheKey, rnd.clientArea.innerHTML)
if (needCache) {
renderCache.set(cacheKey, rnd.clientArea.innerHTML)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const InfoPanel: FC<InfoPanelProps> = (props) => {
autoScaleMargin: 0,
rescaleAmount: 1,
cachePrefix: 'infoPanel',
needCache: false,
viewSz: new Vec2(width, height),
width: width,
height: height
Expand Down