Skip to content

Tooltips ​

The tooltip menu options configure default and custom tooltips for nodes and edges.

By default:

  • Tooltips are enabled.
  • Node and edge titles/subtitles come from their respective header maps.
  • Properties come from the node/edge property maps.

Disabling tooltips ​

Pretty straightforward by setting the enabled property to false.

ts
const options = {
    UI: {
        tooltip: { 
            enabled: false
        }
    }
}

Choosing what shows a tooltip ​

enabled also takes a map of kinds or a function, for a graph that wants tooltips on some hovers only. The kinds are nodes, edges and groups, the groups Simplify draws. A missing key is true, so { edges: false } keeps nodes and groups.

A graph whose nodes already grow into a detailed card on hover has no use for a node tooltip, but a group only explains itself in its tooltip before it is opened:

ts
const options = {
    UI: {
        tooltip: { 
            enabled: { nodes: false, edges: false, groups: true }
        }
    }
}

A function is asked on every hover, with the element and its kind ('node', 'edge' or 'group'). A function that throws counts as false, and the error is logged once per element.

ts
const options = {
    UI: {
        tooltip: { 
            enabled: (element, kind) => kind === 'node' && element.getData().important === true
        }
    }
}

The tooltip itself is left out only when enabled is false, or a map with every kind off.

Header mapping ​

Similar to the mapping done in the sidebar's main header, you can provide mapping for the tooltip's header for both nodes and edges.

ts
const options = {
    UI: {
        tooltip: {  
            nodeHeaderMap: {
                title: node => `Node ${node.id}`,
                subtitle: node => node.data.description ?? ''
            },
            edgeHeaderMap: {
                title: edge => `Edge ${edge.from} → ${edge.to}`,
                subtitle: edge => edge.data.label ?? ''
            }
        }
    }
}

Extra content ​

Similar to the sidebar's extra content, you can define additional content to be appened at the end of the tooltip.

ts
const options = {
    UI: {
        tooltip: { 
            renderNodeExtra: (node) => {
                const div = document.createElement('div')
                div.textContent = `Type: ${node.data.type ?? 'Unknown'}`
                return div
            },
            renderEdgeExtra: (edge) => `Weight: ${edge.data.weight ?? '0'}`
        }
    }
}

Custom rendering ​

Finally, you can completly override a tooltip's content using the render function.

ts
const options = {
    UI: {
        tooltip: {
            render: (element) => {
                const div = document.createElement('div')
                div.textContent = `Element ID: ${element.id}`
                div.style.fontWeight = 'bold'
                return div
            }
        }
    }
}

Fetching tooltip content ​

render, renderNodeExtra, renderEdgeExtra, nodePropertiesMap and edgePropertiesMap may all be async. The tooltip shows a placeholder while the promise is pending, swaps the content in when it resolves, and repositions itself so the grown tooltip stays on screen.

ts
const options = {
    UI: {
        tooltip: {
            renderNodeExtra: async (node, { signal }) => { 
                const res = await fetch(`/enrich/${node.getData().uuid}`, { signal })
                return renderChips(await res.json())
            },
        },
    },
}

The tooltip is the surface where this matters most, because it is a single reused container opened behind a 400 ms delay: a fetch started for one node would otherwise land in a tooltip already describing another. It cannot here — hovering a second node aborts the first render's signal and drops its result, even if it resolves last. See asynchronous content for the full contract and for UI.asyncContent, which customises the placeholder.

Pinning a pending tooltip

Pinning while content is still loading is fine: the copy fills itself in when the fetch resolves, as long as it hasn't been superseded by another hover first.