vizmatic 0.2.0 → 0.3.1
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 +76 -1
- package/ROADMAP.md +4 -2
- package/assets/THIRD_PARTY_LICENSES.md +3 -0
- package/dist/cli.js +33 -12433
- package/dist/index.cjs +1095 -189
- package/dist/index.d.cts +80 -7
- package/dist/index.d.ts +80 -7
- package/dist/index.js +1088 -188
- 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 +11 -8
package/dist/index.cjs
CHANGED
|
@@ -36,10 +36,13 @@ __export(index_exports, {
|
|
|
36
36
|
Badge: () => Badge,
|
|
37
37
|
BadgePill: () => BadgePill,
|
|
38
38
|
BarChart: () => BarChart,
|
|
39
|
+
Board: () => Board,
|
|
39
40
|
Box: () => Box,
|
|
41
|
+
CANVAS_ITEM_COMPONENT: () => CANVAS_ITEM_COMPONENT,
|
|
40
42
|
CHECK_DIAGNOSTIC_CODES: () => CHECK_DIAGNOSTIC_CODES,
|
|
41
43
|
CalloutCard: () => CalloutCard,
|
|
42
44
|
Canvas: () => Canvas,
|
|
45
|
+
CanvasItem: () => CanvasItem,
|
|
43
46
|
CanvasOverflowError: () => CanvasOverflowError,
|
|
44
47
|
Card: () => Card,
|
|
45
48
|
ChartFrame: () => ChartFrame,
|
|
@@ -72,7 +75,9 @@ __export(index_exports, {
|
|
|
72
75
|
MetricCard: () => MetricCard,
|
|
73
76
|
MiniBarChart: () => MiniBarChart,
|
|
74
77
|
Panel: () => Panel,
|
|
78
|
+
ParetoBarChart: () => ParetoBarChart,
|
|
75
79
|
ParetoChart: () => ParetoChart,
|
|
80
|
+
PieChart: () => PieChart,
|
|
76
81
|
Pipeline: () => Pipeline,
|
|
77
82
|
ProgressList: () => ProgressList,
|
|
78
83
|
ProgressRow: () => ProgressRow,
|
|
@@ -152,6 +157,7 @@ __export(index_exports, {
|
|
|
152
157
|
toneGradients: () => toneGradients,
|
|
153
158
|
tween: () => tween,
|
|
154
159
|
typography: () => typography,
|
|
160
|
+
withColorAlpha: () => withColorAlpha,
|
|
155
161
|
wrapWithBrand: () => wrapWithBrand,
|
|
156
162
|
wrapWithWatermark: () => wrapWithWatermark
|
|
157
163
|
});
|
|
@@ -376,7 +382,7 @@ function getReadableToneColor(tone, c, background = c.bgCard, backdrop = c.bgCar
|
|
|
376
382
|
return colorContrast(color, background, backdrop) >= 4.5 ? color : getReadableTextColor(background, c, backdrop);
|
|
377
383
|
}
|
|
378
384
|
function getToneFill(tone, c) {
|
|
379
|
-
if (c.preset !== "engineering") return
|
|
385
|
+
if (c.preset !== "engineering") return withColorAlpha(getToneColor(tone, c), 22 / 255);
|
|
380
386
|
return {
|
|
381
387
|
blue: "#cddcfa",
|
|
382
388
|
purple: "#dfcff8",
|
|
@@ -513,6 +519,17 @@ function parseColor(color) {
|
|
|
513
519
|
alpha: parsed.alpha
|
|
514
520
|
};
|
|
515
521
|
}
|
|
522
|
+
function withColorAlpha(color, opacity) {
|
|
523
|
+
if (typeof color !== "string" || !Number.isFinite(opacity)) return "transparent";
|
|
524
|
+
const parsed = parseColor(color);
|
|
525
|
+
if (!parsed) return "transparent";
|
|
526
|
+
const alpha = Math.min(1, Math.max(0, parsed.alpha * Math.min(1, Math.max(0, opacity))));
|
|
527
|
+
const hex = color.trim();
|
|
528
|
+
if (/^#[\da-f]{6}$/i.test(hex)) {
|
|
529
|
+
return `${hex}${Math.round(alpha * 255).toString(16).padStart(2, "0")}`;
|
|
530
|
+
}
|
|
531
|
+
return `rgba(${parsed.channels.join(", ")}, ${Number(alpha.toFixed(6))})`;
|
|
532
|
+
}
|
|
516
533
|
function colorLuminance(color, backdrop) {
|
|
517
534
|
const parsed = parseColor(color);
|
|
518
535
|
if (!parsed) return void 0;
|
|
@@ -592,9 +609,12 @@ __export(primitives_exports, {
|
|
|
592
609
|
Badge: () => Badge,
|
|
593
610
|
BadgePill: () => BadgePill,
|
|
594
611
|
BarChart: () => BarChart,
|
|
612
|
+
Board: () => Board,
|
|
595
613
|
Box: () => Box,
|
|
614
|
+
CANVAS_ITEM_COMPONENT: () => CANVAS_ITEM_COMPONENT,
|
|
596
615
|
CalloutCard: () => CalloutCard,
|
|
597
616
|
Canvas: () => Canvas,
|
|
617
|
+
CanvasItem: () => CanvasItem,
|
|
598
618
|
Card: () => Card,
|
|
599
619
|
ChartFrame: () => ChartFrame,
|
|
600
620
|
CodeBlock: () => CodeBlock,
|
|
@@ -626,7 +646,9 @@ __export(primitives_exports, {
|
|
|
626
646
|
MetricCard: () => MetricCard,
|
|
627
647
|
MiniBarChart: () => MiniBarChart,
|
|
628
648
|
Panel: () => Panel,
|
|
649
|
+
ParetoBarChart: () => ParetoBarChart,
|
|
629
650
|
ParetoChart: () => ParetoChart,
|
|
651
|
+
PieChart: () => PieChart,
|
|
630
652
|
Pipeline: () => Pipeline,
|
|
631
653
|
ProgressList: () => ProgressList,
|
|
632
654
|
ProgressRow: () => ProgressRow,
|
|
@@ -1422,10 +1444,10 @@ function Box({
|
|
|
1422
1444
|
style.backgroundColor = "transparent";
|
|
1423
1445
|
} else if (gradient) {
|
|
1424
1446
|
style.backgroundImage = gradientBg;
|
|
1425
|
-
style.boxShadow = `0 4px 20px ${solidColor}
|
|
1447
|
+
style.boxShadow = `0 4px 20px ${withColorAlpha(solidColor, 48 / 255)}`;
|
|
1426
1448
|
} else {
|
|
1427
1449
|
style.backgroundColor = solidColor;
|
|
1428
|
-
style.boxShadow = `0 4px 20px ${solidColor}
|
|
1450
|
+
style.boxShadow = `0 4px 20px ${withColorAlpha(solidColor, 48 / 255)}`;
|
|
1429
1451
|
}
|
|
1430
1452
|
return import_react2.default.createElement(
|
|
1431
1453
|
"div",
|
|
@@ -1447,7 +1469,7 @@ function Box({
|
|
|
1447
1469
|
style: {
|
|
1448
1470
|
fontSize: fontSize - 2,
|
|
1449
1471
|
fontWeight: 400,
|
|
1450
|
-
color: outlined ? c.textMuted : gradient ?
|
|
1472
|
+
color: outlined ? c.textMuted : gradient ? withColorAlpha(c.textOnColor, 179 / 255) : solidTextColor,
|
|
1451
1473
|
fontFamily: c.fontMono,
|
|
1452
1474
|
textAlign: "center"
|
|
1453
1475
|
}
|
|
@@ -1977,8 +1999,8 @@ function BadgePill({
|
|
|
1977
1999
|
...height != null ? { height } : {},
|
|
1978
2000
|
padding,
|
|
1979
2001
|
borderRadius: engineering ? Math.min(radius, 5) : radius,
|
|
1980
|
-
...engineering ? { backgroundColor: getToneFill(tone, c) } : filled ? { backgroundImage: getToneGradient(tone) } : { backgroundColor:
|
|
1981
|
-
border: `1px solid ${engineering ? accent : filled ?
|
|
2002
|
+
...engineering ? { backgroundColor: getToneFill(tone, c) } : filled ? { backgroundImage: getToneGradient(tone) } : { backgroundColor: withColorAlpha(accent, 24 / 255) },
|
|
2003
|
+
border: `1px solid ${engineering ? accent : filled ? withColorAlpha(accent, 0) : withColorAlpha(accent, 85 / 255)}`,
|
|
1982
2004
|
color: engineering ? c.textPrimary : filled ? c.textOnColor : accentText,
|
|
1983
2005
|
fontSize,
|
|
1984
2006
|
fontWeight: 800,
|
|
@@ -2080,7 +2102,7 @@ function StepCard({
|
|
|
2080
2102
|
radius: engineering ? 5 : radius,
|
|
2081
2103
|
shadow: engineering ? false : shadow,
|
|
2082
2104
|
background: engineering ? getToneFill(tone, c) : void 0,
|
|
2083
|
-
borderColor: engineering ? accent :
|
|
2105
|
+
borderColor: engineering ? accent : withColorAlpha(accent, 136 / 255),
|
|
2084
2106
|
children: import_react3.default.createElement(
|
|
2085
2107
|
"div",
|
|
2086
2108
|
{
|
|
@@ -2156,7 +2178,7 @@ function MetricCard({
|
|
|
2156
2178
|
padding,
|
|
2157
2179
|
radius,
|
|
2158
2180
|
shadow,
|
|
2159
|
-
borderColor:
|
|
2181
|
+
borderColor: withColorAlpha(accent, 102 / 255),
|
|
2160
2182
|
children: import_react3.default.createElement(
|
|
2161
2183
|
"div",
|
|
2162
2184
|
{
|
|
@@ -2406,7 +2428,7 @@ function DetailList({
|
|
|
2406
2428
|
padding,
|
|
2407
2429
|
borderRadius: 8,
|
|
2408
2430
|
backgroundColor: c.bgSubtle,
|
|
2409
|
-
border: `1px solid ${tone ?
|
|
2431
|
+
border: `1px solid ${tone ? withColorAlpha(accent, 68 / 255) : c.borderSubtle}`,
|
|
2410
2432
|
color: c.textSecondary,
|
|
2411
2433
|
fontSize,
|
|
2412
2434
|
lineHeight: 1.3,
|
|
@@ -2470,7 +2492,7 @@ function Tile({
|
|
|
2470
2492
|
padding,
|
|
2471
2493
|
radius,
|
|
2472
2494
|
shadow,
|
|
2473
|
-
borderColor:
|
|
2495
|
+
borderColor: withColorAlpha(accent, 136 / 255),
|
|
2474
2496
|
children: import_react4.default.createElement(
|
|
2475
2497
|
"div",
|
|
2476
2498
|
{
|
|
@@ -2604,7 +2626,7 @@ function CodeBlock({
|
|
|
2604
2626
|
width: "100%",
|
|
2605
2627
|
padding: accent ? "3px 7px" : "1px 0",
|
|
2606
2628
|
borderRadius: accent ? 5 : 0,
|
|
2607
|
-
...accent ? { backgroundColor:
|
|
2629
|
+
...accent ? { backgroundColor: withColorAlpha(accent, 31 / 255) } : {},
|
|
2608
2630
|
boxSizing: "border-box"
|
|
2609
2631
|
}
|
|
2610
2632
|
},
|
|
@@ -2660,7 +2682,7 @@ function CodeBlock({
|
|
|
2660
2682
|
padding,
|
|
2661
2683
|
borderRadius: radius,
|
|
2662
2684
|
backgroundColor: background ?? c.bgSubtle,
|
|
2663
|
-
border: `1px solid ${tone ?
|
|
2685
|
+
border: `1px solid ${tone ? withColorAlpha(headerAccent, 68 / 255) : c.borderSubtle}`,
|
|
2664
2686
|
boxSizing: "border-box",
|
|
2665
2687
|
...shadow ? { boxShadow: `0 9px 24px ${c.shadow}` } : {}
|
|
2666
2688
|
}
|
|
@@ -2743,7 +2765,7 @@ function renderComparisonDivider(divider, c, key) {
|
|
|
2743
2765
|
);
|
|
2744
2766
|
}
|
|
2745
2767
|
function Comparison({
|
|
2746
|
-
sides,
|
|
2768
|
+
sides: sides2,
|
|
2747
2769
|
c,
|
|
2748
2770
|
divider = false,
|
|
2749
2771
|
gap = 14,
|
|
@@ -2752,7 +2774,7 @@ function Comparison({
|
|
|
2752
2774
|
align = "stretch",
|
|
2753
2775
|
math = false
|
|
2754
2776
|
}) {
|
|
2755
|
-
const children =
|
|
2777
|
+
const children = sides2.flatMap((side, index) => {
|
|
2756
2778
|
const tone = side.tone ?? "blue";
|
|
2757
2779
|
const panel = import_react4.default.createElement(
|
|
2758
2780
|
import_react4.default.Fragment,
|
|
@@ -2782,7 +2804,7 @@ function Comparison({
|
|
|
2782
2804
|
) : side.children ?? DetailList({ items: side.lines ?? [], c, tone, math })
|
|
2783
2805
|
})
|
|
2784
2806
|
);
|
|
2785
|
-
if (divider && index <
|
|
2807
|
+
if (divider && index < sides2.length - 1) {
|
|
2786
2808
|
return [panel, renderComparisonDivider(divider, c, `comparison-divider-${index}`)];
|
|
2787
2809
|
}
|
|
2788
2810
|
return [panel];
|
|
@@ -3022,7 +3044,7 @@ function StatusRow({
|
|
|
3022
3044
|
const markerAlpha = 38 / 255;
|
|
3023
3045
|
const rowAlpha = boxed ? 18 / 255 : 0;
|
|
3024
3046
|
const markerBackgroundAlpha = Math.round((rowAlpha + markerAlpha * (1 - rowAlpha)) * 255);
|
|
3025
|
-
const markerBackground =
|
|
3047
|
+
const markerBackground = withColorAlpha(accent, markerBackgroundAlpha / 255);
|
|
3026
3048
|
const accentText = getReadableToneColor(resolvedTone, c, markerBackground, c.bgCard);
|
|
3027
3049
|
const glyph = statusGlyphs[status];
|
|
3028
3050
|
const marker = import_react5.default.createElement("div", {
|
|
@@ -3034,7 +3056,7 @@ function StatusRow({
|
|
|
3034
3056
|
height: 18,
|
|
3035
3057
|
flexShrink: 0,
|
|
3036
3058
|
borderRadius: 999,
|
|
3037
|
-
backgroundColor: status === "dot" ? accent :
|
|
3059
|
+
backgroundColor: status === "dot" ? accent : withColorAlpha(accent, 38 / 255),
|
|
3038
3060
|
border: `1px solid ${accent}`,
|
|
3039
3061
|
color: accentText,
|
|
3040
3062
|
fontFamily: "Inter",
|
|
@@ -3055,8 +3077,8 @@ function StatusRow({
|
|
|
3055
3077
|
...boxed ? {
|
|
3056
3078
|
padding: "7px 10px",
|
|
3057
3079
|
borderRadius: 8,
|
|
3058
|
-
backgroundColor:
|
|
3059
|
-
border: `1px solid ${accent}
|
|
3080
|
+
backgroundColor: withColorAlpha(accent, 18 / 255),
|
|
3081
|
+
border: `1px solid ${withColorAlpha(accent, 58 / 255)}`
|
|
3060
3082
|
} : { padding: "3px 0" }
|
|
3061
3083
|
}
|
|
3062
3084
|
},
|
|
@@ -3121,7 +3143,7 @@ function renderTimelineCard(event, c, math, width) {
|
|
|
3121
3143
|
...typeof resolvedWidth === "string" ? { minWidth: 0 } : {},
|
|
3122
3144
|
padding: "10px 12px",
|
|
3123
3145
|
borderRadius: 8,
|
|
3124
|
-
border: `1px solid ${accent}
|
|
3146
|
+
border: `1px solid ${withColorAlpha(accent, 68 / 255)}`,
|
|
3125
3147
|
backgroundColor: c.bgCard,
|
|
3126
3148
|
boxShadow: `0 7px 18px ${c.shadow}`,
|
|
3127
3149
|
boxSizing: "border-box"
|
|
@@ -3638,6 +3660,284 @@ function addSvgAccessibility(svg, graphs, layoutNodes) {
|
|
|
3638
3660
|
).replace(/<\/svg>\s*$/, `${groupMarkup}</svg>`);
|
|
3639
3661
|
}
|
|
3640
3662
|
|
|
3663
|
+
// src/graph-routing.ts
|
|
3664
|
+
var EPSILON = 1e-3;
|
|
3665
|
+
var MAX_GRID_POINTS = 18e3;
|
|
3666
|
+
var MAX_SEARCH_STATES = 54e3;
|
|
3667
|
+
var MAX_TOTAL_SEARCH_STATES = 16e4;
|
|
3668
|
+
var MAX_ROUTED_EDGES = 256;
|
|
3669
|
+
var MAX_OBSTACLES = 64;
|
|
3670
|
+
var sides = ["right", "bottom", "left", "top"];
|
|
3671
|
+
function box(node, clearance = 0) {
|
|
3672
|
+
return {
|
|
3673
|
+
left: node.cx - node.width / 2 - clearance,
|
|
3674
|
+
right: node.cx + node.width / 2 + clearance,
|
|
3675
|
+
top: node.cy - node.height / 2 - clearance,
|
|
3676
|
+
bottom: node.cy + node.height / 2 + clearance
|
|
3677
|
+
};
|
|
3678
|
+
}
|
|
3679
|
+
function inside(point, obstacle) {
|
|
3680
|
+
return point.x > obstacle.left + EPSILON && point.x < obstacle.right - EPSILON && point.y > obstacle.top + EPSILON && point.y < obstacle.bottom - EPSILON;
|
|
3681
|
+
}
|
|
3682
|
+
function routingSegmentBlocked(a, b, obstacle) {
|
|
3683
|
+
if (Math.abs(a.y - b.y) < EPSILON) {
|
|
3684
|
+
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;
|
|
3685
|
+
}
|
|
3686
|
+
if (Math.abs(a.x - b.x) < EPSILON) {
|
|
3687
|
+
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;
|
|
3688
|
+
}
|
|
3689
|
+
return true;
|
|
3690
|
+
}
|
|
3691
|
+
function preferredSide(from, to) {
|
|
3692
|
+
if (Math.abs(to.cx - from.cx) >= Math.abs(to.cy - from.cy)) return to.cx >= from.cx ? "right" : "left";
|
|
3693
|
+
return to.cy >= from.cy ? "bottom" : "top";
|
|
3694
|
+
}
|
|
3695
|
+
function routingAnchor(node, side, offset = 0.5) {
|
|
3696
|
+
const bounds = box(node);
|
|
3697
|
+
if (side === "left" || side === "right") return { x: bounds[side], y: bounds.top + node.height * offset };
|
|
3698
|
+
return { x: bounds.left + node.width * offset, y: bounds[side] };
|
|
3699
|
+
}
|
|
3700
|
+
function outward(point, side, distance) {
|
|
3701
|
+
return {
|
|
3702
|
+
x: point.x + (side === "right" ? distance : side === "left" ? -distance : 0),
|
|
3703
|
+
y: point.y + (side === "bottom" ? distance : side === "top" ? -distance : 0)
|
|
3704
|
+
};
|
|
3705
|
+
}
|
|
3706
|
+
function simplify(points) {
|
|
3707
|
+
const result = [];
|
|
3708
|
+
for (const point of points) {
|
|
3709
|
+
const last = result[result.length - 1];
|
|
3710
|
+
if (last && Math.abs(last.x - point.x) < EPSILON && Math.abs(last.y - point.y) < EPSILON) continue;
|
|
3711
|
+
const previous = result[result.length - 2];
|
|
3712
|
+
if (previous && last && (previous.x === last.x && last.x === point.x || previous.y === last.y && last.y === point.y)) {
|
|
3713
|
+
result[result.length - 1] = point;
|
|
3714
|
+
} else result.push(point);
|
|
3715
|
+
}
|
|
3716
|
+
return result;
|
|
3717
|
+
}
|
|
3718
|
+
function overlappingLength(a, b, c, d) {
|
|
3719
|
+
if (a.y === b.y && c.y === d.y && Math.abs(a.y - c.y) < EPSILON) {
|
|
3720
|
+
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)));
|
|
3721
|
+
}
|
|
3722
|
+
if (a.x === b.x && c.x === d.x && Math.abs(a.x - c.x) < EPSILON) {
|
|
3723
|
+
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)));
|
|
3724
|
+
}
|
|
3725
|
+
return 0;
|
|
3726
|
+
}
|
|
3727
|
+
var MinQueue = class {
|
|
3728
|
+
items = [];
|
|
3729
|
+
get length() {
|
|
3730
|
+
return this.items.length;
|
|
3731
|
+
}
|
|
3732
|
+
push(value) {
|
|
3733
|
+
const items = this.items;
|
|
3734
|
+
items.push(value);
|
|
3735
|
+
let index = items.length - 1;
|
|
3736
|
+
while (index > 0) {
|
|
3737
|
+
const parent = index - 1 >> 1;
|
|
3738
|
+
if (items[parent].priority <= value.priority) break;
|
|
3739
|
+
items[index] = items[parent];
|
|
3740
|
+
index = parent;
|
|
3741
|
+
}
|
|
3742
|
+
items[index] = value;
|
|
3743
|
+
}
|
|
3744
|
+
pop() {
|
|
3745
|
+
const items = this.items;
|
|
3746
|
+
const first = items[0];
|
|
3747
|
+
const last = items.pop();
|
|
3748
|
+
if (items.length === 0) return first;
|
|
3749
|
+
let index = 0;
|
|
3750
|
+
while (index * 2 + 1 < items.length) {
|
|
3751
|
+
const left = index * 2 + 1;
|
|
3752
|
+
const right = left + 1;
|
|
3753
|
+
const child = right < items.length && items[right].priority < items[left].priority ? right : left;
|
|
3754
|
+
if (items[child].priority >= last.priority) break;
|
|
3755
|
+
items[index] = items[child];
|
|
3756
|
+
index = child;
|
|
3757
|
+
}
|
|
3758
|
+
items[index] = last;
|
|
3759
|
+
return first;
|
|
3760
|
+
}
|
|
3761
|
+
};
|
|
3762
|
+
function findPath(start, end, obstacles, width, height, previousRoutes, gap, budget) {
|
|
3763
|
+
const within = (point) => point.x >= 0 && point.x <= width && point.y >= 0 && point.y <= height;
|
|
3764
|
+
if (!within(start) || !within(end) || obstacles.some((obstacle) => inside(start, obstacle) || inside(end, obstacle))) {
|
|
3765
|
+
return { reason: "an endpoint has no clear exit inside the canvas" };
|
|
3766
|
+
}
|
|
3767
|
+
const xs = /* @__PURE__ */ new Set([0, width, start.x, end.x]);
|
|
3768
|
+
const ys = /* @__PURE__ */ new Set([0, height, start.y, end.y]);
|
|
3769
|
+
for (const obstacle of obstacles) {
|
|
3770
|
+
if (obstacle.left >= 0 && obstacle.left <= width) xs.add(obstacle.left);
|
|
3771
|
+
if (obstacle.right >= 0 && obstacle.right <= width) xs.add(obstacle.right);
|
|
3772
|
+
if (obstacle.top >= 0 && obstacle.top <= height) ys.add(obstacle.top);
|
|
3773
|
+
if (obstacle.bottom >= 0 && obstacle.bottom <= height) ys.add(obstacle.bottom);
|
|
3774
|
+
}
|
|
3775
|
+
for (const route of previousRoutes.slice(-8)) for (const point of route) {
|
|
3776
|
+
for (const offset of [-gap, gap]) {
|
|
3777
|
+
if (point.x + offset >= 0 && point.x + offset <= width) xs.add(point.x + offset);
|
|
3778
|
+
if (point.y + offset >= 0 && point.y + offset <= height) ys.add(point.y + offset);
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3781
|
+
const xValues = [...xs].sort((a, b) => a - b);
|
|
3782
|
+
const yValues = [...ys].sort((a, b) => a - b);
|
|
3783
|
+
const columns = xValues.length;
|
|
3784
|
+
const gridSize = columns * yValues.length;
|
|
3785
|
+
if (gridSize > MAX_GRID_POINTS) return { reason: `routing grid exceeds ${MAX_GRID_POINTS} points; simplify the graph` };
|
|
3786
|
+
const startIndex = yValues.indexOf(start.y) * columns + xValues.indexOf(start.x);
|
|
3787
|
+
const endIndex = yValues.indexOf(end.y) * columns + xValues.indexOf(end.x);
|
|
3788
|
+
const pointAt = (index) => ({ x: xValues[index % columns], y: yValues[Math.floor(index / columns)] });
|
|
3789
|
+
const costs = new Float64Array(gridSize * 3).fill(Infinity);
|
|
3790
|
+
const parents = new Int32Array(gridSize * 3).fill(-1);
|
|
3791
|
+
const queue = new MinQueue();
|
|
3792
|
+
costs[startIndex * 3] = 0;
|
|
3793
|
+
queue.push({ state: startIndex * 3, cost: 0, priority: 0 });
|
|
3794
|
+
let visits = 0;
|
|
3795
|
+
while (queue.length > 0) {
|
|
3796
|
+
if (--budget.remaining < 0) return { reason: `diagram routing budget exceeds ${MAX_TOTAL_SEARCH_STATES} search states; simplify the graph` };
|
|
3797
|
+
if (++visits > MAX_SEARCH_STATES) return { reason: `routing search exceeds ${MAX_SEARCH_STATES} states; simplify the graph` };
|
|
3798
|
+
const current = queue.pop();
|
|
3799
|
+
if (current.cost !== costs[current.state]) continue;
|
|
3800
|
+
const index = Math.floor(current.state / 3);
|
|
3801
|
+
const axis = current.state % 3;
|
|
3802
|
+
if (index === endIndex) {
|
|
3803
|
+
const points = [];
|
|
3804
|
+
for (let state = current.state; state >= 0; state = parents[state]) points.push(pointAt(Math.floor(state / 3)));
|
|
3805
|
+
return { points: simplify(points.reverse()) };
|
|
3806
|
+
}
|
|
3807
|
+
const a = pointAt(index);
|
|
3808
|
+
const column = index % columns;
|
|
3809
|
+
const row = Math.floor(index / columns);
|
|
3810
|
+
const neighbors = [
|
|
3811
|
+
column > 0 ? index - 1 : -1,
|
|
3812
|
+
column < columns - 1 ? index + 1 : -1,
|
|
3813
|
+
row > 0 ? index - columns : -1,
|
|
3814
|
+
row < yValues.length - 1 ? index + columns : -1
|
|
3815
|
+
];
|
|
3816
|
+
for (const neighbor of neighbors) {
|
|
3817
|
+
if (neighbor < 0) continue;
|
|
3818
|
+
const b = pointAt(neighbor);
|
|
3819
|
+
if (obstacles.some((obstacle) => routingSegmentBlocked(a, b, obstacle))) continue;
|
|
3820
|
+
const nextAxis = a.y === b.y ? 1 : 2;
|
|
3821
|
+
const state = neighbor * 3 + nextAxis;
|
|
3822
|
+
let overlap = 0;
|
|
3823
|
+
for (const route of previousRoutes) for (let i = 1; i < route.length; i++) overlap += overlappingLength(a, b, route[i - 1], route[i]);
|
|
3824
|
+
const cost = current.cost + Math.abs(b.x - a.x) + Math.abs(b.y - a.y) + (axis !== 0 && axis !== nextAxis ? 18 : 0) + overlap * 5;
|
|
3825
|
+
if (cost >= costs[state]) continue;
|
|
3826
|
+
costs[state] = cost;
|
|
3827
|
+
parents[state] = current.state;
|
|
3828
|
+
queue.push({ state, cost, priority: cost + Math.abs(end.x - b.x) + Math.abs(end.y - b.y) });
|
|
3829
|
+
}
|
|
3830
|
+
}
|
|
3831
|
+
return { reason: "no obstacle-free route exists inside the canvas" };
|
|
3832
|
+
}
|
|
3833
|
+
function endpoint(node, other, portId, requestedSide, selfLoop, target, ordinal, count, gap) {
|
|
3834
|
+
const port = node.ports?.find((candidate) => candidate.id === portId);
|
|
3835
|
+
const side = port?.side ?? requestedSide ?? (selfLoop ? target ? "top" : "right" : preferredSide(node, other));
|
|
3836
|
+
const length = side === "left" || side === "right" ? node.height : node.width;
|
|
3837
|
+
const separation = count > 1 ? Math.min(gap, length * 0.7 / (count - 1)) : 0;
|
|
3838
|
+
const offset = port ? port.offset ?? 0.5 : 0.5 + (ordinal - (count - 1) / 2) * separation / length;
|
|
3839
|
+
return { side, anchor: routingAnchor(node, side, offset), explicit: portId != null || requestedSide != null };
|
|
3840
|
+
}
|
|
3841
|
+
function straightGraphRoute(from, to, edge) {
|
|
3842
|
+
return [
|
|
3843
|
+
endpoint(from, to, edge.fromPort, edge.fromSide, false, false, 0, 1, 0).anchor,
|
|
3844
|
+
endpoint(to, from, edge.toPort, edge.toSide, false, true, 0, 1, 0).anchor
|
|
3845
|
+
];
|
|
3846
|
+
}
|
|
3847
|
+
function routeOrthogonalGraph(nodes, edges, width, height, clearance = 12, gap = 14, extraObstacles = []) {
|
|
3848
|
+
const routes = /* @__PURE__ */ new Map();
|
|
3849
|
+
const failures = [];
|
|
3850
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
3851
|
+
const obstacles = [...nodes.map((node) => box(node, clearance)), ...extraObstacles.map((obstacle) => ({
|
|
3852
|
+
left: obstacle.left - clearance,
|
|
3853
|
+
right: obstacle.right + clearance,
|
|
3854
|
+
top: obstacle.top - clearance,
|
|
3855
|
+
bottom: obstacle.bottom + clearance
|
|
3856
|
+
}))];
|
|
3857
|
+
const routeKey = (edge) => [edge.from, edge.to].sort().join("\0");
|
|
3858
|
+
const counts2 = /* @__PURE__ */ new Map();
|
|
3859
|
+
for (const edge of edges) counts2.set(routeKey(edge), (counts2.get(routeKey(edge)) ?? 0) + 1);
|
|
3860
|
+
const occurrences = /* @__PURE__ */ new Map();
|
|
3861
|
+
const previous = /* @__PURE__ */ new Map();
|
|
3862
|
+
const budget = { remaining: MAX_TOTAL_SEARCH_STATES };
|
|
3863
|
+
edges.forEach((edge, index) => {
|
|
3864
|
+
if (index >= MAX_ROUTED_EDGES) {
|
|
3865
|
+
failures.push({ index, reason: `orthogonal routing supports at most ${MAX_ROUTED_EDGES} edges per diagram` });
|
|
3866
|
+
return;
|
|
3867
|
+
}
|
|
3868
|
+
if (obstacles.length > MAX_OBSTACLES) {
|
|
3869
|
+
failures.push({ index, reason: `orthogonal routing supports at most ${MAX_OBSTACLES} node and header obstacles per diagram` });
|
|
3870
|
+
return;
|
|
3871
|
+
}
|
|
3872
|
+
if (budget.remaining < 0) {
|
|
3873
|
+
failures.push({ index, reason: `diagram routing budget exceeds ${MAX_TOTAL_SEARCH_STATES} search states; simplify the graph` });
|
|
3874
|
+
return;
|
|
3875
|
+
}
|
|
3876
|
+
const from = byId.get(edge.from);
|
|
3877
|
+
const to = byId.get(edge.to);
|
|
3878
|
+
const key = routeKey(edge);
|
|
3879
|
+
const ordinal = occurrences.get(key) ?? 0;
|
|
3880
|
+
occurrences.set(key, ordinal + 1);
|
|
3881
|
+
const count = counts2.get(key) ?? 1;
|
|
3882
|
+
const source = endpoint(from, to, edge.fromPort, edge.fromSide, from === to, false, ordinal, count, gap);
|
|
3883
|
+
const target = endpoint(to, from, edge.toPort, edge.toSide, from === to, true, ordinal, count, gap);
|
|
3884
|
+
const sourceSides = source.explicit ? [source.side] : [source.side, ...sides.filter((side) => side !== source.side)];
|
|
3885
|
+
const targetSides = target.explicit ? [target.side] : [target.side, ...sides.filter((side) => side !== target.side)];
|
|
3886
|
+
let failure = "no obstacle-free route exists inside the canvas";
|
|
3887
|
+
for (const sourceSide of sourceSides) {
|
|
3888
|
+
for (const targetSide of targetSides) {
|
|
3889
|
+
const start = sourceSide === source.side ? source.anchor : routingAnchor(from, sourceSide);
|
|
3890
|
+
const end = targetSide === target.side ? target.anchor : routingAnchor(to, targetSide);
|
|
3891
|
+
if (from === to && start.x === end.x && start.y === end.y) {
|
|
3892
|
+
failure = "a self-loop requires distinct endpoint anchors";
|
|
3893
|
+
continue;
|
|
3894
|
+
}
|
|
3895
|
+
const leadStart = outward(start, sourceSide, clearance);
|
|
3896
|
+
const leadEnd = outward(end, targetSide, clearance);
|
|
3897
|
+
if (obstacles.some((obstacle, obstacleIndex) => obstacleIndex !== nodes.indexOf(from) && routingSegmentBlocked(start, leadStart, obstacle) || obstacleIndex !== nodes.indexOf(to) && routingSegmentBlocked(leadEnd, end, obstacle))) {
|
|
3898
|
+
failure = "another obstacle blocks an endpoint exit";
|
|
3899
|
+
continue;
|
|
3900
|
+
}
|
|
3901
|
+
const result = findPath(leadStart, leadEnd, obstacles, width, height, previous.get(key) ?? [], Math.max(1, gap), budget);
|
|
3902
|
+
if (!result.points) {
|
|
3903
|
+
failure = result.reason;
|
|
3904
|
+
if (/routing (grid|search|budget)/.test(failure)) {
|
|
3905
|
+
failures.push({ index, reason: failure });
|
|
3906
|
+
return;
|
|
3907
|
+
}
|
|
3908
|
+
continue;
|
|
3909
|
+
}
|
|
3910
|
+
const points = simplify([start, ...result.points, end]);
|
|
3911
|
+
if (points.length < 2) continue;
|
|
3912
|
+
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)));
|
|
3913
|
+
if (repeated) {
|
|
3914
|
+
failure = "parallel connectors have no separate lane at the requested clearance";
|
|
3915
|
+
continue;
|
|
3916
|
+
}
|
|
3917
|
+
routes.set(index, points);
|
|
3918
|
+
previous.set(key, [...previous.get(key) ?? [], points]);
|
|
3919
|
+
return;
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
failures.push({ index, reason: failure });
|
|
3923
|
+
});
|
|
3924
|
+
return { routes, failures };
|
|
3925
|
+
}
|
|
3926
|
+
function routingLabelPosition(points) {
|
|
3927
|
+
let longest = 0;
|
|
3928
|
+
let position = points[0];
|
|
3929
|
+
for (let i = 1; i < points.length; i++) {
|
|
3930
|
+
const a = points[i - 1];
|
|
3931
|
+
const b = points[i];
|
|
3932
|
+
const length = Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
|
3933
|
+
if (length > longest) {
|
|
3934
|
+
longest = length;
|
|
3935
|
+
position = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
3936
|
+
}
|
|
3937
|
+
}
|
|
3938
|
+
return position;
|
|
3939
|
+
}
|
|
3940
|
+
|
|
3641
3941
|
// src/primitives/diagrams.ts
|
|
3642
3942
|
function distributeValues(count, start, end) {
|
|
3643
3943
|
if (count <= 0) return [];
|
|
@@ -3721,10 +4021,10 @@ function LayeredNetwork({
|
|
|
3721
4021
|
width: nodeSize + 28,
|
|
3722
4022
|
height: nodeSize + 28,
|
|
3723
4023
|
borderRadius: 999,
|
|
3724
|
-
backgroundColor:
|
|
4024
|
+
backgroundColor: withColorAlpha(c.warningLight, 46 / 255),
|
|
3725
4025
|
border: `4px solid ${c.warningLight}`,
|
|
3726
4026
|
boxSizing: "border-box",
|
|
3727
|
-
boxShadow: `0 0 18px ${c.warningLight}
|
|
4027
|
+
boxShadow: `0 0 18px ${withColorAlpha(c.warningLight, 102 / 255)}`
|
|
3728
4028
|
}
|
|
3729
4029
|
}),
|
|
3730
4030
|
import_react7.default.createElement("div", {
|
|
@@ -3743,7 +4043,7 @@ function LayeredNetwork({
|
|
|
3743
4043
|
color: getReadableTextColor(color, c),
|
|
3744
4044
|
border: active ? `3px solid ${c.warningLight}` : `1.5px solid ${color}`,
|
|
3745
4045
|
boxSizing: "border-box",
|
|
3746
|
-
boxShadow: active ? `0 0 16px ${c.warningLight}
|
|
4046
|
+
boxShadow: active ? `0 0 16px ${withColorAlpha(c.warningLight, 112 / 255)}` : `0 8px 14px ${c.shadow}`,
|
|
3747
4047
|
fontFamily: "JetBrains Mono",
|
|
3748
4048
|
fontSize: 16,
|
|
3749
4049
|
fontWeight: 900,
|
|
@@ -3974,6 +4274,20 @@ function validateGraphDiagramSpec(nodes, edges, groups, layoutMode) {
|
|
|
3974
4274
|
for (const node of nodes) {
|
|
3975
4275
|
if (nodeIds.has(node.id)) throw new Error(`GraphDiagram received duplicate node id "${node.id}".`);
|
|
3976
4276
|
nodeIds.add(node.id);
|
|
4277
|
+
const portIds = /* @__PURE__ */ new Set();
|
|
4278
|
+
for (const port of node.ports ?? []) {
|
|
4279
|
+
if (typeof port.id !== "string" || port.id.trim().length === 0) {
|
|
4280
|
+
throw new Error(`GraphDiagram node "${node.id}" port id must be a non-empty string.`);
|
|
4281
|
+
}
|
|
4282
|
+
if (portIds.has(port.id)) throw new Error(`GraphDiagram node "${node.id}" received duplicate port "${port.id}".`);
|
|
4283
|
+
portIds.add(port.id);
|
|
4284
|
+
if (!["top", "right", "bottom", "left"].includes(port.side)) {
|
|
4285
|
+
throw new Error(`GraphDiagram node "${node.id}" port "${port.id}" must use side "top", "right", "bottom", or "left".`);
|
|
4286
|
+
}
|
|
4287
|
+
if (port.offset != null && (!Number.isFinite(port.offset) || port.offset < 0 || port.offset > 1)) {
|
|
4288
|
+
throw new Error(`GraphDiagram node "${node.id}" port "${port.id}" offset must be between 0 and 1.`);
|
|
4289
|
+
}
|
|
4290
|
+
}
|
|
3977
4291
|
}
|
|
3978
4292
|
const groupsById = /* @__PURE__ */ new Map();
|
|
3979
4293
|
for (const group of groups) {
|
|
@@ -4017,6 +4331,20 @@ function validateGraphDiagramSpec(nodes, edges, groups, layoutMode) {
|
|
|
4017
4331
|
if (edgeIds.has(edge.id)) throw new Error(`GraphDiagram received duplicate edge id "${edge.id}".`);
|
|
4018
4332
|
edgeIds.add(edge.id);
|
|
4019
4333
|
}
|
|
4334
|
+
for (const side of ["from", "to"]) {
|
|
4335
|
+
const reference = side === "from" ? edge.fromPort : edge.toPort;
|
|
4336
|
+
const endpointSide = side === "from" ? edge.fromSide : edge.toSide;
|
|
4337
|
+
const node = nodes.find((candidate) => candidate.id === edge[side]);
|
|
4338
|
+
if (reference != null && !node.ports?.some((port) => port.id === reference)) {
|
|
4339
|
+
throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" references missing ${side} port "${reference}" on node "${node.id}".`);
|
|
4340
|
+
}
|
|
4341
|
+
if (endpointSide != null && !["top", "right", "bottom", "left"].includes(endpointSide)) {
|
|
4342
|
+
throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" ${side}Side must be "top", "right", "bottom", or "left".`);
|
|
4343
|
+
}
|
|
4344
|
+
if (reference != null && endpointSide != null) {
|
|
4345
|
+
throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" cannot combine ${side}Port and ${side}Side.`);
|
|
4346
|
+
}
|
|
4347
|
+
}
|
|
4020
4348
|
validateDiagramHref(edge.href, `edge "${edge.id ?? `${edge.from}" -> "${edge.to}`}"`);
|
|
4021
4349
|
}
|
|
4022
4350
|
for (const node of nodes) {
|
|
@@ -4092,6 +4420,8 @@ function GraphDiagram({
|
|
|
4092
4420
|
nodeGap = 34,
|
|
4093
4421
|
rankGap = 64,
|
|
4094
4422
|
edgeGap = 14,
|
|
4423
|
+
routing = "dagre",
|
|
4424
|
+
routingClearance = 12,
|
|
4095
4425
|
sizing = "content",
|
|
4096
4426
|
iconSize = 20,
|
|
4097
4427
|
id,
|
|
@@ -4100,6 +4430,8 @@ function GraphDiagram({
|
|
|
4100
4430
|
description
|
|
4101
4431
|
}) {
|
|
4102
4432
|
if (id != null && id.trim().length === 0) throw new Error("GraphDiagram id must not be empty.");
|
|
4433
|
+
if (!["dagre", "straight", "orthogonal"].includes(routing)) throw new Error('GraphDiagram routing must be "dagre", "straight", or "orthogonal".');
|
|
4434
|
+
if (!Number.isFinite(routingClearance) || routingClearance <= 0) throw new Error("GraphDiagram routingClearance must be a finite positive number.");
|
|
4103
4435
|
const fullyPositioned = nodes.filter((node) => node.x != null && node.y != null).length;
|
|
4104
4436
|
const partiallyPositioned = nodes.some((node) => node.x == null !== (node.y == null));
|
|
4105
4437
|
if (partiallyPositioned || fullyPositioned > 0 && fullyPositioned < nodes.length) {
|
|
@@ -4194,7 +4526,30 @@ function GraphDiagram({
|
|
|
4194
4526
|
} else {
|
|
4195
4527
|
layout = manualGraphLayout(nodes, resolvedWidth, resolvedHeight, nodeWidth, nodeHeight, padding);
|
|
4196
4528
|
}
|
|
4529
|
+
const anchored = (edge) => edge.fromPort != null || edge.toPort != null || edge.fromSide != null || edge.toSide != null;
|
|
4530
|
+
const orthogonalEdges = edges.flatMap((edge, index) => routing === "orthogonal" || routing === "dagre" && anchored(edge) || routing === "straight" && edge.from === edge.to ? [{ edge, index }] : []);
|
|
4531
|
+
const routed = routeOrthogonalGraph(
|
|
4532
|
+
Array.from(layout.values()),
|
|
4533
|
+
orthogonalEdges.map(({ edge }) => edge),
|
|
4534
|
+
resolvedWidth,
|
|
4535
|
+
resolvedHeight,
|
|
4536
|
+
routingClearance,
|
|
4537
|
+
edgeGap,
|
|
4538
|
+
groupLayout.map((group) => ({
|
|
4539
|
+
left: group.cx - group.width / 2,
|
|
4540
|
+
right: group.cx + group.width / 2,
|
|
4541
|
+
top: group.cy - group.height / 2,
|
|
4542
|
+
bottom: group.cy - group.height / 2 + 26
|
|
4543
|
+
}))
|
|
4544
|
+
);
|
|
4545
|
+
const orthogonalPoints = new Map(Array.from(routed.routes, ([index, points]) => [orthogonalEdges[index].index, points]));
|
|
4546
|
+
const failedIndexes = new Set(routed.failures.map((failure) => orthogonalEdges[failure.index].index));
|
|
4547
|
+
const routingFailures = routed.failures.map((failure) => {
|
|
4548
|
+
const { edge } = orthogonalEdges[failure.index];
|
|
4549
|
+
return `Connector "${edge.from}" -> "${edge.to}" was not drawn: ${failure.reason}.`;
|
|
4550
|
+
});
|
|
4197
4551
|
const edgeLayouts = edges.flatMap((edge, index) => {
|
|
4552
|
+
if (failedIndexes.has(index)) return [];
|
|
4198
4553
|
const from = layout.get(edge.from);
|
|
4199
4554
|
const to = layout.get(edge.to);
|
|
4200
4555
|
if (!from || !to) return [];
|
|
@@ -4223,14 +4578,16 @@ function GraphDiagram({
|
|
|
4223
4578
|
{ x: from.cx + 10, y: from.cy - from.height / 2 - loopClearance },
|
|
4224
4579
|
{ x: from.cx + 10, y: from.cy - from.height / 2 }
|
|
4225
4580
|
] : void 0;
|
|
4226
|
-
const
|
|
4581
|
+
const routedPoints = orthogonalPoints.get(index);
|
|
4582
|
+
const points = routedPoints ?? (routing === "straight" ? straightGraphRoute(from, to, edge) : automatic?.points.length ? automatic.points : manualLoopPoints ?? [
|
|
4227
4583
|
{ x: from.cx + dx * fromScale, y: from.cy + dy * fromScale },
|
|
4228
4584
|
{ x: to.cx - dx * toScale, y: to.cy - dy * toScale }
|
|
4229
|
-
];
|
|
4585
|
+
]);
|
|
4230
4586
|
const manualLoopLabel = manualLoopPoints ? {
|
|
4231
4587
|
x: from.cx + from.width / 2 + loopClearance,
|
|
4232
4588
|
y: from.cy - from.height / 2 - loopClearance / 2
|
|
4233
4589
|
} : void 0;
|
|
4590
|
+
const routedLabel = routedPoints || routing === "straight" ? routingLabelPosition(points) : void 0;
|
|
4234
4591
|
return [{
|
|
4235
4592
|
...edge,
|
|
4236
4593
|
index,
|
|
@@ -4238,14 +4595,14 @@ function GraphDiagram({
|
|
|
4238
4595
|
color,
|
|
4239
4596
|
markerId,
|
|
4240
4597
|
points,
|
|
4241
|
-
labelX: automatic?.labelX ?? manualLoopLabel?.x ?? (points[0].x + points[points.length - 1].x) / 2,
|
|
4242
|
-
labelY: automatic?.labelY ?? manualLoopLabel?.y ?? (points[0].y + points[points.length - 1].y) / 2
|
|
4598
|
+
labelX: routedLabel?.x ?? automatic?.labelX ?? manualLoopLabel?.x ?? (points[0].x + points[points.length - 1].x) / 2,
|
|
4599
|
+
labelY: routedLabel?.y ?? automatic?.labelY ?? manualLoopLabel?.y ?? (points[0].y + points[points.length - 1].y) / 2
|
|
4243
4600
|
}];
|
|
4244
4601
|
});
|
|
4245
4602
|
const crossings = connectorCrossings(edgeLayouts);
|
|
4246
4603
|
const labelCollisions = connectorLabelCollisions(edgeLayouts, layout, groupLayout);
|
|
4247
4604
|
const crowdedEndpoints = crowdedConnectorEndpoints(edgeLayouts);
|
|
4248
|
-
const parallelGroups = parallelConnectorGroups(edgeLayouts);
|
|
4605
|
+
const parallelGroups = parallelConnectorGroups(edgeLayouts.filter((edge) => !orthogonalPoints.has(edge.index)));
|
|
4249
4606
|
const groupElements = groupLayout.map((group) => {
|
|
4250
4607
|
const accent = group.muted ? c.textMuted : getToneColor(group.tone ?? "blue", c);
|
|
4251
4608
|
return import_react7.default.createElement("div", {
|
|
@@ -4260,8 +4617,8 @@ function GraphDiagram({
|
|
|
4260
4617
|
display: "flex",
|
|
4261
4618
|
boxSizing: "border-box",
|
|
4262
4619
|
borderRadius: c.preset === "engineering" ? 6 : 12,
|
|
4263
|
-
border: `${c.preset === "engineering" ? 1.25 : 1.5}px ${group.muted ? "dashed" : "solid"} ${accent
|
|
4264
|
-
backgroundColor:
|
|
4620
|
+
border: `${c.preset === "engineering" ? 1.25 : 1.5}px ${group.muted ? "dashed" : "solid"} ${withColorAlpha(accent, (group.muted ? 85 : 119) / 255)}`,
|
|
4621
|
+
backgroundColor: withColorAlpha(accent, (c.preset === "engineering" ? 8 : 13) / 255),
|
|
4265
4622
|
opacity: group.muted ? 0.68 : 1
|
|
4266
4623
|
}
|
|
4267
4624
|
}, import_react7.default.createElement(
|
|
@@ -4311,6 +4668,8 @@ function GraphDiagram({
|
|
|
4311
4668
|
"data-vizmatic-connector-label-collisions": labelCollisions,
|
|
4312
4669
|
"data-vizmatic-crowded-connector-endpoints": crowdedEndpoints,
|
|
4313
4670
|
"data-vizmatic-parallel-connector-groups": parallelGroups,
|
|
4671
|
+
"data-vizmatic-unrouted-connectors": routingFailures.length,
|
|
4672
|
+
"data-vizmatic-routing-failures": routingFailures.length ? JSON.stringify(routingFailures) : void 0,
|
|
4314
4673
|
style: {
|
|
4315
4674
|
position: "relative",
|
|
4316
4675
|
display: "flex",
|
|
@@ -4429,7 +4788,7 @@ function GraphDiagram({
|
|
|
4429
4788
|
boxSizing: "border-box",
|
|
4430
4789
|
borderRadius: c.preset === "engineering" ? 5 : 10,
|
|
4431
4790
|
backgroundColor: node.muted ? c.bgSubtle : fill,
|
|
4432
|
-
border: `${c.preset === "engineering" ? 1.25 : 1.5}px solid ${node.muted ? c.borderLight :
|
|
4791
|
+
border: `${c.preset === "engineering" ? 1.25 : 1.5}px solid ${node.muted ? c.borderLight : c.preset === "engineering" ? accent : withColorAlpha(accent, 136 / 255)}`,
|
|
4433
4792
|
...!node.muted && c.preset !== "engineering" ? { boxShadow: `0 8px 18px ${c.shadow}` } : {},
|
|
4434
4793
|
opacity: node.muted ? 0.62 : 1,
|
|
4435
4794
|
color: c.preset === "engineering" ? c.textPrimary : accentText,
|
|
@@ -4653,7 +5012,7 @@ function TreeDiagram({
|
|
|
4653
5012
|
boxSizing: "border-box",
|
|
4654
5013
|
borderRadius: 8,
|
|
4655
5014
|
backgroundColor: node.muted ? c.bgSubtle : c.bgCard,
|
|
4656
|
-
border: `1.5px solid ${node.muted ? c.borderLight :
|
|
5015
|
+
border: `1.5px solid ${node.muted ? c.borderLight : withColorAlpha(accent, 136 / 255)}`,
|
|
4657
5016
|
...!node.muted ? { boxShadow: `0 8px 18px ${c.shadow}` } : {},
|
|
4658
5017
|
opacity: node.muted ? 0.62 : 1,
|
|
4659
5018
|
color: accentText,
|
|
@@ -4713,7 +5072,7 @@ function CalloutCard({
|
|
|
4713
5072
|
padding,
|
|
4714
5073
|
borderRadius: engineering ? 5 : 10,
|
|
4715
5074
|
boxSizing: "border-box",
|
|
4716
|
-
...engineering ? { backgroundColor: getToneFill(tone, c), color: c.textPrimary, border: `1px solid ${accent}` } : filled ? { backgroundImage: getToneGradient(tone), color: c.textOnColor, border: `1px solid ${accent}
|
|
5075
|
+
...engineering ? { backgroundColor: getToneFill(tone, c), color: c.textPrimary, border: `1px solid ${accent}` } : filled ? { backgroundImage: getToneGradient(tone), color: c.textOnColor, border: `1px solid ${withColorAlpha(accent, 0)}` } : { backgroundColor: c.bgCard, color: c.textPrimary, border: `1px solid ${withColorAlpha(accent, 102 / 255)}` },
|
|
4717
5076
|
display: "flex",
|
|
4718
5077
|
flexDirection: "column",
|
|
4719
5078
|
alignItems: align === "center" ? "center" : "flex-start",
|
|
@@ -5059,8 +5418,8 @@ function SequenceDiagram({
|
|
|
5059
5418
|
height: spanHeight,
|
|
5060
5419
|
display: "flex",
|
|
5061
5420
|
boxSizing: "border-box",
|
|
5062
|
-
border: `1.25px ${span.fragment.muted ? "dotted" : "dashed"} ${accent
|
|
5063
|
-
backgroundColor:
|
|
5421
|
+
border: `1.25px ${span.fragment.muted ? "dotted" : "dashed"} ${withColorAlpha(accent, (span.fragment.muted ? 85 : 153) / 255)}`,
|
|
5422
|
+
backgroundColor: withColorAlpha(accent, 11 / 255),
|
|
5064
5423
|
borderRadius: c.preset === "engineering" ? 4 : 8,
|
|
5065
5424
|
pointerEvents: "none"
|
|
5066
5425
|
}
|
|
@@ -5210,7 +5569,7 @@ function SequenceDiagram({
|
|
|
5210
5569
|
padding: "6px 9px",
|
|
5211
5570
|
borderRadius: c.preset === "engineering" ? 3 : 7,
|
|
5212
5571
|
backgroundColor: note.muted ? c.bgSubtle : getToneFill(tone, c),
|
|
5213
|
-
border: `1px solid ${accent
|
|
5572
|
+
border: `1px solid ${withColorAlpha(accent, (note.muted ? 102 : 153) / 255)}`,
|
|
5214
5573
|
color: note.muted ? c.textMuted : getReadableTextColor(getToneFill(tone, c), c),
|
|
5215
5574
|
fontFamily: c.fontSans,
|
|
5216
5575
|
fontSize: 11,
|
|
@@ -5568,6 +5927,8 @@ function DataflowDiagram({
|
|
|
5568
5927
|
nodeGap,
|
|
5569
5928
|
rankGap,
|
|
5570
5929
|
edgeGap,
|
|
5930
|
+
routing,
|
|
5931
|
+
routingClearance,
|
|
5571
5932
|
sizing,
|
|
5572
5933
|
iconSize
|
|
5573
5934
|
}) {
|
|
@@ -5593,6 +5954,8 @@ function DataflowDiagram({
|
|
|
5593
5954
|
nodeGap,
|
|
5594
5955
|
rankGap,
|
|
5595
5956
|
edgeGap,
|
|
5957
|
+
routing,
|
|
5958
|
+
routingClearance,
|
|
5596
5959
|
sizing,
|
|
5597
5960
|
iconSize
|
|
5598
5961
|
});
|
|
@@ -5721,8 +6084,8 @@ function portIdentity(port) {
|
|
|
5721
6084
|
function portText(port) {
|
|
5722
6085
|
if (typeof port === "string" || typeof port === "number") return String(port);
|
|
5723
6086
|
if (port.label) return port.label;
|
|
5724
|
-
const
|
|
5725
|
-
return [port.protocol,
|
|
6087
|
+
const endpoint2 = port.port ?? port.id;
|
|
6088
|
+
return [port.protocol, endpoint2 == null ? void 0 : String(endpoint2)].filter(Boolean).join("/") || port.direction || "port";
|
|
5726
6089
|
}
|
|
5727
6090
|
function portForReference(node, reference) {
|
|
5728
6091
|
if (reference == null) return void 0;
|
|
@@ -5832,6 +6195,9 @@ function compileDeployment(spec) {
|
|
|
5832
6195
|
const boundaries = spec.boundaries ?? [];
|
|
5833
6196
|
const connections = spec.connections ?? [];
|
|
5834
6197
|
validateDeploymentSpec(boundaries, spec.nodes, connections);
|
|
6198
|
+
const anchorPorts = spec.routing != null && spec.routing !== "dagre";
|
|
6199
|
+
const incomingSide = spec.direction === "TB" ? "top" : spec.direction === "BT" ? "bottom" : spec.direction === "RL" ? "right" : "left";
|
|
6200
|
+
const outgoingSide = spec.direction === "TB" ? "bottom" : spec.direction === "BT" ? "top" : spec.direction === "RL" ? "left" : "right";
|
|
5835
6201
|
const groups = boundaries.map((boundary) => ({
|
|
5836
6202
|
id: boundary.id,
|
|
5837
6203
|
label: boundary.label,
|
|
@@ -5858,7 +6224,16 @@ function compileDeployment(spec) {
|
|
|
5858
6224
|
height: node.height,
|
|
5859
6225
|
group: node.boundary,
|
|
5860
6226
|
icon: node.icon ?? nodeKindIcons[kind],
|
|
5861
|
-
iconSize: node.iconSize
|
|
6227
|
+
iconSize: node.iconSize,
|
|
6228
|
+
ports: anchorPorts ? nodePorts.map((port, index) => {
|
|
6229
|
+
const incoming = typeof port === "object" ? port.direction === "ingress" : false;
|
|
6230
|
+
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));
|
|
6231
|
+
return {
|
|
6232
|
+
id: portIdentity(port),
|
|
6233
|
+
side: typeof port === "object" && port.side != null ? port.side : incoming || targetOnly ? incomingSide : outgoingSide,
|
|
6234
|
+
offset: typeof port === "object" && port.offset != null ? port.offset : (index + 1) / (nodePorts.length + 1)
|
|
6235
|
+
};
|
|
6236
|
+
}) : void 0
|
|
5862
6237
|
};
|
|
5863
6238
|
});
|
|
5864
6239
|
const edges = connections.map((connection) => {
|
|
@@ -5882,7 +6257,11 @@ function compileDeployment(spec) {
|
|
|
5882
6257
|
arrow: connection.arrow ?? "forward",
|
|
5883
6258
|
label: connectionLabel(connection, sourcePort ?? fallbackFromPort, targetPort ?? fallbackToPort),
|
|
5884
6259
|
href: connection.href,
|
|
5885
|
-
title: connection.title
|
|
6260
|
+
title: connection.title,
|
|
6261
|
+
fromPort: anchorPorts && fromReference != null ? String(fromReference) : void 0,
|
|
6262
|
+
toPort: anchorPorts && toReference != null ? String(toReference) : void 0,
|
|
6263
|
+
fromSide: connection.fromSide,
|
|
6264
|
+
toSide: connection.toSide
|
|
5886
6265
|
};
|
|
5887
6266
|
});
|
|
5888
6267
|
return {
|
|
@@ -5900,7 +6279,7 @@ function DeploymentDiagram({
|
|
|
5900
6279
|
ariaLabel = "Deployment diagram",
|
|
5901
6280
|
...graphProps
|
|
5902
6281
|
}) {
|
|
5903
|
-
const compiled = compileDeployment({ nodes, boundaries, connections, ariaLabel });
|
|
6282
|
+
const compiled = compileDeployment({ nodes, boundaries, connections, ariaLabel, direction: graphProps.direction, routing: graphProps.routing });
|
|
5904
6283
|
return GraphDiagram({
|
|
5905
6284
|
...graphProps,
|
|
5906
6285
|
c,
|
|
@@ -6126,11 +6505,11 @@ function compileTransformer(spec) {
|
|
|
6126
6505
|
for (const route of routes) {
|
|
6127
6506
|
const kind = resolveRouteKind(route);
|
|
6128
6507
|
const endpoints = expandedRouteEndpoints(route, repeatCounts, expandRepeats);
|
|
6129
|
-
for (const [index,
|
|
6508
|
+
for (const [index, endpoint2] of endpoints.entries()) {
|
|
6130
6509
|
edges.push({
|
|
6131
6510
|
id: route.id == null ? void 0 : endpoints.length === 1 ? route.id : `${route.id}-${index + 1}`,
|
|
6132
|
-
from:
|
|
6133
|
-
to:
|
|
6511
|
+
from: endpoint2.from,
|
|
6512
|
+
to: endpoint2.to,
|
|
6134
6513
|
tone: route.tone ?? routeTones[kind],
|
|
6135
6514
|
muted: route.muted,
|
|
6136
6515
|
kind: graphRouteKind(kind),
|
|
@@ -6365,8 +6744,8 @@ function TiledMatrix({
|
|
|
6365
6744
|
height: cellSize,
|
|
6366
6745
|
boxSizing: "border-box",
|
|
6367
6746
|
borderRadius: Math.max(2, Math.min(6, Math.round(cellSize * 0.18))),
|
|
6368
|
-
backgroundColor: region ?
|
|
6369
|
-
border: `1px solid ${region ?
|
|
6747
|
+
backgroundColor: region ? withColorAlpha(accent, 66 / 255) : muted ? c.bgSubtle : withColorAlpha(baseAccent, 15 / 255),
|
|
6748
|
+
border: `1px solid ${region ? withColorAlpha(accent, 170 / 255) : c.borderSubtle}`,
|
|
6370
6749
|
opacity: muted ? 0.55 : 1
|
|
6371
6750
|
}
|
|
6372
6751
|
});
|
|
@@ -6541,7 +6920,7 @@ function Grid({
|
|
|
6541
6920
|
const config = isGridCell(cell) ? cell : {};
|
|
6542
6921
|
const toneColor = config.tone ? getToneColor(config.tone, c) : void 0;
|
|
6543
6922
|
const isHeader = rowIndex < headerRows || colIndex < headerCols;
|
|
6544
|
-
const backgroundColor = config.backgroundColor ?? (toneColor ?
|
|
6923
|
+
const backgroundColor = config.backgroundColor ?? (toneColor ? withColorAlpha(toneColor, 34 / 255) : isHeader ? c.bgSubtle : c.bgHover);
|
|
6545
6924
|
const toneTextColor = config.tone ? getReadableToneColor(config.tone, c, backgroundColor, c.bgHover) : void 0;
|
|
6546
6925
|
return {
|
|
6547
6926
|
width: cellWidth,
|
|
@@ -6551,7 +6930,7 @@ function Grid({
|
|
|
6551
6930
|
justifyContent: "center",
|
|
6552
6931
|
borderRadius: radius,
|
|
6553
6932
|
backgroundColor,
|
|
6554
|
-
border: `1px solid ${config.borderColor ?? (toneColor ?
|
|
6933
|
+
border: `1px solid ${config.borderColor ?? (toneColor ? withColorAlpha(toneColor, 85 / 255) : c.borderSubtle)}`,
|
|
6555
6934
|
color: config.color ?? (toneTextColor ?? (isHeader ? c.textPrimary : c.textSecondary)),
|
|
6556
6935
|
...config.opacity !== void 0 ? { opacity: config.opacity } : {},
|
|
6557
6936
|
fontFamily: "JetBrains Mono",
|
|
@@ -6805,7 +7184,138 @@ function AxisPlot({
|
|
|
6805
7184
|
}
|
|
6806
7185
|
|
|
6807
7186
|
// src/primitives/charts.ts
|
|
7187
|
+
var import_react12 = __toESM(require("react"), 1);
|
|
7188
|
+
|
|
7189
|
+
// src/canvas-chart-fit.ts
|
|
6808
7190
|
var import_react11 = __toESM(require("react"), 1);
|
|
7191
|
+
var CANVAS_CHART_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.canvasChartComponent");
|
|
7192
|
+
var CHART_FRAME_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.chartFrameComponent");
|
|
7193
|
+
var FIT_PROP = "__vizmaticCanvasChartFit";
|
|
7194
|
+
var SCOPE_PROP = "data-vizmatic-chart-fit-scope";
|
|
7195
|
+
var VIEWPORT_PROP = "data-vizmatic-chart-fit-viewport";
|
|
7196
|
+
function isCanvasChart(component) {
|
|
7197
|
+
return typeof component === "function" && Boolean(component[CANVAS_CHART_COMPONENT]);
|
|
7198
|
+
}
|
|
7199
|
+
function CanvasChartFit({ children, width, height }) {
|
|
7200
|
+
let chart = children;
|
|
7201
|
+
for (let depth = 0; (0, import_react11.isValidElement)(chart) && typeof chart.type === "function" && depth < 16; depth += 1) {
|
|
7202
|
+
if (chart.type[CHART_FRAME_COMPONENT]) {
|
|
7203
|
+
const props = chart.props;
|
|
7204
|
+
const padding = typeof props.padding === "number" ? props.padding : 16;
|
|
7205
|
+
chart = import_react11.default.cloneElement(chart, {
|
|
7206
|
+
...props,
|
|
7207
|
+
width: typeof props.width === "number" ? props.width + 2 * (padding + 1) : props.width,
|
|
7208
|
+
height: void 0
|
|
7209
|
+
});
|
|
7210
|
+
break;
|
|
7211
|
+
}
|
|
7212
|
+
chart = chart.type(chart.props);
|
|
7213
|
+
}
|
|
7214
|
+
return import_react11.default.createElement("div", {
|
|
7215
|
+
[FIT_PROP]: { width, height },
|
|
7216
|
+
style: { position: "relative", display: "flex", width, height, flexShrink: 0 }
|
|
7217
|
+
}, import_react11.default.createElement("div", {
|
|
7218
|
+
style: { position: "absolute", left: 0, top: 0, display: "flex", alignItems: "flex-start" }
|
|
7219
|
+
}, chart));
|
|
7220
|
+
}
|
|
7221
|
+
function prepareChartFits(element) {
|
|
7222
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
7223
|
+
const visit = (node, scope) => {
|
|
7224
|
+
if (Array.isArray(node)) return node.map((child) => visit(child, scope));
|
|
7225
|
+
if (!(0, import_react11.isValidElement)(node)) return node;
|
|
7226
|
+
if (typeof node.type === "function") {
|
|
7227
|
+
const resolved = visit(node.type(node.props), scope);
|
|
7228
|
+
return node.key != null && (0, import_react11.isValidElement)(resolved) ? import_react11.default.cloneElement(resolved, { key: node.key }) : resolved;
|
|
7229
|
+
}
|
|
7230
|
+
const size = node.props[FIT_PROP];
|
|
7231
|
+
const props = { ...node.props };
|
|
7232
|
+
delete props[FIT_PROP];
|
|
7233
|
+
if (size) {
|
|
7234
|
+
const id = String(sizes.size);
|
|
7235
|
+
sizes.set(id, size);
|
|
7236
|
+
props[VIEWPORT_PROP] = id;
|
|
7237
|
+
return import_react11.default.cloneElement(node, props, visit(node.props.children, id));
|
|
7238
|
+
}
|
|
7239
|
+
if (scope !== void 0 && typeof node.type === "string") props[SCOPE_PROP] = scope;
|
|
7240
|
+
const children = node.props.children;
|
|
7241
|
+
return children === void 0 ? import_react11.default.cloneElement(node, props) : import_react11.default.cloneElement(node, props, visit(children, scope));
|
|
7242
|
+
};
|
|
7243
|
+
return { element: visit(element), sizes };
|
|
7244
|
+
}
|
|
7245
|
+
function fittedTree(element, geometry) {
|
|
7246
|
+
if (Array.isArray(element)) return element.map((child) => fittedTree(child, geometry));
|
|
7247
|
+
if (!(0, import_react11.isValidElement)(element)) return element;
|
|
7248
|
+
const id = element.props[VIEWPORT_PROP];
|
|
7249
|
+
const children = element.props.children;
|
|
7250
|
+
if (typeof id === "string") {
|
|
7251
|
+
const fit = geometry.get(id);
|
|
7252
|
+
const content = import_react11.default.Children.only(children);
|
|
7253
|
+
return import_react11.default.cloneElement(element, {}, import_react11.default.cloneElement(content, { style: {
|
|
7254
|
+
...content.props.style,
|
|
7255
|
+
left: fit.left,
|
|
7256
|
+
top: fit.top,
|
|
7257
|
+
transform: `scale(${fit.scale})`,
|
|
7258
|
+
transformOrigin: "top left"
|
|
7259
|
+
} }));
|
|
7260
|
+
}
|
|
7261
|
+
return children === void 0 ? element : import_react11.default.cloneElement(element, {}, fittedTree(children, geometry));
|
|
7262
|
+
}
|
|
7263
|
+
async function renderWithCanvasChartFit(render, element, options) {
|
|
7264
|
+
const prepared = prepareChartFits(element);
|
|
7265
|
+
if (!prepared.sizes.size) return render(prepared.element, options);
|
|
7266
|
+
const viewports = /* @__PURE__ */ new Map();
|
|
7267
|
+
const bounds = /* @__PURE__ */ new Map();
|
|
7268
|
+
await render(prepared.element, { ...options, onNodeDetected(node) {
|
|
7269
|
+
const viewport = node.props[VIEWPORT_PROP];
|
|
7270
|
+
if (typeof viewport === "string") viewports.set(viewport, node);
|
|
7271
|
+
const id = node.props[SCOPE_PROP];
|
|
7272
|
+
if (typeof id !== "string" || node.width <= 0 || node.height <= 0) return;
|
|
7273
|
+
const prior = bounds.get(id);
|
|
7274
|
+
bounds.set(id, {
|
|
7275
|
+
left: Math.min(prior?.left ?? Infinity, node.left),
|
|
7276
|
+
top: Math.min(prior?.top ?? Infinity, node.top),
|
|
7277
|
+
right: Math.max(prior?.right ?? -Infinity, node.left + node.width),
|
|
7278
|
+
bottom: Math.max(prior?.bottom ?? -Infinity, node.top + node.height)
|
|
7279
|
+
});
|
|
7280
|
+
} });
|
|
7281
|
+
const geometry = /* @__PURE__ */ new Map();
|
|
7282
|
+
for (const [id, size] of prepared.sizes) {
|
|
7283
|
+
const viewport = viewports.get(id);
|
|
7284
|
+
const measured = bounds.get(id);
|
|
7285
|
+
if (!viewport || !measured) throw new Error("Could not measure the chart inside CanvasItem.");
|
|
7286
|
+
const width = measured.right - measured.left, height = measured.bottom - measured.top;
|
|
7287
|
+
const scale = Math.min(size.width / width, size.height / height);
|
|
7288
|
+
if (!Number.isFinite(scale) || scale <= 0) throw new Error("CanvasItem charts require positive, finite dimensions.");
|
|
7289
|
+
geometry.set(id, {
|
|
7290
|
+
...size,
|
|
7291
|
+
scale,
|
|
7292
|
+
left: (size.width - width * scale) / 2 - (measured.left - viewport.left) * scale,
|
|
7293
|
+
top: (size.height - height * scale) / 2 - (measured.top - viewport.top) * scale
|
|
7294
|
+
});
|
|
7295
|
+
}
|
|
7296
|
+
const finalViewports = /* @__PURE__ */ new Map();
|
|
7297
|
+
return render(fittedTree(prepared.element, geometry), { ...options, onNodeDetected(node) {
|
|
7298
|
+
const viewport = node.props[VIEWPORT_PROP];
|
|
7299
|
+
if (typeof viewport === "string") finalViewports.set(viewport, node);
|
|
7300
|
+
const id = node.props[SCOPE_PROP];
|
|
7301
|
+
const fit = typeof id === "string" ? geometry.get(id) : void 0;
|
|
7302
|
+
const origin = typeof id === "string" ? finalViewports.get(id) : void 0;
|
|
7303
|
+
if (fit && origin) {
|
|
7304
|
+
const left = origin.left + fit.left, top = origin.top + fit.top;
|
|
7305
|
+
const style = node.props.style ?? {};
|
|
7306
|
+
options.onNodeDetected?.({
|
|
7307
|
+
...node,
|
|
7308
|
+
left: left + (node.left - left) * fit.scale,
|
|
7309
|
+
top: top + (node.top - top) * fit.scale,
|
|
7310
|
+
width: node.width * fit.scale,
|
|
7311
|
+
height: node.height * fit.scale,
|
|
7312
|
+
props: { ...node.props, style: { ...style, ...typeof style.fontSize === "number" ? { fontSize: style.fontSize * fit.scale } : {} } }
|
|
7313
|
+
});
|
|
7314
|
+
} else options.onNodeDetected?.(node);
|
|
7315
|
+
} });
|
|
7316
|
+
}
|
|
7317
|
+
|
|
7318
|
+
// src/primitives/charts.ts
|
|
6809
7319
|
var chartPalette = ["primary", "secondary", "positive", "warning", "info", "accent", "critical"];
|
|
6810
7320
|
function isColorName(value) {
|
|
6811
7321
|
return chartPalette.includes(value) || value === "neutral";
|
|
@@ -6895,7 +7405,7 @@ function chartLabel(key, text, x, y, c, options = {}) {
|
|
|
6895
7405
|
);
|
|
6896
7406
|
transform = void 0;
|
|
6897
7407
|
}
|
|
6898
|
-
return
|
|
7408
|
+
return import_react12.default.createElement("div", {
|
|
6899
7409
|
key,
|
|
6900
7410
|
style: {
|
|
6901
7411
|
position: "absolute",
|
|
@@ -6937,7 +7447,10 @@ function pointLabelPlacement(x, y, plot, index, width = 70) {
|
|
|
6937
7447
|
}
|
|
6938
7448
|
};
|
|
6939
7449
|
}
|
|
6940
|
-
function ChartFrame({
|
|
7450
|
+
function ChartFrame(props) {
|
|
7451
|
+
return import_react12.default.createElement(ChartFrameContent, props);
|
|
7452
|
+
}
|
|
7453
|
+
function ChartFrameContent({
|
|
6941
7454
|
children,
|
|
6942
7455
|
c,
|
|
6943
7456
|
title,
|
|
@@ -6948,7 +7461,7 @@ function ChartFrame({
|
|
|
6948
7461
|
height,
|
|
6949
7462
|
padding = 16
|
|
6950
7463
|
}) {
|
|
6951
|
-
return
|
|
7464
|
+
return import_react12.default.createElement(
|
|
6952
7465
|
"div",
|
|
6953
7466
|
{
|
|
6954
7467
|
style: {
|
|
@@ -6965,20 +7478,20 @@ function ChartFrame({
|
|
|
6965
7478
|
boxShadow: `0 9px 24px ${c.shadow}`
|
|
6966
7479
|
}
|
|
6967
7480
|
},
|
|
6968
|
-
(title || subtitle) &&
|
|
7481
|
+
(title || subtitle) && import_react12.default.createElement(
|
|
6969
7482
|
"div",
|
|
6970
7483
|
{
|
|
6971
7484
|
style: { display: "flex", flexDirection: "column", gap: 4, minWidth: 0, maxWidth: "100%" }
|
|
6972
7485
|
},
|
|
6973
|
-
title &&
|
|
7486
|
+
title && import_react12.default.createElement("div", {
|
|
6974
7487
|
style: { ...typography.small, ...textFitStyle(), color: c.textPrimary, fontWeight: 900 }
|
|
6975
7488
|
}, title),
|
|
6976
|
-
subtitle &&
|
|
7489
|
+
subtitle && import_react12.default.createElement("div", {
|
|
6977
7490
|
style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary, lineHeight: 1.35 }
|
|
6978
7491
|
}, subtitle)
|
|
6979
7492
|
),
|
|
6980
7493
|
children,
|
|
6981
|
-
(legend || footer) &&
|
|
7494
|
+
(legend || footer) && import_react12.default.createElement(
|
|
6982
7495
|
"div",
|
|
6983
7496
|
{
|
|
6984
7497
|
style: {
|
|
@@ -6989,18 +7502,18 @@ function ChartFrame({
|
|
|
6989
7502
|
minHeight: 18
|
|
6990
7503
|
}
|
|
6991
7504
|
},
|
|
6992
|
-
legend &&
|
|
7505
|
+
legend && import_react12.default.createElement(
|
|
6993
7506
|
"div",
|
|
6994
7507
|
{
|
|
6995
7508
|
style: { display: "flex", alignItems: "center", gap: 12, flexWrap: "wrap", minWidth: 0 }
|
|
6996
7509
|
},
|
|
6997
|
-
...legend.map((item, index) =>
|
|
7510
|
+
...legend.map((item, index) => import_react12.default.createElement(
|
|
6998
7511
|
"div",
|
|
6999
7512
|
{
|
|
7000
7513
|
key: `${item.label}-${index}`,
|
|
7001
7514
|
style: { display: "flex", alignItems: "center", gap: 6, minWidth: 0 }
|
|
7002
7515
|
},
|
|
7003
|
-
|
|
7516
|
+
import_react12.default.createElement("span", {
|
|
7004
7517
|
style: {
|
|
7005
7518
|
width: 14,
|
|
7006
7519
|
height: 3,
|
|
@@ -7009,17 +7522,18 @@ function ChartFrame({
|
|
|
7009
7522
|
display: "flex"
|
|
7010
7523
|
}
|
|
7011
7524
|
}),
|
|
7012
|
-
|
|
7525
|
+
import_react12.default.createElement("span", {
|
|
7013
7526
|
style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary }
|
|
7014
7527
|
}, item.label)
|
|
7015
7528
|
))
|
|
7016
7529
|
),
|
|
7017
|
-
footer &&
|
|
7530
|
+
footer && import_react12.default.createElement("div", {
|
|
7018
7531
|
style: { ...typography.tiny, ...textFitStyle("right"), color: c.textMuted }
|
|
7019
7532
|
}, footer)
|
|
7020
7533
|
)
|
|
7021
7534
|
);
|
|
7022
7535
|
}
|
|
7536
|
+
Object.defineProperty(ChartFrameContent, CHART_FRAME_COMPONENT, { value: true });
|
|
7023
7537
|
function polarPoint(cx, cy, radius, angleDegrees) {
|
|
7024
7538
|
const radians = angleDegrees * Math.PI / 180;
|
|
7025
7539
|
return {
|
|
@@ -7043,6 +7557,153 @@ function donutArcPath(cx, cy, outerRadius, innerRadius, startAngle, endAngle) {
|
|
|
7043
7557
|
"Z"
|
|
7044
7558
|
].join(" ");
|
|
7045
7559
|
}
|
|
7560
|
+
function validateNonNegativeSegments(segments, chartName) {
|
|
7561
|
+
let total = 0;
|
|
7562
|
+
for (const segment of segments) {
|
|
7563
|
+
if (!Number.isFinite(segment.value) || segment.value < 0) {
|
|
7564
|
+
throw new RangeError(`${chartName} values must be finite, non-negative numbers.`);
|
|
7565
|
+
}
|
|
7566
|
+
total += segment.value;
|
|
7567
|
+
if (!Number.isFinite(total)) {
|
|
7568
|
+
throw new RangeError(`${chartName} total must be finite.`);
|
|
7569
|
+
}
|
|
7570
|
+
}
|
|
7571
|
+
return total;
|
|
7572
|
+
}
|
|
7573
|
+
function pieSectorPath(cx, cy, radius, startAngle, endAngle) {
|
|
7574
|
+
const span = endAngle - startAngle;
|
|
7575
|
+
const start = polarPoint(cx, cy, radius, startAngle);
|
|
7576
|
+
if (span >= 359.999) {
|
|
7577
|
+
const opposite = polarPoint(cx, cy, radius, startAngle + 180);
|
|
7578
|
+
return [
|
|
7579
|
+
`M ${cx} ${cy}`,
|
|
7580
|
+
`L ${start.x} ${start.y}`,
|
|
7581
|
+
`A ${radius} ${radius} 0 1 1 ${opposite.x} ${opposite.y}`,
|
|
7582
|
+
`A ${radius} ${radius} 0 1 1 ${start.x} ${start.y}`,
|
|
7583
|
+
"Z"
|
|
7584
|
+
].join(" ");
|
|
7585
|
+
}
|
|
7586
|
+
const end = polarPoint(cx, cy, radius, endAngle);
|
|
7587
|
+
const largeArc = span > 180 ? 1 : 0;
|
|
7588
|
+
return `M ${cx} ${cy} L ${start.x} ${start.y} A ${radius} ${radius} 0 ${largeArc} 1 ${end.x} ${end.y} Z`;
|
|
7589
|
+
}
|
|
7590
|
+
function PieChart({
|
|
7591
|
+
segments,
|
|
7592
|
+
c,
|
|
7593
|
+
title,
|
|
7594
|
+
subtitle,
|
|
7595
|
+
width = 360,
|
|
7596
|
+
height = 240,
|
|
7597
|
+
size,
|
|
7598
|
+
format = "decimal",
|
|
7599
|
+
showLegend = true,
|
|
7600
|
+
footer
|
|
7601
|
+
}) {
|
|
7602
|
+
const total = validateNonNegativeSegments(segments, "PieChart");
|
|
7603
|
+
const positiveSegments = segments.filter((segment) => segment.value > 0);
|
|
7604
|
+
const resolvedSize = size ?? Math.min(184, Math.max(132, height - 44), Math.max(132, width * 0.5));
|
|
7605
|
+
const radius = resolvedSize / 2 - 2;
|
|
7606
|
+
const cx = resolvedSize / 2;
|
|
7607
|
+
const cy = resolvedSize / 2;
|
|
7608
|
+
let cursor = -90;
|
|
7609
|
+
const paths = positiveSegments.map((segment, index) => {
|
|
7610
|
+
const span = total > 0 ? segment.value / total * 360 : 0;
|
|
7611
|
+
const start = cursor;
|
|
7612
|
+
const end = index === positiveSegments.length - 1 ? 270 : cursor + span;
|
|
7613
|
+
cursor += span;
|
|
7614
|
+
return import_react12.default.createElement("path", {
|
|
7615
|
+
key: `pie-segment-${segment.label}-${index}`,
|
|
7616
|
+
d: pieSectorPath(cx, cy, radius, start, end),
|
|
7617
|
+
fill: chartColor(segment.color, c, index),
|
|
7618
|
+
stroke: c.bgCard,
|
|
7619
|
+
strokeWidth: positiveSegments.length > 1 ? 2 : 0,
|
|
7620
|
+
"data-pie-label": segment.label,
|
|
7621
|
+
"data-pie-value": segment.value,
|
|
7622
|
+
"data-pie-share": total > 0 ? segment.value / total : 0
|
|
7623
|
+
});
|
|
7624
|
+
});
|
|
7625
|
+
const legend = showLegend && positiveSegments.length > 0 && import_react12.default.createElement("div", {
|
|
7626
|
+
style: {
|
|
7627
|
+
display: "flex",
|
|
7628
|
+
flexDirection: "column",
|
|
7629
|
+
gap: 8,
|
|
7630
|
+
flex: 1,
|
|
7631
|
+
minWidth: 112
|
|
7632
|
+
}
|
|
7633
|
+
}, ...positiveSegments.map((segment, index) => {
|
|
7634
|
+
const formattedValue = formatChartValue(segment.value, format);
|
|
7635
|
+
const share = formatChartValue(segment.value / total, "percent");
|
|
7636
|
+
const label = segment.valueLabel ?? (format === "percent" ? formattedValue : `${formattedValue} \xB7 ${share}`);
|
|
7637
|
+
return import_react12.default.createElement(
|
|
7638
|
+
"div",
|
|
7639
|
+
{
|
|
7640
|
+
key: `pie-legend-${segment.label}-${index}`,
|
|
7641
|
+
style: { display: "flex", alignItems: "center", gap: 8, minWidth: 0 }
|
|
7642
|
+
},
|
|
7643
|
+
import_react12.default.createElement("span", {
|
|
7644
|
+
style: {
|
|
7645
|
+
display: "flex",
|
|
7646
|
+
width: 10,
|
|
7647
|
+
height: 10,
|
|
7648
|
+
borderRadius: 3,
|
|
7649
|
+
backgroundColor: chartColor(segment.color, c, index),
|
|
7650
|
+
flexShrink: 0
|
|
7651
|
+
}
|
|
7652
|
+
}),
|
|
7653
|
+
import_react12.default.createElement("span", {
|
|
7654
|
+
style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary, flex: 1 }
|
|
7655
|
+
}, segment.label),
|
|
7656
|
+
import_react12.default.createElement("span", {
|
|
7657
|
+
style: {
|
|
7658
|
+
...typography.tiny,
|
|
7659
|
+
color: c.textPrimary,
|
|
7660
|
+
fontFamily: "JetBrains Mono",
|
|
7661
|
+
fontWeight: 850,
|
|
7662
|
+
flexShrink: 0
|
|
7663
|
+
}
|
|
7664
|
+
}, label)
|
|
7665
|
+
);
|
|
7666
|
+
}));
|
|
7667
|
+
return ChartFrame({
|
|
7668
|
+
c,
|
|
7669
|
+
title,
|
|
7670
|
+
subtitle,
|
|
7671
|
+
footer,
|
|
7672
|
+
width,
|
|
7673
|
+
children: import_react12.default.createElement(
|
|
7674
|
+
"div",
|
|
7675
|
+
{
|
|
7676
|
+
style: {
|
|
7677
|
+
display: "flex",
|
|
7678
|
+
alignItems: "center",
|
|
7679
|
+
justifyContent: showLegend ? "space-between" : "center",
|
|
7680
|
+
gap: 18,
|
|
7681
|
+
minHeight: resolvedSize,
|
|
7682
|
+
width: "100%"
|
|
7683
|
+
}
|
|
7684
|
+
},
|
|
7685
|
+
import_react12.default.createElement(
|
|
7686
|
+
"svg",
|
|
7687
|
+
{
|
|
7688
|
+
width: resolvedSize,
|
|
7689
|
+
height: resolvedSize,
|
|
7690
|
+
viewBox: `0 0 ${resolvedSize} ${resolvedSize}`,
|
|
7691
|
+
role: "img",
|
|
7692
|
+
"aria-label": title ?? "Pie chart"
|
|
7693
|
+
},
|
|
7694
|
+
positiveSegments.length === 0 ? import_react12.default.createElement("circle", {
|
|
7695
|
+
cx,
|
|
7696
|
+
cy,
|
|
7697
|
+
r: radius,
|
|
7698
|
+
fill: "none",
|
|
7699
|
+
stroke: c.borderLight,
|
|
7700
|
+
strokeWidth: 2
|
|
7701
|
+
}) : paths
|
|
7702
|
+
),
|
|
7703
|
+
legend
|
|
7704
|
+
)
|
|
7705
|
+
});
|
|
7706
|
+
}
|
|
7046
7707
|
function DonutChart({
|
|
7047
7708
|
segments,
|
|
7048
7709
|
c,
|
|
@@ -7075,13 +7736,13 @@ function DonutChart({
|
|
|
7075
7736
|
const end = cursor + rawSpan - gap / 2;
|
|
7076
7737
|
cursor += rawSpan;
|
|
7077
7738
|
if (end <= start) return null;
|
|
7078
|
-
return
|
|
7739
|
+
return import_react12.default.createElement("path", {
|
|
7079
7740
|
key: `donut-segment-${segment.label}-${index}`,
|
|
7080
7741
|
d: donutArcPath(cx, cy, outerRadius, innerRadius, start, end),
|
|
7081
7742
|
fill: chartColor(segment.color, c, index)
|
|
7082
7743
|
});
|
|
7083
7744
|
}).filter(Boolean);
|
|
7084
|
-
const legend = showLegend && positiveSegments.length > 0 &&
|
|
7745
|
+
const legend = showLegend && positiveSegments.length > 0 && import_react12.default.createElement("div", {
|
|
7085
7746
|
style: {
|
|
7086
7747
|
display: "flex",
|
|
7087
7748
|
flexDirection: "column",
|
|
@@ -7089,7 +7750,7 @@ function DonutChart({
|
|
|
7089
7750
|
flex: 1,
|
|
7090
7751
|
minWidth: 112
|
|
7091
7752
|
}
|
|
7092
|
-
}, ...positiveSegments.map((segment, index) =>
|
|
7753
|
+
}, ...positiveSegments.map((segment, index) => import_react12.default.createElement(
|
|
7093
7754
|
"div",
|
|
7094
7755
|
{
|
|
7095
7756
|
key: `donut-legend-${segment.label}-${index}`,
|
|
@@ -7100,7 +7761,7 @@ function DonutChart({
|
|
|
7100
7761
|
minWidth: 0
|
|
7101
7762
|
}
|
|
7102
7763
|
},
|
|
7103
|
-
|
|
7764
|
+
import_react12.default.createElement("span", {
|
|
7104
7765
|
style: {
|
|
7105
7766
|
display: "flex",
|
|
7106
7767
|
width: 10,
|
|
@@ -7110,7 +7771,7 @@ function DonutChart({
|
|
|
7110
7771
|
flexShrink: 0
|
|
7111
7772
|
}
|
|
7112
7773
|
}),
|
|
7113
|
-
|
|
7774
|
+
import_react12.default.createElement("span", {
|
|
7114
7775
|
style: {
|
|
7115
7776
|
...typography.tiny,
|
|
7116
7777
|
...textFitStyle(),
|
|
@@ -7118,7 +7779,7 @@ function DonutChart({
|
|
|
7118
7779
|
flex: 1
|
|
7119
7780
|
}
|
|
7120
7781
|
}, segment.label),
|
|
7121
|
-
|
|
7782
|
+
import_react12.default.createElement("span", {
|
|
7122
7783
|
style: {
|
|
7123
7784
|
...typography.tiny,
|
|
7124
7785
|
color: c.textPrimary,
|
|
@@ -7136,7 +7797,7 @@ function DonutChart({
|
|
|
7136
7797
|
width,
|
|
7137
7798
|
height,
|
|
7138
7799
|
padding: 16,
|
|
7139
|
-
children:
|
|
7800
|
+
children: import_react12.default.createElement(
|
|
7140
7801
|
"div",
|
|
7141
7802
|
{
|
|
7142
7803
|
style: {
|
|
@@ -7148,7 +7809,7 @@ function DonutChart({
|
|
|
7148
7809
|
width: "100%"
|
|
7149
7810
|
}
|
|
7150
7811
|
},
|
|
7151
|
-
|
|
7812
|
+
import_react12.default.createElement(
|
|
7152
7813
|
"div",
|
|
7153
7814
|
{
|
|
7154
7815
|
style: {
|
|
@@ -7159,14 +7820,14 @@ function DonutChart({
|
|
|
7159
7820
|
flexShrink: 0
|
|
7160
7821
|
}
|
|
7161
7822
|
},
|
|
7162
|
-
|
|
7823
|
+
import_react12.default.createElement(
|
|
7163
7824
|
"svg",
|
|
7164
7825
|
{
|
|
7165
7826
|
width: resolvedSize,
|
|
7166
7827
|
height: resolvedSize,
|
|
7167
7828
|
viewBox: `0 0 ${resolvedSize} ${resolvedSize}`
|
|
7168
7829
|
},
|
|
7169
|
-
positiveSegments.length === 0 ?
|
|
7830
|
+
positiveSegments.length === 0 ? import_react12.default.createElement("circle", {
|
|
7170
7831
|
cx,
|
|
7171
7832
|
cy,
|
|
7172
7833
|
r: (outerRadius + innerRadius) / 2,
|
|
@@ -7175,7 +7836,7 @@ function DonutChart({
|
|
|
7175
7836
|
strokeWidth: resolvedThickness
|
|
7176
7837
|
}) : paths
|
|
7177
7838
|
),
|
|
7178
|
-
(centerLabel != null || resolvedCenterValue != null) &&
|
|
7839
|
+
(centerLabel != null || resolvedCenterValue != null) && import_react12.default.createElement(
|
|
7179
7840
|
"div",
|
|
7180
7841
|
{
|
|
7181
7842
|
style: {
|
|
@@ -7194,7 +7855,7 @@ function DonutChart({
|
|
|
7194
7855
|
textAlign: "center"
|
|
7195
7856
|
}
|
|
7196
7857
|
},
|
|
7197
|
-
resolvedCenterValue != null &&
|
|
7858
|
+
resolvedCenterValue != null && import_react12.default.createElement("div", {
|
|
7198
7859
|
style: {
|
|
7199
7860
|
...typography.small,
|
|
7200
7861
|
color: c.textPrimary,
|
|
@@ -7205,7 +7866,7 @@ function DonutChart({
|
|
|
7205
7866
|
...textFitStyle("center")
|
|
7206
7867
|
}
|
|
7207
7868
|
}, resolvedCenterValue),
|
|
7208
|
-
centerLabel != null &&
|
|
7869
|
+
centerLabel != null && import_react12.default.createElement("div", {
|
|
7209
7870
|
style: {
|
|
7210
7871
|
...typography.tiny,
|
|
7211
7872
|
color: c.textMuted,
|
|
@@ -7230,7 +7891,7 @@ function StackedBar({
|
|
|
7230
7891
|
}) {
|
|
7231
7892
|
const positiveSegments = segments.filter((segment) => segment.value > 0);
|
|
7232
7893
|
const total = positiveSegments.reduce((sum, segment) => sum + segment.value, 0);
|
|
7233
|
-
return
|
|
7894
|
+
return import_react12.default.createElement(
|
|
7234
7895
|
"div",
|
|
7235
7896
|
{
|
|
7236
7897
|
style: {
|
|
@@ -7240,7 +7901,7 @@ function StackedBar({
|
|
|
7240
7901
|
gap: 10
|
|
7241
7902
|
}
|
|
7242
7903
|
},
|
|
7243
|
-
(title || subtitle) &&
|
|
7904
|
+
(title || subtitle) && import_react12.default.createElement(
|
|
7244
7905
|
"div",
|
|
7245
7906
|
{
|
|
7246
7907
|
style: {
|
|
@@ -7249,14 +7910,14 @@ function StackedBar({
|
|
|
7249
7910
|
gap: 3
|
|
7250
7911
|
}
|
|
7251
7912
|
},
|
|
7252
|
-
title &&
|
|
7913
|
+
title && import_react12.default.createElement("div", {
|
|
7253
7914
|
style: { ...typography.label, color: c.textPrimary, fontWeight: 850 }
|
|
7254
7915
|
}, title),
|
|
7255
|
-
subtitle &&
|
|
7916
|
+
subtitle && import_react12.default.createElement("div", {
|
|
7256
7917
|
style: { ...typography.tiny, color: c.textSecondary }
|
|
7257
7918
|
}, subtitle)
|
|
7258
7919
|
),
|
|
7259
|
-
|
|
7920
|
+
import_react12.default.createElement(
|
|
7260
7921
|
"div",
|
|
7261
7922
|
{
|
|
7262
7923
|
style: {
|
|
@@ -7274,7 +7935,7 @@ function StackedBar({
|
|
|
7274
7935
|
const share = total > 0 ? segment.value / total : 0;
|
|
7275
7936
|
const segmentWidth = width * share;
|
|
7276
7937
|
const color = chartColor(segment.color, c, index);
|
|
7277
|
-
return
|
|
7938
|
+
return import_react12.default.createElement(
|
|
7278
7939
|
"div",
|
|
7279
7940
|
{
|
|
7280
7941
|
key: `${segment.label}-${index}`,
|
|
@@ -7288,7 +7949,7 @@ function StackedBar({
|
|
|
7288
7949
|
...index < positiveSegments.length - 1 ? { borderRight: `2px solid ${c.bgSubtle}` } : {}
|
|
7289
7950
|
}
|
|
7290
7951
|
},
|
|
7291
|
-
segmentWidth >= 64 &&
|
|
7952
|
+
segmentWidth >= 64 && import_react12.default.createElement("span", {
|
|
7292
7953
|
style: {
|
|
7293
7954
|
...typography.small,
|
|
7294
7955
|
color: getReadableTextColor(color, c),
|
|
@@ -7299,7 +7960,7 @@ function StackedBar({
|
|
|
7299
7960
|
);
|
|
7300
7961
|
})
|
|
7301
7962
|
),
|
|
7302
|
-
showLegend &&
|
|
7963
|
+
showLegend && import_react12.default.createElement(
|
|
7303
7964
|
"div",
|
|
7304
7965
|
{
|
|
7305
7966
|
style: {
|
|
@@ -7311,13 +7972,13 @@ function StackedBar({
|
|
|
7311
7972
|
},
|
|
7312
7973
|
...positiveSegments.map((segment, index) => {
|
|
7313
7974
|
const share = total > 0 ? segment.value / total : 0;
|
|
7314
|
-
return
|
|
7975
|
+
return import_react12.default.createElement(
|
|
7315
7976
|
"div",
|
|
7316
7977
|
{
|
|
7317
7978
|
key: `legend-${segment.label}-${index}`,
|
|
7318
7979
|
style: { display: "flex", alignItems: "center", gap: 7 }
|
|
7319
7980
|
},
|
|
7320
|
-
|
|
7981
|
+
import_react12.default.createElement("span", {
|
|
7321
7982
|
style: {
|
|
7322
7983
|
width: 12,
|
|
7323
7984
|
height: 12,
|
|
@@ -7326,7 +7987,7 @@ function StackedBar({
|
|
|
7326
7987
|
backgroundColor: chartColor(segment.color, c, index)
|
|
7327
7988
|
}
|
|
7328
7989
|
}),
|
|
7329
|
-
|
|
7990
|
+
import_react12.default.createElement("span", {
|
|
7330
7991
|
style: { ...typography.tiny, color: c.textSecondary }
|
|
7331
7992
|
}, `${segment.label} ${segment.valueLabel ?? formatChartValue(share, "percent")}`)
|
|
7332
7993
|
);
|
|
@@ -7372,18 +8033,18 @@ function BarChart({
|
|
|
7372
8033
|
subtitle,
|
|
7373
8034
|
width,
|
|
7374
8035
|
footer,
|
|
7375
|
-
children:
|
|
8036
|
+
children: import_react12.default.createElement(
|
|
7376
8037
|
"div",
|
|
7377
8038
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7378
|
-
|
|
8039
|
+
import_react12.default.createElement(
|
|
7379
8040
|
"svg",
|
|
7380
8041
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7381
|
-
showGrid &&
|
|
8042
|
+
showGrid && import_react12.default.createElement(
|
|
7382
8043
|
"g",
|
|
7383
8044
|
{},
|
|
7384
8045
|
...ticks.map((tick) => {
|
|
7385
8046
|
const y = yInPlot(tick, domain, plot);
|
|
7386
|
-
return
|
|
8047
|
+
return import_react12.default.createElement("line", {
|
|
7387
8048
|
key: `tick-${tick}`,
|
|
7388
8049
|
x1: plot.x,
|
|
7389
8050
|
y1: y,
|
|
@@ -7394,10 +8055,10 @@ function BarChart({
|
|
|
7394
8055
|
});
|
|
7395
8056
|
})
|
|
7396
8057
|
),
|
|
7397
|
-
|
|
7398
|
-
|
|
8058
|
+
import_react12.default.createElement("line", { x1: plot.x, y1: plot.y, x2: plot.x, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
8059
|
+
import_react12.default.createElement("line", { x1: plot.x, y1: baselineY, x2: plot.right, y2: baselineY, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
7399
8060
|
...barGeometries.map(
|
|
7400
|
-
({ item, index, x, y, barHeight, color }) =>
|
|
8061
|
+
({ item, index, x, y, barHeight, color }) => import_react12.default.createElement("rect", {
|
|
7401
8062
|
key: `${item.label}-${index}`,
|
|
7402
8063
|
x,
|
|
7403
8064
|
y,
|
|
@@ -7433,6 +8094,186 @@ function BarChart({
|
|
|
7433
8094
|
)
|
|
7434
8095
|
});
|
|
7435
8096
|
}
|
|
8097
|
+
function ParetoBarChart({
|
|
8098
|
+
data,
|
|
8099
|
+
c,
|
|
8100
|
+
title,
|
|
8101
|
+
subtitle,
|
|
8102
|
+
width = 520,
|
|
8103
|
+
height = 300,
|
|
8104
|
+
format = "integer",
|
|
8105
|
+
showGrid = true,
|
|
8106
|
+
showValues = true,
|
|
8107
|
+
footer
|
|
8108
|
+
}) {
|
|
8109
|
+
let total = 0;
|
|
8110
|
+
for (const item of data) {
|
|
8111
|
+
if (!Number.isFinite(item.value) || item.value < 0) {
|
|
8112
|
+
throw new RangeError("ParetoBarChart values must be finite, non-negative numbers.");
|
|
8113
|
+
}
|
|
8114
|
+
total += item.value;
|
|
8115
|
+
if (!Number.isFinite(total)) {
|
|
8116
|
+
throw new RangeError("ParetoBarChart total must be finite.");
|
|
8117
|
+
}
|
|
8118
|
+
}
|
|
8119
|
+
const sorted = data.map((item, index) => ({ item, index })).sort((left, right) => right.item.value - left.item.value || left.index - right.index);
|
|
8120
|
+
const maximum = Math.max(1, ...sorted.map(({ item }) => item.value));
|
|
8121
|
+
const margin = { top: 24, right: 48, bottom: 48, left: 48 };
|
|
8122
|
+
const plot = createPlotArea(width, height, margin);
|
|
8123
|
+
const valueDomain = {
|
|
8124
|
+
min: 0,
|
|
8125
|
+
range: maximum > Number.MAX_VALUE / 1.16 ? maximum : maximum * 1.16
|
|
8126
|
+
};
|
|
8127
|
+
const countTicks = chartTicks(0, maximum, 4);
|
|
8128
|
+
const slot = plot.innerWidth / Math.max(sorted.length, 1);
|
|
8129
|
+
const barWidth = Math.max(6, Math.min(68, slot * 0.68));
|
|
8130
|
+
let accumulated = 0;
|
|
8131
|
+
const bars = sorted.map(({ item, index }, order) => {
|
|
8132
|
+
accumulated += item.value;
|
|
8133
|
+
const cumulative = total === 0 ? 0 : order === sorted.length - 1 ? 1 : accumulated / total;
|
|
8134
|
+
const x = plot.x + order * slot + (slot - barWidth) / 2;
|
|
8135
|
+
const top = yInPlot(item.value, valueDomain, plot);
|
|
8136
|
+
return {
|
|
8137
|
+
item,
|
|
8138
|
+
sourceIndex: index,
|
|
8139
|
+
order,
|
|
8140
|
+
x,
|
|
8141
|
+
y: top,
|
|
8142
|
+
height: Math.max(0, plot.bottom - top),
|
|
8143
|
+
color: chartColor(item.color, c, order),
|
|
8144
|
+
centerX: x + barWidth / 2,
|
|
8145
|
+
cumulative,
|
|
8146
|
+
cumulativeY: plot.bottom - cumulative * plot.innerHeight
|
|
8147
|
+
};
|
|
8148
|
+
});
|
|
8149
|
+
const cumulativePath = bars.map(({ centerX, cumulativeY }, index) => `${index === 0 ? "M" : "L"} ${centerX.toFixed(1)} ${cumulativeY.toFixed(1)}`).join(" ");
|
|
8150
|
+
return ChartFrame({
|
|
8151
|
+
c,
|
|
8152
|
+
title,
|
|
8153
|
+
subtitle,
|
|
8154
|
+
width,
|
|
8155
|
+
footer,
|
|
8156
|
+
children: import_react12.default.createElement(
|
|
8157
|
+
"div",
|
|
8158
|
+
{
|
|
8159
|
+
style: { position: "relative", width, height, display: "flex" }
|
|
8160
|
+
},
|
|
8161
|
+
import_react12.default.createElement(
|
|
8162
|
+
"svg",
|
|
8163
|
+
{
|
|
8164
|
+
width,
|
|
8165
|
+
height,
|
|
8166
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
8167
|
+
role: "img",
|
|
8168
|
+
"aria-label": title ?? "Pareto bar chart"
|
|
8169
|
+
},
|
|
8170
|
+
showGrid && import_react12.default.createElement(
|
|
8171
|
+
"g",
|
|
8172
|
+
{},
|
|
8173
|
+
...countTicks.map((tick) => {
|
|
8174
|
+
const y = yInPlot(tick, valueDomain, plot);
|
|
8175
|
+
return import_react12.default.createElement("line", {
|
|
8176
|
+
key: `pareto-count-grid-${tick}`,
|
|
8177
|
+
x1: plot.x,
|
|
8178
|
+
y1: y,
|
|
8179
|
+
x2: plot.right,
|
|
8180
|
+
y2: y,
|
|
8181
|
+
stroke: c.borderSubtle,
|
|
8182
|
+
strokeWidth: 1
|
|
8183
|
+
});
|
|
8184
|
+
})
|
|
8185
|
+
),
|
|
8186
|
+
import_react12.default.createElement("line", {
|
|
8187
|
+
x1: plot.x,
|
|
8188
|
+
y1: plot.bottom,
|
|
8189
|
+
x2: plot.right,
|
|
8190
|
+
y2: plot.bottom,
|
|
8191
|
+
stroke: c.borderLight,
|
|
8192
|
+
strokeWidth: 1.2
|
|
8193
|
+
}),
|
|
8194
|
+
import_react12.default.createElement("line", {
|
|
8195
|
+
x1: plot.right,
|
|
8196
|
+
y1: plot.y,
|
|
8197
|
+
x2: plot.right,
|
|
8198
|
+
y2: plot.bottom,
|
|
8199
|
+
stroke: c.borderLight,
|
|
8200
|
+
strokeWidth: 1.2
|
|
8201
|
+
}),
|
|
8202
|
+
...bars.map(({ item, order, x, y, height: barHeight, color }) => import_react12.default.createElement("rect", {
|
|
8203
|
+
key: `pareto-bar-${item.label}-${order}`,
|
|
8204
|
+
x,
|
|
8205
|
+
y,
|
|
8206
|
+
width: barWidth,
|
|
8207
|
+
height: barHeight,
|
|
8208
|
+
rx: 4,
|
|
8209
|
+
fill: color,
|
|
8210
|
+
opacity: 0.86,
|
|
8211
|
+
"data-pareto-bar": item.label,
|
|
8212
|
+
"data-pareto-value": item.value,
|
|
8213
|
+
"data-pareto-order": order
|
|
8214
|
+
})),
|
|
8215
|
+
cumulativePath && import_react12.default.createElement("path", {
|
|
8216
|
+
d: cumulativePath,
|
|
8217
|
+
fill: "none",
|
|
8218
|
+
stroke: chartColor("critical", c),
|
|
8219
|
+
strokeWidth: 3,
|
|
8220
|
+
strokeLinecap: "round",
|
|
8221
|
+
strokeLinejoin: "round",
|
|
8222
|
+
"data-pareto-cumulative-line": true
|
|
8223
|
+
}),
|
|
8224
|
+
...bars.map(({ item, sourceIndex, centerX, cumulativeY, cumulative, order }) => import_react12.default.createElement("circle", {
|
|
8225
|
+
key: `pareto-cumulative-point-${order}`,
|
|
8226
|
+
cx: centerX,
|
|
8227
|
+
cy: cumulativeY,
|
|
8228
|
+
r: 4,
|
|
8229
|
+
fill: chartColor("critical", c),
|
|
8230
|
+
stroke: c.bgCard,
|
|
8231
|
+
strokeWidth: 2,
|
|
8232
|
+
"data-pareto-category": item.label,
|
|
8233
|
+
"data-pareto-source-index": sourceIndex,
|
|
8234
|
+
"data-pareto-cumulative-percent": cumulative * 100
|
|
8235
|
+
}))
|
|
8236
|
+
),
|
|
8237
|
+
...countTicks.map((tick) => chartLabel(
|
|
8238
|
+
`pareto-count-label-${tick}`,
|
|
8239
|
+
formatChartValue(tick, format),
|
|
8240
|
+
plot.x - 7,
|
|
8241
|
+
yInPlot(tick, valueDomain, plot),
|
|
8242
|
+
c,
|
|
8243
|
+
{ align: "right", width: 36 }
|
|
8244
|
+
)),
|
|
8245
|
+
...[0, 0.5, 1].map((share) => chartLabel(
|
|
8246
|
+
`pareto-percent-label-${share}`,
|
|
8247
|
+
`${Math.round(share * 100)}%`,
|
|
8248
|
+
plot.right + 7,
|
|
8249
|
+
plot.bottom - share * plot.innerHeight,
|
|
8250
|
+
c,
|
|
8251
|
+
{ align: "left", width: 38 }
|
|
8252
|
+
)),
|
|
8253
|
+
...bars.flatMap(({ item, order, centerX, y }) => [
|
|
8254
|
+
...showValues ? [chartLabel(
|
|
8255
|
+
`pareto-value-${order}`,
|
|
8256
|
+
item.valueLabel ?? formatChartValue(item.value, format),
|
|
8257
|
+
centerX,
|
|
8258
|
+
clamp(y - 8, plot.y + 8, plot.bottom - 12),
|
|
8259
|
+
c,
|
|
8260
|
+
{ color: c.textPrimary, fontWeight: 800, width: Math.min(slot, 64), bounds: { x: plot.x, y: plot.y, width: plot.innerWidth, height: plot.innerHeight } }
|
|
8261
|
+
)] : [],
|
|
8262
|
+
chartLabel(
|
|
8263
|
+
`pareto-category-${order}`,
|
|
8264
|
+
item.label,
|
|
8265
|
+
centerX,
|
|
8266
|
+
height - 17,
|
|
8267
|
+
c,
|
|
8268
|
+
{
|
|
8269
|
+
width: Math.max(1, Math.min(96, slot - 2)),
|
|
8270
|
+
bounds: { x: plot.x, y: plot.bottom + 1, width: plot.innerWidth, height: Math.max(1, height - plot.bottom - 2), padding: 0 }
|
|
8271
|
+
}
|
|
8272
|
+
)
|
|
8273
|
+
])
|
|
8274
|
+
)
|
|
8275
|
+
});
|
|
8276
|
+
}
|
|
7436
8277
|
function LineChart({
|
|
7437
8278
|
series,
|
|
7438
8279
|
c,
|
|
@@ -7476,18 +8317,18 @@ function LineChart({
|
|
|
7476
8317
|
width,
|
|
7477
8318
|
footer,
|
|
7478
8319
|
legend: series.map((item, index) => ({ label: item.name, color: item.color ?? chartPalette[index % chartPalette.length] })),
|
|
7479
|
-
children:
|
|
8320
|
+
children: import_react12.default.createElement(
|
|
7480
8321
|
"div",
|
|
7481
8322
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7482
|
-
|
|
8323
|
+
import_react12.default.createElement(
|
|
7483
8324
|
"svg",
|
|
7484
8325
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7485
|
-
showGrid &&
|
|
8326
|
+
showGrid && import_react12.default.createElement(
|
|
7486
8327
|
"g",
|
|
7487
8328
|
{},
|
|
7488
8329
|
...ticks.map((tick) => {
|
|
7489
8330
|
const y = yInPlot(tick, domain, plot);
|
|
7490
|
-
return
|
|
8331
|
+
return import_react12.default.createElement("line", {
|
|
7491
8332
|
key: `line-tick-${tick}`,
|
|
7492
8333
|
x1: plot.x,
|
|
7493
8334
|
y1: y,
|
|
@@ -7498,8 +8339,8 @@ function LineChart({
|
|
|
7498
8339
|
});
|
|
7499
8340
|
})
|
|
7500
8341
|
),
|
|
7501
|
-
|
|
7502
|
-
|
|
8342
|
+
import_react12.default.createElement("line", { x1: plot.x, y1: plot.y, x2: plot.x, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
8343
|
+
import_react12.default.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
7503
8344
|
...series.flatMap((item, seriesIndex) => {
|
|
7504
8345
|
if (item.points.length === 0) return [];
|
|
7505
8346
|
const color = chartColor(item.color, c, seriesIndex);
|
|
@@ -7512,9 +8353,9 @@ function LineChart({
|
|
|
7512
8353
|
}
|
|
7513
8354
|
const elements = [];
|
|
7514
8355
|
if (areaPath) {
|
|
7515
|
-
elements.push(
|
|
8356
|
+
elements.push(import_react12.default.createElement("path", { key: `${item.name}-area`, d: areaPath, fill: color, opacity: 0.12 }));
|
|
7516
8357
|
}
|
|
7517
|
-
elements.push(
|
|
8358
|
+
elements.push(import_react12.default.createElement("path", {
|
|
7518
8359
|
key: `${item.name}-line`,
|
|
7519
8360
|
d: linePath,
|
|
7520
8361
|
fill: "none",
|
|
@@ -7526,7 +8367,7 @@ function LineChart({
|
|
|
7526
8367
|
if (showPoints) {
|
|
7527
8368
|
elements.push(...item.points.map((value, index) => {
|
|
7528
8369
|
const point = pointFor(value, index);
|
|
7529
|
-
return
|
|
8370
|
+
return import_react12.default.createElement("circle", {
|
|
7530
8371
|
key: `${item.name}-point-${index}`,
|
|
7531
8372
|
cx: point.x,
|
|
7532
8373
|
cy: point.y,
|
|
@@ -7557,9 +8398,15 @@ function LineChart({
|
|
|
7557
8398
|
)
|
|
7558
8399
|
});
|
|
7559
8400
|
}
|
|
8401
|
+
for (const chart of [PieChart, DonutChart, StackedBar, BarChart, ParetoBarChart, LineChart]) {
|
|
8402
|
+
Object.defineProperty(chart, CANVAS_CHART_COMPONENT, { value: true });
|
|
8403
|
+
}
|
|
7560
8404
|
|
|
7561
8405
|
// src/primitives/plots.ts
|
|
7562
|
-
var
|
|
8406
|
+
var import_react13 = __toESM(require("react"), 1);
|
|
8407
|
+
for (const chart of [ScatterPlot, ParetoChart, QuadrantChart, IntervalPlot]) {
|
|
8408
|
+
Object.defineProperty(chart, CANVAS_CHART_COMPONENT, { value: true });
|
|
8409
|
+
}
|
|
7563
8410
|
function xTickLabelAlign(index, count) {
|
|
7564
8411
|
if (index === 0) return "left";
|
|
7565
8412
|
if (index === count - 1) return "right";
|
|
@@ -7603,18 +8450,18 @@ function ScatterPlot({
|
|
|
7603
8450
|
subtitle,
|
|
7604
8451
|
width,
|
|
7605
8452
|
footer,
|
|
7606
|
-
children:
|
|
8453
|
+
children: import_react13.default.createElement(
|
|
7607
8454
|
"div",
|
|
7608
8455
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7609
|
-
|
|
8456
|
+
import_react13.default.createElement(
|
|
7610
8457
|
"svg",
|
|
7611
8458
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7612
|
-
showGrid &&
|
|
8459
|
+
showGrid && import_react13.default.createElement(
|
|
7613
8460
|
"g",
|
|
7614
8461
|
{},
|
|
7615
8462
|
...xTicks.map((tick) => {
|
|
7616
8463
|
const x = xInPlot(tick, xDomain, plot);
|
|
7617
|
-
return
|
|
8464
|
+
return import_react13.default.createElement("line", {
|
|
7618
8465
|
key: `x-tick-${tick}`,
|
|
7619
8466
|
x1: x,
|
|
7620
8467
|
y1: plot.y,
|
|
@@ -7626,7 +8473,7 @@ function ScatterPlot({
|
|
|
7626
8473
|
}),
|
|
7627
8474
|
...yTicks.map((tick) => {
|
|
7628
8475
|
const y = yInPlot(tick, yDomain, plot);
|
|
7629
|
-
return
|
|
8476
|
+
return import_react13.default.createElement("line", {
|
|
7630
8477
|
key: `y-tick-${tick}`,
|
|
7631
8478
|
x1: plot.x,
|
|
7632
8479
|
y1: y,
|
|
@@ -7637,9 +8484,9 @@ function ScatterPlot({
|
|
|
7637
8484
|
});
|
|
7638
8485
|
})
|
|
7639
8486
|
),
|
|
7640
|
-
|
|
8487
|
+
import_react13.default.createElement("rect", { x: plot.x, y: plot.y, width: plot.innerWidth, height: plot.innerHeight, fill: "transparent", stroke: c.borderLight, strokeWidth: 1.2, rx: 6 }),
|
|
7641
8488
|
...pointGeometries.map(
|
|
7642
|
-
({ item, index, point, color }) =>
|
|
8489
|
+
({ item, index, point, color }) => import_react13.default.createElement("circle", {
|
|
7643
8490
|
key: `${item.label ?? "point"}-${index}`,
|
|
7644
8491
|
cx: point.x,
|
|
7645
8492
|
cy: point.y,
|
|
@@ -7790,18 +8637,18 @@ function ParetoChart({
|
|
|
7790
8637
|
{ label: "Pareto frontier", color: frontier },
|
|
7791
8638
|
{ label: "dominated", color: "neutral" }
|
|
7792
8639
|
],
|
|
7793
|
-
children:
|
|
8640
|
+
children: import_react13.default.createElement(
|
|
7794
8641
|
"div",
|
|
7795
8642
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
7796
|
-
|
|
8643
|
+
import_react13.default.createElement(
|
|
7797
8644
|
"svg",
|
|
7798
8645
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7799
|
-
showGrid &&
|
|
8646
|
+
showGrid && import_react13.default.createElement(
|
|
7800
8647
|
"g",
|
|
7801
8648
|
{},
|
|
7802
8649
|
...xTicks.map((tick) => {
|
|
7803
8650
|
const x = pointFor(tick, yDomain.min).x;
|
|
7804
|
-
return
|
|
8651
|
+
return import_react13.default.createElement("line", {
|
|
7805
8652
|
key: `pareto-x-grid-${tick}`,
|
|
7806
8653
|
x1: x,
|
|
7807
8654
|
y1: plot.y,
|
|
@@ -7813,7 +8660,7 @@ function ParetoChart({
|
|
|
7813
8660
|
}),
|
|
7814
8661
|
...yTicks.map((tick) => {
|
|
7815
8662
|
const y = yInPlot(tick, yDomain, plot);
|
|
7816
|
-
return
|
|
8663
|
+
return import_react13.default.createElement("line", {
|
|
7817
8664
|
key: `pareto-y-grid-${tick}`,
|
|
7818
8665
|
x1: plot.x,
|
|
7819
8666
|
y1: y,
|
|
@@ -7824,7 +8671,7 @@ function ParetoChart({
|
|
|
7824
8671
|
});
|
|
7825
8672
|
})
|
|
7826
8673
|
),
|
|
7827
|
-
|
|
8674
|
+
import_react13.default.createElement("rect", {
|
|
7828
8675
|
x: plot.x,
|
|
7829
8676
|
y: plot.y,
|
|
7830
8677
|
width: plot.innerWidth,
|
|
@@ -7834,17 +8681,17 @@ function ParetoChart({
|
|
|
7834
8681
|
strokeWidth: 1.2,
|
|
7835
8682
|
rx: 6
|
|
7836
8683
|
}),
|
|
7837
|
-
showGoal &&
|
|
8684
|
+
showGoal && import_react13.default.createElement(
|
|
7838
8685
|
"g",
|
|
7839
8686
|
{ "data-pareto-goal": true, stroke: frontier, fill: "none", strokeWidth: 2, strokeLinecap: "round" },
|
|
7840
|
-
|
|
7841
|
-
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
|
|
7845
|
-
|
|
8687
|
+
import_react13.default.createElement("line", { x1: goalXStart, y1: goalY, x2: goalXEnd, y2: goalY }),
|
|
8688
|
+
import_react13.default.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY - arrowSize }),
|
|
8689
|
+
import_react13.default.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY + arrowSize }),
|
|
8690
|
+
import_react13.default.createElement("line", { x1: goalXStart, y1: goalYStart, x2: goalXStart, y2: goalYEnd }),
|
|
8691
|
+
import_react13.default.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart - arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) }),
|
|
8692
|
+
import_react13.default.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart + arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) })
|
|
7846
8693
|
),
|
|
7847
|
-
frontierPath &&
|
|
8694
|
+
frontierPath && import_react13.default.createElement("path", {
|
|
7848
8695
|
"data-pareto-frontier": true,
|
|
7849
8696
|
d: frontierPath,
|
|
7850
8697
|
fill: "none",
|
|
@@ -7853,7 +8700,7 @@ function ParetoChart({
|
|
|
7853
8700
|
strokeLinecap: "round",
|
|
7854
8701
|
strokeLinejoin: "round"
|
|
7855
8702
|
}),
|
|
7856
|
-
...pointGeometries.filter((geometry) => !geometry.frontier).concat(pointGeometries.filter((geometry) => geometry.frontier)).map(({ point, index, x, y, color, frontier: isFrontier }) =>
|
|
8703
|
+
...pointGeometries.filter((geometry) => !geometry.frontier).concat(pointGeometries.filter((geometry) => geometry.frontier)).map(({ point, index, x, y, color, frontier: isFrontier }) => import_react13.default.createElement("circle", {
|
|
7857
8704
|
key: `pareto-point-${point.label ?? "point"}-${index}`,
|
|
7858
8705
|
"data-pareto-status": isFrontier ? "frontier" : "dominated",
|
|
7859
8706
|
cx: x,
|
|
@@ -7965,18 +8812,18 @@ function QuadrantChart({
|
|
|
7965
8812
|
subtitle,
|
|
7966
8813
|
width,
|
|
7967
8814
|
footer,
|
|
7968
|
-
children:
|
|
8815
|
+
children: import_react13.default.createElement(
|
|
7969
8816
|
"div",
|
|
7970
8817
|
{
|
|
7971
8818
|
style: { position: "relative", width, height, display: "flex" }
|
|
7972
8819
|
},
|
|
7973
|
-
|
|
8820
|
+
import_react13.default.createElement(
|
|
7974
8821
|
"svg",
|
|
7975
8822
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
7976
8823
|
...regionEntries.map(({ key, region, x, y, width: regionWidth, height: regionHeight }, index) => {
|
|
7977
8824
|
const color = chartColor(region.color, c, index);
|
|
7978
8825
|
const emphasized = region.emphasis === true;
|
|
7979
|
-
return
|
|
8826
|
+
return import_react13.default.createElement("rect", {
|
|
7980
8827
|
key: `quadrant-${key}`,
|
|
7981
8828
|
x,
|
|
7982
8829
|
y,
|
|
@@ -7988,12 +8835,12 @@ function QuadrantChart({
|
|
|
7988
8835
|
strokeWidth: emphasized ? 2 : 0
|
|
7989
8836
|
});
|
|
7990
8837
|
}),
|
|
7991
|
-
showGrid &&
|
|
8838
|
+
showGrid && import_react13.default.createElement(
|
|
7992
8839
|
"g",
|
|
7993
8840
|
{},
|
|
7994
8841
|
...xTicks.map((tick) => {
|
|
7995
8842
|
const x = xInPlot(tick, xDomain, plot);
|
|
7996
|
-
return
|
|
8843
|
+
return import_react13.default.createElement("line", {
|
|
7997
8844
|
key: `quadrant-x-grid-${tick}`,
|
|
7998
8845
|
x1: x,
|
|
7999
8846
|
y1: plot.y,
|
|
@@ -8005,7 +8852,7 @@ function QuadrantChart({
|
|
|
8005
8852
|
}),
|
|
8006
8853
|
...yTicks.map((tick) => {
|
|
8007
8854
|
const y = yInPlot(tick, yDomain, plot);
|
|
8008
|
-
return
|
|
8855
|
+
return import_react13.default.createElement("line", {
|
|
8009
8856
|
key: `quadrant-y-grid-${tick}`,
|
|
8010
8857
|
x1: plot.x,
|
|
8011
8858
|
y1: y,
|
|
@@ -8016,7 +8863,7 @@ function QuadrantChart({
|
|
|
8016
8863
|
});
|
|
8017
8864
|
})
|
|
8018
8865
|
),
|
|
8019
|
-
|
|
8866
|
+
import_react13.default.createElement("rect", {
|
|
8020
8867
|
x: plot.x,
|
|
8021
8868
|
y: plot.y,
|
|
8022
8869
|
width: plot.innerWidth,
|
|
@@ -8026,7 +8873,7 @@ function QuadrantChart({
|
|
|
8026
8873
|
strokeWidth: 1.2,
|
|
8027
8874
|
rx: 8
|
|
8028
8875
|
}),
|
|
8029
|
-
|
|
8876
|
+
import_react13.default.createElement("line", {
|
|
8030
8877
|
x1: midX,
|
|
8031
8878
|
y1: plot.y,
|
|
8032
8879
|
x2: midX,
|
|
@@ -8034,7 +8881,7 @@ function QuadrantChart({
|
|
|
8034
8881
|
stroke: c.borderLight,
|
|
8035
8882
|
strokeWidth: 1.4
|
|
8036
8883
|
}),
|
|
8037
|
-
|
|
8884
|
+
import_react13.default.createElement("line", {
|
|
8038
8885
|
x1: plot.x,
|
|
8039
8886
|
y1: midY,
|
|
8040
8887
|
x2: plot.right,
|
|
@@ -8044,7 +8891,7 @@ function QuadrantChart({
|
|
|
8044
8891
|
}),
|
|
8045
8892
|
...(showTicks ? xTicks : []).map((tick) => {
|
|
8046
8893
|
const x = xInPlot(tick, xDomain, plot);
|
|
8047
|
-
return
|
|
8894
|
+
return import_react13.default.createElement("line", {
|
|
8048
8895
|
key: `quadrant-x-tick-${tick}`,
|
|
8049
8896
|
x1: x,
|
|
8050
8897
|
y1: plot.bottom,
|
|
@@ -8056,7 +8903,7 @@ function QuadrantChart({
|
|
|
8056
8903
|
}),
|
|
8057
8904
|
...(showTicks ? yTicks : []).map((tick) => {
|
|
8058
8905
|
const y = yInPlot(tick, yDomain, plot);
|
|
8059
|
-
return
|
|
8906
|
+
return import_react13.default.createElement("line", {
|
|
8060
8907
|
key: `quadrant-y-tick-${tick}`,
|
|
8061
8908
|
x1: plot.x - 5,
|
|
8062
8909
|
y1: y,
|
|
@@ -8066,7 +8913,7 @@ function QuadrantChart({
|
|
|
8066
8913
|
strokeWidth: 1.2
|
|
8067
8914
|
});
|
|
8068
8915
|
}),
|
|
8069
|
-
...pointGeometries.map(({ point, index, x, y, color }) =>
|
|
8916
|
+
...pointGeometries.map(({ point, index, x, y, color }) => import_react13.default.createElement("circle", {
|
|
8070
8917
|
key: `quadrant-point-${point.label ?? index}`,
|
|
8071
8918
|
cx: x,
|
|
8072
8919
|
cy: y,
|
|
@@ -8168,15 +9015,15 @@ function IntervalPlot({
|
|
|
8168
9015
|
subtitle,
|
|
8169
9016
|
width,
|
|
8170
9017
|
footer,
|
|
8171
|
-
children:
|
|
9018
|
+
children: import_react13.default.createElement(
|
|
8172
9019
|
"div",
|
|
8173
9020
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
8174
|
-
|
|
9021
|
+
import_react13.default.createElement(
|
|
8175
9022
|
"svg",
|
|
8176
9023
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
8177
9024
|
...ticks.map((tick) => {
|
|
8178
9025
|
const x = scaleX(tick);
|
|
8179
|
-
return
|
|
9026
|
+
return import_react13.default.createElement("line", {
|
|
8180
9027
|
key: `interval-tick-${tick}`,
|
|
8181
9028
|
x1: x,
|
|
8182
9029
|
y1: plot.y,
|
|
@@ -8186,10 +9033,10 @@ function IntervalPlot({
|
|
|
8186
9033
|
strokeWidth: 1
|
|
8187
9034
|
});
|
|
8188
9035
|
}),
|
|
8189
|
-
|
|
9036
|
+
import_react13.default.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
8190
9037
|
...rows.flatMap(({ item, index, y, color, lowX, midX, highX }) => [
|
|
8191
|
-
|
|
8192
|
-
|
|
9038
|
+
import_react13.default.createElement("line", { key: `${item.label}-range-${index}`, x1: lowX, y1: y, x2: highX, y2: y, stroke: color, strokeWidth: 9, strokeLinecap: "round", opacity: 0.9 }),
|
|
9039
|
+
import_react13.default.createElement("circle", { key: `${item.label}-mid-${index}`, cx: midX, cy: y, r: 10, fill: c.bgCard, stroke: color, strokeWidth: 4 })
|
|
8193
9040
|
])
|
|
8194
9041
|
),
|
|
8195
9042
|
...ticks.map((tick, index) => {
|
|
@@ -8226,19 +9073,19 @@ function IntervalPlot({
|
|
|
8226
9073
|
}
|
|
8227
9074
|
function Badge({ label, c, color = "primary" }) {
|
|
8228
9075
|
const solidColor = getReadableColor(color, c);
|
|
8229
|
-
return
|
|
9076
|
+
return import_react13.default.createElement("div", {
|
|
8230
9077
|
style: {
|
|
8231
9078
|
display: "flex",
|
|
8232
9079
|
alignItems: "center",
|
|
8233
9080
|
justifyContent: "center",
|
|
8234
|
-
backgroundColor:
|
|
9081
|
+
backgroundColor: withColorAlpha(solidColor, 32 / 255),
|
|
8235
9082
|
color: solidColor,
|
|
8236
9083
|
borderRadius: 999,
|
|
8237
9084
|
padding: "4px 12px",
|
|
8238
9085
|
fontSize: 11,
|
|
8239
9086
|
fontWeight: 600,
|
|
8240
9087
|
fontFamily: "Inter",
|
|
8241
|
-
border: `1px solid ${solidColor}
|
|
9088
|
+
border: `1px solid ${withColorAlpha(solidColor, 64 / 255)}`
|
|
8242
9089
|
}
|
|
8243
9090
|
}, label);
|
|
8244
9091
|
}
|
|
@@ -8247,7 +9094,7 @@ function DotPoint({ x, y, label, color, c, size = 12, labelOffset }) {
|
|
|
8247
9094
|
const offY = labelOffset?.y ?? -22;
|
|
8248
9095
|
return [
|
|
8249
9096
|
// Dot
|
|
8250
|
-
|
|
9097
|
+
import_react13.default.createElement("div", {
|
|
8251
9098
|
key: `dot-${label}`,
|
|
8252
9099
|
style: {
|
|
8253
9100
|
position: "absolute",
|
|
@@ -8257,12 +9104,12 @@ function DotPoint({ x, y, label, color, c, size = 12, labelOffset }) {
|
|
|
8257
9104
|
height: size,
|
|
8258
9105
|
borderRadius: "50%",
|
|
8259
9106
|
backgroundColor: color,
|
|
8260
|
-
boxShadow: `0 0 14px ${color}
|
|
9107
|
+
boxShadow: `0 0 14px ${withColorAlpha(color, 80 / 255)}`,
|
|
8261
9108
|
display: "flex"
|
|
8262
9109
|
}
|
|
8263
9110
|
}),
|
|
8264
9111
|
// Label
|
|
8265
|
-
|
|
9112
|
+
import_react13.default.createElement("div", {
|
|
8266
9113
|
key: `label-${label}`,
|
|
8267
9114
|
style: {
|
|
8268
9115
|
position: "absolute",
|
|
@@ -8288,7 +9135,7 @@ function DashedLine({ x1, y1, x2, y2, color, dotSpacing = 8, dotSize = 2 }) {
|
|
|
8288
9135
|
if (i % 2 === 1) continue;
|
|
8289
9136
|
const t = i / numDots;
|
|
8290
9137
|
dots.push(
|
|
8291
|
-
|
|
9138
|
+
import_react13.default.createElement("div", {
|
|
8292
9139
|
key: `dash-${i}`,
|
|
8293
9140
|
style: {
|
|
8294
9141
|
position: "absolute",
|
|
@@ -8305,7 +9152,7 @@ function DashedLine({ x1, y1, x2, y2, color, dotSpacing = 8, dotSize = 2 }) {
|
|
|
8305
9152
|
return dots;
|
|
8306
9153
|
}
|
|
8307
9154
|
function Legend({ items, c, title }) {
|
|
8308
|
-
return
|
|
9155
|
+
return import_react13.default.createElement(
|
|
8309
9156
|
"div",
|
|
8310
9157
|
{
|
|
8311
9158
|
style: {
|
|
@@ -8318,7 +9165,7 @@ function Legend({ items, c, title }) {
|
|
|
8318
9165
|
padding: "14px 16px"
|
|
8319
9166
|
}
|
|
8320
9167
|
},
|
|
8321
|
-
title &&
|
|
9168
|
+
title && import_react13.default.createElement("div", {
|
|
8322
9169
|
style: {
|
|
8323
9170
|
fontSize: 11,
|
|
8324
9171
|
fontWeight: 700,
|
|
@@ -8329,13 +9176,13 @@ function Legend({ items, c, title }) {
|
|
|
8329
9176
|
}
|
|
8330
9177
|
}, title),
|
|
8331
9178
|
...items.map(
|
|
8332
|
-
(item, i) =>
|
|
9179
|
+
(item, i) => import_react13.default.createElement(
|
|
8333
9180
|
"div",
|
|
8334
9181
|
{
|
|
8335
9182
|
key: `legend-${i}`,
|
|
8336
9183
|
style: { display: "flex", alignItems: "center", gap: 8 }
|
|
8337
9184
|
},
|
|
8338
|
-
|
|
9185
|
+
import_react13.default.createElement("div", {
|
|
8339
9186
|
style: {
|
|
8340
9187
|
width: 16,
|
|
8341
9188
|
height: item.style === "dashed" ? 0 : 2,
|
|
@@ -8345,7 +9192,7 @@ function Legend({ items, c, title }) {
|
|
|
8345
9192
|
} : {}
|
|
8346
9193
|
}
|
|
8347
9194
|
}),
|
|
8348
|
-
|
|
9195
|
+
import_react13.default.createElement("div", {
|
|
8349
9196
|
style: {
|
|
8350
9197
|
fontSize: 11,
|
|
8351
9198
|
color: c.textMuted,
|
|
@@ -8357,6 +9204,45 @@ function Legend({ items, c, title }) {
|
|
|
8357
9204
|
);
|
|
8358
9205
|
}
|
|
8359
9206
|
|
|
9207
|
+
// src/primitives/board.ts
|
|
9208
|
+
var import_react14 = __toESM(require("react"), 1);
|
|
9209
|
+
var CANVAS_ITEM_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.canvas-item");
|
|
9210
|
+
function dimension(value, name) {
|
|
9211
|
+
if (value !== void 0 && (!Number.isFinite(value) || value <= 0 || value > 8192)) {
|
|
9212
|
+
throw new Error(`${name} must be a finite number greater than 0 and at most 8192.`);
|
|
9213
|
+
}
|
|
9214
|
+
return value;
|
|
9215
|
+
}
|
|
9216
|
+
function Board({ children, c, width = 960, height = 540, background }) {
|
|
9217
|
+
return import_react14.default.createElement("div", { style: {
|
|
9218
|
+
display: "flex",
|
|
9219
|
+
position: "relative",
|
|
9220
|
+
width: dimension(width, "Board width"),
|
|
9221
|
+
height: dimension(height, "Board height"),
|
|
9222
|
+
overflow: "hidden",
|
|
9223
|
+
backgroundColor: background ?? "transparent",
|
|
9224
|
+
color: c.textPrimary
|
|
9225
|
+
} }, children);
|
|
9226
|
+
}
|
|
9227
|
+
function CanvasItem({ children, x, y, width, height }) {
|
|
9228
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) throw new Error("CanvasItem x and y must be finite numbers.");
|
|
9229
|
+
const sizedChildren = import_react14.default.Children.map(children, (child) => {
|
|
9230
|
+
if (!import_react14.default.isValidElement(child)) return child;
|
|
9231
|
+
const sized = import_react14.default.cloneElement(child, { ...width !== void 0 ? { width } : {}, ...height !== void 0 ? { height } : {} });
|
|
9232
|
+
return width !== void 0 && height !== void 0 && isCanvasChart(child.type) ? import_react14.default.createElement(CanvasChartFit, { width, height, __vizmaticTextScope: child.props.__vizmaticTextScope }, sized) : sized;
|
|
9233
|
+
});
|
|
9234
|
+
return import_react14.default.createElement("div", { style: {
|
|
9235
|
+
display: "flex",
|
|
9236
|
+
position: "absolute",
|
|
9237
|
+
left: x,
|
|
9238
|
+
top: y,
|
|
9239
|
+
width: dimension(width, "CanvasItem width"),
|
|
9240
|
+
height: dimension(height, "CanvasItem height"),
|
|
9241
|
+
alignItems: "stretch"
|
|
9242
|
+
} }, sizedChildren);
|
|
9243
|
+
}
|
|
9244
|
+
Object.defineProperty(CanvasItem, CANVAS_ITEM_COMPONENT, { value: true });
|
|
9245
|
+
|
|
8360
9246
|
// src/render.ts
|
|
8361
9247
|
var import_resvg_js = require("@resvg/resvg-js");
|
|
8362
9248
|
var import_os = require("os");
|
|
@@ -8367,12 +9253,12 @@ var import_url = require("url");
|
|
|
8367
9253
|
var import_zlib = require("zlib");
|
|
8368
9254
|
|
|
8369
9255
|
// src/brand.ts
|
|
8370
|
-
var
|
|
9256
|
+
var import_react15 = __toESM(require("react"), 1);
|
|
8371
9257
|
var DEFAULT_WATERMARK_TEXT = "Vizmatic";
|
|
8372
9258
|
var WATERMARK_COLOR_DARK = "#a78bfa";
|
|
8373
9259
|
var WATERMARK_COLOR_LIGHT = "#7c3aed";
|
|
8374
9260
|
function VizmaticIcon({ size = 14, color }) {
|
|
8375
|
-
return
|
|
9261
|
+
return import_react15.default.createElement(
|
|
8376
9262
|
"svg",
|
|
8377
9263
|
{
|
|
8378
9264
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -8381,19 +9267,19 @@ function VizmaticIcon({ size = 14, color }) {
|
|
|
8381
9267
|
viewBox: "0 0 28 28",
|
|
8382
9268
|
fill: "none"
|
|
8383
9269
|
},
|
|
8384
|
-
|
|
8385
|
-
|
|
8386
|
-
|
|
8387
|
-
|
|
8388
|
-
|
|
8389
|
-
|
|
9270
|
+
import_react15.default.createElement("rect", { x: 2.5, y: 2.5, width: 23, height: 23, rx: 6.5, stroke: color, strokeWidth: 2, opacity: 0.54 }),
|
|
9271
|
+
import_react15.default.createElement("rect", { x: 7, y: 7, width: 5.5, height: 5.5, rx: 1.8, fill: color, opacity: 0.35 }),
|
|
9272
|
+
import_react15.default.createElement("rect", { x: 15.5, y: 7, width: 5.5, height: 5.5, rx: 1.8, fill: color }),
|
|
9273
|
+
import_react15.default.createElement("rect", { x: 7, y: 15.5, width: 5.5, height: 5.5, rx: 1.8, fill: color, opacity: 0.82 }),
|
|
9274
|
+
import_react15.default.createElement("rect", { x: 15.5, y: 15.5, width: 5.5, height: 5.5, rx: 1.8, stroke: color, strokeWidth: 1.5, opacity: 0.72 }),
|
|
9275
|
+
import_react15.default.createElement("path", { d: "M9.75 9.75h8.5M9.75 18.25h8.5M9.75 9.75v8.5M18.25 9.75v8.5", stroke: color, strokeWidth: 1.6, strokeLinecap: "round", opacity: 0.88 })
|
|
8390
9276
|
);
|
|
8391
9277
|
}
|
|
8392
9278
|
function normalizeWatermark(watermark) {
|
|
8393
9279
|
if (watermark == null || watermark === false) return void 0;
|
|
8394
9280
|
if (watermark === true) return {};
|
|
8395
9281
|
if (typeof watermark === "string") return { text: watermark };
|
|
8396
|
-
if (
|
|
9282
|
+
if (import_react15.default.isValidElement(watermark)) {
|
|
8397
9283
|
if (watermark.type !== Watermark) return { element: watermark };
|
|
8398
9284
|
const { children, ...props } = watermark.props;
|
|
8399
9285
|
return {
|
|
@@ -8422,7 +9308,7 @@ function positionStyle(position) {
|
|
|
8422
9308
|
function imageNode(image) {
|
|
8423
9309
|
if (!image) return void 0;
|
|
8424
9310
|
const imageOptions = typeof image === "string" ? { src: image } : image;
|
|
8425
|
-
return
|
|
9311
|
+
return import_react15.default.createElement("img", {
|
|
8426
9312
|
src: imageOptions.src,
|
|
8427
9313
|
alt: imageOptions.alt ?? "",
|
|
8428
9314
|
width: imageOptions.width ?? 14,
|
|
@@ -8437,9 +9323,9 @@ function imageNode(image) {
|
|
|
8437
9323
|
}
|
|
8438
9324
|
function iconNode(icon, color) {
|
|
8439
9325
|
if (icon === false) return void 0;
|
|
8440
|
-
if (icon == null) return
|
|
9326
|
+
if (icon == null) return import_react15.default.createElement(VizmaticIcon, { size: 13, color });
|
|
8441
9327
|
if (typeof icon !== "string") return icon;
|
|
8442
|
-
return
|
|
9328
|
+
return import_react15.default.createElement("div", {
|
|
8443
9329
|
style: {
|
|
8444
9330
|
minWidth: 13,
|
|
8445
9331
|
height: 13,
|
|
@@ -8464,7 +9350,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
|
|
|
8464
9350
|
const text = options?.text ?? DEFAULT_WATERMARK_TEXT;
|
|
8465
9351
|
const content = options?.element ?? [
|
|
8466
9352
|
icon,
|
|
8467
|
-
text !== false && text &&
|
|
9353
|
+
text !== false && text && import_react15.default.createElement("div", {
|
|
8468
9354
|
key: "text",
|
|
8469
9355
|
style: {
|
|
8470
9356
|
fontSize: 11,
|
|
@@ -8475,7 +9361,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
|
|
|
8475
9361
|
}
|
|
8476
9362
|
}, text)
|
|
8477
9363
|
];
|
|
8478
|
-
return
|
|
9364
|
+
return import_react15.default.createElement(
|
|
8479
9365
|
"div",
|
|
8480
9366
|
{
|
|
8481
9367
|
style: {
|
|
@@ -8486,7 +9372,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
|
|
|
8486
9372
|
}
|
|
8487
9373
|
},
|
|
8488
9374
|
element,
|
|
8489
|
-
options &&
|
|
9375
|
+
options && import_react15.default.createElement(
|
|
8490
9376
|
"div",
|
|
8491
9377
|
{
|
|
8492
9378
|
style: {
|
|
@@ -8637,7 +9523,8 @@ function resolveSatori(api) {
|
|
|
8637
9523
|
}
|
|
8638
9524
|
throw new Error("satori export could not be resolved");
|
|
8639
9525
|
}
|
|
8640
|
-
var
|
|
9526
|
+
var renderSatori = resolveSatori(satoriModule);
|
|
9527
|
+
var satori = (element, options) => renderWithCanvasChartFit(renderSatori, element, options);
|
|
8641
9528
|
|
|
8642
9529
|
// src/render.ts
|
|
8643
9530
|
var FONT_CACHE_DIR = process.env.VIZMATIC_FONT_DIR ?? (0, import_path.join)(process.env.XDG_CACHE_HOME ?? (0, import_path.join)((0, import_os.homedir)(), ".cache"), "vizmatic", "fonts");
|
|
@@ -9976,30 +10863,30 @@ function readEndpoint(line, from) {
|
|
|
9976
10863
|
next: content.next
|
|
9977
10864
|
};
|
|
9978
10865
|
}
|
|
9979
|
-
function addNode(state,
|
|
9980
|
-
if (state.groupIds.has(
|
|
10866
|
+
function addNode(state, endpoint2, groupId, line, sourceLines, diagnostics, explicitlyDeclared) {
|
|
10867
|
+
if (state.groupIds.has(endpoint2.id)) {
|
|
9981
10868
|
addImportDiagnostic(
|
|
9982
10869
|
diagnostics,
|
|
9983
10870
|
sourceLines,
|
|
9984
10871
|
line,
|
|
9985
10872
|
"import.unsupported_semantics",
|
|
9986
10873
|
"error",
|
|
9987
|
-
`Mermaid id "${
|
|
10874
|
+
`Mermaid id "${endpoint2.id}" is already used by a subgraph and cannot also be a node.`
|
|
9988
10875
|
);
|
|
9989
10876
|
return false;
|
|
9990
10877
|
}
|
|
9991
|
-
if (labelHasUnsupportedMarkup(
|
|
10878
|
+
if (labelHasUnsupportedMarkup(endpoint2.label)) {
|
|
9992
10879
|
addImportDiagnostic(
|
|
9993
10880
|
diagnostics,
|
|
9994
10881
|
sourceLines,
|
|
9995
10882
|
line,
|
|
9996
10883
|
"import.unsupported_semantics",
|
|
9997
10884
|
"error",
|
|
9998
|
-
`Mermaid label for node "${
|
|
10885
|
+
`Mermaid label for node "${endpoint2.id}" uses HTML or Markdown formatting that GraphDiagram cannot preserve.`
|
|
9999
10886
|
);
|
|
10000
10887
|
return false;
|
|
10001
10888
|
}
|
|
10002
|
-
const existingIndex = state.nodeIndexes.get(
|
|
10889
|
+
const existingIndex = state.nodeIndexes.get(endpoint2.id);
|
|
10003
10890
|
if (existingIndex !== void 0) {
|
|
10004
10891
|
const existing = state.nodes[existingIndex];
|
|
10005
10892
|
if (!existing) return false;
|
|
@@ -10010,7 +10897,7 @@ function addNode(state, endpoint, groupId, line, sourceLines, diagnostics, expli
|
|
|
10010
10897
|
line,
|
|
10011
10898
|
"import.unsupported_semantics",
|
|
10012
10899
|
"error",
|
|
10013
|
-
`Mermaid node "${
|
|
10900
|
+
`Mermaid node "${endpoint2.id}" is assigned to more than one subgraph; GraphDiagram nodes support one group.`
|
|
10014
10901
|
);
|
|
10015
10902
|
return false;
|
|
10016
10903
|
}
|
|
@@ -10021,28 +10908,28 @@ function addNode(state, endpoint, groupId, line, sourceLines, diagnostics, expli
|
|
|
10021
10908
|
line,
|
|
10022
10909
|
"import.unsupported_semantics",
|
|
10023
10910
|
"error",
|
|
10024
|
-
`Mermaid node "${
|
|
10911
|
+
`Mermaid node "${endpoint2.id}" is referenced both inside and outside a subgraph; its group membership is ambiguous.`
|
|
10025
10912
|
);
|
|
10026
10913
|
return false;
|
|
10027
10914
|
}
|
|
10028
|
-
if (explicitlyDeclared) existing.label =
|
|
10915
|
+
if (explicitlyDeclared) existing.label = endpoint2.label;
|
|
10029
10916
|
} else {
|
|
10030
|
-
state.nodeIndexes.set(
|
|
10917
|
+
state.nodeIndexes.set(endpoint2.id, state.nodes.length);
|
|
10031
10918
|
state.nodes.push({
|
|
10032
|
-
id:
|
|
10033
|
-
label:
|
|
10919
|
+
id: endpoint2.id,
|
|
10920
|
+
label: endpoint2.label,
|
|
10034
10921
|
...groupId ? { group: groupId } : {}
|
|
10035
10922
|
});
|
|
10036
10923
|
}
|
|
10037
|
-
if (
|
|
10038
|
-
state.warnedShapes.add(
|
|
10924
|
+
if (endpoint2.shape === "lossy" && !state.warnedShapes.has(endpoint2.id)) {
|
|
10925
|
+
state.warnedShapes.add(endpoint2.id);
|
|
10039
10926
|
addImportDiagnostic(
|
|
10040
10927
|
diagnostics,
|
|
10041
10928
|
sourceLines,
|
|
10042
10929
|
line,
|
|
10043
10930
|
"import.lossy_semantics",
|
|
10044
10931
|
"warning",
|
|
10045
|
-
`Mermaid node "${
|
|
10932
|
+
`Mermaid node "${endpoint2.id}" uses a non-rectangular shape; it will render as a generic GraphDiagram node.`
|
|
10046
10933
|
);
|
|
10047
10934
|
}
|
|
10048
10935
|
return true;
|
|
@@ -10441,7 +11328,7 @@ var import_path3 = require("path");
|
|
|
10441
11328
|
|
|
10442
11329
|
// src/diagnostics.ts
|
|
10443
11330
|
var import_parse_css_color3 = __toESM(require("parse-css-color"), 1);
|
|
10444
|
-
var
|
|
11331
|
+
var import_react16 = require("react");
|
|
10445
11332
|
var CHECK_DIAGNOSTIC_CODES = [
|
|
10446
11333
|
"accessibility.low_contrast",
|
|
10447
11334
|
"api.unsupported_prop",
|
|
@@ -10450,6 +11337,7 @@ var CHECK_DIAGNOSTIC_CODES = [
|
|
|
10450
11337
|
"frame.unknown_preset",
|
|
10451
11338
|
"layout.auto_size",
|
|
10452
11339
|
"layout.connector_congestion",
|
|
11340
|
+
"layout.connector_unroutable",
|
|
10453
11341
|
"layout.overflow",
|
|
10454
11342
|
"layout.text_overlap",
|
|
10455
11343
|
"layout.whitespace_imbalance",
|
|
@@ -10545,14 +11433,14 @@ function styleRecord(value) {
|
|
|
10545
11433
|
return value;
|
|
10546
11434
|
}
|
|
10547
11435
|
function hasDirectText(children) {
|
|
10548
|
-
return
|
|
11436
|
+
return import_react16.Children.toArray(children).some((child) => typeof child === "string" || typeof child === "number");
|
|
10549
11437
|
}
|
|
10550
11438
|
function elementId(props) {
|
|
10551
11439
|
const value = props.id ?? props["data-vizmatic-id"];
|
|
10552
11440
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
10553
11441
|
}
|
|
10554
11442
|
function resolveFunctionComponent(node, trustedComponents) {
|
|
10555
|
-
if (!(0,
|
|
11443
|
+
if (!(0, import_react16.isValidElement)(node) || typeof node.type !== "function" || trustedComponents.has(node.type)) return void 0;
|
|
10556
11444
|
const component = node.type;
|
|
10557
11445
|
if (component.__vizmaticPrimitive) return void 0;
|
|
10558
11446
|
if (component.prototype?.isReactComponent) return void 0;
|
|
@@ -10567,7 +11455,7 @@ function analyzeContrast(element, theme, trustedComponents = /* @__PURE__ */ new
|
|
|
10567
11455
|
const seen = /* @__PURE__ */ new Set();
|
|
10568
11456
|
let visited = 0;
|
|
10569
11457
|
function visit(node, inherited, path) {
|
|
10570
|
-
if (visited++ >= MAX_CONTRAST_NODES || !(0,
|
|
11458
|
+
if (visited++ >= MAX_CONTRAST_NODES || !(0, import_react16.isValidElement)(node)) return;
|
|
10571
11459
|
const resolved = resolveFunctionComponent(node, trustedComponents);
|
|
10572
11460
|
if (resolved !== void 0) {
|
|
10573
11461
|
visit(resolved, inherited, path);
|
|
@@ -10608,7 +11496,7 @@ function analyzeContrast(element, theme, trustedComponents = /* @__PURE__ */ new
|
|
|
10608
11496
|
}
|
|
10609
11497
|
}
|
|
10610
11498
|
}
|
|
10611
|
-
|
|
11499
|
+
import_react16.Children.forEach(props.children, (child, index) => visit(child, context, `${path}.${index}`));
|
|
10612
11500
|
}
|
|
10613
11501
|
visit(element, { background: colorFromCss(rootBackground2) }, "root");
|
|
10614
11502
|
return diagnostics;
|
|
@@ -10744,6 +11632,18 @@ function analyzeRenderedLayout(nodes, theme) {
|
|
|
10744
11632
|
const value = node.props[attribute2];
|
|
10745
11633
|
return typeof value === "number" ? value : Number(value) || 0;
|
|
10746
11634
|
}));
|
|
11635
|
+
for (const source of nodes.filter((node) => Number(node.props["data-vizmatic-unrouted-connectors"]) > 0)) {
|
|
11636
|
+
const messages = JSON.parse(String(source.props["data-vizmatic-routing-failures"]));
|
|
11637
|
+
for (const message of messages.slice(0, MAX_DIAGNOSTICS_PER_RULE)) diagnostics.push({
|
|
11638
|
+
code: "layout.connector_unroutable",
|
|
11639
|
+
severity: "error",
|
|
11640
|
+
theme,
|
|
11641
|
+
message,
|
|
11642
|
+
suggestion: "Increase canvas size or spacing, reduce routingClearance, or choose a different endpoint side or port.",
|
|
11643
|
+
elementId: elementId(source.props),
|
|
11644
|
+
location: { x: source.left, y: source.top, width: source.width, height: source.height }
|
|
11645
|
+
});
|
|
11646
|
+
}
|
|
10747
11647
|
const connectorCrossings2 = maxDataNumber("data-vizmatic-connector-crossings");
|
|
10748
11648
|
if (connectorCrossings2 > 0) {
|
|
10749
11649
|
const source = nodes.find((node) => Number(node.props["data-vizmatic-connector-crossings"]) > 0);
|
|
@@ -11197,10 +12097,13 @@ async function checkFrame(input, options = {}) {
|
|
|
11197
12097
|
Badge,
|
|
11198
12098
|
BadgePill,
|
|
11199
12099
|
BarChart,
|
|
12100
|
+
Board,
|
|
11200
12101
|
Box,
|
|
12102
|
+
CANVAS_ITEM_COMPONENT,
|
|
11201
12103
|
CHECK_DIAGNOSTIC_CODES,
|
|
11202
12104
|
CalloutCard,
|
|
11203
12105
|
Canvas,
|
|
12106
|
+
CanvasItem,
|
|
11204
12107
|
CanvasOverflowError,
|
|
11205
12108
|
Card,
|
|
11206
12109
|
ChartFrame,
|
|
@@ -11233,7 +12136,9 @@ async function checkFrame(input, options = {}) {
|
|
|
11233
12136
|
MetricCard,
|
|
11234
12137
|
MiniBarChart,
|
|
11235
12138
|
Panel,
|
|
12139
|
+
ParetoBarChart,
|
|
11236
12140
|
ParetoChart,
|
|
12141
|
+
PieChart,
|
|
11237
12142
|
Pipeline,
|
|
11238
12143
|
ProgressList,
|
|
11239
12144
|
ProgressRow,
|
|
@@ -11313,6 +12218,7 @@ async function checkFrame(input, options = {}) {
|
|
|
11313
12218
|
toneGradients,
|
|
11314
12219
|
tween,
|
|
11315
12220
|
typography,
|
|
12221
|
+
withColorAlpha,
|
|
11316
12222
|
wrapWithBrand,
|
|
11317
12223
|
wrapWithWatermark
|
|
11318
12224
|
});
|