@dxos/react-ui-graph 0.8.4-main.d05673bc65 → 0.8.4-main.dfabb4ec29
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/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 +37 -102
- package/dist/lib/browser/index.mjs.map +3 -3
- 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 +37 -102
- package/dist/lib/node-esm/index.mjs.map +3 -3
- 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 +2 -2
- 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 +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-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-projector.d.ts.map +1 -1
- 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/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.map +1 -1
- package/dist/types/src/graph/renderer/renderer.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.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 +18 -25
- package/src/components/Graph/Graph.stories.tsx +21 -19
- package/src/components/Graph/Graph.tsx +10 -12
- package/src/components/Mesh/Mesh.stories.tsx +0 -1
- package/src/components/SVG/Root.tsx +3 -3
- package/src/components/SVG/SVG.tsx +0 -1
- package/src/components/SVG/Svg.stories.tsx +2 -3
- package/src/fx/fx.stories.tsx +5 -6
- package/src/graph/projector/graph-drag.ts +0 -1
- package/src/graph/projector/graph-force-projector.ts +0 -1
- package/src/graph/projector/graph-hierarchical-projector.ts +0 -1
- package/src/graph/projector/graph-projector.ts +0 -1
- package/src/graph/projector/graph-radial-projector.ts +0 -1
- package/src/graph/projector/graph-relational-projector.ts +0 -1
- package/src/graph/renderer/graph-renderer.ts +4 -5
- package/src/stories/hooks.stories.tsx +2 -2
- package/src/testing/data.ts +9 -9
- package/src/testing/hooks.ts +2 -3
- package/src/testing/model.ts +3 -3
- package/styles/graph.css +1 -1
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.dfabb4ec29",
|
|
4
4
|
"description": "GEM Graph.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -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/
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
47
|
+
"@dxos/async": "0.8.4-main.dfabb4ec29",
|
|
48
|
+
"@dxos/debug": "0.8.4-main.dfabb4ec29",
|
|
49
|
+
"@dxos/graph": "0.8.4-main.dfabb4ec29",
|
|
50
|
+
"@dxos/log": "0.8.4-main.dfabb4ec29",
|
|
51
|
+
"@dxos/invariant": "0.8.4-main.dfabb4ec29",
|
|
52
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.dfabb4ec29",
|
|
53
|
+
"@dxos/node-std": "0.8.4-main.dfabb4ec29"
|
|
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/random": "0.8.4-main.
|
|
74
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
75
|
-
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.
|
|
76
|
-
"@dxos/react-ui
|
|
77
|
-
"@dxos/
|
|
78
|
-
"@dxos/
|
|
66
|
+
"@dxos/random": "0.8.4-main.dfabb4ec29",
|
|
67
|
+
"@dxos/react-ui-stack": "0.8.4-main.dfabb4ec29",
|
|
68
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.dfabb4ec29",
|
|
69
|
+
"@dxos/react-ui": "0.8.4-main.dfabb4ec29",
|
|
70
|
+
"@dxos/storybook-utils": "0.8.4-main.dfabb4ec29",
|
|
71
|
+
"@dxos/ui-theme": "0.8.4-main.dfabb4ec29"
|
|
79
72
|
},
|
|
80
73
|
"peerDependencies": {
|
|
81
74
|
"react": "~19.2.3",
|
|
82
75
|
"react-dom": "~19.2.3",
|
|
83
|
-
"@dxos/
|
|
84
|
-
"@dxos/ui
|
|
76
|
+
"@dxos/ui-theme": "0.8.4-main.dfabb4ec29",
|
|
77
|
+
"@dxos/react-ui": "0.8.4-main.dfabb4ec29"
|
|
85
78
|
},
|
|
86
79
|
"optionalDependencies": {
|
|
87
|
-
"@dxos/random": "0.8.4-main.
|
|
80
|
+
"@dxos/random": "0.8.4-main.dfabb4ec29"
|
|
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
14
|
import { Card } from '@dxos/react-ui';
|
|
15
|
+
import { JsonHighlighter, Syntax } from '@dxos/react-ui-syntax-highlighter';
|
|
13
16
|
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
14
|
-
import { JsonFilter, SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
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);
|
|
@@ -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 my-form-padding px-form-padding 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
|
};
|
|
@@ -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';
|
|
@@ -28,7 +28,7 @@ export type GraphController = {
|
|
|
28
28
|
|
|
29
29
|
export type GraphProps<Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any> = ThemedClassName<
|
|
30
30
|
Pick<GraphRendererOptions<Node>, 'labels' | 'subgraphs' | 'attributes'> & {
|
|
31
|
-
model?: GraphModel.
|
|
31
|
+
model?: GraphModel.ReactiveGraphModel<Node, Edge>;
|
|
32
32
|
projector?: GraphProjector<Node>;
|
|
33
33
|
renderer?: GraphRenderer<Node>;
|
|
34
34
|
drag?: boolean;
|
|
@@ -68,8 +68,8 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
68
68
|
// TODO(burdon): Replace drag when projector is updated.
|
|
69
69
|
drag: drag ? createGraphDrag(context, projector) : undefined,
|
|
70
70
|
arrows: { end: arrows },
|
|
71
|
-
onNodeClick: onSelect
|
|
72
|
-
onNodePointerEnter: onInspect
|
|
71
|
+
onNodeClick: onSelect,
|
|
72
|
+
onNodePointerEnter: onInspect,
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -97,22 +97,20 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
97
97
|
useEffect(() => {
|
|
98
98
|
projector.updateData(model?.graph);
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
model
|
|
103
|
-
?
|
|
100
|
+
return combine(
|
|
101
|
+
// Subscribe to model changes if reactive model.
|
|
102
|
+
model
|
|
103
|
+
? model.subscribe(() => {
|
|
104
104
|
projector.updateData(model?.graph);
|
|
105
105
|
})
|
|
106
|
-
: undefined
|
|
106
|
+
: undefined,
|
|
107
107
|
|
|
108
|
-
return combine(
|
|
109
|
-
unsubscribeModel,
|
|
110
108
|
projector.updated.on(({ layout }) => {
|
|
111
109
|
try {
|
|
112
110
|
renderer.render(layout);
|
|
113
111
|
} catch (error) {
|
|
114
|
-
void projector.stop();
|
|
115
112
|
log.catch(error);
|
|
113
|
+
void projector.stop();
|
|
116
114
|
}
|
|
117
115
|
}),
|
|
118
116
|
);
|
|
@@ -14,7 +14,7 @@ import React, {
|
|
|
14
14
|
import { useResizeDetector } from 'react-resize-detector';
|
|
15
15
|
|
|
16
16
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
17
|
-
import { mx } from '@dxos/ui-theme';
|
|
17
|
+
import { composableProps, mx } from '@dxos/ui-theme';
|
|
18
18
|
|
|
19
19
|
import { SVGContext, type SVGContextOptions, SVGContextProvider } from '../../hooks';
|
|
20
20
|
|
|
@@ -24,7 +24,7 @@ export type RootProps = ThemedClassName<PropsWithChildren<SVGContextOptions & Co
|
|
|
24
24
|
* Makes the SVG context available to child nodes.
|
|
25
25
|
* Automatically resizes the SVG element, which expands to fit the container.
|
|
26
26
|
*/
|
|
27
|
-
export const Root = forwardRef<SVGContext, RootProps>(({
|
|
27
|
+
export const Root = forwardRef<SVGContext, RootProps>(({ children, scale, centered, ...props }, ref) => {
|
|
28
28
|
const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({ refreshRate: 200 });
|
|
29
29
|
|
|
30
30
|
const context = useMemo<SVGContext>(() => {
|
|
@@ -48,7 +48,7 @@ export const Root = forwardRef<SVGContext, RootProps>(({ classNames, children, s
|
|
|
48
48
|
|
|
49
49
|
return (
|
|
50
50
|
<SVGContextProvider value={context}>
|
|
51
|
-
<div {...props
|
|
51
|
+
<div {...composableProps(props, { classNames: 'dx-expander' })} ref={containerRef}>
|
|
52
52
|
<svg
|
|
53
53
|
xmlns='http://www.w3.org/2000/svg'
|
|
54
54
|
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
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;
|
package/src/fx/fx.stories.tsx
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
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';
|
|
@@ -11,22 +13,19 @@ import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
|
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 }, () => {
|
|
@@ -7,7 +7,6 @@ import { drag, pointer, select } from 'd3';
|
|
|
7
7
|
import { type SVGContext } from '../../hooks';
|
|
8
8
|
import { type Point } from '../../util';
|
|
9
9
|
import { type GraphLayoutNode } from '../types';
|
|
10
|
-
|
|
11
10
|
import { type GraphProjector } from './graph-projector';
|
|
12
11
|
|
|
13
12
|
enum Mode {
|
|
@@ -18,7 +18,6 @@ import { type Graph } from '@dxos/graph';
|
|
|
18
18
|
import { log } from '@dxos/log';
|
|
19
19
|
|
|
20
20
|
import { type GraphLayoutEdge, type GraphLayoutNode } from '../types';
|
|
21
|
-
|
|
22
21
|
import { forcePoint } from './graph-forces';
|
|
23
22
|
import { GraphProjector, type GraphProjectorOptions } from './graph-projector';
|
|
24
23
|
|
|
@@ -6,7 +6,6 @@ import { type Graph } from '@dxos/graph';
|
|
|
6
6
|
import { log } from '@dxos/log';
|
|
7
7
|
|
|
8
8
|
import { type GraphLayoutNode } from '../types';
|
|
9
|
-
|
|
10
9
|
import { type GraphProjectorOptions } from './graph-projector';
|
|
11
10
|
import { GraphRadialProjector, layoutRadial, updateNode } from './graph-radial-projector';
|
|
12
11
|
|
|
@@ -6,7 +6,6 @@ import { type Graph, type SelectionModel } from '@dxos/graph';
|
|
|
6
6
|
|
|
7
7
|
import { type SVGContext } from '../../hooks';
|
|
8
8
|
import { type GraphLayout, type GraphLayoutNode, emptyGraph } from '../types';
|
|
9
|
-
|
|
10
9
|
import { Projector, type ProjectorOptions } from './projector';
|
|
11
10
|
|
|
12
11
|
export type GraphProjectorOptions = ProjectorOptions & {};
|
|
@@ -9,7 +9,6 @@ import { log } from '@dxos/log';
|
|
|
9
9
|
|
|
10
10
|
import { type Point } from '../../util';
|
|
11
11
|
import { type GraphLayoutNode } from '../types';
|
|
12
|
-
|
|
13
12
|
import { GraphProjector, type GraphProjectorOptions } from './graph-projector';
|
|
14
13
|
|
|
15
14
|
export type GraphRadialProjectorOptions = GraphProjectorOptions & {
|
|
@@ -6,7 +6,6 @@ import { type Graph } from '@dxos/graph';
|
|
|
6
6
|
import { log } from '@dxos/log';
|
|
7
7
|
|
|
8
8
|
import { type GraphLayoutNode } from '../types';
|
|
9
|
-
|
|
10
9
|
import { type GraphProjectorOptions } from './graph-projector';
|
|
11
10
|
import { GraphRadialProjector, layoutHorizontal, layoutRadial, updateNode } from './graph-radial-projector';
|
|
12
11
|
|
|
@@ -9,7 +9,6 @@ import { log } from '@dxos/log';
|
|
|
9
9
|
|
|
10
10
|
import { type D3Callable, type D3Selection, type Point, getCircumferencePoints } from '../../util';
|
|
11
11
|
import { type GraphLayout, type GraphLayoutEdge, type GraphLayoutNode } from '../types';
|
|
12
|
-
|
|
13
12
|
import { createBullets } from './bullets';
|
|
14
13
|
import { Renderer, type RendererOptions } from './renderer';
|
|
15
14
|
|
|
@@ -251,20 +250,20 @@ const createNode: D3Callable = <Data>(group: D3Selection, options: GraphRenderer
|
|
|
251
250
|
options.onNodePointerEnter(node, event);
|
|
252
251
|
});
|
|
253
252
|
|
|
254
|
-
group.attr('data-hover', 'handled');
|
|
253
|
+
group.attr('data-hover', 'handled');
|
|
255
254
|
} else if (options.highlight !== false) {
|
|
256
255
|
circle.on('pointerenter', function () {
|
|
257
256
|
select(this.closest('g.dx-node')).raise();
|
|
258
257
|
if (options.labels) {
|
|
259
|
-
select(this.parentElement).classed('dx-active', true).classed('dx-highlight', true);
|
|
258
|
+
select(this.parentElement).classed('dx-node-active', true).classed('dx-highlight', true);
|
|
260
259
|
}
|
|
261
260
|
});
|
|
262
261
|
|
|
263
262
|
group.on('pointerleave', function () {
|
|
264
263
|
if (options.labels) {
|
|
265
|
-
select(this).classed('dx-active', false);
|
|
264
|
+
select(this).classed('dx-node-active', false);
|
|
266
265
|
setTimeout(() => {
|
|
267
|
-
if (!select(this).classed('dx-active')) {
|
|
266
|
+
if (!select(this).classed('dx-node-active')) {
|
|
268
267
|
select(this).classed('dx-highlight', false);
|
|
269
268
|
}
|
|
270
269
|
}, 300);
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// Copyright 2020 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';
|
|
@@ -27,8 +29,6 @@ import {
|
|
|
27
29
|
import { useGrid, useSvgContext, useZoom } from '../hooks';
|
|
28
30
|
import { TestGraphModel, type TestNode, convertTreeToGraph, createTree } from '../testing';
|
|
29
31
|
|
|
30
|
-
import '../../styles/graph.css';
|
|
31
|
-
|
|
32
32
|
type ComponentProps = PropsWithChildren<{
|
|
33
33
|
graph: () => Graph.Graph<TestNode, Graph.Edge.Any>;
|
|
34
34
|
projectorOptions?: GraphForceProjectorOptions;
|
package/src/testing/data.ts
CHANGED
|
@@ -3,25 +3,25 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Graph } from '@dxos/graph';
|
|
6
|
-
import {
|
|
6
|
+
import { random } from '@dxos/random';
|
|
7
7
|
|
|
8
8
|
import { type TestNode } from './model';
|
|
9
9
|
|
|
10
|
-
// https://www.npmjs.com/package/
|
|
11
|
-
export const seed = (seed: number) =>
|
|
10
|
+
// https://www.npmjs.com/package/random#setting-a-randomness-seed
|
|
11
|
+
export const seed = (seed: number) => random.seed(seed);
|
|
12
12
|
|
|
13
13
|
//
|
|
14
14
|
// Create data.
|
|
15
15
|
//
|
|
16
16
|
|
|
17
17
|
export const createNode = (type: string = undefined): TestNode => ({
|
|
18
|
-
id:
|
|
18
|
+
id: random.string.uuid(),
|
|
19
19
|
type,
|
|
20
|
-
label:
|
|
20
|
+
label: random.lorem.words(3).replace(/ /g, '-'),
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
export const createNodes = (n = 0, types?: string[]): TestNode[] =>
|
|
24
|
-
Array.from({ length: n }, () => createNode(types ?
|
|
24
|
+
Array.from({ length: n }, () => createNode(types ? random.helpers.arrayElement(types) : undefined));
|
|
25
25
|
|
|
26
26
|
export const createEdge = (source: TestNode, target: TestNode): Graph.Edge.Any => ({
|
|
27
27
|
id: `${source.id}-${target.id}`,
|
|
@@ -38,7 +38,7 @@ export const createTree = ({ depth = 2, children = 3 } = {}): TestNode => {
|
|
|
38
38
|
const createChildren = (root: TestNode, d = 0) => {
|
|
39
39
|
if (d < depth) {
|
|
40
40
|
const max = Math.round(Math.log(depth + 1 - d) * children);
|
|
41
|
-
const num =
|
|
41
|
+
const num = random.number.int({ min: 1, max });
|
|
42
42
|
root.children = [...new Array(num)].map(() => {
|
|
43
43
|
return createChildren(createNode(), d + 1);
|
|
44
44
|
});
|
|
@@ -82,8 +82,8 @@ export const createGraph = (numNodes = 0, numEdges = 0, types?: string[]): Graph
|
|
|
82
82
|
const edges = new Map();
|
|
83
83
|
if (numEdges && nodes.length >= 2) {
|
|
84
84
|
for (let i = 0; i < numEdges; i++) {
|
|
85
|
-
const source =
|
|
86
|
-
const target =
|
|
85
|
+
const source = random.helpers.arrayElement(nodes);
|
|
86
|
+
const target = random.helpers.arrayElement(nodes);
|
|
87
87
|
if (source.id !== target.id) {
|
|
88
88
|
const edge = createEdge(source, target);
|
|
89
89
|
if (!edges.get(edge.id)) {
|
package/src/testing/hooks.ts
CHANGED
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
import update from 'immutability-helper';
|
|
6
6
|
|
|
7
7
|
import { type Graph } from '@dxos/graph';
|
|
8
|
-
import {
|
|
8
|
+
import { random } from '@dxos/random';
|
|
9
9
|
|
|
10
10
|
import { useStateRef } from '../hooks';
|
|
11
|
-
|
|
12
11
|
import { createEdge, createNode } from './data';
|
|
13
12
|
import { type TestNode } from './model';
|
|
14
13
|
|
|
@@ -53,7 +52,7 @@ export const useGraphGenerator = (options: { data?: Graph.Any } = {}) => {
|
|
|
53
52
|
let interval;
|
|
54
53
|
|
|
55
54
|
const mutator = () => {
|
|
56
|
-
const parent = data.nodes.length ?
|
|
55
|
+
const parent = data.nodes.length ? random.helpers.arrayElement(data.nodes) : undefined;
|
|
57
56
|
const node = createNode();
|
|
58
57
|
|
|
59
58
|
updateData({
|
package/src/testing/model.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Graph, GraphModel } from '@dxos/graph';
|
|
6
|
-
import {
|
|
6
|
+
import { random } from '@dxos/random';
|
|
7
7
|
|
|
8
8
|
import { createEdge, createNode } from './data';
|
|
9
9
|
|
|
@@ -14,13 +14,13 @@ export type TestNode = Graph.Node.Any & {
|
|
|
14
14
|
|
|
15
15
|
export class TestGraphModel extends GraphModel.ReactiveGraphModel<TestNode> {
|
|
16
16
|
getRandomNode() {
|
|
17
|
-
return
|
|
17
|
+
return random.helpers.arrayElement(this._graph.nodes);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
createNodes(node: TestNode = undefined, n = 1): void {
|
|
21
21
|
Array.from({ length: n }).forEach(() => {
|
|
22
22
|
const child = this.addNode(createNode());
|
|
23
|
-
const parent = node ||
|
|
23
|
+
const parent = node || random.helpers.arrayElement(this._graph.nodes);
|
|
24
24
|
if (parent) {
|
|
25
25
|
this.addEdge(createEdge(parent, child));
|
|
26
26
|
}
|
package/styles/graph.css
CHANGED