@dxos/react-ui-graph 0.8.4-main.b97322e → 0.8.4-main.bc2380dfbc

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 (118) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +5 -7
  3. package/dist/lib/browser/chunk-EASNZZ7B.mjs +52 -0
  4. package/dist/lib/browser/chunk-EASNZZ7B.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +1129 -298
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +16 -16
  9. package/dist/lib/browser/testing/index.mjs.map +3 -3
  10. package/dist/lib/node-esm/chunk-JSE2X4ML.mjs +54 -0
  11. package/dist/lib/node-esm/chunk-JSE2X4ML.mjs.map +7 -0
  12. package/dist/lib/node-esm/index.mjs +1129 -298
  13. package/dist/lib/node-esm/index.mjs.map +4 -4
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/lib/node-esm/testing/index.mjs +16 -16
  16. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  17. package/dist/types/src/components/Graph/Graph.d.ts +4 -5
  18. package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
  19. package/dist/types/src/components/Graph/Graph.stories.d.ts +20 -11
  20. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
  21. package/dist/types/src/components/Mesh/Mesh.d.ts.map +1 -1
  22. package/dist/types/src/components/Mesh/Mesh.stories.d.ts +9 -5
  23. package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
  24. package/dist/types/src/components/SVG/Grid.d.ts.map +1 -1
  25. package/dist/types/src/components/SVG/Markers.d.ts.map +1 -1
  26. package/dist/types/src/components/SVG/Root.d.ts +8 -4
  27. package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
  28. package/dist/types/src/components/SVG/SVG.d.ts +14 -17
  29. package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
  30. package/dist/types/src/components/SVG/Svg.stories.d.ts +11 -9
  31. package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
  32. package/dist/types/src/components/SVG/Zoom.d.ts.map +1 -1
  33. package/dist/types/src/fx/fx.stories.d.ts +16 -15
  34. package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
  35. package/dist/types/src/fx/pulsar.d.ts.map +1 -1
  36. package/dist/types/src/graph/markers.d.ts.map +1 -1
  37. package/dist/types/src/graph/projector/graph-drag.d.ts +1 -1
  38. package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
  39. package/dist/types/src/graph/projector/graph-force-projector.d.ts +2 -2
  40. package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
  41. package/dist/types/src/graph/projector/graph-forces.d.ts.map +1 -1
  42. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +2 -2
  43. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
  44. package/dist/types/src/graph/projector/graph-projector.d.ts +4 -4
  45. package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
  46. package/dist/types/src/graph/projector/graph-radial-projector.d.ts +2 -2
  47. package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
  48. package/dist/types/src/graph/projector/graph-relational-projector.d.ts +2 -2
  49. package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
  50. package/dist/types/src/graph/projector/projector.d.ts.map +1 -1
  51. package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
  52. package/dist/types/src/graph/renderer/graph-renderer.d.ts +1 -1
  53. package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
  54. package/dist/types/src/graph/renderer/renderer.d.ts +6 -1
  55. package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
  56. package/dist/types/src/graph/types.d.ts +1 -1
  57. package/dist/types/src/graph/types.d.ts.map +1 -1
  58. package/dist/types/src/hooks/useGrid.d.ts.map +1 -1
  59. package/dist/types/src/hooks/useStateRef.d.ts.map +1 -1
  60. package/dist/types/src/hooks/useSvgContext.d.ts.map +1 -1
  61. package/dist/types/src/hooks/useZoom.d.ts.map +1 -1
  62. package/dist/types/src/stories/hooks.stories.d.ts +14 -9
  63. package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
  64. package/dist/types/src/testing/data.d.ts +5 -5
  65. package/dist/types/src/testing/data.d.ts.map +1 -1
  66. package/dist/types/src/testing/hooks.d.ts +2 -16
  67. package/dist/types/src/testing/hooks.d.ts.map +1 -1
  68. package/dist/types/src/testing/model.d.ts +4 -8
  69. package/dist/types/src/testing/model.d.ts.map +1 -1
  70. package/dist/types/src/util/events.d.ts.map +1 -1
  71. package/dist/types/src/util/fraction.d.ts +1 -1
  72. package/dist/types/src/util/fraction.d.ts.map +1 -1
  73. package/dist/types/src/util/points.d.ts.map +1 -1
  74. package/dist/types/src/util/scale.d.ts.map +1 -1
  75. package/dist/types/src/util/screen.d.ts +1 -1
  76. package/dist/types/src/util/screen.d.ts.map +1 -1
  77. package/dist/types/src/util/vector.d.ts +1 -1
  78. package/dist/types/src/util/vector.d.ts.map +1 -1
  79. package/dist/types/tsconfig.tsbuildinfo +1 -1
  80. package/package.json +33 -35
  81. package/src/components/Graph/Graph.stories.tsx +73 -69
  82. package/src/components/Graph/Graph.tsx +25 -20
  83. package/src/components/Mesh/Mesh.stories.tsx +16 -13
  84. package/src/components/Mesh/Mesh.tsx +44 -36
  85. package/src/components/SVG/Grid.tsx +2 -2
  86. package/src/components/SVG/Markers.tsx +1 -1
  87. package/src/components/SVG/Root.tsx +41 -9
  88. package/src/components/SVG/SVG.tsx +13 -4
  89. package/src/components/SVG/Svg.stories.tsx +23 -19
  90. package/src/components/SVG/Zoom.tsx +1 -1
  91. package/src/fx/fx.stories.tsx +18 -15
  92. package/src/graph/projector/graph-drag.ts +1 -1
  93. package/src/graph/projector/graph-force-projector.ts +2 -2
  94. package/src/graph/projector/graph-forces.ts +1 -1
  95. package/src/graph/projector/graph-hierarchical-projector.ts +4 -4
  96. package/src/graph/projector/graph-projector.ts +5 -5
  97. package/src/graph/projector/graph-radial-projector.ts +3 -3
  98. package/src/graph/projector/graph-relational-projector.ts +4 -4
  99. package/src/graph/projector/projector.ts +1 -1
  100. package/src/graph/renderer/bullets.ts +1 -1
  101. package/src/graph/renderer/graph-renderer.ts +16 -7
  102. package/src/graph/renderer/renderer.ts +7 -5
  103. package/src/graph/types.ts +1 -1
  104. package/src/hooks/useStateRef.ts +1 -1
  105. package/src/hooks/useZoom.ts +1 -1
  106. package/src/stories/hooks.stories.tsx +49 -37
  107. package/src/testing/data.ts +14 -14
  108. package/src/testing/hooks.ts +5 -5
  109. package/src/testing/model.ts +6 -6
  110. package/src/util/fraction.ts +1 -1
  111. package/src/util/screen.test.ts +1 -1
  112. package/src/util/screen.ts +1 -1
  113. package/src/util/vector.ts +1 -1
  114. package/styles/graph.css +292 -43
  115. package/dist/lib/browser/chunk-MGVY54T5.mjs +0 -979
  116. package/dist/lib/browser/chunk-MGVY54T5.mjs.map +0 -7
  117. package/dist/lib/node-esm/chunk-X5YVOSXZ.mjs +0 -981
  118. package/dist/lib/node-esm/chunk-X5YVOSXZ.mjs.map +0 -7
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { geoPath, select, type GeoStream } from 'd3';
5
+ import { type GeoStream, geoPath, select } from 'd3';
6
6
  import { useEffect } from 'react';
7
7
  import { feature, mesh } from 'topojson-client';
8
8
  import { type GeometryCollection, type GeometryObject, type Objects, type Topology } from 'topojson-specification';
@@ -20,43 +20,51 @@ export const Mesh = ({ radius = 16, value = 0.5 }: MeshProps) => {
20
20
  const { svg, size } = useSvgContext();
21
21
 
22
22
  useEffect(() => {
23
- if (size) {
24
- // TODO(burdon): Resize doesn't trigger.
25
- const topology = hexTopology(size, radius, value);
26
- const projection = hexProjection(radius);
27
- const path = geoPath().projection(projection);
28
-
29
- select(svg)
30
- .append('g')
31
- .attr('class', 'hexagon')
32
- .selectAll('path')
33
- .data(topology.objects.hexagons.geometries)
34
- .enter()
35
- .append('path')
36
- .attr('d', (d) => path(feature(topology, d)))
37
- .attr('class', (d) => ((d.properties as Custom)?.fill ? 'fill' : null));
38
- // .on('mousedown', mousedown)
39
- // .on('mousemove', mousemove)
40
- // .on('mouseup', mouseup);
41
-
42
- select(svg).append('path').datum(mesh(topology, topology.objects.hexagons)).attr('class', 'mesh').attr('d', path);
43
-
44
- const redraw = (border: any) => {
45
- border.attr(
46
- 'd',
47
- path(
48
- mesh(
49
- topology,
50
- topology.objects.hexagons,
51
- (a, b) => (a.properties as Custom).fill !== (b.properties as Custom).fill,
52
- ),
23
+ if (!size) {
24
+ return;
25
+ }
26
+
27
+ const topology = hexTopology(size, radius, value);
28
+ const projection = hexProjection(radius);
29
+ const path = geoPath().projection(projection);
30
+
31
+ // Replace the previous render: idempotent join on a single keyed root group, then
32
+ // recreate the inner layers. Without this the effect re-runs (e.g. animating `value`
33
+ // or on resize) appended new groups on top of the old ones instead of replacing them.
34
+ const root = select(svg)
35
+ .selectAll<SVGGElement, null>('g.dx-mesh-root')
36
+ .data([null])
37
+ .join('g')
38
+ .classed('dx-mesh-root', true);
39
+ root.selectAll('*').remove();
40
+
41
+ root
42
+ .append('g')
43
+ .attr('class', 'hexagon')
44
+ .selectAll('path')
45
+ .data(topology.objects.hexagons.geometries)
46
+ .enter()
47
+ .append('path')
48
+ .attr('d', (d) => path(feature(topology, d)))
49
+ .attr('class', (d) => ((d.properties as Custom)?.fill ? 'fill' : null));
50
+
51
+ root.append('path').datum(mesh(topology, topology.objects.hexagons)).attr('class', 'mesh').attr('d', path);
52
+
53
+ const redraw = (border: any) => {
54
+ border.attr(
55
+ 'd',
56
+ path(
57
+ mesh(
58
+ topology,
59
+ topology.objects.hexagons,
60
+ (a, b) => (a.properties as Custom).fill !== (b.properties as Custom).fill,
53
61
  ),
54
- );
55
- };
62
+ ),
63
+ );
64
+ };
56
65
 
57
- select(svg).append('path').attr('class', 'border').call(redraw);
58
- }
59
- }, [svg, size, value]);
66
+ root.append('path').attr('class', 'border').call(redraw);
67
+ }, [svg, size, value, radius]);
60
68
 
61
69
  return null;
62
70
  };
@@ -5,9 +5,9 @@
5
5
  import React from 'react';
6
6
 
7
7
  import { type ThemedClassName } from '@dxos/react-ui';
8
- import { mx } from '@dxos/react-ui-theme';
8
+ import { mx } from '@dxos/ui-theme';
9
9
 
10
- import { useGrid, type GridOptions } from '../../hooks';
10
+ import { type GridOptions, useGrid } from '../../hooks';
11
11
 
12
12
  export type GridProps = ThemedClassName<GridOptions>;
13
13
 
@@ -16,7 +16,7 @@ export type MarkersProps = {
16
16
  * SVG markers wrapper.
17
17
  */
18
18
  export const Markers = ({ arrowSize, className }: MarkersProps) => {
19
- const ref = useRef();
19
+ const ref = useRef(null);
20
20
  useEffect(() => {
21
21
  select(ref.current).call(createMarkers({ arrowSize }));
22
22
  }, [ref]);
@@ -3,26 +3,58 @@
3
3
  //
4
4
 
5
5
  import { select } from 'd3';
6
- import React, { forwardRef, type PropsWithChildren, useEffect, useMemo, useImperativeHandle } from 'react';
7
- import { useResizeDetector } from 'react-resize-detector';
6
+ import React, {
7
+ type ComponentPropsWithoutRef,
8
+ type PropsWithChildren,
9
+ forwardRef,
10
+ useEffect,
11
+ useImperativeHandle,
12
+ useMemo,
13
+ useState,
14
+ } from 'react';
8
15
 
9
16
  import { type ThemedClassName } from '@dxos/react-ui';
10
- import { mx } from '@dxos/react-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.
26
+ *
27
+ * NOTE: Uses `ResizeObserver` directly rather than `react-resize-detector` — the latter's
28
+ * `useResizeDetector` was flaky in our Storybook environment (sometimes never fired its
29
+ * initial measurement), leaving the SVG stuck at `opacity-0` with no rendered content.
19
30
  */
20
- export const Root = forwardRef<SVGContext, RootProps>(({ classNames, children, ...props }, ref) => {
21
- const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({ refreshRate: 200 });
31
+ export const Root = forwardRef<SVGContext, RootProps>(({ children, scale, centered, ...props }, ref) => {
32
+ const [container, setContainer] = useState<HTMLDivElement | null>(null);
33
+ const [size, setSize] = useState<{ width: number; height: number }>({ width: 0, height: 0 });
34
+
35
+ useEffect(() => {
36
+ if (!container) {
37
+ return;
38
+ }
39
+ const rect = container.getBoundingClientRect();
40
+ setSize({ width: rect.width, height: rect.height });
41
+ const observer = new ResizeObserver((entries) => {
42
+ const entry = entries[0];
43
+ if (!entry) {
44
+ return;
45
+ }
46
+ const { width, height } = entry.contentRect;
47
+ setSize((prev) => (prev.width === width && prev.height === height ? prev : { width, height }));
48
+ });
49
+ observer.observe(container);
50
+ return () => observer.disconnect();
51
+ }, [container]);
52
+
53
+ const { width, height } = size;
22
54
 
23
55
  const context = useMemo<SVGContext>(() => {
24
- return new SVGContext(props);
25
- }, [props.scale, props.centered]);
56
+ return new SVGContext({ scale, centered });
57
+ }, [scale, centered]);
26
58
 
27
59
  useImperativeHandle(ref, () => context, [context]);
28
60
 
@@ -41,7 +73,7 @@ export const Root = forwardRef<SVGContext, RootProps>(({ classNames, children, .
41
73
 
42
74
  return (
43
75
  <SVGContextProvider value={context}>
44
- <div ref={containerRef} className={mx('grid grow overflow-hidden', classNames)}>
76
+ <div {...composableProps(props, { classNames: 'dx-expander' })} ref={setContainer}>
45
77
  <svg
46
78
  xmlns='http://www.w3.org/2000/svg'
47
79
  ref={context.ref}
@@ -6,16 +6,25 @@ import { type PropsWithChildren } from 'react';
6
6
 
7
7
  import { type ThemedClassName } from '@dxos/react-ui';
8
8
 
9
+ import { Graph, type GraphProps as SVGGraphProps } from '../Graph';
10
+ import { Mesh, type MeshProps as SVGMeshProps } from '../Mesh';
9
11
  import { Grid, type GridProps as SVGGridProps } from './Grid';
10
12
  import { Markers, type MarkersProps as SVGMarkersProps } from './Markers';
11
13
  import { Root, type RootProps as SVGRootProps } from './Root';
12
- import { Zoom, type ZoomProps as SVGZoomProps } from './Zoom';
13
- import { Graph, type GraphProps as SVGGraphProps } from '../Graph';
14
- import { Mesh, type MeshProps as SVGMeshProps } from '../Mesh';
14
+ import { type ZoomProps as SVGZoomProps, Zoom } from './Zoom';
15
15
 
16
16
  export type SVGProps = PropsWithChildren<ThemedClassName>;
17
17
 
18
- export const SVG = {
18
+ type SVG = {
19
+ Root: typeof Root;
20
+ Grid: typeof Grid;
21
+ Markers: typeof Markers;
22
+ Mesh: typeof Mesh;
23
+ Zoom: typeof Zoom;
24
+ Graph: typeof Graph;
25
+ };
26
+
27
+ export const SVG: SVG = {
19
28
  Root,
20
29
  Grid,
21
30
  Markers,
@@ -2,32 +2,21 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
5
+ import '../../../styles/graph.css';
6
6
 
7
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
7
8
  import React, { useRef } from 'react';
8
9
 
9
- import { type Meta, withLayout, withTheme } from '@dxos/storybook-utils';
10
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
10
11
 
12
+ import { type SVGContext, useGrid, useZoom } from '../../hooks';
11
13
  import { SVG } from './SVG';
12
- import { useGrid, useZoom, type SVGContext } from '../../hooks';
13
-
14
- import '../../../styles/graph.css';
15
14
 
16
15
  type ComponentProps = {
17
16
  grid?: boolean;
18
17
  zoom?: boolean;
19
18
  };
20
19
 
21
- const DefaultStory = (props: ComponentProps) => {
22
- const context = useRef<SVGContext>(null);
23
-
24
- return (
25
- <SVG.Root ref={context}>
26
- <Component {...props} />
27
- </SVG.Root>
28
- );
29
- };
30
-
31
20
  const Component = (options: ComponentProps) => {
32
21
  const grid = useGrid({ visible: options.grid, axis: true });
33
22
  const zoom = useZoom({ enabled: options.zoom });
@@ -42,15 +31,30 @@ const Component = (options: ComponentProps) => {
42
31
  );
43
32
  };
44
33
 
45
- const meta: Meta<typeof Component> = {
34
+ const DefaultStory = (props: ComponentProps) => {
35
+ const context = useRef<SVGContext>(null);
36
+
37
+ return (
38
+ <SVG.Root ref={context}>
39
+ <Component {...props} />
40
+ </SVG.Root>
41
+ );
42
+ };
43
+
44
+ const meta = {
46
45
  title: 'ui/react-ui-graph/SVGRoot',
47
46
  render: DefaultStory,
48
- decorators: [withTheme, withLayout({ fullscreen: true })],
49
- };
47
+ decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
48
+ parameters: {
49
+ layout: 'fullscreen',
50
+ },
51
+ } satisfies Meta<typeof DefaultStory>;
50
52
 
51
53
  export default meta;
52
54
 
53
- export const Default = {
55
+ type Story = StoryObj<typeof meta>;
56
+
57
+ export const Default: Story = {
54
58
  args: {
55
59
  grid: true,
56
60
  },
@@ -4,7 +4,7 @@
4
4
 
5
5
  import React, { type ReactNode, memo, useMemo } from 'react';
6
6
 
7
- import { useZoom, type ZoomExtent } from '../../hooks';
7
+ import { type ZoomExtent, useZoom } from '../../hooks';
8
8
 
9
9
  export type ZoomProps = {
10
10
  extent?: ZoomExtent;
@@ -2,20 +2,18 @@
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
- import { Pulsar } from './pulsar';
14
13
  import { SVG } from '../components';
15
14
  import { useGrid, useZoom } from '../hooks';
16
15
  import { type D3Callable } from '../util';
17
-
18
- import '../../styles/graph.css';
16
+ import { Pulsar } from './pulsar';
19
17
 
20
18
  type Datum = {
21
19
  x: number;
@@ -23,11 +21,11 @@ type Datum = {
23
21
  r: number;
24
22
  };
25
23
 
26
- type StoryProps = {
24
+ type DefaultStoryProps = {
27
25
  count: number;
28
26
  } & Pulsar.Options;
29
27
 
30
- const DefaultStory = (props: StoryProps) => {
28
+ const DefaultStory = (props: DefaultStoryProps) => {
31
29
  return (
32
30
  <SVG.Root>
33
31
  <StoryComponent {...props} />
@@ -35,7 +33,7 @@ const DefaultStory = (props: StoryProps) => {
35
33
  );
36
34
  };
37
35
 
38
- const StoryComponent: FC<StoryProps> = ({ count = 1, ...options }) => {
36
+ const StoryComponent: FC<DefaultStoryProps> = ({ count = 1, ...options }) => {
39
37
  const items = useMemo<Datum[]>(
40
38
  () =>
41
39
  Array.from({ length: count }, () => {
@@ -53,7 +51,7 @@ const StoryComponent: FC<StoryProps> = ({ count = 1, ...options }) => {
53
51
  const grid = useGrid({ axis: true, grid: false });
54
52
  const zoom = useZoom();
55
53
 
56
- const root = useRef<SVGGElement>();
54
+ const root = useRef<SVGGElement>(null);
57
55
  useEffect(() => {
58
56
  select(root.current)
59
57
  .selectAll('g')
@@ -92,21 +90,26 @@ const createNode: D3Callable<SVGGElement, Datum> = (group, classNames, options)
92
90
  });
93
91
  };
94
92
 
95
- const meta: Meta = {
93
+ const meta = {
96
94
  title: 'ui/react-ui-graph/fx',
97
95
  render: DefaultStory,
98
- decorators: [withTheme, withLayout({ fullscreen: true })],
99
- };
96
+ decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
97
+ parameters: {
98
+ layout: 'fullscreen',
99
+ },
100
+ } satisfies Meta<typeof DefaultStory>;
100
101
 
101
102
  export default meta;
102
103
 
103
- export const DefaultPulse = {
104
+ type Story = StoryObj<typeof meta>;
105
+
106
+ export const DefaultPulse: Story = {
104
107
  args: {
105
108
  count: 20,
106
109
  },
107
110
  };
108
111
 
109
- export const RapidPulse = {
112
+ export const RapidPulse: Story = {
110
113
  args: {
111
114
  count: 20,
112
115
  duration: 1_000,
@@ -4,10 +4,10 @@
4
4
 
5
5
  import { drag, pointer, select } from 'd3';
6
6
 
7
- import { type GraphProjector } from './graph-projector';
8
7
  import { type SVGContext } from '../../hooks';
9
8
  import { type Point } from '../../util';
10
9
  import { type GraphLayoutNode } from '../types';
10
+ import { type GraphProjector } from './graph-projector';
11
11
 
12
12
  enum Mode {
13
13
  MOVE = 0,
@@ -17,9 +17,9 @@ import {
17
17
  import { type Graph } from '@dxos/graph';
18
18
  import { log } from '@dxos/log';
19
19
 
20
+ import { type GraphLayoutEdge, type GraphLayoutNode } from '../types';
20
21
  import { forcePoint } from './graph-forces';
21
22
  import { GraphProjector, type GraphProjectorOptions } from './graph-projector';
22
- import { type GraphLayoutEdge, type GraphLayoutNode } from '../types';
23
23
 
24
24
  /**
25
25
  * Return value or invoke function.
@@ -222,7 +222,7 @@ export class GraphForceProjector<NodeData = any> extends GraphProjector<NodeData
222
222
  this.restart();
223
223
  }
224
224
 
225
- override onUpdate(graph?: Graph): void {
225
+ override onUpdate(graph?: Graph.Any): void {
226
226
  log('onUpdate', { graph: { nodes: graph?.nodes.length, edges: graph?.edges.length } });
227
227
  this._simulation.stop();
228
228
  this.mergeData(graph);
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type Force, forceX, forceY, type SimulationLinkDatum, type SimulationNodeDatum } from 'd3';
5
+ import { type Force, type SimulationLinkDatum, type SimulationNodeDatum, forceX, forceY } from 'd3';
6
6
 
7
7
  export type ForcePointOptions = {
8
8
  x?: number;
@@ -5,9 +5,9 @@
5
5
  import { type Graph } from '@dxos/graph';
6
6
  import { log } from '@dxos/log';
7
7
 
8
+ import { type GraphLayoutNode } from '../types';
8
9
  import { type GraphProjectorOptions } from './graph-projector';
9
10
  import { GraphRadialProjector, layoutRadial, updateNode } from './graph-radial-projector';
10
- import { type GraphLayoutNode } from '../types';
11
11
 
12
12
  export type GraphHierarchicalProjectorOptions = GraphProjectorOptions & {
13
13
  radius?: number;
@@ -19,14 +19,14 @@ export class GraphHierarchicalProjector<
19
19
  NodeData = any,
20
20
  Options extends GraphHierarchicalProjectorOptions = any,
21
21
  > extends GraphRadialProjector<NodeData, Options> {
22
- protected override onUpdate(graph?: Graph) {
22
+ protected override onUpdate(graph?: Graph.Any) {
23
23
  log('onUpdate', {
24
24
  graph: { nodes: graph?.nodes.length, edges: graph?.edges.length },
25
- selection: this.selection?.selected.value,
25
+ selection: this.selection?.getSelectedIds(),
26
26
  });
27
27
 
28
28
  this.mergeData(graph);
29
- const selected = this.selection?.selected.value?.[0];
29
+ const selected = this.selection?.getSelectedIds()[0];
30
30
  if (selected) {
31
31
  const node = this.layout.graph.nodes.find((node) => node.id === selected);
32
32
  if (node) {
@@ -2,11 +2,11 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type SelectionModel, type Graph } from '@dxos/graph';
5
+ import { type Graph, type SelectionModel } from '@dxos/graph';
6
6
 
7
- import { Projector, type ProjectorOptions } from './projector';
8
7
  import { type SVGContext } from '../../hooks';
9
- import { emptyGraph, type GraphLayout, type GraphLayoutNode } from '../types';
8
+ import { type GraphLayout, type GraphLayoutNode, emptyGraph } from '../types';
9
+ import { Projector, type ProjectorOptions } from './projector';
10
10
 
11
11
  export type GraphProjectorOptions = ProjectorOptions & {};
12
12
 
@@ -14,7 +14,7 @@ export type GraphProjectorOptions = ProjectorOptions & {};
14
14
  * Base class for graph projectors.
15
15
  */
16
16
  export abstract class GraphProjector<NodeData = any, Options extends GraphProjectorOptions = any> extends Projector<
17
- Graph,
17
+ Graph.Any,
18
18
  GraphLayout<NodeData>,
19
19
  Options
20
20
  > {
@@ -59,7 +59,7 @@ export abstract class GraphProjector<NodeData = any, Options extends GraphProjec
59
59
  * Merge external data with internal representation (e.g., so force properties like position are preserved).
60
60
  * @param data
61
61
  */
62
- protected mergeData(data: Graph = emptyGraph) {
62
+ protected mergeData(data: Graph.Any = emptyGraph) {
63
63
  // Merge nodes.
64
64
  const nodes: GraphLayoutNode[] = data.nodes.map((node) => {
65
65
  let current: GraphLayoutNode = this._layout.graph.nodes.find((n) => n.id === this.options.idAccessor(node));
@@ -2,14 +2,14 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { easeCubic, timer, type Timer } from 'd3';
5
+ import { type Timer, easeCubic, timer } from 'd3';
6
6
 
7
7
  import { type Graph } from '@dxos/graph';
8
8
  import { log } from '@dxos/log';
9
9
 
10
- import { GraphProjector, type GraphProjectorOptions } from './graph-projector';
11
10
  import { type Point } from '../../util';
12
11
  import { type GraphLayoutNode } from '../types';
12
+ import { GraphProjector, type GraphProjectorOptions } from './graph-projector';
13
13
 
14
14
  export type GraphRadialProjectorOptions = GraphProjectorOptions & {
15
15
  radius?: number;
@@ -27,7 +27,7 @@ export class GraphRadialProjector<
27
27
  return undefined;
28
28
  }
29
29
 
30
- protected override onUpdate(graph?: Graph) {
30
+ protected override onUpdate(graph?: Graph.Any) {
31
31
  log('onUpdate', { graph: { nodes: graph?.nodes.length, edges: graph?.edges.length } });
32
32
  this.mergeData(graph);
33
33
  this.doRadialLayout();
@@ -5,9 +5,9 @@
5
5
  import { type Graph } from '@dxos/graph';
6
6
  import { log } from '@dxos/log';
7
7
 
8
+ import { type GraphLayoutNode } from '../types';
8
9
  import { type GraphProjectorOptions } from './graph-projector';
9
10
  import { GraphRadialProjector, layoutHorizontal, layoutRadial, updateNode } from './graph-radial-projector';
10
- import { type GraphLayoutNode } from '../types';
11
11
 
12
12
  export type GraphRelationalProjectorOptions = GraphProjectorOptions & {
13
13
  radius?: number;
@@ -19,14 +19,14 @@ export class GraphRelationalProjector<
19
19
  NodeData = any,
20
20
  Options extends GraphRelationalProjectorOptions = any,
21
21
  > extends GraphRadialProjector<NodeData, Options> {
22
- protected override onUpdate(graph?: Graph) {
22
+ protected override onUpdate(graph?: Graph.Any) {
23
23
  log('onUpdate', {
24
24
  graph: { nodes: graph?.nodes.length, edges: graph?.edges.length },
25
- selection: this.selection?.selected.value,
25
+ selection: this.selection?.getSelectedIds(),
26
26
  });
27
27
 
28
28
  this.mergeData(graph);
29
- const selected = this.selection?.selected.value?.[0];
29
+ const selected = this.selection?.getSelectedIds()[0];
30
30
  if (selected) {
31
31
  const node = this.layout.graph.nodes.find((node) => node.id === selected);
32
32
  if (node) {
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { type SVGContext } from '../../hooks';
6
6
  import { EventEmitter } from '../../util';
7
- import { defaultIdAccessor, type IdAccessor } from '../types';
7
+ import { type IdAccessor, defaultIdAccessor } from '../types';
8
8
 
9
9
  export type ProjectorOptions = {
10
10
  idAccessor?: IdAccessor;
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { easeLinear, interpolate, select } from 'd3';
6
6
 
7
- import { type D3Selection, type D3Callable } from '../../util';
7
+ import { type D3Callable, type D3Selection } from '../../util';
8
8
 
9
9
  export type BulletOptions = {
10
10
  max?: number;
@@ -2,15 +2,15 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import { line, select, polygonHull, easeCubicOut } from 'd3';
5
+ import { easeCubicOut, line, polygonHull, select } from 'd3';
6
6
  import * as Clipper from 'js-clipper';
7
7
 
8
8
  import { log } from '@dxos/log';
9
9
 
10
+ import { type D3Callable, type D3Selection, type Point, getCircumferencePoints } from '../../util';
11
+ import { type GraphLayout, type GraphLayoutEdge, type GraphLayoutNode } from '../types';
10
12
  import { createBullets } from './bullets';
11
13
  import { Renderer, type RendererOptions } from './renderer';
12
- import { getCircumferencePoints, type D3Selection, type D3Callable, type Point } from '../../util';
13
- import { type GraphLayout, type GraphLayoutEdge, type GraphLayoutNode } from '../types';
14
14
 
15
15
  const createLine = line<Point>();
16
16
 
@@ -59,6 +59,12 @@ export class GraphRenderer<NodeData = any, EdgeData = any> extends Renderer<
59
59
  GraphRendererOptions<NodeData, EdgeData>
60
60
  > {
61
61
  override render(layout: GraphLayout<NodeData, EdgeData>) {
62
+ // The SVG group ref is unset between mount cycles and before the container has sized;
63
+ // skip the render rather than throw — the projector will emit again on the next tick.
64
+ if (!this.root) {
65
+ return;
66
+ }
67
+
62
68
  log('render', layout);
63
69
 
64
70
  const root = select(this.root);
@@ -208,6 +214,9 @@ export class GraphRenderer<NodeData = any, EdgeData = any> extends Renderer<
208
214
  * @param node
209
215
  */
210
216
  fireBullet(node: GraphLayoutNode<NodeData>) {
217
+ if (!this.root) {
218
+ return;
219
+ }
211
220
  select(this.root).selectAll('g.dx-edges').selectAll('path').call(createBullets(this.root, node.id));
212
221
  }
213
222
  }
@@ -250,20 +259,20 @@ const createNode: D3Callable = <Data>(group: D3Selection, options: GraphRenderer
250
259
  options.onNodePointerEnter(node, event);
251
260
  });
252
261
 
253
- group.attr('data-hover', 'handled'); // TODO(burdon): ???
262
+ group.attr('data-hover', 'handled');
254
263
  } else if (options.highlight !== false) {
255
264
  circle.on('pointerenter', function () {
256
265
  select(this.closest('g.dx-node')).raise();
257
266
  if (options.labels) {
258
- select(this.parentElement).classed('dx-active', true).classed('dx-highlight', true);
267
+ select(this.parentElement).classed('dx-node-active', true).classed('dx-highlight', true);
259
268
  }
260
269
  });
261
270
 
262
271
  group.on('pointerleave', function () {
263
272
  if (options.labels) {
264
- select(this).classed('dx-active', false);
273
+ select(this).classed('dx-node-active', false);
265
274
  setTimeout(() => {
266
- if (!select(this).classed('dx-active')) {
275
+ if (!select(this).classed('dx-node-active')) {
267
276
  select(this).classed('dx-highlight', false);
268
277
  }
269
278
  }, 300);