@multiplatform.one/node-graph 9.0.11 → 9.2.0
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/dist/cjs/graphLayout/GraphDots.cjs +60 -0
- package/dist/cjs/graphLayout/GraphDots.native.js +66 -0
- package/dist/cjs/graphLayout/GraphDots.native.js.map +1 -0
- package/dist/cjs/graphLayout/GraphLayout.cjs +153 -0
- package/dist/cjs/graphLayout/GraphLayout.native.js +163 -0
- package/dist/cjs/graphLayout/GraphLayout.native.js.map +1 -0
- package/dist/cjs/graphLayout/GraphSvg.cjs +68 -0
- package/dist/cjs/graphLayout/GraphSvg.native.js +73 -0
- package/dist/cjs/graphLayout/GraphSvg.native.js.map +1 -0
- package/dist/cjs/graphLayout/GraphViewport.cjs +264 -0
- package/dist/cjs/graphLayout/GraphViewport.native.js +280 -0
- package/dist/cjs/graphLayout/GraphViewport.native.js.map +1 -0
- package/dist/cjs/graphLayout/index.cjs +51 -0
- package/dist/cjs/graphLayout/index.native.js +54 -0
- package/dist/cjs/graphLayout/index.native.js.map +1 -0
- package/dist/cjs/graphLayout/ogden.fixture.cjs +30 -0
- package/dist/cjs/graphLayout/ogden.fixture.native.js +33 -0
- package/dist/cjs/graphLayout/ogden.fixture.native.js.map +1 -0
- package/dist/cjs/graphLayout/plan.cjs +263 -0
- package/dist/cjs/graphLayout/plan.native.js +372 -0
- package/dist/cjs/graphLayout/plan.native.js.map +1 -0
- package/dist/cjs/graphLayout/viewMath.cjs +142 -0
- package/dist/cjs/graphLayout/viewMath.native.js +147 -0
- package/dist/cjs/graphLayout/viewMath.native.js.map +1 -0
- package/dist/esm/NodeGraph.native.js.map +1 -1
- package/dist/esm/bench/frameSampler.native.js.map +1 -1
- package/dist/esm/bench/generateGraph.native.js.map +1 -1
- package/dist/esm/diagnostics/GraphDiagnostics.native.js.map +1 -1
- package/dist/esm/diagnostics/LiveGraphDiagnostics.native.js.map +1 -1
- package/dist/esm/diagnostics/fromWire.native.js.map +1 -1
- package/dist/esm/diagnostics/lastError.native.js.map +1 -1
- package/dist/esm/diagnostics/types.native.js.map +1 -1
- package/dist/esm/diagnostics/useGraphDiagnostics.native.js.map +1 -1
- package/dist/esm/dom/GraphDomLayout.native.js.map +1 -1
- package/dist/esm/dom/boot.native.js.map +1 -1
- package/dist/esm/dom/wire.native.js.map +1 -1
- package/dist/esm/edges/GraphEdge.native.js.map +1 -1
- package/dist/esm/edges/edgeKinds.native.js.map +1 -1
- package/dist/esm/edges/edgePath.native.js.map +1 -1
- package/dist/esm/edges/edgeRoute.native.js.map +1 -1
- package/dist/esm/edges/edgeStyle.native.js.map +1 -1
- package/dist/esm/edges/useEdgeObstacles.native.js.map +1 -1
- package/dist/esm/graphLayout/GraphDots.mjs +35 -0
- package/dist/esm/graphLayout/GraphDots.mjs.map +1 -0
- package/dist/esm/graphLayout/GraphDots.native.js +38 -0
- package/dist/esm/graphLayout/GraphDots.native.js.map +1 -0
- package/dist/esm/graphLayout/GraphLayout.mjs +127 -0
- package/dist/esm/graphLayout/GraphLayout.mjs.map +1 -0
- package/dist/esm/graphLayout/GraphLayout.native.js +134 -0
- package/dist/esm/graphLayout/GraphLayout.native.js.map +1 -0
- package/dist/esm/graphLayout/GraphSvg.mjs +42 -0
- package/dist/esm/graphLayout/GraphSvg.mjs.map +1 -0
- package/dist/esm/graphLayout/GraphSvg.native.js +44 -0
- package/dist/esm/graphLayout/GraphSvg.native.js.map +1 -0
- package/dist/esm/graphLayout/GraphViewport.mjs +239 -0
- package/dist/esm/graphLayout/GraphViewport.mjs.map +1 -0
- package/dist/esm/graphLayout/GraphViewport.native.js +252 -0
- package/dist/esm/graphLayout/GraphViewport.native.js.map +1 -0
- package/dist/esm/graphLayout/index.mjs +7 -0
- package/dist/esm/graphLayout/index.mjs.map +1 -0
- package/dist/esm/graphLayout/index.native.js +7 -0
- package/dist/esm/graphLayout/index.native.js.map +1 -0
- package/dist/esm/graphLayout/ogden.fixture.mjs +4 -0
- package/dist/esm/graphLayout/ogden.fixture.mjs.map +1 -0
- package/dist/esm/graphLayout/ogden.fixture.native.js +4 -0
- package/dist/esm/graphLayout/ogden.fixture.native.js.map +1 -0
- package/dist/esm/graphLayout/plan.mjs +235 -0
- package/dist/esm/graphLayout/plan.mjs.map +1 -0
- package/dist/esm/graphLayout/plan.native.js +341 -0
- package/dist/esm/graphLayout/plan.native.js.map +1 -0
- package/dist/esm/graphLayout/viewMath.mjs +105 -0
- package/dist/esm/graphLayout/viewMath.mjs.map +1 -0
- package/dist/esm/graphLayout/viewMath.native.js +107 -0
- package/dist/esm/graphLayout/viewMath.native.js.map +1 -0
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/interaction/lassoIntercept.native.js.map +1 -1
- package/dist/esm/interaction/legalTargets.native.js.map +1 -1
- package/dist/esm/interaction/snapAlignment.native.js.map +1 -1
- package/dist/esm/interaction/snapChanges.native.js.map +1 -1
- package/dist/esm/interaction/spatialHash.native.js.map +1 -1
- package/dist/esm/interaction/useLassoSelect.native.js.map +1 -1
- package/dist/esm/knobs/KnobEnvelopeProvider.native.js.map +1 -1
- package/dist/esm/knobs/envelope.native.js.map +1 -1
- package/dist/esm/knobs/graphKnobs.native.js.map +1 -1
- package/dist/esm/knobs/useKnobEnvelope.native.js.map +1 -1
- package/dist/esm/layout/dagre.native.js.map +1 -1
- package/dist/esm/layout/layout.native.js.map +1 -1
- package/dist/esm/layout/runner.native.js.map +1 -1
- package/dist/esm/layout/structuredCloneShim.native.js.map +1 -1
- package/dist/esm/layout/types.native.js.map +1 -1
- package/dist/esm/layout/worker.entry.native.js.map +1 -1
- package/dist/esm/layout/worker.generated.native.js.map +1 -1
- package/dist/esm/model/commands.native.js.map +1 -1
- package/dist/esm/model/connect.native.js.map +1 -1
- package/dist/esm/model/document.native.js.map +1 -1
- package/dist/esm/model/history.native.js.map +1 -1
- package/dist/esm/model/index.native.js.map +1 -1
- package/dist/esm/model/schema.native.js.map +1 -1
- package/dist/esm/model/select.native.js.map +1 -1
- package/dist/esm/model/serialize.native.js.map +1 -1
- package/dist/esm/native/DomOnlyStory.native.js.map +1 -1
- package/dist/esm/native/GraphToolbar.native.js.map +1 -1
- package/dist/esm/native/domEntryRegistry.native.js.map +1 -1
- package/dist/esm/native/graphChildren.native.js.map +1 -1
- package/dist/esm/nodes/GraphNode.native.js.map +1 -1
- package/dist/esm/nodes/GraphPort.native.js.map +1 -1
- package/dist/esm/nodes/handleGeometry.native.js.map +1 -1
- package/dist/esm/nodes/lod.native.js.map +1 -1
- package/dist/esm/nodes/nodeMeasure.native.js.map +1 -1
- package/dist/esm/nodes/overviewNode.native.js.map +1 -1
- package/dist/esm/react-flow/ConnectionPuck.native.js.map +1 -1
- package/dist/esm/react-flow/GraphActions.native.js.map +1 -1
- package/dist/esm/react-flow/GraphCommandBridge.native.js.map +1 -1
- package/dist/esm/react-flow/GraphNodeHost.native.js.map +1 -1
- package/dist/esm/react-flow/GraphPaintProbe.native.js.map +1 -1
- package/dist/esm/react-flow/GraphZoomVar.native.js.map +1 -1
- package/dist/esm/react-flow/LassoOverlay.native.js.map +1 -1
- package/dist/esm/react-flow/NodeGraphWeb.native.js.map +1 -1
- package/dist/esm/react-flow/SnapGuides.native.js.map +1 -1
- package/dist/esm/react-flow/demoControlBody.native.js.map +1 -1
- package/dist/esm/react-flow/demoNodeBody.native.js.map +1 -1
- package/dist/esm/react-flow/fixtures.native.js.map +1 -1
- package/dist/esm/react-flow/flowAdapter.native.js.map +1 -1
- package/dist/esm/react-flow/graphHandle.native.js.map +1 -1
- package/dist/esm/react-flow/nodeCensus.native.js.map +1 -1
- package/dist/esm/react-flow/useGraphController.native.js.map +1 -1
- package/dist/esm/react-flow/xy.native.js.map +1 -1
- package/dist/esm/react-flow/xyPaths.native.js.map +1 -1
- package/dist/esm/theme/GraphFaces.native.js.map +1 -1
- package/dist/esm/theme/GraphVarsStyle.native.js.map +1 -1
- package/dist/esm/theme/faces.generated.native.js.map +1 -1
- package/dist/esm/theme/faces.native.js.map +1 -1
- package/dist/esm/theme/graphVars.native.js.map +1 -1
- package/dist/jsx/graphLayout/GraphDots.mjs +35 -0
- package/dist/jsx/graphLayout/GraphDots.mjs.map +1 -0
- package/dist/jsx/graphLayout/GraphDots.native.js +66 -0
- package/dist/jsx/graphLayout/GraphDots.native.js.map +1 -0
- package/dist/jsx/graphLayout/GraphLayout.mjs +127 -0
- package/dist/jsx/graphLayout/GraphLayout.mjs.map +1 -0
- package/dist/jsx/graphLayout/GraphLayout.native.js +163 -0
- package/dist/jsx/graphLayout/GraphLayout.native.js.map +1 -0
- package/dist/jsx/graphLayout/GraphSvg.mjs +42 -0
- package/dist/jsx/graphLayout/GraphSvg.mjs.map +1 -0
- package/dist/jsx/graphLayout/GraphSvg.native.js +73 -0
- package/dist/jsx/graphLayout/GraphSvg.native.js.map +1 -0
- package/dist/jsx/graphLayout/GraphViewport.mjs +239 -0
- package/dist/jsx/graphLayout/GraphViewport.mjs.map +1 -0
- package/dist/jsx/graphLayout/GraphViewport.native.js +280 -0
- package/dist/jsx/graphLayout/GraphViewport.native.js.map +1 -0
- package/dist/jsx/graphLayout/index.mjs +7 -0
- package/dist/jsx/graphLayout/index.mjs.map +1 -0
- package/dist/jsx/graphLayout/index.native.js +54 -0
- package/dist/jsx/graphLayout/index.native.js.map +1 -0
- package/dist/jsx/graphLayout/ogden.fixture.mjs +4 -0
- package/dist/jsx/graphLayout/ogden.fixture.mjs.map +1 -0
- package/dist/jsx/graphLayout/ogden.fixture.native.js +33 -0
- package/dist/jsx/graphLayout/ogden.fixture.native.js.map +1 -0
- package/dist/jsx/graphLayout/plan.mjs +235 -0
- package/dist/jsx/graphLayout/plan.mjs.map +1 -0
- package/dist/jsx/graphLayout/plan.native.js +372 -0
- package/dist/jsx/graphLayout/plan.native.js.map +1 -0
- package/dist/jsx/graphLayout/viewMath.mjs +105 -0
- package/dist/jsx/graphLayout/viewMath.mjs.map +1 -0
- package/dist/jsx/graphLayout/viewMath.native.js +147 -0
- package/dist/jsx/graphLayout/viewMath.native.js.map +1 -0
- package/graph-layout.ts +1 -0
- package/package.json +21 -6
- package/src/graphLayout/GraphDots.tsx +32 -0
- package/src/graphLayout/GraphLayout.stories.tsx +86 -0
- package/src/graphLayout/GraphLayout.tsx +152 -0
- package/src/graphLayout/GraphSvg.native.tsx +31 -0
- package/src/graphLayout/GraphSvg.tsx +45 -0
- package/src/graphLayout/GraphViewport.native.tsx +231 -0
- package/src/graphLayout/GraphViewport.tsx +247 -0
- package/src/graphLayout/index.ts +31 -0
- package/src/graphLayout/ogden.fixture.ts +120 -0
- package/src/graphLayout/plan.spec.ts +202 -0
- package/src/graphLayout/plan.ts +223 -0
- package/src/graphLayout/purity.spec.ts +67 -0
- package/src/graphLayout/viewMath.spec.ts +185 -0
- package/src/graphLayout/viewMath.ts +151 -0
- package/types/graphLayout/GraphDots.d.ts +9 -0
- package/types/graphLayout/GraphDots.d.ts.map +1 -0
- package/types/graphLayout/GraphLayout.d.ts +22 -0
- package/types/graphLayout/GraphLayout.d.ts.map +1 -0
- package/types/graphLayout/GraphSvg.d.ts +17 -0
- package/types/graphLayout/GraphSvg.d.ts.map +1 -0
- package/types/graphLayout/GraphSvg.native.d.ts +5 -0
- package/types/graphLayout/GraphSvg.native.d.ts.map +1 -0
- package/types/graphLayout/GraphViewport.d.ts +11 -0
- package/types/graphLayout/GraphViewport.d.ts.map +1 -0
- package/types/graphLayout/GraphViewport.native.d.ts +4 -0
- package/types/graphLayout/GraphViewport.native.d.ts.map +1 -0
- package/types/graphLayout/index.d.ts +11 -0
- package/types/graphLayout/index.d.ts.map +1 -0
- package/types/graphLayout/ogden.fixture.d.ts +3 -0
- package/types/graphLayout/ogden.fixture.d.ts.map +1 -0
- package/types/graphLayout/plan.d.ts +52 -0
- package/types/graphLayout/plan.d.ts.map +1 -0
- package/types/graphLayout/viewMath.d.ts +47 -0
- package/types/graphLayout/viewMath.d.ts.map +1 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const graphZoom = {
|
|
2
|
+
floor: 0.1,
|
|
3
|
+
step: 1.25,
|
|
4
|
+
settleMs: 220
|
|
5
|
+
};
|
|
6
|
+
function leastScale(content, viewport) {
|
|
7
|
+
"worklet";
|
|
8
|
+
|
|
9
|
+
if (content.width <= 0 || content.height <= 0 || viewport.width <= 0 || viewport.height <= 0) return 1;
|
|
10
|
+
const fit = Math.min(viewport.width / content.width, viewport.height / content.height);
|
|
11
|
+
return Math.min(1, Math.max(graphZoom.floor, fit));
|
|
12
|
+
}
|
|
13
|
+
function clampOffset(offset, content, viewport) {
|
|
14
|
+
"worklet";
|
|
15
|
+
|
|
16
|
+
if (content <= viewport) return (viewport - content) / 2;
|
|
17
|
+
return Math.min(0, Math.max(viewport - content, offset));
|
|
18
|
+
}
|
|
19
|
+
function clampView(view, content, viewport) {
|
|
20
|
+
"worklet";
|
|
21
|
+
|
|
22
|
+
const scale = Math.min(1, Math.max(leastScale(content, viewport), view.scale));
|
|
23
|
+
return {
|
|
24
|
+
scale,
|
|
25
|
+
x: clampOffset(view.x, content.width * scale, viewport.width),
|
|
26
|
+
y: clampOffset(view.y, content.height * scale, viewport.height)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function zoomAt(view, scale, focal, content, viewport) {
|
|
30
|
+
"worklet";
|
|
31
|
+
|
|
32
|
+
const next = Math.min(1, Math.max(leastScale(content, viewport), scale));
|
|
33
|
+
const ratio = next / view.scale;
|
|
34
|
+
return clampView({
|
|
35
|
+
scale: next,
|
|
36
|
+
x: focal.x - (focal.x - view.x) * ratio,
|
|
37
|
+
y: focal.y - (focal.y - view.y) * ratio
|
|
38
|
+
}, content, viewport);
|
|
39
|
+
}
|
|
40
|
+
function fittedView(content, viewport) {
|
|
41
|
+
"worklet";
|
|
42
|
+
|
|
43
|
+
return clampView({
|
|
44
|
+
scale: leastScale(content, viewport),
|
|
45
|
+
x: 0,
|
|
46
|
+
y: 0
|
|
47
|
+
}, content, viewport);
|
|
48
|
+
}
|
|
49
|
+
function toggledView(view, at, content, viewport) {
|
|
50
|
+
"worklet";
|
|
51
|
+
|
|
52
|
+
const least = leastScale(content, viewport);
|
|
53
|
+
return view.scale < 1 - 1e-3 ? zoomAt(view, 1, at, content, viewport) : zoomAt(view, least, at, content, viewport);
|
|
54
|
+
}
|
|
55
|
+
function keyedView(key, view, content, viewport) {
|
|
56
|
+
const centre = {
|
|
57
|
+
x: viewport.width / 2,
|
|
58
|
+
y: viewport.height / 2
|
|
59
|
+
};
|
|
60
|
+
if (key === "+" || key === "=") return zoomAt(view, view.scale * graphZoom.step, centre, content, viewport);
|
|
61
|
+
if (key === "-" || key === "_") return zoomAt(view, view.scale / graphZoom.step, centre, content, viewport);
|
|
62
|
+
if (key === "0") return zoomAt(view, 1, centre, content, viewport);
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
function dotPitch(pitch, scale) {
|
|
66
|
+
"worklet";
|
|
67
|
+
|
|
68
|
+
let spaced = pitch;
|
|
69
|
+
while (spaced * scale < pitch / 2) spaced *= 2;
|
|
70
|
+
return spaced;
|
|
71
|
+
}
|
|
72
|
+
function dotPhase(offset, scale, pitch, spaced) {
|
|
73
|
+
"worklet";
|
|
74
|
+
|
|
75
|
+
const step = spaced * scale;
|
|
76
|
+
const start = offset + pitch / 2 * scale;
|
|
77
|
+
return (start % step + step) % step - step;
|
|
78
|
+
}
|
|
79
|
+
function reachOf(offset, view, total, chunk) {
|
|
80
|
+
const start = Math.max(0, Math.floor(offset / chunk) * chunk - chunk);
|
|
81
|
+
return [start, Math.max(0, Math.min(view + chunk * 3, total - start))];
|
|
82
|
+
}
|
|
83
|
+
function dotArea(offset, viewport, canvas, chunk) {
|
|
84
|
+
const [x, width] = reachOf(offset.x, viewport.width, canvas.width, chunk);
|
|
85
|
+
const [y, height] = reachOf(offset.y, viewport.height, canvas.height, chunk);
|
|
86
|
+
return {
|
|
87
|
+
x,
|
|
88
|
+
y,
|
|
89
|
+
width,
|
|
90
|
+
height
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function dotPath(area, pitch) {
|
|
94
|
+
const runs = [];
|
|
95
|
+
const first = start => Math.ceil((start - pitch / 2) / pitch) * pitch + pitch / 2 - start;
|
|
96
|
+
for (let y = first(area.y); y < area.height; y += pitch) {
|
|
97
|
+
for (let x = first(area.x); x < area.width; x += pitch) runs.push(`M${x} ${y}h0.01`);
|
|
98
|
+
}
|
|
99
|
+
return runs.join("");
|
|
100
|
+
}
|
|
101
|
+
function sameArea(a, b) {
|
|
102
|
+
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
103
|
+
}
|
|
104
|
+
export { clampOffset, clampView, dotArea, dotPath, dotPhase, dotPitch, fittedView, graphZoom, keyedView, leastScale, sameArea, toggledView, zoomAt };
|
|
105
|
+
//# sourceMappingURL=viewMath.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["graphZoom","floor","step","settleMs","leastScale","content","viewport","width","height","fit","Math","min","max","clampOffset","offset","clampView","view","scale","x","y","zoomAt","focal","next","ratio","fittedView","toggledView","at","least","keyedView","key","centre","dotPitch","pitch","spaced","dotPhase","start","reachOf","total","chunk","dotArea","canvas","dotPath","area","runs","first","ceil","push","join","sameArea","a","b"],"sources":["../../../src/graphLayout/viewMath.ts"],"sourcesContent":[null],"mappings":"AAwBO,MAAMA,SAAA,GAAY;EACvBC,KAAA,EAAO;EACPC,IAAA,EAAM;EACNC,QAAA,EAAU;AACZ;AAEO,SAASC,WAAWC,OAAA,EAAiBC,QAAA,EAA0B;EACpE;;EACA,IAAID,OAAA,CAAQE,KAAA,IAAS,KAAKF,OAAA,CAAQG,MAAA,IAAU,KAAKF,QAAA,CAASC,KAAA,IAAS,KAAKD,QAAA,CAASE,MAAA,IAAU,GACzF,OAAO;EACT,MAAMC,GAAA,GAAMC,IAAA,CAAKC,GAAA,CAAIL,QAAA,CAASC,KAAA,GAAQF,OAAA,CAAQE,KAAA,EAAOD,QAAA,CAASE,MAAA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
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
}), mod);
|
|
25
|
+
var viewMath_exports = {};
|
|
26
|
+
__export(viewMath_exports, {
|
|
27
|
+
clampOffset: () => clampOffset,
|
|
28
|
+
clampView: () => clampView,
|
|
29
|
+
dotArea: () => dotArea,
|
|
30
|
+
dotPath: () => dotPath,
|
|
31
|
+
dotPhase: () => dotPhase,
|
|
32
|
+
dotPitch: () => dotPitch,
|
|
33
|
+
fittedView: () => fittedView,
|
|
34
|
+
graphZoom: () => graphZoom,
|
|
35
|
+
keyedView: () => keyedView,
|
|
36
|
+
leastScale: () => leastScale,
|
|
37
|
+
sameArea: () => sameArea,
|
|
38
|
+
toggledView: () => toggledView,
|
|
39
|
+
zoomAt: () => zoomAt
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(viewMath_exports);
|
|
42
|
+
var graphZoom = {
|
|
43
|
+
floor: 0.1,
|
|
44
|
+
step: 1.25,
|
|
45
|
+
settleMs: 220
|
|
46
|
+
};
|
|
47
|
+
function leastScale(content, viewport) {
|
|
48
|
+
"worklet";
|
|
49
|
+
|
|
50
|
+
if (content.width <= 0 || content.height <= 0 || viewport.width <= 0 || viewport.height <= 0) return 1;
|
|
51
|
+
var fit = Math.min(viewport.width / content.width, viewport.height / content.height);
|
|
52
|
+
return Math.min(1, Math.max(graphZoom.floor, fit));
|
|
53
|
+
}
|
|
54
|
+
function clampOffset(offset, content, viewport) {
|
|
55
|
+
"worklet";
|
|
56
|
+
|
|
57
|
+
if (content <= viewport) return (viewport - content) / 2;
|
|
58
|
+
return Math.min(0, Math.max(viewport - content, offset));
|
|
59
|
+
}
|
|
60
|
+
function clampView(view, content, viewport) {
|
|
61
|
+
"worklet";
|
|
62
|
+
|
|
63
|
+
var scale = Math.min(1, Math.max(leastScale(content, viewport), view.scale));
|
|
64
|
+
return {
|
|
65
|
+
scale,
|
|
66
|
+
x: clampOffset(view.x, content.width * scale, viewport.width),
|
|
67
|
+
y: clampOffset(view.y, content.height * scale, viewport.height)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function zoomAt(view, scale, focal, content, viewport) {
|
|
71
|
+
"worklet";
|
|
72
|
+
|
|
73
|
+
var next = Math.min(1, Math.max(leastScale(content, viewport), scale));
|
|
74
|
+
var ratio = next / view.scale;
|
|
75
|
+
return clampView({
|
|
76
|
+
scale: next,
|
|
77
|
+
x: focal.x - (focal.x - view.x) * ratio,
|
|
78
|
+
y: focal.y - (focal.y - view.y) * ratio
|
|
79
|
+
}, content, viewport);
|
|
80
|
+
}
|
|
81
|
+
function fittedView(content, viewport) {
|
|
82
|
+
"worklet";
|
|
83
|
+
|
|
84
|
+
return clampView({
|
|
85
|
+
scale: leastScale(content, viewport),
|
|
86
|
+
x: 0,
|
|
87
|
+
y: 0
|
|
88
|
+
}, content, viewport);
|
|
89
|
+
}
|
|
90
|
+
function toggledView(view, at, content, viewport) {
|
|
91
|
+
"worklet";
|
|
92
|
+
|
|
93
|
+
var least = leastScale(content, viewport);
|
|
94
|
+
return view.scale < 1 - 1e-3 ? zoomAt(view, 1, at, content, viewport) : zoomAt(view, least, at, content, viewport);
|
|
95
|
+
}
|
|
96
|
+
function keyedView(key, view, content, viewport) {
|
|
97
|
+
var centre = {
|
|
98
|
+
x: viewport.width / 2,
|
|
99
|
+
y: viewport.height / 2
|
|
100
|
+
};
|
|
101
|
+
if (key === "+" || key === "=") return zoomAt(view, view.scale * graphZoom.step, centre, content, viewport);
|
|
102
|
+
if (key === "-" || key === "_") return zoomAt(view, view.scale / graphZoom.step, centre, content, viewport);
|
|
103
|
+
if (key === "0") return zoomAt(view, 1, centre, content, viewport);
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
function dotPitch(pitch, scale) {
|
|
107
|
+
"worklet";
|
|
108
|
+
|
|
109
|
+
var spaced = pitch;
|
|
110
|
+
while (spaced * scale < pitch / 2) spaced *= 2;
|
|
111
|
+
return spaced;
|
|
112
|
+
}
|
|
113
|
+
function dotPhase(offset, scale, pitch, spaced) {
|
|
114
|
+
"worklet";
|
|
115
|
+
|
|
116
|
+
var step = spaced * scale;
|
|
117
|
+
var start = offset + pitch / 2 * scale;
|
|
118
|
+
return (start % step + step) % step - step;
|
|
119
|
+
}
|
|
120
|
+
function reachOf(offset, view, total, chunk) {
|
|
121
|
+
var start = Math.max(0, Math.floor(offset / chunk) * chunk - chunk);
|
|
122
|
+
return [start, Math.max(0, Math.min(view + chunk * 3, total - start))];
|
|
123
|
+
}
|
|
124
|
+
function dotArea(offset, viewport, canvas, chunk) {
|
|
125
|
+
var [x, width] = reachOf(offset.x, viewport.width, canvas.width, chunk);
|
|
126
|
+
var [y, height] = reachOf(offset.y, viewport.height, canvas.height, chunk);
|
|
127
|
+
return {
|
|
128
|
+
x,
|
|
129
|
+
y,
|
|
130
|
+
width,
|
|
131
|
+
height
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function dotPath(area, pitch) {
|
|
135
|
+
var runs = [];
|
|
136
|
+
var first = function first2(start) {
|
|
137
|
+
return Math.ceil((start - pitch / 2) / pitch) * pitch + pitch / 2 - start;
|
|
138
|
+
};
|
|
139
|
+
for (var y = first(area.y); y < area.height; y += pitch) {
|
|
140
|
+
for (var x = first(area.x); x < area.width; x += pitch) runs.push(`M${x} ${y}h0.01`);
|
|
141
|
+
}
|
|
142
|
+
return runs.join("");
|
|
143
|
+
}
|
|
144
|
+
function sameArea(a, b) {
|
|
145
|
+
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=viewMath.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","viewMath_exports","clampOffset","clampView","dotArea","dotPath","dotPhase","dotPitch","fittedView","graphZoom","keyedView","leastScale","sameArea","toggledView","zoomAt","module","exports","floor","step","settleMs","content","viewport","width","height","fit","Math","min","max","offset","view","scale","x","y","focal","next","ratio","at","least","centre"],"sources":["../../../src/graphLayout/viewMath.ts"],"sourcesContent":[null],"mappings":"AAwBO,YAAM;;AAAY,IACvBA,SAAO,GAAAC,MAAA,CAAAC,cAAA;AAAA,IACPC,gBAAM,GAAAF,MAAA,CAAAG,wBAAA;AAAA,IACNC,iBAAU,GAAAJ,MAAA,CAAAK,mBAAA;AACZ,IAAAC,YAAA,GAAAN,MAAA,CAAAO,SAAA,CAAAC,cAAA;AAEO,IAAAC,QAAS,GAAAA,CAAAC,MAAW,EAAAC,GAAA,KAAiB;EAC1C,SAAAC,IAAA,IAAAD,GAAA,EACAZ,SAAI,CAAQW,MAAA,EAAAE,IAAS,EAAK;IAAAC,GAAA,EAAAF,GAAQ,CAAAC,IAAA;IA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AC9C,IAAAiB,MAAA;IACAP,CAAA,EAAAV,QAAY,CAAAC,KAAO;IACrBU,CAAA,EAAAX,QAAA,CAAAE,MAAA;EAEO;EACL,IAAA3B,GAAO,KAAE,GAAM,IAAEA,GAAK,KAAE,GAAM,EAAE,OAAOkB,MAAA,CAAAe,IAAU,EAAEA,IAAA,CAAAC,KAAW,GAAArB,SAAW,CAAES,IAAA,EAAAoB,MAAA,EAAAlB,OAAA,EAAAC,QAAA;EAC7E,IAAAzB,GAAA,YAAAA,GAAA,iBAAAkB,MAAA,CAAAe,IAAA,EAAAA,IAAA,CAAAC,KAAA,GAAArB,SAAA,CAAAS,IAAA,EAAAoB,MAAA,EAAAlB,OAAA,EAAAC,QAAA","ignoreList":[]}
|
package/graph-layout.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/graphLayout/index";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/node-graph",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "Node graph editor — React Flow on web, Tamagui knob-aware nodes, an Expo DOM host on native",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"multiplatform",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"demo.ts",
|
|
23
23
|
"dist",
|
|
24
24
|
"dom-inner.ts",
|
|
25
|
+
"graph-layout.ts",
|
|
25
26
|
"metro",
|
|
26
27
|
"model.ts",
|
|
27
28
|
"src",
|
|
@@ -53,6 +54,14 @@
|
|
|
53
54
|
"import": "./dist/esm/model/index.mjs",
|
|
54
55
|
"require": "./dist/cjs/model/index.cjs"
|
|
55
56
|
},
|
|
57
|
+
"./graph-layout": {
|
|
58
|
+
"source": "./src/graphLayout/index.ts",
|
|
59
|
+
"react-native": "./src/graphLayout/index.ts",
|
|
60
|
+
"types": "./types/graphLayout/index.d.ts",
|
|
61
|
+
"import": "./dist/esm/graphLayout/index.mjs",
|
|
62
|
+
"require": "./dist/cjs/graphLayout/index.cjs",
|
|
63
|
+
"default": "./dist/esm/graphLayout/index.mjs"
|
|
64
|
+
},
|
|
56
65
|
"./dom": {
|
|
57
66
|
"source": "./src/dom/NodeGraphDom.ts",
|
|
58
67
|
"react-native": "./src/dom/NodeGraphDom.ts",
|
|
@@ -82,16 +91,16 @@
|
|
|
82
91
|
},
|
|
83
92
|
"dependencies": {
|
|
84
93
|
"@dagrejs/dagre": "^3.1.1",
|
|
85
|
-
"@multiplatform.one/forms": "^9.0
|
|
86
|
-
"@multiplatform.one/theme": "^9.0
|
|
94
|
+
"@multiplatform.one/forms": "^9.2.0",
|
|
95
|
+
"@multiplatform.one/theme": "^9.2.0",
|
|
87
96
|
"@tamagui/web": "2.7.6",
|
|
88
97
|
"@xyflow/react": "^12.12.0",
|
|
89
98
|
"@xyflow/system": "0.0.83",
|
|
90
99
|
"tamagui": "2.7.6"
|
|
91
100
|
},
|
|
92
101
|
"devDependencies": {
|
|
93
|
-
"@multiplatform.one/config": "9.0
|
|
94
|
-
"@multiplatform.one/test-utils": "9.0
|
|
102
|
+
"@multiplatform.one/config": "9.2.0",
|
|
103
|
+
"@multiplatform.one/test-utils": "9.2.0",
|
|
95
104
|
"@tamagui/build": "2.7.6",
|
|
96
105
|
"@testing-library/react": "^16.3.3",
|
|
97
106
|
"@types/react-dom": "^19.2.3",
|
|
@@ -104,12 +113,15 @@
|
|
|
104
113
|
"vitest": "^4.1.12"
|
|
105
114
|
},
|
|
106
115
|
"peerDependencies": {
|
|
107
|
-
"@multiplatform.one/components": "^9.0
|
|
116
|
+
"@multiplatform.one/components": "^9.2.0",
|
|
108
117
|
"expo": ">=55",
|
|
109
118
|
"expo-haptics": "*",
|
|
110
119
|
"react": "^19.1.0",
|
|
111
120
|
"react-dom": "^19.1.0",
|
|
112
121
|
"react-native": ">=0.83.0",
|
|
122
|
+
"react-native-gesture-handler": ">=2.0.0",
|
|
123
|
+
"react-native-reanimated": "^4.2.0",
|
|
124
|
+
"react-native-svg": "^15.15.0",
|
|
113
125
|
"react-native-webview": ">=13.16.0"
|
|
114
126
|
},
|
|
115
127
|
"peerDependenciesMeta": {
|
|
@@ -125,6 +137,9 @@
|
|
|
125
137
|
"react-native": {
|
|
126
138
|
"optional": true
|
|
127
139
|
},
|
|
140
|
+
"react-native-gesture-handler": {
|
|
141
|
+
"optional": true
|
|
142
|
+
},
|
|
128
143
|
"react-native-webview": {
|
|
129
144
|
"optional": true
|
|
130
145
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { View } from "tamagui";
|
|
3
|
+
import { GraphPath, GraphSvg } from "./GraphSvg";
|
|
4
|
+
import { dotPath } from "./viewMath";
|
|
5
|
+
import type { DotArea } from "./viewMath";
|
|
6
|
+
|
|
7
|
+
export interface GraphDotsProps {
|
|
8
|
+
readonly area: DotArea;
|
|
9
|
+
readonly pitch: number;
|
|
10
|
+
readonly dot: number;
|
|
11
|
+
readonly color: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function GraphDots({ area, pitch, dot, color }: GraphDotsProps) {
|
|
15
|
+
const path = useMemo(() => dotPath(area, pitch), [area, pitch]);
|
|
16
|
+
return (
|
|
17
|
+
<View
|
|
18
|
+
position="absolute"
|
|
19
|
+
left={area.x}
|
|
20
|
+
top={area.y}
|
|
21
|
+
width={area.width}
|
|
22
|
+
height={area.height}
|
|
23
|
+
pointerEvents="none"
|
|
24
|
+
aria-hidden
|
|
25
|
+
testID="graph-dots"
|
|
26
|
+
>
|
|
27
|
+
<GraphSvg width={area.width} height={area.height}>
|
|
28
|
+
<GraphPath d={path} stroke={color} strokeWidth={dot} round />
|
|
29
|
+
</GraphSvg>
|
|
30
|
+
</View>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Card, SizableText } from "@multiplatform.one/components";
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react-native-web-vite";
|
|
3
|
+
import { YStack } from "tamagui";
|
|
4
|
+
import { GraphLayout } from "./GraphLayout";
|
|
5
|
+
import type { GraphLayoutEdge, GraphLayoutNode } from "./plan";
|
|
6
|
+
import { ogdenApps, ogdenLinks } from "./ogden.fixture";
|
|
7
|
+
|
|
8
|
+
const apps = [...ogdenApps, "sandbox-a", "sandbox-b", "sandbox-c"];
|
|
9
|
+
const nodes: GraphLayoutNode[] = apps.map((id) => ({ id, width: 96, height: 72 }));
|
|
10
|
+
const edges: GraphLayoutEdge[] = ogdenLinks.map(([source, target], index) => ({
|
|
11
|
+
source,
|
|
12
|
+
target,
|
|
13
|
+
emphasis: index % 13 === 0,
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
function Tile({ id }: { id: string }) {
|
|
17
|
+
return (
|
|
18
|
+
<Card flex={1} alignItems="center" justifyContent="center" testID={`graph-tile-${id}`}>
|
|
19
|
+
<SizableText size="$2" numberOfLines={2} textAlign="center">
|
|
20
|
+
{id}
|
|
21
|
+
</SizableText>
|
|
22
|
+
</Card>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const renderNode = (id: string) => <Tile id={id} />;
|
|
27
|
+
|
|
28
|
+
const meta: Meta<typeof GraphLayout> = {
|
|
29
|
+
title: "NodeGraph/GraphLayout",
|
|
30
|
+
component: GraphLayout,
|
|
31
|
+
parameters: {
|
|
32
|
+
status: { type: "beta" },
|
|
33
|
+
layout: "fullscreen",
|
|
34
|
+
nativeGallery: { scroll: false },
|
|
35
|
+
docs: {
|
|
36
|
+
description: {
|
|
37
|
+
component:
|
|
38
|
+
"A read-only graph of host views (LC-294). Nodes are whatever the host renders at the size it gives; GraphLayout places them with NodeGraph's dagre engine, draws every edge through NodeGraph's own edge path and router in theme tokens, and pans and zooms the canvas over a $color6 dot grid. Edges end on box edges and never run under a node. Emphasis is the theme accent. An editable graph is NodeGraph.",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
export default meta;
|
|
44
|
+
|
|
45
|
+
type Story = StoryObj<typeof GraphLayout>;
|
|
46
|
+
|
|
47
|
+
function Frame(props: Parameters<typeof GraphLayout>[0]) {
|
|
48
|
+
return (
|
|
49
|
+
<YStack height="100vh" width="100%">
|
|
50
|
+
<GraphLayout {...props} />
|
|
51
|
+
</YStack>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const Apps: Story = {
|
|
56
|
+
render: () => <Frame nodes={nodes} edges={edges} renderNode={renderNode} />,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const LeftToRight: Story = {
|
|
60
|
+
render: () => <Frame nodes={nodes} edges={edges} renderNode={renderNode} direction="LR" />,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const TopToBottom: Story = {
|
|
64
|
+
render: () => <Frame nodes={nodes} edges={edges} renderNode={renderNode} direction="TB" />,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const EdgeKinds: Story = {
|
|
68
|
+
render: () => (
|
|
69
|
+
<Frame
|
|
70
|
+
nodes={["source", "flow", "data", "error", "conditional"].map((id) => ({
|
|
71
|
+
id,
|
|
72
|
+
width: 96,
|
|
73
|
+
height: 72,
|
|
74
|
+
}))}
|
|
75
|
+
edges={[
|
|
76
|
+
{ source: "source", target: "flow", kind: "flow" },
|
|
77
|
+
{ source: "source", target: "data", kind: "data" },
|
|
78
|
+
{ source: "source", target: "error", kind: "error" },
|
|
79
|
+
{ source: "source", target: "conditional", kind: "conditional" },
|
|
80
|
+
]}
|
|
81
|
+
renderNode={renderNode}
|
|
82
|
+
direction="LR"
|
|
83
|
+
dots={false}
|
|
84
|
+
/>
|
|
85
|
+
),
|
|
86
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { defaultKnobs, usePresetContext } from "@multiplatform.one/theme";
|
|
2
|
+
import { Fragment, useMemo, useState } from "react";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
import type { LayoutChangeEvent } from "react-native";
|
|
5
|
+
import { getTokenValue, useTheme, View } from "tamagui";
|
|
6
|
+
import { edgeStrokeWidth, themeTokenName } from "../edges/edgeStyle";
|
|
7
|
+
import type { XY } from "../model/document";
|
|
8
|
+
import { GraphPath, GraphSvg } from "./GraphSvg";
|
|
9
|
+
import { GraphViewport } from "./GraphViewport";
|
|
10
|
+
import { planGraphLayout } from "./plan";
|
|
11
|
+
import type { GraphDirection, GraphLayoutEdge, GraphLayoutNode } from "./plan";
|
|
12
|
+
import type { Extent } from "./viewMath";
|
|
13
|
+
|
|
14
|
+
export type GraphSpaceToken = `$${number}`;
|
|
15
|
+
|
|
16
|
+
export interface GraphLayoutProps {
|
|
17
|
+
readonly nodes: readonly GraphLayoutNode[];
|
|
18
|
+
readonly edges: readonly GraphLayoutEdge[];
|
|
19
|
+
readonly renderNode: (id: string) => ReactNode;
|
|
20
|
+
readonly direction?: GraphDirection | "auto";
|
|
21
|
+
readonly positions?: Readonly<Record<string, XY>>;
|
|
22
|
+
readonly spacing?: { readonly node?: GraphSpaceToken; readonly rank?: GraphSpaceToken };
|
|
23
|
+
readonly dots?: boolean;
|
|
24
|
+
readonly frozen?: boolean;
|
|
25
|
+
readonly testID?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function resolveGraphDirection(
|
|
29
|
+
direction: GraphDirection | "auto",
|
|
30
|
+
viewport: Extent,
|
|
31
|
+
): GraphDirection {
|
|
32
|
+
if (direction !== "auto") return direction;
|
|
33
|
+
return viewport.height > viewport.width ? "LR" : "TB";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function space(token: GraphSpaceToken): number {
|
|
37
|
+
const value = getTokenValue(token as Parameters<typeof getTokenValue>[0], "space");
|
|
38
|
+
return typeof value === "number" ? value : 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function useStrokeWidth(): number {
|
|
42
|
+
const preset = usePresetContext();
|
|
43
|
+
const knobs = preset ? { ...preset.preset.knobs, ...preset.overrides } : defaultKnobs;
|
|
44
|
+
return edgeStrokeWidth(knobs.borderWidth);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function useColour(): (token: string) => string {
|
|
48
|
+
const theme = useTheme() as unknown as Record<string, { get?: () => unknown } | undefined>;
|
|
49
|
+
return (token) => {
|
|
50
|
+
const value = theme[themeTokenName(token)]?.get?.();
|
|
51
|
+
return typeof value === "string" ? value : "currentColor";
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function GraphLayout({
|
|
56
|
+
nodes,
|
|
57
|
+
edges,
|
|
58
|
+
renderNode,
|
|
59
|
+
direction = "auto",
|
|
60
|
+
positions,
|
|
61
|
+
spacing,
|
|
62
|
+
dots = true,
|
|
63
|
+
frozen,
|
|
64
|
+
testID = "graph-layout",
|
|
65
|
+
}: GraphLayoutProps) {
|
|
66
|
+
const [viewport, setViewport] = useState<Extent>({ width: 0, height: 0 });
|
|
67
|
+
const strokeWidth = useStrokeWidth();
|
|
68
|
+
const colour = useColour();
|
|
69
|
+
const resolved = resolveGraphDirection(direction, viewport);
|
|
70
|
+
const nodeSpacing = space(spacing?.node ?? "$4");
|
|
71
|
+
const rankSpacing = space(spacing?.rank ?? "$8");
|
|
72
|
+
const margin = space("$4");
|
|
73
|
+
const pitch = space("$6");
|
|
74
|
+
const plan = useMemo(
|
|
75
|
+
() =>
|
|
76
|
+
planGraphLayout({
|
|
77
|
+
nodes,
|
|
78
|
+
edges,
|
|
79
|
+
direction: resolved,
|
|
80
|
+
nodeSpacing,
|
|
81
|
+
rankSpacing,
|
|
82
|
+
margin,
|
|
83
|
+
strokeWidth,
|
|
84
|
+
wrapWidth: viewport.width > 0 ? viewport.width - margin * 2 : undefined,
|
|
85
|
+
positions,
|
|
86
|
+
}),
|
|
87
|
+
[
|
|
88
|
+
nodes,
|
|
89
|
+
edges,
|
|
90
|
+
resolved,
|
|
91
|
+
nodeSpacing,
|
|
92
|
+
rankSpacing,
|
|
93
|
+
margin,
|
|
94
|
+
strokeWidth,
|
|
95
|
+
viewport.width,
|
|
96
|
+
positions,
|
|
97
|
+
],
|
|
98
|
+
);
|
|
99
|
+
const onLayout = (event: LayoutChangeEvent) => {
|
|
100
|
+
const { width, height } = event.nativeEvent.layout;
|
|
101
|
+
if (width !== viewport.width || height !== viewport.height) setViewport({ width, height });
|
|
102
|
+
};
|
|
103
|
+
const content = {
|
|
104
|
+
width: Math.max(plan.width, viewport.width),
|
|
105
|
+
height: Math.max(plan.height, viewport.height),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<View flex={1} onLayout={onLayout} testID={testID} data-graph-direction={resolved}>
|
|
110
|
+
{viewport.width > 0 && viewport.height > 0 ? (
|
|
111
|
+
<GraphViewport
|
|
112
|
+
content={content}
|
|
113
|
+
viewport={viewport}
|
|
114
|
+
dots={dots ? { pitch, dot: strokeWidth, color: colour("$color6") } : undefined}
|
|
115
|
+
frozen={frozen}
|
|
116
|
+
>
|
|
117
|
+
<View width={content.width} height={content.height}>
|
|
118
|
+
<GraphSvg width={plan.width} height={plan.height}>
|
|
119
|
+
{plan.edges.map((edge) => {
|
|
120
|
+
const paint = colour(edge.stroke);
|
|
121
|
+
return (
|
|
122
|
+
<Fragment key={edge.id}>
|
|
123
|
+
<GraphPath
|
|
124
|
+
d={edge.d}
|
|
125
|
+
stroke={paint}
|
|
126
|
+
strokeWidth={edge.emphasis ? strokeWidth * 2 : strokeWidth}
|
|
127
|
+
dash={edge.dash}
|
|
128
|
+
/>
|
|
129
|
+
<GraphPath d={edge.head} fill={paint} />
|
|
130
|
+
</Fragment>
|
|
131
|
+
);
|
|
132
|
+
})}
|
|
133
|
+
</GraphSvg>
|
|
134
|
+
{plan.nodes.map((node) => (
|
|
135
|
+
<View
|
|
136
|
+
key={node.id}
|
|
137
|
+
position="absolute"
|
|
138
|
+
left={node.x}
|
|
139
|
+
top={node.y}
|
|
140
|
+
width={node.width}
|
|
141
|
+
height={node.height}
|
|
142
|
+
testID={`graph-node-${node.id}`}
|
|
143
|
+
>
|
|
144
|
+
{renderNode(node.id)}
|
|
145
|
+
</View>
|
|
146
|
+
))}
|
|
147
|
+
</View>
|
|
148
|
+
</GraphViewport>
|
|
149
|
+
) : null}
|
|
150
|
+
</View>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Path, Svg } from "react-native-svg";
|
|
2
|
+
import type { GraphPathProps, GraphSvgProps } from "./GraphSvg";
|
|
3
|
+
|
|
4
|
+
export type { GraphPathProps, GraphSvgProps } from "./GraphSvg";
|
|
5
|
+
|
|
6
|
+
export function GraphSvg({ width, height, children }: GraphSvgProps) {
|
|
7
|
+
return (
|
|
8
|
+
<Svg
|
|
9
|
+
width={width}
|
|
10
|
+
height={height}
|
|
11
|
+
pointerEvents="none"
|
|
12
|
+
style={{ position: "absolute", left: 0, top: 0, overflow: "visible" }}
|
|
13
|
+
>
|
|
14
|
+
{children}
|
|
15
|
+
</Svg>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function GraphPath({ d, stroke, strokeWidth, dash, fill, round }: GraphPathProps) {
|
|
20
|
+
return (
|
|
21
|
+
<Path
|
|
22
|
+
d={d}
|
|
23
|
+
fill={fill ?? "none"}
|
|
24
|
+
stroke={stroke ?? "none"}
|
|
25
|
+
strokeWidth={strokeWidth}
|
|
26
|
+
strokeDasharray={dash}
|
|
27
|
+
strokeLinecap={round ? "round" : "butt"}
|
|
28
|
+
strokeLinejoin="round"
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|