@neo4j-ndl/react-graph 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/LICENSE +674 -0
  2. package/lib/LICENSES.txt +229 -0
  3. package/lib/NOTICE.txt +26 -0
  4. package/lib/cjs/graph-visualization-buttons.js +175 -0
  5. package/lib/cjs/graph-visualization-buttons.js.map +1 -0
  6. package/lib/cjs/graph-visualization-context.js +62 -0
  7. package/lib/cjs/graph-visualization-context.js.map +1 -0
  8. package/lib/cjs/graph-visualization-sidepanel.js +56 -0
  9. package/lib/cjs/graph-visualization-sidepanel.js.map +1 -0
  10. package/lib/cjs/graph-visualization.js +328 -0
  11. package/lib/cjs/graph-visualization.js.map +1 -0
  12. package/lib/cjs/index.js +28 -0
  13. package/lib/cjs/index.js.map +1 -0
  14. package/lib/cjs/map-to-nvl-graph.js +167 -0
  15. package/lib/cjs/map-to-nvl-graph.js.map +1 -0
  16. package/lib/cjs/sidepanel-components/button-group.js +96 -0
  17. package/lib/cjs/sidepanel-components/button-group.js.map +1 -0
  18. package/lib/cjs/sidepanel-components/clickable-urls.js +46 -0
  19. package/lib/cjs/sidepanel-components/clickable-urls.js.map +1 -0
  20. package/lib/cjs/sidepanel-components/details-panel.js +86 -0
  21. package/lib/cjs/sidepanel-components/details-panel.js.map +1 -0
  22. package/lib/cjs/sidepanel-components/overview-panel.js +45 -0
  23. package/lib/cjs/sidepanel-components/overview-panel.js.map +1 -0
  24. package/lib/cjs/sidepanel-components/properties-table.js +49 -0
  25. package/lib/cjs/sidepanel-components/properties-table.js.map +1 -0
  26. package/lib/cjs/sidepanel-components/show-all.js +44 -0
  27. package/lib/cjs/sidepanel-components/show-all.js.map +1 -0
  28. package/lib/cjs/sidepanel-components/single-selection-sidepanel-contents.js +35 -0
  29. package/lib/cjs/sidepanel-components/single-selection-sidepanel-contents.js.map +1 -0
  30. package/lib/cjs/stories/graph-visualization-barebones.story.js +93 -0
  31. package/lib/cjs/stories/graph-visualization-barebones.story.js.map +1 -0
  32. package/lib/cjs/stories/graph-visualization-custom.story.js +74 -0
  33. package/lib/cjs/stories/graph-visualization-custom.story.js.map +1 -0
  34. package/lib/cjs/stories/graph-visualization-default.story.js +93 -0
  35. package/lib/cjs/stories/graph-visualization-default.story.js.map +1 -0
  36. package/lib/cjs/stories/graph-visualization-highlighting.story.js +30 -0
  37. package/lib/cjs/stories/graph-visualization-highlighting.story.js.map +1 -0
  38. package/lib/cjs/stories/graph-visualization-maximalist.story.js +105 -0
  39. package/lib/cjs/stories/graph-visualization-maximalist.story.js.map +1 -0
  40. package/lib/cjs/stories/graph-visualization-search.story.js +36 -0
  41. package/lib/cjs/stories/graph-visualization-search.story.js.map +1 -0
  42. package/lib/cjs/stories/graph-visualization.stories.js +112 -0
  43. package/lib/cjs/stories/graph-visualization.stories.js.map +1 -0
  44. package/lib/cjs/stories/index.js +51 -0
  45. package/lib/cjs/stories/index.js.map +1 -0
  46. package/lib/cjs/stories/story-data.js +89 -0
  47. package/lib/cjs/stories/story-data.js.map +1 -0
  48. package/lib/cjs/use-managed-node-state.js +262 -0
  49. package/lib/cjs/use-managed-node-state.js.map +1 -0
  50. package/lib/cjs/use-semi-controlled-state.js +43 -0
  51. package/lib/cjs/use-semi-controlled-state.js.map +1 -0
  52. package/lib/cjs/utils.js +68 -0
  53. package/lib/cjs/utils.js.map +1 -0
  54. package/lib/esm/graph-visualization-buttons.js +159 -0
  55. package/lib/esm/graph-visualization-buttons.js.map +1 -0
  56. package/lib/esm/graph-visualization-context.js +58 -0
  57. package/lib/esm/graph-visualization-context.js.map +1 -0
  58. package/lib/esm/graph-visualization-sidepanel.js +52 -0
  59. package/lib/esm/graph-visualization-sidepanel.js.map +1 -0
  60. package/lib/esm/graph-visualization.js +298 -0
  61. package/lib/esm/graph-visualization.js.map +1 -0
  62. package/lib/esm/index.js +23 -0
  63. package/lib/esm/index.js.map +1 -0
  64. package/lib/esm/map-to-nvl-graph.js +162 -0
  65. package/lib/esm/map-to-nvl-graph.js.map +1 -0
  66. package/lib/esm/sidepanel-components/button-group.js +69 -0
  67. package/lib/esm/sidepanel-components/button-group.js.map +1 -0
  68. package/lib/esm/sidepanel-components/clickable-urls.js +40 -0
  69. package/lib/esm/sidepanel-components/clickable-urls.js.map +1 -0
  70. package/lib/esm/sidepanel-components/details-panel.js +82 -0
  71. package/lib/esm/sidepanel-components/details-panel.js.map +1 -0
  72. package/lib/esm/sidepanel-components/overview-panel.js +41 -0
  73. package/lib/esm/sidepanel-components/overview-panel.js.map +1 -0
  74. package/lib/esm/sidepanel-components/properties-table.js +45 -0
  75. package/lib/esm/sidepanel-components/properties-table.js.map +1 -0
  76. package/lib/esm/sidepanel-components/show-all.js +41 -0
  77. package/lib/esm/sidepanel-components/show-all.js.map +1 -0
  78. package/lib/esm/sidepanel-components/single-selection-sidepanel-contents.js +31 -0
  79. package/lib/esm/sidepanel-components/single-selection-sidepanel-contents.js.map +1 -0
  80. package/lib/esm/stories/graph-visualization-barebones.story.js +90 -0
  81. package/lib/esm/stories/graph-visualization-barebones.story.js.map +1 -0
  82. package/lib/esm/stories/graph-visualization-custom.story.js +71 -0
  83. package/lib/esm/stories/graph-visualization-custom.story.js.map +1 -0
  84. package/lib/esm/stories/graph-visualization-default.story.js +90 -0
  85. package/lib/esm/stories/graph-visualization-default.story.js.map +1 -0
  86. package/lib/esm/stories/graph-visualization-highlighting.story.js +28 -0
  87. package/lib/esm/stories/graph-visualization-highlighting.story.js.map +1 -0
  88. package/lib/esm/stories/graph-visualization-maximalist.story.js +102 -0
  89. package/lib/esm/stories/graph-visualization-maximalist.story.js.map +1 -0
  90. package/lib/esm/stories/graph-visualization-search.story.js +34 -0
  91. package/lib/esm/stories/graph-visualization-search.story.js.map +1 -0
  92. package/lib/esm/stories/graph-visualization.stories.js +109 -0
  93. package/lib/esm/stories/graph-visualization.stories.js.map +1 -0
  94. package/lib/esm/stories/index.js +39 -0
  95. package/lib/esm/stories/index.js.map +1 -0
  96. package/lib/esm/stories/story-data.js +86 -0
  97. package/lib/esm/stories/story-data.js.map +1 -0
  98. package/lib/esm/use-managed-node-state.js +259 -0
  99. package/lib/esm/use-managed-node-state.js.map +1 -0
  100. package/lib/esm/use-semi-controlled-state.js +40 -0
  101. package/lib/esm/use-semi-controlled-state.js.map +1 -0
  102. package/lib/esm/utils.js +60 -0
  103. package/lib/esm/utils.js.map +1 -0
  104. package/lib/types/graph-visualization-buttons.d.ts +56 -0
  105. package/lib/types/graph-visualization-context.d.ts +122 -0
  106. package/lib/types/graph-visualization-sidepanel.d.ts +32 -0
  107. package/lib/types/graph-visualization.d.ts +178 -0
  108. package/lib/types/index.d.ts +22 -0
  109. package/lib/types/map-to-nvl-graph.d.ts +37 -0
  110. package/lib/types/sidepanel-components/button-group.d.ts +24 -0
  111. package/lib/types/sidepanel-components/clickable-urls.d.ts +26 -0
  112. package/lib/types/sidepanel-components/details-panel.d.ts +25 -0
  113. package/lib/types/sidepanel-components/overview-panel.d.ts +21 -0
  114. package/lib/types/sidepanel-components/properties-table.d.ts +31 -0
  115. package/lib/types/sidepanel-components/show-all.d.ts +29 -0
  116. package/lib/types/sidepanel-components/single-selection-sidepanel-contents.d.ts +21 -0
  117. package/lib/types/stories/graph-visualization-barebones.story.d.ts +23 -0
  118. package/lib/types/stories/graph-visualization-custom.story.d.ts +23 -0
  119. package/lib/types/stories/graph-visualization-default.story.d.ts +23 -0
  120. package/lib/types/stories/graph-visualization-highlighting.story.d.ts +22 -0
  121. package/lib/types/stories/graph-visualization-maximalist.story.d.ts +23 -0
  122. package/lib/types/stories/graph-visualization-search.story.d.ts +22 -0
  123. package/lib/types/stories/graph-visualization.stories.d.ts +39 -0
  124. package/lib/types/stories/index.d.ts +32 -0
  125. package/lib/types/stories/story-data.d.ts +26 -0
  126. package/lib/types/use-managed-node-state.d.ts +116 -0
  127. package/lib/types/use-semi-controlled-state.d.ts +23 -0
  128. package/lib/types/utils.d.ts +29 -0
  129. package/package.json +79 -0
@@ -0,0 +1,58 @@
1
+ /**
2
+ *
3
+ * Copyright (c) "Neo4j"
4
+ * Neo4j Sweden AB [http://neo4j.com]
5
+ *
6
+ * This file is part of Neo4j.
7
+ *
8
+ * Neo4j is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+ import { createContext, useContext } from 'react';
22
+ export const GraphVisualizationContext = createContext(undefined);
23
+ /**
24
+ * Hook to access the graph visualization context.
25
+ *
26
+ * This hook is used to implement custom UI components like buttons, panels, and controls
27
+ * that need access to data and functionality from the graph visualization component.
28
+ * @see {@link GraphVisualizationContextData}
29
+ *
30
+ * @returns The graph visualization context containing NVL instance, sidepanel, gestures, and graph data
31
+ * @throws Error if used outside of a GraphVisualizationContext provider
32
+ *
33
+ * @example
34
+ * ```tsx
35
+ * const NodeLoggerButton = () => {
36
+ * const { selected } = useGraphVisualizationContext();
37
+ *
38
+ * const handleClick = () => {
39
+ * console.log('Selected nodes:', selected.nodeIds);
40
+ * };
41
+ *
42
+ * return (
43
+ * <button onClick={handleClick}>
44
+ * Log Selected Nodes ({selected.nodeIds.length})
45
+ * </button>
46
+ * );
47
+ * };
48
+ * ```
49
+ * @alpha
50
+ */
51
+ export const useGraphVisualizationContext = () => {
52
+ const context = useContext(GraphVisualizationContext);
53
+ if (!context) {
54
+ throw new Error('useGraphVisualizationContext must be used within a GraphVisualizationContext');
55
+ }
56
+ return context;
57
+ };
58
+ //# sourceMappingURL=graph-visualization-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-visualization-context.js","sourceRoot":"","sources":["../../src/graph-visualization-context.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAuElD,MAAM,CAAC,MAAM,yBAAyB,GAAG,aAAa,CAEpD,SAAS,CAAC,CAAC;AAEb;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,EAAE;IAC/C,MAAM,OAAO,GAAG,UAAU,CAAC,yBAAyB,CAAC,CAAC;IACtD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,8EAA8E,CAC/E,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ *
4
+ * Copyright (c) "Neo4j"
5
+ * Neo4j Sweden AB [http://neo4j.com]
6
+ *
7
+ * This file is part of Neo4j.
8
+ *
9
+ * Neo4j is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
+ */
22
+ import { Resizable } from 're-resizable';
23
+ export const GraphVisualizationSidepanel = ({ sidepanel, }) => {
24
+ const { children, isSidePanelOpen, sidePanelWidth, onSidePanelResize, minWidth = 230, } = sidepanel;
25
+ if (!isSidePanelOpen) {
26
+ return null;
27
+ }
28
+ return (_jsx(Resizable, { defaultSize: {
29
+ height: '100%',
30
+ width: sidePanelWidth !== null && sidePanelWidth !== void 0 ? sidePanelWidth : 400,
31
+ }, className: "ndl-graph-resizable", minWidth: minWidth, maxWidth: "66%", enable: {
32
+ bottom: false,
33
+ bottomLeft: false,
34
+ bottomRight: false,
35
+ left: true,
36
+ right: false,
37
+ top: false,
38
+ topLeft: false,
39
+ topRight: false,
40
+ }, handleClasses: { left: 'ndl-sidepanel-handle' }, onResizeStop: (_e, _dir, ref) => {
41
+ onSidePanelResize(ref.getBoundingClientRect().width);
42
+ }, children: _jsx("div", { className: "ndl-graph-visualization-sidepanel-content", children: children }) }));
43
+ };
44
+ const Title = ({ children }) => {
45
+ return (_jsx("div", { className: "ndl-graph-visualization-sidepanel-title ndl-grid-area-title", children: children }));
46
+ };
47
+ GraphVisualizationSidepanel.Title = Title;
48
+ const Content = ({ children }) => {
49
+ return _jsx("section", { className: "ndl-grid-area-content", children: children });
50
+ };
51
+ GraphVisualizationSidepanel.Content = Content;
52
+ //# sourceMappingURL=graph-visualization-sidepanel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-visualization-sidepanel.js","sourceRoot":"","sources":["../../src/graph-visualization-sidepanel.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,EAC1C,SAAS,GAGV,EAAE,EAAE;IACH,MAAM,EACJ,QAAQ,EACR,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,QAAQ,GAAG,GAAG,GACf,GAAG,SAAS,CAAC;IAEd,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,KAAC,SAAS,IACR,WAAW,EAAE;YACX,MAAM,EAAE,MAAM;YACd,KAAK,EAAE,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,GAAG;SAC7B,EACD,SAAS,EAAC,qBAAqB,EAC/B,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAC,KAAK,EACd,MAAM,EAAE;YACN,MAAM,EAAE,KAAK;YACb,UAAU,EAAE,KAAK;YACjB,WAAW,EAAE,KAAK;YAClB,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,KAAK;YACZ,GAAG,EAAE,KAAK;YACV,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,KAAK;SAChB,EACD,aAAa,EAAE,EAAE,IAAI,EAAE,sBAAsB,EAAE,EAC/C,YAAY,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;YAC9B,iBAAiB,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC,KAAK,CAAC,CAAC;QACvD,CAAC,YAED,cAAK,SAAS,EAAC,2CAA2C,YACvD,QAAQ,GACL,GACI,CACb,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG,CAAC,EAAE,QAAQ,EAAiC,EAAE,EAAE;IAC5D,OAAO,CACL,cAAK,SAAS,EAAC,6DAA6D,YACzE,QAAQ,GACL,CACP,CAAC;AACJ,CAAC,CAAC;AACF,2BAA2B,CAAC,KAAK,GAAG,KAAK,CAAC;AAE1C,MAAM,OAAO,GAAG,CAAC,EAAE,QAAQ,EAAiC,EAAE,EAAE;IAC9D,OAAO,kBAAS,SAAS,EAAC,uBAAuB,YAAE,QAAQ,GAAW,CAAC;AACzE,CAAC,CAAC;AACF,2BAA2B,CAAC,OAAO,GAAG,OAAO,CAAC"}
@@ -0,0 +1,298 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ /**
14
+ *
15
+ * Copyright (c) "Neo4j"
16
+ * Neo4j Sweden AB [http://neo4j.com]
17
+ *
18
+ * This file is part of Neo4j.
19
+ *
20
+ * Neo4j is free software: you can redistribute it and/or modify
21
+ * it under the terms of the GNU General Public License as published by
22
+ * the Free Software Foundation, either version 3 of the License, or
23
+ * (at your option) any later version.
24
+ *
25
+ * This program is distributed in the hope that it will be useful,
26
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
+ * GNU General Public License for more details.
29
+ *
30
+ * You should have received a copy of the GNU General Public License
31
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
32
+ */
33
+ import { tokens } from '@neo4j-ndl/base';
34
+ import { IconButtonArray, useNeedleTheme, } from '@neo4j-ndl/react';
35
+ import { InteractiveNvlWrapper, } from '@neo4j-nvl/react';
36
+ import { default as cx } from 'classnames';
37
+ import React, { useEffect, useId, useMemo, useState } from 'react';
38
+ import { BoxSelectButton, DownloadButton, LassoSelectButton, SearchButton, SingleSelectButton, ToggleSidePanelButton, ZoomInButton, ZoomOutButton, ZoomToFitButton, } from './graph-visualization-buttons';
39
+ import { GraphVisualizationContext, } from './graph-visualization-context';
40
+ import { GraphVisualizationSidepanel } from './graph-visualization-sidepanel';
41
+ import { mapToNvlGraph } from './map-to-nvl-graph';
42
+ import { SingleSelectionSidepanelContents } from './sidepanel-components/single-selection-sidepanel-contents';
43
+ import { useManagedNodeState } from './use-managed-node-state';
44
+ import { useSemicontrolledState } from './use-semi-controlled-state';
45
+ const PLACEMENTS = {
46
+ 'bottom-left': 'ndl-graph-visualization-interaction-island ndl-bottom-left',
47
+ 'bottom-right': 'ndl-graph-visualization-interaction-island ndl-bottom-right',
48
+ 'top-left': 'ndl-graph-visualization-interaction-island ndl-top-left',
49
+ 'top-right': 'ndl-graph-visualization-interaction-island ndl-top-right',
50
+ };
51
+ const InteractionIsland = ({ children, className, placement, }) => {
52
+ return _jsx("div", { className: cx(PLACEMENTS[placement], className), children: children });
53
+ };
54
+ export const DEFAULT_NVL_OPTIONS = {
55
+ disableTelemetry: true,
56
+ disableWebGL: true,
57
+ maxZoom: 3,
58
+ minZoom: 0.05,
59
+ relationshipThreshold: 0.55,
60
+ useWebGL: false,
61
+ };
62
+ const DEFAULT_COMPONENTS = {
63
+ bottomLeftIsland: null,
64
+ bottomRightIsland: (_jsxs(IconButtonArray, { orientation: "vertical", isFloating: true, children: [_jsx(ZoomInButton, {}), " ", _jsx(ZoomOutButton, {}), " ", _jsx(ZoomToFitButton, {})] })),
65
+ topLeftIsland: null,
66
+ topRightIsland: (_jsxs("div", { className: "ndl-graph-visualization-default-download-group", children: [_jsx(DownloadButton, {}), " ", _jsx(ToggleSidePanelButton, {})] })),
67
+ };
68
+ /**
69
+ * A comprehensive graph visualization component for rendering Neo4j-style graphs with interactive features.
70
+ *
71
+ * @remarks
72
+ * This component provides a complete graph visualization solution with built-in interaction modes,
73
+ * selection handling, zoom controls, and an optional sidepanel. It wraps the NVL (Neo4j Visualization Library)
74
+ * with additional UI controls and state management.
75
+ *
76
+ * The component supports various interaction modes including single selection, box selection, and lasso selection.
77
+ * It also provides customizable UI islands for placing controls at different corners of the visualization.
78
+ *
79
+ * @example
80
+ * Basic usage:
81
+ * ```tsx
82
+ * <GraphVisualization
83
+ * nodes={nodes}
84
+ * rels={relationships}
85
+ * selected={selection}
86
+ * setSelected={setSelection}
87
+ * />
88
+ * ```
89
+ *
90
+ * @example
91
+ * With custom controls:
92
+ * ```tsx
93
+ * <GraphVisualization
94
+ * nodes={nodes}
95
+ * rels={relationships}
96
+ * topRightIsland={<CustomControls />}
97
+ * sidepanel={{
98
+ * contents: <CustomSidepanel />,
99
+ * isSidePanelOpen: true,
100
+ * setIsSidePanelOpen: setSidepanelOpen
101
+ * sidePanelWidth: 400,
102
+ * onSidePanelResize: setSidepanelWidth,
103
+ * }}
104
+ * />
105
+ * ```
106
+ *
107
+ * @example
108
+ * With highlighting:
109
+ * ```tsx
110
+ * <GraphVisualization
111
+ * nodes={nodes}
112
+ * rels={relationships}
113
+ * // undefined = no highlighting (default behavior)
114
+ * // empty array = no search matches (dims all nodes)
115
+ * // array with IDs = highlight only those items
116
+ * highlightedNodeIds={searchResults.nodeIds}
117
+ * highlightedRelationshipIds={searchResults.relationshipIds}
118
+ * />
119
+ * ```
120
+ *
121
+ * @param props - {@link GraphVisualizationProps}
122
+ * @returns A React component that renders an interactive graph visualization
123
+ *
124
+ * @alpha
125
+ */
126
+ export function GraphVisualization(_a) {
127
+ var _b, _c;
128
+ var { nvlRef: rawNvlRef, nvlCallbacks, nvlOptions, sidepanel: rawSidepanel, nodes: rawNodes, rels: rawRels, highlightedNodeIds, highlightedRelationshipIds, topLeftIsland = DEFAULT_COMPONENTS.topLeftIsland, topRightIsland = DEFAULT_COMPONENTS.topRightIsland, bottomLeftIsland = DEFAULT_COMPONENTS.bottomLeftIsland, bottomRightIsland = DEFAULT_COMPONENTS.bottomRightIsland, gesture = 'single', setGesture, selected: rawSelected, setSelected: rawSetSelected, interactionMode: rawInteractionMode, setInteractionMode: rawSetInteractionMode, mouseEventCallbacks = {}, className, style, htmlAttributes, ref, as } = _a, restProps = __rest(_a, ["nvlRef", "nvlCallbacks", "nvlOptions", "sidepanel", "nodes", "rels", "highlightedNodeIds", "highlightedRelationshipIds", "topLeftIsland", "topRightIsland", "bottomLeftIsland", "bottomRightIsland", "gesture", "setGesture", "selected", "setSelected", "interactionMode", "setInteractionMode", "mouseEventCallbacks", "className", "style", "htmlAttributes", "ref", "as"]);
129
+ const nvlRef = useMemo(() => rawNvlRef !== null && rawNvlRef !== void 0 ? rawNvlRef : React.createRef(), [rawNvlRef]);
130
+ const instanceId = useId();
131
+ // Respect NDL theme changes
132
+ const { theme } = useNeedleTheme();
133
+ const { bg, border, text } = tokens.theme[theme].palette.neutral;
134
+ // key required for nvl react responsiveness
135
+ const [key, setKey] = useState(0);
136
+ useEffect(() => {
137
+ setKey((prevKey) => prevKey + 1);
138
+ }, [theme]);
139
+ // Semi-control interaction mode and selection state
140
+ const [interactionMode, setInteractionMode] = useSemicontrolledState(rawInteractionMode !== null && rawInteractionMode !== void 0 ? rawInteractionMode : 'select', rawSetInteractionMode);
141
+ const [selected, setSelected] = useSemicontrolledState(rawSelected !== null && rawSelected !== void 0 ? rawSelected : { nodeIds: [], relationshipIds: [] }, rawSetSelected);
142
+ const nvlGraph = useMemo(() => mapToNvlGraph(rawNodes, rawRels), [rawNodes, rawRels]);
143
+ const { nodesWithState, relsWithState, wrappedMouseEventCallbacks } = useManagedNodeState({
144
+ gesture,
145
+ highlightedNodeIds,
146
+ highlightedRelationshipIds,
147
+ interactionMode,
148
+ mouseEventCallbacks,
149
+ nvlGraph,
150
+ selected,
151
+ setInteractionMode,
152
+ setSelected,
153
+ });
154
+ const [isSidePanelOpen, setIsSidePanelOpen] = useSemicontrolledState((_b = rawSidepanel === null || rawSidepanel === void 0 ? void 0 : rawSidepanel.isSidePanelOpen) !== null && _b !== void 0 ? _b : true, rawSidepanel === null || rawSidepanel === void 0 ? void 0 : rawSidepanel.setIsSidePanelOpen);
155
+ const [sidePanelWidth, setSidePanelWidth] = useSemicontrolledState((_c = rawSidepanel === null || rawSidepanel === void 0 ? void 0 : rawSidepanel.sidePanelWidth) !== null && _c !== void 0 ? _c : 400, rawSidepanel === null || rawSidepanel === void 0 ? void 0 : rawSidepanel.onSidePanelResize);
156
+ const sidepanel = useMemo(() => {
157
+ if (rawSidepanel === undefined) {
158
+ return {
159
+ children: _jsx(GraphVisualization.SingleSelectionSidePanelContents, {}),
160
+ isSidePanelOpen,
161
+ onSidePanelResize: setSidePanelWidth,
162
+ setIsSidePanelOpen,
163
+ sidePanelWidth,
164
+ };
165
+ }
166
+ return rawSidepanel;
167
+ }, [
168
+ rawSidepanel,
169
+ isSidePanelOpen,
170
+ setIsSidePanelOpen,
171
+ sidePanelWidth,
172
+ setSidePanelWidth,
173
+ ]);
174
+ const Component = as !== null && as !== void 0 ? as : 'div';
175
+ return (_jsx(Component, Object.assign({ ref: ref, className: cx('ndl-graph-visualization-container', className), style: style }, htmlAttributes, { children: _jsxs(GraphVisualizationContext.Provider, { value: {
176
+ gesture,
177
+ interactionMode,
178
+ nvlGraph,
179
+ nvlInstance: nvlRef,
180
+ selected,
181
+ setGesture,
182
+ sidepanel,
183
+ }, children: [_jsxs("div", { className: "ndl-graph-visualization", children: [_jsx(InteractiveNvlWrapper, Object.assign({ layout: "d3Force", nodes: nodesWithState, rels: relsWithState, nvlOptions: Object.assign(Object.assign(Object.assign({}, DEFAULT_NVL_OPTIONS), { instanceId, styling: {
184
+ defaultRelationshipColor: border.strongest,
185
+ disabledItemColor: bg.strong,
186
+ disabledItemFontColor: text.weakest,
187
+ dropShadowColor: border.weak,
188
+ selectedInnerBorderColor: bg.default,
189
+ } }), nvlOptions), nvlCallbacks: Object.assign({ onLayoutComputing(isComputing) {
190
+ var _a;
191
+ if (!isComputing) {
192
+ (_a = nvlRef.current) === null || _a === void 0 ? void 0 : _a.fit(nvlRef.current.getNodes().map((neighbors) => neighbors.id), { noPan: true });
193
+ }
194
+ } }, nvlCallbacks), mouseEventCallbacks: wrappedMouseEventCallbacks, ref: nvlRef }, restProps), key), topLeftIsland !== null && (_jsx(InteractionIsland, { placement: "top-left", children: topLeftIsland })), topRightIsland !== null && (_jsx(InteractionIsland, { placement: "top-right", children: topRightIsland })), bottomLeftIsland !== null && (_jsx(InteractionIsland, { placement: "bottom-left", children: bottomLeftIsland })), bottomRightIsland !== null && (_jsx(InteractionIsland, { placement: "bottom-right", children: bottomRightIsland }))] }), sidepanel && _jsx(GraphVisualizationSidepanel, { sidepanel: sidepanel })] }) })));
195
+ }
196
+ /**
197
+ * Zoom in button for use within a GraphVisualization component.
198
+ *
199
+ * @remarks
200
+ * Increases zoom level by 1.3x
201
+ *
202
+ * @alpha
203
+ */
204
+ GraphVisualization.ZoomInButton = ZoomInButton;
205
+ /**
206
+ * Zoom out button for use within a GraphVisualization component.
207
+ *
208
+ * @remarks
209
+ * Decreases zoom level by 0.7x
210
+ *
211
+ * @alpha
212
+ */
213
+ GraphVisualization.ZoomOutButton = ZoomOutButton;
214
+ /**
215
+ * Zoom to fit button for use within a GraphVisualization component.
216
+ *
217
+ * @remarks
218
+ * Automatically adjusts zoom and pan to show all nodes and relationships
219
+ *
220
+ * @alpha
221
+ */
222
+ GraphVisualization.ZoomToFitButton = ZoomToFitButton;
223
+ /**
224
+ * Sidepanel toggle button for use within a GraphVisualization component.
225
+ *
226
+ * @remarks
227
+ * Shows or hides the sidepanel containing node and relationship details.
228
+ * Requires a sidepanel to be configured in the GraphVisualization component.
229
+ *
230
+ * @throws Error when used without a configured sidepanel
231
+ *
232
+ * @alpha
233
+ */
234
+ GraphVisualization.ToggleSidePanelButton = ToggleSidePanelButton;
235
+ /**
236
+ * Download button for use within a GraphVisualization component.
237
+ *
238
+ * @remarks
239
+ * Opens a dropdown menu with download options. Currently supports PNG format.
240
+ * Captures the current visualization state including zoom level.
241
+ *
242
+ * @alpha
243
+ */
244
+ GraphVisualization.DownloadButton = DownloadButton;
245
+ /**
246
+ * Box selection button for use within a GraphVisualization component.
247
+ *
248
+ * @remarks
249
+ * Enables box selection mode where dragging creates a rectangular selection area.
250
+ * Disabled unless the `setGesture` callback is passed.
251
+ * Shows active state when enabled and supports keyboard shortcut 'B'.
252
+ *
253
+ * @alpha
254
+ */
255
+ GraphVisualization.BoxSelectButton = BoxSelectButton;
256
+ /**
257
+ * Lasso selection button for use within a GraphVisualization component.
258
+ *
259
+ * @remarks
260
+ * Enables lasso selection mode where dragging creates a free-form selection area.
261
+ * Disabled unless the `setGesture` callback is passed.
262
+ * Shows active state when enabled and supports keyboard shortcut 'L'.
263
+ *
264
+ * @alpha
265
+ */
266
+ GraphVisualization.LassoSelectButton = LassoSelectButton;
267
+ /**
268
+ * Single node selection button for use within a GraphVisualization component.
269
+ *
270
+ * @remarks
271
+ * Enables single selection mode where clicking selects individual nodes or relationships.
272
+ * Shows active state when enabled and supports keyboard shortcut 'S'.
273
+ *
274
+ * @alpha
275
+ */
276
+ GraphVisualization.SingleSelectButton = SingleSelectButton;
277
+ /**
278
+ * Search button for use within a GraphVisualization component.
279
+ *
280
+ * @remarks
281
+ * Enables search mode where clicking opens a search input for filtering nodes and relationships.
282
+ *
283
+ * @alpha
284
+ */
285
+ GraphVisualization.SearchButton = SearchButton;
286
+ /**
287
+ * Single node selection side panel for use within a GraphVisualization component.
288
+ *
289
+ * @remarks
290
+ * Displays detailed information about the selected node or relationship.
291
+ * Panel is automatically opened when a node or relationship is selected.
292
+ * Also when user click on the show panel button in the top right corner.
293
+ *
294
+ * @alpha
295
+ */
296
+ GraphVisualization.SingleSelectionSidePanelContents =
297
+ SingleSelectionSidepanelContents;
298
+ //# sourceMappingURL=graph-visualization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-visualization.js","sourceRoot":"","sources":["../../src/graph-visualization.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EACL,eAAe,EAEf,cAAc,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,qBAAqB,GAEtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEnE,OAAO,EACL,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,eAAe,GAChB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAGL,yBAAyB,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AAC;AAEzD;;;;;;;;GAQG;AACH,kBAAkB,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;AAE3D;;;;;;;GAOG;AACH,kBAAkB,CAAC,YAAY,GAAG,YAAY,CAAC;AAE/C;;;;;;;;;GASG;AACH,kBAAkB,CAAC,gCAAgC;IACjD,gCAAgC,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ *
3
+ * Copyright (c) "Neo4j"
4
+ * Neo4j Sweden AB [http://neo4j.com]
5
+ *
6
+ * This file is part of Neo4j.
7
+ *
8
+ * Neo4j is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+ export { GraphVisualization } from './graph-visualization';
22
+ export { useGraphVisualizationContext, } from './graph-visualization-context';
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EACL,4BAA4B,GAc7B,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,162 @@
1
+ /**
2
+ *
3
+ * Copyright (c) "Neo4j"
4
+ * Neo4j Sweden AB [http://neo4j.com]
5
+ *
6
+ * This file is part of Neo4j.
7
+ *
8
+ * Neo4j is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+ import { calculateDefaultNodeColors } from '@neo4j-devtools/word-color';
22
+ import { tokens } from '@neo4j-ndl/base';
23
+ export const DEFAULT_REL_COLOR = tokens.colors.neutral['40'];
24
+ export const NO_LABEL_FALLBACK_COLOR = tokens.colors.neutral['40'];
25
+ const sortAlphabetically = (a = '', b = '') => a.toLowerCase().localeCompare(b.toLowerCase());
26
+ function getMostCommonColor(colors) {
27
+ var _a;
28
+ const [firstColor] = colors;
29
+ if (firstColor === undefined) {
30
+ return NO_LABEL_FALLBACK_COLOR;
31
+ }
32
+ const colorCounts = {};
33
+ for (const color of colors) {
34
+ colorCounts[color] = ((_a = colorCounts[color]) !== null && _a !== void 0 ? _a : 0) + 1;
35
+ }
36
+ let maxCount = 0;
37
+ let mostCommonColor = firstColor;
38
+ for (const [color, colorCount] of Object.entries(colorCounts)) {
39
+ if (colorCount > maxCount) {
40
+ maxCount = colorCount;
41
+ mostCommonColor = color;
42
+ }
43
+ }
44
+ return mostCommonColor;
45
+ }
46
+ function transformToItemMetada(arg) {
47
+ return Object.entries(arg).reduce((acc, [label, colors]) => {
48
+ acc[label] = {
49
+ mostCommonColor: getMostCommonColor(colors),
50
+ totalCount: colors.length,
51
+ };
52
+ return acc;
53
+ }, {});
54
+ }
55
+ export const captionPriorityOrder = [
56
+ /^name$/i,
57
+ /^title$/i,
58
+ /^label$/i,
59
+ /name$/i,
60
+ /description$/i,
61
+ /^.+/,
62
+ ];
63
+ export function getDefaultCaptionKey(options) {
64
+ const captionKeys = options
65
+ .filter((option) => option.type === 'property')
66
+ .map((option) => option.captionKey);
67
+ for (const regex of captionPriorityOrder) {
68
+ const matchingKey = captionKeys.find((key) => regex.test(key));
69
+ if (matchingKey !== undefined) {
70
+ return {
71
+ captionKey: matchingKey,
72
+ type: 'property',
73
+ };
74
+ }
75
+ }
76
+ const typeOption = options.find((option) => option.type === 'type');
77
+ if (typeOption) {
78
+ return typeOption;
79
+ }
80
+ return options.find((option) => option.type === 'id');
81
+ }
82
+ const getDefaultNodeCaption = (item) => {
83
+ const options = Object.keys(item.properties).map((property) => ({
84
+ captionKey: property,
85
+ type: 'property',
86
+ }));
87
+ options.push({ type: 'id' }, { type: 'type' });
88
+ const defaultCaptionKey = getDefaultCaptionKey(options);
89
+ if ((defaultCaptionKey === null || defaultCaptionKey === void 0 ? void 0 : defaultCaptionKey.type) === 'property') {
90
+ const caption = item.properties[defaultCaptionKey.captionKey];
91
+ if (caption !== undefined) {
92
+ // remove quotes from string
93
+ if (caption.type === 'string') {
94
+ return [{ value: caption.stringified.slice(1, -1) }];
95
+ }
96
+ return [{ value: caption.stringified }];
97
+ }
98
+ }
99
+ const [firstLabel] = item.labels;
100
+ if ((defaultCaptionKey === null || defaultCaptionKey === void 0 ? void 0 : defaultCaptionKey.type) === 'type' && firstLabel !== undefined) {
101
+ return [{ value: firstLabel }];
102
+ }
103
+ return [{ value: item.id }];
104
+ };
105
+ // Properties can be huge, so we split them out into a separate lookup table
106
+ // to prevent them from making the physics slow
107
+ // here we also apply default colors & captions to nodes and relationships
108
+ // and sample colors for the sidepanel
109
+ // in the future we'll apply styling here as well
110
+ export function mapToNvlGraph(rawNodes, rawRels) {
111
+ const labelColorPairs = {};
112
+ const typeColorPairs = {};
113
+ const nodeData = {};
114
+ const relData = {};
115
+ const nodes = rawNodes.map((node) => {
116
+ var _a;
117
+ const [firstLabel] = node.labels;
118
+ const newNode = Object.assign(Object.assign({ captions: getDefaultNodeCaption(node), color: (_a = node.color) !== null && _a !== void 0 ? _a : (firstLabel === undefined
119
+ ? NO_LABEL_FALLBACK_COLOR
120
+ : calculateDefaultNodeColors(firstLabel).backgroundColor) }, node), { labels: undefined, properties: undefined });
121
+ nodeData[node.id] = {
122
+ color: newNode.color,
123
+ id: node.id,
124
+ labelsSorted: [...node.labels].sort(sortAlphabetically),
125
+ properties: node.properties,
126
+ };
127
+ node.labels.forEach((label) => {
128
+ var _a;
129
+ labelColorPairs[label] = [
130
+ ...((_a = labelColorPairs[label]) !== null && _a !== void 0 ? _a : []),
131
+ newNode.color,
132
+ ];
133
+ });
134
+ return newNode;
135
+ });
136
+ const rels = rawRels.map((rel) => {
137
+ var _a, _b, _c;
138
+ relData[rel.id] = {
139
+ color: (_a = rel.color) !== null && _a !== void 0 ? _a : DEFAULT_REL_COLOR,
140
+ id: rel.id,
141
+ properties: rel.properties,
142
+ type: rel.type,
143
+ };
144
+ typeColorPairs[rel.type] = [
145
+ ...((_b = typeColorPairs[rel.type]) !== null && _b !== void 0 ? _b : []),
146
+ (_c = rel.color) !== null && _c !== void 0 ? _c : DEFAULT_REL_COLOR,
147
+ ];
148
+ return Object.assign(Object.assign({ captions: [{ value: rel.type }], color: DEFAULT_REL_COLOR }, rel), { properties: undefined, type: undefined });
149
+ });
150
+ const labelMetaData = transformToItemMetada(labelColorPairs);
151
+ const typeMetaData = transformToItemMetada(typeColorPairs);
152
+ const dataLookupTable = {
153
+ labelMetaData,
154
+ labels: Object.keys(labelMetaData).sort((a, b) => sortAlphabetically(a, b)),
155
+ nodes: nodeData,
156
+ relationships: relData,
157
+ typeMetaData,
158
+ types: Object.keys(typeMetaData).sort((a, b) => sortAlphabetically(a, b)),
159
+ };
160
+ return { dataLookupTable, nodes, rels };
161
+ }
162
+ //# sourceMappingURL=map-to-nvl-graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-to-nvl-graph.js","sourceRoot":"","sources":["../../src/map-to-nvl-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAA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