@dxos/react-ui-graph 0.8.4-main.1068cf700f → 0.8.4-main.1c7ec43d41
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/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 +49 -110
- 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 +49 -110
- 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 +3 -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-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 +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 +25 -23
- package/src/components/Graph/Graph.tsx +15 -17
- package/src/components/Mesh/Mesh.stories.tsx +2 -3
- package/src/components/SVG/Root.tsx +14 -7
- 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-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 +4 -4
- 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 +292 -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.1c7ec43d41",
|
|
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/log": "0.8.4-main.
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
47
|
+
"@dxos/async": "0.8.4-main.1c7ec43d41",
|
|
48
|
+
"@dxos/graph": "0.8.4-main.1c7ec43d41",
|
|
49
|
+
"@dxos/node-std": "0.8.4-main.1c7ec43d41",
|
|
50
|
+
"@dxos/log": "0.8.4-main.1c7ec43d41",
|
|
51
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.1c7ec43d41",
|
|
52
|
+
"@dxos/debug": "0.8.4-main.1c7ec43d41",
|
|
53
|
+
"@dxos/invariant": "0.8.4-main.1c7ec43d41"
|
|
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-stack": "0.8.4-main.
|
|
76
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
77
|
-
"@dxos/ui-
|
|
78
|
-
"@dxos/
|
|
66
|
+
"@dxos/random": "0.8.4-main.1c7ec43d41",
|
|
67
|
+
"@dxos/react-ui": "0.8.4-main.1c7ec43d41",
|
|
68
|
+
"@dxos/react-ui-stack": "0.8.4-main.1c7ec43d41",
|
|
69
|
+
"@dxos/storybook-utils": "0.8.4-main.1c7ec43d41",
|
|
70
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.1c7ec43d41",
|
|
71
|
+
"@dxos/ui-theme": "0.8.4-main.1c7ec43d41"
|
|
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.1c7ec43d41",
|
|
77
|
+
"@dxos/ui-theme": "0.8.4-main.1c7ec43d41"
|
|
85
78
|
},
|
|
86
79
|
"optionalDependencies": {
|
|
87
|
-
"@dxos/random": "0.8.4-main.
|
|
80
|
+
"@dxos/random": "0.8.4-main.1c7ec43d41"
|
|
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';
|
|
@@ -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;
|
|
@@ -42,8 +42,8 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
42
42
|
{
|
|
43
43
|
classNames,
|
|
44
44
|
model,
|
|
45
|
-
projector:
|
|
46
|
-
renderer:
|
|
45
|
+
projector: projectorProp,
|
|
46
|
+
renderer: rendererProp,
|
|
47
47
|
drag,
|
|
48
48
|
arrows,
|
|
49
49
|
onSelect,
|
|
@@ -56,25 +56,25 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
56
56
|
const graphRef = useRef<SVGGElement>(null);
|
|
57
57
|
|
|
58
58
|
const { projector, renderer } = useMemo(() => {
|
|
59
|
-
let projector =
|
|
59
|
+
let projector = projectorProp;
|
|
60
60
|
if (!projector) {
|
|
61
61
|
projector = new GraphForceProjector<Node>(context);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
let renderer =
|
|
64
|
+
let renderer = rendererProp;
|
|
65
65
|
if (!renderer) {
|
|
66
66
|
renderer = new GraphRenderer<Node>(context, graphRef, {
|
|
67
67
|
...props,
|
|
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
|
|
|
76
76
|
return { projector, renderer };
|
|
77
|
-
}, [context,
|
|
77
|
+
}, [context, projectorProp, rendererProp, drag]);
|
|
78
78
|
|
|
79
79
|
// External API.
|
|
80
80
|
useImperativeHandle(
|
|
@@ -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
|
);
|
|
@@ -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
|
},
|
|
@@ -3,26 +3,33 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { select } from 'd3';
|
|
6
|
-
import React, {
|
|
6
|
+
import React, {
|
|
7
|
+
type ComponentPropsWithoutRef,
|
|
8
|
+
type PropsWithChildren,
|
|
9
|
+
forwardRef,
|
|
10
|
+
useEffect,
|
|
11
|
+
useImperativeHandle,
|
|
12
|
+
useMemo,
|
|
13
|
+
} from 'react';
|
|
7
14
|
import { useResizeDetector } from 'react-resize-detector';
|
|
8
15
|
|
|
9
16
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
10
|
-
import { mx } from '@dxos/ui-theme';
|
|
17
|
+
import { composableProps, mx } from '@dxos/ui-theme';
|
|
11
18
|
|
|
12
19
|
import { SVGContext, type SVGContextOptions, SVGContextProvider } from '../../hooks';
|
|
13
20
|
|
|
14
|
-
export type RootProps = ThemedClassName<PropsWithChildren<SVGContextOptions
|
|
21
|
+
export type RootProps = ThemedClassName<PropsWithChildren<SVGContextOptions & ComponentPropsWithoutRef<'div'>>>;
|
|
15
22
|
|
|
16
23
|
/**
|
|
17
24
|
* Makes the SVG context available to child nodes.
|
|
18
25
|
* Automatically resizes the SVG element, which expands to fit the container.
|
|
19
26
|
*/
|
|
20
|
-
export const Root = forwardRef<SVGContext, RootProps>(({
|
|
27
|
+
export const Root = forwardRef<SVGContext, RootProps>(({ children, scale, centered, ...props }, ref) => {
|
|
21
28
|
const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({ refreshRate: 200 });
|
|
22
29
|
|
|
23
30
|
const context = useMemo<SVGContext>(() => {
|
|
24
|
-
return new SVGContext(
|
|
25
|
-
}, [
|
|
31
|
+
return new SVGContext({ scale, centered });
|
|
32
|
+
}, [scale, centered]);
|
|
26
33
|
|
|
27
34
|
useImperativeHandle(ref, () => context, [context]);
|
|
28
35
|
|
|
@@ -41,7 +48,7 @@ export const Root = forwardRef<SVGContext, RootProps>(({ classNames, children, .
|
|
|
41
48
|
|
|
42
49
|
return (
|
|
43
50
|
<SVGContextProvider value={context}>
|
|
44
|
-
<div
|
|
51
|
+
<div {...composableProps(props, { classNames: 'dx-expander' })} ref={containerRef}>
|
|
45
52
|
<svg
|
|
46
53
|
xmlns='http://www.w3.org/2000/svg'
|
|
47
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
|
-
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
|
},
|
|
@@ -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';
|
|
@@ -10,7 +12,7 @@ import React, { type PropsWithChildren, useContext, useEffect, useMemo, useRef }
|
|
|
10
12
|
import { combine } from '@dxos/async';
|
|
11
13
|
import { type Graph } from '@dxos/graph';
|
|
12
14
|
import { log } from '@dxos/log';
|
|
13
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
15
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
14
16
|
import { withRegistry } from '@dxos/storybook-utils';
|
|
15
17
|
|
|
16
18
|
import { SVG } from '../components';
|
|
@@ -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;
|
|
@@ -158,7 +158,7 @@ const DefaultStory = ({ children, ...props }: ComponentProps) => {
|
|
|
158
158
|
const meta = {
|
|
159
159
|
title: 'ui/react-ui-graph/hooks',
|
|
160
160
|
render: DefaultStory,
|
|
161
|
-
decorators: [withRegistry, withTheme()],
|
|
161
|
+
decorators: [withRegistry, withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
162
162
|
parameters: {
|
|
163
163
|
layout: 'fullscreen',
|
|
164
164
|
},
|
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)) {
|