Skip to content

Commit 7af2dba

Browse files
adamnschFlorentinD
andcommitted
Start adding hover effects
Co-Authored-By: Florentin Dörre <florentin.dorre@neotechnology.com>
1 parent d0dae64 commit 7af2dba

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

js-applet/src/index.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FreeLayoutType, NVL } from '@neo4j-nvl/base'
22
import type { Node, NvlOptions, Relationship } from '@neo4j-nvl/base'
3-
import { DragNodeInteraction, PanInteraction, ZoomInteraction } from '@neo4j-nvl/interaction-handlers'
3+
import { DragNodeInteraction, PanInteraction, ZoomInteraction, HoverInteraction } from '@neo4j-nvl/interaction-handlers'
44

55
class PyNVL {
66
nvl: NVL
@@ -13,6 +13,7 @@ class PyNVL {
1313

1414
constructor(
1515
frame: HTMLElement,
16+
tooltip: HTMLElement,
1617
nvlNodes: Node[] = [],
1718
nvlRels: Relationship[] = [],
1819
options: NvlOptions = {},
@@ -24,6 +25,28 @@ class PyNVL {
2425
this.panInteraction = new PanInteraction(this.nvl)
2526
this.dragNodeInteraction = new DragNodeInteraction(this.nvl)
2627

28+
const hoverInteraction = new HoverInteraction(this.nvl)
29+
30+
hoverInteraction.updateCallback('onHover', (element, hitElements, event) => {
31+
if (element === undefined) {
32+
tooltip.setHTMLUnsafe("")
33+
if (tooltip.style.display === "block") {
34+
tooltip.style.display = "none";
35+
}
36+
} else if ("from" in element) {
37+
const rel = element as Relationship
38+
if (tooltip.style.display === "none") {
39+
tooltip.style.display = "block";
40+
}
41+
tooltip.setHTMLUnsafe("<b>Source ID:</b> " + rel.from + "</br><b>Target ID:</b> " + rel.to)
42+
} else if ("id" in element) {
43+
if (tooltip.style.display === "none") {
44+
tooltip.style.display = "block";
45+
}
46+
tooltip.setHTMLUnsafe("<b>ID:</b> " + element.id)
47+
}
48+
})
49+
2750
if (options.layout === FreeLayoutType) {
2851
this.nvl.setNodePositions(nvlNodes, false)
2952
}

python-wrapper/src/neo4j_viz/nvl.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ def render(
5151
js_code = f"""
5252
var myNvl = new NVLBase.NVL(
5353
document.getElementById('{container_id}'),
54+
document.getElementById('tooltip'),
5455
{nodes_json},
5556
{rels_json},
56-
{render_options_json}
57+
{render_options_json},
5758
);
5859
"""
5960
full_code = self.library_code + js_code
6061
html_output = f"""
61-
<div id="{container_id}" style="width: {width}; height: {height};"></div>
62+
<div id="{container_id}" style="width: {width}; height: {height}; position: relative;">
63+
<div id="tooltip" style="width: 20%; max-height: 90%; position: absolute; z-index: 2147483647; right: 0; bottom: 0; background: white; display: none; border: solid; border-color: #BBBEC3; border-width: 0.5px; padding: 0.6rem; border-radius: 8px; margin-bottom: 1rem; margin-right: 0.5rem; filter: drop-shadow(0 4px 8px rgba(26,27,29,0.12)); font: PublicSans; font-color: #4D5157; font-size: 14px"></div>
64+
</div>
6265
<script>
6366
{full_code}
6467
</script>

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)