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.js
CHANGED
|
@@ -439,9 +439,12 @@ __export(primitives_exports, {
|
|
|
439
439
|
Badge: () => Badge,
|
|
440
440
|
BadgePill: () => BadgePill,
|
|
441
441
|
BarChart: () => BarChart,
|
|
442
|
+
Board: () => Board,
|
|
442
443
|
Box: () => Box,
|
|
444
|
+
CANVAS_ITEM_COMPONENT: () => CANVAS_ITEM_COMPONENT,
|
|
443
445
|
CalloutCard: () => CalloutCard,
|
|
444
446
|
Canvas: () => Canvas,
|
|
447
|
+
CanvasItem: () => CanvasItem,
|
|
445
448
|
Card: () => Card,
|
|
446
449
|
ChartFrame: () => ChartFrame,
|
|
447
450
|
CodeBlock: () => CodeBlock,
|
|
@@ -473,7 +476,9 @@ __export(primitives_exports, {
|
|
|
473
476
|
MetricCard: () => MetricCard,
|
|
474
477
|
MiniBarChart: () => MiniBarChart,
|
|
475
478
|
Panel: () => Panel,
|
|
479
|
+
ParetoBarChart: () => ParetoBarChart,
|
|
476
480
|
ParetoChart: () => ParetoChart,
|
|
481
|
+
PieChart: () => PieChart,
|
|
477
482
|
Pipeline: () => Pipeline,
|
|
478
483
|
ProgressList: () => ProgressList,
|
|
479
484
|
ProgressRow: () => ProgressRow,
|
|
@@ -2590,7 +2595,7 @@ function renderComparisonDivider(divider, c, key) {
|
|
|
2590
2595
|
);
|
|
2591
2596
|
}
|
|
2592
2597
|
function Comparison({
|
|
2593
|
-
sides,
|
|
2598
|
+
sides: sides2,
|
|
2594
2599
|
c,
|
|
2595
2600
|
divider = false,
|
|
2596
2601
|
gap = 14,
|
|
@@ -2599,7 +2604,7 @@ function Comparison({
|
|
|
2599
2604
|
align = "stretch",
|
|
2600
2605
|
math = false
|
|
2601
2606
|
}) {
|
|
2602
|
-
const children =
|
|
2607
|
+
const children = sides2.flatMap((side, index) => {
|
|
2603
2608
|
const tone = side.tone ?? "blue";
|
|
2604
2609
|
const panel = React4.createElement(
|
|
2605
2610
|
React4.Fragment,
|
|
@@ -2629,7 +2634,7 @@ function Comparison({
|
|
|
2629
2634
|
) : side.children ?? DetailList({ items: side.lines ?? [], c, tone, math })
|
|
2630
2635
|
})
|
|
2631
2636
|
);
|
|
2632
|
-
if (divider && index <
|
|
2637
|
+
if (divider && index < sides2.length - 1) {
|
|
2633
2638
|
return [panel, renderComparisonDivider(divider, c, `comparison-divider-${index}`)];
|
|
2634
2639
|
}
|
|
2635
2640
|
return [panel];
|
|
@@ -3485,6 +3490,284 @@ function addSvgAccessibility(svg, graphs, layoutNodes) {
|
|
|
3485
3490
|
).replace(/<\/svg>\s*$/, `${groupMarkup}</svg>`);
|
|
3486
3491
|
}
|
|
3487
3492
|
|
|
3493
|
+
// src/graph-routing.ts
|
|
3494
|
+
var EPSILON = 1e-3;
|
|
3495
|
+
var MAX_GRID_POINTS = 18e3;
|
|
3496
|
+
var MAX_SEARCH_STATES = 54e3;
|
|
3497
|
+
var MAX_TOTAL_SEARCH_STATES = 16e4;
|
|
3498
|
+
var MAX_ROUTED_EDGES = 256;
|
|
3499
|
+
var MAX_OBSTACLES = 64;
|
|
3500
|
+
var sides = ["right", "bottom", "left", "top"];
|
|
3501
|
+
function box(node, clearance = 0) {
|
|
3502
|
+
return {
|
|
3503
|
+
left: node.cx - node.width / 2 - clearance,
|
|
3504
|
+
right: node.cx + node.width / 2 + clearance,
|
|
3505
|
+
top: node.cy - node.height / 2 - clearance,
|
|
3506
|
+
bottom: node.cy + node.height / 2 + clearance
|
|
3507
|
+
};
|
|
3508
|
+
}
|
|
3509
|
+
function inside(point, obstacle) {
|
|
3510
|
+
return point.x > obstacle.left + EPSILON && point.x < obstacle.right - EPSILON && point.y > obstacle.top + EPSILON && point.y < obstacle.bottom - EPSILON;
|
|
3511
|
+
}
|
|
3512
|
+
function routingSegmentBlocked(a, b, obstacle) {
|
|
3513
|
+
if (Math.abs(a.y - b.y) < EPSILON) {
|
|
3514
|
+
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;
|
|
3515
|
+
}
|
|
3516
|
+
if (Math.abs(a.x - b.x) < EPSILON) {
|
|
3517
|
+
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;
|
|
3518
|
+
}
|
|
3519
|
+
return true;
|
|
3520
|
+
}
|
|
3521
|
+
function preferredSide(from, to) {
|
|
3522
|
+
if (Math.abs(to.cx - from.cx) >= Math.abs(to.cy - from.cy)) return to.cx >= from.cx ? "right" : "left";
|
|
3523
|
+
return to.cy >= from.cy ? "bottom" : "top";
|
|
3524
|
+
}
|
|
3525
|
+
function routingAnchor(node, side, offset = 0.5) {
|
|
3526
|
+
const bounds = box(node);
|
|
3527
|
+
if (side === "left" || side === "right") return { x: bounds[side], y: bounds.top + node.height * offset };
|
|
3528
|
+
return { x: bounds.left + node.width * offset, y: bounds[side] };
|
|
3529
|
+
}
|
|
3530
|
+
function outward(point, side, distance) {
|
|
3531
|
+
return {
|
|
3532
|
+
x: point.x + (side === "right" ? distance : side === "left" ? -distance : 0),
|
|
3533
|
+
y: point.y + (side === "bottom" ? distance : side === "top" ? -distance : 0)
|
|
3534
|
+
};
|
|
3535
|
+
}
|
|
3536
|
+
function simplify(points) {
|
|
3537
|
+
const result = [];
|
|
3538
|
+
for (const point of points) {
|
|
3539
|
+
const last = result[result.length - 1];
|
|
3540
|
+
if (last && Math.abs(last.x - point.x) < EPSILON && Math.abs(last.y - point.y) < EPSILON) continue;
|
|
3541
|
+
const previous = result[result.length - 2];
|
|
3542
|
+
if (previous && last && (previous.x === last.x && last.x === point.x || previous.y === last.y && last.y === point.y)) {
|
|
3543
|
+
result[result.length - 1] = point;
|
|
3544
|
+
} else result.push(point);
|
|
3545
|
+
}
|
|
3546
|
+
return result;
|
|
3547
|
+
}
|
|
3548
|
+
function overlappingLength(a, b, c, d) {
|
|
3549
|
+
if (a.y === b.y && c.y === d.y && Math.abs(a.y - c.y) < EPSILON) {
|
|
3550
|
+
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)));
|
|
3551
|
+
}
|
|
3552
|
+
if (a.x === b.x && c.x === d.x && Math.abs(a.x - c.x) < EPSILON) {
|
|
3553
|
+
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)));
|
|
3554
|
+
}
|
|
3555
|
+
return 0;
|
|
3556
|
+
}
|
|
3557
|
+
var MinQueue = class {
|
|
3558
|
+
items = [];
|
|
3559
|
+
get length() {
|
|
3560
|
+
return this.items.length;
|
|
3561
|
+
}
|
|
3562
|
+
push(value) {
|
|
3563
|
+
const items = this.items;
|
|
3564
|
+
items.push(value);
|
|
3565
|
+
let index = items.length - 1;
|
|
3566
|
+
while (index > 0) {
|
|
3567
|
+
const parent = index - 1 >> 1;
|
|
3568
|
+
if (items[parent].priority <= value.priority) break;
|
|
3569
|
+
items[index] = items[parent];
|
|
3570
|
+
index = parent;
|
|
3571
|
+
}
|
|
3572
|
+
items[index] = value;
|
|
3573
|
+
}
|
|
3574
|
+
pop() {
|
|
3575
|
+
const items = this.items;
|
|
3576
|
+
const first = items[0];
|
|
3577
|
+
const last = items.pop();
|
|
3578
|
+
if (items.length === 0) return first;
|
|
3579
|
+
let index = 0;
|
|
3580
|
+
while (index * 2 + 1 < items.length) {
|
|
3581
|
+
const left = index * 2 + 1;
|
|
3582
|
+
const right = left + 1;
|
|
3583
|
+
const child = right < items.length && items[right].priority < items[left].priority ? right : left;
|
|
3584
|
+
if (items[child].priority >= last.priority) break;
|
|
3585
|
+
items[index] = items[child];
|
|
3586
|
+
index = child;
|
|
3587
|
+
}
|
|
3588
|
+
items[index] = last;
|
|
3589
|
+
return first;
|
|
3590
|
+
}
|
|
3591
|
+
};
|
|
3592
|
+
function findPath(start, end, obstacles, width, height, previousRoutes, gap, budget) {
|
|
3593
|
+
const within = (point) => point.x >= 0 && point.x <= width && point.y >= 0 && point.y <= height;
|
|
3594
|
+
if (!within(start) || !within(end) || obstacles.some((obstacle) => inside(start, obstacle) || inside(end, obstacle))) {
|
|
3595
|
+
return { reason: "an endpoint has no clear exit inside the canvas" };
|
|
3596
|
+
}
|
|
3597
|
+
const xs = /* @__PURE__ */ new Set([0, width, start.x, end.x]);
|
|
3598
|
+
const ys = /* @__PURE__ */ new Set([0, height, start.y, end.y]);
|
|
3599
|
+
for (const obstacle of obstacles) {
|
|
3600
|
+
if (obstacle.left >= 0 && obstacle.left <= width) xs.add(obstacle.left);
|
|
3601
|
+
if (obstacle.right >= 0 && obstacle.right <= width) xs.add(obstacle.right);
|
|
3602
|
+
if (obstacle.top >= 0 && obstacle.top <= height) ys.add(obstacle.top);
|
|
3603
|
+
if (obstacle.bottom >= 0 && obstacle.bottom <= height) ys.add(obstacle.bottom);
|
|
3604
|
+
}
|
|
3605
|
+
for (const route of previousRoutes.slice(-8)) for (const point of route) {
|
|
3606
|
+
for (const offset of [-gap, gap]) {
|
|
3607
|
+
if (point.x + offset >= 0 && point.x + offset <= width) xs.add(point.x + offset);
|
|
3608
|
+
if (point.y + offset >= 0 && point.y + offset <= height) ys.add(point.y + offset);
|
|
3609
|
+
}
|
|
3610
|
+
}
|
|
3611
|
+
const xValues = [...xs].sort((a, b) => a - b);
|
|
3612
|
+
const yValues = [...ys].sort((a, b) => a - b);
|
|
3613
|
+
const columns = xValues.length;
|
|
3614
|
+
const gridSize = columns * yValues.length;
|
|
3615
|
+
if (gridSize > MAX_GRID_POINTS) return { reason: `routing grid exceeds ${MAX_GRID_POINTS} points; simplify the graph` };
|
|
3616
|
+
const startIndex = yValues.indexOf(start.y) * columns + xValues.indexOf(start.x);
|
|
3617
|
+
const endIndex = yValues.indexOf(end.y) * columns + xValues.indexOf(end.x);
|
|
3618
|
+
const pointAt = (index) => ({ x: xValues[index % columns], y: yValues[Math.floor(index / columns)] });
|
|
3619
|
+
const costs = new Float64Array(gridSize * 3).fill(Infinity);
|
|
3620
|
+
const parents = new Int32Array(gridSize * 3).fill(-1);
|
|
3621
|
+
const queue = new MinQueue();
|
|
3622
|
+
costs[startIndex * 3] = 0;
|
|
3623
|
+
queue.push({ state: startIndex * 3, cost: 0, priority: 0 });
|
|
3624
|
+
let visits = 0;
|
|
3625
|
+
while (queue.length > 0) {
|
|
3626
|
+
if (--budget.remaining < 0) return { reason: `diagram routing budget exceeds ${MAX_TOTAL_SEARCH_STATES} search states; simplify the graph` };
|
|
3627
|
+
if (++visits > MAX_SEARCH_STATES) return { reason: `routing search exceeds ${MAX_SEARCH_STATES} states; simplify the graph` };
|
|
3628
|
+
const current = queue.pop();
|
|
3629
|
+
if (current.cost !== costs[current.state]) continue;
|
|
3630
|
+
const index = Math.floor(current.state / 3);
|
|
3631
|
+
const axis = current.state % 3;
|
|
3632
|
+
if (index === endIndex) {
|
|
3633
|
+
const points = [];
|
|
3634
|
+
for (let state = current.state; state >= 0; state = parents[state]) points.push(pointAt(Math.floor(state / 3)));
|
|
3635
|
+
return { points: simplify(points.reverse()) };
|
|
3636
|
+
}
|
|
3637
|
+
const a = pointAt(index);
|
|
3638
|
+
const column = index % columns;
|
|
3639
|
+
const row = Math.floor(index / columns);
|
|
3640
|
+
const neighbors = [
|
|
3641
|
+
column > 0 ? index - 1 : -1,
|
|
3642
|
+
column < columns - 1 ? index + 1 : -1,
|
|
3643
|
+
row > 0 ? index - columns : -1,
|
|
3644
|
+
row < yValues.length - 1 ? index + columns : -1
|
|
3645
|
+
];
|
|
3646
|
+
for (const neighbor of neighbors) {
|
|
3647
|
+
if (neighbor < 0) continue;
|
|
3648
|
+
const b = pointAt(neighbor);
|
|
3649
|
+
if (obstacles.some((obstacle) => routingSegmentBlocked(a, b, obstacle))) continue;
|
|
3650
|
+
const nextAxis = a.y === b.y ? 1 : 2;
|
|
3651
|
+
const state = neighbor * 3 + nextAxis;
|
|
3652
|
+
let overlap = 0;
|
|
3653
|
+
for (const route of previousRoutes) for (let i = 1; i < route.length; i++) overlap += overlappingLength(a, b, route[i - 1], route[i]);
|
|
3654
|
+
const cost = current.cost + Math.abs(b.x - a.x) + Math.abs(b.y - a.y) + (axis !== 0 && axis !== nextAxis ? 18 : 0) + overlap * 5;
|
|
3655
|
+
if (cost >= costs[state]) continue;
|
|
3656
|
+
costs[state] = cost;
|
|
3657
|
+
parents[state] = current.state;
|
|
3658
|
+
queue.push({ state, cost, priority: cost + Math.abs(end.x - b.x) + Math.abs(end.y - b.y) });
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3661
|
+
return { reason: "no obstacle-free route exists inside the canvas" };
|
|
3662
|
+
}
|
|
3663
|
+
function endpoint(node, other, portId, requestedSide, selfLoop, target, ordinal, count, gap) {
|
|
3664
|
+
const port = node.ports?.find((candidate) => candidate.id === portId);
|
|
3665
|
+
const side = port?.side ?? requestedSide ?? (selfLoop ? target ? "top" : "right" : preferredSide(node, other));
|
|
3666
|
+
const length = side === "left" || side === "right" ? node.height : node.width;
|
|
3667
|
+
const separation = count > 1 ? Math.min(gap, length * 0.7 / (count - 1)) : 0;
|
|
3668
|
+
const offset = port ? port.offset ?? 0.5 : 0.5 + (ordinal - (count - 1) / 2) * separation / length;
|
|
3669
|
+
return { side, anchor: routingAnchor(node, side, offset), explicit: portId != null || requestedSide != null };
|
|
3670
|
+
}
|
|
3671
|
+
function straightGraphRoute(from, to, edge) {
|
|
3672
|
+
return [
|
|
3673
|
+
endpoint(from, to, edge.fromPort, edge.fromSide, false, false, 0, 1, 0).anchor,
|
|
3674
|
+
endpoint(to, from, edge.toPort, edge.toSide, false, true, 0, 1, 0).anchor
|
|
3675
|
+
];
|
|
3676
|
+
}
|
|
3677
|
+
function routeOrthogonalGraph(nodes, edges, width, height, clearance = 12, gap = 14, extraObstacles = []) {
|
|
3678
|
+
const routes = /* @__PURE__ */ new Map();
|
|
3679
|
+
const failures = [];
|
|
3680
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
3681
|
+
const obstacles = [...nodes.map((node) => box(node, clearance)), ...extraObstacles.map((obstacle) => ({
|
|
3682
|
+
left: obstacle.left - clearance,
|
|
3683
|
+
right: obstacle.right + clearance,
|
|
3684
|
+
top: obstacle.top - clearance,
|
|
3685
|
+
bottom: obstacle.bottom + clearance
|
|
3686
|
+
}))];
|
|
3687
|
+
const routeKey = (edge) => [edge.from, edge.to].sort().join("\0");
|
|
3688
|
+
const counts2 = /* @__PURE__ */ new Map();
|
|
3689
|
+
for (const edge of edges) counts2.set(routeKey(edge), (counts2.get(routeKey(edge)) ?? 0) + 1);
|
|
3690
|
+
const occurrences = /* @__PURE__ */ new Map();
|
|
3691
|
+
const previous = /* @__PURE__ */ new Map();
|
|
3692
|
+
const budget = { remaining: MAX_TOTAL_SEARCH_STATES };
|
|
3693
|
+
edges.forEach((edge, index) => {
|
|
3694
|
+
if (index >= MAX_ROUTED_EDGES) {
|
|
3695
|
+
failures.push({ index, reason: `orthogonal routing supports at most ${MAX_ROUTED_EDGES} edges per diagram` });
|
|
3696
|
+
return;
|
|
3697
|
+
}
|
|
3698
|
+
if (obstacles.length > MAX_OBSTACLES) {
|
|
3699
|
+
failures.push({ index, reason: `orthogonal routing supports at most ${MAX_OBSTACLES} node and header obstacles per diagram` });
|
|
3700
|
+
return;
|
|
3701
|
+
}
|
|
3702
|
+
if (budget.remaining < 0) {
|
|
3703
|
+
failures.push({ index, reason: `diagram routing budget exceeds ${MAX_TOTAL_SEARCH_STATES} search states; simplify the graph` });
|
|
3704
|
+
return;
|
|
3705
|
+
}
|
|
3706
|
+
const from = byId.get(edge.from);
|
|
3707
|
+
const to = byId.get(edge.to);
|
|
3708
|
+
const key = routeKey(edge);
|
|
3709
|
+
const ordinal = occurrences.get(key) ?? 0;
|
|
3710
|
+
occurrences.set(key, ordinal + 1);
|
|
3711
|
+
const count = counts2.get(key) ?? 1;
|
|
3712
|
+
const source = endpoint(from, to, edge.fromPort, edge.fromSide, from === to, false, ordinal, count, gap);
|
|
3713
|
+
const target = endpoint(to, from, edge.toPort, edge.toSide, from === to, true, ordinal, count, gap);
|
|
3714
|
+
const sourceSides = source.explicit ? [source.side] : [source.side, ...sides.filter((side) => side !== source.side)];
|
|
3715
|
+
const targetSides = target.explicit ? [target.side] : [target.side, ...sides.filter((side) => side !== target.side)];
|
|
3716
|
+
let failure = "no obstacle-free route exists inside the canvas";
|
|
3717
|
+
for (const sourceSide of sourceSides) {
|
|
3718
|
+
for (const targetSide of targetSides) {
|
|
3719
|
+
const start = sourceSide === source.side ? source.anchor : routingAnchor(from, sourceSide);
|
|
3720
|
+
const end = targetSide === target.side ? target.anchor : routingAnchor(to, targetSide);
|
|
3721
|
+
if (from === to && start.x === end.x && start.y === end.y) {
|
|
3722
|
+
failure = "a self-loop requires distinct endpoint anchors";
|
|
3723
|
+
continue;
|
|
3724
|
+
}
|
|
3725
|
+
const leadStart = outward(start, sourceSide, clearance);
|
|
3726
|
+
const leadEnd = outward(end, targetSide, clearance);
|
|
3727
|
+
if (obstacles.some((obstacle, obstacleIndex) => obstacleIndex !== nodes.indexOf(from) && routingSegmentBlocked(start, leadStart, obstacle) || obstacleIndex !== nodes.indexOf(to) && routingSegmentBlocked(leadEnd, end, obstacle))) {
|
|
3728
|
+
failure = "another obstacle blocks an endpoint exit";
|
|
3729
|
+
continue;
|
|
3730
|
+
}
|
|
3731
|
+
const result = findPath(leadStart, leadEnd, obstacles, width, height, previous.get(key) ?? [], Math.max(1, gap), budget);
|
|
3732
|
+
if (!result.points) {
|
|
3733
|
+
failure = result.reason;
|
|
3734
|
+
if (/routing (grid|search|budget)/.test(failure)) {
|
|
3735
|
+
failures.push({ index, reason: failure });
|
|
3736
|
+
return;
|
|
3737
|
+
}
|
|
3738
|
+
continue;
|
|
3739
|
+
}
|
|
3740
|
+
const points = simplify([start, ...result.points, end]);
|
|
3741
|
+
if (points.length < 2) continue;
|
|
3742
|
+
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)));
|
|
3743
|
+
if (repeated) {
|
|
3744
|
+
failure = "parallel connectors have no separate lane at the requested clearance";
|
|
3745
|
+
continue;
|
|
3746
|
+
}
|
|
3747
|
+
routes.set(index, points);
|
|
3748
|
+
previous.set(key, [...previous.get(key) ?? [], points]);
|
|
3749
|
+
return;
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
failures.push({ index, reason: failure });
|
|
3753
|
+
});
|
|
3754
|
+
return { routes, failures };
|
|
3755
|
+
}
|
|
3756
|
+
function routingLabelPosition(points) {
|
|
3757
|
+
let longest = 0;
|
|
3758
|
+
let position = points[0];
|
|
3759
|
+
for (let i = 1; i < points.length; i++) {
|
|
3760
|
+
const a = points[i - 1];
|
|
3761
|
+
const b = points[i];
|
|
3762
|
+
const length = Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
|
3763
|
+
if (length > longest) {
|
|
3764
|
+
longest = length;
|
|
3765
|
+
position = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
3766
|
+
}
|
|
3767
|
+
}
|
|
3768
|
+
return position;
|
|
3769
|
+
}
|
|
3770
|
+
|
|
3488
3771
|
// src/primitives/diagrams.ts
|
|
3489
3772
|
function distributeValues(count, start, end) {
|
|
3490
3773
|
if (count <= 0) return [];
|
|
@@ -3821,6 +4104,20 @@ function validateGraphDiagramSpec(nodes, edges, groups, layoutMode) {
|
|
|
3821
4104
|
for (const node of nodes) {
|
|
3822
4105
|
if (nodeIds.has(node.id)) throw new Error(`GraphDiagram received duplicate node id "${node.id}".`);
|
|
3823
4106
|
nodeIds.add(node.id);
|
|
4107
|
+
const portIds = /* @__PURE__ */ new Set();
|
|
4108
|
+
for (const port of node.ports ?? []) {
|
|
4109
|
+
if (typeof port.id !== "string" || port.id.trim().length === 0) {
|
|
4110
|
+
throw new Error(`GraphDiagram node "${node.id}" port id must be a non-empty string.`);
|
|
4111
|
+
}
|
|
4112
|
+
if (portIds.has(port.id)) throw new Error(`GraphDiagram node "${node.id}" received duplicate port "${port.id}".`);
|
|
4113
|
+
portIds.add(port.id);
|
|
4114
|
+
if (!["top", "right", "bottom", "left"].includes(port.side)) {
|
|
4115
|
+
throw new Error(`GraphDiagram node "${node.id}" port "${port.id}" must use side "top", "right", "bottom", or "left".`);
|
|
4116
|
+
}
|
|
4117
|
+
if (port.offset != null && (!Number.isFinite(port.offset) || port.offset < 0 || port.offset > 1)) {
|
|
4118
|
+
throw new Error(`GraphDiagram node "${node.id}" port "${port.id}" offset must be between 0 and 1.`);
|
|
4119
|
+
}
|
|
4120
|
+
}
|
|
3824
4121
|
}
|
|
3825
4122
|
const groupsById = /* @__PURE__ */ new Map();
|
|
3826
4123
|
for (const group of groups) {
|
|
@@ -3864,6 +4161,20 @@ function validateGraphDiagramSpec(nodes, edges, groups, layoutMode) {
|
|
|
3864
4161
|
if (edgeIds.has(edge.id)) throw new Error(`GraphDiagram received duplicate edge id "${edge.id}".`);
|
|
3865
4162
|
edgeIds.add(edge.id);
|
|
3866
4163
|
}
|
|
4164
|
+
for (const side of ["from", "to"]) {
|
|
4165
|
+
const reference = side === "from" ? edge.fromPort : edge.toPort;
|
|
4166
|
+
const endpointSide = side === "from" ? edge.fromSide : edge.toSide;
|
|
4167
|
+
const node = nodes.find((candidate) => candidate.id === edge[side]);
|
|
4168
|
+
if (reference != null && !node.ports?.some((port) => port.id === reference)) {
|
|
4169
|
+
throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" references missing ${side} port "${reference}" on node "${node.id}".`);
|
|
4170
|
+
}
|
|
4171
|
+
if (endpointSide != null && !["top", "right", "bottom", "left"].includes(endpointSide)) {
|
|
4172
|
+
throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" ${side}Side must be "top", "right", "bottom", or "left".`);
|
|
4173
|
+
}
|
|
4174
|
+
if (reference != null && endpointSide != null) {
|
|
4175
|
+
throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" cannot combine ${side}Port and ${side}Side.`);
|
|
4176
|
+
}
|
|
4177
|
+
}
|
|
3867
4178
|
validateDiagramHref(edge.href, `edge "${edge.id ?? `${edge.from}" -> "${edge.to}`}"`);
|
|
3868
4179
|
}
|
|
3869
4180
|
for (const node of nodes) {
|
|
@@ -3939,6 +4250,8 @@ function GraphDiagram({
|
|
|
3939
4250
|
nodeGap = 34,
|
|
3940
4251
|
rankGap = 64,
|
|
3941
4252
|
edgeGap = 14,
|
|
4253
|
+
routing = "dagre",
|
|
4254
|
+
routingClearance = 12,
|
|
3942
4255
|
sizing = "content",
|
|
3943
4256
|
iconSize = 20,
|
|
3944
4257
|
id,
|
|
@@ -3947,6 +4260,8 @@ function GraphDiagram({
|
|
|
3947
4260
|
description
|
|
3948
4261
|
}) {
|
|
3949
4262
|
if (id != null && id.trim().length === 0) throw new Error("GraphDiagram id must not be empty.");
|
|
4263
|
+
if (!["dagre", "straight", "orthogonal"].includes(routing)) throw new Error('GraphDiagram routing must be "dagre", "straight", or "orthogonal".');
|
|
4264
|
+
if (!Number.isFinite(routingClearance) || routingClearance <= 0) throw new Error("GraphDiagram routingClearance must be a finite positive number.");
|
|
3950
4265
|
const fullyPositioned = nodes.filter((node) => node.x != null && node.y != null).length;
|
|
3951
4266
|
const partiallyPositioned = nodes.some((node) => node.x == null !== (node.y == null));
|
|
3952
4267
|
if (partiallyPositioned || fullyPositioned > 0 && fullyPositioned < nodes.length) {
|
|
@@ -4041,7 +4356,30 @@ function GraphDiagram({
|
|
|
4041
4356
|
} else {
|
|
4042
4357
|
layout = manualGraphLayout(nodes, resolvedWidth, resolvedHeight, nodeWidth, nodeHeight, padding);
|
|
4043
4358
|
}
|
|
4359
|
+
const anchored = (edge) => edge.fromPort != null || edge.toPort != null || edge.fromSide != null || edge.toSide != null;
|
|
4360
|
+
const orthogonalEdges = edges.flatMap((edge, index) => routing === "orthogonal" || routing === "dagre" && anchored(edge) || routing === "straight" && edge.from === edge.to ? [{ edge, index }] : []);
|
|
4361
|
+
const routed = routeOrthogonalGraph(
|
|
4362
|
+
Array.from(layout.values()),
|
|
4363
|
+
orthogonalEdges.map(({ edge }) => edge),
|
|
4364
|
+
resolvedWidth,
|
|
4365
|
+
resolvedHeight,
|
|
4366
|
+
routingClearance,
|
|
4367
|
+
edgeGap,
|
|
4368
|
+
groupLayout.map((group) => ({
|
|
4369
|
+
left: group.cx - group.width / 2,
|
|
4370
|
+
right: group.cx + group.width / 2,
|
|
4371
|
+
top: group.cy - group.height / 2,
|
|
4372
|
+
bottom: group.cy - group.height / 2 + 26
|
|
4373
|
+
}))
|
|
4374
|
+
);
|
|
4375
|
+
const orthogonalPoints = new Map(Array.from(routed.routes, ([index, points]) => [orthogonalEdges[index].index, points]));
|
|
4376
|
+
const failedIndexes = new Set(routed.failures.map((failure) => orthogonalEdges[failure.index].index));
|
|
4377
|
+
const routingFailures = routed.failures.map((failure) => {
|
|
4378
|
+
const { edge } = orthogonalEdges[failure.index];
|
|
4379
|
+
return `Connector "${edge.from}" -> "${edge.to}" was not drawn: ${failure.reason}.`;
|
|
4380
|
+
});
|
|
4044
4381
|
const edgeLayouts = edges.flatMap((edge, index) => {
|
|
4382
|
+
if (failedIndexes.has(index)) return [];
|
|
4045
4383
|
const from = layout.get(edge.from);
|
|
4046
4384
|
const to = layout.get(edge.to);
|
|
4047
4385
|
if (!from || !to) return [];
|
|
@@ -4070,14 +4408,16 @@ function GraphDiagram({
|
|
|
4070
4408
|
{ x: from.cx + 10, y: from.cy - from.height / 2 - loopClearance },
|
|
4071
4409
|
{ x: from.cx + 10, y: from.cy - from.height / 2 }
|
|
4072
4410
|
] : void 0;
|
|
4073
|
-
const
|
|
4411
|
+
const routedPoints = orthogonalPoints.get(index);
|
|
4412
|
+
const points = routedPoints ?? (routing === "straight" ? straightGraphRoute(from, to, edge) : automatic?.points.length ? automatic.points : manualLoopPoints ?? [
|
|
4074
4413
|
{ x: from.cx + dx * fromScale, y: from.cy + dy * fromScale },
|
|
4075
4414
|
{ x: to.cx - dx * toScale, y: to.cy - dy * toScale }
|
|
4076
|
-
];
|
|
4415
|
+
]);
|
|
4077
4416
|
const manualLoopLabel = manualLoopPoints ? {
|
|
4078
4417
|
x: from.cx + from.width / 2 + loopClearance,
|
|
4079
4418
|
y: from.cy - from.height / 2 - loopClearance / 2
|
|
4080
4419
|
} : void 0;
|
|
4420
|
+
const routedLabel = routedPoints || routing === "straight" ? routingLabelPosition(points) : void 0;
|
|
4081
4421
|
return [{
|
|
4082
4422
|
...edge,
|
|
4083
4423
|
index,
|
|
@@ -4085,14 +4425,14 @@ function GraphDiagram({
|
|
|
4085
4425
|
color,
|
|
4086
4426
|
markerId,
|
|
4087
4427
|
points,
|
|
4088
|
-
labelX: automatic?.labelX ?? manualLoopLabel?.x ?? (points[0].x + points[points.length - 1].x) / 2,
|
|
4089
|
-
labelY: automatic?.labelY ?? manualLoopLabel?.y ?? (points[0].y + points[points.length - 1].y) / 2
|
|
4428
|
+
labelX: routedLabel?.x ?? automatic?.labelX ?? manualLoopLabel?.x ?? (points[0].x + points[points.length - 1].x) / 2,
|
|
4429
|
+
labelY: routedLabel?.y ?? automatic?.labelY ?? manualLoopLabel?.y ?? (points[0].y + points[points.length - 1].y) / 2
|
|
4090
4430
|
}];
|
|
4091
4431
|
});
|
|
4092
4432
|
const crossings = connectorCrossings(edgeLayouts);
|
|
4093
4433
|
const labelCollisions = connectorLabelCollisions(edgeLayouts, layout, groupLayout);
|
|
4094
4434
|
const crowdedEndpoints = crowdedConnectorEndpoints(edgeLayouts);
|
|
4095
|
-
const parallelGroups = parallelConnectorGroups(edgeLayouts);
|
|
4435
|
+
const parallelGroups = parallelConnectorGroups(edgeLayouts.filter((edge) => !orthogonalPoints.has(edge.index)));
|
|
4096
4436
|
const groupElements = groupLayout.map((group) => {
|
|
4097
4437
|
const accent = group.muted ? c.textMuted : getToneColor(group.tone ?? "blue", c);
|
|
4098
4438
|
return React6.createElement("div", {
|
|
@@ -4158,6 +4498,8 @@ function GraphDiagram({
|
|
|
4158
4498
|
"data-vizmatic-connector-label-collisions": labelCollisions,
|
|
4159
4499
|
"data-vizmatic-crowded-connector-endpoints": crowdedEndpoints,
|
|
4160
4500
|
"data-vizmatic-parallel-connector-groups": parallelGroups,
|
|
4501
|
+
"data-vizmatic-unrouted-connectors": routingFailures.length,
|
|
4502
|
+
"data-vizmatic-routing-failures": routingFailures.length ? JSON.stringify(routingFailures) : void 0,
|
|
4161
4503
|
style: {
|
|
4162
4504
|
position: "relative",
|
|
4163
4505
|
display: "flex",
|
|
@@ -5415,6 +5757,8 @@ function DataflowDiagram({
|
|
|
5415
5757
|
nodeGap,
|
|
5416
5758
|
rankGap,
|
|
5417
5759
|
edgeGap,
|
|
5760
|
+
routing,
|
|
5761
|
+
routingClearance,
|
|
5418
5762
|
sizing,
|
|
5419
5763
|
iconSize
|
|
5420
5764
|
}) {
|
|
@@ -5440,6 +5784,8 @@ function DataflowDiagram({
|
|
|
5440
5784
|
nodeGap,
|
|
5441
5785
|
rankGap,
|
|
5442
5786
|
edgeGap,
|
|
5787
|
+
routing,
|
|
5788
|
+
routingClearance,
|
|
5443
5789
|
sizing,
|
|
5444
5790
|
iconSize
|
|
5445
5791
|
});
|
|
@@ -5568,8 +5914,8 @@ function portIdentity(port) {
|
|
|
5568
5914
|
function portText(port) {
|
|
5569
5915
|
if (typeof port === "string" || typeof port === "number") return String(port);
|
|
5570
5916
|
if (port.label) return port.label;
|
|
5571
|
-
const
|
|
5572
|
-
return [port.protocol,
|
|
5917
|
+
const endpoint2 = port.port ?? port.id;
|
|
5918
|
+
return [port.protocol, endpoint2 == null ? void 0 : String(endpoint2)].filter(Boolean).join("/") || port.direction || "port";
|
|
5573
5919
|
}
|
|
5574
5920
|
function portForReference(node, reference) {
|
|
5575
5921
|
if (reference == null) return void 0;
|
|
@@ -5679,6 +6025,9 @@ function compileDeployment(spec) {
|
|
|
5679
6025
|
const boundaries = spec.boundaries ?? [];
|
|
5680
6026
|
const connections = spec.connections ?? [];
|
|
5681
6027
|
validateDeploymentSpec(boundaries, spec.nodes, connections);
|
|
6028
|
+
const anchorPorts = spec.routing != null && spec.routing !== "dagre";
|
|
6029
|
+
const incomingSide = spec.direction === "TB" ? "top" : spec.direction === "BT" ? "bottom" : spec.direction === "RL" ? "right" : "left";
|
|
6030
|
+
const outgoingSide = spec.direction === "TB" ? "bottom" : spec.direction === "BT" ? "top" : spec.direction === "RL" ? "left" : "right";
|
|
5682
6031
|
const groups = boundaries.map((boundary) => ({
|
|
5683
6032
|
id: boundary.id,
|
|
5684
6033
|
label: boundary.label,
|
|
@@ -5705,7 +6054,16 @@ function compileDeployment(spec) {
|
|
|
5705
6054
|
height: node.height,
|
|
5706
6055
|
group: node.boundary,
|
|
5707
6056
|
icon: node.icon ?? nodeKindIcons[kind],
|
|
5708
|
-
iconSize: node.iconSize
|
|
6057
|
+
iconSize: node.iconSize,
|
|
6058
|
+
ports: anchorPorts ? nodePorts.map((port, index) => {
|
|
6059
|
+
const incoming = typeof port === "object" ? port.direction === "ingress" : false;
|
|
6060
|
+
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));
|
|
6061
|
+
return {
|
|
6062
|
+
id: portIdentity(port),
|
|
6063
|
+
side: typeof port === "object" && port.side != null ? port.side : incoming || targetOnly ? incomingSide : outgoingSide,
|
|
6064
|
+
offset: typeof port === "object" && port.offset != null ? port.offset : (index + 1) / (nodePorts.length + 1)
|
|
6065
|
+
};
|
|
6066
|
+
}) : void 0
|
|
5709
6067
|
};
|
|
5710
6068
|
});
|
|
5711
6069
|
const edges = connections.map((connection) => {
|
|
@@ -5729,7 +6087,11 @@ function compileDeployment(spec) {
|
|
|
5729
6087
|
arrow: connection.arrow ?? "forward",
|
|
5730
6088
|
label: connectionLabel(connection, sourcePort ?? fallbackFromPort, targetPort ?? fallbackToPort),
|
|
5731
6089
|
href: connection.href,
|
|
5732
|
-
title: connection.title
|
|
6090
|
+
title: connection.title,
|
|
6091
|
+
fromPort: anchorPorts && fromReference != null ? String(fromReference) : void 0,
|
|
6092
|
+
toPort: anchorPorts && toReference != null ? String(toReference) : void 0,
|
|
6093
|
+
fromSide: connection.fromSide,
|
|
6094
|
+
toSide: connection.toSide
|
|
5733
6095
|
};
|
|
5734
6096
|
});
|
|
5735
6097
|
return {
|
|
@@ -5747,7 +6109,7 @@ function DeploymentDiagram({
|
|
|
5747
6109
|
ariaLabel = "Deployment diagram",
|
|
5748
6110
|
...graphProps
|
|
5749
6111
|
}) {
|
|
5750
|
-
const compiled = compileDeployment({ nodes, boundaries, connections, ariaLabel });
|
|
6112
|
+
const compiled = compileDeployment({ nodes, boundaries, connections, ariaLabel, direction: graphProps.direction, routing: graphProps.routing });
|
|
5751
6113
|
return GraphDiagram({
|
|
5752
6114
|
...graphProps,
|
|
5753
6115
|
c,
|
|
@@ -5973,11 +6335,11 @@ function compileTransformer(spec) {
|
|
|
5973
6335
|
for (const route of routes) {
|
|
5974
6336
|
const kind = resolveRouteKind(route);
|
|
5975
6337
|
const endpoints = expandedRouteEndpoints(route, repeatCounts, expandRepeats);
|
|
5976
|
-
for (const [index,
|
|
6338
|
+
for (const [index, endpoint2] of endpoints.entries()) {
|
|
5977
6339
|
edges.push({
|
|
5978
6340
|
id: route.id == null ? void 0 : endpoints.length === 1 ? route.id : `${route.id}-${index + 1}`,
|
|
5979
|
-
from:
|
|
5980
|
-
to:
|
|
6341
|
+
from: endpoint2.from,
|
|
6342
|
+
to: endpoint2.to,
|
|
5981
6343
|
tone: route.tone ?? routeTones[kind],
|
|
5982
6344
|
muted: route.muted,
|
|
5983
6345
|
kind: graphRouteKind(kind),
|
|
@@ -6652,7 +7014,138 @@ function AxisPlot({
|
|
|
6652
7014
|
}
|
|
6653
7015
|
|
|
6654
7016
|
// src/primitives/charts.ts
|
|
6655
|
-
import
|
|
7017
|
+
import React11 from "react";
|
|
7018
|
+
|
|
7019
|
+
// src/canvas-chart-fit.ts
|
|
7020
|
+
import React10, { isValidElement as isValidElement2 } from "react";
|
|
7021
|
+
var CANVAS_CHART_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.canvasChartComponent");
|
|
7022
|
+
var CHART_FRAME_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.chartFrameComponent");
|
|
7023
|
+
var FIT_PROP = "__vizmaticCanvasChartFit";
|
|
7024
|
+
var SCOPE_PROP = "data-vizmatic-chart-fit-scope";
|
|
7025
|
+
var VIEWPORT_PROP = "data-vizmatic-chart-fit-viewport";
|
|
7026
|
+
function isCanvasChart(component) {
|
|
7027
|
+
return typeof component === "function" && Boolean(component[CANVAS_CHART_COMPONENT]);
|
|
7028
|
+
}
|
|
7029
|
+
function CanvasChartFit({ children, width, height }) {
|
|
7030
|
+
let chart = children;
|
|
7031
|
+
for (let depth = 0; isValidElement2(chart) && typeof chart.type === "function" && depth < 16; depth += 1) {
|
|
7032
|
+
if (chart.type[CHART_FRAME_COMPONENT]) {
|
|
7033
|
+
const props = chart.props;
|
|
7034
|
+
const padding = typeof props.padding === "number" ? props.padding : 16;
|
|
7035
|
+
chart = React10.cloneElement(chart, {
|
|
7036
|
+
...props,
|
|
7037
|
+
width: typeof props.width === "number" ? props.width + 2 * (padding + 1) : props.width,
|
|
7038
|
+
height: void 0
|
|
7039
|
+
});
|
|
7040
|
+
break;
|
|
7041
|
+
}
|
|
7042
|
+
chart = chart.type(chart.props);
|
|
7043
|
+
}
|
|
7044
|
+
return React10.createElement("div", {
|
|
7045
|
+
[FIT_PROP]: { width, height },
|
|
7046
|
+
style: { position: "relative", display: "flex", width, height, flexShrink: 0 }
|
|
7047
|
+
}, React10.createElement("div", {
|
|
7048
|
+
style: { position: "absolute", left: 0, top: 0, display: "flex", alignItems: "flex-start" }
|
|
7049
|
+
}, chart));
|
|
7050
|
+
}
|
|
7051
|
+
function prepareChartFits(element) {
|
|
7052
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
7053
|
+
const visit = (node, scope) => {
|
|
7054
|
+
if (Array.isArray(node)) return node.map((child) => visit(child, scope));
|
|
7055
|
+
if (!isValidElement2(node)) return node;
|
|
7056
|
+
if (typeof node.type === "function") {
|
|
7057
|
+
const resolved = visit(node.type(node.props), scope);
|
|
7058
|
+
return node.key != null && isValidElement2(resolved) ? React10.cloneElement(resolved, { key: node.key }) : resolved;
|
|
7059
|
+
}
|
|
7060
|
+
const size = node.props[FIT_PROP];
|
|
7061
|
+
const props = { ...node.props };
|
|
7062
|
+
delete props[FIT_PROP];
|
|
7063
|
+
if (size) {
|
|
7064
|
+
const id = String(sizes.size);
|
|
7065
|
+
sizes.set(id, size);
|
|
7066
|
+
props[VIEWPORT_PROP] = id;
|
|
7067
|
+
return React10.cloneElement(node, props, visit(node.props.children, id));
|
|
7068
|
+
}
|
|
7069
|
+
if (scope !== void 0 && typeof node.type === "string") props[SCOPE_PROP] = scope;
|
|
7070
|
+
const children = node.props.children;
|
|
7071
|
+
return children === void 0 ? React10.cloneElement(node, props) : React10.cloneElement(node, props, visit(children, scope));
|
|
7072
|
+
};
|
|
7073
|
+
return { element: visit(element), sizes };
|
|
7074
|
+
}
|
|
7075
|
+
function fittedTree(element, geometry) {
|
|
7076
|
+
if (Array.isArray(element)) return element.map((child) => fittedTree(child, geometry));
|
|
7077
|
+
if (!isValidElement2(element)) return element;
|
|
7078
|
+
const id = element.props[VIEWPORT_PROP];
|
|
7079
|
+
const children = element.props.children;
|
|
7080
|
+
if (typeof id === "string") {
|
|
7081
|
+
const fit = geometry.get(id);
|
|
7082
|
+
const content = React10.Children.only(children);
|
|
7083
|
+
return React10.cloneElement(element, {}, React10.cloneElement(content, { style: {
|
|
7084
|
+
...content.props.style,
|
|
7085
|
+
left: fit.left,
|
|
7086
|
+
top: fit.top,
|
|
7087
|
+
transform: `scale(${fit.scale})`,
|
|
7088
|
+
transformOrigin: "top left"
|
|
7089
|
+
} }));
|
|
7090
|
+
}
|
|
7091
|
+
return children === void 0 ? element : React10.cloneElement(element, {}, fittedTree(children, geometry));
|
|
7092
|
+
}
|
|
7093
|
+
async function renderWithCanvasChartFit(render, element, options) {
|
|
7094
|
+
const prepared = prepareChartFits(element);
|
|
7095
|
+
if (!prepared.sizes.size) return render(prepared.element, options);
|
|
7096
|
+
const viewports = /* @__PURE__ */ new Map();
|
|
7097
|
+
const bounds = /* @__PURE__ */ new Map();
|
|
7098
|
+
await render(prepared.element, { ...options, onNodeDetected(node) {
|
|
7099
|
+
const viewport = node.props[VIEWPORT_PROP];
|
|
7100
|
+
if (typeof viewport === "string") viewports.set(viewport, node);
|
|
7101
|
+
const id = node.props[SCOPE_PROP];
|
|
7102
|
+
if (typeof id !== "string" || node.width <= 0 || node.height <= 0) return;
|
|
7103
|
+
const prior = bounds.get(id);
|
|
7104
|
+
bounds.set(id, {
|
|
7105
|
+
left: Math.min(prior?.left ?? Infinity, node.left),
|
|
7106
|
+
top: Math.min(prior?.top ?? Infinity, node.top),
|
|
7107
|
+
right: Math.max(prior?.right ?? -Infinity, node.left + node.width),
|
|
7108
|
+
bottom: Math.max(prior?.bottom ?? -Infinity, node.top + node.height)
|
|
7109
|
+
});
|
|
7110
|
+
} });
|
|
7111
|
+
const geometry = /* @__PURE__ */ new Map();
|
|
7112
|
+
for (const [id, size] of prepared.sizes) {
|
|
7113
|
+
const viewport = viewports.get(id);
|
|
7114
|
+
const measured = bounds.get(id);
|
|
7115
|
+
if (!viewport || !measured) throw new Error("Could not measure the chart inside CanvasItem.");
|
|
7116
|
+
const width = measured.right - measured.left, height = measured.bottom - measured.top;
|
|
7117
|
+
const scale = Math.min(size.width / width, size.height / height);
|
|
7118
|
+
if (!Number.isFinite(scale) || scale <= 0) throw new Error("CanvasItem charts require positive, finite dimensions.");
|
|
7119
|
+
geometry.set(id, {
|
|
7120
|
+
...size,
|
|
7121
|
+
scale,
|
|
7122
|
+
left: (size.width - width * scale) / 2 - (measured.left - viewport.left) * scale,
|
|
7123
|
+
top: (size.height - height * scale) / 2 - (measured.top - viewport.top) * scale
|
|
7124
|
+
});
|
|
7125
|
+
}
|
|
7126
|
+
const finalViewports = /* @__PURE__ */ new Map();
|
|
7127
|
+
return render(fittedTree(prepared.element, geometry), { ...options, onNodeDetected(node) {
|
|
7128
|
+
const viewport = node.props[VIEWPORT_PROP];
|
|
7129
|
+
if (typeof viewport === "string") finalViewports.set(viewport, node);
|
|
7130
|
+
const id = node.props[SCOPE_PROP];
|
|
7131
|
+
const fit = typeof id === "string" ? geometry.get(id) : void 0;
|
|
7132
|
+
const origin = typeof id === "string" ? finalViewports.get(id) : void 0;
|
|
7133
|
+
if (fit && origin) {
|
|
7134
|
+
const left = origin.left + fit.left, top = origin.top + fit.top;
|
|
7135
|
+
const style = node.props.style ?? {};
|
|
7136
|
+
options.onNodeDetected?.({
|
|
7137
|
+
...node,
|
|
7138
|
+
left: left + (node.left - left) * fit.scale,
|
|
7139
|
+
top: top + (node.top - top) * fit.scale,
|
|
7140
|
+
width: node.width * fit.scale,
|
|
7141
|
+
height: node.height * fit.scale,
|
|
7142
|
+
props: { ...node.props, style: { ...style, ...typeof style.fontSize === "number" ? { fontSize: style.fontSize * fit.scale } : {} } }
|
|
7143
|
+
});
|
|
7144
|
+
} else options.onNodeDetected?.(node);
|
|
7145
|
+
} });
|
|
7146
|
+
}
|
|
7147
|
+
|
|
7148
|
+
// src/primitives/charts.ts
|
|
6656
7149
|
var chartPalette = ["primary", "secondary", "positive", "warning", "info", "accent", "critical"];
|
|
6657
7150
|
function isColorName(value) {
|
|
6658
7151
|
return chartPalette.includes(value) || value === "neutral";
|
|
@@ -6742,7 +7235,7 @@ function chartLabel(key, text, x, y, c, options = {}) {
|
|
|
6742
7235
|
);
|
|
6743
7236
|
transform = void 0;
|
|
6744
7237
|
}
|
|
6745
|
-
return
|
|
7238
|
+
return React11.createElement("div", {
|
|
6746
7239
|
key,
|
|
6747
7240
|
style: {
|
|
6748
7241
|
position: "absolute",
|
|
@@ -6784,7 +7277,10 @@ function pointLabelPlacement(x, y, plot, index, width = 70) {
|
|
|
6784
7277
|
}
|
|
6785
7278
|
};
|
|
6786
7279
|
}
|
|
6787
|
-
function ChartFrame({
|
|
7280
|
+
function ChartFrame(props) {
|
|
7281
|
+
return React11.createElement(ChartFrameContent, props);
|
|
7282
|
+
}
|
|
7283
|
+
function ChartFrameContent({
|
|
6788
7284
|
children,
|
|
6789
7285
|
c,
|
|
6790
7286
|
title,
|
|
@@ -6795,7 +7291,7 @@ function ChartFrame({
|
|
|
6795
7291
|
height,
|
|
6796
7292
|
padding = 16
|
|
6797
7293
|
}) {
|
|
6798
|
-
return
|
|
7294
|
+
return React11.createElement(
|
|
6799
7295
|
"div",
|
|
6800
7296
|
{
|
|
6801
7297
|
style: {
|
|
@@ -6812,20 +7308,20 @@ function ChartFrame({
|
|
|
6812
7308
|
boxShadow: `0 9px 24px ${c.shadow}`
|
|
6813
7309
|
}
|
|
6814
7310
|
},
|
|
6815
|
-
(title || subtitle) &&
|
|
7311
|
+
(title || subtitle) && React11.createElement(
|
|
6816
7312
|
"div",
|
|
6817
7313
|
{
|
|
6818
7314
|
style: { display: "flex", flexDirection: "column", gap: 4, minWidth: 0, maxWidth: "100%" }
|
|
6819
7315
|
},
|
|
6820
|
-
title &&
|
|
7316
|
+
title && React11.createElement("div", {
|
|
6821
7317
|
style: { ...typography.small, ...textFitStyle(), color: c.textPrimary, fontWeight: 900 }
|
|
6822
7318
|
}, title),
|
|
6823
|
-
subtitle &&
|
|
7319
|
+
subtitle && React11.createElement("div", {
|
|
6824
7320
|
style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary, lineHeight: 1.35 }
|
|
6825
7321
|
}, subtitle)
|
|
6826
7322
|
),
|
|
6827
7323
|
children,
|
|
6828
|
-
(legend || footer) &&
|
|
7324
|
+
(legend || footer) && React11.createElement(
|
|
6829
7325
|
"div",
|
|
6830
7326
|
{
|
|
6831
7327
|
style: {
|
|
@@ -6836,18 +7332,18 @@ function ChartFrame({
|
|
|
6836
7332
|
minHeight: 18
|
|
6837
7333
|
}
|
|
6838
7334
|
},
|
|
6839
|
-
legend &&
|
|
7335
|
+
legend && React11.createElement(
|
|
6840
7336
|
"div",
|
|
6841
7337
|
{
|
|
6842
7338
|
style: { display: "flex", alignItems: "center", gap: 12, flexWrap: "wrap", minWidth: 0 }
|
|
6843
7339
|
},
|
|
6844
|
-
...legend.map((item, index) =>
|
|
7340
|
+
...legend.map((item, index) => React11.createElement(
|
|
6845
7341
|
"div",
|
|
6846
7342
|
{
|
|
6847
7343
|
key: `${item.label}-${index}`,
|
|
6848
7344
|
style: { display: "flex", alignItems: "center", gap: 6, minWidth: 0 }
|
|
6849
7345
|
},
|
|
6850
|
-
|
|
7346
|
+
React11.createElement("span", {
|
|
6851
7347
|
style: {
|
|
6852
7348
|
width: 14,
|
|
6853
7349
|
height: 3,
|
|
@@ -6856,17 +7352,18 @@ function ChartFrame({
|
|
|
6856
7352
|
display: "flex"
|
|
6857
7353
|
}
|
|
6858
7354
|
}),
|
|
6859
|
-
|
|
7355
|
+
React11.createElement("span", {
|
|
6860
7356
|
style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary }
|
|
6861
7357
|
}, item.label)
|
|
6862
7358
|
))
|
|
6863
7359
|
),
|
|
6864
|
-
footer &&
|
|
7360
|
+
footer && React11.createElement("div", {
|
|
6865
7361
|
style: { ...typography.tiny, ...textFitStyle("right"), color: c.textMuted }
|
|
6866
7362
|
}, footer)
|
|
6867
7363
|
)
|
|
6868
7364
|
);
|
|
6869
7365
|
}
|
|
7366
|
+
Object.defineProperty(ChartFrameContent, CHART_FRAME_COMPONENT, { value: true });
|
|
6870
7367
|
function polarPoint(cx, cy, radius, angleDegrees) {
|
|
6871
7368
|
const radians = angleDegrees * Math.PI / 180;
|
|
6872
7369
|
return {
|
|
@@ -6890,6 +7387,153 @@ function donutArcPath(cx, cy, outerRadius, innerRadius, startAngle, endAngle) {
|
|
|
6890
7387
|
"Z"
|
|
6891
7388
|
].join(" ");
|
|
6892
7389
|
}
|
|
7390
|
+
function validateNonNegativeSegments(segments, chartName) {
|
|
7391
|
+
let total = 0;
|
|
7392
|
+
for (const segment of segments) {
|
|
7393
|
+
if (!Number.isFinite(segment.value) || segment.value < 0) {
|
|
7394
|
+
throw new RangeError(`${chartName} values must be finite, non-negative numbers.`);
|
|
7395
|
+
}
|
|
7396
|
+
total += segment.value;
|
|
7397
|
+
if (!Number.isFinite(total)) {
|
|
7398
|
+
throw new RangeError(`${chartName} total must be finite.`);
|
|
7399
|
+
}
|
|
7400
|
+
}
|
|
7401
|
+
return total;
|
|
7402
|
+
}
|
|
7403
|
+
function pieSectorPath(cx, cy, radius, startAngle, endAngle) {
|
|
7404
|
+
const span = endAngle - startAngle;
|
|
7405
|
+
const start = polarPoint(cx, cy, radius, startAngle);
|
|
7406
|
+
if (span >= 359.999) {
|
|
7407
|
+
const opposite = polarPoint(cx, cy, radius, startAngle + 180);
|
|
7408
|
+
return [
|
|
7409
|
+
`M ${cx} ${cy}`,
|
|
7410
|
+
`L ${start.x} ${start.y}`,
|
|
7411
|
+
`A ${radius} ${radius} 0 1 1 ${opposite.x} ${opposite.y}`,
|
|
7412
|
+
`A ${radius} ${radius} 0 1 1 ${start.x} ${start.y}`,
|
|
7413
|
+
"Z"
|
|
7414
|
+
].join(" ");
|
|
7415
|
+
}
|
|
7416
|
+
const end = polarPoint(cx, cy, radius, endAngle);
|
|
7417
|
+
const largeArc = span > 180 ? 1 : 0;
|
|
7418
|
+
return `M ${cx} ${cy} L ${start.x} ${start.y} A ${radius} ${radius} 0 ${largeArc} 1 ${end.x} ${end.y} Z`;
|
|
7419
|
+
}
|
|
7420
|
+
function PieChart({
|
|
7421
|
+
segments,
|
|
7422
|
+
c,
|
|
7423
|
+
title,
|
|
7424
|
+
subtitle,
|
|
7425
|
+
width = 360,
|
|
7426
|
+
height = 240,
|
|
7427
|
+
size,
|
|
7428
|
+
format = "decimal",
|
|
7429
|
+
showLegend = true,
|
|
7430
|
+
footer
|
|
7431
|
+
}) {
|
|
7432
|
+
const total = validateNonNegativeSegments(segments, "PieChart");
|
|
7433
|
+
const positiveSegments = segments.filter((segment) => segment.value > 0);
|
|
7434
|
+
const resolvedSize = size ?? Math.min(184, Math.max(132, height - 44), Math.max(132, width * 0.5));
|
|
7435
|
+
const radius = resolvedSize / 2 - 2;
|
|
7436
|
+
const cx = resolvedSize / 2;
|
|
7437
|
+
const cy = resolvedSize / 2;
|
|
7438
|
+
let cursor = -90;
|
|
7439
|
+
const paths = positiveSegments.map((segment, index) => {
|
|
7440
|
+
const span = total > 0 ? segment.value / total * 360 : 0;
|
|
7441
|
+
const start = cursor;
|
|
7442
|
+
const end = index === positiveSegments.length - 1 ? 270 : cursor + span;
|
|
7443
|
+
cursor += span;
|
|
7444
|
+
return React11.createElement("path", {
|
|
7445
|
+
key: `pie-segment-${segment.label}-${index}`,
|
|
7446
|
+
d: pieSectorPath(cx, cy, radius, start, end),
|
|
7447
|
+
fill: chartColor(segment.color, c, index),
|
|
7448
|
+
stroke: c.bgCard,
|
|
7449
|
+
strokeWidth: positiveSegments.length > 1 ? 2 : 0,
|
|
7450
|
+
"data-pie-label": segment.label,
|
|
7451
|
+
"data-pie-value": segment.value,
|
|
7452
|
+
"data-pie-share": total > 0 ? segment.value / total : 0
|
|
7453
|
+
});
|
|
7454
|
+
});
|
|
7455
|
+
const legend = showLegend && positiveSegments.length > 0 && React11.createElement("div", {
|
|
7456
|
+
style: {
|
|
7457
|
+
display: "flex",
|
|
7458
|
+
flexDirection: "column",
|
|
7459
|
+
gap: 8,
|
|
7460
|
+
flex: 1,
|
|
7461
|
+
minWidth: 112
|
|
7462
|
+
}
|
|
7463
|
+
}, ...positiveSegments.map((segment, index) => {
|
|
7464
|
+
const formattedValue = formatChartValue(segment.value, format);
|
|
7465
|
+
const share = formatChartValue(segment.value / total, "percent");
|
|
7466
|
+
const label = segment.valueLabel ?? (format === "percent" ? formattedValue : `${formattedValue} \xB7 ${share}`);
|
|
7467
|
+
return React11.createElement(
|
|
7468
|
+
"div",
|
|
7469
|
+
{
|
|
7470
|
+
key: `pie-legend-${segment.label}-${index}`,
|
|
7471
|
+
style: { display: "flex", alignItems: "center", gap: 8, minWidth: 0 }
|
|
7472
|
+
},
|
|
7473
|
+
React11.createElement("span", {
|
|
7474
|
+
style: {
|
|
7475
|
+
display: "flex",
|
|
7476
|
+
width: 10,
|
|
7477
|
+
height: 10,
|
|
7478
|
+
borderRadius: 3,
|
|
7479
|
+
backgroundColor: chartColor(segment.color, c, index),
|
|
7480
|
+
flexShrink: 0
|
|
7481
|
+
}
|
|
7482
|
+
}),
|
|
7483
|
+
React11.createElement("span", {
|
|
7484
|
+
style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary, flex: 1 }
|
|
7485
|
+
}, segment.label),
|
|
7486
|
+
React11.createElement("span", {
|
|
7487
|
+
style: {
|
|
7488
|
+
...typography.tiny,
|
|
7489
|
+
color: c.textPrimary,
|
|
7490
|
+
fontFamily: "JetBrains Mono",
|
|
7491
|
+
fontWeight: 850,
|
|
7492
|
+
flexShrink: 0
|
|
7493
|
+
}
|
|
7494
|
+
}, label)
|
|
7495
|
+
);
|
|
7496
|
+
}));
|
|
7497
|
+
return ChartFrame({
|
|
7498
|
+
c,
|
|
7499
|
+
title,
|
|
7500
|
+
subtitle,
|
|
7501
|
+
footer,
|
|
7502
|
+
width,
|
|
7503
|
+
children: React11.createElement(
|
|
7504
|
+
"div",
|
|
7505
|
+
{
|
|
7506
|
+
style: {
|
|
7507
|
+
display: "flex",
|
|
7508
|
+
alignItems: "center",
|
|
7509
|
+
justifyContent: showLegend ? "space-between" : "center",
|
|
7510
|
+
gap: 18,
|
|
7511
|
+
minHeight: resolvedSize,
|
|
7512
|
+
width: "100%"
|
|
7513
|
+
}
|
|
7514
|
+
},
|
|
7515
|
+
React11.createElement(
|
|
7516
|
+
"svg",
|
|
7517
|
+
{
|
|
7518
|
+
width: resolvedSize,
|
|
7519
|
+
height: resolvedSize,
|
|
7520
|
+
viewBox: `0 0 ${resolvedSize} ${resolvedSize}`,
|
|
7521
|
+
role: "img",
|
|
7522
|
+
"aria-label": title ?? "Pie chart"
|
|
7523
|
+
},
|
|
7524
|
+
positiveSegments.length === 0 ? React11.createElement("circle", {
|
|
7525
|
+
cx,
|
|
7526
|
+
cy,
|
|
7527
|
+
r: radius,
|
|
7528
|
+
fill: "none",
|
|
7529
|
+
stroke: c.borderLight,
|
|
7530
|
+
strokeWidth: 2
|
|
7531
|
+
}) : paths
|
|
7532
|
+
),
|
|
7533
|
+
legend
|
|
7534
|
+
)
|
|
7535
|
+
});
|
|
7536
|
+
}
|
|
6893
7537
|
function DonutChart({
|
|
6894
7538
|
segments,
|
|
6895
7539
|
c,
|
|
@@ -6922,13 +7566,13 @@ function DonutChart({
|
|
|
6922
7566
|
const end = cursor + rawSpan - gap / 2;
|
|
6923
7567
|
cursor += rawSpan;
|
|
6924
7568
|
if (end <= start) return null;
|
|
6925
|
-
return
|
|
7569
|
+
return React11.createElement("path", {
|
|
6926
7570
|
key: `donut-segment-${segment.label}-${index}`,
|
|
6927
7571
|
d: donutArcPath(cx, cy, outerRadius, innerRadius, start, end),
|
|
6928
7572
|
fill: chartColor(segment.color, c, index)
|
|
6929
7573
|
});
|
|
6930
7574
|
}).filter(Boolean);
|
|
6931
|
-
const legend = showLegend && positiveSegments.length > 0 &&
|
|
7575
|
+
const legend = showLegend && positiveSegments.length > 0 && React11.createElement("div", {
|
|
6932
7576
|
style: {
|
|
6933
7577
|
display: "flex",
|
|
6934
7578
|
flexDirection: "column",
|
|
@@ -6936,7 +7580,7 @@ function DonutChart({
|
|
|
6936
7580
|
flex: 1,
|
|
6937
7581
|
minWidth: 112
|
|
6938
7582
|
}
|
|
6939
|
-
}, ...positiveSegments.map((segment, index) =>
|
|
7583
|
+
}, ...positiveSegments.map((segment, index) => React11.createElement(
|
|
6940
7584
|
"div",
|
|
6941
7585
|
{
|
|
6942
7586
|
key: `donut-legend-${segment.label}-${index}`,
|
|
@@ -6947,7 +7591,7 @@ function DonutChart({
|
|
|
6947
7591
|
minWidth: 0
|
|
6948
7592
|
}
|
|
6949
7593
|
},
|
|
6950
|
-
|
|
7594
|
+
React11.createElement("span", {
|
|
6951
7595
|
style: {
|
|
6952
7596
|
display: "flex",
|
|
6953
7597
|
width: 10,
|
|
@@ -6957,7 +7601,7 @@ function DonutChart({
|
|
|
6957
7601
|
flexShrink: 0
|
|
6958
7602
|
}
|
|
6959
7603
|
}),
|
|
6960
|
-
|
|
7604
|
+
React11.createElement("span", {
|
|
6961
7605
|
style: {
|
|
6962
7606
|
...typography.tiny,
|
|
6963
7607
|
...textFitStyle(),
|
|
@@ -6965,7 +7609,7 @@ function DonutChart({
|
|
|
6965
7609
|
flex: 1
|
|
6966
7610
|
}
|
|
6967
7611
|
}, segment.label),
|
|
6968
|
-
|
|
7612
|
+
React11.createElement("span", {
|
|
6969
7613
|
style: {
|
|
6970
7614
|
...typography.tiny,
|
|
6971
7615
|
color: c.textPrimary,
|
|
@@ -6983,7 +7627,7 @@ function DonutChart({
|
|
|
6983
7627
|
width,
|
|
6984
7628
|
height,
|
|
6985
7629
|
padding: 16,
|
|
6986
|
-
children:
|
|
7630
|
+
children: React11.createElement(
|
|
6987
7631
|
"div",
|
|
6988
7632
|
{
|
|
6989
7633
|
style: {
|
|
@@ -6995,7 +7639,7 @@ function DonutChart({
|
|
|
6995
7639
|
width: "100%"
|
|
6996
7640
|
}
|
|
6997
7641
|
},
|
|
6998
|
-
|
|
7642
|
+
React11.createElement(
|
|
6999
7643
|
"div",
|
|
7000
7644
|
{
|
|
7001
7645
|
style: {
|
|
@@ -7006,14 +7650,14 @@ function DonutChart({
|
|
|
7006
7650
|
flexShrink: 0
|
|
7007
7651
|
}
|
|
7008
7652
|
},
|
|
7009
|
-
|
|
7653
|
+
React11.createElement(
|
|
7010
7654
|
"svg",
|
|
7011
7655
|
{
|
|
7012
7656
|
width: resolvedSize,
|
|
7013
7657
|
height: resolvedSize,
|
|
7014
7658
|
viewBox: `0 0 ${resolvedSize} ${resolvedSize}`
|
|
7015
7659
|
},
|
|
7016
|
-
positiveSegments.length === 0 ?
|
|
7660
|
+
positiveSegments.length === 0 ? React11.createElement("circle", {
|
|
7017
7661
|
cx,
|
|
7018
7662
|
cy,
|
|
7019
7663
|
r: (outerRadius + innerRadius) / 2,
|
|
@@ -7022,7 +7666,7 @@ function DonutChart({
|
|
|
7022
7666
|
strokeWidth: resolvedThickness
|
|
7023
7667
|
}) : paths
|
|
7024
7668
|
),
|
|
7025
|
-
(centerLabel != null || resolvedCenterValue != null) &&
|
|
7669
|
+
(centerLabel != null || resolvedCenterValue != null) && React11.createElement(
|
|
7026
7670
|
"div",
|
|
7027
7671
|
{
|
|
7028
7672
|
style: {
|
|
@@ -7041,7 +7685,7 @@ function DonutChart({
|
|
|
7041
7685
|
textAlign: "center"
|
|
7042
7686
|
}
|
|
7043
7687
|
},
|
|
7044
|
-
resolvedCenterValue != null &&
|
|
7688
|
+
resolvedCenterValue != null && React11.createElement("div", {
|
|
7045
7689
|
style: {
|
|
7046
7690
|
...typography.small,
|
|
7047
7691
|
color: c.textPrimary,
|
|
@@ -7052,7 +7696,7 @@ function DonutChart({
|
|
|
7052
7696
|
...textFitStyle("center")
|
|
7053
7697
|
}
|
|
7054
7698
|
}, resolvedCenterValue),
|
|
7055
|
-
centerLabel != null &&
|
|
7699
|
+
centerLabel != null && React11.createElement("div", {
|
|
7056
7700
|
style: {
|
|
7057
7701
|
...typography.tiny,
|
|
7058
7702
|
color: c.textMuted,
|
|
@@ -7077,7 +7721,7 @@ function StackedBar({
|
|
|
7077
7721
|
}) {
|
|
7078
7722
|
const positiveSegments = segments.filter((segment) => segment.value > 0);
|
|
7079
7723
|
const total = positiveSegments.reduce((sum, segment) => sum + segment.value, 0);
|
|
7080
|
-
return
|
|
7724
|
+
return React11.createElement(
|
|
7081
7725
|
"div",
|
|
7082
7726
|
{
|
|
7083
7727
|
style: {
|
|
@@ -7087,7 +7731,7 @@ function StackedBar({
|
|
|
7087
7731
|
gap: 10
|
|
7088
7732
|
}
|
|
7089
7733
|
},
|
|
7090
|
-
(title || subtitle) &&
|
|
7734
|
+
(title || subtitle) && React11.createElement(
|
|
7091
7735
|
"div",
|
|
7092
7736
|
{
|
|
7093
7737
|
style: {
|
|
@@ -7096,14 +7740,14 @@ function StackedBar({
|
|
|
7096
7740
|
gap: 3
|
|
7097
7741
|
}
|
|
7098
7742
|
},
|
|
7099
|
-
title &&
|
|
7743
|
+
title && React11.createElement("div", {
|
|
7100
7744
|
style: { ...typography.label, color: c.textPrimary, fontWeight: 850 }
|
|
7101
7745
|
}, title),
|
|
7102
|
-
subtitle &&
|
|
7746
|
+
subtitle && React11.createElement("div", {
|
|
7103
7747
|
style: { ...typography.tiny, color: c.textSecondary }
|
|
7104
7748
|
}, subtitle)
|
|
7105
7749
|
),
|
|
7106
|
-
|
|
7750
|
+
React11.createElement(
|
|
7107
7751
|
"div",
|
|
7108
7752
|
{
|
|
7109
7753
|
style: {
|
|
@@ -7121,7 +7765,7 @@ function StackedBar({
|
|
|
7121
7765
|
const share = total > 0 ? segment.value / total : 0;
|
|
7122
7766
|
const segmentWidth = width * share;
|
|
7123
7767
|
const color = chartColor(segment.color, c, index);
|
|
7124
|
-
return
|
|
7768
|
+
return React11.createElement(
|
|
7125
7769
|
"div",
|
|
7126
7770
|
{
|
|
7127
7771
|
key: `${segment.label}-${index}`,
|
|
@@ -7135,7 +7779,7 @@ function StackedBar({
|
|
|
7135
7779
|
...index < positiveSegments.length - 1 ? { borderRight: `2px solid ${c.bgSubtle}` } : {}
|
|
7136
7780
|
}
|
|
7137
7781
|
},
|
|
7138
|
-
segmentWidth >= 64 &&
|
|
7782
|
+
segmentWidth >= 64 && React11.createElement("span", {
|
|
7139
7783
|
style: {
|
|
7140
7784
|
...typography.small,
|
|
7141
7785
|
color: getReadableTextColor(color, c),
|
|
@@ -7146,7 +7790,7 @@ function StackedBar({
|
|
|
7146
7790
|
);
|
|
7147
7791
|
})
|
|
7148
7792
|
),
|
|
7149
|
-
showLegend &&
|
|
7793
|
+
showLegend && React11.createElement(
|
|
7150
7794
|
"div",
|
|
7151
7795
|
{
|
|
7152
7796
|
style: {
|
|
@@ -7158,13 +7802,13 @@ function StackedBar({
|
|
|
7158
7802
|
},
|
|
7159
7803
|
...positiveSegments.map((segment, index) => {
|
|
7160
7804
|
const share = total > 0 ? segment.value / total : 0;
|
|
7161
|
-
return
|
|
7805
|
+
return React11.createElement(
|
|
7162
7806
|
"div",
|
|
7163
7807
|
{
|
|
7164
7808
|
key: `legend-${segment.label}-${index}`,
|
|
7165
7809
|
style: { display: "flex", alignItems: "center", gap: 7 }
|
|
7166
7810
|
},
|
|
7167
|
-
|
|
7811
|
+
React11.createElement("span", {
|
|
7168
7812
|
style: {
|
|
7169
7813
|
width: 12,
|
|
7170
7814
|
height: 12,
|
|
@@ -7173,7 +7817,7 @@ function StackedBar({
|
|
|
7173
7817
|
backgroundColor: chartColor(segment.color, c, index)
|
|
7174
7818
|
}
|
|
7175
7819
|
}),
|
|
7176
|
-
|
|
7820
|
+
React11.createElement("span", {
|
|
7177
7821
|
style: { ...typography.tiny, color: c.textSecondary }
|
|
7178
7822
|
}, `${segment.label} ${segment.valueLabel ?? formatChartValue(share, "percent")}`)
|
|
7179
7823
|
);
|
|
@@ -7219,18 +7863,18 @@ function BarChart({
|
|
|
7219
7863
|
subtitle,
|
|
7220
7864
|
width,
|
|
7221
7865
|
footer,
|
|
7222
|
-
children:
|
|
7866
|
+
children: React11.createElement(
|
|
7223
7867
|
"div",
|
|
7224
7868
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7225
|
-
|
|
7869
|
+
React11.createElement(
|
|
7226
7870
|
"svg",
|
|
7227
7871
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7228
|
-
showGrid &&
|
|
7872
|
+
showGrid && React11.createElement(
|
|
7229
7873
|
"g",
|
|
7230
7874
|
{},
|
|
7231
7875
|
...ticks.map((tick) => {
|
|
7232
7876
|
const y = yInPlot(tick, domain, plot);
|
|
7233
|
-
return
|
|
7877
|
+
return React11.createElement("line", {
|
|
7234
7878
|
key: `tick-${tick}`,
|
|
7235
7879
|
x1: plot.x,
|
|
7236
7880
|
y1: y,
|
|
@@ -7241,10 +7885,10 @@ function BarChart({
|
|
|
7241
7885
|
});
|
|
7242
7886
|
})
|
|
7243
7887
|
),
|
|
7244
|
-
|
|
7245
|
-
|
|
7888
|
+
React11.createElement("line", { x1: plot.x, y1: plot.y, x2: plot.x, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
7889
|
+
React11.createElement("line", { x1: plot.x, y1: baselineY, x2: plot.right, y2: baselineY, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
7246
7890
|
...barGeometries.map(
|
|
7247
|
-
({ item, index, x, y, barHeight, color }) =>
|
|
7891
|
+
({ item, index, x, y, barHeight, color }) => React11.createElement("rect", {
|
|
7248
7892
|
key: `${item.label}-${index}`,
|
|
7249
7893
|
x,
|
|
7250
7894
|
y,
|
|
@@ -7280,6 +7924,186 @@ function BarChart({
|
|
|
7280
7924
|
)
|
|
7281
7925
|
});
|
|
7282
7926
|
}
|
|
7927
|
+
function ParetoBarChart({
|
|
7928
|
+
data,
|
|
7929
|
+
c,
|
|
7930
|
+
title,
|
|
7931
|
+
subtitle,
|
|
7932
|
+
width = 520,
|
|
7933
|
+
height = 300,
|
|
7934
|
+
format = "integer",
|
|
7935
|
+
showGrid = true,
|
|
7936
|
+
showValues = true,
|
|
7937
|
+
footer
|
|
7938
|
+
}) {
|
|
7939
|
+
let total = 0;
|
|
7940
|
+
for (const item of data) {
|
|
7941
|
+
if (!Number.isFinite(item.value) || item.value < 0) {
|
|
7942
|
+
throw new RangeError("ParetoBarChart values must be finite, non-negative numbers.");
|
|
7943
|
+
}
|
|
7944
|
+
total += item.value;
|
|
7945
|
+
if (!Number.isFinite(total)) {
|
|
7946
|
+
throw new RangeError("ParetoBarChart total must be finite.");
|
|
7947
|
+
}
|
|
7948
|
+
}
|
|
7949
|
+
const sorted = data.map((item, index) => ({ item, index })).sort((left, right) => right.item.value - left.item.value || left.index - right.index);
|
|
7950
|
+
const maximum = Math.max(1, ...sorted.map(({ item }) => item.value));
|
|
7951
|
+
const margin = { top: 24, right: 48, bottom: 48, left: 48 };
|
|
7952
|
+
const plot = createPlotArea(width, height, margin);
|
|
7953
|
+
const valueDomain = {
|
|
7954
|
+
min: 0,
|
|
7955
|
+
range: maximum > Number.MAX_VALUE / 1.16 ? maximum : maximum * 1.16
|
|
7956
|
+
};
|
|
7957
|
+
const countTicks = chartTicks(0, maximum, 4);
|
|
7958
|
+
const slot = plot.innerWidth / Math.max(sorted.length, 1);
|
|
7959
|
+
const barWidth = Math.max(6, Math.min(68, slot * 0.68));
|
|
7960
|
+
let accumulated = 0;
|
|
7961
|
+
const bars = sorted.map(({ item, index }, order) => {
|
|
7962
|
+
accumulated += item.value;
|
|
7963
|
+
const cumulative = total === 0 ? 0 : order === sorted.length - 1 ? 1 : accumulated / total;
|
|
7964
|
+
const x = plot.x + order * slot + (slot - barWidth) / 2;
|
|
7965
|
+
const top = yInPlot(item.value, valueDomain, plot);
|
|
7966
|
+
return {
|
|
7967
|
+
item,
|
|
7968
|
+
sourceIndex: index,
|
|
7969
|
+
order,
|
|
7970
|
+
x,
|
|
7971
|
+
y: top,
|
|
7972
|
+
height: Math.max(0, plot.bottom - top),
|
|
7973
|
+
color: chartColor(item.color, c, order),
|
|
7974
|
+
centerX: x + barWidth / 2,
|
|
7975
|
+
cumulative,
|
|
7976
|
+
cumulativeY: plot.bottom - cumulative * plot.innerHeight
|
|
7977
|
+
};
|
|
7978
|
+
});
|
|
7979
|
+
const cumulativePath = bars.map(({ centerX, cumulativeY }, index) => `${index === 0 ? "M" : "L"} ${centerX.toFixed(1)} ${cumulativeY.toFixed(1)}`).join(" ");
|
|
7980
|
+
return ChartFrame({
|
|
7981
|
+
c,
|
|
7982
|
+
title,
|
|
7983
|
+
subtitle,
|
|
7984
|
+
width,
|
|
7985
|
+
footer,
|
|
7986
|
+
children: React11.createElement(
|
|
7987
|
+
"div",
|
|
7988
|
+
{
|
|
7989
|
+
style: { position: "relative", width, height, display: "flex" }
|
|
7990
|
+
},
|
|
7991
|
+
React11.createElement(
|
|
7992
|
+
"svg",
|
|
7993
|
+
{
|
|
7994
|
+
width,
|
|
7995
|
+
height,
|
|
7996
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
7997
|
+
role: "img",
|
|
7998
|
+
"aria-label": title ?? "Pareto bar chart"
|
|
7999
|
+
},
|
|
8000
|
+
showGrid && React11.createElement(
|
|
8001
|
+
"g",
|
|
8002
|
+
{},
|
|
8003
|
+
...countTicks.map((tick) => {
|
|
8004
|
+
const y = yInPlot(tick, valueDomain, plot);
|
|
8005
|
+
return React11.createElement("line", {
|
|
8006
|
+
key: `pareto-count-grid-${tick}`,
|
|
8007
|
+
x1: plot.x,
|
|
8008
|
+
y1: y,
|
|
8009
|
+
x2: plot.right,
|
|
8010
|
+
y2: y,
|
|
8011
|
+
stroke: c.borderSubtle,
|
|
8012
|
+
strokeWidth: 1
|
|
8013
|
+
});
|
|
8014
|
+
})
|
|
8015
|
+
),
|
|
8016
|
+
React11.createElement("line", {
|
|
8017
|
+
x1: plot.x,
|
|
8018
|
+
y1: plot.bottom,
|
|
8019
|
+
x2: plot.right,
|
|
8020
|
+
y2: plot.bottom,
|
|
8021
|
+
stroke: c.borderLight,
|
|
8022
|
+
strokeWidth: 1.2
|
|
8023
|
+
}),
|
|
8024
|
+
React11.createElement("line", {
|
|
8025
|
+
x1: plot.right,
|
|
8026
|
+
y1: plot.y,
|
|
8027
|
+
x2: plot.right,
|
|
8028
|
+
y2: plot.bottom,
|
|
8029
|
+
stroke: c.borderLight,
|
|
8030
|
+
strokeWidth: 1.2
|
|
8031
|
+
}),
|
|
8032
|
+
...bars.map(({ item, order, x, y, height: barHeight, color }) => React11.createElement("rect", {
|
|
8033
|
+
key: `pareto-bar-${item.label}-${order}`,
|
|
8034
|
+
x,
|
|
8035
|
+
y,
|
|
8036
|
+
width: barWidth,
|
|
8037
|
+
height: barHeight,
|
|
8038
|
+
rx: 4,
|
|
8039
|
+
fill: color,
|
|
8040
|
+
opacity: 0.86,
|
|
8041
|
+
"data-pareto-bar": item.label,
|
|
8042
|
+
"data-pareto-value": item.value,
|
|
8043
|
+
"data-pareto-order": order
|
|
8044
|
+
})),
|
|
8045
|
+
cumulativePath && React11.createElement("path", {
|
|
8046
|
+
d: cumulativePath,
|
|
8047
|
+
fill: "none",
|
|
8048
|
+
stroke: chartColor("critical", c),
|
|
8049
|
+
strokeWidth: 3,
|
|
8050
|
+
strokeLinecap: "round",
|
|
8051
|
+
strokeLinejoin: "round",
|
|
8052
|
+
"data-pareto-cumulative-line": true
|
|
8053
|
+
}),
|
|
8054
|
+
...bars.map(({ item, sourceIndex, centerX, cumulativeY, cumulative, order }) => React11.createElement("circle", {
|
|
8055
|
+
key: `pareto-cumulative-point-${order}`,
|
|
8056
|
+
cx: centerX,
|
|
8057
|
+
cy: cumulativeY,
|
|
8058
|
+
r: 4,
|
|
8059
|
+
fill: chartColor("critical", c),
|
|
8060
|
+
stroke: c.bgCard,
|
|
8061
|
+
strokeWidth: 2,
|
|
8062
|
+
"data-pareto-category": item.label,
|
|
8063
|
+
"data-pareto-source-index": sourceIndex,
|
|
8064
|
+
"data-pareto-cumulative-percent": cumulative * 100
|
|
8065
|
+
}))
|
|
8066
|
+
),
|
|
8067
|
+
...countTicks.map((tick) => chartLabel(
|
|
8068
|
+
`pareto-count-label-${tick}`,
|
|
8069
|
+
formatChartValue(tick, format),
|
|
8070
|
+
plot.x - 7,
|
|
8071
|
+
yInPlot(tick, valueDomain, plot),
|
|
8072
|
+
c,
|
|
8073
|
+
{ align: "right", width: 36 }
|
|
8074
|
+
)),
|
|
8075
|
+
...[0, 0.5, 1].map((share) => chartLabel(
|
|
8076
|
+
`pareto-percent-label-${share}`,
|
|
8077
|
+
`${Math.round(share * 100)}%`,
|
|
8078
|
+
plot.right + 7,
|
|
8079
|
+
plot.bottom - share * plot.innerHeight,
|
|
8080
|
+
c,
|
|
8081
|
+
{ align: "left", width: 38 }
|
|
8082
|
+
)),
|
|
8083
|
+
...bars.flatMap(({ item, order, centerX, y }) => [
|
|
8084
|
+
...showValues ? [chartLabel(
|
|
8085
|
+
`pareto-value-${order}`,
|
|
8086
|
+
item.valueLabel ?? formatChartValue(item.value, format),
|
|
8087
|
+
centerX,
|
|
8088
|
+
clamp(y - 8, plot.y + 8, plot.bottom - 12),
|
|
8089
|
+
c,
|
|
8090
|
+
{ color: c.textPrimary, fontWeight: 800, width: Math.min(slot, 64), bounds: { x: plot.x, y: plot.y, width: plot.innerWidth, height: plot.innerHeight } }
|
|
8091
|
+
)] : [],
|
|
8092
|
+
chartLabel(
|
|
8093
|
+
`pareto-category-${order}`,
|
|
8094
|
+
item.label,
|
|
8095
|
+
centerX,
|
|
8096
|
+
height - 17,
|
|
8097
|
+
c,
|
|
8098
|
+
{
|
|
8099
|
+
width: Math.max(1, Math.min(96, slot - 2)),
|
|
8100
|
+
bounds: { x: plot.x, y: plot.bottom + 1, width: plot.innerWidth, height: Math.max(1, height - plot.bottom - 2), padding: 0 }
|
|
8101
|
+
}
|
|
8102
|
+
)
|
|
8103
|
+
])
|
|
8104
|
+
)
|
|
8105
|
+
});
|
|
8106
|
+
}
|
|
7283
8107
|
function LineChart({
|
|
7284
8108
|
series,
|
|
7285
8109
|
c,
|
|
@@ -7323,18 +8147,18 @@ function LineChart({
|
|
|
7323
8147
|
width,
|
|
7324
8148
|
footer,
|
|
7325
8149
|
legend: series.map((item, index) => ({ label: item.name, color: item.color ?? chartPalette[index % chartPalette.length] })),
|
|
7326
|
-
children:
|
|
8150
|
+
children: React11.createElement(
|
|
7327
8151
|
"div",
|
|
7328
8152
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7329
|
-
|
|
8153
|
+
React11.createElement(
|
|
7330
8154
|
"svg",
|
|
7331
8155
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7332
|
-
showGrid &&
|
|
8156
|
+
showGrid && React11.createElement(
|
|
7333
8157
|
"g",
|
|
7334
8158
|
{},
|
|
7335
8159
|
...ticks.map((tick) => {
|
|
7336
8160
|
const y = yInPlot(tick, domain, plot);
|
|
7337
|
-
return
|
|
8161
|
+
return React11.createElement("line", {
|
|
7338
8162
|
key: `line-tick-${tick}`,
|
|
7339
8163
|
x1: plot.x,
|
|
7340
8164
|
y1: y,
|
|
@@ -7345,8 +8169,8 @@ function LineChart({
|
|
|
7345
8169
|
});
|
|
7346
8170
|
})
|
|
7347
8171
|
),
|
|
7348
|
-
|
|
7349
|
-
|
|
8172
|
+
React11.createElement("line", { x1: plot.x, y1: plot.y, x2: plot.x, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
8173
|
+
React11.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
7350
8174
|
...series.flatMap((item, seriesIndex) => {
|
|
7351
8175
|
if (item.points.length === 0) return [];
|
|
7352
8176
|
const color = chartColor(item.color, c, seriesIndex);
|
|
@@ -7359,9 +8183,9 @@ function LineChart({
|
|
|
7359
8183
|
}
|
|
7360
8184
|
const elements = [];
|
|
7361
8185
|
if (areaPath) {
|
|
7362
|
-
elements.push(
|
|
8186
|
+
elements.push(React11.createElement("path", { key: `${item.name}-area`, d: areaPath, fill: color, opacity: 0.12 }));
|
|
7363
8187
|
}
|
|
7364
|
-
elements.push(
|
|
8188
|
+
elements.push(React11.createElement("path", {
|
|
7365
8189
|
key: `${item.name}-line`,
|
|
7366
8190
|
d: linePath,
|
|
7367
8191
|
fill: "none",
|
|
@@ -7373,7 +8197,7 @@ function LineChart({
|
|
|
7373
8197
|
if (showPoints) {
|
|
7374
8198
|
elements.push(...item.points.map((value, index) => {
|
|
7375
8199
|
const point = pointFor(value, index);
|
|
7376
|
-
return
|
|
8200
|
+
return React11.createElement("circle", {
|
|
7377
8201
|
key: `${item.name}-point-${index}`,
|
|
7378
8202
|
cx: point.x,
|
|
7379
8203
|
cy: point.y,
|
|
@@ -7404,9 +8228,15 @@ function LineChart({
|
|
|
7404
8228
|
)
|
|
7405
8229
|
});
|
|
7406
8230
|
}
|
|
8231
|
+
for (const chart of [PieChart, DonutChart, StackedBar, BarChart, ParetoBarChart, LineChart]) {
|
|
8232
|
+
Object.defineProperty(chart, CANVAS_CHART_COMPONENT, { value: true });
|
|
8233
|
+
}
|
|
7407
8234
|
|
|
7408
8235
|
// src/primitives/plots.ts
|
|
7409
|
-
import
|
|
8236
|
+
import React12 from "react";
|
|
8237
|
+
for (const chart of [ScatterPlot, ParetoChart, QuadrantChart, IntervalPlot]) {
|
|
8238
|
+
Object.defineProperty(chart, CANVAS_CHART_COMPONENT, { value: true });
|
|
8239
|
+
}
|
|
7410
8240
|
function xTickLabelAlign(index, count) {
|
|
7411
8241
|
if (index === 0) return "left";
|
|
7412
8242
|
if (index === count - 1) return "right";
|
|
@@ -7450,18 +8280,18 @@ function ScatterPlot({
|
|
|
7450
8280
|
subtitle,
|
|
7451
8281
|
width,
|
|
7452
8282
|
footer,
|
|
7453
|
-
children:
|
|
8283
|
+
children: React12.createElement(
|
|
7454
8284
|
"div",
|
|
7455
8285
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7456
|
-
|
|
8286
|
+
React12.createElement(
|
|
7457
8287
|
"svg",
|
|
7458
8288
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7459
|
-
showGrid &&
|
|
8289
|
+
showGrid && React12.createElement(
|
|
7460
8290
|
"g",
|
|
7461
8291
|
{},
|
|
7462
8292
|
...xTicks.map((tick) => {
|
|
7463
8293
|
const x = xInPlot(tick, xDomain, plot);
|
|
7464
|
-
return
|
|
8294
|
+
return React12.createElement("line", {
|
|
7465
8295
|
key: `x-tick-${tick}`,
|
|
7466
8296
|
x1: x,
|
|
7467
8297
|
y1: plot.y,
|
|
@@ -7473,7 +8303,7 @@ function ScatterPlot({
|
|
|
7473
8303
|
}),
|
|
7474
8304
|
...yTicks.map((tick) => {
|
|
7475
8305
|
const y = yInPlot(tick, yDomain, plot);
|
|
7476
|
-
return
|
|
8306
|
+
return React12.createElement("line", {
|
|
7477
8307
|
key: `y-tick-${tick}`,
|
|
7478
8308
|
x1: plot.x,
|
|
7479
8309
|
y1: y,
|
|
@@ -7484,9 +8314,9 @@ function ScatterPlot({
|
|
|
7484
8314
|
});
|
|
7485
8315
|
})
|
|
7486
8316
|
),
|
|
7487
|
-
|
|
8317
|
+
React12.createElement("rect", { x: plot.x, y: plot.y, width: plot.innerWidth, height: plot.innerHeight, fill: "transparent", stroke: c.borderLight, strokeWidth: 1.2, rx: 6 }),
|
|
7488
8318
|
...pointGeometries.map(
|
|
7489
|
-
({ item, index, point, color }) =>
|
|
8319
|
+
({ item, index, point, color }) => React12.createElement("circle", {
|
|
7490
8320
|
key: `${item.label ?? "point"}-${index}`,
|
|
7491
8321
|
cx: point.x,
|
|
7492
8322
|
cy: point.y,
|
|
@@ -7637,18 +8467,18 @@ function ParetoChart({
|
|
|
7637
8467
|
{ label: "Pareto frontier", color: frontier },
|
|
7638
8468
|
{ label: "dominated", color: "neutral" }
|
|
7639
8469
|
],
|
|
7640
|
-
children:
|
|
8470
|
+
children: React12.createElement(
|
|
7641
8471
|
"div",
|
|
7642
8472
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7643
|
-
|
|
8473
|
+
React12.createElement(
|
|
7644
8474
|
"svg",
|
|
7645
8475
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7646
|
-
showGrid &&
|
|
8476
|
+
showGrid && React12.createElement(
|
|
7647
8477
|
"g",
|
|
7648
8478
|
{},
|
|
7649
8479
|
...xTicks.map((tick) => {
|
|
7650
8480
|
const x = pointFor(tick, yDomain.min).x;
|
|
7651
|
-
return
|
|
8481
|
+
return React12.createElement("line", {
|
|
7652
8482
|
key: `pareto-x-grid-${tick}`,
|
|
7653
8483
|
x1: x,
|
|
7654
8484
|
y1: plot.y,
|
|
@@ -7660,7 +8490,7 @@ function ParetoChart({
|
|
|
7660
8490
|
}),
|
|
7661
8491
|
...yTicks.map((tick) => {
|
|
7662
8492
|
const y = yInPlot(tick, yDomain, plot);
|
|
7663
|
-
return
|
|
8493
|
+
return React12.createElement("line", {
|
|
7664
8494
|
key: `pareto-y-grid-${tick}`,
|
|
7665
8495
|
x1: plot.x,
|
|
7666
8496
|
y1: y,
|
|
@@ -7671,7 +8501,7 @@ function ParetoChart({
|
|
|
7671
8501
|
});
|
|
7672
8502
|
})
|
|
7673
8503
|
),
|
|
7674
|
-
|
|
8504
|
+
React12.createElement("rect", {
|
|
7675
8505
|
x: plot.x,
|
|
7676
8506
|
y: plot.y,
|
|
7677
8507
|
width: plot.innerWidth,
|
|
@@ -7681,17 +8511,17 @@ function ParetoChart({
|
|
|
7681
8511
|
strokeWidth: 1.2,
|
|
7682
8512
|
rx: 6
|
|
7683
8513
|
}),
|
|
7684
|
-
showGoal &&
|
|
8514
|
+
showGoal && React12.createElement(
|
|
7685
8515
|
"g",
|
|
7686
8516
|
{ "data-pareto-goal": true, stroke: frontier, fill: "none", strokeWidth: 2, strokeLinecap: "round" },
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
8517
|
+
React12.createElement("line", { x1: goalXStart, y1: goalY, x2: goalXEnd, y2: goalY }),
|
|
8518
|
+
React12.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY - arrowSize }),
|
|
8519
|
+
React12.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY + arrowSize }),
|
|
8520
|
+
React12.createElement("line", { x1: goalXStart, y1: goalYStart, x2: goalXStart, y2: goalYEnd }),
|
|
8521
|
+
React12.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart - arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) }),
|
|
8522
|
+
React12.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart + arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) })
|
|
7693
8523
|
),
|
|
7694
|
-
frontierPath &&
|
|
8524
|
+
frontierPath && React12.createElement("path", {
|
|
7695
8525
|
"data-pareto-frontier": true,
|
|
7696
8526
|
d: frontierPath,
|
|
7697
8527
|
fill: "none",
|
|
@@ -7700,7 +8530,7 @@ function ParetoChart({
|
|
|
7700
8530
|
strokeLinecap: "round",
|
|
7701
8531
|
strokeLinejoin: "round"
|
|
7702
8532
|
}),
|
|
7703
|
-
...pointGeometries.filter((geometry) => !geometry.frontier).concat(pointGeometries.filter((geometry) => geometry.frontier)).map(({ point, index, x, y, color, frontier: isFrontier }) =>
|
|
8533
|
+
...pointGeometries.filter((geometry) => !geometry.frontier).concat(pointGeometries.filter((geometry) => geometry.frontier)).map(({ point, index, x, y, color, frontier: isFrontier }) => React12.createElement("circle", {
|
|
7704
8534
|
key: `pareto-point-${point.label ?? "point"}-${index}`,
|
|
7705
8535
|
"data-pareto-status": isFrontier ? "frontier" : "dominated",
|
|
7706
8536
|
cx: x,
|
|
@@ -7812,18 +8642,18 @@ function QuadrantChart({
|
|
|
7812
8642
|
subtitle,
|
|
7813
8643
|
width,
|
|
7814
8644
|
footer,
|
|
7815
|
-
children:
|
|
8645
|
+
children: React12.createElement(
|
|
7816
8646
|
"div",
|
|
7817
8647
|
{
|
|
7818
8648
|
style: { position: "relative", width, height, display: "flex" }
|
|
7819
8649
|
},
|
|
7820
|
-
|
|
8650
|
+
React12.createElement(
|
|
7821
8651
|
"svg",
|
|
7822
8652
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7823
8653
|
...regionEntries.map(({ key, region, x, y, width: regionWidth, height: regionHeight }, index) => {
|
|
7824
8654
|
const color = chartColor(region.color, c, index);
|
|
7825
8655
|
const emphasized = region.emphasis === true;
|
|
7826
|
-
return
|
|
8656
|
+
return React12.createElement("rect", {
|
|
7827
8657
|
key: `quadrant-${key}`,
|
|
7828
8658
|
x,
|
|
7829
8659
|
y,
|
|
@@ -7835,12 +8665,12 @@ function QuadrantChart({
|
|
|
7835
8665
|
strokeWidth: emphasized ? 2 : 0
|
|
7836
8666
|
});
|
|
7837
8667
|
}),
|
|
7838
|
-
showGrid &&
|
|
8668
|
+
showGrid && React12.createElement(
|
|
7839
8669
|
"g",
|
|
7840
8670
|
{},
|
|
7841
8671
|
...xTicks.map((tick) => {
|
|
7842
8672
|
const x = xInPlot(tick, xDomain, plot);
|
|
7843
|
-
return
|
|
8673
|
+
return React12.createElement("line", {
|
|
7844
8674
|
key: `quadrant-x-grid-${tick}`,
|
|
7845
8675
|
x1: x,
|
|
7846
8676
|
y1: plot.y,
|
|
@@ -7852,7 +8682,7 @@ function QuadrantChart({
|
|
|
7852
8682
|
}),
|
|
7853
8683
|
...yTicks.map((tick) => {
|
|
7854
8684
|
const y = yInPlot(tick, yDomain, plot);
|
|
7855
|
-
return
|
|
8685
|
+
return React12.createElement("line", {
|
|
7856
8686
|
key: `quadrant-y-grid-${tick}`,
|
|
7857
8687
|
x1: plot.x,
|
|
7858
8688
|
y1: y,
|
|
@@ -7863,7 +8693,7 @@ function QuadrantChart({
|
|
|
7863
8693
|
});
|
|
7864
8694
|
})
|
|
7865
8695
|
),
|
|
7866
|
-
|
|
8696
|
+
React12.createElement("rect", {
|
|
7867
8697
|
x: plot.x,
|
|
7868
8698
|
y: plot.y,
|
|
7869
8699
|
width: plot.innerWidth,
|
|
@@ -7873,7 +8703,7 @@ function QuadrantChart({
|
|
|
7873
8703
|
strokeWidth: 1.2,
|
|
7874
8704
|
rx: 8
|
|
7875
8705
|
}),
|
|
7876
|
-
|
|
8706
|
+
React12.createElement("line", {
|
|
7877
8707
|
x1: midX,
|
|
7878
8708
|
y1: plot.y,
|
|
7879
8709
|
x2: midX,
|
|
@@ -7881,7 +8711,7 @@ function QuadrantChart({
|
|
|
7881
8711
|
stroke: c.borderLight,
|
|
7882
8712
|
strokeWidth: 1.4
|
|
7883
8713
|
}),
|
|
7884
|
-
|
|
8714
|
+
React12.createElement("line", {
|
|
7885
8715
|
x1: plot.x,
|
|
7886
8716
|
y1: midY,
|
|
7887
8717
|
x2: plot.right,
|
|
@@ -7891,7 +8721,7 @@ function QuadrantChart({
|
|
|
7891
8721
|
}),
|
|
7892
8722
|
...(showTicks ? xTicks : []).map((tick) => {
|
|
7893
8723
|
const x = xInPlot(tick, xDomain, plot);
|
|
7894
|
-
return
|
|
8724
|
+
return React12.createElement("line", {
|
|
7895
8725
|
key: `quadrant-x-tick-${tick}`,
|
|
7896
8726
|
x1: x,
|
|
7897
8727
|
y1: plot.bottom,
|
|
@@ -7903,7 +8733,7 @@ function QuadrantChart({
|
|
|
7903
8733
|
}),
|
|
7904
8734
|
...(showTicks ? yTicks : []).map((tick) => {
|
|
7905
8735
|
const y = yInPlot(tick, yDomain, plot);
|
|
7906
|
-
return
|
|
8736
|
+
return React12.createElement("line", {
|
|
7907
8737
|
key: `quadrant-y-tick-${tick}`,
|
|
7908
8738
|
x1: plot.x - 5,
|
|
7909
8739
|
y1: y,
|
|
@@ -7913,7 +8743,7 @@ function QuadrantChart({
|
|
|
7913
8743
|
strokeWidth: 1.2
|
|
7914
8744
|
});
|
|
7915
8745
|
}),
|
|
7916
|
-
...pointGeometries.map(({ point, index, x, y, color }) =>
|
|
8746
|
+
...pointGeometries.map(({ point, index, x, y, color }) => React12.createElement("circle", {
|
|
7917
8747
|
key: `quadrant-point-${point.label ?? index}`,
|
|
7918
8748
|
cx: x,
|
|
7919
8749
|
cy: y,
|
|
@@ -8015,15 +8845,15 @@ function IntervalPlot({
|
|
|
8015
8845
|
subtitle,
|
|
8016
8846
|
width,
|
|
8017
8847
|
footer,
|
|
8018
|
-
children:
|
|
8848
|
+
children: React12.createElement(
|
|
8019
8849
|
"div",
|
|
8020
8850
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
8021
|
-
|
|
8851
|
+
React12.createElement(
|
|
8022
8852
|
"svg",
|
|
8023
8853
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
8024
8854
|
...ticks.map((tick) => {
|
|
8025
8855
|
const x = scaleX(tick);
|
|
8026
|
-
return
|
|
8856
|
+
return React12.createElement("line", {
|
|
8027
8857
|
key: `interval-tick-${tick}`,
|
|
8028
8858
|
x1: x,
|
|
8029
8859
|
y1: plot.y,
|
|
@@ -8033,10 +8863,10 @@ function IntervalPlot({
|
|
|
8033
8863
|
strokeWidth: 1
|
|
8034
8864
|
});
|
|
8035
8865
|
}),
|
|
8036
|
-
|
|
8866
|
+
React12.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
8037
8867
|
...rows.flatMap(({ item, index, y, color, lowX, midX, highX }) => [
|
|
8038
|
-
|
|
8039
|
-
|
|
8868
|
+
React12.createElement("line", { key: `${item.label}-range-${index}`, x1: lowX, y1: y, x2: highX, y2: y, stroke: color, strokeWidth: 9, strokeLinecap: "round", opacity: 0.9 }),
|
|
8869
|
+
React12.createElement("circle", { key: `${item.label}-mid-${index}`, cx: midX, cy: y, r: 10, fill: c.bgCard, stroke: color, strokeWidth: 4 })
|
|
8040
8870
|
])
|
|
8041
8871
|
),
|
|
8042
8872
|
...ticks.map((tick, index) => {
|
|
@@ -8073,7 +8903,7 @@ function IntervalPlot({
|
|
|
8073
8903
|
}
|
|
8074
8904
|
function Badge({ label, c, color = "primary" }) {
|
|
8075
8905
|
const solidColor = getReadableColor(color, c);
|
|
8076
|
-
return
|
|
8906
|
+
return React12.createElement("div", {
|
|
8077
8907
|
style: {
|
|
8078
8908
|
display: "flex",
|
|
8079
8909
|
alignItems: "center",
|
|
@@ -8094,7 +8924,7 @@ function DotPoint({ x, y, label, color, c, size = 12, labelOffset }) {
|
|
|
8094
8924
|
const offY = labelOffset?.y ?? -22;
|
|
8095
8925
|
return [
|
|
8096
8926
|
// Dot
|
|
8097
|
-
|
|
8927
|
+
React12.createElement("div", {
|
|
8098
8928
|
key: `dot-${label}`,
|
|
8099
8929
|
style: {
|
|
8100
8930
|
position: "absolute",
|
|
@@ -8109,7 +8939,7 @@ function DotPoint({ x, y, label, color, c, size = 12, labelOffset }) {
|
|
|
8109
8939
|
}
|
|
8110
8940
|
}),
|
|
8111
8941
|
// Label
|
|
8112
|
-
|
|
8942
|
+
React12.createElement("div", {
|
|
8113
8943
|
key: `label-${label}`,
|
|
8114
8944
|
style: {
|
|
8115
8945
|
position: "absolute",
|
|
@@ -8135,7 +8965,7 @@ function DashedLine({ x1, y1, x2, y2, color, dotSpacing = 8, dotSize = 2 }) {
|
|
|
8135
8965
|
if (i % 2 === 1) continue;
|
|
8136
8966
|
const t = i / numDots;
|
|
8137
8967
|
dots.push(
|
|
8138
|
-
|
|
8968
|
+
React12.createElement("div", {
|
|
8139
8969
|
key: `dash-${i}`,
|
|
8140
8970
|
style: {
|
|
8141
8971
|
position: "absolute",
|
|
@@ -8152,7 +8982,7 @@ function DashedLine({ x1, y1, x2, y2, color, dotSpacing = 8, dotSize = 2 }) {
|
|
|
8152
8982
|
return dots;
|
|
8153
8983
|
}
|
|
8154
8984
|
function Legend({ items, c, title }) {
|
|
8155
|
-
return
|
|
8985
|
+
return React12.createElement(
|
|
8156
8986
|
"div",
|
|
8157
8987
|
{
|
|
8158
8988
|
style: {
|
|
@@ -8165,7 +8995,7 @@ function Legend({ items, c, title }) {
|
|
|
8165
8995
|
padding: "14px 16px"
|
|
8166
8996
|
}
|
|
8167
8997
|
},
|
|
8168
|
-
title &&
|
|
8998
|
+
title && React12.createElement("div", {
|
|
8169
8999
|
style: {
|
|
8170
9000
|
fontSize: 11,
|
|
8171
9001
|
fontWeight: 700,
|
|
@@ -8176,13 +9006,13 @@ function Legend({ items, c, title }) {
|
|
|
8176
9006
|
}
|
|
8177
9007
|
}, title),
|
|
8178
9008
|
...items.map(
|
|
8179
|
-
(item, i) =>
|
|
9009
|
+
(item, i) => React12.createElement(
|
|
8180
9010
|
"div",
|
|
8181
9011
|
{
|
|
8182
9012
|
key: `legend-${i}`,
|
|
8183
9013
|
style: { display: "flex", alignItems: "center", gap: 8 }
|
|
8184
9014
|
},
|
|
8185
|
-
|
|
9015
|
+
React12.createElement("div", {
|
|
8186
9016
|
style: {
|
|
8187
9017
|
width: 16,
|
|
8188
9018
|
height: item.style === "dashed" ? 0 : 2,
|
|
@@ -8192,7 +9022,7 @@ function Legend({ items, c, title }) {
|
|
|
8192
9022
|
} : {}
|
|
8193
9023
|
}
|
|
8194
9024
|
}),
|
|
8195
|
-
|
|
9025
|
+
React12.createElement("div", {
|
|
8196
9026
|
style: {
|
|
8197
9027
|
fontSize: 11,
|
|
8198
9028
|
color: c.textMuted,
|
|
@@ -8204,6 +9034,45 @@ function Legend({ items, c, title }) {
|
|
|
8204
9034
|
);
|
|
8205
9035
|
}
|
|
8206
9036
|
|
|
9037
|
+
// src/primitives/board.ts
|
|
9038
|
+
import React13 from "react";
|
|
9039
|
+
var CANVAS_ITEM_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.canvas-item");
|
|
9040
|
+
function dimension(value, name) {
|
|
9041
|
+
if (value !== void 0 && (!Number.isFinite(value) || value <= 0 || value > 8192)) {
|
|
9042
|
+
throw new Error(`${name} must be a finite number greater than 0 and at most 8192.`);
|
|
9043
|
+
}
|
|
9044
|
+
return value;
|
|
9045
|
+
}
|
|
9046
|
+
function Board({ children, c, width = 960, height = 540, background }) {
|
|
9047
|
+
return React13.createElement("div", { style: {
|
|
9048
|
+
display: "flex",
|
|
9049
|
+
position: "relative",
|
|
9050
|
+
width: dimension(width, "Board width"),
|
|
9051
|
+
height: dimension(height, "Board height"),
|
|
9052
|
+
overflow: "hidden",
|
|
9053
|
+
backgroundColor: background ?? "transparent",
|
|
9054
|
+
color: c.textPrimary
|
|
9055
|
+
} }, children);
|
|
9056
|
+
}
|
|
9057
|
+
function CanvasItem({ children, x, y, width, height }) {
|
|
9058
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) throw new Error("CanvasItem x and y must be finite numbers.");
|
|
9059
|
+
const sizedChildren = React13.Children.map(children, (child) => {
|
|
9060
|
+
if (!React13.isValidElement(child)) return child;
|
|
9061
|
+
const sized = React13.cloneElement(child, { ...width !== void 0 ? { width } : {}, ...height !== void 0 ? { height } : {} });
|
|
9062
|
+
return width !== void 0 && height !== void 0 && isCanvasChart(child.type) ? React13.createElement(CanvasChartFit, { width, height, __vizmaticTextScope: child.props.__vizmaticTextScope }, sized) : sized;
|
|
9063
|
+
});
|
|
9064
|
+
return React13.createElement("div", { style: {
|
|
9065
|
+
display: "flex",
|
|
9066
|
+
position: "absolute",
|
|
9067
|
+
left: x,
|
|
9068
|
+
top: y,
|
|
9069
|
+
width: dimension(width, "CanvasItem width"),
|
|
9070
|
+
height: dimension(height, "CanvasItem height"),
|
|
9071
|
+
alignItems: "stretch"
|
|
9072
|
+
} }, sizedChildren);
|
|
9073
|
+
}
|
|
9074
|
+
Object.defineProperty(CanvasItem, CANVAS_ITEM_COMPONENT, { value: true });
|
|
9075
|
+
|
|
8207
9076
|
// src/render.ts
|
|
8208
9077
|
import { Resvg } from "@resvg/resvg-js";
|
|
8209
9078
|
import { homedir } from "os";
|
|
@@ -8214,12 +9083,12 @@ import { fileURLToPath } from "url";
|
|
|
8214
9083
|
import { brotliDecompressSync } from "zlib";
|
|
8215
9084
|
|
|
8216
9085
|
// src/brand.ts
|
|
8217
|
-
import
|
|
9086
|
+
import React14 from "react";
|
|
8218
9087
|
var DEFAULT_WATERMARK_TEXT = "Vizmatic";
|
|
8219
9088
|
var WATERMARK_COLOR_DARK = "#a78bfa";
|
|
8220
9089
|
var WATERMARK_COLOR_LIGHT = "#7c3aed";
|
|
8221
9090
|
function VizmaticIcon({ size = 14, color }) {
|
|
8222
|
-
return
|
|
9091
|
+
return React14.createElement(
|
|
8223
9092
|
"svg",
|
|
8224
9093
|
{
|
|
8225
9094
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -8228,19 +9097,19 @@ function VizmaticIcon({ size = 14, color }) {
|
|
|
8228
9097
|
viewBox: "0 0 28 28",
|
|
8229
9098
|
fill: "none"
|
|
8230
9099
|
},
|
|
8231
|
-
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
9100
|
+
React14.createElement("rect", { x: 2.5, y: 2.5, width: 23, height: 23, rx: 6.5, stroke: color, strokeWidth: 2, opacity: 0.54 }),
|
|
9101
|
+
React14.createElement("rect", { x: 7, y: 7, width: 5.5, height: 5.5, rx: 1.8, fill: color, opacity: 0.35 }),
|
|
9102
|
+
React14.createElement("rect", { x: 15.5, y: 7, width: 5.5, height: 5.5, rx: 1.8, fill: color }),
|
|
9103
|
+
React14.createElement("rect", { x: 7, y: 15.5, width: 5.5, height: 5.5, rx: 1.8, fill: color, opacity: 0.82 }),
|
|
9104
|
+
React14.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 }),
|
|
9105
|
+
React14.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 })
|
|
8237
9106
|
);
|
|
8238
9107
|
}
|
|
8239
9108
|
function normalizeWatermark(watermark) {
|
|
8240
9109
|
if (watermark == null || watermark === false) return void 0;
|
|
8241
9110
|
if (watermark === true) return {};
|
|
8242
9111
|
if (typeof watermark === "string") return { text: watermark };
|
|
8243
|
-
if (
|
|
9112
|
+
if (React14.isValidElement(watermark)) {
|
|
8244
9113
|
if (watermark.type !== Watermark) return { element: watermark };
|
|
8245
9114
|
const { children, ...props } = watermark.props;
|
|
8246
9115
|
return {
|
|
@@ -8269,7 +9138,7 @@ function positionStyle(position) {
|
|
|
8269
9138
|
function imageNode(image) {
|
|
8270
9139
|
if (!image) return void 0;
|
|
8271
9140
|
const imageOptions = typeof image === "string" ? { src: image } : image;
|
|
8272
|
-
return
|
|
9141
|
+
return React14.createElement("img", {
|
|
8273
9142
|
src: imageOptions.src,
|
|
8274
9143
|
alt: imageOptions.alt ?? "",
|
|
8275
9144
|
width: imageOptions.width ?? 14,
|
|
@@ -8284,9 +9153,9 @@ function imageNode(image) {
|
|
|
8284
9153
|
}
|
|
8285
9154
|
function iconNode(icon, color) {
|
|
8286
9155
|
if (icon === false) return void 0;
|
|
8287
|
-
if (icon == null) return
|
|
9156
|
+
if (icon == null) return React14.createElement(VizmaticIcon, { size: 13, color });
|
|
8288
9157
|
if (typeof icon !== "string") return icon;
|
|
8289
|
-
return
|
|
9158
|
+
return React14.createElement("div", {
|
|
8290
9159
|
style: {
|
|
8291
9160
|
minWidth: 13,
|
|
8292
9161
|
height: 13,
|
|
@@ -8311,7 +9180,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
|
|
|
8311
9180
|
const text = options?.text ?? DEFAULT_WATERMARK_TEXT;
|
|
8312
9181
|
const content = options?.element ?? [
|
|
8313
9182
|
icon,
|
|
8314
|
-
text !== false && text &&
|
|
9183
|
+
text !== false && text && React14.createElement("div", {
|
|
8315
9184
|
key: "text",
|
|
8316
9185
|
style: {
|
|
8317
9186
|
fontSize: 11,
|
|
@@ -8322,7 +9191,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
|
|
|
8322
9191
|
}
|
|
8323
9192
|
}, text)
|
|
8324
9193
|
];
|
|
8325
|
-
return
|
|
9194
|
+
return React14.createElement(
|
|
8326
9195
|
"div",
|
|
8327
9196
|
{
|
|
8328
9197
|
style: {
|
|
@@ -8333,7 +9202,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
|
|
|
8333
9202
|
}
|
|
8334
9203
|
},
|
|
8335
9204
|
element,
|
|
8336
|
-
options &&
|
|
9205
|
+
options && React14.createElement(
|
|
8337
9206
|
"div",
|
|
8338
9207
|
{
|
|
8339
9208
|
style: {
|
|
@@ -8484,7 +9353,8 @@ function resolveSatori(api) {
|
|
|
8484
9353
|
}
|
|
8485
9354
|
throw new Error("satori export could not be resolved");
|
|
8486
9355
|
}
|
|
8487
|
-
var
|
|
9356
|
+
var renderSatori = resolveSatori(satoriModule);
|
|
9357
|
+
var satori = (element, options) => renderWithCanvasChartFit(renderSatori, element, options);
|
|
8488
9358
|
|
|
8489
9359
|
// src/render.ts
|
|
8490
9360
|
var FONT_CACHE_DIR = process.env.VIZMATIC_FONT_DIR ?? join(process.env.XDG_CACHE_HOME ?? join(homedir(), ".cache"), "vizmatic", "fonts");
|
|
@@ -9823,30 +10693,30 @@ function readEndpoint(line, from) {
|
|
|
9823
10693
|
next: content.next
|
|
9824
10694
|
};
|
|
9825
10695
|
}
|
|
9826
|
-
function addNode(state,
|
|
9827
|
-
if (state.groupIds.has(
|
|
10696
|
+
function addNode(state, endpoint2, groupId, line, sourceLines, diagnostics, explicitlyDeclared) {
|
|
10697
|
+
if (state.groupIds.has(endpoint2.id)) {
|
|
9828
10698
|
addImportDiagnostic(
|
|
9829
10699
|
diagnostics,
|
|
9830
10700
|
sourceLines,
|
|
9831
10701
|
line,
|
|
9832
10702
|
"import.unsupported_semantics",
|
|
9833
10703
|
"error",
|
|
9834
|
-
`Mermaid id "${
|
|
10704
|
+
`Mermaid id "${endpoint2.id}" is already used by a subgraph and cannot also be a node.`
|
|
9835
10705
|
);
|
|
9836
10706
|
return false;
|
|
9837
10707
|
}
|
|
9838
|
-
if (labelHasUnsupportedMarkup(
|
|
10708
|
+
if (labelHasUnsupportedMarkup(endpoint2.label)) {
|
|
9839
10709
|
addImportDiagnostic(
|
|
9840
10710
|
diagnostics,
|
|
9841
10711
|
sourceLines,
|
|
9842
10712
|
line,
|
|
9843
10713
|
"import.unsupported_semantics",
|
|
9844
10714
|
"error",
|
|
9845
|
-
`Mermaid label for node "${
|
|
10715
|
+
`Mermaid label for node "${endpoint2.id}" uses HTML or Markdown formatting that GraphDiagram cannot preserve.`
|
|
9846
10716
|
);
|
|
9847
10717
|
return false;
|
|
9848
10718
|
}
|
|
9849
|
-
const existingIndex = state.nodeIndexes.get(
|
|
10719
|
+
const existingIndex = state.nodeIndexes.get(endpoint2.id);
|
|
9850
10720
|
if (existingIndex !== void 0) {
|
|
9851
10721
|
const existing = state.nodes[existingIndex];
|
|
9852
10722
|
if (!existing) return false;
|
|
@@ -9857,7 +10727,7 @@ function addNode(state, endpoint, groupId, line, sourceLines, diagnostics, expli
|
|
|
9857
10727
|
line,
|
|
9858
10728
|
"import.unsupported_semantics",
|
|
9859
10729
|
"error",
|
|
9860
|
-
`Mermaid node "${
|
|
10730
|
+
`Mermaid node "${endpoint2.id}" is assigned to more than one subgraph; GraphDiagram nodes support one group.`
|
|
9861
10731
|
);
|
|
9862
10732
|
return false;
|
|
9863
10733
|
}
|
|
@@ -9868,28 +10738,28 @@ function addNode(state, endpoint, groupId, line, sourceLines, diagnostics, expli
|
|
|
9868
10738
|
line,
|
|
9869
10739
|
"import.unsupported_semantics",
|
|
9870
10740
|
"error",
|
|
9871
|
-
`Mermaid node "${
|
|
10741
|
+
`Mermaid node "${endpoint2.id}" is referenced both inside and outside a subgraph; its group membership is ambiguous.`
|
|
9872
10742
|
);
|
|
9873
10743
|
return false;
|
|
9874
10744
|
}
|
|
9875
|
-
if (explicitlyDeclared) existing.label =
|
|
10745
|
+
if (explicitlyDeclared) existing.label = endpoint2.label;
|
|
9876
10746
|
} else {
|
|
9877
|
-
state.nodeIndexes.set(
|
|
10747
|
+
state.nodeIndexes.set(endpoint2.id, state.nodes.length);
|
|
9878
10748
|
state.nodes.push({
|
|
9879
|
-
id:
|
|
9880
|
-
label:
|
|
10749
|
+
id: endpoint2.id,
|
|
10750
|
+
label: endpoint2.label,
|
|
9881
10751
|
...groupId ? { group: groupId } : {}
|
|
9882
10752
|
});
|
|
9883
10753
|
}
|
|
9884
|
-
if (
|
|
9885
|
-
state.warnedShapes.add(
|
|
10754
|
+
if (endpoint2.shape === "lossy" && !state.warnedShapes.has(endpoint2.id)) {
|
|
10755
|
+
state.warnedShapes.add(endpoint2.id);
|
|
9886
10756
|
addImportDiagnostic(
|
|
9887
10757
|
diagnostics,
|
|
9888
10758
|
sourceLines,
|
|
9889
10759
|
line,
|
|
9890
10760
|
"import.lossy_semantics",
|
|
9891
10761
|
"warning",
|
|
9892
|
-
`Mermaid node "${
|
|
10762
|
+
`Mermaid node "${endpoint2.id}" uses a non-rectangular shape; it will render as a generic GraphDiagram node.`
|
|
9893
10763
|
);
|
|
9894
10764
|
}
|
|
9895
10765
|
return true;
|
|
@@ -10288,7 +11158,7 @@ import { join as join2 } from "path";
|
|
|
10288
11158
|
|
|
10289
11159
|
// src/diagnostics.ts
|
|
10290
11160
|
import parseCssColor3 from "parse-css-color";
|
|
10291
|
-
import { Children, isValidElement as
|
|
11161
|
+
import { Children, isValidElement as isValidElement3 } from "react";
|
|
10292
11162
|
var CHECK_DIAGNOSTIC_CODES = [
|
|
10293
11163
|
"accessibility.low_contrast",
|
|
10294
11164
|
"api.unsupported_prop",
|
|
@@ -10297,6 +11167,7 @@ var CHECK_DIAGNOSTIC_CODES = [
|
|
|
10297
11167
|
"frame.unknown_preset",
|
|
10298
11168
|
"layout.auto_size",
|
|
10299
11169
|
"layout.connector_congestion",
|
|
11170
|
+
"layout.connector_unroutable",
|
|
10300
11171
|
"layout.overflow",
|
|
10301
11172
|
"layout.text_overlap",
|
|
10302
11173
|
"layout.whitespace_imbalance",
|
|
@@ -10399,7 +11270,7 @@ function elementId(props) {
|
|
|
10399
11270
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
10400
11271
|
}
|
|
10401
11272
|
function resolveFunctionComponent(node, trustedComponents) {
|
|
10402
|
-
if (!
|
|
11273
|
+
if (!isValidElement3(node) || typeof node.type !== "function" || trustedComponents.has(node.type)) return void 0;
|
|
10403
11274
|
const component = node.type;
|
|
10404
11275
|
if (component.__vizmaticPrimitive) return void 0;
|
|
10405
11276
|
if (component.prototype?.isReactComponent) return void 0;
|
|
@@ -10414,7 +11285,7 @@ function analyzeContrast(element, theme, trustedComponents = /* @__PURE__ */ new
|
|
|
10414
11285
|
const seen = /* @__PURE__ */ new Set();
|
|
10415
11286
|
let visited = 0;
|
|
10416
11287
|
function visit(node, inherited, path) {
|
|
10417
|
-
if (visited++ >= MAX_CONTRAST_NODES || !
|
|
11288
|
+
if (visited++ >= MAX_CONTRAST_NODES || !isValidElement3(node)) return;
|
|
10418
11289
|
const resolved = resolveFunctionComponent(node, trustedComponents);
|
|
10419
11290
|
if (resolved !== void 0) {
|
|
10420
11291
|
visit(resolved, inherited, path);
|
|
@@ -10591,6 +11462,18 @@ function analyzeRenderedLayout(nodes, theme) {
|
|
|
10591
11462
|
const value = node.props[attribute2];
|
|
10592
11463
|
return typeof value === "number" ? value : Number(value) || 0;
|
|
10593
11464
|
}));
|
|
11465
|
+
for (const source of nodes.filter((node) => Number(node.props["data-vizmatic-unrouted-connectors"]) > 0)) {
|
|
11466
|
+
const messages = JSON.parse(String(source.props["data-vizmatic-routing-failures"]));
|
|
11467
|
+
for (const message of messages.slice(0, MAX_DIAGNOSTICS_PER_RULE)) diagnostics.push({
|
|
11468
|
+
code: "layout.connector_unroutable",
|
|
11469
|
+
severity: "error",
|
|
11470
|
+
theme,
|
|
11471
|
+
message,
|
|
11472
|
+
suggestion: "Increase canvas size or spacing, reduce routingClearance, or choose a different endpoint side or port.",
|
|
11473
|
+
elementId: elementId(source.props),
|
|
11474
|
+
location: { x: source.left, y: source.top, width: source.width, height: source.height }
|
|
11475
|
+
});
|
|
11476
|
+
}
|
|
10594
11477
|
const connectorCrossings2 = maxDataNumber("data-vizmatic-connector-crossings");
|
|
10595
11478
|
if (connectorCrossings2 > 0) {
|
|
10596
11479
|
const source = nodes.find((node) => Number(node.props["data-vizmatic-connector-crossings"]) > 0);
|
|
@@ -11043,10 +11926,13 @@ export {
|
|
|
11043
11926
|
Badge,
|
|
11044
11927
|
BadgePill,
|
|
11045
11928
|
BarChart,
|
|
11929
|
+
Board,
|
|
11046
11930
|
Box,
|
|
11931
|
+
CANVAS_ITEM_COMPONENT,
|
|
11047
11932
|
CHECK_DIAGNOSTIC_CODES,
|
|
11048
11933
|
CalloutCard,
|
|
11049
11934
|
Canvas,
|
|
11935
|
+
CanvasItem,
|
|
11050
11936
|
CanvasOverflowError,
|
|
11051
11937
|
Card,
|
|
11052
11938
|
ChartFrame,
|
|
@@ -11079,7 +11965,9 @@ export {
|
|
|
11079
11965
|
MetricCard,
|
|
11080
11966
|
MiniBarChart,
|
|
11081
11967
|
Panel,
|
|
11968
|
+
ParetoBarChart,
|
|
11082
11969
|
ParetoChart,
|
|
11970
|
+
PieChart,
|
|
11083
11971
|
Pipeline,
|
|
11084
11972
|
ProgressList,
|
|
11085
11973
|
ProgressRow,
|