@principal-ai/principal-view-react 0.13.10 → 0.13.12
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/components/GraphRenderer.d.ts +14 -0
- package/dist/components/GraphRenderer.d.ts.map +1 -1
- package/dist/components/GraphRenderer.js +31 -12
- package/dist/components/GraphRenderer.js.map +1 -1
- package/dist/components/MultiCanvasRenderer.d.ts +75 -0
- package/dist/components/MultiCanvasRenderer.d.ts.map +1 -0
- package/dist/components/MultiCanvasRenderer.js +207 -0
- package/dist/components/MultiCanvasRenderer.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/canvasBounds.d.ts +29 -0
- package/dist/utils/canvasBounds.d.ts.map +1 -0
- package/dist/utils/canvasBounds.js +56 -0
- package/dist/utils/canvasBounds.js.map +1 -0
- package/package.json +1 -1
- package/src/components/GraphRenderer.tsx +54 -10
- package/src/components/MultiCanvasRenderer.tsx +299 -0
- package/src/index.ts +9 -0
- package/src/stories/MultiCanvasRenderer.stories.tsx +370 -0
- package/src/utils/canvasBounds.ts +91 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { ExtendedCanvas } from '@principal-ai/principal-view-core';
|
|
2
|
+
|
|
3
|
+
export interface CanvasBounds {
|
|
4
|
+
minX: number;
|
|
5
|
+
minY: number;
|
|
6
|
+
maxX: number;
|
|
7
|
+
maxY: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const DEFAULT_NODE_WIDTH = 200;
|
|
13
|
+
const DEFAULT_NODE_HEIGHT = 100;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Calculate the bounding box of all nodes in a canvas.
|
|
17
|
+
* Returns the min/max coordinates and total dimensions.
|
|
18
|
+
*/
|
|
19
|
+
export function getCanvasBounds(canvas: ExtendedCanvas): CanvasBounds {
|
|
20
|
+
if (!canvas.nodes || canvas.nodes.length === 0) {
|
|
21
|
+
return {
|
|
22
|
+
minX: 0,
|
|
23
|
+
minY: 0,
|
|
24
|
+
maxX: DEFAULT_NODE_WIDTH,
|
|
25
|
+
maxY: DEFAULT_NODE_HEIGHT,
|
|
26
|
+
width: DEFAULT_NODE_WIDTH,
|
|
27
|
+
height: DEFAULT_NODE_HEIGHT,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let minX = Infinity;
|
|
32
|
+
let minY = Infinity;
|
|
33
|
+
let maxX = -Infinity;
|
|
34
|
+
let maxY = -Infinity;
|
|
35
|
+
|
|
36
|
+
for (const node of canvas.nodes) {
|
|
37
|
+
const x = node.x ?? 0;
|
|
38
|
+
const y = node.y ?? 0;
|
|
39
|
+
const width = node.width ?? DEFAULT_NODE_WIDTH;
|
|
40
|
+
const height = node.height ?? DEFAULT_NODE_HEIGHT;
|
|
41
|
+
|
|
42
|
+
minX = Math.min(minX, x);
|
|
43
|
+
minY = Math.min(minY, y);
|
|
44
|
+
maxX = Math.max(maxX, x + width);
|
|
45
|
+
maxY = Math.max(maxY, y + height);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
minX,
|
|
50
|
+
minY,
|
|
51
|
+
maxX,
|
|
52
|
+
maxY,
|
|
53
|
+
width: maxX - minX,
|
|
54
|
+
height: maxY - minY,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Calculate a recommended display size for a canvas cell.
|
|
60
|
+
* Adds padding and enforces minimum dimensions.
|
|
61
|
+
*/
|
|
62
|
+
export function getCanvasDisplaySize(
|
|
63
|
+
canvas: ExtendedCanvas,
|
|
64
|
+
options: {
|
|
65
|
+
padding?: number;
|
|
66
|
+
minWidth?: number;
|
|
67
|
+
minHeight?: number;
|
|
68
|
+
maxWidth?: number;
|
|
69
|
+
maxHeight?: number;
|
|
70
|
+
} = {}
|
|
71
|
+
): { width: number; height: number } {
|
|
72
|
+
const {
|
|
73
|
+
padding = 100,
|
|
74
|
+
minWidth = 300,
|
|
75
|
+
minHeight = 200,
|
|
76
|
+
maxWidth = 1200,
|
|
77
|
+
maxHeight = 800,
|
|
78
|
+
} = options;
|
|
79
|
+
|
|
80
|
+
const bounds = getCanvasBounds(canvas);
|
|
81
|
+
|
|
82
|
+
// Add padding to content dimensions
|
|
83
|
+
const contentWidth = bounds.width + padding * 2;
|
|
84
|
+
const contentHeight = bounds.height + padding * 2;
|
|
85
|
+
|
|
86
|
+
// Clamp to min/max
|
|
87
|
+
const width = Math.min(maxWidth, Math.max(minWidth, contentWidth));
|
|
88
|
+
const height = Math.min(maxHeight, Math.max(minHeight, contentHeight));
|
|
89
|
+
|
|
90
|
+
return { width, height };
|
|
91
|
+
}
|