Skip to content

Commit c264670

Browse files
authored
Merge pull request #144 from neo4j/properties-hover
Add properties to element on hover effect
2 parents 77e0704 + 3b13c1b commit c264670

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

docs/source/rendering.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ It defaults to 10.000, because rendering a large number of nodes can be slow and
4545
However, you can increase this value if you are confident that your environment can handle the scale.
4646
In this case you might also want to pass ``Renderer.WEB_GL`` as the ``renderer`` to improve performance.
4747

48-
By default a tooltip will be shown when hovering over a node or relationship.
48+
By default a tooltip showing IDs and properties will be shown when mouse hovering over a node or relationship.
4949
But you can disable this by passing ``show_hover_tooltip=False``.
5050

5151

js-applet/src/index.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import { FreeLayoutType, NVL } from '@neo4j-nvl/base'
22
import type { Node, NvlOptions, Relationship } from '@neo4j-nvl/base'
33
import { DragNodeInteraction, PanInteraction, ZoomInteraction, HoverInteraction } from '@neo4j-nvl/interaction-handlers'
44

5+
interface PyNode extends Node {
6+
properties: Object;
7+
}
8+
9+
interface PyRel extends Relationship {
10+
properties: Object;
11+
}
12+
513
class PyNVL {
614
nvl: NVL
715

@@ -30,23 +38,34 @@ class PyNVL {
3038
if (tooltip !== null) {
3139
this.hoverInteraction = new HoverInteraction(this.nvl)
3240

33-
this.hoverInteraction.updateCallback('onHover', (element) => {
41+
this.hoverInteraction.updateCallback('onHover', (element: PyNode | PyRel) => {
3442
if (element === undefined) {
3543
tooltip.textContent = "";
3644
if (tooltip.style.display === "block") {
3745
tooltip.style.display = "none";
3846
}
3947
} else if ("from" in element) {
40-
const rel = element as Relationship
48+
const rel = element as PyRel
49+
50+
let hoverInfo: string = (`<b>Source ID:</b> ${rel.from} </br><b>Target ID:</b> ${rel.to}`)
51+
for (const [key, value] of Object.entries(element.properties)) {
52+
hoverInfo += `</br><b>${key}:</b> ${value}`
53+
}
54+
tooltip.setHTMLUnsafe(hoverInfo)
55+
4156
if (tooltip.style.display === "none") {
4257
tooltip.style.display = "block";
4358
}
44-
tooltip.setHTMLUnsafe(`<b>Source ID:</b> ${rel.from} </br><b>Target ID:</b> ${rel.to}`)
4559
} else if ("id" in element) {
60+
let hoverInfo: string = `<b>ID:</b> ${element.id}`
61+
for (const [key, value] of Object.entries(element.properties)) {
62+
hoverInfo += `</br><b>${key}:</b> ${value}`
63+
}
64+
tooltip.setHTMLUnsafe(hoverInfo)
65+
4666
if (tooltip.style.display === "none") {
4767
tooltip.style.display = "block";
4868
}
49-
tooltip.setHTMLUnsafe(`<b>ID:</b> ${element.id}`)
5069
}
5170
})
5271
}

python-wrapper/src/neo4j_viz/resources/nvl_entrypoint/base.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)