@dxos/react-ui-graph 0.8.4-main.f5c0578 → 0.8.4-main.fcfe5033a5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +5 -7
  2. package/dist/lib/browser/chunk-LKC455GK.mjs +52 -0
  3. package/dist/lib/browser/chunk-LKC455GK.mjs.map +7 -0
  4. package/dist/lib/browser/index.mjs +1089 -240
  5. package/dist/lib/browser/index.mjs.map +4 -4
  6. package/dist/lib/browser/meta.json +1 -1
  7. package/dist/lib/browser/testing/index.mjs +16 -16
  8. package/dist/lib/browser/testing/index.mjs.map +3 -3
  9. package/dist/lib/node-esm/chunk-JE4KZCUF.mjs +54 -0
  10. package/dist/lib/node-esm/chunk-JE4KZCUF.mjs.map +7 -0
  11. package/dist/lib/node-esm/index.mjs +1089 -240
  12. package/dist/lib/node-esm/index.mjs.map +4 -4
  13. package/dist/lib/node-esm/meta.json +1 -1
  14. package/dist/lib/node-esm/testing/index.mjs +16 -16
  15. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  16. package/dist/types/src/components/Graph/Graph.d.ts +4 -5
  17. package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
  18. package/dist/types/src/components/Graph/Graph.stories.d.ts +17 -8
  19. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
  20. package/dist/types/src/components/Mesh/Mesh.stories.d.ts +9 -5
  21. package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
  22. package/dist/types/src/components/SVG/Root.d.ts +4 -4
  23. package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
  24. package/dist/types/src/components/SVG/SVG.d.ts +14 -17
  25. package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
  26. package/dist/types/src/components/SVG/Svg.stories.d.ts +11 -9
  27. package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
  28. package/dist/types/src/fx/fx.stories.d.ts +16 -15
  29. package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
  30. package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
  31. package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
  32. package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
  33. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
  34. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
  35. package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
  36. package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
  37. package/dist/types/src/graph/projector/graph-radial-projector.d.ts +1 -1
  38. package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
  39. package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
  40. package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
  41. package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
  42. package/dist/types/src/graph/types.d.ts +1 -1
  43. package/dist/types/src/graph/types.d.ts.map +1 -1
  44. package/dist/types/src/stories/hooks.stories.d.ts +14 -9
  45. package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
  46. package/dist/types/src/testing/data.d.ts +4 -4
  47. package/dist/types/src/testing/data.d.ts.map +1 -1
  48. package/dist/types/src/testing/hooks.d.ts +2 -16
  49. package/dist/types/src/testing/hooks.d.ts.map +1 -1
  50. package/dist/types/src/testing/model.d.ts +4 -8
  51. package/dist/types/src/testing/model.d.ts.map +1 -1
  52. package/dist/types/src/util/fraction.d.ts +1 -1
  53. package/dist/types/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +31 -26
  55. package/src/components/Graph/Graph.stories.tsx +61 -56
  56. package/src/components/Graph/Graph.tsx +24 -16
  57. package/src/components/Mesh/Mesh.stories.tsx +9 -9
  58. package/src/components/SVG/Grid.tsx +1 -1
  59. package/src/components/SVG/Markers.tsx +1 -1
  60. package/src/components/SVG/Root.tsx +14 -7
  61. package/src/components/SVG/SVG.tsx +10 -2
  62. package/src/components/SVG/Svg.stories.tsx +22 -19
  63. package/src/fx/fx.stories.tsx +17 -15
  64. package/src/graph/projector/graph-drag.ts +0 -1
  65. package/src/graph/projector/graph-force-projector.ts +1 -2
  66. package/src/graph/projector/graph-hierarchical-projector.ts +3 -4
  67. package/src/graph/projector/graph-projector.ts +2 -3
  68. package/src/graph/projector/graph-radial-projector.ts +1 -2
  69. package/src/graph/projector/graph-relational-projector.ts +3 -4
  70. package/src/graph/renderer/graph-renderer.ts +0 -1
  71. package/src/graph/types.ts +1 -1
  72. package/src/hooks/useStateRef.ts +1 -1
  73. package/src/stories/hooks.stories.tsx +38 -31
  74. package/src/testing/data.ts +14 -14
  75. package/src/testing/hooks.ts +3 -4
  76. package/src/testing/model.ts +6 -6
  77. package/src/util/fraction.ts +1 -1
  78. package/styles/graph.css +292 -43
  79. package/dist/lib/browser/chunk-HLAKLUDC.mjs +0 -958
  80. package/dist/lib/browser/chunk-HLAKLUDC.mjs.map +0 -7
  81. package/dist/lib/node-esm/chunk-O6GWCXDC.mjs +0 -960
  82. package/dist/lib/node-esm/chunk-O6GWCXDC.mjs.map +0 -7
@@ -2,33 +2,30 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
5
+ import '../../styles/graph.css';
6
6
 
7
- import { type Meta } from '@storybook/react-vite';
7
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
8
  import { select } from 'd3';
9
9
  import React, { type FC, useEffect, useMemo, useRef } from 'react';
10
10
 
11
- import { withLayout, withTheme } from '@dxos/storybook-utils';
11
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
12
12
 
13
13
  import { SVG } from '../components';
14
14
  import { useGrid, useZoom } from '../hooks';
15
15
  import { type D3Callable } from '../util';
16
-
17
16
  import { Pulsar } from './pulsar';
18
17
 
19
- import '../../styles/graph.css';
20
-
21
18
  type Datum = {
22
19
  x: number;
23
20
  y: number;
24
21
  r: number;
25
22
  };
26
23
 
27
- type StoryProps = {
24
+ type DefaultStoryProps = {
28
25
  count: number;
29
26
  } & Pulsar.Options;
30
27
 
31
- const DefaultStory = (props: StoryProps) => {
28
+ const DefaultStory = (props: DefaultStoryProps) => {
32
29
  return (
33
30
  <SVG.Root>
34
31
  <StoryComponent {...props} />
@@ -36,7 +33,7 @@ const DefaultStory = (props: StoryProps) => {
36
33
  );
37
34
  };
38
35
 
39
- const StoryComponent: FC<StoryProps> = ({ count = 1, ...options }) => {
36
+ const StoryComponent: FC<DefaultStoryProps> = ({ count = 1, ...options }) => {
40
37
  const items = useMemo<Datum[]>(
41
38
  () =>
42
39
  Array.from({ length: count }, () => {
@@ -54,7 +51,7 @@ const StoryComponent: FC<StoryProps> = ({ count = 1, ...options }) => {
54
51
  const grid = useGrid({ axis: true, grid: false });
55
52
  const zoom = useZoom();
56
53
 
57
- const root = useRef<SVGGElement>();
54
+ const root = useRef<SVGGElement>(null);
58
55
  useEffect(() => {
59
56
  select(root.current)
60
57
  .selectAll('g')
@@ -93,21 +90,26 @@ const createNode: D3Callable<SVGGElement, Datum> = (group, classNames, options)
93
90
  });
94
91
  };
95
92
 
96
- const meta: Meta = {
93
+ const meta = {
97
94
  title: 'ui/react-ui-graph/fx',
98
95
  render: DefaultStory,
99
- decorators: [withTheme, withLayout({ fullscreen: true })],
100
- };
96
+ decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
97
+ parameters: {
98
+ layout: 'fullscreen',
99
+ },
100
+ } satisfies Meta<typeof DefaultStory>;
101
101
 
102
102
  export default meta;
103
103
 
104
- export const DefaultPulse = {
104
+ type Story = StoryObj<typeof meta>;
105
+
106
+ export const DefaultPulse: Story = {
105
107
  args: {
106
108
  count: 20,
107
109
  },
108
110
  };
109
111
 
110
- export const RapidPulse = {
112
+ export const RapidPulse: Story = {
111
113
  args: {
112
114
  count: 20,
113
115
  duration: 1_000,
@@ -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
 
@@ -223,7 +222,7 @@ export class GraphForceProjector<NodeData = any> extends GraphProjector<NodeData
223
222
  this.restart();
224
223
  }
225
224
 
226
- override onUpdate(graph?: Graph): void {
225
+ override onUpdate(graph?: Graph.Any): void {
227
226
  log('onUpdate', { graph: { nodes: graph?.nodes.length, edges: graph?.edges.length } });
228
227
  this._simulation.stop();
229
228
  this.mergeData(graph);
@@ -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
 
@@ -20,14 +19,14 @@ export class GraphHierarchicalProjector<
20
19
  NodeData = any,
21
20
  Options extends GraphHierarchicalProjectorOptions = any,
22
21
  > extends GraphRadialProjector<NodeData, Options> {
23
- protected override onUpdate(graph?: Graph) {
22
+ protected override onUpdate(graph?: Graph.Any) {
24
23
  log('onUpdate', {
25
24
  graph: { nodes: graph?.nodes.length, edges: graph?.edges.length },
26
- selection: this.selection?.selected.value,
25
+ selection: this.selection?.getSelectedIds(),
27
26
  });
28
27
 
29
28
  this.mergeData(graph);
30
- const selected = this.selection?.selected.value?.[0];
29
+ const selected = this.selection?.getSelectedIds()[0];
31
30
  if (selected) {
32
31
  const node = this.layout.graph.nodes.find((node) => node.id === selected);
33
32
  if (node) {
@@ -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 & {};
@@ -15,7 +14,7 @@ export type GraphProjectorOptions = ProjectorOptions & {};
15
14
  * Base class for graph projectors.
16
15
  */
17
16
  export abstract class GraphProjector<NodeData = any, Options extends GraphProjectorOptions = any> extends Projector<
18
- Graph,
17
+ Graph.Any,
19
18
  GraphLayout<NodeData>,
20
19
  Options
21
20
  > {
@@ -60,7 +59,7 @@ export abstract class GraphProjector<NodeData = any, Options extends GraphProjec
60
59
  * Merge external data with internal representation (e.g., so force properties like position are preserved).
61
60
  * @param data
62
61
  */
63
- protected mergeData(data: Graph = emptyGraph) {
62
+ protected mergeData(data: Graph.Any = emptyGraph) {
64
63
  // Merge nodes.
65
64
  const nodes: GraphLayoutNode[] = data.nodes.map((node) => {
66
65
  let current: GraphLayoutNode = this._layout.graph.nodes.find((n) => n.id === this.options.idAccessor(node));
@@ -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 & {
@@ -28,7 +27,7 @@ export class GraphRadialProjector<
28
27
  return undefined;
29
28
  }
30
29
 
31
- protected override onUpdate(graph?: Graph) {
30
+ protected override onUpdate(graph?: Graph.Any) {
32
31
  log('onUpdate', { graph: { nodes: graph?.nodes.length, edges: graph?.edges.length } });
33
32
  this.mergeData(graph);
34
33
  this.doRadialLayout();
@@ -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
 
@@ -20,14 +19,14 @@ export class GraphRelationalProjector<
20
19
  NodeData = any,
21
20
  Options extends GraphRelationalProjectorOptions = any,
22
21
  > extends GraphRadialProjector<NodeData, Options> {
23
- protected override onUpdate(graph?: Graph) {
22
+ protected override onUpdate(graph?: Graph.Any) {
24
23
  log('onUpdate', {
25
24
  graph: { nodes: graph?.nodes.length, edges: graph?.edges.length },
26
- selection: this.selection?.selected.value,
25
+ selection: this.selection?.getSelectedIds(),
27
26
  });
28
27
 
29
28
  this.mergeData(graph);
30
- const selected = this.selection?.selected.value?.[0];
29
+ const selected = this.selection?.getSelectedIds()[0];
31
30
  if (selected) {
32
31
  const node = this.layout.graph.nodes.find((node) => node.id === selected);
33
32
  if (node) {
@@ -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
 
@@ -19,7 +19,7 @@ export const defaultIdAccessor: IdAccessor = (node: any) => {
19
19
  return node.id;
20
20
  };
21
21
 
22
- export const emptyGraph: Graph = {
22
+ export const emptyGraph: Graph.Any = {
23
23
  nodes: [],
24
24
  edges: [],
25
25
  };
@@ -16,7 +16,7 @@ export const useStateRef = <V>(
16
16
  initialValue?: V | (() => V),
17
17
  ): [V | undefined, Dispatch<SetStateAction<V | undefined>>, RefObject<V | undefined>] => {
18
18
  const [value, setValue] = useState<V | undefined>(initialValue);
19
- const ref = useRef<V>();
19
+ const ref = useRef<V>(null);
20
20
  useEffect(() => {
21
21
  ref.current = value;
22
22
  }, [initialValue, value]);
@@ -2,15 +2,18 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
5
+ import '../../styles/graph.css';
6
6
 
7
- import { type StoryObj } from '@storybook/react-vite';
7
+ import { RegistryContext } from '@effect-atom/atom-react';
8
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
9
  import { select } from 'd3';
9
- import React, { type PropsWithChildren, useEffect, useMemo, useRef } from 'react';
10
+ import React, { type PropsWithChildren, useContext, useEffect, useMemo, useRef } from 'react';
10
11
 
11
12
  import { combine } from '@dxos/async';
13
+ import { type Graph } from '@dxos/graph';
12
14
  import { log } from '@dxos/log';
13
- import { type Meta, withLayout, withTheme } from '@dxos/storybook-utils';
15
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
16
+ import { withRegistry } from '@dxos/storybook-utils';
14
17
 
15
18
  import { SVG } from '../components';
16
19
  import {
@@ -26,10 +29,8 @@ import {
26
29
  import { useGrid, useSvgContext, useZoom } from '../hooks';
27
30
  import { TestGraphModel, type TestNode, convertTreeToGraph, createTree } from '../testing';
28
31
 
29
- import '../../styles/graph.css';
30
-
31
- type StoryProps = PropsWithChildren<{
32
- model: TestGraphModel;
32
+ type ComponentProps = PropsWithChildren<{
33
+ graph: () => Graph.Graph<TestNode, Graph.Edge.Any>;
33
34
  projectorOptions?: GraphForceProjectorOptions;
34
35
  count?: number;
35
36
  interval?: number;
@@ -37,28 +38,20 @@ type StoryProps = PropsWithChildren<{
37
38
  grid?: boolean;
38
39
  }>;
39
40
 
40
- const DefaultStory = ({ children, ...props }: StoryProps) => {
41
- return (
42
- <>
43
- <SVG.Root>
44
- <StoryComponent {...props} />
45
- </SVG.Root>
46
- {children && <div className='absolute left-4 bottom-4 font-mono text-green-500 text-xs'>{children}</div>}
47
- </>
48
- );
49
- };
50
-
51
- const StoryComponent = ({
52
- model,
41
+ const Component = ({
42
+ graph: graphFactory,
53
43
  projectorOptions,
54
44
  count = 0,
55
45
  interval = 200,
56
46
  link = false,
57
47
  grid: showGrid = false,
58
- }: StoryProps) => {
48
+ }: ComponentProps) => {
49
+ const registry = useContext(RegistryContext);
50
+ const model = useMemo(() => new TestGraphModel(registry, graphFactory()), [registry, graphFactory]);
51
+
59
52
  const context = useSvgContext();
60
- const graphRef = useRef<SVGGElement>();
61
- const markersRef = useRef<SVGGElement>();
53
+ const graphRef = useRef<SVGGElement>(null);
54
+ const markersRef = useRef<SVGGElement>(null);
62
55
  const grid = useGrid({ visible: showGrid });
63
56
  const zoom = useZoom();
64
57
 
@@ -94,7 +87,7 @@ const StoryComponent = ({
94
87
  labels: {
95
88
  text: (node: GraphLayoutNode<TestNode>) => node.id.substring(0, 4),
96
89
  },
97
- onNodeClick: (node: GraphLayoutNode<TestNode>, event: MouseEvent) => {
90
+ onNodeClick: (node: GraphLayoutNode<TestNode>) => {
98
91
  renderer.fireBullet(node);
99
92
  },
100
93
  onLinkClick: (edge: GraphLayoutEdge<TestNode>, event: MouseEvent) => {
@@ -151,19 +144,33 @@ const StoryComponent = ({
151
144
  );
152
145
  };
153
146
 
154
- const meta: Meta = {
147
+ const DefaultStory = ({ children, ...props }: ComponentProps) => {
148
+ return (
149
+ <>
150
+ <SVG.Root>
151
+ <Component {...props} />
152
+ </SVG.Root>
153
+ {children && <div className='absolute left-4 bottom-4 font-mono text-green-500 text-xs'>{children}</div>}
154
+ </>
155
+ );
156
+ };
157
+
158
+ const meta = {
155
159
  title: 'ui/react-ui-graph/hooks',
156
160
  render: DefaultStory,
157
- decorators: [withTheme, withLayout({ fullscreen: true })],
158
- };
161
+ decorators: [withRegistry, withTheme(), withLayout({ layout: 'fullscreen' })],
162
+ parameters: {
163
+ layout: 'fullscreen',
164
+ },
165
+ } satisfies Meta<typeof DefaultStory>;
159
166
 
160
167
  export default meta;
161
168
 
162
- type Story = StoryObj<typeof DefaultStory>;
169
+ type Story = StoryObj<typeof meta>;
163
170
 
164
171
  export const Default: Story = {
165
172
  args: {
166
- model: new TestGraphModel(convertTreeToGraph(createTree({ depth: 3 }))),
173
+ graph: () => convertTreeToGraph(createTree({ depth: 3 })),
167
174
  grid: true,
168
175
  count: 300,
169
176
  interval: 20,
@@ -188,7 +195,7 @@ export const Default: Story = {
188
195
 
189
196
  export const Bullets: Story = {
190
197
  args: {
191
- model: new TestGraphModel(convertTreeToGraph(createTree({ depth: 4 }))),
198
+ graph: () => convertTreeToGraph(createTree({ depth: 4 })),
192
199
  children: <span>⌘-DRAG to edge or create node; ⌘-CLICK to delete edge.</span>,
193
200
  link: true,
194
201
  grid: false,
@@ -2,28 +2,28 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { type BaseGraphEdge, type Graph } from '@dxos/graph';
6
- import { faker } from '@dxos/random';
5
+ import { type Graph } from '@dxos/graph';
6
+ import { random } from '@dxos/random';
7
7
 
8
8
  import { type TestNode } from './model';
9
9
 
10
- // https://www.npmjs.com/package/faker#setting-a-randomness-seed
11
- export const seed = (seed: number) => faker.seed(seed);
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: faker.string.uuid(),
18
+ id: random.string.uuid(),
19
19
  type,
20
- label: faker.lorem.words(3).replace(/ /g, '-'),
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 ? faker.helpers.arrayElement(types) : undefined));
24
+ Array.from({ length: n }, () => createNode(types ? random.helpers.arrayElement(types) : undefined));
25
25
 
26
- export const createEdge = (source: TestNode, target: TestNode): BaseGraphEdge => ({
26
+ export const createEdge = (source: TestNode, target: TestNode): Graph.Edge.Any => ({
27
27
  id: `${source.id}-${target.id}`,
28
28
  source: source.id,
29
29
  target: 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 = faker.number.int({ min: 1, max });
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
  });
@@ -54,8 +54,8 @@ export const createTree = ({ depth = 2, children = 3 } = {}): TestNode => {
54
54
  * Converts a tree into a graph.
55
55
  * @param root
56
56
  */
57
- export const convertTreeToGraph = (root: TestNode): Graph => {
58
- const traverse = (node: TestNode, graph: Graph) => {
57
+ export const convertTreeToGraph = (root: TestNode): Graph.Any => {
58
+ const traverse = (node: TestNode, graph: Graph.Any) => {
59
59
  graph.nodes.push(node);
60
60
  node.children?.forEach((child) => {
61
61
  graph.edges.push(createEdge(node, child));
@@ -76,14 +76,14 @@ export const convertTreeToGraph = (root: TestNode): Graph => {
76
76
  * @param numNodes
77
77
  * @param numEdges
78
78
  */
79
- export const createGraph = (numNodes = 0, numEdges = 0, types?: string[]): Graph => {
79
+ export const createGraph = (numNodes = 0, numEdges = 0, types?: string[]): Graph.Any => {
80
80
  const nodes = createNodes(numNodes, types);
81
81
 
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 = faker.helpers.arrayElement(nodes);
86
- const target = faker.helpers.arrayElement(nodes);
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)) {
@@ -5,10 +5,9 @@
5
5
  import update from 'immutability-helper';
6
6
 
7
7
  import { type Graph } from '@dxos/graph';
8
- import { faker } from '@dxos/random';
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
 
@@ -47,13 +46,13 @@ export const useObjectMutator = <T>(initalValue: T): ObjectMutator<T> => {
47
46
  /**
48
47
  * Test data set generator and mutator.
49
48
  */
50
- export const useGraphGenerator = (options: { data?: Graph } = {}) => {
49
+ export const useGraphGenerator = (options: { data?: Graph.Any } = {}) => {
51
50
  const [data, setData, updateData] = useObjectMutator(options.data || { nodes: [], edges: [] });
52
51
 
53
52
  let interval;
54
53
 
55
54
  const mutator = () => {
56
- const parent = data.nodes.length ? faker.helpers.arrayElement(data.nodes) : undefined;
55
+ const parent = data.nodes.length ? random.helpers.arrayElement(data.nodes) : undefined;
57
56
  const node = createNode();
58
57
 
59
58
  updateData({
@@ -2,25 +2,25 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { type BaseGraphNode, ReactiveGraphModel } from '@dxos/graph';
6
- import { faker } from '@dxos/random';
5
+ import { type Graph, GraphModel } from '@dxos/graph';
6
+ import { random } from '@dxos/random';
7
7
 
8
8
  import { createEdge, createNode } from './data';
9
9
 
10
- export type TestNode = BaseGraphNode & {
10
+ export type TestNode = Graph.Node.Any & {
11
11
  label?: string;
12
12
  children?: TestNode[];
13
13
  };
14
14
 
15
- export class TestGraphModel extends ReactiveGraphModel<TestNode> {
15
+ export class TestGraphModel extends GraphModel.ReactiveGraphModel<TestNode> {
16
16
  getRandomNode() {
17
- return faker.helpers.arrayElement(this._graph.nodes);
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 || faker.helpers.arrayElement(this._graph.nodes);
23
+ const parent = node || random.helpers.arrayElement(this._graph.nodes);
24
24
  if (parent) {
25
25
  this.addEdge(createEdge(parent, child));
26
26
  }
@@ -30,7 +30,7 @@ export class FractionUtil {
30
30
 
31
31
  /**
32
32
  * @param {Fraction}
33
- * Convert to rounded number.
33
+ * Convert to rounded-sm number.
34
34
  */
35
35
  static toNumber = ([n, d]: Fraction): number => {
36
36
  FractionUtil.validate([n, d]);