@dxos/react-ui-graph 0.8.4-main.ef1bc66f44 → 0.8.4-main.effb148878
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.
- package/LICENSE +102 -5
- package/README.md +5 -7
- package/dist/lib/browser/{chunk-LKC455GK.mjs → chunk-EASNZZ7B.mjs} +1 -1
- package/dist/lib/browser/{chunk-LKC455GK.mjs.map → chunk-EASNZZ7B.mjs.map} +2 -2
- package/dist/lib/browser/index.mjs +926 -371
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +14 -14
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-JE4KZCUF.mjs → chunk-JSE2X4ML.mjs} +1 -1
- package/dist/lib/node-esm/{chunk-JE4KZCUF.mjs.map → chunk-JSE2X4ML.mjs.map} +2 -2
- package/dist/lib/node-esm/index.mjs +926 -371
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +14 -14
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/components/Graph/Graph.d.ts +8 -4
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +5 -5
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Grid.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Markers.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Root.d.ts +7 -3
- package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
- package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts +1 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +3 -3
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/fx/pulsar.d.ts.map +1 -1
- package/dist/types/src/graph/markers.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-bundle-projector.d.ts +47 -0
- package/dist/types/src/graph/projector/graph-bundle-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts +60 -0
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-forces.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-lattice-projector.d.ts +23 -0
- package/dist/types/src/graph/projector/graph-lattice-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +6 -0
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/index.d.ts +3 -0
- package/dist/types/src/graph/projector/index.d.ts.map +1 -1
- package/dist/types/src/graph/projector/projector.d.ts +10 -1
- package/dist/types/src/graph/projector/projector.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts +21 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/renderer.d.ts +12 -1
- package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
- package/dist/types/src/graph/types.d.ts +14 -0
- package/dist/types/src/graph/types.d.ts.map +1 -1
- package/dist/types/src/hooks/useGrid.d.ts.map +1 -1
- package/dist/types/src/hooks/useStateRef.d.ts.map +1 -1
- package/dist/types/src/hooks/useSvgContext.d.ts.map +1 -1
- package/dist/types/src/hooks/useZoom.d.ts.map +1 -1
- package/dist/types/src/stories/hooks.stories.d.ts +1 -1
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +1 -1
- package/dist/types/src/testing/data.d.ts.map +1 -1
- package/dist/types/src/testing/hooks.d.ts.map +1 -1
- package/dist/types/src/testing/model.d.ts.map +1 -1
- package/dist/types/src/util/events.d.ts.map +1 -1
- package/dist/types/src/util/fraction.d.ts +1 -1
- package/dist/types/src/util/fraction.d.ts.map +1 -1
- package/dist/types/src/util/points.d.ts.map +1 -1
- package/dist/types/src/util/scale.d.ts.map +1 -1
- package/dist/types/src/util/screen.d.ts.map +1 -1
- package/dist/types/src/util/vector.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -26
- package/src/components/Graph/Graph.stories.tsx +25 -23
- package/src/components/Graph/Graph.tsx +51 -23
- package/src/components/Mesh/Mesh.stories.tsx +8 -7
- package/src/components/Mesh/Mesh.tsx +43 -35
- package/src/components/SVG/Root.tsx +41 -8
- package/src/components/SVG/SVG.tsx +0 -1
- package/src/components/SVG/Svg.stories.tsx +4 -5
- package/src/fx/fx.stories.tsx +7 -8
- package/src/graph/projector/graph-bundle-projector.ts +210 -0
- package/src/graph/projector/graph-cluster-projector.ts +325 -0
- package/src/graph/projector/graph-drag.ts +0 -1
- package/src/graph/projector/graph-force-projector.ts +5 -2
- package/src/graph/projector/graph-hierarchical-projector.ts +1 -1
- package/src/graph/projector/graph-lattice-projector.ts +86 -0
- package/src/graph/projector/graph-projector.ts +7 -1
- package/src/graph/projector/graph-radial-projector.ts +30 -3
- package/src/graph/projector/graph-relational-projector.ts +1 -1
- package/src/graph/projector/index.ts +3 -0
- package/src/graph/projector/projector.ts +12 -3
- package/src/graph/renderer/graph-renderer.ts +175 -30
- package/src/graph/renderer/renderer.ts +15 -4
- package/src/graph/types.ts +14 -0
- package/src/stories/hooks.stories.tsx +10 -5
- package/src/testing/data.ts +9 -9
- package/src/testing/hooks.ts +2 -3
- package/src/testing/model.ts +3 -3
- package/src/util/fraction.ts +1 -1
- package/styles/graph.css +341 -43
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-graph",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.effb148878",
|
|
4
4
|
"description": "GEM Graph.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/dxos/dxos"
|
|
10
10
|
},
|
|
11
|
-
"license": "
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
12
12
|
"author": "DXOS.org",
|
|
13
13
|
"sideEffects": [
|
|
14
14
|
"*.css"
|
|
@@ -28,13 +28,6 @@
|
|
|
28
28
|
"./styles/graph.css": "./styles/graph.css"
|
|
29
29
|
},
|
|
30
30
|
"types": "dist/types/src/index.d.ts",
|
|
31
|
-
"typesVersions": {
|
|
32
|
-
"*": {
|
|
33
|
-
"testing": [
|
|
34
|
-
"dist/types/src/testing/index.d.ts"
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
31
|
"files": [
|
|
39
32
|
"testing.d.ts",
|
|
40
33
|
"testing.js",
|
|
@@ -51,13 +44,13 @@
|
|
|
51
44
|
"lodash.defaultsdeep": "^4.6.1",
|
|
52
45
|
"react-resize-detector": "^11.0.1",
|
|
53
46
|
"topojson-client": "^3.1.0",
|
|
54
|
-
"@dxos/async": "0.8.4-main.
|
|
55
|
-
"@dxos/debug": "0.8.4-main.
|
|
56
|
-
"@dxos/invariant": "0.8.4-main.
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/react-ui-mosaic": "0.8.4-main.
|
|
47
|
+
"@dxos/async": "0.8.4-main.effb148878",
|
|
48
|
+
"@dxos/debug": "0.8.4-main.effb148878",
|
|
49
|
+
"@dxos/invariant": "0.8.4-main.effb148878",
|
|
50
|
+
"@dxos/log": "0.8.4-main.effb148878",
|
|
51
|
+
"@dxos/graph": "0.8.4-main.effb148878",
|
|
52
|
+
"@dxos/node-std": "0.8.4-main.effb148878",
|
|
53
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.effb148878"
|
|
61
54
|
},
|
|
62
55
|
"devDependencies": {
|
|
63
56
|
"@babel/core": "^7.18.13",
|
|
@@ -67,24 +60,24 @@
|
|
|
67
60
|
"@types/react-dom": "~19.2.3",
|
|
68
61
|
"@types/topojson-client": "^3.1.4",
|
|
69
62
|
"@types/topojson-specification": "^1.0.5",
|
|
70
|
-
"postcss": "^8.
|
|
63
|
+
"postcss": "^8.5.12",
|
|
71
64
|
"react": "~19.2.3",
|
|
72
65
|
"react-dom": "~19.2.3",
|
|
73
|
-
"@dxos/
|
|
74
|
-
"@dxos/
|
|
75
|
-
"@dxos/react-ui-stack": "0.8.4-main.
|
|
76
|
-
"@dxos/
|
|
77
|
-
"@dxos/
|
|
78
|
-
"@dxos/ui-
|
|
66
|
+
"@dxos/react-ui": "0.8.4-main.effb148878",
|
|
67
|
+
"@dxos/random": "0.8.4-main.effb148878",
|
|
68
|
+
"@dxos/react-ui-stack": "0.8.4-main.effb148878",
|
|
69
|
+
"@dxos/storybook-utils": "0.8.4-main.effb148878",
|
|
70
|
+
"@dxos/ui-theme": "0.8.4-main.effb148878",
|
|
71
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.effb148878"
|
|
79
72
|
},
|
|
80
73
|
"peerDependencies": {
|
|
81
74
|
"react": "~19.2.3",
|
|
82
75
|
"react-dom": "~19.2.3",
|
|
83
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
84
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
76
|
+
"@dxos/react-ui": "0.8.4-main.effb148878",
|
|
77
|
+
"@dxos/ui-theme": "0.8.4-main.effb148878"
|
|
85
78
|
},
|
|
86
79
|
"optionalDependencies": {
|
|
87
|
-
"@dxos/random": "0.8.4-main.
|
|
80
|
+
"@dxos/random": "0.8.4-main.effb148878"
|
|
88
81
|
},
|
|
89
82
|
"publishConfig": {
|
|
90
83
|
"access": "public"
|
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import '../../../styles/graph.css';
|
|
6
|
+
|
|
5
7
|
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
8
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
9
|
import { select } from 'd3';
|
|
8
10
|
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
9
11
|
|
|
10
|
-
import { type Graph, type GraphModel, SelectionModel } from '@dxos/graph';
|
|
12
|
+
import { type Graph, type GraphModel, type SelectionMode, SelectionModel } from '@dxos/graph';
|
|
11
13
|
import { IconButton, Popover, Toolbar } from '@dxos/react-ui';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
14
|
+
import { Card } from '@dxos/react-ui';
|
|
15
|
+
import { JsonHighlighter, Syntax } from '@dxos/react-ui-syntax-highlighter';
|
|
16
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
15
17
|
import { withRegistry } from '@dxos/storybook-utils';
|
|
16
18
|
import { getHashStyles, mx } from '@dxos/ui-theme';
|
|
17
19
|
|
|
@@ -32,11 +34,8 @@ import {
|
|
|
32
34
|
import { type SVGContext } from '../../hooks';
|
|
33
35
|
import { TestGraphModel, type TestNode, convertTreeToGraph, createGraph, createNode, createTree } from '../../testing';
|
|
34
36
|
import { SVG, type SVGGridProps } from '../SVG';
|
|
35
|
-
|
|
36
37
|
import { Graph as GraphComponent, type GraphController, type GraphProps } from './Graph';
|
|
37
38
|
|
|
38
|
-
import '../../../styles/graph.css';
|
|
39
|
-
|
|
40
39
|
type ProjectorType = 'force' | 'radial' | 'hierarchical' | 'relational';
|
|
41
40
|
|
|
42
41
|
type Factory = {
|
|
@@ -50,12 +49,12 @@ const projectorTypes: Record<ProjectorType, Factory> = {
|
|
|
50
49
|
relational: GraphRelationalProjector as Factory,
|
|
51
50
|
};
|
|
52
51
|
|
|
53
|
-
type
|
|
52
|
+
type DefaultStoryProps = GraphProps & {
|
|
54
53
|
debug?: boolean;
|
|
55
54
|
grid?: boolean | SVGGridProps;
|
|
56
55
|
inspect?: boolean;
|
|
57
|
-
singleSelect?: boolean;
|
|
58
56
|
graph: () => Graph.Any;
|
|
57
|
+
selectionMode?: SelectionMode;
|
|
59
58
|
projectorType?: ProjectorType;
|
|
60
59
|
projectorOptions?:
|
|
61
60
|
| GraphForceProjectorOptions
|
|
@@ -68,22 +67,22 @@ const DefaultStory = ({
|
|
|
68
67
|
debug,
|
|
69
68
|
grid,
|
|
70
69
|
inspect,
|
|
71
|
-
|
|
70
|
+
selectionMode,
|
|
72
71
|
graph: _graph,
|
|
73
72
|
projectorType: _projectorType = 'force',
|
|
74
73
|
projectorOptions,
|
|
75
74
|
...props
|
|
76
|
-
}:
|
|
75
|
+
}: DefaultStoryProps) => {
|
|
77
76
|
const graphRef = useRef<GraphController | null>(null);
|
|
78
77
|
const context = useRef<SVGContext>(null);
|
|
79
78
|
const registry = useContext(RegistryContext);
|
|
80
79
|
|
|
81
80
|
// Models.
|
|
82
|
-
const
|
|
81
|
+
const selection = useMemo(() => new SelectionModel({ mode: selectionMode }), [selectionMode]);
|
|
82
|
+
const [model, setModel] = useState<GraphModel.ReactiveGraphModel | undefined>(() => {
|
|
83
83
|
const graph = _graph?.();
|
|
84
84
|
return graph ? new TestGraphModel(registry, graph) : undefined;
|
|
85
85
|
});
|
|
86
|
-
const selection = useMemo(() => new SelectionModel(singleSelect), [singleSelect]);
|
|
87
86
|
|
|
88
87
|
// Projector.
|
|
89
88
|
const [projectorType, setProjectorType] = useState<ProjectorType>(_projectorType);
|
|
@@ -206,7 +205,7 @@ const DefaultStory = ({
|
|
|
206
205
|
|
|
207
206
|
return (
|
|
208
207
|
<Popover.Root open={!!popover} onOpenChange={(state) => !state && setPopover(undefined)}>
|
|
209
|
-
<div className={mx('
|
|
208
|
+
<div className={mx('h-full w-full grid divide-x divide-separator', debug && 'grid-cols-[1fr_30rem]')}>
|
|
210
209
|
<SVG.Root ref={context}>
|
|
211
210
|
<SVG.Markers />
|
|
212
211
|
{grid && <SVG.Grid {...(typeof grid === 'boolean' ? { axis: grid } : grid)} />}
|
|
@@ -261,11 +260,7 @@ const DefaultStory = ({
|
|
|
261
260
|
<Popover.Content onOpenAutoFocus={(event) => event.preventDefault()}>
|
|
262
261
|
<Popover.Viewport>
|
|
263
262
|
<Card.Root>
|
|
264
|
-
<
|
|
265
|
-
language='json'
|
|
266
|
-
classNames='text-xs mlb-cardSpacingBlock pli-cardSpacingInline bg-transparent'
|
|
267
|
-
code={JSON.stringify(popover, null, 2)}
|
|
268
|
-
/>
|
|
263
|
+
<JsonHighlighter data={popover} classNames='text-xs my-form-padding px-form-padding bg-transparent' />
|
|
269
264
|
</Card.Root>
|
|
270
265
|
</Popover.Viewport>
|
|
271
266
|
<Popover.Arrow />
|
|
@@ -287,7 +282,7 @@ const Debug = ({
|
|
|
287
282
|
onDelete,
|
|
288
283
|
onPing,
|
|
289
284
|
}: {
|
|
290
|
-
model?: GraphModel.
|
|
285
|
+
model?: GraphModel.ReactiveGraphModel;
|
|
291
286
|
selection: SelectionModel;
|
|
292
287
|
projector: ProjectorType;
|
|
293
288
|
onToggleProjector: () => void;
|
|
@@ -320,7 +315,14 @@ const Debug = ({
|
|
|
320
315
|
<IconButton onClick={onDelete} label='Delete' icon='ph--x--regular' iconOnly />
|
|
321
316
|
<IconButton onClick={onPing} label='Delete' icon='ph--crosshair-simple--regular' iconOnly />
|
|
322
317
|
</Toolbar.Root>
|
|
323
|
-
<
|
|
318
|
+
<Syntax.Root data={data}>
|
|
319
|
+
<Syntax.Content>
|
|
320
|
+
<Syntax.Filter />
|
|
321
|
+
<Syntax.Viewport>
|
|
322
|
+
<Syntax.Code classNames='text-sm' />
|
|
323
|
+
</Syntax.Viewport>
|
|
324
|
+
</Syntax.Content>
|
|
325
|
+
</Syntax.Root>
|
|
324
326
|
</div>
|
|
325
327
|
);
|
|
326
328
|
};
|
|
@@ -328,7 +330,7 @@ const Debug = ({
|
|
|
328
330
|
const meta = {
|
|
329
331
|
title: 'ui/react-ui-graph/Graph',
|
|
330
332
|
render: DefaultStory,
|
|
331
|
-
decorators: [withRegistry, withTheme()],
|
|
333
|
+
decorators: [withRegistry, withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
332
334
|
parameters: {
|
|
333
335
|
layout: 'fullscreen',
|
|
334
336
|
controls: { disable: true },
|
|
@@ -357,7 +359,7 @@ export const Projector: Story = {
|
|
|
357
359
|
debug: true,
|
|
358
360
|
drag: true,
|
|
359
361
|
arrows: true,
|
|
360
|
-
|
|
362
|
+
selectionMode: 'single',
|
|
361
363
|
projectorType: 'hierarchical',
|
|
362
364
|
projectorOptions: {
|
|
363
365
|
duration: 500,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import React, { type JSX, type Ref, forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
6
6
|
|
|
7
7
|
import { combine } from '@dxos/async';
|
|
8
|
-
import { type Graph as Graph
|
|
8
|
+
import { GraphModel, type Graph as Graph$ } from '@dxos/graph';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
11
11
|
import { mx } from '@dxos/ui-theme';
|
|
@@ -27,14 +27,18 @@ export type GraphController = {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
export type GraphProps<Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any> = ThemedClassName<
|
|
30
|
-
Pick<GraphRendererOptions<Node>, 'labels' | 'subgraphs' | 'attributes'> & {
|
|
31
|
-
model?: GraphModel.
|
|
30
|
+
Pick<GraphRendererOptions<Node>, 'labels' | 'subgraphs' | 'attributes' | 'renderNode'> & {
|
|
31
|
+
model?: GraphModel.ReactiveGraphModel<Node, Edge>;
|
|
32
32
|
projector?: GraphProjector<Node>;
|
|
33
33
|
renderer?: GraphRenderer<Node>;
|
|
34
34
|
drag?: boolean;
|
|
35
35
|
arrows?: boolean;
|
|
36
36
|
onSelect?: (node: GraphLayoutNode<Node>, event: MouseEvent) => void;
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Fires on pointerenter with the hovered node, and on pointerleave with `null`.
|
|
39
|
+
* Use the `null` signal to clear hover-driven previews / highlights.
|
|
40
|
+
*/
|
|
41
|
+
onInspect?: (node: GraphLayoutNode<Node> | null, event: MouseEvent) => void;
|
|
38
42
|
}
|
|
39
43
|
>;
|
|
40
44
|
|
|
@@ -42,8 +46,8 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
42
46
|
{
|
|
43
47
|
classNames,
|
|
44
48
|
model,
|
|
45
|
-
projector:
|
|
46
|
-
renderer:
|
|
49
|
+
projector: projectorProp,
|
|
50
|
+
renderer: rendererProp,
|
|
47
51
|
drag,
|
|
48
52
|
arrows,
|
|
49
53
|
onSelect,
|
|
@@ -56,25 +60,42 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
56
60
|
const graphRef = useRef<SVGGElement>(null);
|
|
57
61
|
|
|
58
62
|
const { projector, renderer } = useMemo(() => {
|
|
59
|
-
let projector =
|
|
63
|
+
let projector = projectorProp;
|
|
60
64
|
if (!projector) {
|
|
61
65
|
projector = new GraphForceProjector<Node>(context);
|
|
62
66
|
}
|
|
63
67
|
|
|
64
|
-
let renderer =
|
|
68
|
+
let renderer = rendererProp;
|
|
65
69
|
if (!renderer) {
|
|
66
70
|
renderer = new GraphRenderer<Node>(context, graphRef, {
|
|
67
71
|
...props,
|
|
68
72
|
// TODO(burdon): Replace drag when projector is updated.
|
|
69
73
|
drag: drag ? createGraphDrag(context, projector) : undefined,
|
|
70
74
|
arrows: { end: arrows },
|
|
71
|
-
onNodeClick: onSelect
|
|
72
|
-
onNodePointerEnter: onInspect ? (node
|
|
75
|
+
onNodeClick: onSelect,
|
|
76
|
+
onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : undefined,
|
|
77
|
+
// Pair pointerenter with leave so consumers can clear hover-driven previews.
|
|
78
|
+
// The callback receives `null` on leave (event still carries the source).
|
|
79
|
+
onNodePointerLeave: onInspect ? (_node, event) => onInspect(null, event) : undefined,
|
|
73
80
|
});
|
|
74
81
|
}
|
|
75
82
|
|
|
76
83
|
return { projector, renderer };
|
|
77
|
-
|
|
84
|
+
// Renderer options are baked into the instance — re-memo when any of them change
|
|
85
|
+
// so a swapped `renderNode` / handler is actually applied.
|
|
86
|
+
}, [
|
|
87
|
+
context,
|
|
88
|
+
projectorProp,
|
|
89
|
+
rendererProp,
|
|
90
|
+
drag,
|
|
91
|
+
arrows,
|
|
92
|
+
onSelect,
|
|
93
|
+
onInspect,
|
|
94
|
+
props.labels,
|
|
95
|
+
props.subgraphs,
|
|
96
|
+
props.attributes,
|
|
97
|
+
props.renderNode,
|
|
98
|
+
]);
|
|
78
99
|
|
|
79
100
|
// External API.
|
|
80
101
|
useImperativeHandle(
|
|
@@ -95,27 +116,34 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
95
116
|
|
|
96
117
|
// Subscriptions.
|
|
97
118
|
useEffect(() => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
model
|
|
103
|
-
?
|
|
119
|
+
// Wire the renderer listener BEFORE calling updateData so the synchronous
|
|
120
|
+
// 'topology' emit (fired from inside onUpdate) reaches the renderer.
|
|
121
|
+
const cleanup = combine(
|
|
122
|
+
// Subscribe to model changes if reactive model.
|
|
123
|
+
model
|
|
124
|
+
? model.subscribe(() => {
|
|
104
125
|
projector.updateData(model?.graph);
|
|
105
126
|
})
|
|
106
|
-
: undefined
|
|
127
|
+
: undefined,
|
|
107
128
|
|
|
108
|
-
|
|
109
|
-
unsubscribeModel,
|
|
110
|
-
projector.updated.on(({ layout }) => {
|
|
129
|
+
projector.updated.on(({ layout, kind }) => {
|
|
111
130
|
try {
|
|
112
|
-
|
|
131
|
+
// 'positions' is the per-tick fast path; 'topology' (and unset, for back-compat) is the full render.
|
|
132
|
+
if (kind === 'positions') {
|
|
133
|
+
renderer.applyPositions(layout);
|
|
134
|
+
} else {
|
|
135
|
+
renderer.render(layout);
|
|
136
|
+
}
|
|
113
137
|
} catch (error) {
|
|
114
|
-
void projector.stop();
|
|
115
138
|
log.catch(error);
|
|
139
|
+
void projector.stop();
|
|
116
140
|
}
|
|
117
141
|
}),
|
|
118
142
|
);
|
|
143
|
+
|
|
144
|
+
projector.updateData(model?.graph);
|
|
145
|
+
|
|
146
|
+
return cleanup;
|
|
119
147
|
}, [model, projector, renderer]);
|
|
120
148
|
|
|
121
149
|
// Start.
|
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React, { useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
8
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
9
9
|
|
|
10
10
|
import { SVG, type SVGRootProps } from '../SVG';
|
|
11
|
-
|
|
12
11
|
import { Mesh } from './Mesh';
|
|
13
12
|
|
|
14
13
|
// TODO(burdon): Create waves/game of life.
|
|
@@ -37,7 +36,7 @@ const DefaultStory = (props: SVGRootProps) => {
|
|
|
37
36
|
const meta = {
|
|
38
37
|
title: 'ui/react-ui-graph/Mesh',
|
|
39
38
|
render: DefaultStory,
|
|
40
|
-
decorators: [withTheme()],
|
|
39
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
41
40
|
parameters: {
|
|
42
41
|
layout: 'fullscreen',
|
|
43
42
|
},
|
|
@@ -47,18 +46,20 @@ export default meta;
|
|
|
47
46
|
|
|
48
47
|
type Story = StoryObj<typeof meta>;
|
|
49
48
|
|
|
49
|
+
// Selectors use the descendant combinator (`[&_X]`) — the mesh / hexagon / border elements
|
|
50
|
+
// live inside the SVG inside the div, so direct-child (`>`) selectors don't match.
|
|
50
51
|
export const Default: Story = {
|
|
51
52
|
args: {
|
|
52
53
|
classNames: [
|
|
53
|
-
'[
|
|
54
|
-
'[
|
|
55
|
-
'[
|
|
54
|
+
'[&_.mesh]:fill-none',
|
|
55
|
+
'[&_.hexagon>path.fill]:fill-blue-800 [&_.hexagon]:stroke-blue-700',
|
|
56
|
+
'[&_.border]:fill-none [&_.border]:stroke-blue-500 [&_.border]:stroke-2',
|
|
56
57
|
],
|
|
57
58
|
},
|
|
58
59
|
};
|
|
59
60
|
|
|
60
61
|
export const Outline: Story = {
|
|
61
62
|
args: {
|
|
62
|
-
classNames: ['[
|
|
63
|
+
classNames: ['[&_.mesh]:fill-none', '[&_.border]:fill-none [&_.border]:stroke-red-500 [&_.border]:stroke-2'],
|
|
63
64
|
},
|
|
64
65
|
};
|
|
@@ -20,43 +20,51 @@ export const Mesh = ({ radius = 16, value = 0.5 }: MeshProps) => {
|
|
|
20
20
|
const { svg, size } = useSvgContext();
|
|
21
21
|
|
|
22
22
|
useEffect(() => {
|
|
23
|
-
if (size) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
23
|
+
if (!size) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const topology = hexTopology(size, radius, value);
|
|
28
|
+
const projection = hexProjection(radius);
|
|
29
|
+
const path = geoPath().projection(projection);
|
|
30
|
+
|
|
31
|
+
// Replace the previous render: idempotent join on a single keyed root group, then
|
|
32
|
+
// recreate the inner layers. Without this the effect re-runs (e.g. animating `value`
|
|
33
|
+
// or on resize) appended new groups on top of the old ones instead of replacing them.
|
|
34
|
+
const root = select(svg)
|
|
35
|
+
.selectAll<SVGGElement, null>('g.dx-mesh-root')
|
|
36
|
+
.data([null])
|
|
37
|
+
.join('g')
|
|
38
|
+
.classed('dx-mesh-root', true);
|
|
39
|
+
root.selectAll('*').remove();
|
|
40
|
+
|
|
41
|
+
root
|
|
42
|
+
.append('g')
|
|
43
|
+
.attr('class', 'hexagon')
|
|
44
|
+
.selectAll('path')
|
|
45
|
+
.data(topology.objects.hexagons.geometries)
|
|
46
|
+
.enter()
|
|
47
|
+
.append('path')
|
|
48
|
+
.attr('d', (d) => path(feature(topology, d)))
|
|
49
|
+
.attr('class', (d) => ((d.properties as Custom)?.fill ? 'fill' : null));
|
|
50
|
+
|
|
51
|
+
root.append('path').datum(mesh(topology, topology.objects.hexagons)).attr('class', 'mesh').attr('d', path);
|
|
52
|
+
|
|
53
|
+
const redraw = (border: any) => {
|
|
54
|
+
border.attr(
|
|
55
|
+
'd',
|
|
56
|
+
path(
|
|
57
|
+
mesh(
|
|
58
|
+
topology,
|
|
59
|
+
topology.objects.hexagons,
|
|
60
|
+
(a, b) => (a.properties as Custom).fill !== (b.properties as Custom).fill,
|
|
53
61
|
),
|
|
54
|
-
)
|
|
55
|
-
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
};
|
|
56
65
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}, [svg, size, value]);
|
|
66
|
+
root.append('path').attr('class', 'border').call(redraw);
|
|
67
|
+
}, [svg, size, value, radius]);
|
|
60
68
|
|
|
61
69
|
return null;
|
|
62
70
|
};
|
|
@@ -3,26 +3,59 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { select } from 'd3';
|
|
6
|
-
import React, {
|
|
7
|
-
|
|
6
|
+
import React, {
|
|
7
|
+
type ComponentPropsWithoutRef,
|
|
8
|
+
type PropsWithChildren,
|
|
9
|
+
forwardRef,
|
|
10
|
+
useEffect,
|
|
11
|
+
useImperativeHandle,
|
|
12
|
+
useMemo,
|
|
13
|
+
useState,
|
|
14
|
+
} from 'react';
|
|
8
15
|
|
|
9
16
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
17
|
+
import { composableProps } from '@dxos/react-ui';
|
|
10
18
|
import { mx } from '@dxos/ui-theme';
|
|
11
19
|
|
|
12
20
|
import { SVGContext, type SVGContextOptions, SVGContextProvider } from '../../hooks';
|
|
13
21
|
|
|
14
|
-
export type RootProps = ThemedClassName<PropsWithChildren<SVGContextOptions
|
|
22
|
+
export type RootProps = ThemedClassName<PropsWithChildren<SVGContextOptions & ComponentPropsWithoutRef<'div'>>>;
|
|
15
23
|
|
|
16
24
|
/**
|
|
17
25
|
* Makes the SVG context available to child nodes.
|
|
18
26
|
* Automatically resizes the SVG element, which expands to fit the container.
|
|
27
|
+
*
|
|
28
|
+
* NOTE: Uses `ResizeObserver` directly rather than `react-resize-detector` — the latter's
|
|
29
|
+
* `useResizeDetector` was flaky in our Storybook environment (sometimes never fired its
|
|
30
|
+
* initial measurement), leaving the SVG stuck at `opacity-0` with no rendered content.
|
|
19
31
|
*/
|
|
20
|
-
export const Root = forwardRef<SVGContext, RootProps>(({
|
|
21
|
-
const
|
|
32
|
+
export const Root = forwardRef<SVGContext, RootProps>(({ children, scale, centered, ...props }, ref) => {
|
|
33
|
+
const [container, setContainer] = useState<HTMLDivElement | null>(null);
|
|
34
|
+
const [size, setSize] = useState<{ width: number; height: number }>({ width: 0, height: 0 });
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (!container) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const rect = container.getBoundingClientRect();
|
|
41
|
+
setSize({ width: rect.width, height: rect.height });
|
|
42
|
+
const observer = new ResizeObserver((entries) => {
|
|
43
|
+
const entry = entries[0];
|
|
44
|
+
if (!entry) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const { width, height } = entry.contentRect;
|
|
48
|
+
setSize((prev) => (prev.width === width && prev.height === height ? prev : { width, height }));
|
|
49
|
+
});
|
|
50
|
+
observer.observe(container);
|
|
51
|
+
return () => observer.disconnect();
|
|
52
|
+
}, [container]);
|
|
53
|
+
|
|
54
|
+
const { width, height } = size;
|
|
22
55
|
|
|
23
56
|
const context = useMemo<SVGContext>(() => {
|
|
24
|
-
return new SVGContext(
|
|
25
|
-
}, [
|
|
57
|
+
return new SVGContext({ scale, centered });
|
|
58
|
+
}, [scale, centered]);
|
|
26
59
|
|
|
27
60
|
useImperativeHandle(ref, () => context, [context]);
|
|
28
61
|
|
|
@@ -41,7 +74,7 @@ export const Root = forwardRef<SVGContext, RootProps>(({ classNames, children, .
|
|
|
41
74
|
|
|
42
75
|
return (
|
|
43
76
|
<SVGContextProvider value={context}>
|
|
44
|
-
<div
|
|
77
|
+
<div {...composableProps(props, { classNames: 'dx-expander' })} ref={setContainer}>
|
|
45
78
|
<svg
|
|
46
79
|
xmlns='http://www.w3.org/2000/svg'
|
|
47
80
|
ref={context.ref}
|
|
@@ -8,7 +8,6 @@ import { type ThemedClassName } from '@dxos/react-ui';
|
|
|
8
8
|
|
|
9
9
|
import { Graph, type GraphProps as SVGGraphProps } from '../Graph';
|
|
10
10
|
import { Mesh, type MeshProps as SVGMeshProps } from '../Mesh';
|
|
11
|
-
|
|
12
11
|
import { Grid, type GridProps as SVGGridProps } from './Grid';
|
|
13
12
|
import { Markers, type MarkersProps as SVGMarkersProps } from './Markers';
|
|
14
13
|
import { Root, type RootProps as SVGRootProps } from './Root';
|
|
@@ -2,17 +2,16 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import '../../../styles/graph.css';
|
|
6
|
+
|
|
5
7
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
8
|
import React, { useRef } from 'react';
|
|
7
9
|
|
|
8
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
10
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
9
11
|
|
|
10
12
|
import { type SVGContext, useGrid, useZoom } from '../../hooks';
|
|
11
|
-
|
|
12
13
|
import { SVG } from './SVG';
|
|
13
14
|
|
|
14
|
-
import '../../../styles/graph.css';
|
|
15
|
-
|
|
16
15
|
type ComponentProps = {
|
|
17
16
|
grid?: boolean;
|
|
18
17
|
zoom?: boolean;
|
|
@@ -45,7 +44,7 @@ const DefaultStory = (props: ComponentProps) => {
|
|
|
45
44
|
const meta = {
|
|
46
45
|
title: 'ui/react-ui-graph/SVGRoot',
|
|
47
46
|
render: DefaultStory,
|
|
48
|
-
decorators: [withTheme()],
|
|
47
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
49
48
|
parameters: {
|
|
50
49
|
layout: 'fullscreen',
|
|
51
50
|
},
|
package/src/fx/fx.stories.tsx
CHANGED
|
@@ -2,31 +2,30 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import '../../styles/graph.css';
|
|
6
|
+
|
|
5
7
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
8
|
import { select } from 'd3';
|
|
7
9
|
import React, { type FC, useEffect, useMemo, useRef } from 'react';
|
|
8
10
|
|
|
9
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
11
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
12
|
|
|
11
13
|
import { SVG } from '../components';
|
|
12
14
|
import { useGrid, useZoom } from '../hooks';
|
|
13
15
|
import { type D3Callable } from '../util';
|
|
14
|
-
|
|
15
16
|
import { Pulsar } from './pulsar';
|
|
16
17
|
|
|
17
|
-
import '../../styles/graph.css';
|
|
18
|
-
|
|
19
18
|
type Datum = {
|
|
20
19
|
x: number;
|
|
21
20
|
y: number;
|
|
22
21
|
r: number;
|
|
23
22
|
};
|
|
24
23
|
|
|
25
|
-
type
|
|
24
|
+
type DefaultStoryProps = {
|
|
26
25
|
count: number;
|
|
27
26
|
} & Pulsar.Options;
|
|
28
27
|
|
|
29
|
-
const DefaultStory = (props:
|
|
28
|
+
const DefaultStory = (props: DefaultStoryProps) => {
|
|
30
29
|
return (
|
|
31
30
|
<SVG.Root>
|
|
32
31
|
<StoryComponent {...props} />
|
|
@@ -34,7 +33,7 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
34
33
|
);
|
|
35
34
|
};
|
|
36
35
|
|
|
37
|
-
const StoryComponent: FC<
|
|
36
|
+
const StoryComponent: FC<DefaultStoryProps> = ({ count = 1, ...options }) => {
|
|
38
37
|
const items = useMemo<Datum[]>(
|
|
39
38
|
() =>
|
|
40
39
|
Array.from({ length: count }, () => {
|
|
@@ -94,7 +93,7 @@ const createNode: D3Callable<SVGGElement, Datum> = (group, classNames, options)
|
|
|
94
93
|
const meta = {
|
|
95
94
|
title: 'ui/react-ui-graph/fx',
|
|
96
95
|
render: DefaultStory,
|
|
97
|
-
decorators: [withTheme()],
|
|
96
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
98
97
|
parameters: {
|
|
99
98
|
layout: 'fullscreen',
|
|
100
99
|
},
|