@dxos/react-ui-graph 0.8.4-main.9735255 → 0.8.4-main.9be5663bfe
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/index.mjs +28 -23
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +13 -13
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/index.mjs +28 -23
- 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 +13 -13
- 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 +3 -3
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.stories.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/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-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/renderer/graph-renderer.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.map +1 -1
- package/dist/types/src/testing/hooks.d.ts.map +1 -1
- package/dist/types/src/util/fraction.d.ts +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -18
- package/src/components/Graph/Graph.stories.tsx +18 -14
- package/src/components/Graph/Graph.tsx +14 -13
- 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 +0 -1
- 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.9be5663bfe",
|
|
4
4
|
"description": "GEM Graph.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"styles"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@effect-atom/atom-react": "^0.
|
|
46
|
+
"@effect-atom/atom-react": "^0.5.0",
|
|
47
47
|
"d3": "^7.9.0",
|
|
48
48
|
"d3-force": "~3.0.0",
|
|
49
49
|
"immutability-helper": "^3.0.2",
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
"lodash.defaultsdeep": "^4.6.1",
|
|
52
52
|
"react-resize-detector": "^11.0.1",
|
|
53
53
|
"topojson-client": "^3.1.0",
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
54
|
+
"@dxos/debug": "0.8.4-main.9be5663bfe",
|
|
55
|
+
"@dxos/async": "0.8.4-main.9be5663bfe",
|
|
56
|
+
"@dxos/graph": "0.8.4-main.9be5663bfe",
|
|
57
|
+
"@dxos/invariant": "0.8.4-main.9be5663bfe",
|
|
58
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.9be5663bfe",
|
|
59
|
+
"@dxos/node-std": "0.8.4-main.9be5663bfe",
|
|
60
|
+
"@dxos/log": "0.8.4-main.9be5663bfe"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@babel/core": "^7.18.13",
|
|
@@ -70,21 +70,21 @@
|
|
|
70
70
|
"postcss": "^8.4.41",
|
|
71
71
|
"react": "~19.2.3",
|
|
72
72
|
"react-dom": "~19.2.3",
|
|
73
|
-
"@dxos/random": "0.8.4-main.
|
|
74
|
-
"@dxos/
|
|
75
|
-
"@dxos/react-ui
|
|
76
|
-
"@dxos/
|
|
77
|
-
"@dxos/
|
|
78
|
-
"@dxos/ui-
|
|
73
|
+
"@dxos/random": "0.8.4-main.9be5663bfe",
|
|
74
|
+
"@dxos/storybook-utils": "0.8.4-main.9be5663bfe",
|
|
75
|
+
"@dxos/react-ui": "0.8.4-main.9be5663bfe",
|
|
76
|
+
"@dxos/ui-theme": "0.8.4-main.9be5663bfe",
|
|
77
|
+
"@dxos/react-ui-stack": "0.8.4-main.9be5663bfe",
|
|
78
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.9be5663bfe"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"react": "~19.2.3",
|
|
82
82
|
"react-dom": "~19.2.3",
|
|
83
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
84
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
83
|
+
"@dxos/react-ui": "0.8.4-main.9be5663bfe",
|
|
84
|
+
"@dxos/ui-theme": "0.8.4-main.9be5663bfe"
|
|
85
85
|
},
|
|
86
86
|
"optionalDependencies": {
|
|
87
|
-
"@dxos/random": "0.8.4-main.
|
|
87
|
+
"@dxos/random": "0.8.4-main.9be5663bfe"
|
|
88
88
|
},
|
|
89
89
|
"publishConfig": {
|
|
90
90
|
"access": "public"
|
|
@@ -2,6 +2,8 @@
|
|
|
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';
|
|
@@ -9,9 +11,9 @@ import React, { useCallback, useContext, useEffect, useMemo, useRef, useState }
|
|
|
9
11
|
|
|
10
12
|
import { type Graph, type GraphModel, 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 { Json, SyntaxHighlighter } 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,7 +49,7 @@ 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;
|
|
@@ -73,13 +72,13 @@ const DefaultStory = ({
|
|
|
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 [model, setModel] = useState<GraphModel.
|
|
81
|
+
const [model, setModel] = useState<GraphModel.ReactiveGraphModel | undefined>(() => {
|
|
83
82
|
const graph = _graph?.();
|
|
84
83
|
return graph ? new TestGraphModel(registry, graph) : undefined;
|
|
85
84
|
});
|
|
@@ -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)} />}
|
|
@@ -263,7 +262,7 @@ const DefaultStory = ({
|
|
|
263
262
|
<Card.Root>
|
|
264
263
|
<SyntaxHighlighter
|
|
265
264
|
language='json'
|
|
266
|
-
classNames='text-xs
|
|
265
|
+
classNames='text-xs my-form-padding px-form-padding bg-transparent'
|
|
267
266
|
code={JSON.stringify(popover, null, 2)}
|
|
268
267
|
/>
|
|
269
268
|
</Card.Root>
|
|
@@ -287,7 +286,7 @@ const Debug = ({
|
|
|
287
286
|
onDelete,
|
|
288
287
|
onPing,
|
|
289
288
|
}: {
|
|
290
|
-
model?: GraphModel.
|
|
289
|
+
model?: GraphModel.ReactiveGraphModel;
|
|
291
290
|
selection: SelectionModel;
|
|
292
291
|
projector: ProjectorType;
|
|
293
292
|
onToggleProjector: () => void;
|
|
@@ -320,7 +319,12 @@ const Debug = ({
|
|
|
320
319
|
<IconButton onClick={onDelete} label='Delete' icon='ph--x--regular' iconOnly />
|
|
321
320
|
<IconButton onClick={onPing} label='Delete' icon='ph--crosshair-simple--regular' iconOnly />
|
|
322
321
|
</Toolbar.Root>
|
|
323
|
-
<
|
|
322
|
+
<Json.Root data={data}>
|
|
323
|
+
<Json.Content>
|
|
324
|
+
<Json.Filter />
|
|
325
|
+
<Json.Data classNames='text-sm' />
|
|
326
|
+
</Json.Content>
|
|
327
|
+
</Json.Root>
|
|
324
328
|
</div>
|
|
325
329
|
);
|
|
326
330
|
};
|
|
@@ -328,7 +332,7 @@ const Debug = ({
|
|
|
328
332
|
const meta = {
|
|
329
333
|
title: 'ui/react-ui-graph/Graph',
|
|
330
334
|
render: DefaultStory,
|
|
331
|
-
decorators: [withRegistry, withTheme],
|
|
335
|
+
decorators: [withRegistry, withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
332
336
|
parameters: {
|
|
333
337
|
layout: 'fullscreen',
|
|
334
338
|
controls: { disable: true },
|
|
@@ -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,
|
|
@@ -54,14 +54,16 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
54
54
|
) => {
|
|
55
55
|
const context = useSvgContext();
|
|
56
56
|
const graphRef = useRef<SVGGElement>(null);
|
|
57
|
+
// TODO(wittjosiah): This doesn't work for some reason.
|
|
58
|
+
// const graph = useAtomValue(model?.graphAtom ?? EMPTY_ATOM);
|
|
57
59
|
|
|
58
60
|
const { projector, renderer } = useMemo(() => {
|
|
59
|
-
let projector =
|
|
61
|
+
let projector = projectorProp;
|
|
60
62
|
if (!projector) {
|
|
61
63
|
projector = new GraphForceProjector<Node>(context);
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
let renderer =
|
|
66
|
+
let renderer = rendererProp;
|
|
65
67
|
if (!renderer) {
|
|
66
68
|
renderer = new GraphRenderer<Node>(context, graphRef, {
|
|
67
69
|
...props,
|
|
@@ -74,7 +76,7 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
return { projector, renderer };
|
|
77
|
-
}, [context,
|
|
79
|
+
}, [context, projectorProp, rendererProp, drag]);
|
|
78
80
|
|
|
79
81
|
// External API.
|
|
80
82
|
useImperativeHandle(
|
|
@@ -98,12 +100,11 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
|
|
|
98
100
|
projector.updateData(model?.graph);
|
|
99
101
|
|
|
100
102
|
// Subscribe to model changes if reactive model.
|
|
101
|
-
const unsubscribeModel =
|
|
102
|
-
model
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
: undefined;
|
|
103
|
+
const unsubscribeModel = model
|
|
104
|
+
? model.subscribe(() => {
|
|
105
|
+
projector.updateData(model?.graph);
|
|
106
|
+
})
|
|
107
|
+
: undefined;
|
|
107
108
|
|
|
108
109
|
return combine(
|
|
109
110
|
unsubscribeModel,
|
|
@@ -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
|
|
|
@@ -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)) {
|
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
|
}
|