vizmatic 0.2.0 → 0.3.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/PROMPT.md +13 -0
- package/README.md +58 -1
- package/ROADMAP.md +4 -2
- package/assets/THIRD_PARTY_LICENSES.md +3 -0
- package/dist/cli.js +23 -12430
- package/dist/index.cjs +1047 -154
- package/dist/index.d.cts +78 -7
- package/dist/index.d.ts +78 -7
- package/dist/index.js +1041 -153
- package/examples/README.md +4 -0
- package/examples/orthogonal-routing.tsx +25 -0
- package/examples/pareto-bar-chart.tsx +44 -0
- package/examples/pie-chart.tsx +46 -0
- package/examples/website-workflow.tsx +38 -0
- package/package.json +10 -7
package/dist/index.cjs
CHANGED
|
@@ -36,10 +36,13 @@ __export(index_exports, {
|
|
|
36
36
|
Badge: () => Badge,
|
|
37
37
|
BadgePill: () => BadgePill,
|
|
38
38
|
BarChart: () => BarChart,
|
|
39
|
+
Board: () => Board,
|
|
39
40
|
Box: () => Box,
|
|
41
|
+
CANVAS_ITEM_COMPONENT: () => CANVAS_ITEM_COMPONENT,
|
|
40
42
|
CHECK_DIAGNOSTIC_CODES: () => CHECK_DIAGNOSTIC_CODES,
|
|
41
43
|
CalloutCard: () => CalloutCard,
|
|
42
44
|
Canvas: () => Canvas,
|
|
45
|
+
CanvasItem: () => CanvasItem,
|
|
43
46
|
CanvasOverflowError: () => CanvasOverflowError,
|
|
44
47
|
Card: () => Card,
|
|
45
48
|
ChartFrame: () => ChartFrame,
|
|
@@ -72,7 +75,9 @@ __export(index_exports, {
|
|
|
72
75
|
MetricCard: () => MetricCard,
|
|
73
76
|
MiniBarChart: () => MiniBarChart,
|
|
74
77
|
Panel: () => Panel,
|
|
78
|
+
ParetoBarChart: () => ParetoBarChart,
|
|
75
79
|
ParetoChart: () => ParetoChart,
|
|
80
|
+
PieChart: () => PieChart,
|
|
76
81
|
Pipeline: () => Pipeline,
|
|
77
82
|
ProgressList: () => ProgressList,
|
|
78
83
|
ProgressRow: () => ProgressRow,
|
|
@@ -592,9 +597,12 @@ __export(primitives_exports, {
|
|
|
592
597
|
Badge: () => Badge,
|
|
593
598
|
BadgePill: () => BadgePill,
|
|
594
599
|
BarChart: () => BarChart,
|
|
600
|
+
Board: () => Board,
|
|
595
601
|
Box: () => Box,
|
|
602
|
+
CANVAS_ITEM_COMPONENT: () => CANVAS_ITEM_COMPONENT,
|
|
596
603
|
CalloutCard: () => CalloutCard,
|
|
597
604
|
Canvas: () => Canvas,
|
|
605
|
+
CanvasItem: () => CanvasItem,
|
|
598
606
|
Card: () => Card,
|
|
599
607
|
ChartFrame: () => ChartFrame,
|
|
600
608
|
CodeBlock: () => CodeBlock,
|
|
@@ -626,7 +634,9 @@ __export(primitives_exports, {
|
|
|
626
634
|
MetricCard: () => MetricCard,
|
|
627
635
|
MiniBarChart: () => MiniBarChart,
|
|
628
636
|
Panel: () => Panel,
|
|
637
|
+
ParetoBarChart: () => ParetoBarChart,
|
|
629
638
|
ParetoChart: () => ParetoChart,
|
|
639
|
+
PieChart: () => PieChart,
|
|
630
640
|
Pipeline: () => Pipeline,
|
|
631
641
|
ProgressList: () => ProgressList,
|
|
632
642
|
ProgressRow: () => ProgressRow,
|
|
@@ -2743,7 +2753,7 @@ function renderComparisonDivider(divider, c, key) {
|
|
|
2743
2753
|
);
|
|
2744
2754
|
}
|
|
2745
2755
|
function Comparison({
|
|
2746
|
-
sides,
|
|
2756
|
+
sides: sides2,
|
|
2747
2757
|
c,
|
|
2748
2758
|
divider = false,
|
|
2749
2759
|
gap = 14,
|
|
@@ -2752,7 +2762,7 @@ function Comparison({
|
|
|
2752
2762
|
align = "stretch",
|
|
2753
2763
|
math = false
|
|
2754
2764
|
}) {
|
|
2755
|
-
const children =
|
|
2765
|
+
const children = sides2.flatMap((side, index) => {
|
|
2756
2766
|
const tone = side.tone ?? "blue";
|
|
2757
2767
|
const panel = import_react4.default.createElement(
|
|
2758
2768
|
import_react4.default.Fragment,
|
|
@@ -2782,7 +2792,7 @@ function Comparison({
|
|
|
2782
2792
|
) : side.children ?? DetailList({ items: side.lines ?? [], c, tone, math })
|
|
2783
2793
|
})
|
|
2784
2794
|
);
|
|
2785
|
-
if (divider && index <
|
|
2795
|
+
if (divider && index < sides2.length - 1) {
|
|
2786
2796
|
return [panel, renderComparisonDivider(divider, c, `comparison-divider-${index}`)];
|
|
2787
2797
|
}
|
|
2788
2798
|
return [panel];
|
|
@@ -3638,6 +3648,284 @@ function addSvgAccessibility(svg, graphs, layoutNodes) {
|
|
|
3638
3648
|
).replace(/<\/svg>\s*$/, `${groupMarkup}</svg>`);
|
|
3639
3649
|
}
|
|
3640
3650
|
|
|
3651
|
+
// src/graph-routing.ts
|
|
3652
|
+
var EPSILON = 1e-3;
|
|
3653
|
+
var MAX_GRID_POINTS = 18e3;
|
|
3654
|
+
var MAX_SEARCH_STATES = 54e3;
|
|
3655
|
+
var MAX_TOTAL_SEARCH_STATES = 16e4;
|
|
3656
|
+
var MAX_ROUTED_EDGES = 256;
|
|
3657
|
+
var MAX_OBSTACLES = 64;
|
|
3658
|
+
var sides = ["right", "bottom", "left", "top"];
|
|
3659
|
+
function box(node, clearance = 0) {
|
|
3660
|
+
return {
|
|
3661
|
+
left: node.cx - node.width / 2 - clearance,
|
|
3662
|
+
right: node.cx + node.width / 2 + clearance,
|
|
3663
|
+
top: node.cy - node.height / 2 - clearance,
|
|
3664
|
+
bottom: node.cy + node.height / 2 + clearance
|
|
3665
|
+
};
|
|
3666
|
+
}
|
|
3667
|
+
function inside(point, obstacle) {
|
|
3668
|
+
return point.x > obstacle.left + EPSILON && point.x < obstacle.right - EPSILON && point.y > obstacle.top + EPSILON && point.y < obstacle.bottom - EPSILON;
|
|
3669
|
+
}
|
|
3670
|
+
function routingSegmentBlocked(a, b, obstacle) {
|
|
3671
|
+
if (Math.abs(a.y - b.y) < EPSILON) {
|
|
3672
|
+
return a.y > obstacle.top + EPSILON && a.y < obstacle.bottom - EPSILON && Math.max(a.x, b.x) > obstacle.left + EPSILON && Math.min(a.x, b.x) < obstacle.right - EPSILON;
|
|
3673
|
+
}
|
|
3674
|
+
if (Math.abs(a.x - b.x) < EPSILON) {
|
|
3675
|
+
return a.x > obstacle.left + EPSILON && a.x < obstacle.right - EPSILON && Math.max(a.y, b.y) > obstacle.top + EPSILON && Math.min(a.y, b.y) < obstacle.bottom - EPSILON;
|
|
3676
|
+
}
|
|
3677
|
+
return true;
|
|
3678
|
+
}
|
|
3679
|
+
function preferredSide(from, to) {
|
|
3680
|
+
if (Math.abs(to.cx - from.cx) >= Math.abs(to.cy - from.cy)) return to.cx >= from.cx ? "right" : "left";
|
|
3681
|
+
return to.cy >= from.cy ? "bottom" : "top";
|
|
3682
|
+
}
|
|
3683
|
+
function routingAnchor(node, side, offset = 0.5) {
|
|
3684
|
+
const bounds = box(node);
|
|
3685
|
+
if (side === "left" || side === "right") return { x: bounds[side], y: bounds.top + node.height * offset };
|
|
3686
|
+
return { x: bounds.left + node.width * offset, y: bounds[side] };
|
|
3687
|
+
}
|
|
3688
|
+
function outward(point, side, distance) {
|
|
3689
|
+
return {
|
|
3690
|
+
x: point.x + (side === "right" ? distance : side === "left" ? -distance : 0),
|
|
3691
|
+
y: point.y + (side === "bottom" ? distance : side === "top" ? -distance : 0)
|
|
3692
|
+
};
|
|
3693
|
+
}
|
|
3694
|
+
function simplify(points) {
|
|
3695
|
+
const result = [];
|
|
3696
|
+
for (const point of points) {
|
|
3697
|
+
const last = result[result.length - 1];
|
|
3698
|
+
if (last && Math.abs(last.x - point.x) < EPSILON && Math.abs(last.y - point.y) < EPSILON) continue;
|
|
3699
|
+
const previous = result[result.length - 2];
|
|
3700
|
+
if (previous && last && (previous.x === last.x && last.x === point.x || previous.y === last.y && last.y === point.y)) {
|
|
3701
|
+
result[result.length - 1] = point;
|
|
3702
|
+
} else result.push(point);
|
|
3703
|
+
}
|
|
3704
|
+
return result;
|
|
3705
|
+
}
|
|
3706
|
+
function overlappingLength(a, b, c, d) {
|
|
3707
|
+
if (a.y === b.y && c.y === d.y && Math.abs(a.y - c.y) < EPSILON) {
|
|
3708
|
+
return Math.max(0, Math.min(Math.max(a.x, b.x), Math.max(c.x, d.x)) - Math.max(Math.min(a.x, b.x), Math.min(c.x, d.x)));
|
|
3709
|
+
}
|
|
3710
|
+
if (a.x === b.x && c.x === d.x && Math.abs(a.x - c.x) < EPSILON) {
|
|
3711
|
+
return Math.max(0, Math.min(Math.max(a.y, b.y), Math.max(c.y, d.y)) - Math.max(Math.min(a.y, b.y), Math.min(c.y, d.y)));
|
|
3712
|
+
}
|
|
3713
|
+
return 0;
|
|
3714
|
+
}
|
|
3715
|
+
var MinQueue = class {
|
|
3716
|
+
items = [];
|
|
3717
|
+
get length() {
|
|
3718
|
+
return this.items.length;
|
|
3719
|
+
}
|
|
3720
|
+
push(value) {
|
|
3721
|
+
const items = this.items;
|
|
3722
|
+
items.push(value);
|
|
3723
|
+
let index = items.length - 1;
|
|
3724
|
+
while (index > 0) {
|
|
3725
|
+
const parent = index - 1 >> 1;
|
|
3726
|
+
if (items[parent].priority <= value.priority) break;
|
|
3727
|
+
items[index] = items[parent];
|
|
3728
|
+
index = parent;
|
|
3729
|
+
}
|
|
3730
|
+
items[index] = value;
|
|
3731
|
+
}
|
|
3732
|
+
pop() {
|
|
3733
|
+
const items = this.items;
|
|
3734
|
+
const first = items[0];
|
|
3735
|
+
const last = items.pop();
|
|
3736
|
+
if (items.length === 0) return first;
|
|
3737
|
+
let index = 0;
|
|
3738
|
+
while (index * 2 + 1 < items.length) {
|
|
3739
|
+
const left = index * 2 + 1;
|
|
3740
|
+
const right = left + 1;
|
|
3741
|
+
const child = right < items.length && items[right].priority < items[left].priority ? right : left;
|
|
3742
|
+
if (items[child].priority >= last.priority) break;
|
|
3743
|
+
items[index] = items[child];
|
|
3744
|
+
index = child;
|
|
3745
|
+
}
|
|
3746
|
+
items[index] = last;
|
|
3747
|
+
return first;
|
|
3748
|
+
}
|
|
3749
|
+
};
|
|
3750
|
+
function findPath(start, end, obstacles, width, height, previousRoutes, gap, budget) {
|
|
3751
|
+
const within = (point) => point.x >= 0 && point.x <= width && point.y >= 0 && point.y <= height;
|
|
3752
|
+
if (!within(start) || !within(end) || obstacles.some((obstacle) => inside(start, obstacle) || inside(end, obstacle))) {
|
|
3753
|
+
return { reason: "an endpoint has no clear exit inside the canvas" };
|
|
3754
|
+
}
|
|
3755
|
+
const xs = /* @__PURE__ */ new Set([0, width, start.x, end.x]);
|
|
3756
|
+
const ys = /* @__PURE__ */ new Set([0, height, start.y, end.y]);
|
|
3757
|
+
for (const obstacle of obstacles) {
|
|
3758
|
+
if (obstacle.left >= 0 && obstacle.left <= width) xs.add(obstacle.left);
|
|
3759
|
+
if (obstacle.right >= 0 && obstacle.right <= width) xs.add(obstacle.right);
|
|
3760
|
+
if (obstacle.top >= 0 && obstacle.top <= height) ys.add(obstacle.top);
|
|
3761
|
+
if (obstacle.bottom >= 0 && obstacle.bottom <= height) ys.add(obstacle.bottom);
|
|
3762
|
+
}
|
|
3763
|
+
for (const route of previousRoutes.slice(-8)) for (const point of route) {
|
|
3764
|
+
for (const offset of [-gap, gap]) {
|
|
3765
|
+
if (point.x + offset >= 0 && point.x + offset <= width) xs.add(point.x + offset);
|
|
3766
|
+
if (point.y + offset >= 0 && point.y + offset <= height) ys.add(point.y + offset);
|
|
3767
|
+
}
|
|
3768
|
+
}
|
|
3769
|
+
const xValues = [...xs].sort((a, b) => a - b);
|
|
3770
|
+
const yValues = [...ys].sort((a, b) => a - b);
|
|
3771
|
+
const columns = xValues.length;
|
|
3772
|
+
const gridSize = columns * yValues.length;
|
|
3773
|
+
if (gridSize > MAX_GRID_POINTS) return { reason: `routing grid exceeds ${MAX_GRID_POINTS} points; simplify the graph` };
|
|
3774
|
+
const startIndex = yValues.indexOf(start.y) * columns + xValues.indexOf(start.x);
|
|
3775
|
+
const endIndex = yValues.indexOf(end.y) * columns + xValues.indexOf(end.x);
|
|
3776
|
+
const pointAt = (index) => ({ x: xValues[index % columns], y: yValues[Math.floor(index / columns)] });
|
|
3777
|
+
const costs = new Float64Array(gridSize * 3).fill(Infinity);
|
|
3778
|
+
const parents = new Int32Array(gridSize * 3).fill(-1);
|
|
3779
|
+
const queue = new MinQueue();
|
|
3780
|
+
costs[startIndex * 3] = 0;
|
|
3781
|
+
queue.push({ state: startIndex * 3, cost: 0, priority: 0 });
|
|
3782
|
+
let visits = 0;
|
|
3783
|
+
while (queue.length > 0) {
|
|
3784
|
+
if (--budget.remaining < 0) return { reason: `diagram routing budget exceeds ${MAX_TOTAL_SEARCH_STATES} search states; simplify the graph` };
|
|
3785
|
+
if (++visits > MAX_SEARCH_STATES) return { reason: `routing search exceeds ${MAX_SEARCH_STATES} states; simplify the graph` };
|
|
3786
|
+
const current = queue.pop();
|
|
3787
|
+
if (current.cost !== costs[current.state]) continue;
|
|
3788
|
+
const index = Math.floor(current.state / 3);
|
|
3789
|
+
const axis = current.state % 3;
|
|
3790
|
+
if (index === endIndex) {
|
|
3791
|
+
const points = [];
|
|
3792
|
+
for (let state = current.state; state >= 0; state = parents[state]) points.push(pointAt(Math.floor(state / 3)));
|
|
3793
|
+
return { points: simplify(points.reverse()) };
|
|
3794
|
+
}
|
|
3795
|
+
const a = pointAt(index);
|
|
3796
|
+
const column = index % columns;
|
|
3797
|
+
const row = Math.floor(index / columns);
|
|
3798
|
+
const neighbors = [
|
|
3799
|
+
column > 0 ? index - 1 : -1,
|
|
3800
|
+
column < columns - 1 ? index + 1 : -1,
|
|
3801
|
+
row > 0 ? index - columns : -1,
|
|
3802
|
+
row < yValues.length - 1 ? index + columns : -1
|
|
3803
|
+
];
|
|
3804
|
+
for (const neighbor of neighbors) {
|
|
3805
|
+
if (neighbor < 0) continue;
|
|
3806
|
+
const b = pointAt(neighbor);
|
|
3807
|
+
if (obstacles.some((obstacle) => routingSegmentBlocked(a, b, obstacle))) continue;
|
|
3808
|
+
const nextAxis = a.y === b.y ? 1 : 2;
|
|
3809
|
+
const state = neighbor * 3 + nextAxis;
|
|
3810
|
+
let overlap = 0;
|
|
3811
|
+
for (const route of previousRoutes) for (let i = 1; i < route.length; i++) overlap += overlappingLength(a, b, route[i - 1], route[i]);
|
|
3812
|
+
const cost = current.cost + Math.abs(b.x - a.x) + Math.abs(b.y - a.y) + (axis !== 0 && axis !== nextAxis ? 18 : 0) + overlap * 5;
|
|
3813
|
+
if (cost >= costs[state]) continue;
|
|
3814
|
+
costs[state] = cost;
|
|
3815
|
+
parents[state] = current.state;
|
|
3816
|
+
queue.push({ state, cost, priority: cost + Math.abs(end.x - b.x) + Math.abs(end.y - b.y) });
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3819
|
+
return { reason: "no obstacle-free route exists inside the canvas" };
|
|
3820
|
+
}
|
|
3821
|
+
function endpoint(node, other, portId, requestedSide, selfLoop, target, ordinal, count, gap) {
|
|
3822
|
+
const port = node.ports?.find((candidate) => candidate.id === portId);
|
|
3823
|
+
const side = port?.side ?? requestedSide ?? (selfLoop ? target ? "top" : "right" : preferredSide(node, other));
|
|
3824
|
+
const length = side === "left" || side === "right" ? node.height : node.width;
|
|
3825
|
+
const separation = count > 1 ? Math.min(gap, length * 0.7 / (count - 1)) : 0;
|
|
3826
|
+
const offset = port ? port.offset ?? 0.5 : 0.5 + (ordinal - (count - 1) / 2) * separation / length;
|
|
3827
|
+
return { side, anchor: routingAnchor(node, side, offset), explicit: portId != null || requestedSide != null };
|
|
3828
|
+
}
|
|
3829
|
+
function straightGraphRoute(from, to, edge) {
|
|
3830
|
+
return [
|
|
3831
|
+
endpoint(from, to, edge.fromPort, edge.fromSide, false, false, 0, 1, 0).anchor,
|
|
3832
|
+
endpoint(to, from, edge.toPort, edge.toSide, false, true, 0, 1, 0).anchor
|
|
3833
|
+
];
|
|
3834
|
+
}
|
|
3835
|
+
function routeOrthogonalGraph(nodes, edges, width, height, clearance = 12, gap = 14, extraObstacles = []) {
|
|
3836
|
+
const routes = /* @__PURE__ */ new Map();
|
|
3837
|
+
const failures = [];
|
|
3838
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
3839
|
+
const obstacles = [...nodes.map((node) => box(node, clearance)), ...extraObstacles.map((obstacle) => ({
|
|
3840
|
+
left: obstacle.left - clearance,
|
|
3841
|
+
right: obstacle.right + clearance,
|
|
3842
|
+
top: obstacle.top - clearance,
|
|
3843
|
+
bottom: obstacle.bottom + clearance
|
|
3844
|
+
}))];
|
|
3845
|
+
const routeKey = (edge) => [edge.from, edge.to].sort().join("\0");
|
|
3846
|
+
const counts2 = /* @__PURE__ */ new Map();
|
|
3847
|
+
for (const edge of edges) counts2.set(routeKey(edge), (counts2.get(routeKey(edge)) ?? 0) + 1);
|
|
3848
|
+
const occurrences = /* @__PURE__ */ new Map();
|
|
3849
|
+
const previous = /* @__PURE__ */ new Map();
|
|
3850
|
+
const budget = { remaining: MAX_TOTAL_SEARCH_STATES };
|
|
3851
|
+
edges.forEach((edge, index) => {
|
|
3852
|
+
if (index >= MAX_ROUTED_EDGES) {
|
|
3853
|
+
failures.push({ index, reason: `orthogonal routing supports at most ${MAX_ROUTED_EDGES} edges per diagram` });
|
|
3854
|
+
return;
|
|
3855
|
+
}
|
|
3856
|
+
if (obstacles.length > MAX_OBSTACLES) {
|
|
3857
|
+
failures.push({ index, reason: `orthogonal routing supports at most ${MAX_OBSTACLES} node and header obstacles per diagram` });
|
|
3858
|
+
return;
|
|
3859
|
+
}
|
|
3860
|
+
if (budget.remaining < 0) {
|
|
3861
|
+
failures.push({ index, reason: `diagram routing budget exceeds ${MAX_TOTAL_SEARCH_STATES} search states; simplify the graph` });
|
|
3862
|
+
return;
|
|
3863
|
+
}
|
|
3864
|
+
const from = byId.get(edge.from);
|
|
3865
|
+
const to = byId.get(edge.to);
|
|
3866
|
+
const key = routeKey(edge);
|
|
3867
|
+
const ordinal = occurrences.get(key) ?? 0;
|
|
3868
|
+
occurrences.set(key, ordinal + 1);
|
|
3869
|
+
const count = counts2.get(key) ?? 1;
|
|
3870
|
+
const source = endpoint(from, to, edge.fromPort, edge.fromSide, from === to, false, ordinal, count, gap);
|
|
3871
|
+
const target = endpoint(to, from, edge.toPort, edge.toSide, from === to, true, ordinal, count, gap);
|
|
3872
|
+
const sourceSides = source.explicit ? [source.side] : [source.side, ...sides.filter((side) => side !== source.side)];
|
|
3873
|
+
const targetSides = target.explicit ? [target.side] : [target.side, ...sides.filter((side) => side !== target.side)];
|
|
3874
|
+
let failure = "no obstacle-free route exists inside the canvas";
|
|
3875
|
+
for (const sourceSide of sourceSides) {
|
|
3876
|
+
for (const targetSide of targetSides) {
|
|
3877
|
+
const start = sourceSide === source.side ? source.anchor : routingAnchor(from, sourceSide);
|
|
3878
|
+
const end = targetSide === target.side ? target.anchor : routingAnchor(to, targetSide);
|
|
3879
|
+
if (from === to && start.x === end.x && start.y === end.y) {
|
|
3880
|
+
failure = "a self-loop requires distinct endpoint anchors";
|
|
3881
|
+
continue;
|
|
3882
|
+
}
|
|
3883
|
+
const leadStart = outward(start, sourceSide, clearance);
|
|
3884
|
+
const leadEnd = outward(end, targetSide, clearance);
|
|
3885
|
+
if (obstacles.some((obstacle, obstacleIndex) => obstacleIndex !== nodes.indexOf(from) && routingSegmentBlocked(start, leadStart, obstacle) || obstacleIndex !== nodes.indexOf(to) && routingSegmentBlocked(leadEnd, end, obstacle))) {
|
|
3886
|
+
failure = "another obstacle blocks an endpoint exit";
|
|
3887
|
+
continue;
|
|
3888
|
+
}
|
|
3889
|
+
const result = findPath(leadStart, leadEnd, obstacles, width, height, previous.get(key) ?? [], Math.max(1, gap), budget);
|
|
3890
|
+
if (!result.points) {
|
|
3891
|
+
failure = result.reason;
|
|
3892
|
+
if (/routing (grid|search|budget)/.test(failure)) {
|
|
3893
|
+
failures.push({ index, reason: failure });
|
|
3894
|
+
return;
|
|
3895
|
+
}
|
|
3896
|
+
continue;
|
|
3897
|
+
}
|
|
3898
|
+
const points = simplify([start, ...result.points, end]);
|
|
3899
|
+
if (points.length < 2) continue;
|
|
3900
|
+
const repeated = (previous.get(key) ?? []).some((route) => route.length === points.length && (route.every((point, position) => point.x === points[position].x && point.y === points[position].y) || route.every((point, position) => point.x === points[points.length - 1 - position].x && point.y === points[points.length - 1 - position].y)));
|
|
3901
|
+
if (repeated) {
|
|
3902
|
+
failure = "parallel connectors have no separate lane at the requested clearance";
|
|
3903
|
+
continue;
|
|
3904
|
+
}
|
|
3905
|
+
routes.set(index, points);
|
|
3906
|
+
previous.set(key, [...previous.get(key) ?? [], points]);
|
|
3907
|
+
return;
|
|
3908
|
+
}
|
|
3909
|
+
}
|
|
3910
|
+
failures.push({ index, reason: failure });
|
|
3911
|
+
});
|
|
3912
|
+
return { routes, failures };
|
|
3913
|
+
}
|
|
3914
|
+
function routingLabelPosition(points) {
|
|
3915
|
+
let longest = 0;
|
|
3916
|
+
let position = points[0];
|
|
3917
|
+
for (let i = 1; i < points.length; i++) {
|
|
3918
|
+
const a = points[i - 1];
|
|
3919
|
+
const b = points[i];
|
|
3920
|
+
const length = Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
|
3921
|
+
if (length > longest) {
|
|
3922
|
+
longest = length;
|
|
3923
|
+
position = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
3924
|
+
}
|
|
3925
|
+
}
|
|
3926
|
+
return position;
|
|
3927
|
+
}
|
|
3928
|
+
|
|
3641
3929
|
// src/primitives/diagrams.ts
|
|
3642
3930
|
function distributeValues(count, start, end) {
|
|
3643
3931
|
if (count <= 0) return [];
|
|
@@ -3974,6 +4262,20 @@ function validateGraphDiagramSpec(nodes, edges, groups, layoutMode) {
|
|
|
3974
4262
|
for (const node of nodes) {
|
|
3975
4263
|
if (nodeIds.has(node.id)) throw new Error(`GraphDiagram received duplicate node id "${node.id}".`);
|
|
3976
4264
|
nodeIds.add(node.id);
|
|
4265
|
+
const portIds = /* @__PURE__ */ new Set();
|
|
4266
|
+
for (const port of node.ports ?? []) {
|
|
4267
|
+
if (typeof port.id !== "string" || port.id.trim().length === 0) {
|
|
4268
|
+
throw new Error(`GraphDiagram node "${node.id}" port id must be a non-empty string.`);
|
|
4269
|
+
}
|
|
4270
|
+
if (portIds.has(port.id)) throw new Error(`GraphDiagram node "${node.id}" received duplicate port "${port.id}".`);
|
|
4271
|
+
portIds.add(port.id);
|
|
4272
|
+
if (!["top", "right", "bottom", "left"].includes(port.side)) {
|
|
4273
|
+
throw new Error(`GraphDiagram node "${node.id}" port "${port.id}" must use side "top", "right", "bottom", or "left".`);
|
|
4274
|
+
}
|
|
4275
|
+
if (port.offset != null && (!Number.isFinite(port.offset) || port.offset < 0 || port.offset > 1)) {
|
|
4276
|
+
throw new Error(`GraphDiagram node "${node.id}" port "${port.id}" offset must be between 0 and 1.`);
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
3977
4279
|
}
|
|
3978
4280
|
const groupsById = /* @__PURE__ */ new Map();
|
|
3979
4281
|
for (const group of groups) {
|
|
@@ -4017,6 +4319,20 @@ function validateGraphDiagramSpec(nodes, edges, groups, layoutMode) {
|
|
|
4017
4319
|
if (edgeIds.has(edge.id)) throw new Error(`GraphDiagram received duplicate edge id "${edge.id}".`);
|
|
4018
4320
|
edgeIds.add(edge.id);
|
|
4019
4321
|
}
|
|
4322
|
+
for (const side of ["from", "to"]) {
|
|
4323
|
+
const reference = side === "from" ? edge.fromPort : edge.toPort;
|
|
4324
|
+
const endpointSide = side === "from" ? edge.fromSide : edge.toSide;
|
|
4325
|
+
const node = nodes.find((candidate) => candidate.id === edge[side]);
|
|
4326
|
+
if (reference != null && !node.ports?.some((port) => port.id === reference)) {
|
|
4327
|
+
throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" references missing ${side} port "${reference}" on node "${node.id}".`);
|
|
4328
|
+
}
|
|
4329
|
+
if (endpointSide != null && !["top", "right", "bottom", "left"].includes(endpointSide)) {
|
|
4330
|
+
throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" ${side}Side must be "top", "right", "bottom", or "left".`);
|
|
4331
|
+
}
|
|
4332
|
+
if (reference != null && endpointSide != null) {
|
|
4333
|
+
throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" cannot combine ${side}Port and ${side}Side.`);
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4020
4336
|
validateDiagramHref(edge.href, `edge "${edge.id ?? `${edge.from}" -> "${edge.to}`}"`);
|
|
4021
4337
|
}
|
|
4022
4338
|
for (const node of nodes) {
|
|
@@ -4092,6 +4408,8 @@ function GraphDiagram({
|
|
|
4092
4408
|
nodeGap = 34,
|
|
4093
4409
|
rankGap = 64,
|
|
4094
4410
|
edgeGap = 14,
|
|
4411
|
+
routing = "dagre",
|
|
4412
|
+
routingClearance = 12,
|
|
4095
4413
|
sizing = "content",
|
|
4096
4414
|
iconSize = 20,
|
|
4097
4415
|
id,
|
|
@@ -4100,6 +4418,8 @@ function GraphDiagram({
|
|
|
4100
4418
|
description
|
|
4101
4419
|
}) {
|
|
4102
4420
|
if (id != null && id.trim().length === 0) throw new Error("GraphDiagram id must not be empty.");
|
|
4421
|
+
if (!["dagre", "straight", "orthogonal"].includes(routing)) throw new Error('GraphDiagram routing must be "dagre", "straight", or "orthogonal".');
|
|
4422
|
+
if (!Number.isFinite(routingClearance) || routingClearance <= 0) throw new Error("GraphDiagram routingClearance must be a finite positive number.");
|
|
4103
4423
|
const fullyPositioned = nodes.filter((node) => node.x != null && node.y != null).length;
|
|
4104
4424
|
const partiallyPositioned = nodes.some((node) => node.x == null !== (node.y == null));
|
|
4105
4425
|
if (partiallyPositioned || fullyPositioned > 0 && fullyPositioned < nodes.length) {
|
|
@@ -4194,7 +4514,30 @@ function GraphDiagram({
|
|
|
4194
4514
|
} else {
|
|
4195
4515
|
layout = manualGraphLayout(nodes, resolvedWidth, resolvedHeight, nodeWidth, nodeHeight, padding);
|
|
4196
4516
|
}
|
|
4517
|
+
const anchored = (edge) => edge.fromPort != null || edge.toPort != null || edge.fromSide != null || edge.toSide != null;
|
|
4518
|
+
const orthogonalEdges = edges.flatMap((edge, index) => routing === "orthogonal" || routing === "dagre" && anchored(edge) || routing === "straight" && edge.from === edge.to ? [{ edge, index }] : []);
|
|
4519
|
+
const routed = routeOrthogonalGraph(
|
|
4520
|
+
Array.from(layout.values()),
|
|
4521
|
+
orthogonalEdges.map(({ edge }) => edge),
|
|
4522
|
+
resolvedWidth,
|
|
4523
|
+
resolvedHeight,
|
|
4524
|
+
routingClearance,
|
|
4525
|
+
edgeGap,
|
|
4526
|
+
groupLayout.map((group) => ({
|
|
4527
|
+
left: group.cx - group.width / 2,
|
|
4528
|
+
right: group.cx + group.width / 2,
|
|
4529
|
+
top: group.cy - group.height / 2,
|
|
4530
|
+
bottom: group.cy - group.height / 2 + 26
|
|
4531
|
+
}))
|
|
4532
|
+
);
|
|
4533
|
+
const orthogonalPoints = new Map(Array.from(routed.routes, ([index, points]) => [orthogonalEdges[index].index, points]));
|
|
4534
|
+
const failedIndexes = new Set(routed.failures.map((failure) => orthogonalEdges[failure.index].index));
|
|
4535
|
+
const routingFailures = routed.failures.map((failure) => {
|
|
4536
|
+
const { edge } = orthogonalEdges[failure.index];
|
|
4537
|
+
return `Connector "${edge.from}" -> "${edge.to}" was not drawn: ${failure.reason}.`;
|
|
4538
|
+
});
|
|
4197
4539
|
const edgeLayouts = edges.flatMap((edge, index) => {
|
|
4540
|
+
if (failedIndexes.has(index)) return [];
|
|
4198
4541
|
const from = layout.get(edge.from);
|
|
4199
4542
|
const to = layout.get(edge.to);
|
|
4200
4543
|
if (!from || !to) return [];
|
|
@@ -4223,14 +4566,16 @@ function GraphDiagram({
|
|
|
4223
4566
|
{ x: from.cx + 10, y: from.cy - from.height / 2 - loopClearance },
|
|
4224
4567
|
{ x: from.cx + 10, y: from.cy - from.height / 2 }
|
|
4225
4568
|
] : void 0;
|
|
4226
|
-
const
|
|
4569
|
+
const routedPoints = orthogonalPoints.get(index);
|
|
4570
|
+
const points = routedPoints ?? (routing === "straight" ? straightGraphRoute(from, to, edge) : automatic?.points.length ? automatic.points : manualLoopPoints ?? [
|
|
4227
4571
|
{ x: from.cx + dx * fromScale, y: from.cy + dy * fromScale },
|
|
4228
4572
|
{ x: to.cx - dx * toScale, y: to.cy - dy * toScale }
|
|
4229
|
-
];
|
|
4573
|
+
]);
|
|
4230
4574
|
const manualLoopLabel = manualLoopPoints ? {
|
|
4231
4575
|
x: from.cx + from.width / 2 + loopClearance,
|
|
4232
4576
|
y: from.cy - from.height / 2 - loopClearance / 2
|
|
4233
4577
|
} : void 0;
|
|
4578
|
+
const routedLabel = routedPoints || routing === "straight" ? routingLabelPosition(points) : void 0;
|
|
4234
4579
|
return [{
|
|
4235
4580
|
...edge,
|
|
4236
4581
|
index,
|
|
@@ -4238,14 +4583,14 @@ function GraphDiagram({
|
|
|
4238
4583
|
color,
|
|
4239
4584
|
markerId,
|
|
4240
4585
|
points,
|
|
4241
|
-
labelX: automatic?.labelX ?? manualLoopLabel?.x ?? (points[0].x + points[points.length - 1].x) / 2,
|
|
4242
|
-
labelY: automatic?.labelY ?? manualLoopLabel?.y ?? (points[0].y + points[points.length - 1].y) / 2
|
|
4586
|
+
labelX: routedLabel?.x ?? automatic?.labelX ?? manualLoopLabel?.x ?? (points[0].x + points[points.length - 1].x) / 2,
|
|
4587
|
+
labelY: routedLabel?.y ?? automatic?.labelY ?? manualLoopLabel?.y ?? (points[0].y + points[points.length - 1].y) / 2
|
|
4243
4588
|
}];
|
|
4244
4589
|
});
|
|
4245
4590
|
const crossings = connectorCrossings(edgeLayouts);
|
|
4246
4591
|
const labelCollisions = connectorLabelCollisions(edgeLayouts, layout, groupLayout);
|
|
4247
4592
|
const crowdedEndpoints = crowdedConnectorEndpoints(edgeLayouts);
|
|
4248
|
-
const parallelGroups = parallelConnectorGroups(edgeLayouts);
|
|
4593
|
+
const parallelGroups = parallelConnectorGroups(edgeLayouts.filter((edge) => !orthogonalPoints.has(edge.index)));
|
|
4249
4594
|
const groupElements = groupLayout.map((group) => {
|
|
4250
4595
|
const accent = group.muted ? c.textMuted : getToneColor(group.tone ?? "blue", c);
|
|
4251
4596
|
return import_react7.default.createElement("div", {
|
|
@@ -4311,6 +4656,8 @@ function GraphDiagram({
|
|
|
4311
4656
|
"data-vizmatic-connector-label-collisions": labelCollisions,
|
|
4312
4657
|
"data-vizmatic-crowded-connector-endpoints": crowdedEndpoints,
|
|
4313
4658
|
"data-vizmatic-parallel-connector-groups": parallelGroups,
|
|
4659
|
+
"data-vizmatic-unrouted-connectors": routingFailures.length,
|
|
4660
|
+
"data-vizmatic-routing-failures": routingFailures.length ? JSON.stringify(routingFailures) : void 0,
|
|
4314
4661
|
style: {
|
|
4315
4662
|
position: "relative",
|
|
4316
4663
|
display: "flex",
|
|
@@ -5568,6 +5915,8 @@ function DataflowDiagram({
|
|
|
5568
5915
|
nodeGap,
|
|
5569
5916
|
rankGap,
|
|
5570
5917
|
edgeGap,
|
|
5918
|
+
routing,
|
|
5919
|
+
routingClearance,
|
|
5571
5920
|
sizing,
|
|
5572
5921
|
iconSize
|
|
5573
5922
|
}) {
|
|
@@ -5593,6 +5942,8 @@ function DataflowDiagram({
|
|
|
5593
5942
|
nodeGap,
|
|
5594
5943
|
rankGap,
|
|
5595
5944
|
edgeGap,
|
|
5945
|
+
routing,
|
|
5946
|
+
routingClearance,
|
|
5596
5947
|
sizing,
|
|
5597
5948
|
iconSize
|
|
5598
5949
|
});
|
|
@@ -5721,8 +6072,8 @@ function portIdentity(port) {
|
|
|
5721
6072
|
function portText(port) {
|
|
5722
6073
|
if (typeof port === "string" || typeof port === "number") return String(port);
|
|
5723
6074
|
if (port.label) return port.label;
|
|
5724
|
-
const
|
|
5725
|
-
return [port.protocol,
|
|
6075
|
+
const endpoint2 = port.port ?? port.id;
|
|
6076
|
+
return [port.protocol, endpoint2 == null ? void 0 : String(endpoint2)].filter(Boolean).join("/") || port.direction || "port";
|
|
5726
6077
|
}
|
|
5727
6078
|
function portForReference(node, reference) {
|
|
5728
6079
|
if (reference == null) return void 0;
|
|
@@ -5832,6 +6183,9 @@ function compileDeployment(spec) {
|
|
|
5832
6183
|
const boundaries = spec.boundaries ?? [];
|
|
5833
6184
|
const connections = spec.connections ?? [];
|
|
5834
6185
|
validateDeploymentSpec(boundaries, spec.nodes, connections);
|
|
6186
|
+
const anchorPorts = spec.routing != null && spec.routing !== "dagre";
|
|
6187
|
+
const incomingSide = spec.direction === "TB" ? "top" : spec.direction === "BT" ? "bottom" : spec.direction === "RL" ? "right" : "left";
|
|
6188
|
+
const outgoingSide = spec.direction === "TB" ? "bottom" : spec.direction === "BT" ? "top" : spec.direction === "RL" ? "left" : "right";
|
|
5835
6189
|
const groups = boundaries.map((boundary) => ({
|
|
5836
6190
|
id: boundary.id,
|
|
5837
6191
|
label: boundary.label,
|
|
@@ -5858,7 +6212,16 @@ function compileDeployment(spec) {
|
|
|
5858
6212
|
height: node.height,
|
|
5859
6213
|
group: node.boundary,
|
|
5860
6214
|
icon: node.icon ?? nodeKindIcons[kind],
|
|
5861
|
-
iconSize: node.iconSize
|
|
6215
|
+
iconSize: node.iconSize,
|
|
6216
|
+
ports: anchorPorts ? nodePorts.map((port, index) => {
|
|
6217
|
+
const incoming = typeof port === "object" ? port.direction === "ingress" : false;
|
|
6218
|
+
const targetOnly = connections.some((connection) => connection.to === node.id && String(connection.toPort) === portIdentity(port)) && !connections.some((connection) => connection.from === node.id && String(connection.fromPort) === portIdentity(port));
|
|
6219
|
+
return {
|
|
6220
|
+
id: portIdentity(port),
|
|
6221
|
+
side: typeof port === "object" && port.side != null ? port.side : incoming || targetOnly ? incomingSide : outgoingSide,
|
|
6222
|
+
offset: typeof port === "object" && port.offset != null ? port.offset : (index + 1) / (nodePorts.length + 1)
|
|
6223
|
+
};
|
|
6224
|
+
}) : void 0
|
|
5862
6225
|
};
|
|
5863
6226
|
});
|
|
5864
6227
|
const edges = connections.map((connection) => {
|
|
@@ -5882,7 +6245,11 @@ function compileDeployment(spec) {
|
|
|
5882
6245
|
arrow: connection.arrow ?? "forward",
|
|
5883
6246
|
label: connectionLabel(connection, sourcePort ?? fallbackFromPort, targetPort ?? fallbackToPort),
|
|
5884
6247
|
href: connection.href,
|
|
5885
|
-
title: connection.title
|
|
6248
|
+
title: connection.title,
|
|
6249
|
+
fromPort: anchorPorts && fromReference != null ? String(fromReference) : void 0,
|
|
6250
|
+
toPort: anchorPorts && toReference != null ? String(toReference) : void 0,
|
|
6251
|
+
fromSide: connection.fromSide,
|
|
6252
|
+
toSide: connection.toSide
|
|
5886
6253
|
};
|
|
5887
6254
|
});
|
|
5888
6255
|
return {
|
|
@@ -5900,7 +6267,7 @@ function DeploymentDiagram({
|
|
|
5900
6267
|
ariaLabel = "Deployment diagram",
|
|
5901
6268
|
...graphProps
|
|
5902
6269
|
}) {
|
|
5903
|
-
const compiled = compileDeployment({ nodes, boundaries, connections, ariaLabel });
|
|
6270
|
+
const compiled = compileDeployment({ nodes, boundaries, connections, ariaLabel, direction: graphProps.direction, routing: graphProps.routing });
|
|
5904
6271
|
return GraphDiagram({
|
|
5905
6272
|
...graphProps,
|
|
5906
6273
|
c,
|
|
@@ -6126,11 +6493,11 @@ function compileTransformer(spec) {
|
|
|
6126
6493
|
for (const route of routes) {
|
|
6127
6494
|
const kind = resolveRouteKind(route);
|
|
6128
6495
|
const endpoints = expandedRouteEndpoints(route, repeatCounts, expandRepeats);
|
|
6129
|
-
for (const [index,
|
|
6496
|
+
for (const [index, endpoint2] of endpoints.entries()) {
|
|
6130
6497
|
edges.push({
|
|
6131
6498
|
id: route.id == null ? void 0 : endpoints.length === 1 ? route.id : `${route.id}-${index + 1}`,
|
|
6132
|
-
from:
|
|
6133
|
-
to:
|
|
6499
|
+
from: endpoint2.from,
|
|
6500
|
+
to: endpoint2.to,
|
|
6134
6501
|
tone: route.tone ?? routeTones[kind],
|
|
6135
6502
|
muted: route.muted,
|
|
6136
6503
|
kind: graphRouteKind(kind),
|
|
@@ -6805,7 +7172,138 @@ function AxisPlot({
|
|
|
6805
7172
|
}
|
|
6806
7173
|
|
|
6807
7174
|
// src/primitives/charts.ts
|
|
7175
|
+
var import_react12 = __toESM(require("react"), 1);
|
|
7176
|
+
|
|
7177
|
+
// src/canvas-chart-fit.ts
|
|
6808
7178
|
var import_react11 = __toESM(require("react"), 1);
|
|
7179
|
+
var CANVAS_CHART_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.canvasChartComponent");
|
|
7180
|
+
var CHART_FRAME_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.chartFrameComponent");
|
|
7181
|
+
var FIT_PROP = "__vizmaticCanvasChartFit";
|
|
7182
|
+
var SCOPE_PROP = "data-vizmatic-chart-fit-scope";
|
|
7183
|
+
var VIEWPORT_PROP = "data-vizmatic-chart-fit-viewport";
|
|
7184
|
+
function isCanvasChart(component) {
|
|
7185
|
+
return typeof component === "function" && Boolean(component[CANVAS_CHART_COMPONENT]);
|
|
7186
|
+
}
|
|
7187
|
+
function CanvasChartFit({ children, width, height }) {
|
|
7188
|
+
let chart = children;
|
|
7189
|
+
for (let depth = 0; (0, import_react11.isValidElement)(chart) && typeof chart.type === "function" && depth < 16; depth += 1) {
|
|
7190
|
+
if (chart.type[CHART_FRAME_COMPONENT]) {
|
|
7191
|
+
const props = chart.props;
|
|
7192
|
+
const padding = typeof props.padding === "number" ? props.padding : 16;
|
|
7193
|
+
chart = import_react11.default.cloneElement(chart, {
|
|
7194
|
+
...props,
|
|
7195
|
+
width: typeof props.width === "number" ? props.width + 2 * (padding + 1) : props.width,
|
|
7196
|
+
height: void 0
|
|
7197
|
+
});
|
|
7198
|
+
break;
|
|
7199
|
+
}
|
|
7200
|
+
chart = chart.type(chart.props);
|
|
7201
|
+
}
|
|
7202
|
+
return import_react11.default.createElement("div", {
|
|
7203
|
+
[FIT_PROP]: { width, height },
|
|
7204
|
+
style: { position: "relative", display: "flex", width, height, flexShrink: 0 }
|
|
7205
|
+
}, import_react11.default.createElement("div", {
|
|
7206
|
+
style: { position: "absolute", left: 0, top: 0, display: "flex", alignItems: "flex-start" }
|
|
7207
|
+
}, chart));
|
|
7208
|
+
}
|
|
7209
|
+
function prepareChartFits(element) {
|
|
7210
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
7211
|
+
const visit = (node, scope) => {
|
|
7212
|
+
if (Array.isArray(node)) return node.map((child) => visit(child, scope));
|
|
7213
|
+
if (!(0, import_react11.isValidElement)(node)) return node;
|
|
7214
|
+
if (typeof node.type === "function") {
|
|
7215
|
+
const resolved = visit(node.type(node.props), scope);
|
|
7216
|
+
return node.key != null && (0, import_react11.isValidElement)(resolved) ? import_react11.default.cloneElement(resolved, { key: node.key }) : resolved;
|
|
7217
|
+
}
|
|
7218
|
+
const size = node.props[FIT_PROP];
|
|
7219
|
+
const props = { ...node.props };
|
|
7220
|
+
delete props[FIT_PROP];
|
|
7221
|
+
if (size) {
|
|
7222
|
+
const id = String(sizes.size);
|
|
7223
|
+
sizes.set(id, size);
|
|
7224
|
+
props[VIEWPORT_PROP] = id;
|
|
7225
|
+
return import_react11.default.cloneElement(node, props, visit(node.props.children, id));
|
|
7226
|
+
}
|
|
7227
|
+
if (scope !== void 0 && typeof node.type === "string") props[SCOPE_PROP] = scope;
|
|
7228
|
+
const children = node.props.children;
|
|
7229
|
+
return children === void 0 ? import_react11.default.cloneElement(node, props) : import_react11.default.cloneElement(node, props, visit(children, scope));
|
|
7230
|
+
};
|
|
7231
|
+
return { element: visit(element), sizes };
|
|
7232
|
+
}
|
|
7233
|
+
function fittedTree(element, geometry) {
|
|
7234
|
+
if (Array.isArray(element)) return element.map((child) => fittedTree(child, geometry));
|
|
7235
|
+
if (!(0, import_react11.isValidElement)(element)) return element;
|
|
7236
|
+
const id = element.props[VIEWPORT_PROP];
|
|
7237
|
+
const children = element.props.children;
|
|
7238
|
+
if (typeof id === "string") {
|
|
7239
|
+
const fit = geometry.get(id);
|
|
7240
|
+
const content = import_react11.default.Children.only(children);
|
|
7241
|
+
return import_react11.default.cloneElement(element, {}, import_react11.default.cloneElement(content, { style: {
|
|
7242
|
+
...content.props.style,
|
|
7243
|
+
left: fit.left,
|
|
7244
|
+
top: fit.top,
|
|
7245
|
+
transform: `scale(${fit.scale})`,
|
|
7246
|
+
transformOrigin: "top left"
|
|
7247
|
+
} }));
|
|
7248
|
+
}
|
|
7249
|
+
return children === void 0 ? element : import_react11.default.cloneElement(element, {}, fittedTree(children, geometry));
|
|
7250
|
+
}
|
|
7251
|
+
async function renderWithCanvasChartFit(render, element, options) {
|
|
7252
|
+
const prepared = prepareChartFits(element);
|
|
7253
|
+
if (!prepared.sizes.size) return render(prepared.element, options);
|
|
7254
|
+
const viewports = /* @__PURE__ */ new Map();
|
|
7255
|
+
const bounds = /* @__PURE__ */ new Map();
|
|
7256
|
+
await render(prepared.element, { ...options, onNodeDetected(node) {
|
|
7257
|
+
const viewport = node.props[VIEWPORT_PROP];
|
|
7258
|
+
if (typeof viewport === "string") viewports.set(viewport, node);
|
|
7259
|
+
const id = node.props[SCOPE_PROP];
|
|
7260
|
+
if (typeof id !== "string" || node.width <= 0 || node.height <= 0) return;
|
|
7261
|
+
const prior = bounds.get(id);
|
|
7262
|
+
bounds.set(id, {
|
|
7263
|
+
left: Math.min(prior?.left ?? Infinity, node.left),
|
|
7264
|
+
top: Math.min(prior?.top ?? Infinity, node.top),
|
|
7265
|
+
right: Math.max(prior?.right ?? -Infinity, node.left + node.width),
|
|
7266
|
+
bottom: Math.max(prior?.bottom ?? -Infinity, node.top + node.height)
|
|
7267
|
+
});
|
|
7268
|
+
} });
|
|
7269
|
+
const geometry = /* @__PURE__ */ new Map();
|
|
7270
|
+
for (const [id, size] of prepared.sizes) {
|
|
7271
|
+
const viewport = viewports.get(id);
|
|
7272
|
+
const measured = bounds.get(id);
|
|
7273
|
+
if (!viewport || !measured) throw new Error("Could not measure the chart inside CanvasItem.");
|
|
7274
|
+
const width = measured.right - measured.left, height = measured.bottom - measured.top;
|
|
7275
|
+
const scale = Math.min(size.width / width, size.height / height);
|
|
7276
|
+
if (!Number.isFinite(scale) || scale <= 0) throw new Error("CanvasItem charts require positive, finite dimensions.");
|
|
7277
|
+
geometry.set(id, {
|
|
7278
|
+
...size,
|
|
7279
|
+
scale,
|
|
7280
|
+
left: (size.width - width * scale) / 2 - (measured.left - viewport.left) * scale,
|
|
7281
|
+
top: (size.height - height * scale) / 2 - (measured.top - viewport.top) * scale
|
|
7282
|
+
});
|
|
7283
|
+
}
|
|
7284
|
+
const finalViewports = /* @__PURE__ */ new Map();
|
|
7285
|
+
return render(fittedTree(prepared.element, geometry), { ...options, onNodeDetected(node) {
|
|
7286
|
+
const viewport = node.props[VIEWPORT_PROP];
|
|
7287
|
+
if (typeof viewport === "string") finalViewports.set(viewport, node);
|
|
7288
|
+
const id = node.props[SCOPE_PROP];
|
|
7289
|
+
const fit = typeof id === "string" ? geometry.get(id) : void 0;
|
|
7290
|
+
const origin = typeof id === "string" ? finalViewports.get(id) : void 0;
|
|
7291
|
+
if (fit && origin) {
|
|
7292
|
+
const left = origin.left + fit.left, top = origin.top + fit.top;
|
|
7293
|
+
const style = node.props.style ?? {};
|
|
7294
|
+
options.onNodeDetected?.({
|
|
7295
|
+
...node,
|
|
7296
|
+
left: left + (node.left - left) * fit.scale,
|
|
7297
|
+
top: top + (node.top - top) * fit.scale,
|
|
7298
|
+
width: node.width * fit.scale,
|
|
7299
|
+
height: node.height * fit.scale,
|
|
7300
|
+
props: { ...node.props, style: { ...style, ...typeof style.fontSize === "number" ? { fontSize: style.fontSize * fit.scale } : {} } }
|
|
7301
|
+
});
|
|
7302
|
+
} else options.onNodeDetected?.(node);
|
|
7303
|
+
} });
|
|
7304
|
+
}
|
|
7305
|
+
|
|
7306
|
+
// src/primitives/charts.ts
|
|
6809
7307
|
var chartPalette = ["primary", "secondary", "positive", "warning", "info", "accent", "critical"];
|
|
6810
7308
|
function isColorName(value) {
|
|
6811
7309
|
return chartPalette.includes(value) || value === "neutral";
|
|
@@ -6895,7 +7393,7 @@ function chartLabel(key, text, x, y, c, options = {}) {
|
|
|
6895
7393
|
);
|
|
6896
7394
|
transform = void 0;
|
|
6897
7395
|
}
|
|
6898
|
-
return
|
|
7396
|
+
return import_react12.default.createElement("div", {
|
|
6899
7397
|
key,
|
|
6900
7398
|
style: {
|
|
6901
7399
|
position: "absolute",
|
|
@@ -6937,7 +7435,10 @@ function pointLabelPlacement(x, y, plot, index, width = 70) {
|
|
|
6937
7435
|
}
|
|
6938
7436
|
};
|
|
6939
7437
|
}
|
|
6940
|
-
function ChartFrame({
|
|
7438
|
+
function ChartFrame(props) {
|
|
7439
|
+
return import_react12.default.createElement(ChartFrameContent, props);
|
|
7440
|
+
}
|
|
7441
|
+
function ChartFrameContent({
|
|
6941
7442
|
children,
|
|
6942
7443
|
c,
|
|
6943
7444
|
title,
|
|
@@ -6948,7 +7449,7 @@ function ChartFrame({
|
|
|
6948
7449
|
height,
|
|
6949
7450
|
padding = 16
|
|
6950
7451
|
}) {
|
|
6951
|
-
return
|
|
7452
|
+
return import_react12.default.createElement(
|
|
6952
7453
|
"div",
|
|
6953
7454
|
{
|
|
6954
7455
|
style: {
|
|
@@ -6965,20 +7466,20 @@ function ChartFrame({
|
|
|
6965
7466
|
boxShadow: `0 9px 24px ${c.shadow}`
|
|
6966
7467
|
}
|
|
6967
7468
|
},
|
|
6968
|
-
(title || subtitle) &&
|
|
7469
|
+
(title || subtitle) && import_react12.default.createElement(
|
|
6969
7470
|
"div",
|
|
6970
7471
|
{
|
|
6971
7472
|
style: { display: "flex", flexDirection: "column", gap: 4, minWidth: 0, maxWidth: "100%" }
|
|
6972
7473
|
},
|
|
6973
|
-
title &&
|
|
7474
|
+
title && import_react12.default.createElement("div", {
|
|
6974
7475
|
style: { ...typography.small, ...textFitStyle(), color: c.textPrimary, fontWeight: 900 }
|
|
6975
7476
|
}, title),
|
|
6976
|
-
subtitle &&
|
|
7477
|
+
subtitle && import_react12.default.createElement("div", {
|
|
6977
7478
|
style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary, lineHeight: 1.35 }
|
|
6978
7479
|
}, subtitle)
|
|
6979
7480
|
),
|
|
6980
7481
|
children,
|
|
6981
|
-
(legend || footer) &&
|
|
7482
|
+
(legend || footer) && import_react12.default.createElement(
|
|
6982
7483
|
"div",
|
|
6983
7484
|
{
|
|
6984
7485
|
style: {
|
|
@@ -6989,18 +7490,18 @@ function ChartFrame({
|
|
|
6989
7490
|
minHeight: 18
|
|
6990
7491
|
}
|
|
6991
7492
|
},
|
|
6992
|
-
legend &&
|
|
7493
|
+
legend && import_react12.default.createElement(
|
|
6993
7494
|
"div",
|
|
6994
7495
|
{
|
|
6995
7496
|
style: { display: "flex", alignItems: "center", gap: 12, flexWrap: "wrap", minWidth: 0 }
|
|
6996
7497
|
},
|
|
6997
|
-
...legend.map((item, index) =>
|
|
7498
|
+
...legend.map((item, index) => import_react12.default.createElement(
|
|
6998
7499
|
"div",
|
|
6999
7500
|
{
|
|
7000
7501
|
key: `${item.label}-${index}`,
|
|
7001
7502
|
style: { display: "flex", alignItems: "center", gap: 6, minWidth: 0 }
|
|
7002
7503
|
},
|
|
7003
|
-
|
|
7504
|
+
import_react12.default.createElement("span", {
|
|
7004
7505
|
style: {
|
|
7005
7506
|
width: 14,
|
|
7006
7507
|
height: 3,
|
|
@@ -7009,17 +7510,18 @@ function ChartFrame({
|
|
|
7009
7510
|
display: "flex"
|
|
7010
7511
|
}
|
|
7011
7512
|
}),
|
|
7012
|
-
|
|
7513
|
+
import_react12.default.createElement("span", {
|
|
7013
7514
|
style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary }
|
|
7014
7515
|
}, item.label)
|
|
7015
7516
|
))
|
|
7016
7517
|
),
|
|
7017
|
-
footer &&
|
|
7518
|
+
footer && import_react12.default.createElement("div", {
|
|
7018
7519
|
style: { ...typography.tiny, ...textFitStyle("right"), color: c.textMuted }
|
|
7019
7520
|
}, footer)
|
|
7020
7521
|
)
|
|
7021
7522
|
);
|
|
7022
7523
|
}
|
|
7524
|
+
Object.defineProperty(ChartFrameContent, CHART_FRAME_COMPONENT, { value: true });
|
|
7023
7525
|
function polarPoint(cx, cy, radius, angleDegrees) {
|
|
7024
7526
|
const radians = angleDegrees * Math.PI / 180;
|
|
7025
7527
|
return {
|
|
@@ -7043,6 +7545,153 @@ function donutArcPath(cx, cy, outerRadius, innerRadius, startAngle, endAngle) {
|
|
|
7043
7545
|
"Z"
|
|
7044
7546
|
].join(" ");
|
|
7045
7547
|
}
|
|
7548
|
+
function validateNonNegativeSegments(segments, chartName) {
|
|
7549
|
+
let total = 0;
|
|
7550
|
+
for (const segment of segments) {
|
|
7551
|
+
if (!Number.isFinite(segment.value) || segment.value < 0) {
|
|
7552
|
+
throw new RangeError(`${chartName} values must be finite, non-negative numbers.`);
|
|
7553
|
+
}
|
|
7554
|
+
total += segment.value;
|
|
7555
|
+
if (!Number.isFinite(total)) {
|
|
7556
|
+
throw new RangeError(`${chartName} total must be finite.`);
|
|
7557
|
+
}
|
|
7558
|
+
}
|
|
7559
|
+
return total;
|
|
7560
|
+
}
|
|
7561
|
+
function pieSectorPath(cx, cy, radius, startAngle, endAngle) {
|
|
7562
|
+
const span = endAngle - startAngle;
|
|
7563
|
+
const start = polarPoint(cx, cy, radius, startAngle);
|
|
7564
|
+
if (span >= 359.999) {
|
|
7565
|
+
const opposite = polarPoint(cx, cy, radius, startAngle + 180);
|
|
7566
|
+
return [
|
|
7567
|
+
`M ${cx} ${cy}`,
|
|
7568
|
+
`L ${start.x} ${start.y}`,
|
|
7569
|
+
`A ${radius} ${radius} 0 1 1 ${opposite.x} ${opposite.y}`,
|
|
7570
|
+
`A ${radius} ${radius} 0 1 1 ${start.x} ${start.y}`,
|
|
7571
|
+
"Z"
|
|
7572
|
+
].join(" ");
|
|
7573
|
+
}
|
|
7574
|
+
const end = polarPoint(cx, cy, radius, endAngle);
|
|
7575
|
+
const largeArc = span > 180 ? 1 : 0;
|
|
7576
|
+
return `M ${cx} ${cy} L ${start.x} ${start.y} A ${radius} ${radius} 0 ${largeArc} 1 ${end.x} ${end.y} Z`;
|
|
7577
|
+
}
|
|
7578
|
+
function PieChart({
|
|
7579
|
+
segments,
|
|
7580
|
+
c,
|
|
7581
|
+
title,
|
|
7582
|
+
subtitle,
|
|
7583
|
+
width = 360,
|
|
7584
|
+
height = 240,
|
|
7585
|
+
size,
|
|
7586
|
+
format = "decimal",
|
|
7587
|
+
showLegend = true,
|
|
7588
|
+
footer
|
|
7589
|
+
}) {
|
|
7590
|
+
const total = validateNonNegativeSegments(segments, "PieChart");
|
|
7591
|
+
const positiveSegments = segments.filter((segment) => segment.value > 0);
|
|
7592
|
+
const resolvedSize = size ?? Math.min(184, Math.max(132, height - 44), Math.max(132, width * 0.5));
|
|
7593
|
+
const radius = resolvedSize / 2 - 2;
|
|
7594
|
+
const cx = resolvedSize / 2;
|
|
7595
|
+
const cy = resolvedSize / 2;
|
|
7596
|
+
let cursor = -90;
|
|
7597
|
+
const paths = positiveSegments.map((segment, index) => {
|
|
7598
|
+
const span = total > 0 ? segment.value / total * 360 : 0;
|
|
7599
|
+
const start = cursor;
|
|
7600
|
+
const end = index === positiveSegments.length - 1 ? 270 : cursor + span;
|
|
7601
|
+
cursor += span;
|
|
7602
|
+
return import_react12.default.createElement("path", {
|
|
7603
|
+
key: `pie-segment-${segment.label}-${index}`,
|
|
7604
|
+
d: pieSectorPath(cx, cy, radius, start, end),
|
|
7605
|
+
fill: chartColor(segment.color, c, index),
|
|
7606
|
+
stroke: c.bgCard,
|
|
7607
|
+
strokeWidth: positiveSegments.length > 1 ? 2 : 0,
|
|
7608
|
+
"data-pie-label": segment.label,
|
|
7609
|
+
"data-pie-value": segment.value,
|
|
7610
|
+
"data-pie-share": total > 0 ? segment.value / total : 0
|
|
7611
|
+
});
|
|
7612
|
+
});
|
|
7613
|
+
const legend = showLegend && positiveSegments.length > 0 && import_react12.default.createElement("div", {
|
|
7614
|
+
style: {
|
|
7615
|
+
display: "flex",
|
|
7616
|
+
flexDirection: "column",
|
|
7617
|
+
gap: 8,
|
|
7618
|
+
flex: 1,
|
|
7619
|
+
minWidth: 112
|
|
7620
|
+
}
|
|
7621
|
+
}, ...positiveSegments.map((segment, index) => {
|
|
7622
|
+
const formattedValue = formatChartValue(segment.value, format);
|
|
7623
|
+
const share = formatChartValue(segment.value / total, "percent");
|
|
7624
|
+
const label = segment.valueLabel ?? (format === "percent" ? formattedValue : `${formattedValue} \xB7 ${share}`);
|
|
7625
|
+
return import_react12.default.createElement(
|
|
7626
|
+
"div",
|
|
7627
|
+
{
|
|
7628
|
+
key: `pie-legend-${segment.label}-${index}`,
|
|
7629
|
+
style: { display: "flex", alignItems: "center", gap: 8, minWidth: 0 }
|
|
7630
|
+
},
|
|
7631
|
+
import_react12.default.createElement("span", {
|
|
7632
|
+
style: {
|
|
7633
|
+
display: "flex",
|
|
7634
|
+
width: 10,
|
|
7635
|
+
height: 10,
|
|
7636
|
+
borderRadius: 3,
|
|
7637
|
+
backgroundColor: chartColor(segment.color, c, index),
|
|
7638
|
+
flexShrink: 0
|
|
7639
|
+
}
|
|
7640
|
+
}),
|
|
7641
|
+
import_react12.default.createElement("span", {
|
|
7642
|
+
style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary, flex: 1 }
|
|
7643
|
+
}, segment.label),
|
|
7644
|
+
import_react12.default.createElement("span", {
|
|
7645
|
+
style: {
|
|
7646
|
+
...typography.tiny,
|
|
7647
|
+
color: c.textPrimary,
|
|
7648
|
+
fontFamily: "JetBrains Mono",
|
|
7649
|
+
fontWeight: 850,
|
|
7650
|
+
flexShrink: 0
|
|
7651
|
+
}
|
|
7652
|
+
}, label)
|
|
7653
|
+
);
|
|
7654
|
+
}));
|
|
7655
|
+
return ChartFrame({
|
|
7656
|
+
c,
|
|
7657
|
+
title,
|
|
7658
|
+
subtitle,
|
|
7659
|
+
footer,
|
|
7660
|
+
width,
|
|
7661
|
+
children: import_react12.default.createElement(
|
|
7662
|
+
"div",
|
|
7663
|
+
{
|
|
7664
|
+
style: {
|
|
7665
|
+
display: "flex",
|
|
7666
|
+
alignItems: "center",
|
|
7667
|
+
justifyContent: showLegend ? "space-between" : "center",
|
|
7668
|
+
gap: 18,
|
|
7669
|
+
minHeight: resolvedSize,
|
|
7670
|
+
width: "100%"
|
|
7671
|
+
}
|
|
7672
|
+
},
|
|
7673
|
+
import_react12.default.createElement(
|
|
7674
|
+
"svg",
|
|
7675
|
+
{
|
|
7676
|
+
width: resolvedSize,
|
|
7677
|
+
height: resolvedSize,
|
|
7678
|
+
viewBox: `0 0 ${resolvedSize} ${resolvedSize}`,
|
|
7679
|
+
role: "img",
|
|
7680
|
+
"aria-label": title ?? "Pie chart"
|
|
7681
|
+
},
|
|
7682
|
+
positiveSegments.length === 0 ? import_react12.default.createElement("circle", {
|
|
7683
|
+
cx,
|
|
7684
|
+
cy,
|
|
7685
|
+
r: radius,
|
|
7686
|
+
fill: "none",
|
|
7687
|
+
stroke: c.borderLight,
|
|
7688
|
+
strokeWidth: 2
|
|
7689
|
+
}) : paths
|
|
7690
|
+
),
|
|
7691
|
+
legend
|
|
7692
|
+
)
|
|
7693
|
+
});
|
|
7694
|
+
}
|
|
7046
7695
|
function DonutChart({
|
|
7047
7696
|
segments,
|
|
7048
7697
|
c,
|
|
@@ -7075,13 +7724,13 @@ function DonutChart({
|
|
|
7075
7724
|
const end = cursor + rawSpan - gap / 2;
|
|
7076
7725
|
cursor += rawSpan;
|
|
7077
7726
|
if (end <= start) return null;
|
|
7078
|
-
return
|
|
7727
|
+
return import_react12.default.createElement("path", {
|
|
7079
7728
|
key: `donut-segment-${segment.label}-${index}`,
|
|
7080
7729
|
d: donutArcPath(cx, cy, outerRadius, innerRadius, start, end),
|
|
7081
7730
|
fill: chartColor(segment.color, c, index)
|
|
7082
7731
|
});
|
|
7083
7732
|
}).filter(Boolean);
|
|
7084
|
-
const legend = showLegend && positiveSegments.length > 0 &&
|
|
7733
|
+
const legend = showLegend && positiveSegments.length > 0 && import_react12.default.createElement("div", {
|
|
7085
7734
|
style: {
|
|
7086
7735
|
display: "flex",
|
|
7087
7736
|
flexDirection: "column",
|
|
@@ -7089,7 +7738,7 @@ function DonutChart({
|
|
|
7089
7738
|
flex: 1,
|
|
7090
7739
|
minWidth: 112
|
|
7091
7740
|
}
|
|
7092
|
-
}, ...positiveSegments.map((segment, index) =>
|
|
7741
|
+
}, ...positiveSegments.map((segment, index) => import_react12.default.createElement(
|
|
7093
7742
|
"div",
|
|
7094
7743
|
{
|
|
7095
7744
|
key: `donut-legend-${segment.label}-${index}`,
|
|
@@ -7100,7 +7749,7 @@ function DonutChart({
|
|
|
7100
7749
|
minWidth: 0
|
|
7101
7750
|
}
|
|
7102
7751
|
},
|
|
7103
|
-
|
|
7752
|
+
import_react12.default.createElement("span", {
|
|
7104
7753
|
style: {
|
|
7105
7754
|
display: "flex",
|
|
7106
7755
|
width: 10,
|
|
@@ -7110,7 +7759,7 @@ function DonutChart({
|
|
|
7110
7759
|
flexShrink: 0
|
|
7111
7760
|
}
|
|
7112
7761
|
}),
|
|
7113
|
-
|
|
7762
|
+
import_react12.default.createElement("span", {
|
|
7114
7763
|
style: {
|
|
7115
7764
|
...typography.tiny,
|
|
7116
7765
|
...textFitStyle(),
|
|
@@ -7118,7 +7767,7 @@ function DonutChart({
|
|
|
7118
7767
|
flex: 1
|
|
7119
7768
|
}
|
|
7120
7769
|
}, segment.label),
|
|
7121
|
-
|
|
7770
|
+
import_react12.default.createElement("span", {
|
|
7122
7771
|
style: {
|
|
7123
7772
|
...typography.tiny,
|
|
7124
7773
|
color: c.textPrimary,
|
|
@@ -7136,7 +7785,7 @@ function DonutChart({
|
|
|
7136
7785
|
width,
|
|
7137
7786
|
height,
|
|
7138
7787
|
padding: 16,
|
|
7139
|
-
children:
|
|
7788
|
+
children: import_react12.default.createElement(
|
|
7140
7789
|
"div",
|
|
7141
7790
|
{
|
|
7142
7791
|
style: {
|
|
@@ -7148,7 +7797,7 @@ function DonutChart({
|
|
|
7148
7797
|
width: "100%"
|
|
7149
7798
|
}
|
|
7150
7799
|
},
|
|
7151
|
-
|
|
7800
|
+
import_react12.default.createElement(
|
|
7152
7801
|
"div",
|
|
7153
7802
|
{
|
|
7154
7803
|
style: {
|
|
@@ -7159,14 +7808,14 @@ function DonutChart({
|
|
|
7159
7808
|
flexShrink: 0
|
|
7160
7809
|
}
|
|
7161
7810
|
},
|
|
7162
|
-
|
|
7811
|
+
import_react12.default.createElement(
|
|
7163
7812
|
"svg",
|
|
7164
7813
|
{
|
|
7165
7814
|
width: resolvedSize,
|
|
7166
7815
|
height: resolvedSize,
|
|
7167
7816
|
viewBox: `0 0 ${resolvedSize} ${resolvedSize}`
|
|
7168
7817
|
},
|
|
7169
|
-
positiveSegments.length === 0 ?
|
|
7818
|
+
positiveSegments.length === 0 ? import_react12.default.createElement("circle", {
|
|
7170
7819
|
cx,
|
|
7171
7820
|
cy,
|
|
7172
7821
|
r: (outerRadius + innerRadius) / 2,
|
|
@@ -7175,7 +7824,7 @@ function DonutChart({
|
|
|
7175
7824
|
strokeWidth: resolvedThickness
|
|
7176
7825
|
}) : paths
|
|
7177
7826
|
),
|
|
7178
|
-
(centerLabel != null || resolvedCenterValue != null) &&
|
|
7827
|
+
(centerLabel != null || resolvedCenterValue != null) && import_react12.default.createElement(
|
|
7179
7828
|
"div",
|
|
7180
7829
|
{
|
|
7181
7830
|
style: {
|
|
@@ -7194,7 +7843,7 @@ function DonutChart({
|
|
|
7194
7843
|
textAlign: "center"
|
|
7195
7844
|
}
|
|
7196
7845
|
},
|
|
7197
|
-
resolvedCenterValue != null &&
|
|
7846
|
+
resolvedCenterValue != null && import_react12.default.createElement("div", {
|
|
7198
7847
|
style: {
|
|
7199
7848
|
...typography.small,
|
|
7200
7849
|
color: c.textPrimary,
|
|
@@ -7205,7 +7854,7 @@ function DonutChart({
|
|
|
7205
7854
|
...textFitStyle("center")
|
|
7206
7855
|
}
|
|
7207
7856
|
}, resolvedCenterValue),
|
|
7208
|
-
centerLabel != null &&
|
|
7857
|
+
centerLabel != null && import_react12.default.createElement("div", {
|
|
7209
7858
|
style: {
|
|
7210
7859
|
...typography.tiny,
|
|
7211
7860
|
color: c.textMuted,
|
|
@@ -7230,7 +7879,7 @@ function StackedBar({
|
|
|
7230
7879
|
}) {
|
|
7231
7880
|
const positiveSegments = segments.filter((segment) => segment.value > 0);
|
|
7232
7881
|
const total = positiveSegments.reduce((sum, segment) => sum + segment.value, 0);
|
|
7233
|
-
return
|
|
7882
|
+
return import_react12.default.createElement(
|
|
7234
7883
|
"div",
|
|
7235
7884
|
{
|
|
7236
7885
|
style: {
|
|
@@ -7240,7 +7889,7 @@ function StackedBar({
|
|
|
7240
7889
|
gap: 10
|
|
7241
7890
|
}
|
|
7242
7891
|
},
|
|
7243
|
-
(title || subtitle) &&
|
|
7892
|
+
(title || subtitle) && import_react12.default.createElement(
|
|
7244
7893
|
"div",
|
|
7245
7894
|
{
|
|
7246
7895
|
style: {
|
|
@@ -7249,14 +7898,14 @@ function StackedBar({
|
|
|
7249
7898
|
gap: 3
|
|
7250
7899
|
}
|
|
7251
7900
|
},
|
|
7252
|
-
title &&
|
|
7901
|
+
title && import_react12.default.createElement("div", {
|
|
7253
7902
|
style: { ...typography.label, color: c.textPrimary, fontWeight: 850 }
|
|
7254
7903
|
}, title),
|
|
7255
|
-
subtitle &&
|
|
7904
|
+
subtitle && import_react12.default.createElement("div", {
|
|
7256
7905
|
style: { ...typography.tiny, color: c.textSecondary }
|
|
7257
7906
|
}, subtitle)
|
|
7258
7907
|
),
|
|
7259
|
-
|
|
7908
|
+
import_react12.default.createElement(
|
|
7260
7909
|
"div",
|
|
7261
7910
|
{
|
|
7262
7911
|
style: {
|
|
@@ -7274,7 +7923,7 @@ function StackedBar({
|
|
|
7274
7923
|
const share = total > 0 ? segment.value / total : 0;
|
|
7275
7924
|
const segmentWidth = width * share;
|
|
7276
7925
|
const color = chartColor(segment.color, c, index);
|
|
7277
|
-
return
|
|
7926
|
+
return import_react12.default.createElement(
|
|
7278
7927
|
"div",
|
|
7279
7928
|
{
|
|
7280
7929
|
key: `${segment.label}-${index}`,
|
|
@@ -7288,7 +7937,7 @@ function StackedBar({
|
|
|
7288
7937
|
...index < positiveSegments.length - 1 ? { borderRight: `2px solid ${c.bgSubtle}` } : {}
|
|
7289
7938
|
}
|
|
7290
7939
|
},
|
|
7291
|
-
segmentWidth >= 64 &&
|
|
7940
|
+
segmentWidth >= 64 && import_react12.default.createElement("span", {
|
|
7292
7941
|
style: {
|
|
7293
7942
|
...typography.small,
|
|
7294
7943
|
color: getReadableTextColor(color, c),
|
|
@@ -7299,7 +7948,7 @@ function StackedBar({
|
|
|
7299
7948
|
);
|
|
7300
7949
|
})
|
|
7301
7950
|
),
|
|
7302
|
-
showLegend &&
|
|
7951
|
+
showLegend && import_react12.default.createElement(
|
|
7303
7952
|
"div",
|
|
7304
7953
|
{
|
|
7305
7954
|
style: {
|
|
@@ -7311,13 +7960,13 @@ function StackedBar({
|
|
|
7311
7960
|
},
|
|
7312
7961
|
...positiveSegments.map((segment, index) => {
|
|
7313
7962
|
const share = total > 0 ? segment.value / total : 0;
|
|
7314
|
-
return
|
|
7963
|
+
return import_react12.default.createElement(
|
|
7315
7964
|
"div",
|
|
7316
7965
|
{
|
|
7317
7966
|
key: `legend-${segment.label}-${index}`,
|
|
7318
7967
|
style: { display: "flex", alignItems: "center", gap: 7 }
|
|
7319
7968
|
},
|
|
7320
|
-
|
|
7969
|
+
import_react12.default.createElement("span", {
|
|
7321
7970
|
style: {
|
|
7322
7971
|
width: 12,
|
|
7323
7972
|
height: 12,
|
|
@@ -7326,7 +7975,7 @@ function StackedBar({
|
|
|
7326
7975
|
backgroundColor: chartColor(segment.color, c, index)
|
|
7327
7976
|
}
|
|
7328
7977
|
}),
|
|
7329
|
-
|
|
7978
|
+
import_react12.default.createElement("span", {
|
|
7330
7979
|
style: { ...typography.tiny, color: c.textSecondary }
|
|
7331
7980
|
}, `${segment.label} ${segment.valueLabel ?? formatChartValue(share, "percent")}`)
|
|
7332
7981
|
);
|
|
@@ -7372,18 +8021,18 @@ function BarChart({
|
|
|
7372
8021
|
subtitle,
|
|
7373
8022
|
width,
|
|
7374
8023
|
footer,
|
|
7375
|
-
children:
|
|
8024
|
+
children: import_react12.default.createElement(
|
|
7376
8025
|
"div",
|
|
7377
8026
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7378
|
-
|
|
8027
|
+
import_react12.default.createElement(
|
|
7379
8028
|
"svg",
|
|
7380
8029
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7381
|
-
showGrid &&
|
|
8030
|
+
showGrid && import_react12.default.createElement(
|
|
7382
8031
|
"g",
|
|
7383
8032
|
{},
|
|
7384
8033
|
...ticks.map((tick) => {
|
|
7385
8034
|
const y = yInPlot(tick, domain, plot);
|
|
7386
|
-
return
|
|
8035
|
+
return import_react12.default.createElement("line", {
|
|
7387
8036
|
key: `tick-${tick}`,
|
|
7388
8037
|
x1: plot.x,
|
|
7389
8038
|
y1: y,
|
|
@@ -7394,10 +8043,10 @@ function BarChart({
|
|
|
7394
8043
|
});
|
|
7395
8044
|
})
|
|
7396
8045
|
),
|
|
7397
|
-
|
|
7398
|
-
|
|
8046
|
+
import_react12.default.createElement("line", { x1: plot.x, y1: plot.y, x2: plot.x, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
8047
|
+
import_react12.default.createElement("line", { x1: plot.x, y1: baselineY, x2: plot.right, y2: baselineY, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
7399
8048
|
...barGeometries.map(
|
|
7400
|
-
({ item, index, x, y, barHeight, color }) =>
|
|
8049
|
+
({ item, index, x, y, barHeight, color }) => import_react12.default.createElement("rect", {
|
|
7401
8050
|
key: `${item.label}-${index}`,
|
|
7402
8051
|
x,
|
|
7403
8052
|
y,
|
|
@@ -7433,6 +8082,186 @@ function BarChart({
|
|
|
7433
8082
|
)
|
|
7434
8083
|
});
|
|
7435
8084
|
}
|
|
8085
|
+
function ParetoBarChart({
|
|
8086
|
+
data,
|
|
8087
|
+
c,
|
|
8088
|
+
title,
|
|
8089
|
+
subtitle,
|
|
8090
|
+
width = 520,
|
|
8091
|
+
height = 300,
|
|
8092
|
+
format = "integer",
|
|
8093
|
+
showGrid = true,
|
|
8094
|
+
showValues = true,
|
|
8095
|
+
footer
|
|
8096
|
+
}) {
|
|
8097
|
+
let total = 0;
|
|
8098
|
+
for (const item of data) {
|
|
8099
|
+
if (!Number.isFinite(item.value) || item.value < 0) {
|
|
8100
|
+
throw new RangeError("ParetoBarChart values must be finite, non-negative numbers.");
|
|
8101
|
+
}
|
|
8102
|
+
total += item.value;
|
|
8103
|
+
if (!Number.isFinite(total)) {
|
|
8104
|
+
throw new RangeError("ParetoBarChart total must be finite.");
|
|
8105
|
+
}
|
|
8106
|
+
}
|
|
8107
|
+
const sorted = data.map((item, index) => ({ item, index })).sort((left, right) => right.item.value - left.item.value || left.index - right.index);
|
|
8108
|
+
const maximum = Math.max(1, ...sorted.map(({ item }) => item.value));
|
|
8109
|
+
const margin = { top: 24, right: 48, bottom: 48, left: 48 };
|
|
8110
|
+
const plot = createPlotArea(width, height, margin);
|
|
8111
|
+
const valueDomain = {
|
|
8112
|
+
min: 0,
|
|
8113
|
+
range: maximum > Number.MAX_VALUE / 1.16 ? maximum : maximum * 1.16
|
|
8114
|
+
};
|
|
8115
|
+
const countTicks = chartTicks(0, maximum, 4);
|
|
8116
|
+
const slot = plot.innerWidth / Math.max(sorted.length, 1);
|
|
8117
|
+
const barWidth = Math.max(6, Math.min(68, slot * 0.68));
|
|
8118
|
+
let accumulated = 0;
|
|
8119
|
+
const bars = sorted.map(({ item, index }, order) => {
|
|
8120
|
+
accumulated += item.value;
|
|
8121
|
+
const cumulative = total === 0 ? 0 : order === sorted.length - 1 ? 1 : accumulated / total;
|
|
8122
|
+
const x = plot.x + order * slot + (slot - barWidth) / 2;
|
|
8123
|
+
const top = yInPlot(item.value, valueDomain, plot);
|
|
8124
|
+
return {
|
|
8125
|
+
item,
|
|
8126
|
+
sourceIndex: index,
|
|
8127
|
+
order,
|
|
8128
|
+
x,
|
|
8129
|
+
y: top,
|
|
8130
|
+
height: Math.max(0, plot.bottom - top),
|
|
8131
|
+
color: chartColor(item.color, c, order),
|
|
8132
|
+
centerX: x + barWidth / 2,
|
|
8133
|
+
cumulative,
|
|
8134
|
+
cumulativeY: plot.bottom - cumulative * plot.innerHeight
|
|
8135
|
+
};
|
|
8136
|
+
});
|
|
8137
|
+
const cumulativePath = bars.map(({ centerX, cumulativeY }, index) => `${index === 0 ? "M" : "L"} ${centerX.toFixed(1)} ${cumulativeY.toFixed(1)}`).join(" ");
|
|
8138
|
+
return ChartFrame({
|
|
8139
|
+
c,
|
|
8140
|
+
title,
|
|
8141
|
+
subtitle,
|
|
8142
|
+
width,
|
|
8143
|
+
footer,
|
|
8144
|
+
children: import_react12.default.createElement(
|
|
8145
|
+
"div",
|
|
8146
|
+
{
|
|
8147
|
+
style: { position: "relative", width, height, display: "flex" }
|
|
8148
|
+
},
|
|
8149
|
+
import_react12.default.createElement(
|
|
8150
|
+
"svg",
|
|
8151
|
+
{
|
|
8152
|
+
width,
|
|
8153
|
+
height,
|
|
8154
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
8155
|
+
role: "img",
|
|
8156
|
+
"aria-label": title ?? "Pareto bar chart"
|
|
8157
|
+
},
|
|
8158
|
+
showGrid && import_react12.default.createElement(
|
|
8159
|
+
"g",
|
|
8160
|
+
{},
|
|
8161
|
+
...countTicks.map((tick) => {
|
|
8162
|
+
const y = yInPlot(tick, valueDomain, plot);
|
|
8163
|
+
return import_react12.default.createElement("line", {
|
|
8164
|
+
key: `pareto-count-grid-${tick}`,
|
|
8165
|
+
x1: plot.x,
|
|
8166
|
+
y1: y,
|
|
8167
|
+
x2: plot.right,
|
|
8168
|
+
y2: y,
|
|
8169
|
+
stroke: c.borderSubtle,
|
|
8170
|
+
strokeWidth: 1
|
|
8171
|
+
});
|
|
8172
|
+
})
|
|
8173
|
+
),
|
|
8174
|
+
import_react12.default.createElement("line", {
|
|
8175
|
+
x1: plot.x,
|
|
8176
|
+
y1: plot.bottom,
|
|
8177
|
+
x2: plot.right,
|
|
8178
|
+
y2: plot.bottom,
|
|
8179
|
+
stroke: c.borderLight,
|
|
8180
|
+
strokeWidth: 1.2
|
|
8181
|
+
}),
|
|
8182
|
+
import_react12.default.createElement("line", {
|
|
8183
|
+
x1: plot.right,
|
|
8184
|
+
y1: plot.y,
|
|
8185
|
+
x2: plot.right,
|
|
8186
|
+
y2: plot.bottom,
|
|
8187
|
+
stroke: c.borderLight,
|
|
8188
|
+
strokeWidth: 1.2
|
|
8189
|
+
}),
|
|
8190
|
+
...bars.map(({ item, order, x, y, height: barHeight, color }) => import_react12.default.createElement("rect", {
|
|
8191
|
+
key: `pareto-bar-${item.label}-${order}`,
|
|
8192
|
+
x,
|
|
8193
|
+
y,
|
|
8194
|
+
width: barWidth,
|
|
8195
|
+
height: barHeight,
|
|
8196
|
+
rx: 4,
|
|
8197
|
+
fill: color,
|
|
8198
|
+
opacity: 0.86,
|
|
8199
|
+
"data-pareto-bar": item.label,
|
|
8200
|
+
"data-pareto-value": item.value,
|
|
8201
|
+
"data-pareto-order": order
|
|
8202
|
+
})),
|
|
8203
|
+
cumulativePath && import_react12.default.createElement("path", {
|
|
8204
|
+
d: cumulativePath,
|
|
8205
|
+
fill: "none",
|
|
8206
|
+
stroke: chartColor("critical", c),
|
|
8207
|
+
strokeWidth: 3,
|
|
8208
|
+
strokeLinecap: "round",
|
|
8209
|
+
strokeLinejoin: "round",
|
|
8210
|
+
"data-pareto-cumulative-line": true
|
|
8211
|
+
}),
|
|
8212
|
+
...bars.map(({ item, sourceIndex, centerX, cumulativeY, cumulative, order }) => import_react12.default.createElement("circle", {
|
|
8213
|
+
key: `pareto-cumulative-point-${order}`,
|
|
8214
|
+
cx: centerX,
|
|
8215
|
+
cy: cumulativeY,
|
|
8216
|
+
r: 4,
|
|
8217
|
+
fill: chartColor("critical", c),
|
|
8218
|
+
stroke: c.bgCard,
|
|
8219
|
+
strokeWidth: 2,
|
|
8220
|
+
"data-pareto-category": item.label,
|
|
8221
|
+
"data-pareto-source-index": sourceIndex,
|
|
8222
|
+
"data-pareto-cumulative-percent": cumulative * 100
|
|
8223
|
+
}))
|
|
8224
|
+
),
|
|
8225
|
+
...countTicks.map((tick) => chartLabel(
|
|
8226
|
+
`pareto-count-label-${tick}`,
|
|
8227
|
+
formatChartValue(tick, format),
|
|
8228
|
+
plot.x - 7,
|
|
8229
|
+
yInPlot(tick, valueDomain, plot),
|
|
8230
|
+
c,
|
|
8231
|
+
{ align: "right", width: 36 }
|
|
8232
|
+
)),
|
|
8233
|
+
...[0, 0.5, 1].map((share) => chartLabel(
|
|
8234
|
+
`pareto-percent-label-${share}`,
|
|
8235
|
+
`${Math.round(share * 100)}%`,
|
|
8236
|
+
plot.right + 7,
|
|
8237
|
+
plot.bottom - share * plot.innerHeight,
|
|
8238
|
+
c,
|
|
8239
|
+
{ align: "left", width: 38 }
|
|
8240
|
+
)),
|
|
8241
|
+
...bars.flatMap(({ item, order, centerX, y }) => [
|
|
8242
|
+
...showValues ? [chartLabel(
|
|
8243
|
+
`pareto-value-${order}`,
|
|
8244
|
+
item.valueLabel ?? formatChartValue(item.value, format),
|
|
8245
|
+
centerX,
|
|
8246
|
+
clamp(y - 8, plot.y + 8, plot.bottom - 12),
|
|
8247
|
+
c,
|
|
8248
|
+
{ color: c.textPrimary, fontWeight: 800, width: Math.min(slot, 64), bounds: { x: plot.x, y: plot.y, width: plot.innerWidth, height: plot.innerHeight } }
|
|
8249
|
+
)] : [],
|
|
8250
|
+
chartLabel(
|
|
8251
|
+
`pareto-category-${order}`,
|
|
8252
|
+
item.label,
|
|
8253
|
+
centerX,
|
|
8254
|
+
height - 17,
|
|
8255
|
+
c,
|
|
8256
|
+
{
|
|
8257
|
+
width: Math.max(1, Math.min(96, slot - 2)),
|
|
8258
|
+
bounds: { x: plot.x, y: plot.bottom + 1, width: plot.innerWidth, height: Math.max(1, height - plot.bottom - 2), padding: 0 }
|
|
8259
|
+
}
|
|
8260
|
+
)
|
|
8261
|
+
])
|
|
8262
|
+
)
|
|
8263
|
+
});
|
|
8264
|
+
}
|
|
7436
8265
|
function LineChart({
|
|
7437
8266
|
series,
|
|
7438
8267
|
c,
|
|
@@ -7476,18 +8305,18 @@ function LineChart({
|
|
|
7476
8305
|
width,
|
|
7477
8306
|
footer,
|
|
7478
8307
|
legend: series.map((item, index) => ({ label: item.name, color: item.color ?? chartPalette[index % chartPalette.length] })),
|
|
7479
|
-
children:
|
|
8308
|
+
children: import_react12.default.createElement(
|
|
7480
8309
|
"div",
|
|
7481
8310
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7482
|
-
|
|
8311
|
+
import_react12.default.createElement(
|
|
7483
8312
|
"svg",
|
|
7484
8313
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7485
|
-
showGrid &&
|
|
8314
|
+
showGrid && import_react12.default.createElement(
|
|
7486
8315
|
"g",
|
|
7487
8316
|
{},
|
|
7488
8317
|
...ticks.map((tick) => {
|
|
7489
8318
|
const y = yInPlot(tick, domain, plot);
|
|
7490
|
-
return
|
|
8319
|
+
return import_react12.default.createElement("line", {
|
|
7491
8320
|
key: `line-tick-${tick}`,
|
|
7492
8321
|
x1: plot.x,
|
|
7493
8322
|
y1: y,
|
|
@@ -7498,8 +8327,8 @@ function LineChart({
|
|
|
7498
8327
|
});
|
|
7499
8328
|
})
|
|
7500
8329
|
),
|
|
7501
|
-
|
|
7502
|
-
|
|
8330
|
+
import_react12.default.createElement("line", { x1: plot.x, y1: plot.y, x2: plot.x, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
8331
|
+
import_react12.default.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
7503
8332
|
...series.flatMap((item, seriesIndex) => {
|
|
7504
8333
|
if (item.points.length === 0) return [];
|
|
7505
8334
|
const color = chartColor(item.color, c, seriesIndex);
|
|
@@ -7512,9 +8341,9 @@ function LineChart({
|
|
|
7512
8341
|
}
|
|
7513
8342
|
const elements = [];
|
|
7514
8343
|
if (areaPath) {
|
|
7515
|
-
elements.push(
|
|
8344
|
+
elements.push(import_react12.default.createElement("path", { key: `${item.name}-area`, d: areaPath, fill: color, opacity: 0.12 }));
|
|
7516
8345
|
}
|
|
7517
|
-
elements.push(
|
|
8346
|
+
elements.push(import_react12.default.createElement("path", {
|
|
7518
8347
|
key: `${item.name}-line`,
|
|
7519
8348
|
d: linePath,
|
|
7520
8349
|
fill: "none",
|
|
@@ -7526,7 +8355,7 @@ function LineChart({
|
|
|
7526
8355
|
if (showPoints) {
|
|
7527
8356
|
elements.push(...item.points.map((value, index) => {
|
|
7528
8357
|
const point = pointFor(value, index);
|
|
7529
|
-
return
|
|
8358
|
+
return import_react12.default.createElement("circle", {
|
|
7530
8359
|
key: `${item.name}-point-${index}`,
|
|
7531
8360
|
cx: point.x,
|
|
7532
8361
|
cy: point.y,
|
|
@@ -7557,9 +8386,15 @@ function LineChart({
|
|
|
7557
8386
|
)
|
|
7558
8387
|
});
|
|
7559
8388
|
}
|
|
8389
|
+
for (const chart of [PieChart, DonutChart, StackedBar, BarChart, ParetoBarChart, LineChart]) {
|
|
8390
|
+
Object.defineProperty(chart, CANVAS_CHART_COMPONENT, { value: true });
|
|
8391
|
+
}
|
|
7560
8392
|
|
|
7561
8393
|
// src/primitives/plots.ts
|
|
7562
|
-
var
|
|
8394
|
+
var import_react13 = __toESM(require("react"), 1);
|
|
8395
|
+
for (const chart of [ScatterPlot, ParetoChart, QuadrantChart, IntervalPlot]) {
|
|
8396
|
+
Object.defineProperty(chart, CANVAS_CHART_COMPONENT, { value: true });
|
|
8397
|
+
}
|
|
7563
8398
|
function xTickLabelAlign(index, count) {
|
|
7564
8399
|
if (index === 0) return "left";
|
|
7565
8400
|
if (index === count - 1) return "right";
|
|
@@ -7603,18 +8438,18 @@ function ScatterPlot({
|
|
|
7603
8438
|
subtitle,
|
|
7604
8439
|
width,
|
|
7605
8440
|
footer,
|
|
7606
|
-
children:
|
|
8441
|
+
children: import_react13.default.createElement(
|
|
7607
8442
|
"div",
|
|
7608
8443
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7609
|
-
|
|
8444
|
+
import_react13.default.createElement(
|
|
7610
8445
|
"svg",
|
|
7611
8446
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7612
|
-
showGrid &&
|
|
8447
|
+
showGrid && import_react13.default.createElement(
|
|
7613
8448
|
"g",
|
|
7614
8449
|
{},
|
|
7615
8450
|
...xTicks.map((tick) => {
|
|
7616
8451
|
const x = xInPlot(tick, xDomain, plot);
|
|
7617
|
-
return
|
|
8452
|
+
return import_react13.default.createElement("line", {
|
|
7618
8453
|
key: `x-tick-${tick}`,
|
|
7619
8454
|
x1: x,
|
|
7620
8455
|
y1: plot.y,
|
|
@@ -7626,7 +8461,7 @@ function ScatterPlot({
|
|
|
7626
8461
|
}),
|
|
7627
8462
|
...yTicks.map((tick) => {
|
|
7628
8463
|
const y = yInPlot(tick, yDomain, plot);
|
|
7629
|
-
return
|
|
8464
|
+
return import_react13.default.createElement("line", {
|
|
7630
8465
|
key: `y-tick-${tick}`,
|
|
7631
8466
|
x1: plot.x,
|
|
7632
8467
|
y1: y,
|
|
@@ -7637,9 +8472,9 @@ function ScatterPlot({
|
|
|
7637
8472
|
});
|
|
7638
8473
|
})
|
|
7639
8474
|
),
|
|
7640
|
-
|
|
8475
|
+
import_react13.default.createElement("rect", { x: plot.x, y: plot.y, width: plot.innerWidth, height: plot.innerHeight, fill: "transparent", stroke: c.borderLight, strokeWidth: 1.2, rx: 6 }),
|
|
7641
8476
|
...pointGeometries.map(
|
|
7642
|
-
({ item, index, point, color }) =>
|
|
8477
|
+
({ item, index, point, color }) => import_react13.default.createElement("circle", {
|
|
7643
8478
|
key: `${item.label ?? "point"}-${index}`,
|
|
7644
8479
|
cx: point.x,
|
|
7645
8480
|
cy: point.y,
|
|
@@ -7790,18 +8625,18 @@ function ParetoChart({
|
|
|
7790
8625
|
{ label: "Pareto frontier", color: frontier },
|
|
7791
8626
|
{ label: "dominated", color: "neutral" }
|
|
7792
8627
|
],
|
|
7793
|
-
children:
|
|
8628
|
+
children: import_react13.default.createElement(
|
|
7794
8629
|
"div",
|
|
7795
8630
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7796
|
-
|
|
8631
|
+
import_react13.default.createElement(
|
|
7797
8632
|
"svg",
|
|
7798
8633
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7799
|
-
showGrid &&
|
|
8634
|
+
showGrid && import_react13.default.createElement(
|
|
7800
8635
|
"g",
|
|
7801
8636
|
{},
|
|
7802
8637
|
...xTicks.map((tick) => {
|
|
7803
8638
|
const x = pointFor(tick, yDomain.min).x;
|
|
7804
|
-
return
|
|
8639
|
+
return import_react13.default.createElement("line", {
|
|
7805
8640
|
key: `pareto-x-grid-${tick}`,
|
|
7806
8641
|
x1: x,
|
|
7807
8642
|
y1: plot.y,
|
|
@@ -7813,7 +8648,7 @@ function ParetoChart({
|
|
|
7813
8648
|
}),
|
|
7814
8649
|
...yTicks.map((tick) => {
|
|
7815
8650
|
const y = yInPlot(tick, yDomain, plot);
|
|
7816
|
-
return
|
|
8651
|
+
return import_react13.default.createElement("line", {
|
|
7817
8652
|
key: `pareto-y-grid-${tick}`,
|
|
7818
8653
|
x1: plot.x,
|
|
7819
8654
|
y1: y,
|
|
@@ -7824,7 +8659,7 @@ function ParetoChart({
|
|
|
7824
8659
|
});
|
|
7825
8660
|
})
|
|
7826
8661
|
),
|
|
7827
|
-
|
|
8662
|
+
import_react13.default.createElement("rect", {
|
|
7828
8663
|
x: plot.x,
|
|
7829
8664
|
y: plot.y,
|
|
7830
8665
|
width: plot.innerWidth,
|
|
@@ -7834,17 +8669,17 @@ function ParetoChart({
|
|
|
7834
8669
|
strokeWidth: 1.2,
|
|
7835
8670
|
rx: 6
|
|
7836
8671
|
}),
|
|
7837
|
-
showGoal &&
|
|
8672
|
+
showGoal && import_react13.default.createElement(
|
|
7838
8673
|
"g",
|
|
7839
8674
|
{ "data-pareto-goal": true, stroke: frontier, fill: "none", strokeWidth: 2, strokeLinecap: "round" },
|
|
7840
|
-
|
|
7841
|
-
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
|
|
7845
|
-
|
|
8675
|
+
import_react13.default.createElement("line", { x1: goalXStart, y1: goalY, x2: goalXEnd, y2: goalY }),
|
|
8676
|
+
import_react13.default.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY - arrowSize }),
|
|
8677
|
+
import_react13.default.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY + arrowSize }),
|
|
8678
|
+
import_react13.default.createElement("line", { x1: goalXStart, y1: goalYStart, x2: goalXStart, y2: goalYEnd }),
|
|
8679
|
+
import_react13.default.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart - arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) }),
|
|
8680
|
+
import_react13.default.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart + arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) })
|
|
7846
8681
|
),
|
|
7847
|
-
frontierPath &&
|
|
8682
|
+
frontierPath && import_react13.default.createElement("path", {
|
|
7848
8683
|
"data-pareto-frontier": true,
|
|
7849
8684
|
d: frontierPath,
|
|
7850
8685
|
fill: "none",
|
|
@@ -7853,7 +8688,7 @@ function ParetoChart({
|
|
|
7853
8688
|
strokeLinecap: "round",
|
|
7854
8689
|
strokeLinejoin: "round"
|
|
7855
8690
|
}),
|
|
7856
|
-
...pointGeometries.filter((geometry) => !geometry.frontier).concat(pointGeometries.filter((geometry) => geometry.frontier)).map(({ point, index, x, y, color, frontier: isFrontier }) =>
|
|
8691
|
+
...pointGeometries.filter((geometry) => !geometry.frontier).concat(pointGeometries.filter((geometry) => geometry.frontier)).map(({ point, index, x, y, color, frontier: isFrontier }) => import_react13.default.createElement("circle", {
|
|
7857
8692
|
key: `pareto-point-${point.label ?? "point"}-${index}`,
|
|
7858
8693
|
"data-pareto-status": isFrontier ? "frontier" : "dominated",
|
|
7859
8694
|
cx: x,
|
|
@@ -7965,18 +8800,18 @@ function QuadrantChart({
|
|
|
7965
8800
|
subtitle,
|
|
7966
8801
|
width,
|
|
7967
8802
|
footer,
|
|
7968
|
-
children:
|
|
8803
|
+
children: import_react13.default.createElement(
|
|
7969
8804
|
"div",
|
|
7970
8805
|
{
|
|
7971
8806
|
style: { position: "relative", width, height, display: "flex" }
|
|
7972
8807
|
},
|
|
7973
|
-
|
|
8808
|
+
import_react13.default.createElement(
|
|
7974
8809
|
"svg",
|
|
7975
8810
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7976
8811
|
...regionEntries.map(({ key, region, x, y, width: regionWidth, height: regionHeight }, index) => {
|
|
7977
8812
|
const color = chartColor(region.color, c, index);
|
|
7978
8813
|
const emphasized = region.emphasis === true;
|
|
7979
|
-
return
|
|
8814
|
+
return import_react13.default.createElement("rect", {
|
|
7980
8815
|
key: `quadrant-${key}`,
|
|
7981
8816
|
x,
|
|
7982
8817
|
y,
|
|
@@ -7988,12 +8823,12 @@ function QuadrantChart({
|
|
|
7988
8823
|
strokeWidth: emphasized ? 2 : 0
|
|
7989
8824
|
});
|
|
7990
8825
|
}),
|
|
7991
|
-
showGrid &&
|
|
8826
|
+
showGrid && import_react13.default.createElement(
|
|
7992
8827
|
"g",
|
|
7993
8828
|
{},
|
|
7994
8829
|
...xTicks.map((tick) => {
|
|
7995
8830
|
const x = xInPlot(tick, xDomain, plot);
|
|
7996
|
-
return
|
|
8831
|
+
return import_react13.default.createElement("line", {
|
|
7997
8832
|
key: `quadrant-x-grid-${tick}`,
|
|
7998
8833
|
x1: x,
|
|
7999
8834
|
y1: plot.y,
|
|
@@ -8005,7 +8840,7 @@ function QuadrantChart({
|
|
|
8005
8840
|
}),
|
|
8006
8841
|
...yTicks.map((tick) => {
|
|
8007
8842
|
const y = yInPlot(tick, yDomain, plot);
|
|
8008
|
-
return
|
|
8843
|
+
return import_react13.default.createElement("line", {
|
|
8009
8844
|
key: `quadrant-y-grid-${tick}`,
|
|
8010
8845
|
x1: plot.x,
|
|
8011
8846
|
y1: y,
|
|
@@ -8016,7 +8851,7 @@ function QuadrantChart({
|
|
|
8016
8851
|
});
|
|
8017
8852
|
})
|
|
8018
8853
|
),
|
|
8019
|
-
|
|
8854
|
+
import_react13.default.createElement("rect", {
|
|
8020
8855
|
x: plot.x,
|
|
8021
8856
|
y: plot.y,
|
|
8022
8857
|
width: plot.innerWidth,
|
|
@@ -8026,7 +8861,7 @@ function QuadrantChart({
|
|
|
8026
8861
|
strokeWidth: 1.2,
|
|
8027
8862
|
rx: 8
|
|
8028
8863
|
}),
|
|
8029
|
-
|
|
8864
|
+
import_react13.default.createElement("line", {
|
|
8030
8865
|
x1: midX,
|
|
8031
8866
|
y1: plot.y,
|
|
8032
8867
|
x2: midX,
|
|
@@ -8034,7 +8869,7 @@ function QuadrantChart({
|
|
|
8034
8869
|
stroke: c.borderLight,
|
|
8035
8870
|
strokeWidth: 1.4
|
|
8036
8871
|
}),
|
|
8037
|
-
|
|
8872
|
+
import_react13.default.createElement("line", {
|
|
8038
8873
|
x1: plot.x,
|
|
8039
8874
|
y1: midY,
|
|
8040
8875
|
x2: plot.right,
|
|
@@ -8044,7 +8879,7 @@ function QuadrantChart({
|
|
|
8044
8879
|
}),
|
|
8045
8880
|
...(showTicks ? xTicks : []).map((tick) => {
|
|
8046
8881
|
const x = xInPlot(tick, xDomain, plot);
|
|
8047
|
-
return
|
|
8882
|
+
return import_react13.default.createElement("line", {
|
|
8048
8883
|
key: `quadrant-x-tick-${tick}`,
|
|
8049
8884
|
x1: x,
|
|
8050
8885
|
y1: plot.bottom,
|
|
@@ -8056,7 +8891,7 @@ function QuadrantChart({
|
|
|
8056
8891
|
}),
|
|
8057
8892
|
...(showTicks ? yTicks : []).map((tick) => {
|
|
8058
8893
|
const y = yInPlot(tick, yDomain, plot);
|
|
8059
|
-
return
|
|
8894
|
+
return import_react13.default.createElement("line", {
|
|
8060
8895
|
key: `quadrant-y-tick-${tick}`,
|
|
8061
8896
|
x1: plot.x - 5,
|
|
8062
8897
|
y1: y,
|
|
@@ -8066,7 +8901,7 @@ function QuadrantChart({
|
|
|
8066
8901
|
strokeWidth: 1.2
|
|
8067
8902
|
});
|
|
8068
8903
|
}),
|
|
8069
|
-
...pointGeometries.map(({ point, index, x, y, color }) =>
|
|
8904
|
+
...pointGeometries.map(({ point, index, x, y, color }) => import_react13.default.createElement("circle", {
|
|
8070
8905
|
key: `quadrant-point-${point.label ?? index}`,
|
|
8071
8906
|
cx: x,
|
|
8072
8907
|
cy: y,
|
|
@@ -8168,15 +9003,15 @@ function IntervalPlot({
|
|
|
8168
9003
|
subtitle,
|
|
8169
9004
|
width,
|
|
8170
9005
|
footer,
|
|
8171
|
-
children:
|
|
9006
|
+
children: import_react13.default.createElement(
|
|
8172
9007
|
"div",
|
|
8173
9008
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
8174
|
-
|
|
9009
|
+
import_react13.default.createElement(
|
|
8175
9010
|
"svg",
|
|
8176
9011
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
8177
9012
|
...ticks.map((tick) => {
|
|
8178
9013
|
const x = scaleX(tick);
|
|
8179
|
-
return
|
|
9014
|
+
return import_react13.default.createElement("line", {
|
|
8180
9015
|
key: `interval-tick-${tick}`,
|
|
8181
9016
|
x1: x,
|
|
8182
9017
|
y1: plot.y,
|
|
@@ -8186,10 +9021,10 @@ function IntervalPlot({
|
|
|
8186
9021
|
strokeWidth: 1
|
|
8187
9022
|
});
|
|
8188
9023
|
}),
|
|
8189
|
-
|
|
9024
|
+
import_react13.default.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
8190
9025
|
...rows.flatMap(({ item, index, y, color, lowX, midX, highX }) => [
|
|
8191
|
-
|
|
8192
|
-
|
|
9026
|
+
import_react13.default.createElement("line", { key: `${item.label}-range-${index}`, x1: lowX, y1: y, x2: highX, y2: y, stroke: color, strokeWidth: 9, strokeLinecap: "round", opacity: 0.9 }),
|
|
9027
|
+
import_react13.default.createElement("circle", { key: `${item.label}-mid-${index}`, cx: midX, cy: y, r: 10, fill: c.bgCard, stroke: color, strokeWidth: 4 })
|
|
8193
9028
|
])
|
|
8194
9029
|
),
|
|
8195
9030
|
...ticks.map((tick, index) => {
|
|
@@ -8226,7 +9061,7 @@ function IntervalPlot({
|
|
|
8226
9061
|
}
|
|
8227
9062
|
function Badge({ label, c, color = "primary" }) {
|
|
8228
9063
|
const solidColor = getReadableColor(color, c);
|
|
8229
|
-
return
|
|
9064
|
+
return import_react13.default.createElement("div", {
|
|
8230
9065
|
style: {
|
|
8231
9066
|
display: "flex",
|
|
8232
9067
|
alignItems: "center",
|
|
@@ -8247,7 +9082,7 @@ function DotPoint({ x, y, label, color, c, size = 12, labelOffset }) {
|
|
|
8247
9082
|
const offY = labelOffset?.y ?? -22;
|
|
8248
9083
|
return [
|
|
8249
9084
|
// Dot
|
|
8250
|
-
|
|
9085
|
+
import_react13.default.createElement("div", {
|
|
8251
9086
|
key: `dot-${label}`,
|
|
8252
9087
|
style: {
|
|
8253
9088
|
position: "absolute",
|
|
@@ -8262,7 +9097,7 @@ function DotPoint({ x, y, label, color, c, size = 12, labelOffset }) {
|
|
|
8262
9097
|
}
|
|
8263
9098
|
}),
|
|
8264
9099
|
// Label
|
|
8265
|
-
|
|
9100
|
+
import_react13.default.createElement("div", {
|
|
8266
9101
|
key: `label-${label}`,
|
|
8267
9102
|
style: {
|
|
8268
9103
|
position: "absolute",
|
|
@@ -8288,7 +9123,7 @@ function DashedLine({ x1, y1, x2, y2, color, dotSpacing = 8, dotSize = 2 }) {
|
|
|
8288
9123
|
if (i % 2 === 1) continue;
|
|
8289
9124
|
const t = i / numDots;
|
|
8290
9125
|
dots.push(
|
|
8291
|
-
|
|
9126
|
+
import_react13.default.createElement("div", {
|
|
8292
9127
|
key: `dash-${i}`,
|
|
8293
9128
|
style: {
|
|
8294
9129
|
position: "absolute",
|
|
@@ -8305,7 +9140,7 @@ function DashedLine({ x1, y1, x2, y2, color, dotSpacing = 8, dotSize = 2 }) {
|
|
|
8305
9140
|
return dots;
|
|
8306
9141
|
}
|
|
8307
9142
|
function Legend({ items, c, title }) {
|
|
8308
|
-
return
|
|
9143
|
+
return import_react13.default.createElement(
|
|
8309
9144
|
"div",
|
|
8310
9145
|
{
|
|
8311
9146
|
style: {
|
|
@@ -8318,7 +9153,7 @@ function Legend({ items, c, title }) {
|
|
|
8318
9153
|
padding: "14px 16px"
|
|
8319
9154
|
}
|
|
8320
9155
|
},
|
|
8321
|
-
title &&
|
|
9156
|
+
title && import_react13.default.createElement("div", {
|
|
8322
9157
|
style: {
|
|
8323
9158
|
fontSize: 11,
|
|
8324
9159
|
fontWeight: 700,
|
|
@@ -8329,13 +9164,13 @@ function Legend({ items, c, title }) {
|
|
|
8329
9164
|
}
|
|
8330
9165
|
}, title),
|
|
8331
9166
|
...items.map(
|
|
8332
|
-
(item, i) =>
|
|
9167
|
+
(item, i) => import_react13.default.createElement(
|
|
8333
9168
|
"div",
|
|
8334
9169
|
{
|
|
8335
9170
|
key: `legend-${i}`,
|
|
8336
9171
|
style: { display: "flex", alignItems: "center", gap: 8 }
|
|
8337
9172
|
},
|
|
8338
|
-
|
|
9173
|
+
import_react13.default.createElement("div", {
|
|
8339
9174
|
style: {
|
|
8340
9175
|
width: 16,
|
|
8341
9176
|
height: item.style === "dashed" ? 0 : 2,
|
|
@@ -8345,7 +9180,7 @@ function Legend({ items, c, title }) {
|
|
|
8345
9180
|
} : {}
|
|
8346
9181
|
}
|
|
8347
9182
|
}),
|
|
8348
|
-
|
|
9183
|
+
import_react13.default.createElement("div", {
|
|
8349
9184
|
style: {
|
|
8350
9185
|
fontSize: 11,
|
|
8351
9186
|
color: c.textMuted,
|
|
@@ -8357,6 +9192,45 @@ function Legend({ items, c, title }) {
|
|
|
8357
9192
|
);
|
|
8358
9193
|
}
|
|
8359
9194
|
|
|
9195
|
+
// src/primitives/board.ts
|
|
9196
|
+
var import_react14 = __toESM(require("react"), 1);
|
|
9197
|
+
var CANVAS_ITEM_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.canvas-item");
|
|
9198
|
+
function dimension(value, name) {
|
|
9199
|
+
if (value !== void 0 && (!Number.isFinite(value) || value <= 0 || value > 8192)) {
|
|
9200
|
+
throw new Error(`${name} must be a finite number greater than 0 and at most 8192.`);
|
|
9201
|
+
}
|
|
9202
|
+
return value;
|
|
9203
|
+
}
|
|
9204
|
+
function Board({ children, c, width = 960, height = 540, background }) {
|
|
9205
|
+
return import_react14.default.createElement("div", { style: {
|
|
9206
|
+
display: "flex",
|
|
9207
|
+
position: "relative",
|
|
9208
|
+
width: dimension(width, "Board width"),
|
|
9209
|
+
height: dimension(height, "Board height"),
|
|
9210
|
+
overflow: "hidden",
|
|
9211
|
+
backgroundColor: background ?? "transparent",
|
|
9212
|
+
color: c.textPrimary
|
|
9213
|
+
} }, children);
|
|
9214
|
+
}
|
|
9215
|
+
function CanvasItem({ children, x, y, width, height }) {
|
|
9216
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) throw new Error("CanvasItem x and y must be finite numbers.");
|
|
9217
|
+
const sizedChildren = import_react14.default.Children.map(children, (child) => {
|
|
9218
|
+
if (!import_react14.default.isValidElement(child)) return child;
|
|
9219
|
+
const sized = import_react14.default.cloneElement(child, { ...width !== void 0 ? { width } : {}, ...height !== void 0 ? { height } : {} });
|
|
9220
|
+
return width !== void 0 && height !== void 0 && isCanvasChart(child.type) ? import_react14.default.createElement(CanvasChartFit, { width, height, __vizmaticTextScope: child.props.__vizmaticTextScope }, sized) : sized;
|
|
9221
|
+
});
|
|
9222
|
+
return import_react14.default.createElement("div", { style: {
|
|
9223
|
+
display: "flex",
|
|
9224
|
+
position: "absolute",
|
|
9225
|
+
left: x,
|
|
9226
|
+
top: y,
|
|
9227
|
+
width: dimension(width, "CanvasItem width"),
|
|
9228
|
+
height: dimension(height, "CanvasItem height"),
|
|
9229
|
+
alignItems: "stretch"
|
|
9230
|
+
} }, sizedChildren);
|
|
9231
|
+
}
|
|
9232
|
+
Object.defineProperty(CanvasItem, CANVAS_ITEM_COMPONENT, { value: true });
|
|
9233
|
+
|
|
8360
9234
|
// src/render.ts
|
|
8361
9235
|
var import_resvg_js = require("@resvg/resvg-js");
|
|
8362
9236
|
var import_os = require("os");
|
|
@@ -8367,12 +9241,12 @@ var import_url = require("url");
|
|
|
8367
9241
|
var import_zlib = require("zlib");
|
|
8368
9242
|
|
|
8369
9243
|
// src/brand.ts
|
|
8370
|
-
var
|
|
9244
|
+
var import_react15 = __toESM(require("react"), 1);
|
|
8371
9245
|
var DEFAULT_WATERMARK_TEXT = "Vizmatic";
|
|
8372
9246
|
var WATERMARK_COLOR_DARK = "#a78bfa";
|
|
8373
9247
|
var WATERMARK_COLOR_LIGHT = "#7c3aed";
|
|
8374
9248
|
function VizmaticIcon({ size = 14, color }) {
|
|
8375
|
-
return
|
|
9249
|
+
return import_react15.default.createElement(
|
|
8376
9250
|
"svg",
|
|
8377
9251
|
{
|
|
8378
9252
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -8381,19 +9255,19 @@ function VizmaticIcon({ size = 14, color }) {
|
|
|
8381
9255
|
viewBox: "0 0 28 28",
|
|
8382
9256
|
fill: "none"
|
|
8383
9257
|
},
|
|
8384
|
-
|
|
8385
|
-
|
|
8386
|
-
|
|
8387
|
-
|
|
8388
|
-
|
|
8389
|
-
|
|
9258
|
+
import_react15.default.createElement("rect", { x: 2.5, y: 2.5, width: 23, height: 23, rx: 6.5, stroke: color, strokeWidth: 2, opacity: 0.54 }),
|
|
9259
|
+
import_react15.default.createElement("rect", { x: 7, y: 7, width: 5.5, height: 5.5, rx: 1.8, fill: color, opacity: 0.35 }),
|
|
9260
|
+
import_react15.default.createElement("rect", { x: 15.5, y: 7, width: 5.5, height: 5.5, rx: 1.8, fill: color }),
|
|
9261
|
+
import_react15.default.createElement("rect", { x: 7, y: 15.5, width: 5.5, height: 5.5, rx: 1.8, fill: color, opacity: 0.82 }),
|
|
9262
|
+
import_react15.default.createElement("rect", { x: 15.5, y: 15.5, width: 5.5, height: 5.5, rx: 1.8, stroke: color, strokeWidth: 1.5, opacity: 0.72 }),
|
|
9263
|
+
import_react15.default.createElement("path", { d: "M9.75 9.75h8.5M9.75 18.25h8.5M9.75 9.75v8.5M18.25 9.75v8.5", stroke: color, strokeWidth: 1.6, strokeLinecap: "round", opacity: 0.88 })
|
|
8390
9264
|
);
|
|
8391
9265
|
}
|
|
8392
9266
|
function normalizeWatermark(watermark) {
|
|
8393
9267
|
if (watermark == null || watermark === false) return void 0;
|
|
8394
9268
|
if (watermark === true) return {};
|
|
8395
9269
|
if (typeof watermark === "string") return { text: watermark };
|
|
8396
|
-
if (
|
|
9270
|
+
if (import_react15.default.isValidElement(watermark)) {
|
|
8397
9271
|
if (watermark.type !== Watermark) return { element: watermark };
|
|
8398
9272
|
const { children, ...props } = watermark.props;
|
|
8399
9273
|
return {
|
|
@@ -8422,7 +9296,7 @@ function positionStyle(position) {
|
|
|
8422
9296
|
function imageNode(image) {
|
|
8423
9297
|
if (!image) return void 0;
|
|
8424
9298
|
const imageOptions = typeof image === "string" ? { src: image } : image;
|
|
8425
|
-
return
|
|
9299
|
+
return import_react15.default.createElement("img", {
|
|
8426
9300
|
src: imageOptions.src,
|
|
8427
9301
|
alt: imageOptions.alt ?? "",
|
|
8428
9302
|
width: imageOptions.width ?? 14,
|
|
@@ -8437,9 +9311,9 @@ function imageNode(image) {
|
|
|
8437
9311
|
}
|
|
8438
9312
|
function iconNode(icon, color) {
|
|
8439
9313
|
if (icon === false) return void 0;
|
|
8440
|
-
if (icon == null) return
|
|
9314
|
+
if (icon == null) return import_react15.default.createElement(VizmaticIcon, { size: 13, color });
|
|
8441
9315
|
if (typeof icon !== "string") return icon;
|
|
8442
|
-
return
|
|
9316
|
+
return import_react15.default.createElement("div", {
|
|
8443
9317
|
style: {
|
|
8444
9318
|
minWidth: 13,
|
|
8445
9319
|
height: 13,
|
|
@@ -8464,7 +9338,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
|
|
|
8464
9338
|
const text = options?.text ?? DEFAULT_WATERMARK_TEXT;
|
|
8465
9339
|
const content = options?.element ?? [
|
|
8466
9340
|
icon,
|
|
8467
|
-
text !== false && text &&
|
|
9341
|
+
text !== false && text && import_react15.default.createElement("div", {
|
|
8468
9342
|
key: "text",
|
|
8469
9343
|
style: {
|
|
8470
9344
|
fontSize: 11,
|
|
@@ -8475,7 +9349,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
|
|
|
8475
9349
|
}
|
|
8476
9350
|
}, text)
|
|
8477
9351
|
];
|
|
8478
|
-
return
|
|
9352
|
+
return import_react15.default.createElement(
|
|
8479
9353
|
"div",
|
|
8480
9354
|
{
|
|
8481
9355
|
style: {
|
|
@@ -8486,7 +9360,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
|
|
|
8486
9360
|
}
|
|
8487
9361
|
},
|
|
8488
9362
|
element,
|
|
8489
|
-
options &&
|
|
9363
|
+
options && import_react15.default.createElement(
|
|
8490
9364
|
"div",
|
|
8491
9365
|
{
|
|
8492
9366
|
style: {
|
|
@@ -8637,7 +9511,8 @@ function resolveSatori(api) {
|
|
|
8637
9511
|
}
|
|
8638
9512
|
throw new Error("satori export could not be resolved");
|
|
8639
9513
|
}
|
|
8640
|
-
var
|
|
9514
|
+
var renderSatori = resolveSatori(satoriModule);
|
|
9515
|
+
var satori = (element, options) => renderWithCanvasChartFit(renderSatori, element, options);
|
|
8641
9516
|
|
|
8642
9517
|
// src/render.ts
|
|
8643
9518
|
var FONT_CACHE_DIR = process.env.VIZMATIC_FONT_DIR ?? (0, import_path.join)(process.env.XDG_CACHE_HOME ?? (0, import_path.join)((0, import_os.homedir)(), ".cache"), "vizmatic", "fonts");
|
|
@@ -9976,30 +10851,30 @@ function readEndpoint(line, from) {
|
|
|
9976
10851
|
next: content.next
|
|
9977
10852
|
};
|
|
9978
10853
|
}
|
|
9979
|
-
function addNode(state,
|
|
9980
|
-
if (state.groupIds.has(
|
|
10854
|
+
function addNode(state, endpoint2, groupId, line, sourceLines, diagnostics, explicitlyDeclared) {
|
|
10855
|
+
if (state.groupIds.has(endpoint2.id)) {
|
|
9981
10856
|
addImportDiagnostic(
|
|
9982
10857
|
diagnostics,
|
|
9983
10858
|
sourceLines,
|
|
9984
10859
|
line,
|
|
9985
10860
|
"import.unsupported_semantics",
|
|
9986
10861
|
"error",
|
|
9987
|
-
`Mermaid id "${
|
|
10862
|
+
`Mermaid id "${endpoint2.id}" is already used by a subgraph and cannot also be a node.`
|
|
9988
10863
|
);
|
|
9989
10864
|
return false;
|
|
9990
10865
|
}
|
|
9991
|
-
if (labelHasUnsupportedMarkup(
|
|
10866
|
+
if (labelHasUnsupportedMarkup(endpoint2.label)) {
|
|
9992
10867
|
addImportDiagnostic(
|
|
9993
10868
|
diagnostics,
|
|
9994
10869
|
sourceLines,
|
|
9995
10870
|
line,
|
|
9996
10871
|
"import.unsupported_semantics",
|
|
9997
10872
|
"error",
|
|
9998
|
-
`Mermaid label for node "${
|
|
10873
|
+
`Mermaid label for node "${endpoint2.id}" uses HTML or Markdown formatting that GraphDiagram cannot preserve.`
|
|
9999
10874
|
);
|
|
10000
10875
|
return false;
|
|
10001
10876
|
}
|
|
10002
|
-
const existingIndex = state.nodeIndexes.get(
|
|
10877
|
+
const existingIndex = state.nodeIndexes.get(endpoint2.id);
|
|
10003
10878
|
if (existingIndex !== void 0) {
|
|
10004
10879
|
const existing = state.nodes[existingIndex];
|
|
10005
10880
|
if (!existing) return false;
|
|
@@ -10010,7 +10885,7 @@ function addNode(state, endpoint, groupId, line, sourceLines, diagnostics, expli
|
|
|
10010
10885
|
line,
|
|
10011
10886
|
"import.unsupported_semantics",
|
|
10012
10887
|
"error",
|
|
10013
|
-
`Mermaid node "${
|
|
10888
|
+
`Mermaid node "${endpoint2.id}" is assigned to more than one subgraph; GraphDiagram nodes support one group.`
|
|
10014
10889
|
);
|
|
10015
10890
|
return false;
|
|
10016
10891
|
}
|
|
@@ -10021,28 +10896,28 @@ function addNode(state, endpoint, groupId, line, sourceLines, diagnostics, expli
|
|
|
10021
10896
|
line,
|
|
10022
10897
|
"import.unsupported_semantics",
|
|
10023
10898
|
"error",
|
|
10024
|
-
`Mermaid node "${
|
|
10899
|
+
`Mermaid node "${endpoint2.id}" is referenced both inside and outside a subgraph; its group membership is ambiguous.`
|
|
10025
10900
|
);
|
|
10026
10901
|
return false;
|
|
10027
10902
|
}
|
|
10028
|
-
if (explicitlyDeclared) existing.label =
|
|
10903
|
+
if (explicitlyDeclared) existing.label = endpoint2.label;
|
|
10029
10904
|
} else {
|
|
10030
|
-
state.nodeIndexes.set(
|
|
10905
|
+
state.nodeIndexes.set(endpoint2.id, state.nodes.length);
|
|
10031
10906
|
state.nodes.push({
|
|
10032
|
-
id:
|
|
10033
|
-
label:
|
|
10907
|
+
id: endpoint2.id,
|
|
10908
|
+
label: endpoint2.label,
|
|
10034
10909
|
...groupId ? { group: groupId } : {}
|
|
10035
10910
|
});
|
|
10036
10911
|
}
|
|
10037
|
-
if (
|
|
10038
|
-
state.warnedShapes.add(
|
|
10912
|
+
if (endpoint2.shape === "lossy" && !state.warnedShapes.has(endpoint2.id)) {
|
|
10913
|
+
state.warnedShapes.add(endpoint2.id);
|
|
10039
10914
|
addImportDiagnostic(
|
|
10040
10915
|
diagnostics,
|
|
10041
10916
|
sourceLines,
|
|
10042
10917
|
line,
|
|
10043
10918
|
"import.lossy_semantics",
|
|
10044
10919
|
"warning",
|
|
10045
|
-
`Mermaid node "${
|
|
10920
|
+
`Mermaid node "${endpoint2.id}" uses a non-rectangular shape; it will render as a generic GraphDiagram node.`
|
|
10046
10921
|
);
|
|
10047
10922
|
}
|
|
10048
10923
|
return true;
|
|
@@ -10441,7 +11316,7 @@ var import_path3 = require("path");
|
|
|
10441
11316
|
|
|
10442
11317
|
// src/diagnostics.ts
|
|
10443
11318
|
var import_parse_css_color3 = __toESM(require("parse-css-color"), 1);
|
|
10444
|
-
var
|
|
11319
|
+
var import_react16 = require("react");
|
|
10445
11320
|
var CHECK_DIAGNOSTIC_CODES = [
|
|
10446
11321
|
"accessibility.low_contrast",
|
|
10447
11322
|
"api.unsupported_prop",
|
|
@@ -10450,6 +11325,7 @@ var CHECK_DIAGNOSTIC_CODES = [
|
|
|
10450
11325
|
"frame.unknown_preset",
|
|
10451
11326
|
"layout.auto_size",
|
|
10452
11327
|
"layout.connector_congestion",
|
|
11328
|
+
"layout.connector_unroutable",
|
|
10453
11329
|
"layout.overflow",
|
|
10454
11330
|
"layout.text_overlap",
|
|
10455
11331
|
"layout.whitespace_imbalance",
|
|
@@ -10545,14 +11421,14 @@ function styleRecord(value) {
|
|
|
10545
11421
|
return value;
|
|
10546
11422
|
}
|
|
10547
11423
|
function hasDirectText(children) {
|
|
10548
|
-
return
|
|
11424
|
+
return import_react16.Children.toArray(children).some((child) => typeof child === "string" || typeof child === "number");
|
|
10549
11425
|
}
|
|
10550
11426
|
function elementId(props) {
|
|
10551
11427
|
const value = props.id ?? props["data-vizmatic-id"];
|
|
10552
11428
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
10553
11429
|
}
|
|
10554
11430
|
function resolveFunctionComponent(node, trustedComponents) {
|
|
10555
|
-
if (!(0,
|
|
11431
|
+
if (!(0, import_react16.isValidElement)(node) || typeof node.type !== "function" || trustedComponents.has(node.type)) return void 0;
|
|
10556
11432
|
const component = node.type;
|
|
10557
11433
|
if (component.__vizmaticPrimitive) return void 0;
|
|
10558
11434
|
if (component.prototype?.isReactComponent) return void 0;
|
|
@@ -10567,7 +11443,7 @@ function analyzeContrast(element, theme, trustedComponents = /* @__PURE__ */ new
|
|
|
10567
11443
|
const seen = /* @__PURE__ */ new Set();
|
|
10568
11444
|
let visited = 0;
|
|
10569
11445
|
function visit(node, inherited, path) {
|
|
10570
|
-
if (visited++ >= MAX_CONTRAST_NODES || !(0,
|
|
11446
|
+
if (visited++ >= MAX_CONTRAST_NODES || !(0, import_react16.isValidElement)(node)) return;
|
|
10571
11447
|
const resolved = resolveFunctionComponent(node, trustedComponents);
|
|
10572
11448
|
if (resolved !== void 0) {
|
|
10573
11449
|
visit(resolved, inherited, path);
|
|
@@ -10608,7 +11484,7 @@ function analyzeContrast(element, theme, trustedComponents = /* @__PURE__ */ new
|
|
|
10608
11484
|
}
|
|
10609
11485
|
}
|
|
10610
11486
|
}
|
|
10611
|
-
|
|
11487
|
+
import_react16.Children.forEach(props.children, (child, index) => visit(child, context, `${path}.${index}`));
|
|
10612
11488
|
}
|
|
10613
11489
|
visit(element, { background: colorFromCss(rootBackground2) }, "root");
|
|
10614
11490
|
return diagnostics;
|
|
@@ -10744,6 +11620,18 @@ function analyzeRenderedLayout(nodes, theme) {
|
|
|
10744
11620
|
const value = node.props[attribute2];
|
|
10745
11621
|
return typeof value === "number" ? value : Number(value) || 0;
|
|
10746
11622
|
}));
|
|
11623
|
+
for (const source of nodes.filter((node) => Number(node.props["data-vizmatic-unrouted-connectors"]) > 0)) {
|
|
11624
|
+
const messages = JSON.parse(String(source.props["data-vizmatic-routing-failures"]));
|
|
11625
|
+
for (const message of messages.slice(0, MAX_DIAGNOSTICS_PER_RULE)) diagnostics.push({
|
|
11626
|
+
code: "layout.connector_unroutable",
|
|
11627
|
+
severity: "error",
|
|
11628
|
+
theme,
|
|
11629
|
+
message,
|
|
11630
|
+
suggestion: "Increase canvas size or spacing, reduce routingClearance, or choose a different endpoint side or port.",
|
|
11631
|
+
elementId: elementId(source.props),
|
|
11632
|
+
location: { x: source.left, y: source.top, width: source.width, height: source.height }
|
|
11633
|
+
});
|
|
11634
|
+
}
|
|
10747
11635
|
const connectorCrossings2 = maxDataNumber("data-vizmatic-connector-crossings");
|
|
10748
11636
|
if (connectorCrossings2 > 0) {
|
|
10749
11637
|
const source = nodes.find((node) => Number(node.props["data-vizmatic-connector-crossings"]) > 0);
|
|
@@ -11197,10 +12085,13 @@ async function checkFrame(input, options = {}) {
|
|
|
11197
12085
|
Badge,
|
|
11198
12086
|
BadgePill,
|
|
11199
12087
|
BarChart,
|
|
12088
|
+
Board,
|
|
11200
12089
|
Box,
|
|
12090
|
+
CANVAS_ITEM_COMPONENT,
|
|
11201
12091
|
CHECK_DIAGNOSTIC_CODES,
|
|
11202
12092
|
CalloutCard,
|
|
11203
12093
|
Canvas,
|
|
12094
|
+
CanvasItem,
|
|
11204
12095
|
CanvasOverflowError,
|
|
11205
12096
|
Card,
|
|
11206
12097
|
ChartFrame,
|
|
@@ -11233,7 +12124,9 @@ async function checkFrame(input, options = {}) {
|
|
|
11233
12124
|
MetricCard,
|
|
11234
12125
|
MiniBarChart,
|
|
11235
12126
|
Panel,
|
|
12127
|
+
ParetoBarChart,
|
|
11236
12128
|
ParetoChart,
|
|
12129
|
+
PieChart,
|
|
11237
12130
|
Pipeline,
|
|
11238
12131
|
ProgressList,
|
|
11239
12132
|
ProgressRow,
|