@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.
Files changed (201) hide show
  1. package/dist/cjs/graphLayout/GraphDots.cjs +60 -0
  2. package/dist/cjs/graphLayout/GraphDots.native.js +66 -0
  3. package/dist/cjs/graphLayout/GraphDots.native.js.map +1 -0
  4. package/dist/cjs/graphLayout/GraphLayout.cjs +153 -0
  5. package/dist/cjs/graphLayout/GraphLayout.native.js +163 -0
  6. package/dist/cjs/graphLayout/GraphLayout.native.js.map +1 -0
  7. package/dist/cjs/graphLayout/GraphSvg.cjs +68 -0
  8. package/dist/cjs/graphLayout/GraphSvg.native.js +73 -0
  9. package/dist/cjs/graphLayout/GraphSvg.native.js.map +1 -0
  10. package/dist/cjs/graphLayout/GraphViewport.cjs +264 -0
  11. package/dist/cjs/graphLayout/GraphViewport.native.js +280 -0
  12. package/dist/cjs/graphLayout/GraphViewport.native.js.map +1 -0
  13. package/dist/cjs/graphLayout/index.cjs +51 -0
  14. package/dist/cjs/graphLayout/index.native.js +54 -0
  15. package/dist/cjs/graphLayout/index.native.js.map +1 -0
  16. package/dist/cjs/graphLayout/ogden.fixture.cjs +30 -0
  17. package/dist/cjs/graphLayout/ogden.fixture.native.js +33 -0
  18. package/dist/cjs/graphLayout/ogden.fixture.native.js.map +1 -0
  19. package/dist/cjs/graphLayout/plan.cjs +263 -0
  20. package/dist/cjs/graphLayout/plan.native.js +372 -0
  21. package/dist/cjs/graphLayout/plan.native.js.map +1 -0
  22. package/dist/cjs/graphLayout/viewMath.cjs +142 -0
  23. package/dist/cjs/graphLayout/viewMath.native.js +147 -0
  24. package/dist/cjs/graphLayout/viewMath.native.js.map +1 -0
  25. package/dist/esm/NodeGraph.native.js.map +1 -1
  26. package/dist/esm/bench/frameSampler.native.js.map +1 -1
  27. package/dist/esm/bench/generateGraph.native.js.map +1 -1
  28. package/dist/esm/diagnostics/GraphDiagnostics.native.js.map +1 -1
  29. package/dist/esm/diagnostics/LiveGraphDiagnostics.native.js.map +1 -1
  30. package/dist/esm/diagnostics/fromWire.native.js.map +1 -1
  31. package/dist/esm/diagnostics/lastError.native.js.map +1 -1
  32. package/dist/esm/diagnostics/types.native.js.map +1 -1
  33. package/dist/esm/diagnostics/useGraphDiagnostics.native.js.map +1 -1
  34. package/dist/esm/dom/GraphDomLayout.native.js.map +1 -1
  35. package/dist/esm/dom/boot.native.js.map +1 -1
  36. package/dist/esm/dom/wire.native.js.map +1 -1
  37. package/dist/esm/edges/GraphEdge.native.js.map +1 -1
  38. package/dist/esm/edges/edgeKinds.native.js.map +1 -1
  39. package/dist/esm/edges/edgePath.native.js.map +1 -1
  40. package/dist/esm/edges/edgeRoute.native.js.map +1 -1
  41. package/dist/esm/edges/edgeStyle.native.js.map +1 -1
  42. package/dist/esm/edges/useEdgeObstacles.native.js.map +1 -1
  43. package/dist/esm/graphLayout/GraphDots.mjs +35 -0
  44. package/dist/esm/graphLayout/GraphDots.mjs.map +1 -0
  45. package/dist/esm/graphLayout/GraphDots.native.js +38 -0
  46. package/dist/esm/graphLayout/GraphDots.native.js.map +1 -0
  47. package/dist/esm/graphLayout/GraphLayout.mjs +127 -0
  48. package/dist/esm/graphLayout/GraphLayout.mjs.map +1 -0
  49. package/dist/esm/graphLayout/GraphLayout.native.js +134 -0
  50. package/dist/esm/graphLayout/GraphLayout.native.js.map +1 -0
  51. package/dist/esm/graphLayout/GraphSvg.mjs +42 -0
  52. package/dist/esm/graphLayout/GraphSvg.mjs.map +1 -0
  53. package/dist/esm/graphLayout/GraphSvg.native.js +44 -0
  54. package/dist/esm/graphLayout/GraphSvg.native.js.map +1 -0
  55. package/dist/esm/graphLayout/GraphViewport.mjs +239 -0
  56. package/dist/esm/graphLayout/GraphViewport.mjs.map +1 -0
  57. package/dist/esm/graphLayout/GraphViewport.native.js +252 -0
  58. package/dist/esm/graphLayout/GraphViewport.native.js.map +1 -0
  59. package/dist/esm/graphLayout/index.mjs +7 -0
  60. package/dist/esm/graphLayout/index.mjs.map +1 -0
  61. package/dist/esm/graphLayout/index.native.js +7 -0
  62. package/dist/esm/graphLayout/index.native.js.map +1 -0
  63. package/dist/esm/graphLayout/ogden.fixture.mjs +4 -0
  64. package/dist/esm/graphLayout/ogden.fixture.mjs.map +1 -0
  65. package/dist/esm/graphLayout/ogden.fixture.native.js +4 -0
  66. package/dist/esm/graphLayout/ogden.fixture.native.js.map +1 -0
  67. package/dist/esm/graphLayout/plan.mjs +235 -0
  68. package/dist/esm/graphLayout/plan.mjs.map +1 -0
  69. package/dist/esm/graphLayout/plan.native.js +341 -0
  70. package/dist/esm/graphLayout/plan.native.js.map +1 -0
  71. package/dist/esm/graphLayout/viewMath.mjs +105 -0
  72. package/dist/esm/graphLayout/viewMath.mjs.map +1 -0
  73. package/dist/esm/graphLayout/viewMath.native.js +107 -0
  74. package/dist/esm/graphLayout/viewMath.native.js.map +1 -0
  75. package/dist/esm/index.native.js.map +1 -1
  76. package/dist/esm/interaction/lassoIntercept.native.js.map +1 -1
  77. package/dist/esm/interaction/legalTargets.native.js.map +1 -1
  78. package/dist/esm/interaction/snapAlignment.native.js.map +1 -1
  79. package/dist/esm/interaction/snapChanges.native.js.map +1 -1
  80. package/dist/esm/interaction/spatialHash.native.js.map +1 -1
  81. package/dist/esm/interaction/useLassoSelect.native.js.map +1 -1
  82. package/dist/esm/knobs/KnobEnvelopeProvider.native.js.map +1 -1
  83. package/dist/esm/knobs/envelope.native.js.map +1 -1
  84. package/dist/esm/knobs/graphKnobs.native.js.map +1 -1
  85. package/dist/esm/knobs/useKnobEnvelope.native.js.map +1 -1
  86. package/dist/esm/layout/dagre.native.js.map +1 -1
  87. package/dist/esm/layout/layout.native.js.map +1 -1
  88. package/dist/esm/layout/runner.native.js.map +1 -1
  89. package/dist/esm/layout/structuredCloneShim.native.js.map +1 -1
  90. package/dist/esm/layout/types.native.js.map +1 -1
  91. package/dist/esm/layout/worker.entry.native.js.map +1 -1
  92. package/dist/esm/layout/worker.generated.native.js.map +1 -1
  93. package/dist/esm/model/commands.native.js.map +1 -1
  94. package/dist/esm/model/connect.native.js.map +1 -1
  95. package/dist/esm/model/document.native.js.map +1 -1
  96. package/dist/esm/model/history.native.js.map +1 -1
  97. package/dist/esm/model/index.native.js.map +1 -1
  98. package/dist/esm/model/schema.native.js.map +1 -1
  99. package/dist/esm/model/select.native.js.map +1 -1
  100. package/dist/esm/model/serialize.native.js.map +1 -1
  101. package/dist/esm/native/DomOnlyStory.native.js.map +1 -1
  102. package/dist/esm/native/GraphToolbar.native.js.map +1 -1
  103. package/dist/esm/native/domEntryRegistry.native.js.map +1 -1
  104. package/dist/esm/native/graphChildren.native.js.map +1 -1
  105. package/dist/esm/nodes/GraphNode.native.js.map +1 -1
  106. package/dist/esm/nodes/GraphPort.native.js.map +1 -1
  107. package/dist/esm/nodes/handleGeometry.native.js.map +1 -1
  108. package/dist/esm/nodes/lod.native.js.map +1 -1
  109. package/dist/esm/nodes/nodeMeasure.native.js.map +1 -1
  110. package/dist/esm/nodes/overviewNode.native.js.map +1 -1
  111. package/dist/esm/react-flow/ConnectionPuck.native.js.map +1 -1
  112. package/dist/esm/react-flow/GraphActions.native.js.map +1 -1
  113. package/dist/esm/react-flow/GraphCommandBridge.native.js.map +1 -1
  114. package/dist/esm/react-flow/GraphNodeHost.native.js.map +1 -1
  115. package/dist/esm/react-flow/GraphPaintProbe.native.js.map +1 -1
  116. package/dist/esm/react-flow/GraphZoomVar.native.js.map +1 -1
  117. package/dist/esm/react-flow/LassoOverlay.native.js.map +1 -1
  118. package/dist/esm/react-flow/NodeGraphWeb.native.js.map +1 -1
  119. package/dist/esm/react-flow/SnapGuides.native.js.map +1 -1
  120. package/dist/esm/react-flow/demoControlBody.native.js.map +1 -1
  121. package/dist/esm/react-flow/demoNodeBody.native.js.map +1 -1
  122. package/dist/esm/react-flow/fixtures.native.js.map +1 -1
  123. package/dist/esm/react-flow/flowAdapter.native.js.map +1 -1
  124. package/dist/esm/react-flow/graphHandle.native.js.map +1 -1
  125. package/dist/esm/react-flow/nodeCensus.native.js.map +1 -1
  126. package/dist/esm/react-flow/useGraphController.native.js.map +1 -1
  127. package/dist/esm/react-flow/xy.native.js.map +1 -1
  128. package/dist/esm/react-flow/xyPaths.native.js.map +1 -1
  129. package/dist/esm/theme/GraphFaces.native.js.map +1 -1
  130. package/dist/esm/theme/GraphVarsStyle.native.js.map +1 -1
  131. package/dist/esm/theme/faces.generated.native.js.map +1 -1
  132. package/dist/esm/theme/faces.native.js.map +1 -1
  133. package/dist/esm/theme/graphVars.native.js.map +1 -1
  134. package/dist/jsx/graphLayout/GraphDots.mjs +35 -0
  135. package/dist/jsx/graphLayout/GraphDots.mjs.map +1 -0
  136. package/dist/jsx/graphLayout/GraphDots.native.js +66 -0
  137. package/dist/jsx/graphLayout/GraphDots.native.js.map +1 -0
  138. package/dist/jsx/graphLayout/GraphLayout.mjs +127 -0
  139. package/dist/jsx/graphLayout/GraphLayout.mjs.map +1 -0
  140. package/dist/jsx/graphLayout/GraphLayout.native.js +163 -0
  141. package/dist/jsx/graphLayout/GraphLayout.native.js.map +1 -0
  142. package/dist/jsx/graphLayout/GraphSvg.mjs +42 -0
  143. package/dist/jsx/graphLayout/GraphSvg.mjs.map +1 -0
  144. package/dist/jsx/graphLayout/GraphSvg.native.js +73 -0
  145. package/dist/jsx/graphLayout/GraphSvg.native.js.map +1 -0
  146. package/dist/jsx/graphLayout/GraphViewport.mjs +239 -0
  147. package/dist/jsx/graphLayout/GraphViewport.mjs.map +1 -0
  148. package/dist/jsx/graphLayout/GraphViewport.native.js +280 -0
  149. package/dist/jsx/graphLayout/GraphViewport.native.js.map +1 -0
  150. package/dist/jsx/graphLayout/index.mjs +7 -0
  151. package/dist/jsx/graphLayout/index.mjs.map +1 -0
  152. package/dist/jsx/graphLayout/index.native.js +54 -0
  153. package/dist/jsx/graphLayout/index.native.js.map +1 -0
  154. package/dist/jsx/graphLayout/ogden.fixture.mjs +4 -0
  155. package/dist/jsx/graphLayout/ogden.fixture.mjs.map +1 -0
  156. package/dist/jsx/graphLayout/ogden.fixture.native.js +33 -0
  157. package/dist/jsx/graphLayout/ogden.fixture.native.js.map +1 -0
  158. package/dist/jsx/graphLayout/plan.mjs +235 -0
  159. package/dist/jsx/graphLayout/plan.mjs.map +1 -0
  160. package/dist/jsx/graphLayout/plan.native.js +372 -0
  161. package/dist/jsx/graphLayout/plan.native.js.map +1 -0
  162. package/dist/jsx/graphLayout/viewMath.mjs +105 -0
  163. package/dist/jsx/graphLayout/viewMath.mjs.map +1 -0
  164. package/dist/jsx/graphLayout/viewMath.native.js +147 -0
  165. package/dist/jsx/graphLayout/viewMath.native.js.map +1 -0
  166. package/graph-layout.ts +1 -0
  167. package/package.json +21 -6
  168. package/src/graphLayout/GraphDots.tsx +32 -0
  169. package/src/graphLayout/GraphLayout.stories.tsx +86 -0
  170. package/src/graphLayout/GraphLayout.tsx +152 -0
  171. package/src/graphLayout/GraphSvg.native.tsx +31 -0
  172. package/src/graphLayout/GraphSvg.tsx +45 -0
  173. package/src/graphLayout/GraphViewport.native.tsx +231 -0
  174. package/src/graphLayout/GraphViewport.tsx +247 -0
  175. package/src/graphLayout/index.ts +31 -0
  176. package/src/graphLayout/ogden.fixture.ts +120 -0
  177. package/src/graphLayout/plan.spec.ts +202 -0
  178. package/src/graphLayout/plan.ts +223 -0
  179. package/src/graphLayout/purity.spec.ts +67 -0
  180. package/src/graphLayout/viewMath.spec.ts +185 -0
  181. package/src/graphLayout/viewMath.ts +151 -0
  182. package/types/graphLayout/GraphDots.d.ts +9 -0
  183. package/types/graphLayout/GraphDots.d.ts.map +1 -0
  184. package/types/graphLayout/GraphLayout.d.ts +22 -0
  185. package/types/graphLayout/GraphLayout.d.ts.map +1 -0
  186. package/types/graphLayout/GraphSvg.d.ts +17 -0
  187. package/types/graphLayout/GraphSvg.d.ts.map +1 -0
  188. package/types/graphLayout/GraphSvg.native.d.ts +5 -0
  189. package/types/graphLayout/GraphSvg.native.d.ts.map +1 -0
  190. package/types/graphLayout/GraphViewport.d.ts +11 -0
  191. package/types/graphLayout/GraphViewport.d.ts.map +1 -0
  192. package/types/graphLayout/GraphViewport.native.d.ts +4 -0
  193. package/types/graphLayout/GraphViewport.native.d.ts.map +1 -0
  194. package/types/graphLayout/index.d.ts +11 -0
  195. package/types/graphLayout/index.d.ts.map +1 -0
  196. package/types/graphLayout/ogden.fixture.d.ts +3 -0
  197. package/types/graphLayout/ogden.fixture.d.ts.map +1 -0
  198. package/types/graphLayout/plan.d.ts +52 -0
  199. package/types/graphLayout/plan.d.ts.map +1 -0
  200. package/types/graphLayout/viewMath.d.ts +47 -0
  201. package/types/graphLayout/viewMath.d.ts.map +1 -0
@@ -0,0 +1,45 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ export interface GraphSvgProps {
4
+ readonly width: number;
5
+ readonly height: number;
6
+ readonly children: ReactNode;
7
+ }
8
+
9
+ export interface GraphPathProps {
10
+ readonly d: string;
11
+ readonly stroke?: string;
12
+ readonly strokeWidth?: number;
13
+ readonly dash?: string;
14
+ readonly fill?: string;
15
+ readonly round?: boolean;
16
+ }
17
+
18
+ export function GraphSvg({ width, height, children }: GraphSvgProps) {
19
+ return (
20
+ <svg
21
+ width={width}
22
+ height={height}
23
+ aria-hidden
24
+ style={{ position: "absolute", left: 0, top: 0, overflow: "visible", pointerEvents: "none" }}
25
+ >
26
+ {children}
27
+ </svg>
28
+ );
29
+ }
30
+
31
+ export function GraphPath({ d, stroke, strokeWidth, dash, fill, round }: GraphPathProps) {
32
+ return (
33
+ <path
34
+ d={d}
35
+ style={{
36
+ fill: fill ?? "none",
37
+ stroke: stroke ?? "none",
38
+ strokeWidth,
39
+ strokeDasharray: dash,
40
+ strokeLinecap: round ? "round" : "butt",
41
+ strokeLinejoin: "round",
42
+ }}
43
+ />
44
+ );
45
+ }
@@ -0,0 +1,231 @@
1
+ import { useEffect, useMemo, useState } from "react";
2
+ import { StyleSheet } from "react-native";
3
+ import { Gesture, GestureDetector } from "react-native-gesture-handler";
4
+ import Animated, {
5
+ cancelAnimation,
6
+ runOnJS,
7
+ useAnimatedReaction,
8
+ useAnimatedStyle,
9
+ useSharedValue,
10
+ withDecay,
11
+ withTiming,
12
+ } from "react-native-reanimated";
13
+ import type { SharedValue } from "react-native-reanimated";
14
+ import { View } from "tamagui";
15
+ import { GraphDots } from "./GraphDots";
16
+ import type { GraphViewportProps } from "./GraphViewport";
17
+ import {
18
+ clampOffset,
19
+ clampView,
20
+ dotPhase,
21
+ dotPitch,
22
+ graphZoom,
23
+ toggledView,
24
+ zoomAt,
25
+ } from "./viewMath";
26
+ import type { Extent, GraphDots as GraphDotsSpec } from "./viewMath";
27
+
28
+ export type { GraphViewportProps } from "./GraphViewport";
29
+
30
+ export function GraphViewport({ content, viewport, dots, frozen, children }: GraphViewportProps) {
31
+ const start = clampView({ scale: 1, x: 0, y: 0 }, content, viewport);
32
+ const scale = useSharedValue(start.scale);
33
+ const x = useSharedValue(start.x);
34
+ const y = useSharedValue(start.y);
35
+ const pinching = useSharedValue(0);
36
+ const focalX = useSharedValue(0);
37
+ const focalY = useSharedValue(0);
38
+ const held = useSharedValue(frozen ? 1 : 0);
39
+ const { width: cw, height: ch } = content;
40
+ const { width: vw, height: vh } = viewport;
41
+
42
+ useEffect(() => {
43
+ const next = clampView(
44
+ { scale: scale.value, x: x.value, y: y.value },
45
+ { width: cw, height: ch },
46
+ { width: vw, height: vh },
47
+ );
48
+ scale.value = next.scale;
49
+ x.value = next.x;
50
+ y.value = next.y;
51
+ }, [cw, ch, vw, vh, scale, x, y]);
52
+
53
+ useEffect(() => {
54
+ held.value = frozen ? 1 : 0;
55
+ }, [frozen, held]);
56
+
57
+ const gesture = useMemo(() => {
58
+ const size = { width: cw, height: ch };
59
+ const view = { width: vw, height: vh };
60
+ const pan = Gesture.Pan()
61
+ .maxPointers(1)
62
+ .onStart(() => {
63
+ "worklet";
64
+ if (held.value) return;
65
+ cancelAnimation(x);
66
+ cancelAnimation(y);
67
+ })
68
+ .onChange((event) => {
69
+ "worklet";
70
+ if (pinching.value || held.value) return;
71
+ x.value = clampOffset(x.value + event.changeX, cw * scale.value, vw);
72
+ y.value = clampOffset(y.value + event.changeY, ch * scale.value, vh);
73
+ })
74
+ .onEnd((event) => {
75
+ "worklet";
76
+ if (pinching.value || held.value) return;
77
+ const wide = cw * scale.value;
78
+ const tall = ch * scale.value;
79
+ x.value = withDecay({
80
+ velocity: event.velocityX,
81
+ clamp: [clampOffset(-Infinity, wide, vw), clampOffset(Infinity, wide, vw)],
82
+ });
83
+ y.value = withDecay({
84
+ velocity: event.velocityY,
85
+ clamp: [clampOffset(-Infinity, tall, vh), clampOffset(Infinity, tall, vh)],
86
+ });
87
+ });
88
+ const pinch = Gesture.Pinch()
89
+ .onStart((event) => {
90
+ "worklet";
91
+ pinching.value = 1;
92
+ if (held.value) return;
93
+ cancelAnimation(x);
94
+ cancelAnimation(y);
95
+ cancelAnimation(scale);
96
+ focalX.value = event.focalX;
97
+ focalY.value = event.focalY;
98
+ })
99
+ .onChange((event) => {
100
+ "worklet";
101
+ if (held.value) return;
102
+ const next = zoomAt(
103
+ {
104
+ scale: scale.value,
105
+ x: x.value + event.focalX - focalX.value,
106
+ y: y.value + event.focalY - focalY.value,
107
+ },
108
+ scale.value * event.scaleChange,
109
+ { x: event.focalX, y: event.focalY },
110
+ size,
111
+ view,
112
+ );
113
+ focalX.value = event.focalX;
114
+ focalY.value = event.focalY;
115
+ scale.value = next.scale;
116
+ x.value = next.x;
117
+ y.value = next.y;
118
+ })
119
+ .onFinalize(() => {
120
+ "worklet";
121
+ pinching.value = 0;
122
+ });
123
+ const reset = Gesture.Tap()
124
+ .numberOfTaps(2)
125
+ .onEnd((event, success) => {
126
+ "worklet";
127
+ if (!success || held.value) return;
128
+ const next = toggledView(
129
+ { scale: scale.value, x: x.value, y: y.value },
130
+ { x: event.x, y: event.y },
131
+ size,
132
+ view,
133
+ );
134
+ scale.value = withTiming(next.scale, { duration: graphZoom.settleMs });
135
+ x.value = withTiming(next.x, { duration: graphZoom.settleMs });
136
+ y.value = withTiming(next.y, { duration: graphZoom.settleMs });
137
+ });
138
+ return Gesture.Race(reset, Gesture.Simultaneous(pinch, pan));
139
+ }, [cw, ch, vw, vh, scale, x, y, pinching, focalX, focalY, held]);
140
+
141
+ const placed = useAnimatedStyle(() => ({
142
+ transform: [
143
+ { translateX: x.value - ((1 - scale.value) * cw) / 2 },
144
+ { translateY: y.value - ((1 - scale.value) * ch) / 2 },
145
+ { scale: scale.value },
146
+ ],
147
+ }));
148
+
149
+ return (
150
+ <GestureDetector gesture={gesture}>
151
+ <Animated.View style={styles.viewport} collapsable={false} testID="graph-viewport">
152
+ {dots ? <DotLayer viewport={viewport} dots={dots} scale={scale} x={x} y={y} /> : null}
153
+ <Animated.View style={[styles.content, placed]}>
154
+ <View width={cw} height={ch}>
155
+ {children}
156
+ </View>
157
+ </Animated.View>
158
+ </Animated.View>
159
+ </GestureDetector>
160
+ );
161
+ }
162
+
163
+ function DotLayer({
164
+ viewport,
165
+ dots,
166
+ scale,
167
+ x,
168
+ y,
169
+ }: {
170
+ viewport: Extent;
171
+ dots: GraphDotsSpec;
172
+ scale: SharedValue<number>;
173
+ x: SharedValue<number>;
174
+ y: SharedValue<number>;
175
+ }) {
176
+ const [drawn, setDrawn] = useState(() => scale.value);
177
+ const spaced = dotPitch(dots.pitch, drawn);
178
+ const step = spaced * drawn;
179
+ const width = viewport.width / 0.85 + step * 2;
180
+ const height = viewport.height / 0.85 + step * 2;
181
+ const pitch = dots.pitch;
182
+ useAnimatedReaction(
183
+ () => scale.value,
184
+ (now) => {
185
+ if (Math.abs(now / drawn - 1) > 0.1 || dotPitch(pitch, now) !== spaced)
186
+ runOnJS(setDrawn)(now);
187
+ },
188
+ [drawn, spaced, pitch],
189
+ );
190
+ const placed = useAnimatedStyle(() => {
191
+ const ratio = scale.value / drawn;
192
+ const shift = (axis: number, offset: number) =>
193
+ dotPhase(offset, scale.value, pitch, spaced) - (ratio * step) / 2 - (axis / 2) * (1 - ratio);
194
+ return {
195
+ transform: [
196
+ { translateX: shift(width, x.value) },
197
+ { translateY: shift(height, y.value) },
198
+ { scale: ratio },
199
+ ],
200
+ };
201
+ });
202
+ return (
203
+ <Animated.View pointerEvents="none" style={[styles.dots, placed]}>
204
+ <View width={width} height={height}>
205
+ <GraphDots
206
+ area={{ x: 0, y: 0, width, height }}
207
+ pitch={step}
208
+ dot={dots.dot}
209
+ color={dots.color}
210
+ />
211
+ </View>
212
+ </Animated.View>
213
+ );
214
+ }
215
+
216
+ const styles = StyleSheet.create({
217
+ viewport: {
218
+ flex: 1,
219
+ overflow: "hidden",
220
+ },
221
+ content: {
222
+ position: "absolute",
223
+ left: 0,
224
+ top: 0,
225
+ },
226
+ dots: {
227
+ position: "absolute",
228
+ left: 0,
229
+ top: 0,
230
+ },
231
+ });
@@ -0,0 +1,247 @@
1
+ import { useEffect, useLayoutEffect, useRef, useState } from "react";
2
+ import type { ReactNode } from "react";
3
+ import type { NativeScrollEvent, NativeSyntheticEvent } from "react-native";
4
+ import { ScrollView, View } from "tamagui";
5
+ import { GraphDots } from "./GraphDots";
6
+ import {
7
+ dotArea,
8
+ dotPitch,
9
+ keyedView,
10
+ leastScale,
11
+ sameArea,
12
+ toggledView,
13
+ zoomAt,
14
+ } from "./viewMath";
15
+ import type { Extent, GraphDots as GraphDotsSpec, GraphView } from "./viewMath";
16
+
17
+ export interface GraphViewportProps {
18
+ readonly content: Extent;
19
+ readonly viewport: Extent;
20
+ readonly dots?: GraphDotsSpec;
21
+ readonly frozen?: boolean;
22
+ readonly children: ReactNode;
23
+ }
24
+
25
+ type Point = { x: number; y: number };
26
+
27
+ interface Scrollable {
28
+ getScrollableNode?: () => HTMLElement | null;
29
+ }
30
+
31
+ function editable(target: EventTarget | null): boolean {
32
+ const element = target as { isContentEditable?: boolean; tagName?: string } | null;
33
+ return (
34
+ Boolean(element?.isContentEditable) ||
35
+ ["INPUT", "TEXTAREA", "SELECT"].includes(element?.tagName ?? "")
36
+ );
37
+ }
38
+
39
+ function onNode(target: EventTarget | null): boolean {
40
+ const element = target as { closest?: (selector: string) => unknown } | null;
41
+ return Boolean(element?.closest?.("[data-testid^='graph-node-']"));
42
+ }
43
+
44
+ export function GraphViewport({ content, viewport, dots, frozen, children }: GraphViewportProps) {
45
+ const scroller = useRef<Scrollable>(null);
46
+ const [scale, setScale] = useState(1);
47
+ const [scroll, setScroll] = useState<Point>({ x: 0, y: 0 });
48
+ const offset = useRef<Point>({ x: 0, y: 0 });
49
+ const pending = useRef<Point | undefined>(undefined);
50
+ const shown = Math.min(1, Math.max(leastScale(content, viewport), scale));
51
+ const wide = content.width * shown;
52
+ const tall = content.height * shown;
53
+ const pad = {
54
+ x: Math.max(0, (viewport.width - wide) / 2),
55
+ y: Math.max(0, (viewport.height - tall) / 2),
56
+ };
57
+ const live = useRef({ shown, pad, content, viewport, frozen });
58
+ live.current = { shown, pad, content, viewport, frozen };
59
+
60
+ const node = () => scroller.current?.getScrollableNode?.() ?? undefined;
61
+ const now = (): GraphView => ({
62
+ scale: live.current.shown,
63
+ x: live.current.pad.x - offset.current.x,
64
+ y: live.current.pad.y - offset.current.y,
65
+ });
66
+ const apply = (next: GraphView) => {
67
+ const { content: size, viewport: view } = live.current;
68
+ const padX = Math.max(0, (view.width - size.width * next.scale) / 2);
69
+ const padY = Math.max(0, (view.height - size.height * next.scale) / 2);
70
+ pending.current = { x: Math.max(0, padX - next.x), y: Math.max(0, padY - next.y) };
71
+ setScale(next.scale);
72
+ };
73
+ const applyRef = useRef(apply);
74
+ applyRef.current = apply;
75
+ const nowRef = useRef(now);
76
+ nowRef.current = now;
77
+
78
+ useLayoutEffect(() => {
79
+ const target = pending.current;
80
+ const element = node();
81
+ if (!target) return;
82
+ pending.current = undefined;
83
+ offset.current = target;
84
+ setScroll(target);
85
+ if (element) {
86
+ element.scrollLeft = target.x;
87
+ element.scrollTop = target.y;
88
+ }
89
+ }, [shown]);
90
+
91
+ useEffect(() => {
92
+ const element = node();
93
+ if (!element || typeof element.addEventListener !== "function") return;
94
+ element.style.touchAction = "pan-x pan-y";
95
+ element.tabIndex = 0;
96
+ const at = (clientX: number, clientY: number): Point => {
97
+ const box = element.getBoundingClientRect();
98
+ return { x: clientX - box.left, y: clientY - box.top };
99
+ };
100
+ const onWheel = (event: WheelEvent) => {
101
+ if (live.current.frozen || (!event.ctrlKey && !event.metaKey)) return;
102
+ event.preventDefault();
103
+ const current = nowRef.current();
104
+ const factor = 1.002 ** -event.deltaY;
105
+ applyRef.current(
106
+ zoomAt(
107
+ current,
108
+ current.scale * factor,
109
+ at(event.clientX, event.clientY),
110
+ live.current.content,
111
+ live.current.viewport,
112
+ ),
113
+ );
114
+ };
115
+ const onDouble = (event: MouseEvent) => {
116
+ if (live.current.frozen || onNode(event.target)) return;
117
+ applyRef.current(
118
+ toggledView(
119
+ nowRef.current(),
120
+ at(event.clientX, event.clientY),
121
+ live.current.content,
122
+ live.current.viewport,
123
+ ),
124
+ );
125
+ };
126
+ const onKey = (event: KeyboardEvent) => {
127
+ if (
128
+ live.current.frozen ||
129
+ event.ctrlKey ||
130
+ event.metaKey ||
131
+ event.altKey ||
132
+ editable(event.target)
133
+ )
134
+ return;
135
+ const next = keyedView(
136
+ event.key,
137
+ nowRef.current(),
138
+ live.current.content,
139
+ live.current.viewport,
140
+ );
141
+ if (!next) return;
142
+ event.preventDefault();
143
+ applyRef.current(next);
144
+ };
145
+ let pinch: { distance: number; scale: number } | undefined;
146
+ const spread = (touches: TouchList) =>
147
+ Math.hypot(
148
+ touches[0]!.clientX - touches[1]!.clientX,
149
+ touches[0]!.clientY - touches[1]!.clientY,
150
+ );
151
+ const middle = (touches: TouchList) =>
152
+ at(
153
+ (touches[0]!.clientX + touches[1]!.clientX) / 2,
154
+ (touches[0]!.clientY + touches[1]!.clientY) / 2,
155
+ );
156
+ const onTouchStart = (event: TouchEvent) => {
157
+ pinch =
158
+ event.touches.length === 2
159
+ ? { distance: spread(event.touches), scale: nowRef.current().scale }
160
+ : undefined;
161
+ };
162
+ const onTouchMove = (event: TouchEvent) => {
163
+ if (live.current.frozen || !pinch || event.touches.length !== 2) return;
164
+ event.preventDefault();
165
+ const ratio = spread(event.touches) / Math.max(1, pinch.distance);
166
+ applyRef.current(
167
+ zoomAt(
168
+ nowRef.current(),
169
+ pinch.scale * ratio,
170
+ middle(event.touches),
171
+ live.current.content,
172
+ live.current.viewport,
173
+ ),
174
+ );
175
+ };
176
+ const onTouchEnd = (event: TouchEvent) => {
177
+ if (event.touches.length < 2) pinch = undefined;
178
+ };
179
+ element.addEventListener("wheel", onWheel, { passive: false });
180
+ element.addEventListener("dblclick", onDouble);
181
+ element.addEventListener("keydown", onKey);
182
+ element.addEventListener("touchstart", onTouchStart, { passive: true });
183
+ element.addEventListener("touchmove", onTouchMove, { passive: false });
184
+ element.addEventListener("touchend", onTouchEnd);
185
+ return () => {
186
+ element.removeEventListener("wheel", onWheel);
187
+ element.removeEventListener("dblclick", onDouble);
188
+ element.removeEventListener("keydown", onKey);
189
+ element.removeEventListener("touchstart", onTouchStart);
190
+ element.removeEventListener("touchmove", onTouchMove);
191
+ element.removeEventListener("touchend", onTouchEnd);
192
+ };
193
+ }, []);
194
+
195
+ const spaced = dots ? dotPitch(dots.pitch, shown) : 1;
196
+ const chunk = spaced * 4;
197
+ const reach = { width: viewport.width / shown, height: viewport.height / shown };
198
+ const area = dotArea({ x: scroll.x / shown, y: scroll.y / shown }, reach, content, chunk);
199
+ const follow = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
200
+ const { x, y } = event.nativeEvent.contentOffset;
201
+ offset.current = { x, y };
202
+ const next = dotArea({ x: x / shown, y: y / shown }, reach, content, chunk);
203
+ if (!sameArea(next, area)) setScroll({ x, y });
204
+ };
205
+
206
+ return (
207
+ <ScrollView
208
+ ref={scroller as never}
209
+ flex={1}
210
+ testID="graph-viewport"
211
+ scrollEnabled={!frozen}
212
+ keyboardShouldPersistTaps="handled"
213
+ showsVerticalScrollIndicator={false}
214
+ showsHorizontalScrollIndicator={false}
215
+ scrollEventThrottle={16}
216
+ onScroll={follow}
217
+ contentContainerStyle={{ alignSelf: "flex-start" }}
218
+ {...({ style: { overflowX: frozen ? "hidden" : "auto" } } as Record<string, unknown>)}
219
+ >
220
+ <View
221
+ minWidth={viewport.width}
222
+ minHeight={viewport.height}
223
+ alignItems="center"
224
+ justifyContent="center"
225
+ >
226
+ <View width={wide} height={tall} overflow="hidden" testID="graph-zoom">
227
+ <View
228
+ position="absolute"
229
+ left={0}
230
+ top={0}
231
+ width={content.width}
232
+ height={content.height}
233
+ {...({ style: { transform: [{ scale: shown }], transformOrigin: "0 0" } } as Record<
234
+ string,
235
+ unknown
236
+ >)}
237
+ >
238
+ {dots ? (
239
+ <GraphDots area={area} pitch={spaced} dot={dots.dot / shown} color={dots.color} />
240
+ ) : null}
241
+ {children}
242
+ </View>
243
+ </View>
244
+ </View>
245
+ </ScrollView>
246
+ );
247
+ }
@@ -0,0 +1,31 @@
1
+ export { GraphLayout, resolveGraphDirection } from "./GraphLayout";
2
+ export type { GraphLayoutProps, GraphSpaceToken } from "./GraphLayout";
3
+ export { GraphViewport } from "./GraphViewport";
4
+ export type { GraphViewportProps } from "./GraphViewport";
5
+ export { GraphDots } from "./GraphDots";
6
+ export type { GraphDotsProps } from "./GraphDots";
7
+ export { arrowHead, graphEdgeId, planGraphLayout, usableEdges } from "./plan";
8
+ export type {
9
+ GraphDirection,
10
+ GraphLayoutEdge,
11
+ GraphLayoutNode,
12
+ GraphPlan,
13
+ GraphPlanInput,
14
+ PlannedEdge,
15
+ PlannedNode,
16
+ } from "./plan";
17
+ export {
18
+ clampOffset,
19
+ clampView,
20
+ dotArea,
21
+ dotPath,
22
+ dotPhase,
23
+ dotPitch,
24
+ fittedView,
25
+ graphZoom,
26
+ keyedView,
27
+ leastScale,
28
+ toggledView,
29
+ zoomAt,
30
+ } from "./viewMath";
31
+ export type { DotArea, Extent, GraphDots as GraphDotsSpec, GraphView } from "./viewMath";
@@ -0,0 +1,120 @@
1
+ export const ogdenApps: readonly string[] = [
2
+ "affine",
3
+ "bit",
4
+ "blog",
5
+ "ciso",
6
+ "crm",
7
+ "crowdsec",
8
+ "docuseal",
9
+ "dtrack",
10
+ "ffx",
11
+ "fizzy",
12
+ "fleet",
13
+ "gitlab",
14
+ "gitlab-fizzy",
15
+ "glitchtip",
16
+ "hookshot",
17
+ "identity-broker",
18
+ "ivatar",
19
+ "librechat",
20
+ "lookout",
21
+ "mailbox-reconciler",
22
+ "mailbox-reconciler-ffx",
23
+ "mailcow",
24
+ "mariadb",
25
+ "matrix",
26
+ "mautic",
27
+ "mongodb",
28
+ "mpo-storybook",
29
+ "mysql",
30
+ "netbird",
31
+ "nextcloud",
32
+ "office",
33
+ "ollama",
34
+ "oncall",
35
+ "openreplay",
36
+ "openreplay-ch",
37
+ "pbx",
38
+ "pbx-db",
39
+ "pdf",
40
+ "peertube",
41
+ "penpot",
42
+ "photos",
43
+ "pokemon-bench",
44
+ "pokemon-kc",
45
+ "pokemon-web",
46
+ "postgres",
47
+ "postiz",
48
+ "pulp",
49
+ "redis",
50
+ "relay",
51
+ "ses-relay",
52
+ "sonarqube",
53
+ "supabase",
54
+ "superset",
55
+ "uptime",
56
+ "wazuh",
57
+ "wellknown",
58
+ "workflows",
59
+ ];
60
+ export const ogdenLinks: readonly (readonly [string, string])[] = [
61
+ ["affine", "postgres"],
62
+ ["bit", "mariadb"],
63
+ ["blog", "mysql"],
64
+ ["blog", "mailcow"],
65
+ ["ciso", "postgres"],
66
+ ["crm", "mysql"],
67
+ ["docuseal", "postgres"],
68
+ ["dtrack", "postgres"],
69
+ ["ffx", "mariadb"],
70
+ ["fizzy", "affine"],
71
+ ["fizzy", "nextcloud"],
72
+ ["fizzy", "mailcow"],
73
+ ["fleet", "mysql"],
74
+ ["gitlab", "postgres"],
75
+ ["gitlab", "mailcow"],
76
+ ["gitlab-fizzy", "fizzy"],
77
+ ["gitlab-fizzy", "gitlab"],
78
+ ["glitchtip", "postgres"],
79
+ ["hookshot", "matrix"],
80
+ ["identity-broker", "matrix"],
81
+ ["identity-broker", "postgres"],
82
+ ["ivatar", "postgres"],
83
+ ["librechat", "ollama"],
84
+ ["librechat", "mongodb"],
85
+ ["mailbox-reconciler", "mailcow"],
86
+ ["mailbox-reconciler-ffx", "mailcow"],
87
+ ["mailcow", "ses-relay"],
88
+ ["matrix", "postgres"],
89
+ ["mautic", "mailcow"],
90
+ ["mautic", "mysql"],
91
+ ["netbird", "postgres"],
92
+ ["nextcloud", "mailcow"],
93
+ ["nextcloud", "office"],
94
+ ["nextcloud", "postgres"],
95
+ ["nextcloud", "pdf"],
96
+ ["oncall", "postgres"],
97
+ ["openreplay", "openreplay-ch"],
98
+ ["openreplay", "postgres"],
99
+ ["pbx", "pbx-db"],
100
+ ["pbx", "mailcow"],
101
+ ["peertube", "postgres"],
102
+ ["peertube", "mailcow"],
103
+ ["penpot", "postgres"],
104
+ ["photos", "postgres"],
105
+ ["photos", "mailcow"],
106
+ ["pokemon-bench", "mariadb"],
107
+ ["pokemon-bench", "pokemon-kc"],
108
+ ["pokemon-kc", "postgres"],
109
+ ["pokemon-web", "pokemon-bench"],
110
+ ["pokemon-web", "pokemon-kc"],
111
+ ["postiz", "postgres"],
112
+ ["postiz", "mailcow"],
113
+ ["pulp", "postgres"],
114
+ ["relay", "postgres"],
115
+ ["sonarqube", "postgres"],
116
+ ["superset", "postgres"],
117
+ ["uptime", "matrix"],
118
+ ["workflows", "postgres"],
119
+ ["workflows", "redis"],
120
+ ];