@dxos/react-ui-graph 0.8.3 → 0.8.4-main.03d5cd7b56
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-EASNZZ7B.mjs +52 -0
- package/dist/lib/browser/chunk-EASNZZ7B.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1109 -319
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +19 -19
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-JSE2X4ML.mjs +54 -0
- package/dist/lib/node-esm/chunk-JSE2X4ML.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1109 -319
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +19 -19
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/components/Graph/Graph.d.ts +4 -5
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +21 -12
- 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 +10 -6
- 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 +4 -4
- package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
- package/dist/types/src/components/SVG/SVG.d.ts +14 -17
- package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts +11 -9
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Zoom.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +16 -15
- 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 +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 +2 -2
- 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 +2 -2
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-projector.d.ts +4 -4
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +2 -2
- 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 +2 -2
- 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 +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/graph/types.d.ts +1 -1
- package/dist/types/src/graph/types.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 +15 -10
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +5 -5
- package/dist/types/src/testing/data.d.ts.map +1 -1
- package/dist/types/src/testing/hooks.d.ts +2 -16
- package/dist/types/src/testing/hooks.d.ts.map +1 -1
- package/dist/types/src/testing/model.d.ts +4 -8
- 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/index.d.ts +2 -2
- package/dist/types/src/util/index.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 +1 -1
- package/dist/types/src/util/screen.d.ts.map +1 -1
- package/dist/types/src/util/vector.d.ts +1 -1
- package/dist/types/src/util/vector.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -34
- package/src/components/Graph/Graph.stories.tsx +73 -69
- package/src/components/Graph/Graph.tsx +25 -20
- package/src/components/Mesh/Mesh.stories.tsx +10 -9
- package/src/components/Mesh/Mesh.tsx +1 -1
- package/src/components/SVG/Grid.tsx +2 -2
- package/src/components/SVG/Markers.tsx +1 -1
- package/src/components/SVG/Root.tsx +14 -7
- package/src/components/SVG/SVG.tsx +13 -4
- package/src/components/SVG/Svg.stories.tsx +23 -19
- package/src/components/SVG/Zoom.tsx +1 -1
- package/src/fx/fx.stories.tsx +18 -15
- package/src/graph/projector/graph-drag.ts +1 -1
- package/src/graph/projector/graph-force-projector.ts +3 -3
- package/src/graph/projector/graph-forces.ts +1 -1
- package/src/graph/projector/graph-hierarchical-projector.ts +4 -4
- package/src/graph/projector/graph-projector.ts +5 -5
- package/src/graph/projector/graph-radial-projector.ts +3 -3
- package/src/graph/projector/graph-relational-projector.ts +4 -4
- package/src/graph/projector/projector.ts +1 -1
- package/src/graph/renderer/bullets.ts +1 -1
- package/src/graph/renderer/graph-renderer.ts +7 -7
- package/src/graph/renderer/renderer.ts +1 -1
- package/src/graph/types.ts +1 -1
- package/src/hooks/useStateRef.ts +1 -1
- package/src/hooks/useZoom.ts +1 -1
- package/src/stories/hooks.stories.tsx +43 -36
- package/src/testing/data.ts +14 -14
- package/src/testing/hooks.ts +5 -5
- package/src/testing/model.ts +6 -6
- package/src/util/fraction.ts +1 -1
- package/src/util/index.ts +2 -2
- package/src/util/screen.test.ts +1 -1
- package/src/util/screen.ts +1 -1
- package/src/util/vector.ts +1 -1
- package/styles/graph.css +292 -43
- package/dist/lib/browser/chunk-2YMRPQU7.mjs +0 -979
- package/dist/lib/browser/chunk-2YMRPQU7.mjs.map +0 -7
- package/dist/lib/node/chunk-WFHWEMPB.cjs +0 -919
- package/dist/lib/node/chunk-WFHWEMPB.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -1547
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -214
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-ITHTKQOY.mjs +0 -981
- package/dist/lib/node-esm/chunk-ITHTKQOY.mjs.map +0 -7
|
@@ -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 {
|
|
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
|
-
|
|
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 '
|
|
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 {
|
|
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
|
|
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({
|
|
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
|
-
|
|
55
|
+
type Story = StoryObj<typeof meta>;
|
|
56
|
+
|
|
57
|
+
export const Default: Story = {
|
|
54
58
|
args: {
|
|
55
59
|
grid: true,
|
|
56
60
|
},
|
package/src/fx/fx.stories.tsx
CHANGED
|
@@ -2,20 +2,18 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '
|
|
5
|
+
import '../../styles/graph.css';
|
|
6
6
|
|
|
7
|
-
import { type Meta } from '@storybook/react';
|
|
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/
|
|
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
|
|
24
|
+
type DefaultStoryProps = {
|
|
27
25
|
count: number;
|
|
28
26
|
} & Pulsar.Options;
|
|
29
27
|
|
|
30
|
-
const DefaultStory = (props:
|
|
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<
|
|
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
|
|
93
|
+
const meta = {
|
|
96
94
|
title: 'ui/react-ui-graph/fx',
|
|
97
95
|
render: DefaultStory,
|
|
98
|
-
decorators: [withTheme, withLayout({
|
|
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
|
-
|
|
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.
|
|
@@ -50,7 +50,7 @@ const maybeForce = <Config>(
|
|
|
50
50
|
cb: (config: Config) => Force<any, any>,
|
|
51
51
|
defaultValue = undefined,
|
|
52
52
|
) => {
|
|
53
|
-
const value = typeof options === 'boolean' ? (options ? {} : undefined) : options ?? defaultValue;
|
|
53
|
+
const value = typeof options === 'boolean' ? (options ? {} : undefined) : (options ?? defaultValue);
|
|
54
54
|
if (value) {
|
|
55
55
|
return cb(value);
|
|
56
56
|
}
|
|
@@ -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,
|
|
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?.
|
|
25
|
+
selection: this.selection?.getSelectedIds(),
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
this.mergeData(graph);
|
|
29
|
-
const selected = this.selection?.
|
|
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
|
|
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 {
|
|
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
|
|
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?.
|
|
25
|
+
selection: this.selection?.getSelectedIds(),
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
this.mergeData(graph);
|
|
29
|
-
const selected = this.selection?.
|
|
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 {
|
|
7
|
+
import { type IdAccessor, defaultIdAccessor } from '../types';
|
|
8
8
|
|
|
9
9
|
export type ProjectorOptions = {
|
|
10
10
|
idAccessor?: IdAccessor;
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
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
|
|
|
@@ -250,20 +250,20 @@ const createNode: D3Callable = <Data>(group: D3Selection, options: GraphRenderer
|
|
|
250
250
|
options.onNodePointerEnter(node, event);
|
|
251
251
|
});
|
|
252
252
|
|
|
253
|
-
group.attr('data-hover', 'handled');
|
|
253
|
+
group.attr('data-hover', 'handled');
|
|
254
254
|
} else if (options.highlight !== false) {
|
|
255
255
|
circle.on('pointerenter', function () {
|
|
256
256
|
select(this.closest('g.dx-node')).raise();
|
|
257
257
|
if (options.labels) {
|
|
258
|
-
select(this.parentElement).classed('dx-active', true).classed('dx-highlight', true);
|
|
258
|
+
select(this.parentElement).classed('dx-node-active', true).classed('dx-highlight', true);
|
|
259
259
|
}
|
|
260
260
|
});
|
|
261
261
|
|
|
262
262
|
group.on('pointerleave', function () {
|
|
263
263
|
if (options.labels) {
|
|
264
|
-
select(this).classed('dx-active', false);
|
|
264
|
+
select(this).classed('dx-node-active', false);
|
|
265
265
|
setTimeout(() => {
|
|
266
|
-
if (!select(this).classed('dx-active')) {
|
|
266
|
+
if (!select(this).classed('dx-node-active')) {
|
|
267
267
|
select(this).classed('dx-highlight', false);
|
|
268
268
|
}
|
|
269
269
|
}, 300);
|
|
@@ -7,7 +7,7 @@ import { type RefObject } from 'react';
|
|
|
7
7
|
import { invariant } from '@dxos/invariant';
|
|
8
8
|
|
|
9
9
|
import { type SVGContext } from '../../hooks';
|
|
10
|
-
import {
|
|
10
|
+
import { type IdAccessor, defaultIdAccessor } from '../types';
|
|
11
11
|
|
|
12
12
|
export type RendererOptions<T = any> = {
|
|
13
13
|
idAccessor: IdAccessor;
|
package/src/graph/types.ts
CHANGED
package/src/hooks/useStateRef.ts
CHANGED
|
@@ -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]);
|
package/src/hooks/useZoom.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { type ZoomBehavior, type ZoomTransform, select, zoom, zoomIdentity } from 'd3';
|
|
6
6
|
import defaultsDeep from 'lodash.defaultsdeep';
|
|
7
7
|
import { type RefObject, useEffect, useMemo, useRef } from 'react';
|
|
8
8
|
|
|
@@ -2,34 +2,35 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '
|
|
5
|
+
import '../../styles/graph.css';
|
|
6
6
|
|
|
7
|
-
import {
|
|
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 {
|
|
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 {
|
|
17
20
|
GraphForceProjector,
|
|
18
|
-
type
|
|
21
|
+
type GraphForceProjectorOptions,
|
|
19
22
|
type GraphLayoutEdge,
|
|
23
|
+
type GraphLayoutNode,
|
|
20
24
|
GraphRenderer,
|
|
21
|
-
type GraphForceProjectorOptions,
|
|
22
|
-
createMarkers,
|
|
23
25
|
createGraphDrag,
|
|
26
|
+
createMarkers,
|
|
24
27
|
linkerRenderer,
|
|
25
28
|
} from '../graph';
|
|
26
|
-
import { useSvgContext, useZoom
|
|
27
|
-
import {
|
|
29
|
+
import { useGrid, useSvgContext, useZoom } from '../hooks';
|
|
30
|
+
import { TestGraphModel, type TestNode, convertTreeToGraph, createTree } from '../testing';
|
|
28
31
|
|
|
29
|
-
|
|
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
|
|
41
|
-
|
|
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
|
-
}:
|
|
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
|
|
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
|
|
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({
|
|
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
|
|
169
|
+
type Story = StoryObj<typeof meta>;
|
|
163
170
|
|
|
164
171
|
export const Default: Story = {
|
|
165
172
|
args: {
|
|
166
|
-
|
|
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
|
-
|
|
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,
|