@exellix/diagrams-toolkit 0.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/README.md +95 -0
- package/package.json +41 -0
- package/src/ConceptSummaryStrip.jsx +75 -0
- package/src/DefaultGraphEdge.jsx +57 -0
- package/src/EmptyState.jsx +16 -0
- package/src/ErrorState.jsx +20 -0
- package/src/FlowCanvas.jsx +103 -0
- package/src/GraphCanvas.jsx +455 -0
- package/src/GraphCanvasZoomControl.jsx +59 -0
- package/src/InspectorShell.jsx +64 -0
- package/src/JsonDocumentPanel.jsx +95 -0
- package/src/ResourceDataTable.jsx +180 -0
- package/src/StatusBadge.jsx +41 -0
- package/src/SyncStateBanner.jsx +58 -0
- package/src/ViewTabStrip.jsx +39 -0
- package/src/ZoomControls.jsx +80 -0
- package/src/index.js +39 -0
- package/src/lib/computeEdgeBezierPath.js +32 -0
- package/src/lib/graphCanvasLayout.js +99 -0
- package/src/lib/graphCanvasZoom.js +33 -0
- package/src/lib/graphViewportResizePan.js +99 -0
- package/src/styles.css +4 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/** Default node card dimensions for screen-bounds estimation. */
|
|
2
|
+
export const GRAPH_NODE_CARD_WIDTH = 320;
|
|
3
|
+
export const GRAPH_NODE_CARD_APPROX_HEIGHT = 240;
|
|
4
|
+
export const GRAPH_VIEWPORT_RESIZE_EDGE_PAD = 48;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {{ nodes: object[], extraNodes?: object[] }} opts
|
|
8
|
+
*/
|
|
9
|
+
export function canvasNodesForViewportBounds({ nodes, extraNodes = [] }) {
|
|
10
|
+
const list = [...(extraNodes || []), ...(nodes || [])];
|
|
11
|
+
return list;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {object[]} list
|
|
16
|
+
* @param {{ scale: number, x: number, y: number }} transform
|
|
17
|
+
*/
|
|
18
|
+
export function graphContentScreenBounds(
|
|
19
|
+
list,
|
|
20
|
+
transform,
|
|
21
|
+
{
|
|
22
|
+
cardWidth = GRAPH_NODE_CARD_WIDTH,
|
|
23
|
+
cardHeight = GRAPH_NODE_CARD_APPROX_HEIGHT,
|
|
24
|
+
} = {},
|
|
25
|
+
) {
|
|
26
|
+
if (!list?.length) return null;
|
|
27
|
+
const { scale, x: tx, y: ty } = transform;
|
|
28
|
+
let minX = Infinity;
|
|
29
|
+
let minY = Infinity;
|
|
30
|
+
let maxX = -Infinity;
|
|
31
|
+
let maxY = -Infinity;
|
|
32
|
+
for (const n of list) {
|
|
33
|
+
minX = Math.min(minX, n.x * scale + tx);
|
|
34
|
+
minY = Math.min(minY, n.y * scale + ty);
|
|
35
|
+
maxX = Math.max(maxX, (n.x + cardWidth) * scale + tx);
|
|
36
|
+
maxY = Math.max(maxY, (n.y + cardHeight) * scale + ty);
|
|
37
|
+
}
|
|
38
|
+
return { minX, minY, maxX, maxY };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {{
|
|
43
|
+
* prevSize: { width: number, height: number },
|
|
44
|
+
* nextSize: { width: number, height: number },
|
|
45
|
+
* transform: { scale: number, x: number, y: number },
|
|
46
|
+
* nodes: object[],
|
|
47
|
+
* extraNodes?: object[],
|
|
48
|
+
* cardWidth?: number,
|
|
49
|
+
* cardHeight?: number,
|
|
50
|
+
* }} opts
|
|
51
|
+
* @returns {{ x: number, y: number }}
|
|
52
|
+
*/
|
|
53
|
+
export function computeGraphViewportResizePan({
|
|
54
|
+
prevSize,
|
|
55
|
+
nextSize,
|
|
56
|
+
transform,
|
|
57
|
+
nodes,
|
|
58
|
+
extraNodes = [],
|
|
59
|
+
cardWidth = GRAPH_NODE_CARD_WIDTH,
|
|
60
|
+
cardHeight = GRAPH_NODE_CARD_APPROX_HEIGHT,
|
|
61
|
+
}) {
|
|
62
|
+
const dx = nextSize.width - prevSize.width;
|
|
63
|
+
const dy = nextSize.height - prevSize.height;
|
|
64
|
+
if (Math.abs(dx) < 1 && Math.abs(dy) < 1) return { x: 0, y: 0 };
|
|
65
|
+
|
|
66
|
+
const list = canvasNodesForViewportBounds({ nodes, extraNodes });
|
|
67
|
+
const bounds = graphContentScreenBounds(list, transform, { cardWidth, cardHeight });
|
|
68
|
+
if (!bounds) return { x: 0, y: 0 };
|
|
69
|
+
|
|
70
|
+
const pad = GRAPH_VIEWPORT_RESIZE_EDGE_PAD;
|
|
71
|
+
let panX = 0;
|
|
72
|
+
let panY = 0;
|
|
73
|
+
|
|
74
|
+
if (dx < -1) {
|
|
75
|
+
const rightLimit = nextSize.width - pad;
|
|
76
|
+
if (bounds.maxX > rightLimit) {
|
|
77
|
+
panX = Math.min(0, rightLimit - bounds.maxX);
|
|
78
|
+
}
|
|
79
|
+
} else if (dx > 1) {
|
|
80
|
+
const leftLimit = pad;
|
|
81
|
+
if (bounds.minX < leftLimit) {
|
|
82
|
+
panX = Math.max(0, leftLimit - bounds.minX);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (dy < -1) {
|
|
87
|
+
const bottomLimit = nextSize.height - pad;
|
|
88
|
+
if (bounds.maxY > bottomLimit) {
|
|
89
|
+
panY = Math.min(0, bottomLimit - bounds.maxY);
|
|
90
|
+
}
|
|
91
|
+
} else if (dy > 1) {
|
|
92
|
+
const topLimit = pad;
|
|
93
|
+
if (bounds.minY < topLimit) {
|
|
94
|
+
panY = Math.max(0, topLimit - bounds.minY);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return { x: panX, y: panY };
|
|
99
|
+
}
|
package/src/styles.css
ADDED