vizmatic 0.7.0 → 0.7.2
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 +25 -1
- package/ROADMAP.md +2 -2
- package/dist/{chunk-4XE64I2U.js → chunk-DZHX76RS.js} +8 -1
- package/dist/{chunk-CJOXWJQA.js → chunk-F6QI6QJY.js} +96 -6
- package/dist/chunk-QVYHYC7T.js +88 -0
- package/dist/cli.js +3 -3
- package/dist/index.cjs +1357 -722
- package/dist/index.d.cts +132 -67
- package/dist/index.d.ts +132 -67
- package/dist/index.js +881 -340
- package/dist/scene-browser.js +18 -18
- package/dist/scene-cli.js +1 -1
- package/dist/scene-runtime.cjs +8 -1
- package/dist/scene-runtime.d.cts +1 -1
- package/dist/scene-runtime.d.ts +1 -1
- package/dist/scene-runtime.js +1 -1
- package/dist/stage-browser/browser.d.ts +120 -2
- package/dist/stage-browser/stage.js +5 -5
- package/dist/stage-export.cjs +87 -5
- package/dist/stage-export.d.cts +5 -1
- package/dist/stage-export.d.ts +5 -1
- package/dist/stage-export.js +11 -1
- package/dist/stage.cjs +221 -22
- package/dist/stage.d.cts +122 -4
- package/dist/stage.d.ts +122 -4
- package/dist/stage.js +203 -9
- package/dist/{svg-import-Djj2q7Pc.d.ts → svg-import-5_oTbEJR.d.cts} +2 -2
- package/dist/{svg-import-Djj2q7Pc.d.cts → svg-import-5_oTbEJR.d.ts} +2 -2
- package/dist/{video-CcHW1qhV.d.ts → video-BSwNJZkn.d.cts} +25 -1
- package/dist/{video-CcHW1qhV.d.cts → video-BSwNJZkn.d.ts} +25 -1
- package/examples/README.md +1 -0
- package/examples/entity-relationship.tsx +50 -0
- package/package.json +1 -1
- package/dist/chunk-MAHT32CE.js +0 -79
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
prepareScene,
|
|
9
9
|
sceneSha256,
|
|
10
10
|
validateResolvedSceneResources
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-DZHX76RS.js";
|
|
12
12
|
import {
|
|
13
13
|
CANVAS_CHART_COMPONENT,
|
|
14
14
|
CHART_FRAME_COMPONENT,
|
|
@@ -18,6 +18,10 @@ import {
|
|
|
18
18
|
Watermark,
|
|
19
19
|
addSvgAccessibility,
|
|
20
20
|
analyzeAnimationCadence,
|
|
21
|
+
captionsToSrt,
|
|
22
|
+
chapterMetadata,
|
|
23
|
+
chartAccessibilityAttributes,
|
|
24
|
+
chartDescription,
|
|
21
25
|
convertIndexedToRgb,
|
|
22
26
|
cropPixels,
|
|
23
27
|
decodePng,
|
|
@@ -51,7 +55,7 @@ import {
|
|
|
51
55
|
withRenderContext,
|
|
52
56
|
wrapWithBrand,
|
|
53
57
|
wrapWithWatermark
|
|
54
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-F6QI6QJY.js";
|
|
55
59
|
import {
|
|
56
60
|
DEFAULT_DENSITY,
|
|
57
61
|
DENSITY_NAMES,
|
|
@@ -122,6 +126,7 @@ __export(primitives_exports, {
|
|
|
122
126
|
DonutChart: () => DonutChart,
|
|
123
127
|
DotPoint: () => DotPoint,
|
|
124
128
|
ELEMENT_SYMBOLS: () => ELEMENT_SYMBOLS,
|
|
129
|
+
EntityRelationshipDiagram: () => EntityRelationshipDiagram,
|
|
125
130
|
EquationCard: () => EquationCard,
|
|
126
131
|
FactRows: () => FactRows,
|
|
127
132
|
Flow: () => Flow,
|
|
@@ -1809,7 +1814,8 @@ function Sparkline({
|
|
|
1809
1814
|
endDot = true,
|
|
1810
1815
|
min,
|
|
1811
1816
|
max,
|
|
1812
|
-
strokeWidth
|
|
1817
|
+
strokeWidth,
|
|
1818
|
+
...accessibility
|
|
1813
1819
|
}) {
|
|
1814
1820
|
const d = densityOf(c);
|
|
1815
1821
|
const w = width ?? d.f(72);
|
|
@@ -1824,7 +1830,7 @@ function Sparkline({
|
|
|
1824
1830
|
const y = (value) => inset + (1 - (value - low) / range) * (h - inset * 2);
|
|
1825
1831
|
const path = values.map((value, index) => `${index === 0 ? "M" : "L"} ${x(index).toFixed(2)} ${y(value).toFixed(2)}`).join(" ");
|
|
1826
1832
|
const last = values.length - 1;
|
|
1827
|
-
|
|
1833
|
+
const chart = React4.createElement(
|
|
1828
1834
|
"svg",
|
|
1829
1835
|
{
|
|
1830
1836
|
width: w,
|
|
@@ -1857,6 +1863,15 @@ function Sparkline({
|
|
|
1857
1863
|
})
|
|
1858
1864
|
])
|
|
1859
1865
|
);
|
|
1866
|
+
if (!accessibility.ariaLabel && !accessibility.description) return chart;
|
|
1867
|
+
return React4.createElement("div", {
|
|
1868
|
+
...chartAccessibilityAttributes({
|
|
1869
|
+
...accessibility,
|
|
1870
|
+
ariaLabel: accessibility.ariaLabel ?? "Sparkline",
|
|
1871
|
+
description: chartDescription(accessibility.description, values.map((value, index) => `Point ${index + 1}: ${value}`))
|
|
1872
|
+
}),
|
|
1873
|
+
style: { display: "flex", width: w, height: h, flexShrink: 0 }
|
|
1874
|
+
}, chart);
|
|
1860
1875
|
}
|
|
1861
1876
|
function InlineBar({ value, c, width = "100%", height, tone, color, warnAt }) {
|
|
1862
1877
|
const d = densityOf(c);
|
|
@@ -2185,7 +2200,8 @@ function MiniBarChart({
|
|
|
2185
2200
|
gap: gapProp,
|
|
2186
2201
|
radius: radiusProp,
|
|
2187
2202
|
fontSize: fontSizeProp,
|
|
2188
|
-
showValues = false
|
|
2203
|
+
showValues = false,
|
|
2204
|
+
...accessibility
|
|
2189
2205
|
}) {
|
|
2190
2206
|
const gap = gapProp ?? densityOf(c).s(10);
|
|
2191
2207
|
const radius = radiusProp ?? densityOf(c).r(3);
|
|
@@ -2197,6 +2213,15 @@ function MiniBarChart({
|
|
|
2197
2213
|
return React5.createElement(
|
|
2198
2214
|
"div",
|
|
2199
2215
|
{
|
|
2216
|
+
...chartAccessibilityAttributes({
|
|
2217
|
+
...accessibility,
|
|
2218
|
+
ariaLabel: accessibility.ariaLabel ?? "Mini bar chart",
|
|
2219
|
+
description: chartDescription(accessibility.description, data.map((item, index) => {
|
|
2220
|
+
const label = typeof item.label === "string" || typeof item.label === "number" ? item.label : `Item ${index + 1}`;
|
|
2221
|
+
const value = typeof item.valueLabel === "string" || typeof item.valueLabel === "number" ? item.valueLabel : item.value;
|
|
2222
|
+
return `${label}: ${value}`;
|
|
2223
|
+
}))
|
|
2224
|
+
}),
|
|
2200
2225
|
style: {
|
|
2201
2226
|
display: "flex",
|
|
2202
2227
|
alignItems: "flex-end",
|
|
@@ -6673,6 +6698,398 @@ function DeploymentDiagram({
|
|
|
6673
6698
|
}
|
|
6674
6699
|
Object.defineProperty(DeploymentDiagram, SVG_ACCESSIBILITY_COMPONENT, { value: true });
|
|
6675
6700
|
|
|
6701
|
+
// src/primitives/entity-relationship.ts
|
|
6702
|
+
import React10 from "react";
|
|
6703
|
+
import dagre2 from "@dagrejs/dagre";
|
|
6704
|
+
var cardinalityWords = {
|
|
6705
|
+
one: "exactly one",
|
|
6706
|
+
"zero-or-one": "zero or one",
|
|
6707
|
+
"one-or-many": "one or more",
|
|
6708
|
+
"zero-or-many": "zero or more"
|
|
6709
|
+
};
|
|
6710
|
+
var legendLines = [
|
|
6711
|
+
"PK primary key \xB7 FK foreign key \xB7 UQ unique \xB7 ? nullable",
|
|
6712
|
+
"|| one \xB7 o| zero or one \xB7 |< one or more \xB7 o< zero or more"
|
|
6713
|
+
];
|
|
6714
|
+
function requiredText(value, label) {
|
|
6715
|
+
if (typeof value !== "string" || !value.trim()) throw new Error(`EntityRelationshipDiagram ${label} must be a non-empty string.`);
|
|
6716
|
+
}
|
|
6717
|
+
function positive(value, label, allowZero = false) {
|
|
6718
|
+
if (!Number.isFinite(value) || (allowZero ? value < 0 : value <= 0)) {
|
|
6719
|
+
throw new RangeError(`EntityRelationshipDiagram ${label} must be a finite ${allowZero ? "non-negative" : "positive"} number.`);
|
|
6720
|
+
}
|
|
6721
|
+
}
|
|
6722
|
+
function endpointAttributes(endpoint2) {
|
|
6723
|
+
return endpoint2.attribute === void 0 ? [] : typeof endpoint2.attribute === "string" ? [endpoint2.attribute] : endpoint2.attribute;
|
|
6724
|
+
}
|
|
6725
|
+
function attributeDescription(attribute) {
|
|
6726
|
+
const constraints = [attribute.primaryKey && "primary key", attribute.foreignKey && "foreign key", attribute.unique && "unique", attribute.nullable ? "nullable" : "not null"].filter(Boolean);
|
|
6727
|
+
return `${attribute.name} (${attribute.type}, ${constraints.join(", ")})`;
|
|
6728
|
+
}
|
|
6729
|
+
function endpointDescription(endpoint2, entities) {
|
|
6730
|
+
const entity = entities.get(endpoint2.entity);
|
|
6731
|
+
const attributes = endpointAttributes(endpoint2);
|
|
6732
|
+
return `${entity.label ?? entity.id}${attributes.length ? ` [${attributes.join(", ")}]` : ""}`;
|
|
6733
|
+
}
|
|
6734
|
+
function validate(entities, relationships) {
|
|
6735
|
+
if (!entities.length) throw new Error("EntityRelationshipDiagram requires at least one entity.");
|
|
6736
|
+
const byId = /* @__PURE__ */ new Map();
|
|
6737
|
+
for (const entity of entities) {
|
|
6738
|
+
requiredText(entity.id, "entity id");
|
|
6739
|
+
if (byId.has(entity.id)) throw new Error(`EntityRelationshipDiagram has duplicate entity id "${entity.id}".`);
|
|
6740
|
+
if (entity.label !== void 0) requiredText(entity.label, `entity "${entity.id}" label`);
|
|
6741
|
+
const names = /* @__PURE__ */ new Set();
|
|
6742
|
+
for (const attribute of entity.attributes) {
|
|
6743
|
+
requiredText(attribute.name, `entity "${entity.id}" attribute name`);
|
|
6744
|
+
requiredText(attribute.type, `attribute "${entity.id}.${attribute.name}" type`);
|
|
6745
|
+
if (names.has(attribute.name)) throw new Error(`EntityRelationshipDiagram has duplicate attribute "${entity.id}.${attribute.name}".`);
|
|
6746
|
+
if (attribute.primaryKey && attribute.nullable) throw new Error(`EntityRelationshipDiagram primary key "${entity.id}.${attribute.name}" cannot be nullable.`);
|
|
6747
|
+
names.add(attribute.name);
|
|
6748
|
+
}
|
|
6749
|
+
byId.set(entity.id, entity);
|
|
6750
|
+
}
|
|
6751
|
+
const ids = /* @__PURE__ */ new Set();
|
|
6752
|
+
for (const relationship of relationships) {
|
|
6753
|
+
requiredText(relationship.id, "relationship id");
|
|
6754
|
+
if (ids.has(relationship.id)) throw new Error(`EntityRelationshipDiagram has duplicate relationship id "${relationship.id}".`);
|
|
6755
|
+
ids.add(relationship.id);
|
|
6756
|
+
for (const endpoint2 of [relationship.from, relationship.to]) {
|
|
6757
|
+
const entity = byId.get(endpoint2.entity);
|
|
6758
|
+
if (!entity) throw new Error(`EntityRelationshipDiagram relationship "${relationship.id}" references missing entity "${endpoint2.entity}".`);
|
|
6759
|
+
if (!Object.hasOwn(cardinalityWords, endpoint2.cardinality)) throw new Error(`EntityRelationshipDiagram relationship "${relationship.id}" has invalid cardinality "${endpoint2.cardinality}".`);
|
|
6760
|
+
const attributes = endpointAttributes(endpoint2);
|
|
6761
|
+
if (endpoint2.attribute !== void 0 && attributes.length === 0) throw new Error(`EntityRelationshipDiagram relationship "${relationship.id}" needs at least one endpoint attribute.`);
|
|
6762
|
+
if (new Set(attributes).size !== attributes.length) throw new Error(`EntityRelationshipDiagram relationship "${relationship.id}" repeats an endpoint attribute.`);
|
|
6763
|
+
for (const name of attributes) {
|
|
6764
|
+
if (!entity.attributes.some((attribute) => attribute.name === name)) throw new Error(`EntityRelationshipDiagram relationship "${relationship.id}" references missing attribute "${entity.id}.${name}".`);
|
|
6765
|
+
}
|
|
6766
|
+
}
|
|
6767
|
+
const from = endpointAttributes(relationship.from), to = endpointAttributes(relationship.to);
|
|
6768
|
+
if (from.length && to.length && from.length !== to.length) throw new Error(`EntityRelationshipDiagram relationship "${relationship.id}" has mismatched composite attribute counts.`);
|
|
6769
|
+
}
|
|
6770
|
+
return byId;
|
|
6771
|
+
}
|
|
6772
|
+
function cardinalitySize(cardinality, scale) {
|
|
6773
|
+
const many = cardinality.endsWith("many"), optional = cardinality.startsWith("zero");
|
|
6774
|
+
return { length: ((optional ? many ? 25 : 19 : many ? 20 : 12) + 0.75) * scale, halfWidth: ((many ? 6 : 5) + 0.75) * scale };
|
|
6775
|
+
}
|
|
6776
|
+
function cardinalityBounds(cardinality, point, toward, scale) {
|
|
6777
|
+
const size = cardinalitySize(cardinality, scale);
|
|
6778
|
+
const horizontal = point.y === toward.y;
|
|
6779
|
+
const end = { x: point.x + Math.sign(toward.x - point.x) * size.length, y: point.y + Math.sign(toward.y - point.y) * size.length };
|
|
6780
|
+
return {
|
|
6781
|
+
left: Math.min(point.x, end.x) - (horizontal ? 0.75 * scale : size.halfWidth),
|
|
6782
|
+
right: Math.max(point.x, end.x) + (horizontal ? 0.75 * scale : size.halfWidth),
|
|
6783
|
+
top: Math.min(point.y, end.y) - (horizontal ? size.halfWidth : 0.75 * scale),
|
|
6784
|
+
bottom: Math.max(point.y, end.y) + (horizontal ? size.halfWidth : 0.75 * scale)
|
|
6785
|
+
};
|
|
6786
|
+
}
|
|
6787
|
+
function cardinalityGlyph(cardinality, point, toward, color, background, scale, key) {
|
|
6788
|
+
const length = Math.hypot(toward.x - point.x, toward.y - point.y);
|
|
6789
|
+
const ux = (toward.x - point.x) / length, uy = (toward.y - point.y) / length;
|
|
6790
|
+
const at = (along, across = 0) => ({ x: point.x + (ux * along - uy * across) * scale, y: point.y + (uy * along + ux * across) * scale });
|
|
6791
|
+
const bar = (along) => {
|
|
6792
|
+
const a = at(along, -5), b = at(along, 5);
|
|
6793
|
+
return `M ${a.x} ${a.y} L ${b.x} ${b.y}`;
|
|
6794
|
+
};
|
|
6795
|
+
const many = cardinality.endsWith("many");
|
|
6796
|
+
const optional = cardinality.startsWith("zero");
|
|
6797
|
+
const middle = at(13), top = at(0, -6), bottom = at(0, 6);
|
|
6798
|
+
const path = many ? `M ${top.x} ${top.y} L ${middle.x} ${middle.y} L ${bottom.x} ${bottom.y} M ${point.x} ${point.y} L ${middle.x} ${middle.y}` : bar(5);
|
|
6799
|
+
const circle = at(many ? 21 : 15);
|
|
6800
|
+
return React10.createElement(
|
|
6801
|
+
"g",
|
|
6802
|
+
{ key, "data-er-cardinality": cardinality },
|
|
6803
|
+
React10.createElement("path", { d: `${path}${optional ? "" : ` ${bar(many ? 20 : 12)}`}`, fill: "none", stroke: color, strokeWidth: 1.5 * scale }),
|
|
6804
|
+
optional && React10.createElement("circle", { cx: circle.x, cy: circle.y, r: 4 * scale, fill: background, stroke: color, strokeWidth: 1.5 * scale })
|
|
6805
|
+
);
|
|
6806
|
+
}
|
|
6807
|
+
function EntityRelationshipDiagram({
|
|
6808
|
+
c: baseTheme,
|
|
6809
|
+
entities,
|
|
6810
|
+
relationships = [],
|
|
6811
|
+
title,
|
|
6812
|
+
description,
|
|
6813
|
+
id,
|
|
6814
|
+
direction = "LR",
|
|
6815
|
+
width,
|
|
6816
|
+
height,
|
|
6817
|
+
entityWidth,
|
|
6818
|
+
fontSize,
|
|
6819
|
+
padding: paddingProp,
|
|
6820
|
+
gap: gapProp,
|
|
6821
|
+
showLegend = true,
|
|
6822
|
+
density
|
|
6823
|
+
}) {
|
|
6824
|
+
const c = density === void 0 ? baseTheme : withDensity(baseTheme, density);
|
|
6825
|
+
const d = densityOf(c);
|
|
6826
|
+
const visibleTitle = title?.trim();
|
|
6827
|
+
const svgTitle = visibleTitle || "Entity relationship diagram";
|
|
6828
|
+
const textSize = fontSize ?? d.type.small;
|
|
6829
|
+
const headerSize = Math.max(textSize, d.type.label);
|
|
6830
|
+
const padding = paddingProp ?? d.s(32);
|
|
6831
|
+
const gap = gapProp ?? d.s(100);
|
|
6832
|
+
positive(textSize, "fontSize");
|
|
6833
|
+
positive(padding, "padding", true);
|
|
6834
|
+
positive(gap, "gap");
|
|
6835
|
+
if (width !== void 0) positive(width, "width");
|
|
6836
|
+
if (height !== void 0) positive(height, "height");
|
|
6837
|
+
if (entityWidth !== void 0) positive(entityWidth, "entityWidth");
|
|
6838
|
+
if (id !== void 0) requiredText(id, "id");
|
|
6839
|
+
if (!["LR", "RL", "TB", "BT"].includes(direction)) throw new Error("EntityRelationshipDiagram direction must be LR, RL, TB, or BT.");
|
|
6840
|
+
const byId = validate(entities, relationships);
|
|
6841
|
+
const lineScale = Math.max(0.8, textSize / 12);
|
|
6842
|
+
const markerSizes = relationships.flatMap((relationship) => [cardinalitySize(relationship.from.cardinality, lineScale), cardinalitySize(relationship.to.cardinality, lineScale)]);
|
|
6843
|
+
const markerLength = Math.max(0, ...markerSizes.map((size) => size.length));
|
|
6844
|
+
const markerPitch = Math.max(0, ...markerSizes.map((size) => size.halfWidth * 2)) + Math.max(d.s(4), lineScale * 1.5);
|
|
6845
|
+
const baseClearance = Math.max(28, d.s(28));
|
|
6846
|
+
const routingClearance = Math.max(baseClearance, markerLength + d.s(4) + Math.max(2, d.s(2)));
|
|
6847
|
+
const enlargedMarkers = routingClearance > baseClearance;
|
|
6848
|
+
const bodyPadding = enlargedMarkers && relationships.some((relationship) => relationship.from.entity === relationship.to.entity) ? Math.max(padding, routingClearance + d.s(4)) : padding;
|
|
6849
|
+
const anchorRow = (endpoint2) => {
|
|
6850
|
+
const entity = byId.get(endpoint2.entity), names = endpointAttributes(endpoint2);
|
|
6851
|
+
return names.length ? Math.round(names.reduce((sum, name) => sum + entity.attributes.findIndex((attribute) => attribute.name === name), 0) / names.length) : Math.floor(Math.max(0, entity.attributes.length - 1) / 2);
|
|
6852
|
+
};
|
|
6853
|
+
const rowEndpointCounts = new Map(entities.map((entity) => [entity.id, /* @__PURE__ */ new Map()]));
|
|
6854
|
+
const entityEndpointCounts = /* @__PURE__ */ new Map();
|
|
6855
|
+
for (const relationship of relationships) for (const endpoint2 of [relationship.from, relationship.to]) {
|
|
6856
|
+
const counts2 = rowEndpointCounts.get(endpoint2.entity), row = anchorRow(endpoint2);
|
|
6857
|
+
counts2.set(row, (counts2.get(row) ?? 0) + 1);
|
|
6858
|
+
entityEndpointCounts.set(endpoint2.entity, (entityEndpointCounts.get(endpoint2.entity) ?? 0) + 1);
|
|
6859
|
+
}
|
|
6860
|
+
const rowHeight = Math.ceil(Math.max(d.s(25), textSize * 1.7));
|
|
6861
|
+
const headerHeight = Math.ceil(Math.max(d.s(35), headerSize * 2));
|
|
6862
|
+
const inset = d.s(12);
|
|
6863
|
+
const keyWidth = Math.ceil(estimateTextWidth("PK FK UQ", textSize, { mono: true })) + inset;
|
|
6864
|
+
const titleHeight = visibleTitle ? Math.ceil(d.type.heading * 1.5 + d.s(12)) : 0;
|
|
6865
|
+
const legendHeight = showLegend ? Math.ceil(textSize * 3.2 + d.s(12)) : 0;
|
|
6866
|
+
const legendWidth = showLegend ? Math.max(480, ...legendLines.map((line) => estimateTextWidth(line, textSize) + padding * 2)) : 0;
|
|
6867
|
+
const labelPadding = relationships.some((relationship) => relationship.label) ? Math.ceil(textSize * 2 + d.s(8)) : 0;
|
|
6868
|
+
const graph = new dagre2.graphlib.Graph({ multigraph: true }).setGraph({
|
|
6869
|
+
rankdir: direction,
|
|
6870
|
+
nodesep: enlargedMarkers ? Math.max(gap * 0.75, routingClearance * 2 + markerPitch) : gap * 0.75,
|
|
6871
|
+
ranksep: Math.max(gap, 74, routingClearance * 2 + markerPitch),
|
|
6872
|
+
edgesep: d.s(26),
|
|
6873
|
+
marginx: 0,
|
|
6874
|
+
marginy: 0
|
|
6875
|
+
}).setDefaultEdgeLabel(() => ({}));
|
|
6876
|
+
const measures = new Map(entities.map((entity) => {
|
|
6877
|
+
const nameWidth = Math.max(30, ...entity.attributes.map((attribute) => estimateTextWidth(attribute.name, textSize, { mono: true })));
|
|
6878
|
+
const typeWidth = Math.max(24, ...entity.attributes.map((attribute) => estimateTextWidth(attribute.type + (attribute.nullable ? "?" : ""), textSize, { mono: true })));
|
|
6879
|
+
const rowHeights = Array.from({ length: Math.max(1, entity.attributes.length) }, (_, index) => Math.max(rowHeight, Math.ceil((rowEndpointCounts.get(entity.id).get(index) ?? 0) * markerPitch)));
|
|
6880
|
+
let rowY = headerHeight;
|
|
6881
|
+
const rowCenters = rowHeights.map((height2) => {
|
|
6882
|
+
const center2 = rowY + height2 / 2;
|
|
6883
|
+
rowY += height2;
|
|
6884
|
+
return center2;
|
|
6885
|
+
});
|
|
6886
|
+
const measured = {
|
|
6887
|
+
width: Math.ceil(Math.max(
|
|
6888
|
+
entityWidth ?? d.s(210),
|
|
6889
|
+
estimateTextWidth(entity.label ?? entity.id, headerSize, { weight: 600 }) + inset * 2,
|
|
6890
|
+
keyWidth + nameWidth + typeWidth + inset * 4,
|
|
6891
|
+
direction === "TB" || direction === "BT" ? markerPitch * ((entityEndpointCounts.get(entity.id) ?? 0) + 1) : 0
|
|
6892
|
+
)),
|
|
6893
|
+
height: rowY,
|
|
6894
|
+
rowHeights,
|
|
6895
|
+
rowCenters,
|
|
6896
|
+
typeWidth: Math.ceil(typeWidth)
|
|
6897
|
+
};
|
|
6898
|
+
graph.setNode(entity.id, { width: measured.width, height: measured.height });
|
|
6899
|
+
return [entity.id, measured];
|
|
6900
|
+
}));
|
|
6901
|
+
for (const relationship of relationships) graph.setEdge(relationship.from.entity, relationship.to.entity, {
|
|
6902
|
+
width: relationship.label ? estimateTextWidth(relationship.label, textSize) + d.s(64) : 0,
|
|
6903
|
+
height: relationship.label ? textSize * 2 : 0,
|
|
6904
|
+
labelpos: "c"
|
|
6905
|
+
}, relationship.id);
|
|
6906
|
+
dagre2.layout(graph);
|
|
6907
|
+
const graphWidth = graph.graph().width ?? 0, graphHeight = graph.graph().height ?? 0;
|
|
6908
|
+
const minWidth = Math.ceil(Math.max(graphWidth + (bodyPadding + labelPadding) * 2, legendWidth, visibleTitle ? estimateTextWidth(visibleTitle, d.type.heading, { weight: 600 }) + padding * 2 : 0));
|
|
6909
|
+
const minHeight = Math.ceil(graphHeight + (bodyPadding + labelPadding) * 2 + titleHeight + legendHeight);
|
|
6910
|
+
if (width !== void 0 && width < minWidth) throw new RangeError(`EntityRelationshipDiagram width needs at least ${minWidth}px to keep entity text readable.`);
|
|
6911
|
+
if (height !== void 0 && height < minHeight) throw new RangeError(`EntityRelationshipDiagram height needs at least ${minHeight}px to keep entity text readable.`);
|
|
6912
|
+
const resolvedWidth = width ?? minWidth, resolvedHeight = height ?? minHeight;
|
|
6913
|
+
const offsetX = (resolvedWidth - graphWidth) / 2;
|
|
6914
|
+
const offsetY = bodyPadding + titleHeight + labelPadding + (resolvedHeight - minHeight) / 2;
|
|
6915
|
+
const nodes = entities.map((entity) => {
|
|
6916
|
+
const node = graph.node(entity.id), measure = measures.get(entity.id);
|
|
6917
|
+
return { id: entity.id, cx: node.x + offsetX, cy: node.y + offsetY, width: measure.width, height: measure.height, ports: [] };
|
|
6918
|
+
});
|
|
6919
|
+
const nodeById = new Map(nodes.map((node) => [node.id, node]));
|
|
6920
|
+
const portRequests = [];
|
|
6921
|
+
const endpointPort = (endpoint2, other, port) => {
|
|
6922
|
+
const node = nodeById.get(endpoint2.entity), target = nodeById.get(other.entity);
|
|
6923
|
+
const horizontal = direction === "LR" || direction === "RL";
|
|
6924
|
+
const side = node === target ? "right" : horizontal ? target.cx >= node.cx ? "right" : "left" : target.cy >= node.cy ? "bottom" : "top";
|
|
6925
|
+
const desired = side === "top" || side === "bottom" ? node.width / 2 : measures.get(node.id).rowCenters[anchorRow(endpoint2)];
|
|
6926
|
+
portRequests.push({ node, id: port, side, desired });
|
|
6927
|
+
};
|
|
6928
|
+
const edges = relationships.map((relationship, index) => {
|
|
6929
|
+
const fromPort = `from-${index}`, toPort = `to-${index}`;
|
|
6930
|
+
endpointPort(relationship.from, relationship.to, fromPort);
|
|
6931
|
+
endpointPort(relationship.to, relationship.from, toPort);
|
|
6932
|
+
return { from: relationship.from.entity, to: relationship.to.entity, fromPort, toPort };
|
|
6933
|
+
});
|
|
6934
|
+
for (const node of nodes) for (const side of ["left", "right", "top", "bottom"]) {
|
|
6935
|
+
const requests = portRequests.filter((request) => request.node === node && request.side === side).sort((a, b) => a.desired - b.desired);
|
|
6936
|
+
const extent = side === "left" || side === "right" ? node.height : node.width;
|
|
6937
|
+
const positions = [];
|
|
6938
|
+
for (let start = 0; start < requests.length; ) {
|
|
6939
|
+
let end = start + 1;
|
|
6940
|
+
while (end < requests.length && requests[end].desired === requests[start].desired) end++;
|
|
6941
|
+
for (let index = start; index < end; index++) positions[index] = requests[index].desired + (index - start - (end - start - 1) / 2) * markerPitch;
|
|
6942
|
+
start = end;
|
|
6943
|
+
}
|
|
6944
|
+
for (let index = 0; index < positions.length; index++) positions[index] = Math.max(positions[index], index ? positions[index - 1] + markerPitch : markerPitch / 2);
|
|
6945
|
+
for (let index = positions.length - 1; index >= 0; index--) positions[index] = Math.min(positions[index], index === positions.length - 1 ? extent - markerPitch / 2 : positions[index + 1] - markerPitch);
|
|
6946
|
+
requests.forEach((request, index) => node.ports.push({ id: request.id, side, offset: positions[index] / extent }));
|
|
6947
|
+
}
|
|
6948
|
+
const routed = routeOrthogonalGraph(nodes, edges, resolvedWidth, resolvedHeight - legendHeight, routingClearance, Math.max(d.s(18), markerPitch));
|
|
6949
|
+
if (routed.failures.length) throw new Error(`EntityRelationshipDiagram could not route relationship "${relationships[routed.failures[0].index].id}": ${routed.failures[0].reason}`);
|
|
6950
|
+
const relationshipText = (relationship) => `${endpointDescription(relationship.from, byId)} (${cardinalityWords[relationship.from.cardinality]}) to ${endpointDescription(relationship.to, byId)} (${cardinalityWords[relationship.to.cardinality]})${relationship.label ? `: ${relationship.label}` : ""}${relationship.identifying ? ", identifying relationship" : ", non-identifying relationship"}.`;
|
|
6951
|
+
const schemaSummary = `${entities.length} entities and ${relationships.length} relationships. ${entities.map((entity) => `${entity.label ?? entity.id}: ${entity.attributes.map(attributeDescription).join("; ") || "no attributes shown"}.`).join(" ")} ${relationships.map(relationshipText).join(" ")}`;
|
|
6952
|
+
const lineColor = c.textSecondary;
|
|
6953
|
+
const labels = [];
|
|
6954
|
+
const placedLabels = [];
|
|
6955
|
+
const markerBoxes = relationships.flatMap((relationship, index) => {
|
|
6956
|
+
const points = routed.routes.get(index);
|
|
6957
|
+
return [cardinalityBounds(relationship.from.cardinality, points[0], points[1], lineScale), cardinalityBounds(relationship.to.cardinality, points.at(-1), points.at(-2), lineScale)];
|
|
6958
|
+
});
|
|
6959
|
+
const occupied = nodes.map((node) => ({ left: node.cx - node.width / 2 - 3, right: node.cx + node.width / 2 + 3, top: node.cy - node.height / 2 - 3, bottom: node.cy + node.height / 2 + 3 }));
|
|
6960
|
+
const paths = relationships.flatMap((relationship, index) => {
|
|
6961
|
+
const points = routed.routes.get(index);
|
|
6962
|
+
const path = roundedPolylinePath(points, d.s(4)).d;
|
|
6963
|
+
if (relationship.label) {
|
|
6964
|
+
const segments = points.slice(1).map((point, at) => ({ a: points[at], b: point, length: Math.hypot(point.x - points[at].x, point.y - points[at].y) }));
|
|
6965
|
+
const labelWidth = Math.ceil(estimateTextWidth(relationship.label, textSize)) + d.s(10);
|
|
6966
|
+
const labelHeight = Math.ceil(textSize * 1.4) + 4;
|
|
6967
|
+
const candidates = segments.sort((a, b) => b.length - a.length).flatMap((segment) => {
|
|
6968
|
+
return [0.5, 0.25, 0.75].flatMap((fraction) => [1, 2, 3].flatMap((distance) => [-1, 1].map((side) => {
|
|
6969
|
+
const x = segment.a.x + (segment.b.x - segment.a.x) * fraction;
|
|
6970
|
+
const y = segment.a.y + (segment.b.y - segment.a.y) * fraction;
|
|
6971
|
+
const horizontal = segment.a.y === segment.b.y;
|
|
6972
|
+
const cx = x + (horizontal ? 0 : side * (labelWidth / 2 + d.s(6)) * distance);
|
|
6973
|
+
const cy = y + (horizontal ? side * (labelHeight / 2 + d.s(6)) * distance : 0);
|
|
6974
|
+
return { left: cx - labelWidth / 2, right: cx + labelWidth / 2, top: cy - labelHeight / 2, bottom: cy + labelHeight / 2 };
|
|
6975
|
+
})));
|
|
6976
|
+
});
|
|
6977
|
+
const label = candidates.find((box2) => box2.left >= 0 && box2.right <= resolvedWidth && box2.top >= padding + titleHeight && box2.bottom <= resolvedHeight - padding - legendHeight && ![...occupied, ...markerBoxes, ...placedLabels].some((other) => box2.left < other.right && box2.right > other.left && box2.top < other.bottom && box2.bottom > other.top) && ![...routed.routes.values()].some((route) => samplesHitBox(route, box2)));
|
|
6978
|
+
if (!label) throw new Error(`EntityRelationshipDiagram could not place label for relationship "${relationship.id}" without covering the schema. Increase gap or canvas size.`);
|
|
6979
|
+
placedLabels.push(label);
|
|
6980
|
+
labels.push(React10.createElement("div", { key: `label-${relationship.id}`, style: {
|
|
6981
|
+
position: "absolute",
|
|
6982
|
+
left: label.left,
|
|
6983
|
+
top: label.top,
|
|
6984
|
+
width: labelWidth,
|
|
6985
|
+
height: labelHeight,
|
|
6986
|
+
display: "flex",
|
|
6987
|
+
alignItems: "center",
|
|
6988
|
+
justifyContent: "center",
|
|
6989
|
+
backgroundColor: c.bg,
|
|
6990
|
+
color: c.textSecondary,
|
|
6991
|
+
fontSize: textSize,
|
|
6992
|
+
fontFamily: c.fontSans,
|
|
6993
|
+
whiteSpace: "nowrap"
|
|
6994
|
+
} }, relationship.label));
|
|
6995
|
+
}
|
|
6996
|
+
return [
|
|
6997
|
+
React10.createElement("path", {
|
|
6998
|
+
key: `path-${relationship.id}`,
|
|
6999
|
+
d: path,
|
|
7000
|
+
fill: "none",
|
|
7001
|
+
stroke: lineColor,
|
|
7002
|
+
strokeWidth: d.w(1.5),
|
|
7003
|
+
strokeDasharray: relationship.identifying ? void 0 : `${d.s(5)} ${d.s(4)}`,
|
|
7004
|
+
"data-vizmatic-graph-edge-id": encodeURIComponent(relationship.id),
|
|
7005
|
+
"data-vizmatic-graph-edge-from": encodeURIComponent(relationship.from.entity),
|
|
7006
|
+
"data-vizmatic-graph-edge-to": encodeURIComponent(relationship.to.entity),
|
|
7007
|
+
"data-vizmatic-graph-edge-label": encodeURIComponent(relationship.label ?? ""),
|
|
7008
|
+
"data-vizmatic-graph-edge-title": encodeURIComponent(relationshipText(relationship))
|
|
7009
|
+
}),
|
|
7010
|
+
cardinalityGlyph(relationship.from.cardinality, points[0], points[1], lineColor, c.bg, lineScale, `from-${relationship.id}`),
|
|
7011
|
+
cardinalityGlyph(relationship.to.cardinality, points.at(-1), points.at(-2), lineColor, c.bg, lineScale, `to-${relationship.id}`)
|
|
7012
|
+
];
|
|
7013
|
+
});
|
|
7014
|
+
return React10.createElement(
|
|
7015
|
+
"div",
|
|
7016
|
+
{
|
|
7017
|
+
role: "img",
|
|
7018
|
+
"aria-label": svgTitle,
|
|
7019
|
+
"data-vizmatic-svg-id": id,
|
|
7020
|
+
"data-vizmatic-svg-title": svgTitle,
|
|
7021
|
+
"data-vizmatic-svg-description": [description, schemaSummary].filter(Boolean).join(" "),
|
|
7022
|
+
style: { display: "flex", position: "relative", flexShrink: 0, width: resolvedWidth, height: resolvedHeight }
|
|
7023
|
+
},
|
|
7024
|
+
visibleTitle && React10.createElement("div", { style: { position: "absolute", left: padding, top: padding, fontFamily: c.fontSans, fontSize: d.type.heading, fontWeight: 600, color: c.textPrimary } }, visibleTitle),
|
|
7025
|
+
React10.createElement("svg", { width: resolvedWidth, height: resolvedHeight, viewBox: `0 0 ${resolvedWidth} ${resolvedHeight}`, style: { position: "absolute", left: 0, top: 0 } }, ...paths),
|
|
7026
|
+
...labels,
|
|
7027
|
+
...entities.map((entity) => {
|
|
7028
|
+
const node = nodeById.get(entity.id), measure = measures.get(entity.id);
|
|
7029
|
+
const keyColor = getReadableToneColor(entity.tone ?? "blue", c, c.bgCard, c.bgCard);
|
|
7030
|
+
return React10.createElement(
|
|
7031
|
+
"div",
|
|
7032
|
+
{
|
|
7033
|
+
key: entity.id,
|
|
7034
|
+
"data-vizmatic-graph-node-id": entity.id,
|
|
7035
|
+
"data-vizmatic-graph-node-label": entity.label ?? entity.id,
|
|
7036
|
+
"data-vizmatic-graph-node-detail": entity.attributes.map(attributeDescription).join("; "),
|
|
7037
|
+
style: {
|
|
7038
|
+
position: "absolute",
|
|
7039
|
+
left: node.cx - node.width / 2,
|
|
7040
|
+
top: node.cy - node.height / 2,
|
|
7041
|
+
display: "flex",
|
|
7042
|
+
flexDirection: "column",
|
|
7043
|
+
width: node.width,
|
|
7044
|
+
height: node.height,
|
|
7045
|
+
border: `1px solid ${c.borderLight}`,
|
|
7046
|
+
borderRadius: d.r(4),
|
|
7047
|
+
backgroundColor: c.bgCard,
|
|
7048
|
+
overflow: "hidden"
|
|
7049
|
+
}
|
|
7050
|
+
},
|
|
7051
|
+
React10.createElement("div", { style: {
|
|
7052
|
+
display: "flex",
|
|
7053
|
+
alignItems: "center",
|
|
7054
|
+
height: headerHeight,
|
|
7055
|
+
flexShrink: 0,
|
|
7056
|
+
padding: `0 ${inset}px`,
|
|
7057
|
+
fontFamily: c.fontSans,
|
|
7058
|
+
fontSize: headerSize,
|
|
7059
|
+
fontWeight: 600,
|
|
7060
|
+
color: keyColor,
|
|
7061
|
+
backgroundColor: c.bgCardAlt,
|
|
7062
|
+
borderBottom: `1px solid ${c.borderLight}`
|
|
7063
|
+
} }, entity.label ?? entity.id),
|
|
7064
|
+
...entity.attributes.map((attribute, index) => React10.createElement(
|
|
7065
|
+
"div",
|
|
7066
|
+
{ key: attribute.name, style: {
|
|
7067
|
+
display: "flex",
|
|
7068
|
+
alignItems: "center",
|
|
7069
|
+
height: measure.rowHeights[index],
|
|
7070
|
+
flexShrink: 0,
|
|
7071
|
+
padding: `0 ${inset}px`,
|
|
7072
|
+
gap: inset,
|
|
7073
|
+
fontFamily: c.fontMono,
|
|
7074
|
+
fontSize: textSize,
|
|
7075
|
+
color: c.textPrimary
|
|
7076
|
+
} },
|
|
7077
|
+
React10.createElement("span", { style: { width: keyWidth - inset, flexShrink: 0, color: keyColor } }, [attribute.primaryKey && "PK", attribute.foreignKey && "FK", attribute.unique && "UQ"].filter(Boolean).join(" ")),
|
|
7078
|
+
React10.createElement("span", { style: { flexGrow: 1, whiteSpace: "nowrap" } }, attribute.name),
|
|
7079
|
+
React10.createElement("span", { style: { width: measure.typeWidth, flexShrink: 0, textAlign: "right", color: c.textSecondary } }, attribute.type + (attribute.nullable ? "?" : ""))
|
|
7080
|
+
)),
|
|
7081
|
+
!entity.attributes.length && React10.createElement("div", { style: { display: "flex", alignItems: "center", padding: `0 ${inset}px`, height: measure.rowHeights[0], fontSize: textSize, color: c.textSecondary, fontFamily: c.fontSans } }, "No attributes shown")
|
|
7082
|
+
);
|
|
7083
|
+
}),
|
|
7084
|
+
showLegend && React10.createElement(
|
|
7085
|
+
"div",
|
|
7086
|
+
{ style: { position: "absolute", left: padding, right: padding, bottom: padding, display: "flex", flexDirection: "column", gap: d.s(5), fontSize: textSize, lineHeight: 1.3, fontFamily: c.fontSans, color: c.textSecondary } },
|
|
7087
|
+
...legendLines.map((line) => React10.createElement("div", { key: line, style: { display: "flex", whiteSpace: "nowrap", flexShrink: 0 } }, line))
|
|
7088
|
+
)
|
|
7089
|
+
);
|
|
7090
|
+
}
|
|
7091
|
+
Object.defineProperty(EntityRelationshipDiagram, SVG_ACCESSIBILITY_COMPONENT, { value: true });
|
|
7092
|
+
|
|
6676
7093
|
// src/primitives/transformer.ts
|
|
6677
7094
|
var blockLabels = {
|
|
6678
7095
|
embedding: "Embedding",
|
|
@@ -6934,7 +7351,7 @@ function TransformerTopology({
|
|
|
6934
7351
|
Object.defineProperty(TransformerTopology, SVG_ACCESSIBILITY_COMPONENT, { value: true });
|
|
6935
7352
|
|
|
6936
7353
|
// src/primitives/data.ts
|
|
6937
|
-
import
|
|
7354
|
+
import React11 from "react";
|
|
6938
7355
|
function Matrix({
|
|
6939
7356
|
data,
|
|
6940
7357
|
c,
|
|
@@ -6954,7 +7371,8 @@ function Matrix({
|
|
|
6954
7371
|
highlightCol,
|
|
6955
7372
|
highlightCell,
|
|
6956
7373
|
highlightColor = c.info,
|
|
6957
|
-
colorDomain
|
|
7374
|
+
colorDomain,
|
|
7375
|
+
...accessibility
|
|
6958
7376
|
}) {
|
|
6959
7377
|
const cellSize = cellSizeProp ?? densityOf(c).f(38);
|
|
6960
7378
|
const fontSize = fontSizeProp ?? densityOf(c).type.small;
|
|
@@ -7006,9 +7424,19 @@ function Matrix({
|
|
|
7006
7424
|
if (colorValue2 < 0.67) return c.infoDark;
|
|
7007
7425
|
return c.positiveDark;
|
|
7008
7426
|
};
|
|
7009
|
-
|
|
7427
|
+
const cellDescriptions = data.flatMap((row, rowIndex) => row.map((value, columnIndex) => {
|
|
7428
|
+
const label = labels?.[rowIndex]?.[columnIndex];
|
|
7429
|
+
const text = typeof label === "string" || typeof label === "number" ? label : formatValue(value);
|
|
7430
|
+
return `${rowLabels?.[rowIndex] ?? `Row ${rowIndex + 1}`}, ${colLabels?.[columnIndex] ?? `column ${columnIndex + 1}`}: ${text}`;
|
|
7431
|
+
}));
|
|
7432
|
+
return React11.createElement(
|
|
7010
7433
|
"div",
|
|
7011
7434
|
{
|
|
7435
|
+
...chartAccessibilityAttributes({
|
|
7436
|
+
...accessibility,
|
|
7437
|
+
ariaLabel: accessibility.ariaLabel ?? title ?? "Matrix",
|
|
7438
|
+
description: chartDescription(accessibility.description, cellDescriptions)
|
|
7439
|
+
}),
|
|
7012
7440
|
style: {
|
|
7013
7441
|
display: "flex",
|
|
7014
7442
|
flexDirection: "column",
|
|
@@ -7016,10 +7444,10 @@ function Matrix({
|
|
|
7016
7444
|
gap: densityOf(c).s(8)
|
|
7017
7445
|
}
|
|
7018
7446
|
},
|
|
7019
|
-
title &&
|
|
7447
|
+
title && React11.createElement("div", {
|
|
7020
7448
|
style: { ...typeOf(c, "label"), color: c.textPrimary }
|
|
7021
7449
|
}, title),
|
|
7022
|
-
|
|
7450
|
+
React11.createElement(
|
|
7023
7451
|
"div",
|
|
7024
7452
|
{
|
|
7025
7453
|
style: {
|
|
@@ -7029,7 +7457,7 @@ function Matrix({
|
|
|
7029
7457
|
}
|
|
7030
7458
|
},
|
|
7031
7459
|
// Column labels
|
|
7032
|
-
colLabels &&
|
|
7460
|
+
colLabels && React11.createElement(
|
|
7033
7461
|
"div",
|
|
7034
7462
|
{
|
|
7035
7463
|
style: {
|
|
@@ -7039,7 +7467,7 @@ function Matrix({
|
|
|
7039
7467
|
}
|
|
7040
7468
|
},
|
|
7041
7469
|
...colLabels.map(
|
|
7042
|
-
(label, i) =>
|
|
7470
|
+
(label, i) => React11.createElement("div", {
|
|
7043
7471
|
key: `col-${i}`,
|
|
7044
7472
|
style: {
|
|
7045
7473
|
width: resolvedCellWidth,
|
|
@@ -7053,7 +7481,7 @@ function Matrix({
|
|
|
7053
7481
|
)
|
|
7054
7482
|
),
|
|
7055
7483
|
...data.map(
|
|
7056
|
-
(row, ri) =>
|
|
7484
|
+
(row, ri) => React11.createElement(
|
|
7057
7485
|
"div",
|
|
7058
7486
|
{
|
|
7059
7487
|
key: `row-${ri}`,
|
|
@@ -7063,7 +7491,7 @@ function Matrix({
|
|
|
7063
7491
|
alignItems: "center"
|
|
7064
7492
|
}
|
|
7065
7493
|
},
|
|
7066
|
-
rowLabels &&
|
|
7494
|
+
rowLabels && React11.createElement("div", {
|
|
7067
7495
|
style: {
|
|
7068
7496
|
width: resolvedRowLabelWidth,
|
|
7069
7497
|
textAlign: "right",
|
|
@@ -7079,7 +7507,7 @@ function Matrix({
|
|
|
7079
7507
|
const highlighted = ri === highlightRow || ci === highlightCol;
|
|
7080
7508
|
const backgroundColor = highlighted ? compositeColor(withColorAlpha(highlightColor, 0.24), baseBackgroundColor) : baseBackgroundColor;
|
|
7081
7509
|
const exactCell = ri === highlightCell?.row && ci === highlightCell?.col;
|
|
7082
|
-
return
|
|
7510
|
+
return React11.createElement("div", {
|
|
7083
7511
|
key: `cell-${ri}-${ci}`,
|
|
7084
7512
|
style: {
|
|
7085
7513
|
width: resolvedCellWidth,
|
|
@@ -7119,9 +7547,12 @@ function Heatmap({
|
|
|
7119
7547
|
highlightCol,
|
|
7120
7548
|
highlightCell,
|
|
7121
7549
|
highlightColor,
|
|
7122
|
-
colorDomain
|
|
7550
|
+
colorDomain,
|
|
7551
|
+
...accessibility
|
|
7123
7552
|
}) {
|
|
7124
7553
|
return Matrix({
|
|
7554
|
+
...accessibility,
|
|
7555
|
+
ariaLabel: accessibility.ariaLabel ?? title ?? "Heatmap",
|
|
7125
7556
|
data,
|
|
7126
7557
|
colLabels: xLabels,
|
|
7127
7558
|
rowLabels: yLabels,
|
|
@@ -7154,7 +7585,9 @@ function TiledMatrix({
|
|
|
7154
7585
|
gap: gapProp,
|
|
7155
7586
|
tone = "blue",
|
|
7156
7587
|
muted = false,
|
|
7157
|
-
crossedOut = false
|
|
7588
|
+
crossedOut = false,
|
|
7589
|
+
id,
|
|
7590
|
+
description
|
|
7158
7591
|
}) {
|
|
7159
7592
|
const gap = gapProp ?? densityOf(c).s(3);
|
|
7160
7593
|
const safeRows = Math.max(1, Math.floor(rows));
|
|
@@ -7162,7 +7595,7 @@ function TiledMatrix({
|
|
|
7162
7595
|
const baseAccent = getToneColor(tone, c);
|
|
7163
7596
|
const cellRows = Array.from(
|
|
7164
7597
|
{ length: safeRows },
|
|
7165
|
-
(_, row) =>
|
|
7598
|
+
(_, row) => React11.createElement(
|
|
7166
7599
|
"div",
|
|
7167
7600
|
{
|
|
7168
7601
|
key: `tiled-matrix-row-${row}`,
|
|
@@ -7177,7 +7610,7 @@ function TiledMatrix({
|
|
|
7177
7610
|
);
|
|
7178
7611
|
const region = regionIndex >= 0 ? regions[regionIndex] : void 0;
|
|
7179
7612
|
const accent = getToneColor(region?.tone ?? tone, c);
|
|
7180
|
-
return
|
|
7613
|
+
return React11.createElement("div", {
|
|
7181
7614
|
key: `tiled-matrix-cell-${row}-${col}`,
|
|
7182
7615
|
"data-region": regionIndex >= 0 ? regionIndex : void 0,
|
|
7183
7616
|
style: {
|
|
@@ -7193,7 +7626,7 @@ function TiledMatrix({
|
|
|
7193
7626
|
})
|
|
7194
7627
|
)
|
|
7195
7628
|
);
|
|
7196
|
-
const grid =
|
|
7629
|
+
const grid = React11.createElement(
|
|
7197
7630
|
"div",
|
|
7198
7631
|
{
|
|
7199
7632
|
"data-crossed-out": crossedOut ? "true" : void 0,
|
|
@@ -7212,7 +7645,7 @@ function TiledMatrix({
|
|
|
7212
7645
|
},
|
|
7213
7646
|
...cellRows,
|
|
7214
7647
|
...crossedOut ? [
|
|
7215
|
-
|
|
7648
|
+
React11.createElement("div", {
|
|
7216
7649
|
key: "cross-forward",
|
|
7217
7650
|
style: {
|
|
7218
7651
|
position: "absolute",
|
|
@@ -7227,7 +7660,7 @@ function TiledMatrix({
|
|
|
7227
7660
|
boxShadow: `0 0 0 1px ${c.bgCard}`
|
|
7228
7661
|
}
|
|
7229
7662
|
}),
|
|
7230
|
-
|
|
7663
|
+
React11.createElement("div", {
|
|
7231
7664
|
key: "cross-backward",
|
|
7232
7665
|
style: {
|
|
7233
7666
|
position: "absolute",
|
|
@@ -7244,11 +7677,17 @@ function TiledMatrix({
|
|
|
7244
7677
|
})
|
|
7245
7678
|
] : []
|
|
7246
7679
|
);
|
|
7247
|
-
return
|
|
7680
|
+
return React11.createElement(
|
|
7248
7681
|
"div",
|
|
7249
7682
|
{
|
|
7250
|
-
|
|
7251
|
-
|
|
7683
|
+
...chartAccessibilityAttributes({
|
|
7684
|
+
id,
|
|
7685
|
+
ariaLabel: ariaLabel ?? (typeof title === "string" ? title : "Tiled matrix"),
|
|
7686
|
+
description: chartDescription(description, [
|
|
7687
|
+
`${safeRows} rows by ${safeCols} columns`,
|
|
7688
|
+
...regions.map((region, index) => `Region ${index + 1}: rows ${region.rowStart + 1} to ${region.rowEnd + 1}, columns ${region.colStart + 1} to ${region.colEnd + 1}`)
|
|
7689
|
+
])
|
|
7690
|
+
}),
|
|
7252
7691
|
style: {
|
|
7253
7692
|
display: "flex",
|
|
7254
7693
|
flexDirection: "column",
|
|
@@ -7257,7 +7696,7 @@ function TiledMatrix({
|
|
|
7257
7696
|
}
|
|
7258
7697
|
},
|
|
7259
7698
|
...compactChildren([
|
|
7260
|
-
title &&
|
|
7699
|
+
title && React11.createElement("div", {
|
|
7261
7700
|
style: {
|
|
7262
7701
|
color: muted ? c.textMuted : getReadableToneColor(tone, c),
|
|
7263
7702
|
fontFamily: "Inter",
|
|
@@ -7267,7 +7706,7 @@ function TiledMatrix({
|
|
|
7267
7706
|
textAlign: "center"
|
|
7268
7707
|
}
|
|
7269
7708
|
}, title),
|
|
7270
|
-
subtitle &&
|
|
7709
|
+
subtitle && React11.createElement("div", {
|
|
7271
7710
|
style: {
|
|
7272
7711
|
color: c.textMuted,
|
|
7273
7712
|
fontFamily: "JetBrains Mono",
|
|
@@ -7313,7 +7752,7 @@ function DataTable({
|
|
|
7313
7752
|
};
|
|
7314
7753
|
const widths = Array.from({ length: columnCount }, (_, index) => columnWidth(index));
|
|
7315
7754
|
const alignmentOf = (colIndex) => align?.[colIndex] ?? (colIndex < headerCols ? "left" : "right");
|
|
7316
|
-
return
|
|
7755
|
+
return React11.createElement(
|
|
7317
7756
|
"div",
|
|
7318
7757
|
{
|
|
7319
7758
|
style: {
|
|
@@ -7322,7 +7761,7 @@ function DataTable({
|
|
|
7322
7761
|
...width != null ? { width } : {}
|
|
7323
7762
|
}
|
|
7324
7763
|
},
|
|
7325
|
-
...rows.map((row, rowIndex) =>
|
|
7764
|
+
...rows.map((row, rowIndex) => React11.createElement(
|
|
7326
7765
|
"div",
|
|
7327
7766
|
{
|
|
7328
7767
|
key: `${rowIndex}-${row.map(String).join("|")}`,
|
|
@@ -7338,7 +7777,7 @@ function DataTable({
|
|
|
7338
7777
|
const isHeaderRow = rowIndex < headerRows;
|
|
7339
7778
|
const isHeaderCol = colIndex < headerCols;
|
|
7340
7779
|
const alignment = alignmentOf(colIndex);
|
|
7341
|
-
return
|
|
7780
|
+
return React11.createElement("div", {
|
|
7342
7781
|
key: `${rowIndex}-${colIndex}-${String(cell)}`,
|
|
7343
7782
|
style: {
|
|
7344
7783
|
...width != null && colIndex === 0 ? { flex: 1 } : { width: widths[colIndex] },
|
|
@@ -7358,7 +7797,7 @@ function DataTable({
|
|
|
7358
7797
|
);
|
|
7359
7798
|
}
|
|
7360
7799
|
function isGridCell(cell) {
|
|
7361
|
-
return typeof cell === "object" && cell !== null && !
|
|
7800
|
+
return typeof cell === "object" && cell !== null && !React11.isValidElement(cell) && ("label" in cell || "tone" in cell || "color" in cell || "backgroundColor" in cell || "borderColor" in cell || "opacity" in cell);
|
|
7362
7801
|
}
|
|
7363
7802
|
function Grid({
|
|
7364
7803
|
rows,
|
|
@@ -7405,7 +7844,7 @@ function Grid({
|
|
|
7405
7844
|
...textFitStyle("center")
|
|
7406
7845
|
};
|
|
7407
7846
|
};
|
|
7408
|
-
return
|
|
7847
|
+
return React11.createElement(
|
|
7409
7848
|
"div",
|
|
7410
7849
|
{
|
|
7411
7850
|
style: {
|
|
@@ -7415,7 +7854,7 @@ function Grid({
|
|
|
7415
7854
|
alignItems: "center"
|
|
7416
7855
|
}
|
|
7417
7856
|
},
|
|
7418
|
-
...rows.map((row, rowIndex) =>
|
|
7857
|
+
...rows.map((row, rowIndex) => React11.createElement(
|
|
7419
7858
|
"div",
|
|
7420
7859
|
{
|
|
7421
7860
|
key: `grid-row-${rowIndex}`,
|
|
@@ -7424,7 +7863,7 @@ function Grid({
|
|
|
7424
7863
|
gap
|
|
7425
7864
|
}
|
|
7426
7865
|
},
|
|
7427
|
-
...row.map((cell, colIndex) =>
|
|
7866
|
+
...row.map((cell, colIndex) => React11.createElement("div", {
|
|
7428
7867
|
key: `grid-cell-${rowIndex}-${colIndex}`,
|
|
7429
7868
|
style: cellStyle(cell, rowIndex, colIndex)
|
|
7430
7869
|
}, renderCellLabel(cell)))
|
|
@@ -7453,7 +7892,8 @@ function AxisPlot({
|
|
|
7453
7892
|
paths = [],
|
|
7454
7893
|
xAxisLabel,
|
|
7455
7894
|
yAxisLabel,
|
|
7456
|
-
children
|
|
7895
|
+
children,
|
|
7896
|
+
...accessibility
|
|
7457
7897
|
}) {
|
|
7458
7898
|
const padding = paddingProp ?? densityOf(c).s(18);
|
|
7459
7899
|
const innerWidth = Math.max(1, width - padding * 2);
|
|
@@ -7485,7 +7925,7 @@ function AxisPlot({
|
|
|
7485
7925
|
const x = padding + innerWidth * index / (gridCount + 1);
|
|
7486
7926
|
const y = padding + innerHeight * index / (gridCount + 1);
|
|
7487
7927
|
return [
|
|
7488
|
-
|
|
7928
|
+
React11.createElement("line", {
|
|
7489
7929
|
key: `axis-grid-x-${index}`,
|
|
7490
7930
|
x1: x,
|
|
7491
7931
|
y1: padding,
|
|
@@ -7495,7 +7935,7 @@ function AxisPlot({
|
|
|
7495
7935
|
strokeWidth: 1,
|
|
7496
7936
|
opacity: 0.75
|
|
7497
7937
|
}),
|
|
7498
|
-
|
|
7938
|
+
React11.createElement("line", {
|
|
7499
7939
|
key: `axis-grid-y-${index}`,
|
|
7500
7940
|
x1: padding,
|
|
7501
7941
|
y1: y,
|
|
@@ -7510,7 +7950,7 @@ function AxisPlot({
|
|
|
7510
7950
|
}
|
|
7511
7951
|
if (showAxes) {
|
|
7512
7952
|
elements.push(
|
|
7513
|
-
|
|
7953
|
+
React11.createElement("line", {
|
|
7514
7954
|
key: "axis-x",
|
|
7515
7955
|
x1: padding,
|
|
7516
7956
|
y1: xAxisY,
|
|
@@ -7520,7 +7960,7 @@ function AxisPlot({
|
|
|
7520
7960
|
strokeWidth: 1.6,
|
|
7521
7961
|
opacity: 0.85
|
|
7522
7962
|
}),
|
|
7523
|
-
|
|
7963
|
+
React11.createElement("line", {
|
|
7524
7964
|
key: "axis-y",
|
|
7525
7965
|
x1: yAxisX,
|
|
7526
7966
|
y1: padding,
|
|
@@ -7543,7 +7983,7 @@ function AxisPlot({
|
|
|
7543
7983
|
commands.push(`L ${sx(point.x)} ${sy(point.y)}`);
|
|
7544
7984
|
}
|
|
7545
7985
|
}
|
|
7546
|
-
return [
|
|
7986
|
+
return [React11.createElement("path", {
|
|
7547
7987
|
key: `axis-path-${index}`,
|
|
7548
7988
|
d: commands.join(" "),
|
|
7549
7989
|
fill: "none",
|
|
@@ -7598,16 +8038,28 @@ function AxisPlot({
|
|
|
7598
8038
|
strokeWidth: point.strokeWidth,
|
|
7599
8039
|
opacity: point.opacity
|
|
7600
8040
|
})));
|
|
7601
|
-
elements.push(...
|
|
7602
|
-
const
|
|
8041
|
+
elements.push(...React11.Children.toArray(children).filter(React11.isValidElement));
|
|
8042
|
+
const accessible = chartAccessibilityAttributes({
|
|
8043
|
+
...accessibility,
|
|
8044
|
+
ariaLabel: accessibility.ariaLabel ?? "Axis plot",
|
|
8045
|
+
description: chartDescription(accessibility.description, [
|
|
8046
|
+
`${xAxisLabel ?? "x"} range ${xMin} to ${xMax}, ${yAxisLabel ?? "y"} range ${yMin} to ${yMax}`,
|
|
8047
|
+
...points.map((point, index) => `Point ${index + 1}: x ${point.x}, y ${point.y}`),
|
|
8048
|
+
...vectors.map((vector2, index) => `Vector ${index + 1}: (${vector2.x1}, ${vector2.y1}) to (${vector2.x2}, ${vector2.y2})`),
|
|
8049
|
+
...paths.map((path, index) => `Path ${index + 1}: ${path.points.map((point) => `(${point.x}, ${point.y})`).join(", ")}`)
|
|
8050
|
+
])
|
|
8051
|
+
});
|
|
8052
|
+
const svg = React11.createElement("svg", {
|
|
8053
|
+
...!xAxisLabel && !yAxisLabel ? accessible : {},
|
|
7603
8054
|
width,
|
|
7604
8055
|
height,
|
|
7605
8056
|
viewBox: `0 0 ${width} ${height}`
|
|
7606
8057
|
}, ...elements);
|
|
7607
8058
|
if (!xAxisLabel && !yAxisLabel) return svg;
|
|
7608
|
-
return
|
|
8059
|
+
return React11.createElement(
|
|
7609
8060
|
"div",
|
|
7610
8061
|
{
|
|
8062
|
+
...accessible,
|
|
7611
8063
|
style: {
|
|
7612
8064
|
position: "relative",
|
|
7613
8065
|
width,
|
|
@@ -7616,7 +8068,7 @@ function AxisPlot({
|
|
|
7616
8068
|
}
|
|
7617
8069
|
},
|
|
7618
8070
|
svg,
|
|
7619
|
-
xAxisLabel &&
|
|
8071
|
+
xAxisLabel && React11.createElement("div", {
|
|
7620
8072
|
key: "axis-x-label",
|
|
7621
8073
|
style: {
|
|
7622
8074
|
position: "absolute",
|
|
@@ -7631,7 +8083,7 @@ function AxisPlot({
|
|
|
7631
8083
|
fontWeight: 750
|
|
7632
8084
|
}
|
|
7633
8085
|
}, xAxisLabel),
|
|
7634
|
-
yAxisLabel &&
|
|
8086
|
+
yAxisLabel && React11.createElement("div", {
|
|
7635
8087
|
key: "axis-y-label",
|
|
7636
8088
|
style: {
|
|
7637
8089
|
position: "absolute",
|
|
@@ -7650,7 +8102,7 @@ function AxisPlot({
|
|
|
7650
8102
|
}
|
|
7651
8103
|
|
|
7652
8104
|
// src/primitives/charts.ts
|
|
7653
|
-
import
|
|
8105
|
+
import React12 from "react";
|
|
7654
8106
|
var chartPalette = ["primary", "warning", "positive", "violet", "info", "accent", "critical"];
|
|
7655
8107
|
function isColorName(value) {
|
|
7656
8108
|
return chartPalette.includes(value) || value === "neutral" || value === "secondary";
|
|
@@ -7754,7 +8206,7 @@ function chartLabel(key, text, x, y, c, options = {}) {
|
|
|
7754
8206
|
);
|
|
7755
8207
|
transform = void 0;
|
|
7756
8208
|
}
|
|
7757
|
-
return
|
|
8209
|
+
return React12.createElement("div", {
|
|
7758
8210
|
key,
|
|
7759
8211
|
style: {
|
|
7760
8212
|
position: "absolute",
|
|
@@ -7797,7 +8249,7 @@ function pointLabelPlacement(x, y, plot, index, width = 70) {
|
|
|
7797
8249
|
};
|
|
7798
8250
|
}
|
|
7799
8251
|
function ChartFrame(props) {
|
|
7800
|
-
return
|
|
8252
|
+
return React12.createElement(ChartFrameContent, props);
|
|
7801
8253
|
}
|
|
7802
8254
|
function ChartFrameContent({
|
|
7803
8255
|
children,
|
|
@@ -7809,13 +8261,21 @@ function ChartFrameContent({
|
|
|
7809
8261
|
width = "100%",
|
|
7810
8262
|
height,
|
|
7811
8263
|
padding: paddingProp,
|
|
7812
|
-
framed = false
|
|
8264
|
+
framed = false,
|
|
8265
|
+
id,
|
|
8266
|
+
ariaLabel,
|
|
8267
|
+
description
|
|
7813
8268
|
}) {
|
|
7814
8269
|
const d = densityOf(c);
|
|
7815
8270
|
const padding = paddingProp ?? (framed ? d.s(14) : 0);
|
|
7816
|
-
return
|
|
8271
|
+
return React12.createElement(
|
|
7817
8272
|
"div",
|
|
7818
8273
|
{
|
|
8274
|
+
...chartAccessibilityAttributes({
|
|
8275
|
+
id,
|
|
8276
|
+
ariaLabel: ariaLabel ?? title ?? "Chart",
|
|
8277
|
+
description: [subtitle, description].filter(Boolean).join(" ")
|
|
8278
|
+
}),
|
|
7819
8279
|
style: {
|
|
7820
8280
|
width,
|
|
7821
8281
|
...height ? { height } : {},
|
|
@@ -7827,20 +8287,20 @@ function ChartFrameContent({
|
|
|
7827
8287
|
...framed ? { borderRadius: d.r(8), border: `1px solid ${c.borderSubtle}`, backgroundColor: c.bgCard } : {}
|
|
7828
8288
|
}
|
|
7829
8289
|
},
|
|
7830
|
-
(title || subtitle) &&
|
|
8290
|
+
(title || subtitle) && React12.createElement(
|
|
7831
8291
|
"div",
|
|
7832
8292
|
{
|
|
7833
8293
|
style: { display: "flex", flexDirection: "column", gap: d.s(2), minWidth: 0, maxWidth: "100%" }
|
|
7834
8294
|
},
|
|
7835
|
-
title &&
|
|
8295
|
+
title && React12.createElement("div", {
|
|
7836
8296
|
style: { ...typeOf(c, "label"), ...textFitStyle(), color: c.textPrimary, fontWeight: 600 }
|
|
7837
8297
|
}, title),
|
|
7838
|
-
subtitle &&
|
|
8298
|
+
subtitle && React12.createElement("div", {
|
|
7839
8299
|
style: { ...typeOf(c, "tiny"), ...textFitStyle(), color: c.textSecondary, lineHeight: 1.35 }
|
|
7840
8300
|
}, subtitle)
|
|
7841
8301
|
),
|
|
7842
8302
|
children,
|
|
7843
|
-
(legend || footer) &&
|
|
8303
|
+
(legend || footer) && React12.createElement(
|
|
7844
8304
|
"div",
|
|
7845
8305
|
{
|
|
7846
8306
|
style: {
|
|
@@ -7850,18 +8310,18 @@ function ChartFrameContent({
|
|
|
7850
8310
|
gap: d.s(12)
|
|
7851
8311
|
}
|
|
7852
8312
|
},
|
|
7853
|
-
legend &&
|
|
8313
|
+
legend && React12.createElement(
|
|
7854
8314
|
"div",
|
|
7855
8315
|
{
|
|
7856
8316
|
style: { display: "flex", alignItems: "center", gap: d.s(12), flexWrap: "wrap", minWidth: 0 }
|
|
7857
8317
|
},
|
|
7858
|
-
...legend.map((item, index) =>
|
|
8318
|
+
...legend.map((item, index) => React12.createElement(
|
|
7859
8319
|
"div",
|
|
7860
8320
|
{
|
|
7861
8321
|
key: `${item.label}-${index}`,
|
|
7862
8322
|
style: { display: "flex", alignItems: "center", gap: d.s(6), minWidth: 0 }
|
|
7863
8323
|
},
|
|
7864
|
-
|
|
8324
|
+
React12.createElement("span", {
|
|
7865
8325
|
style: {
|
|
7866
8326
|
width: d.f(12),
|
|
7867
8327
|
height: Math.max(2, d.w(2)),
|
|
@@ -7869,12 +8329,12 @@ function ChartFrameContent({
|
|
|
7869
8329
|
display: "flex"
|
|
7870
8330
|
}
|
|
7871
8331
|
}),
|
|
7872
|
-
|
|
8332
|
+
React12.createElement("span", {
|
|
7873
8333
|
style: { ...typeOf(c, "tiny"), ...textFitStyle(), color: c.textSecondary }
|
|
7874
8334
|
}, item.label)
|
|
7875
8335
|
))
|
|
7876
8336
|
),
|
|
7877
|
-
footer &&
|
|
8337
|
+
footer && React12.createElement("div", {
|
|
7878
8338
|
style: { ...typeOf(c, "tiny"), ...textFitStyle("right"), color: c.textMuted }
|
|
7879
8339
|
}, footer)
|
|
7880
8340
|
)
|
|
@@ -7944,7 +8404,8 @@ function PieChart({
|
|
|
7944
8404
|
size,
|
|
7945
8405
|
format = "decimal",
|
|
7946
8406
|
showLegend = true,
|
|
7947
|
-
footer
|
|
8407
|
+
footer,
|
|
8408
|
+
...accessibility
|
|
7948
8409
|
}) {
|
|
7949
8410
|
const total = validateNonNegativeSegments(segments, "PieChart");
|
|
7950
8411
|
const positiveSegments = segments.filter((segment) => segment.value > 0);
|
|
@@ -7958,7 +8419,7 @@ function PieChart({
|
|
|
7958
8419
|
const start = cursor;
|
|
7959
8420
|
const end = index === positiveSegments.length - 1 ? 270 : cursor + span;
|
|
7960
8421
|
cursor += span;
|
|
7961
|
-
return
|
|
8422
|
+
return React12.createElement("path", {
|
|
7962
8423
|
key: `pie-segment-${segment.label}-${index}`,
|
|
7963
8424
|
d: pieSectorPath(cx, cy, radius, start, end),
|
|
7964
8425
|
fill: chartColor(segment.color, c, index),
|
|
@@ -7969,7 +8430,7 @@ function PieChart({
|
|
|
7969
8430
|
"data-pie-share": total > 0 ? segment.value / total : 0
|
|
7970
8431
|
});
|
|
7971
8432
|
});
|
|
7972
|
-
const legend = showLegend && positiveSegments.length > 0 &&
|
|
8433
|
+
const legend = showLegend && positiveSegments.length > 0 && React12.createElement("div", {
|
|
7973
8434
|
style: {
|
|
7974
8435
|
display: "flex",
|
|
7975
8436
|
flexDirection: "column",
|
|
@@ -7981,13 +8442,13 @@ function PieChart({
|
|
|
7981
8442
|
const formattedValue = formatChartValue(segment.value, format);
|
|
7982
8443
|
const share = formatChartValue(segment.value / total, "percent");
|
|
7983
8444
|
const label = segment.valueLabel ?? (format === "percent" ? formattedValue : `${formattedValue} \xB7 ${share}`);
|
|
7984
|
-
return
|
|
8445
|
+
return React12.createElement(
|
|
7985
8446
|
"div",
|
|
7986
8447
|
{
|
|
7987
8448
|
key: `pie-legend-${segment.label}-${index}`,
|
|
7988
8449
|
style: { display: "flex", alignItems: "center", gap: 8, minWidth: 0 }
|
|
7989
8450
|
},
|
|
7990
|
-
|
|
8451
|
+
React12.createElement("span", {
|
|
7991
8452
|
style: {
|
|
7992
8453
|
display: "flex",
|
|
7993
8454
|
width: 10,
|
|
@@ -7997,10 +8458,10 @@ function PieChart({
|
|
|
7997
8458
|
flexShrink: 0
|
|
7998
8459
|
}
|
|
7999
8460
|
}),
|
|
8000
|
-
|
|
8461
|
+
React12.createElement("span", {
|
|
8001
8462
|
style: { ...typeOf(c, "tiny"), ...textFitStyle(), color: c.textSecondary, flex: 1 }
|
|
8002
8463
|
}, segment.label),
|
|
8003
|
-
|
|
8464
|
+
React12.createElement("span", {
|
|
8004
8465
|
style: {
|
|
8005
8466
|
...typeOf(c, "tiny"),
|
|
8006
8467
|
color: c.textPrimary,
|
|
@@ -8012,12 +8473,15 @@ function PieChart({
|
|
|
8012
8473
|
);
|
|
8013
8474
|
}));
|
|
8014
8475
|
return ChartFrame({
|
|
8476
|
+
...accessibility,
|
|
8477
|
+
ariaLabel: accessibility.ariaLabel ?? title ?? "Pie chart",
|
|
8478
|
+
description: chartDescription(accessibility.description, valueDescriptions(segments, format)),
|
|
8015
8479
|
c,
|
|
8016
8480
|
title,
|
|
8017
8481
|
subtitle,
|
|
8018
8482
|
footer,
|
|
8019
8483
|
width,
|
|
8020
|
-
children:
|
|
8484
|
+
children: React12.createElement(
|
|
8021
8485
|
"div",
|
|
8022
8486
|
{
|
|
8023
8487
|
style: {
|
|
@@ -8029,7 +8493,7 @@ function PieChart({
|
|
|
8029
8493
|
width: "100%"
|
|
8030
8494
|
}
|
|
8031
8495
|
},
|
|
8032
|
-
|
|
8496
|
+
React12.createElement(
|
|
8033
8497
|
"svg",
|
|
8034
8498
|
{
|
|
8035
8499
|
width: resolvedSize,
|
|
@@ -8038,7 +8502,7 @@ function PieChart({
|
|
|
8038
8502
|
role: "img",
|
|
8039
8503
|
"aria-label": title ?? "Pie chart"
|
|
8040
8504
|
},
|
|
8041
|
-
positiveSegments.length === 0 ?
|
|
8505
|
+
positiveSegments.length === 0 ? React12.createElement("circle", {
|
|
8042
8506
|
cx,
|
|
8043
8507
|
cy,
|
|
8044
8508
|
r: radius,
|
|
@@ -8064,7 +8528,8 @@ function DonutChart({
|
|
|
8064
8528
|
centerLabel,
|
|
8065
8529
|
centerValue,
|
|
8066
8530
|
showLegend = true,
|
|
8067
|
-
footer
|
|
8531
|
+
footer,
|
|
8532
|
+
...accessibility
|
|
8068
8533
|
}) {
|
|
8069
8534
|
const positiveSegments = segments.filter((segment) => segment.value > 0);
|
|
8070
8535
|
const total = positiveSegments.reduce((sum, segment) => sum + segment.value, 0);
|
|
@@ -8083,13 +8548,13 @@ function DonutChart({
|
|
|
8083
8548
|
const end = cursor + rawSpan - gap / 2;
|
|
8084
8549
|
cursor += rawSpan;
|
|
8085
8550
|
if (end <= start) return null;
|
|
8086
|
-
return
|
|
8551
|
+
return React12.createElement("path", {
|
|
8087
8552
|
key: `donut-segment-${segment.label}-${index}`,
|
|
8088
8553
|
d: donutArcPath(cx, cy, outerRadius, innerRadius, start, end),
|
|
8089
8554
|
fill: chartColor(segment.color, c, index)
|
|
8090
8555
|
});
|
|
8091
8556
|
}).filter(Boolean);
|
|
8092
|
-
const legend = showLegend && positiveSegments.length > 0 &&
|
|
8557
|
+
const legend = showLegend && positiveSegments.length > 0 && React12.createElement("div", {
|
|
8093
8558
|
style: {
|
|
8094
8559
|
display: "flex",
|
|
8095
8560
|
flexDirection: "column",
|
|
@@ -8097,7 +8562,7 @@ function DonutChart({
|
|
|
8097
8562
|
flex: 1,
|
|
8098
8563
|
minWidth: 112
|
|
8099
8564
|
}
|
|
8100
|
-
}, ...positiveSegments.map((segment, index) =>
|
|
8565
|
+
}, ...positiveSegments.map((segment, index) => React12.createElement(
|
|
8101
8566
|
"div",
|
|
8102
8567
|
{
|
|
8103
8568
|
key: `donut-legend-${segment.label}-${index}`,
|
|
@@ -8108,7 +8573,7 @@ function DonutChart({
|
|
|
8108
8573
|
minWidth: 0
|
|
8109
8574
|
}
|
|
8110
8575
|
},
|
|
8111
|
-
|
|
8576
|
+
React12.createElement("span", {
|
|
8112
8577
|
style: {
|
|
8113
8578
|
display: "flex",
|
|
8114
8579
|
width: 10,
|
|
@@ -8118,7 +8583,7 @@ function DonutChart({
|
|
|
8118
8583
|
flexShrink: 0
|
|
8119
8584
|
}
|
|
8120
8585
|
}),
|
|
8121
|
-
|
|
8586
|
+
React12.createElement("span", {
|
|
8122
8587
|
style: {
|
|
8123
8588
|
...typeOf(c, "tiny"),
|
|
8124
8589
|
...textFitStyle(),
|
|
@@ -8126,7 +8591,7 @@ function DonutChart({
|
|
|
8126
8591
|
flex: 1
|
|
8127
8592
|
}
|
|
8128
8593
|
}, segment.label),
|
|
8129
|
-
|
|
8594
|
+
React12.createElement("span", {
|
|
8130
8595
|
style: {
|
|
8131
8596
|
...typeOf(c, "tiny"),
|
|
8132
8597
|
color: c.textPrimary,
|
|
@@ -8137,6 +8602,9 @@ function DonutChart({
|
|
|
8137
8602
|
}, segment.valueLabel ?? formatChartValue(segment.value, format))
|
|
8138
8603
|
)));
|
|
8139
8604
|
return ChartFrame({
|
|
8605
|
+
...accessibility,
|
|
8606
|
+
ariaLabel: accessibility.ariaLabel ?? title ?? "Donut chart",
|
|
8607
|
+
description: chartDescription(accessibility.description, valueDescriptions(positiveSegments, format)),
|
|
8140
8608
|
c,
|
|
8141
8609
|
title,
|
|
8142
8610
|
subtitle,
|
|
@@ -8144,7 +8612,7 @@ function DonutChart({
|
|
|
8144
8612
|
width,
|
|
8145
8613
|
height,
|
|
8146
8614
|
padding: densityOf(c).s(16),
|
|
8147
|
-
children:
|
|
8615
|
+
children: React12.createElement(
|
|
8148
8616
|
"div",
|
|
8149
8617
|
{
|
|
8150
8618
|
style: {
|
|
@@ -8156,7 +8624,7 @@ function DonutChart({
|
|
|
8156
8624
|
width: "100%"
|
|
8157
8625
|
}
|
|
8158
8626
|
},
|
|
8159
|
-
|
|
8627
|
+
React12.createElement(
|
|
8160
8628
|
"div",
|
|
8161
8629
|
{
|
|
8162
8630
|
style: {
|
|
@@ -8167,14 +8635,14 @@ function DonutChart({
|
|
|
8167
8635
|
flexShrink: 0
|
|
8168
8636
|
}
|
|
8169
8637
|
},
|
|
8170
|
-
|
|
8638
|
+
React12.createElement(
|
|
8171
8639
|
"svg",
|
|
8172
8640
|
{
|
|
8173
8641
|
width: resolvedSize,
|
|
8174
8642
|
height: resolvedSize,
|
|
8175
8643
|
viewBox: `0 0 ${resolvedSize} ${resolvedSize}`
|
|
8176
8644
|
},
|
|
8177
|
-
positiveSegments.length === 0 ?
|
|
8645
|
+
positiveSegments.length === 0 ? React12.createElement("circle", {
|
|
8178
8646
|
cx,
|
|
8179
8647
|
cy,
|
|
8180
8648
|
r: (outerRadius + innerRadius) / 2,
|
|
@@ -8183,7 +8651,7 @@ function DonutChart({
|
|
|
8183
8651
|
strokeWidth: resolvedThickness
|
|
8184
8652
|
}) : paths
|
|
8185
8653
|
),
|
|
8186
|
-
(centerLabel != null || resolvedCenterValue != null) &&
|
|
8654
|
+
(centerLabel != null || resolvedCenterValue != null) && React12.createElement(
|
|
8187
8655
|
"div",
|
|
8188
8656
|
{
|
|
8189
8657
|
style: {
|
|
@@ -8202,7 +8670,7 @@ function DonutChart({
|
|
|
8202
8670
|
textAlign: "center"
|
|
8203
8671
|
}
|
|
8204
8672
|
},
|
|
8205
|
-
resolvedCenterValue != null &&
|
|
8673
|
+
resolvedCenterValue != null && React12.createElement("div", {
|
|
8206
8674
|
style: {
|
|
8207
8675
|
...typeOf(c, "small"),
|
|
8208
8676
|
color: c.textPrimary,
|
|
@@ -8213,7 +8681,7 @@ function DonutChart({
|
|
|
8213
8681
|
...textFitStyle("center")
|
|
8214
8682
|
}
|
|
8215
8683
|
}, resolvedCenterValue),
|
|
8216
|
-
centerLabel != null &&
|
|
8684
|
+
centerLabel != null && React12.createElement("div", {
|
|
8217
8685
|
style: {
|
|
8218
8686
|
...typeOf(c, "tiny"),
|
|
8219
8687
|
color: c.textMuted,
|
|
@@ -8227,6 +8695,9 @@ function DonutChart({
|
|
|
8227
8695
|
)
|
|
8228
8696
|
});
|
|
8229
8697
|
}
|
|
8698
|
+
function valueDescriptions(data, format = "decimal") {
|
|
8699
|
+
return data.map((item) => `${item.label}: ${item.valueLabel ?? formatChartValue(item.value, format)}`);
|
|
8700
|
+
}
|
|
8230
8701
|
function StackedBar({
|
|
8231
8702
|
segments,
|
|
8232
8703
|
c,
|
|
@@ -8234,13 +8705,22 @@ function StackedBar({
|
|
|
8234
8705
|
height = 68,
|
|
8235
8706
|
title,
|
|
8236
8707
|
subtitle,
|
|
8237
|
-
showLegend = true
|
|
8708
|
+
showLegend = true,
|
|
8709
|
+
...accessibility
|
|
8238
8710
|
}) {
|
|
8239
8711
|
const positiveSegments = segments.filter((segment) => segment.value > 0);
|
|
8240
8712
|
const total = positiveSegments.reduce((sum, segment) => sum + segment.value, 0);
|
|
8241
|
-
return
|
|
8713
|
+
return React12.createElement(
|
|
8242
8714
|
"div",
|
|
8243
8715
|
{
|
|
8716
|
+
...chartAccessibilityAttributes({
|
|
8717
|
+
...accessibility,
|
|
8718
|
+
ariaLabel: accessibility.ariaLabel ?? title ?? "Stacked bar",
|
|
8719
|
+
description: chartDescription(
|
|
8720
|
+
[subtitle, accessibility.description].filter(Boolean).join(" "),
|
|
8721
|
+
valueDescriptions(positiveSegments)
|
|
8722
|
+
)
|
|
8723
|
+
}),
|
|
8244
8724
|
style: {
|
|
8245
8725
|
width,
|
|
8246
8726
|
display: "flex",
|
|
@@ -8248,7 +8728,7 @@ function StackedBar({
|
|
|
8248
8728
|
gap: densityOf(c).s(10)
|
|
8249
8729
|
}
|
|
8250
8730
|
},
|
|
8251
|
-
(title || subtitle) &&
|
|
8731
|
+
(title || subtitle) && React12.createElement(
|
|
8252
8732
|
"div",
|
|
8253
8733
|
{
|
|
8254
8734
|
style: {
|
|
@@ -8257,14 +8737,14 @@ function StackedBar({
|
|
|
8257
8737
|
gap: densityOf(c).s(3)
|
|
8258
8738
|
}
|
|
8259
8739
|
},
|
|
8260
|
-
title &&
|
|
8740
|
+
title && React12.createElement("div", {
|
|
8261
8741
|
style: { ...typeOf(c, "label"), color: c.textPrimary, fontWeight: 600 }
|
|
8262
8742
|
}, title),
|
|
8263
|
-
subtitle &&
|
|
8743
|
+
subtitle && React12.createElement("div", {
|
|
8264
8744
|
style: { ...typeOf(c, "tiny"), color: c.textSecondary }
|
|
8265
8745
|
}, subtitle)
|
|
8266
8746
|
),
|
|
8267
|
-
|
|
8747
|
+
React12.createElement(
|
|
8268
8748
|
"div",
|
|
8269
8749
|
{
|
|
8270
8750
|
style: {
|
|
@@ -8282,7 +8762,7 @@ function StackedBar({
|
|
|
8282
8762
|
const share = total > 0 ? segment.value / total : 0;
|
|
8283
8763
|
const segmentWidth = width * share;
|
|
8284
8764
|
const color = chartColor(segment.color, c, index);
|
|
8285
|
-
return
|
|
8765
|
+
return React12.createElement(
|
|
8286
8766
|
"div",
|
|
8287
8767
|
{
|
|
8288
8768
|
key: `${segment.label}-${index}`,
|
|
@@ -8296,7 +8776,7 @@ function StackedBar({
|
|
|
8296
8776
|
...index < positiveSegments.length - 1 ? { borderRight: `2px solid ${c.bgSubtle}` } : {}
|
|
8297
8777
|
}
|
|
8298
8778
|
},
|
|
8299
|
-
segmentWidth >= 64 &&
|
|
8779
|
+
segmentWidth >= 64 && React12.createElement("span", {
|
|
8300
8780
|
style: {
|
|
8301
8781
|
...typeOf(c, "small"),
|
|
8302
8782
|
color: getReadableTextColor(color, c),
|
|
@@ -8307,7 +8787,7 @@ function StackedBar({
|
|
|
8307
8787
|
);
|
|
8308
8788
|
})
|
|
8309
8789
|
),
|
|
8310
|
-
showLegend &&
|
|
8790
|
+
showLegend && React12.createElement(
|
|
8311
8791
|
"div",
|
|
8312
8792
|
{
|
|
8313
8793
|
style: {
|
|
@@ -8319,13 +8799,13 @@ function StackedBar({
|
|
|
8319
8799
|
},
|
|
8320
8800
|
...positiveSegments.map((segment, index) => {
|
|
8321
8801
|
const share = total > 0 ? segment.value / total : 0;
|
|
8322
|
-
return
|
|
8802
|
+
return React12.createElement(
|
|
8323
8803
|
"div",
|
|
8324
8804
|
{
|
|
8325
8805
|
key: `legend-${segment.label}-${index}`,
|
|
8326
8806
|
style: { display: "flex", alignItems: "center", gap: 7 }
|
|
8327
8807
|
},
|
|
8328
|
-
|
|
8808
|
+
React12.createElement("span", {
|
|
8329
8809
|
style: {
|
|
8330
8810
|
width: 12,
|
|
8331
8811
|
height: 12,
|
|
@@ -8334,7 +8814,7 @@ function StackedBar({
|
|
|
8334
8814
|
backgroundColor: chartColor(segment.color, c, index)
|
|
8335
8815
|
}
|
|
8336
8816
|
}),
|
|
8337
|
-
|
|
8817
|
+
React12.createElement("span", {
|
|
8338
8818
|
style: { ...typeOf(c, "tiny"), color: c.textSecondary }
|
|
8339
8819
|
}, `${segment.label} ${segment.valueLabel ?? formatChartValue(share, "percent")}`)
|
|
8340
8820
|
);
|
|
@@ -8355,7 +8835,8 @@ function BarChart({
|
|
|
8355
8835
|
showGrid = true,
|
|
8356
8836
|
showValues = true,
|
|
8357
8837
|
yAxisLabel,
|
|
8358
|
-
footer
|
|
8838
|
+
footer,
|
|
8839
|
+
...accessibility
|
|
8359
8840
|
}) {
|
|
8360
8841
|
const d = densityOf(c);
|
|
8361
8842
|
const margin = { top: d.f(16), right: d.g(8), bottom: d.f(26), left: d.f(yAxisLabel ? 62 : 34) };
|
|
@@ -8375,23 +8856,26 @@ function BarChart({
|
|
|
8375
8856
|
return { item, index, x, y, barHeight, valueY, color: chartColor(item.color, c, 0) };
|
|
8376
8857
|
});
|
|
8377
8858
|
return ChartFrame({
|
|
8859
|
+
...accessibility,
|
|
8860
|
+
ariaLabel: accessibility.ariaLabel ?? title ?? "Bar chart",
|
|
8861
|
+
description: chartDescription(accessibility.description, valueDescriptions(data, format)),
|
|
8378
8862
|
c,
|
|
8379
8863
|
title,
|
|
8380
8864
|
subtitle,
|
|
8381
8865
|
width,
|
|
8382
8866
|
footer,
|
|
8383
|
-
children:
|
|
8867
|
+
children: React12.createElement(
|
|
8384
8868
|
"div",
|
|
8385
8869
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
8386
|
-
|
|
8870
|
+
React12.createElement(
|
|
8387
8871
|
"svg",
|
|
8388
8872
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
8389
|
-
showGrid &&
|
|
8873
|
+
showGrid && React12.createElement(
|
|
8390
8874
|
"g",
|
|
8391
8875
|
{},
|
|
8392
8876
|
...ticks.map((tick) => {
|
|
8393
8877
|
const y = yInPlot(tick, domain, plot);
|
|
8394
|
-
return
|
|
8878
|
+
return React12.createElement("line", {
|
|
8395
8879
|
key: `tick-${tick}`,
|
|
8396
8880
|
x1: plot.x,
|
|
8397
8881
|
y1: y,
|
|
@@ -8402,9 +8886,9 @@ function BarChart({
|
|
|
8402
8886
|
});
|
|
8403
8887
|
})
|
|
8404
8888
|
),
|
|
8405
|
-
|
|
8889
|
+
React12.createElement("line", { x1: plot.x, y1: baselineY, x2: plot.right, y2: baselineY, stroke: c.borderLight, strokeWidth: d.stroke.hair }),
|
|
8406
8890
|
...barGeometries.map(
|
|
8407
|
-
({ item, index, x, y, barHeight, color }) =>
|
|
8891
|
+
({ item, index, x, y, barHeight, color }) => React12.createElement("rect", {
|
|
8408
8892
|
key: `${item.label}-${index}`,
|
|
8409
8893
|
x,
|
|
8410
8894
|
y,
|
|
@@ -8447,7 +8931,8 @@ function ParetoBarChart({
|
|
|
8447
8931
|
format = "integer",
|
|
8448
8932
|
showGrid = true,
|
|
8449
8933
|
showValues = true,
|
|
8450
|
-
footer
|
|
8934
|
+
footer,
|
|
8935
|
+
...accessibility
|
|
8451
8936
|
}) {
|
|
8452
8937
|
let total = 0;
|
|
8453
8938
|
for (const item of data) {
|
|
@@ -8492,17 +8977,22 @@ function ParetoBarChart({
|
|
|
8492
8977
|
});
|
|
8493
8978
|
const cumulativePath = bars.map(({ centerX, cumulativeY }, index) => `${index === 0 ? "M" : "L"} ${centerX.toFixed(1)} ${cumulativeY.toFixed(1)}`).join(" ");
|
|
8494
8979
|
return ChartFrame({
|
|
8980
|
+
...accessibility,
|
|
8981
|
+
ariaLabel: accessibility.ariaLabel ?? title ?? "Pareto bar chart",
|
|
8982
|
+
description: chartDescription(accessibility.description, bars.map(
|
|
8983
|
+
({ item, cumulative }) => `${item.label}: ${item.valueLabel ?? formatChartValue(item.value, format)}, cumulative ${formatChartValue(cumulative, "percent")}`
|
|
8984
|
+
)),
|
|
8495
8985
|
c,
|
|
8496
8986
|
title,
|
|
8497
8987
|
subtitle,
|
|
8498
8988
|
width,
|
|
8499
8989
|
footer,
|
|
8500
|
-
children:
|
|
8990
|
+
children: React12.createElement(
|
|
8501
8991
|
"div",
|
|
8502
8992
|
{
|
|
8503
8993
|
style: { position: "relative", width, height, display: "flex" }
|
|
8504
8994
|
},
|
|
8505
|
-
|
|
8995
|
+
React12.createElement(
|
|
8506
8996
|
"svg",
|
|
8507
8997
|
{
|
|
8508
8998
|
width,
|
|
@@ -8511,12 +9001,12 @@ function ParetoBarChart({
|
|
|
8511
9001
|
role: "img",
|
|
8512
9002
|
"aria-label": title ?? "Pareto bar chart"
|
|
8513
9003
|
},
|
|
8514
|
-
showGrid &&
|
|
9004
|
+
showGrid && React12.createElement(
|
|
8515
9005
|
"g",
|
|
8516
9006
|
{},
|
|
8517
9007
|
...countTicks.map((tick) => {
|
|
8518
9008
|
const y = yInPlot(tick, valueDomain, plot);
|
|
8519
|
-
return
|
|
9009
|
+
return React12.createElement("line", {
|
|
8520
9010
|
key: `pareto-count-grid-${tick}`,
|
|
8521
9011
|
x1: plot.x,
|
|
8522
9012
|
y1: y,
|
|
@@ -8527,7 +9017,7 @@ function ParetoBarChart({
|
|
|
8527
9017
|
});
|
|
8528
9018
|
})
|
|
8529
9019
|
),
|
|
8530
|
-
|
|
9020
|
+
React12.createElement("line", {
|
|
8531
9021
|
x1: plot.x,
|
|
8532
9022
|
y1: plot.bottom,
|
|
8533
9023
|
x2: plot.right,
|
|
@@ -8535,7 +9025,7 @@ function ParetoBarChart({
|
|
|
8535
9025
|
stroke: c.borderLight,
|
|
8536
9026
|
strokeWidth: d.stroke.hair
|
|
8537
9027
|
}),
|
|
8538
|
-
...bars.map(({ item, order, x, y, height: barHeight, color }) =>
|
|
9028
|
+
...bars.map(({ item, order, x, y, height: barHeight, color }) => React12.createElement("rect", {
|
|
8539
9029
|
key: `pareto-bar-${item.label}-${order}`,
|
|
8540
9030
|
x,
|
|
8541
9031
|
y,
|
|
@@ -8547,7 +9037,7 @@ function ParetoBarChart({
|
|
|
8547
9037
|
"data-pareto-value": item.value,
|
|
8548
9038
|
"data-pareto-order": order
|
|
8549
9039
|
})),
|
|
8550
|
-
cumulativePath &&
|
|
9040
|
+
cumulativePath && React12.createElement("path", {
|
|
8551
9041
|
d: cumulativePath,
|
|
8552
9042
|
fill: "none",
|
|
8553
9043
|
stroke: chartColor("critical", c),
|
|
@@ -8556,7 +9046,7 @@ function ParetoBarChart({
|
|
|
8556
9046
|
strokeLinejoin: "round",
|
|
8557
9047
|
"data-pareto-cumulative-line": true
|
|
8558
9048
|
}),
|
|
8559
|
-
...bars.map(({ item, sourceIndex, centerX, cumulativeY, cumulative, order }) =>
|
|
9049
|
+
...bars.map(({ item, sourceIndex, centerX, cumulativeY, cumulative, order }) => React12.createElement("circle", {
|
|
8560
9050
|
key: `pareto-cumulative-point-${order}`,
|
|
8561
9051
|
cx: centerX,
|
|
8562
9052
|
cy: cumulativeY,
|
|
@@ -8622,7 +9112,8 @@ function LineChart({
|
|
|
8622
9112
|
showPoints = true,
|
|
8623
9113
|
directLabels,
|
|
8624
9114
|
yAxisLabel,
|
|
8625
|
-
footer
|
|
9115
|
+
footer,
|
|
9116
|
+
...accessibility
|
|
8626
9117
|
}) {
|
|
8627
9118
|
const d = densityOf(c);
|
|
8628
9119
|
const direct = directLabels ?? series.length > 1;
|
|
@@ -8647,24 +9138,29 @@ function LineChart({
|
|
|
8647
9138
|
return `${index === 0 ? "M" : "L"} ${point.x.toFixed(1)} ${point.y.toFixed(1)}`;
|
|
8648
9139
|
}).join(" ");
|
|
8649
9140
|
return ChartFrame({
|
|
9141
|
+
...accessibility,
|
|
9142
|
+
ariaLabel: accessibility.ariaLabel ?? title ?? "Line chart",
|
|
9143
|
+
description: chartDescription(accessibility.description, series.map(
|
|
9144
|
+
(item) => `${item.name}: ${item.points.map((value, index) => `${labels?.[index] ?? `Point ${index + 1}`}: ${formatChartValue(value, format)}`).join(", ")}`
|
|
9145
|
+
)),
|
|
8650
9146
|
c,
|
|
8651
9147
|
title,
|
|
8652
9148
|
subtitle,
|
|
8653
9149
|
width,
|
|
8654
9150
|
footer,
|
|
8655
9151
|
...direct ? {} : { legend: series.length > 1 ? series.map((item, index) => ({ label: item.name, color: item.color ?? chartPalette[index % chartPalette.length] })) : void 0 },
|
|
8656
|
-
children:
|
|
9152
|
+
children: React12.createElement(
|
|
8657
9153
|
"div",
|
|
8658
9154
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
8659
|
-
|
|
9155
|
+
React12.createElement(
|
|
8660
9156
|
"svg",
|
|
8661
9157
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
8662
|
-
showGrid &&
|
|
9158
|
+
showGrid && React12.createElement(
|
|
8663
9159
|
"g",
|
|
8664
9160
|
{},
|
|
8665
9161
|
...ticks.map((tick) => {
|
|
8666
9162
|
const y = yInPlot(tick, domain, plot);
|
|
8667
|
-
return
|
|
9163
|
+
return React12.createElement("line", {
|
|
8668
9164
|
key: `line-tick-${tick}`,
|
|
8669
9165
|
x1: plot.x,
|
|
8670
9166
|
y1: y,
|
|
@@ -8675,7 +9171,7 @@ function LineChart({
|
|
|
8675
9171
|
});
|
|
8676
9172
|
})
|
|
8677
9173
|
),
|
|
8678
|
-
|
|
9174
|
+
React12.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: d.stroke.hair }),
|
|
8679
9175
|
...series.flatMap((item, seriesIndex) => {
|
|
8680
9176
|
if (item.points.length === 0) return [];
|
|
8681
9177
|
const color = chartColor(item.color, c, seriesIndex);
|
|
@@ -8688,9 +9184,9 @@ function LineChart({
|
|
|
8688
9184
|
}
|
|
8689
9185
|
const elements = [];
|
|
8690
9186
|
if (areaPath) {
|
|
8691
|
-
elements.push(
|
|
9187
|
+
elements.push(React12.createElement("path", { key: `${item.name}-area`, d: areaPath, fill: color, opacity: 0.1 }));
|
|
8692
9188
|
}
|
|
8693
|
-
elements.push(
|
|
9189
|
+
elements.push(React12.createElement("path", {
|
|
8694
9190
|
key: `${item.name}-line`,
|
|
8695
9191
|
d: linePath,
|
|
8696
9192
|
fill: "none",
|
|
@@ -8702,7 +9198,7 @@ function LineChart({
|
|
|
8702
9198
|
if (showPoints) {
|
|
8703
9199
|
elements.push(...item.points.map((value, index) => {
|
|
8704
9200
|
const point = pointFor(value, index);
|
|
8705
|
-
return
|
|
9201
|
+
return React12.createElement("circle", {
|
|
8706
9202
|
key: `${item.name}-point-${index}`,
|
|
8707
9203
|
cx: point.x,
|
|
8708
9204
|
cy: point.y,
|
|
@@ -8755,7 +9251,7 @@ for (const chart of [PieChart, DonutChart, StackedBar, BarChart, ParetoBarChart,
|
|
|
8755
9251
|
}
|
|
8756
9252
|
|
|
8757
9253
|
// src/primitives/plots.ts
|
|
8758
|
-
import
|
|
9254
|
+
import React13 from "react";
|
|
8759
9255
|
for (const chart of [ScatterPlot, ParetoChart, QuadrantChart, IntervalPlot]) {
|
|
8760
9256
|
Object.defineProperty(chart, CANVAS_CHART_COMPONENT, { value: true });
|
|
8761
9257
|
}
|
|
@@ -8764,6 +9260,12 @@ function xTickLabelAlign(index, count) {
|
|
|
8764
9260
|
if (index === count - 1) return "right";
|
|
8765
9261
|
return "center";
|
|
8766
9262
|
}
|
|
9263
|
+
function pointDescription(point, index, formatX, formatY, xLabel = "x", yLabel = "y") {
|
|
9264
|
+
return `${point.label ?? `Point ${index + 1}`}: ${xLabel} ${formatChartValue(point.x, formatX)}, ${yLabel} ${formatChartValue(point.y, formatY)}`;
|
|
9265
|
+
}
|
|
9266
|
+
function pointDescriptions(points, formatX, formatY, xLabel = "x", yLabel = "y") {
|
|
9267
|
+
return points.map((point, index) => pointDescription(point, index, formatX, formatY, xLabel, yLabel));
|
|
9268
|
+
}
|
|
8767
9269
|
function ScatterPlot({
|
|
8768
9270
|
points,
|
|
8769
9271
|
c,
|
|
@@ -8780,7 +9282,8 @@ function ScatterPlot({
|
|
|
8780
9282
|
formatX = "decimal",
|
|
8781
9283
|
formatY = "decimal",
|
|
8782
9284
|
showGrid = true,
|
|
8783
|
-
footer
|
|
9285
|
+
footer,
|
|
9286
|
+
...accessibility
|
|
8784
9287
|
}) {
|
|
8785
9288
|
const margin = { top: 20, right: 24, bottom: xAxisLabel ? 46 : 34, left: yAxisLabel ? 54 : 42 };
|
|
8786
9289
|
const plot = createPlotArea(width, height, margin);
|
|
@@ -8797,23 +9300,26 @@ function ScatterPlot({
|
|
|
8797
9300
|
return { item, index, point, color: chartColor(item.color, c, index) };
|
|
8798
9301
|
});
|
|
8799
9302
|
return ChartFrame({
|
|
9303
|
+
...accessibility,
|
|
9304
|
+
ariaLabel: accessibility.ariaLabel ?? title ?? "Scatter plot",
|
|
9305
|
+
description: chartDescription(accessibility.description, pointDescriptions(points, formatX, formatY, xAxisLabel, yAxisLabel)),
|
|
8800
9306
|
c,
|
|
8801
9307
|
title,
|
|
8802
9308
|
subtitle,
|
|
8803
9309
|
width,
|
|
8804
9310
|
footer,
|
|
8805
|
-
children:
|
|
9311
|
+
children: React13.createElement(
|
|
8806
9312
|
"div",
|
|
8807
9313
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
8808
|
-
|
|
9314
|
+
React13.createElement(
|
|
8809
9315
|
"svg",
|
|
8810
9316
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
8811
|
-
showGrid &&
|
|
9317
|
+
showGrid && React13.createElement(
|
|
8812
9318
|
"g",
|
|
8813
9319
|
{},
|
|
8814
9320
|
...xTicks.map((tick) => {
|
|
8815
9321
|
const x = xInPlot(tick, xDomain, plot);
|
|
8816
|
-
return
|
|
9322
|
+
return React13.createElement("line", {
|
|
8817
9323
|
key: `x-tick-${tick}`,
|
|
8818
9324
|
x1: x,
|
|
8819
9325
|
y1: plot.y,
|
|
@@ -8825,7 +9331,7 @@ function ScatterPlot({
|
|
|
8825
9331
|
}),
|
|
8826
9332
|
...yTicks.map((tick) => {
|
|
8827
9333
|
const y = yInPlot(tick, yDomain, plot);
|
|
8828
|
-
return
|
|
9334
|
+
return React13.createElement("line", {
|
|
8829
9335
|
key: `y-tick-${tick}`,
|
|
8830
9336
|
x1: plot.x,
|
|
8831
9337
|
y1: y,
|
|
@@ -8836,9 +9342,9 @@ function ScatterPlot({
|
|
|
8836
9342
|
});
|
|
8837
9343
|
})
|
|
8838
9344
|
),
|
|
8839
|
-
|
|
9345
|
+
React13.createElement("rect", { x: plot.x, y: plot.y, width: plot.innerWidth, height: plot.innerHeight, fill: "transparent", stroke: c.borderLight, strokeWidth: 1.2, rx: 6 }),
|
|
8840
9346
|
...pointGeometries.map(
|
|
8841
|
-
({ item, index, point, color }) =>
|
|
9347
|
+
({ item, index, point, color }) => React13.createElement("circle", {
|
|
8842
9348
|
key: `${item.label ?? "point"}-${index}`,
|
|
8843
9349
|
cx: point.x,
|
|
8844
9350
|
cy: point.y,
|
|
@@ -8940,7 +9446,8 @@ function ParetoChart({
|
|
|
8940
9446
|
frontierColor,
|
|
8941
9447
|
showGoal = true,
|
|
8942
9448
|
goalLabel,
|
|
8943
|
-
footer
|
|
9449
|
+
footer,
|
|
9450
|
+
...accessibility
|
|
8944
9451
|
}) {
|
|
8945
9452
|
const margin = { top: 22, right: 26, bottom: xAxisLabel ? 48 : 36, left: yAxisLabel ? 56 : 44 };
|
|
8946
9453
|
const plot = createPlotArea(width, height, margin);
|
|
@@ -8980,6 +9487,15 @@ function ParetoChart({
|
|
|
8980
9487
|
const goalYEnd = yObjective === "maximize" ? goalYStart - 26 : goalYStart + 26;
|
|
8981
9488
|
const arrowSize = 5;
|
|
8982
9489
|
return ChartFrame({
|
|
9490
|
+
...accessibility,
|
|
9491
|
+
ariaLabel: accessibility.ariaLabel ?? title ?? "Pareto frontier",
|
|
9492
|
+
description: chartDescription(accessibility.description, [
|
|
9493
|
+
`${xObjective} ${xAxisLabel ?? "x"}, ${yObjective} ${yAxisLabel ?? "y"}`,
|
|
9494
|
+
...pointGeometries.map(
|
|
9495
|
+
({ point, index, frontier: frontier2 }) => `${pointDescription(point, index, formatX, formatY, xAxisLabel, yAxisLabel)}, ${frontier2 ? "on the Pareto frontier" : "dominated"}`
|
|
9496
|
+
),
|
|
9497
|
+
...pointGeometries.length ? [] : ["No points"]
|
|
9498
|
+
]),
|
|
8983
9499
|
c,
|
|
8984
9500
|
title,
|
|
8985
9501
|
subtitle,
|
|
@@ -8989,18 +9505,18 @@ function ParetoChart({
|
|
|
8989
9505
|
{ label: "Pareto frontier", color: frontier },
|
|
8990
9506
|
{ label: "dominated", color: "neutral" }
|
|
8991
9507
|
],
|
|
8992
|
-
children:
|
|
9508
|
+
children: React13.createElement(
|
|
8993
9509
|
"div",
|
|
8994
9510
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
8995
|
-
|
|
9511
|
+
React13.createElement(
|
|
8996
9512
|
"svg",
|
|
8997
9513
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
8998
|
-
showGrid &&
|
|
9514
|
+
showGrid && React13.createElement(
|
|
8999
9515
|
"g",
|
|
9000
9516
|
{},
|
|
9001
9517
|
...xTicks.map((tick) => {
|
|
9002
9518
|
const x = pointFor(tick, yDomain.min).x;
|
|
9003
|
-
return
|
|
9519
|
+
return React13.createElement("line", {
|
|
9004
9520
|
key: `pareto-x-grid-${tick}`,
|
|
9005
9521
|
x1: x,
|
|
9006
9522
|
y1: plot.y,
|
|
@@ -9012,7 +9528,7 @@ function ParetoChart({
|
|
|
9012
9528
|
}),
|
|
9013
9529
|
...yTicks.map((tick) => {
|
|
9014
9530
|
const y = yInPlot(tick, yDomain, plot);
|
|
9015
|
-
return
|
|
9531
|
+
return React13.createElement("line", {
|
|
9016
9532
|
key: `pareto-y-grid-${tick}`,
|
|
9017
9533
|
x1: plot.x,
|
|
9018
9534
|
y1: y,
|
|
@@ -9023,7 +9539,7 @@ function ParetoChart({
|
|
|
9023
9539
|
});
|
|
9024
9540
|
})
|
|
9025
9541
|
),
|
|
9026
|
-
|
|
9542
|
+
React13.createElement("rect", {
|
|
9027
9543
|
x: plot.x,
|
|
9028
9544
|
y: plot.y,
|
|
9029
9545
|
width: plot.innerWidth,
|
|
@@ -9033,17 +9549,17 @@ function ParetoChart({
|
|
|
9033
9549
|
strokeWidth: 1.2,
|
|
9034
9550
|
rx: 6
|
|
9035
9551
|
}),
|
|
9036
|
-
showGoal &&
|
|
9552
|
+
showGoal && React13.createElement(
|
|
9037
9553
|
"g",
|
|
9038
9554
|
{ "data-pareto-goal": true, stroke: frontier, fill: "none", strokeWidth: 2, strokeLinecap: "round" },
|
|
9039
|
-
|
|
9040
|
-
|
|
9041
|
-
|
|
9042
|
-
|
|
9043
|
-
|
|
9044
|
-
|
|
9555
|
+
React13.createElement("line", { x1: goalXStart, y1: goalY, x2: goalXEnd, y2: goalY }),
|
|
9556
|
+
React13.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY - arrowSize }),
|
|
9557
|
+
React13.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY + arrowSize }),
|
|
9558
|
+
React13.createElement("line", { x1: goalXStart, y1: goalYStart, x2: goalXStart, y2: goalYEnd }),
|
|
9559
|
+
React13.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart - arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) }),
|
|
9560
|
+
React13.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart + arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) })
|
|
9045
9561
|
),
|
|
9046
|
-
frontierPath &&
|
|
9562
|
+
frontierPath && React13.createElement("path", {
|
|
9047
9563
|
"data-pareto-frontier": true,
|
|
9048
9564
|
d: frontierPath,
|
|
9049
9565
|
fill: "none",
|
|
@@ -9052,7 +9568,7 @@ function ParetoChart({
|
|
|
9052
9568
|
strokeLinecap: "round",
|
|
9053
9569
|
strokeLinejoin: "round"
|
|
9054
9570
|
}),
|
|
9055
|
-
...pointGeometries.filter((geometry) => !geometry.frontier).concat(pointGeometries.filter((geometry) => geometry.frontier)).map(({ point, index, x, y, color, frontier: isFrontier }) =>
|
|
9571
|
+
...pointGeometries.filter((geometry) => !geometry.frontier).concat(pointGeometries.filter((geometry) => geometry.frontier)).map(({ point, index, x, y, color, frontier: isFrontier }) => React13.createElement("circle", {
|
|
9056
9572
|
key: `pareto-point-${point.label ?? "point"}-${index}`,
|
|
9057
9573
|
"data-pareto-status": isFrontier ? "frontier" : "dominated",
|
|
9058
9574
|
cx: x,
|
|
@@ -9128,7 +9644,8 @@ function QuadrantChart({
|
|
|
9128
9644
|
formatY = "decimal",
|
|
9129
9645
|
showTicks = false,
|
|
9130
9646
|
showGrid = false,
|
|
9131
|
-
footer
|
|
9647
|
+
footer,
|
|
9648
|
+
...accessibility
|
|
9132
9649
|
}) {
|
|
9133
9650
|
const margin = {
|
|
9134
9651
|
top: 18,
|
|
@@ -9159,23 +9676,31 @@ function QuadrantChart({
|
|
|
9159
9676
|
color: chartColor(point.color, c, index)
|
|
9160
9677
|
}));
|
|
9161
9678
|
return ChartFrame({
|
|
9679
|
+
...accessibility,
|
|
9680
|
+
ariaLabel: accessibility.ariaLabel ?? title ?? "Quadrant chart",
|
|
9681
|
+
description: chartDescription(accessibility.description, [
|
|
9682
|
+
`Thresholds: ${xAxisLabel ?? "x"} ${formatChartValue(resolvedXThreshold, formatX)}, ${yAxisLabel ?? "y"} ${formatChartValue(resolvedYThreshold, formatY)}`,
|
|
9683
|
+
...regionEntries.map(({ key, region }) => `${key}: ${region.label}`),
|
|
9684
|
+
...pointDescriptions(points, formatX, formatY, xAxisLabel, yAxisLabel),
|
|
9685
|
+
...points.length ? [] : ["No points"]
|
|
9686
|
+
]),
|
|
9162
9687
|
c,
|
|
9163
9688
|
title,
|
|
9164
9689
|
subtitle,
|
|
9165
9690
|
width,
|
|
9166
9691
|
footer,
|
|
9167
|
-
children:
|
|
9692
|
+
children: React13.createElement(
|
|
9168
9693
|
"div",
|
|
9169
9694
|
{
|
|
9170
9695
|
style: { position: "relative", width, height, display: "flex" }
|
|
9171
9696
|
},
|
|
9172
|
-
|
|
9697
|
+
React13.createElement(
|
|
9173
9698
|
"svg",
|
|
9174
9699
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
9175
9700
|
...regionEntries.map(({ key, region, x, y, width: regionWidth, height: regionHeight }, index) => {
|
|
9176
9701
|
const color = chartColor(region.color, c, index);
|
|
9177
9702
|
const emphasized = region.emphasis === true;
|
|
9178
|
-
return
|
|
9703
|
+
return React13.createElement("rect", {
|
|
9179
9704
|
key: `quadrant-${key}`,
|
|
9180
9705
|
x,
|
|
9181
9706
|
y,
|
|
@@ -9187,12 +9712,12 @@ function QuadrantChart({
|
|
|
9187
9712
|
strokeWidth: emphasized ? 2 : 0
|
|
9188
9713
|
});
|
|
9189
9714
|
}),
|
|
9190
|
-
showGrid &&
|
|
9715
|
+
showGrid && React13.createElement(
|
|
9191
9716
|
"g",
|
|
9192
9717
|
{},
|
|
9193
9718
|
...xTicks.map((tick) => {
|
|
9194
9719
|
const x = xInPlot(tick, xDomain, plot);
|
|
9195
|
-
return
|
|
9720
|
+
return React13.createElement("line", {
|
|
9196
9721
|
key: `quadrant-x-grid-${tick}`,
|
|
9197
9722
|
x1: x,
|
|
9198
9723
|
y1: plot.y,
|
|
@@ -9204,7 +9729,7 @@ function QuadrantChart({
|
|
|
9204
9729
|
}),
|
|
9205
9730
|
...yTicks.map((tick) => {
|
|
9206
9731
|
const y = yInPlot(tick, yDomain, plot);
|
|
9207
|
-
return
|
|
9732
|
+
return React13.createElement("line", {
|
|
9208
9733
|
key: `quadrant-y-grid-${tick}`,
|
|
9209
9734
|
x1: plot.x,
|
|
9210
9735
|
y1: y,
|
|
@@ -9215,7 +9740,7 @@ function QuadrantChart({
|
|
|
9215
9740
|
});
|
|
9216
9741
|
})
|
|
9217
9742
|
),
|
|
9218
|
-
|
|
9743
|
+
React13.createElement("rect", {
|
|
9219
9744
|
x: plot.x,
|
|
9220
9745
|
y: plot.y,
|
|
9221
9746
|
width: plot.innerWidth,
|
|
@@ -9225,7 +9750,7 @@ function QuadrantChart({
|
|
|
9225
9750
|
strokeWidth: 1.2,
|
|
9226
9751
|
rx: 8
|
|
9227
9752
|
}),
|
|
9228
|
-
|
|
9753
|
+
React13.createElement("line", {
|
|
9229
9754
|
x1: midX,
|
|
9230
9755
|
y1: plot.y,
|
|
9231
9756
|
x2: midX,
|
|
@@ -9233,7 +9758,7 @@ function QuadrantChart({
|
|
|
9233
9758
|
stroke: c.borderLight,
|
|
9234
9759
|
strokeWidth: 1.4
|
|
9235
9760
|
}),
|
|
9236
|
-
|
|
9761
|
+
React13.createElement("line", {
|
|
9237
9762
|
x1: plot.x,
|
|
9238
9763
|
y1: midY,
|
|
9239
9764
|
x2: plot.right,
|
|
@@ -9243,7 +9768,7 @@ function QuadrantChart({
|
|
|
9243
9768
|
}),
|
|
9244
9769
|
...(showTicks ? xTicks : []).map((tick) => {
|
|
9245
9770
|
const x = xInPlot(tick, xDomain, plot);
|
|
9246
|
-
return
|
|
9771
|
+
return React13.createElement("line", {
|
|
9247
9772
|
key: `quadrant-x-tick-${tick}`,
|
|
9248
9773
|
x1: x,
|
|
9249
9774
|
y1: plot.bottom,
|
|
@@ -9255,7 +9780,7 @@ function QuadrantChart({
|
|
|
9255
9780
|
}),
|
|
9256
9781
|
...(showTicks ? yTicks : []).map((tick) => {
|
|
9257
9782
|
const y = yInPlot(tick, yDomain, plot);
|
|
9258
|
-
return
|
|
9783
|
+
return React13.createElement("line", {
|
|
9259
9784
|
key: `quadrant-y-tick-${tick}`,
|
|
9260
9785
|
x1: plot.x - 5,
|
|
9261
9786
|
y1: y,
|
|
@@ -9265,7 +9790,7 @@ function QuadrantChart({
|
|
|
9265
9790
|
strokeWidth: 1.2
|
|
9266
9791
|
});
|
|
9267
9792
|
}),
|
|
9268
|
-
...pointGeometries.map(({ point, index, x, y, color }) =>
|
|
9793
|
+
...pointGeometries.map(({ point, index, x, y, color }) => React13.createElement("circle", {
|
|
9269
9794
|
key: `quadrant-point-${point.label ?? index}`,
|
|
9270
9795
|
cx: x,
|
|
9271
9796
|
cy: y,
|
|
@@ -9341,7 +9866,8 @@ function IntervalPlot({
|
|
|
9341
9866
|
max,
|
|
9342
9867
|
format = "decimal",
|
|
9343
9868
|
axisLabel,
|
|
9344
|
-
footer
|
|
9869
|
+
footer,
|
|
9870
|
+
...accessibility
|
|
9345
9871
|
}) {
|
|
9346
9872
|
const margin = { top: 22, right: 28, bottom: axisLabel ? 44 : 30, left: 96 };
|
|
9347
9873
|
const plot = createPlotArea(width, height, margin);
|
|
@@ -9362,20 +9888,25 @@ function IntervalPlot({
|
|
|
9362
9888
|
};
|
|
9363
9889
|
});
|
|
9364
9890
|
return ChartFrame({
|
|
9891
|
+
...accessibility,
|
|
9892
|
+
ariaLabel: accessibility.ariaLabel ?? title ?? "Interval plot",
|
|
9893
|
+
description: chartDescription(accessibility.description, data.map(
|
|
9894
|
+
(item) => `${item.label}: low ${item.lowLabel ?? formatChartValue(item.low, format)}, midpoint ${item.midLabel ?? formatChartValue(item.mid, format)}, high ${item.highLabel ?? formatChartValue(item.high, format)}`
|
|
9895
|
+
)),
|
|
9365
9896
|
c,
|
|
9366
9897
|
title,
|
|
9367
9898
|
subtitle,
|
|
9368
9899
|
width,
|
|
9369
9900
|
footer,
|
|
9370
|
-
children:
|
|
9901
|
+
children: React13.createElement(
|
|
9371
9902
|
"div",
|
|
9372
9903
|
{ style: { position: "relative", width, height, display: "flex" } },
|
|
9373
|
-
|
|
9904
|
+
React13.createElement(
|
|
9374
9905
|
"svg",
|
|
9375
9906
|
{ width, height, viewBox: `0 0 ${width} ${height}` },
|
|
9376
9907
|
...ticks.map((tick) => {
|
|
9377
9908
|
const x = scaleX(tick);
|
|
9378
|
-
return
|
|
9909
|
+
return React13.createElement("line", {
|
|
9379
9910
|
key: `interval-tick-${tick}`,
|
|
9380
9911
|
x1: x,
|
|
9381
9912
|
y1: plot.y,
|
|
@@ -9385,10 +9916,10 @@ function IntervalPlot({
|
|
|
9385
9916
|
strokeWidth: 1
|
|
9386
9917
|
});
|
|
9387
9918
|
}),
|
|
9388
|
-
|
|
9919
|
+
React13.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
|
|
9389
9920
|
...rows.flatMap(({ item, index, y, color, lowX, midX, highX }) => [
|
|
9390
|
-
|
|
9391
|
-
|
|
9921
|
+
React13.createElement("line", { key: `${item.label}-range-${index}`, x1: lowX, y1: y, x2: highX, y2: y, stroke: color, strokeWidth: 9, strokeLinecap: "round", opacity: 0.9 }),
|
|
9922
|
+
React13.createElement("circle", { key: `${item.label}-mid-${index}`, cx: midX, cy: y, r: 10, fill: c.bgCard, stroke: color, strokeWidth: 4 })
|
|
9392
9923
|
])
|
|
9393
9924
|
),
|
|
9394
9925
|
...ticks.map((tick, index) => {
|
|
@@ -9425,7 +9956,7 @@ function IntervalPlot({
|
|
|
9425
9956
|
}
|
|
9426
9957
|
function Badge({ label, c, color = "primary" }) {
|
|
9427
9958
|
const solidColor = getReadableColor(color, c);
|
|
9428
|
-
return
|
|
9959
|
+
return React13.createElement("div", {
|
|
9429
9960
|
style: {
|
|
9430
9961
|
display: "flex",
|
|
9431
9962
|
alignItems: "center",
|
|
@@ -9446,7 +9977,7 @@ function DotPoint({ x, y, label, color, c, size = 12, labelOffset }) {
|
|
|
9446
9977
|
const offY = labelOffset?.y ?? -22;
|
|
9447
9978
|
return [
|
|
9448
9979
|
// Dot
|
|
9449
|
-
|
|
9980
|
+
React13.createElement("div", {
|
|
9450
9981
|
key: `dot-${label}`,
|
|
9451
9982
|
style: {
|
|
9452
9983
|
position: "absolute",
|
|
@@ -9461,7 +9992,7 @@ function DotPoint({ x, y, label, color, c, size = 12, labelOffset }) {
|
|
|
9461
9992
|
}
|
|
9462
9993
|
}),
|
|
9463
9994
|
// Label
|
|
9464
|
-
|
|
9995
|
+
React13.createElement("div", {
|
|
9465
9996
|
key: `label-${label}`,
|
|
9466
9997
|
style: {
|
|
9467
9998
|
position: "absolute",
|
|
@@ -9487,7 +10018,7 @@ function DashedLine({ x1, y1, x2, y2, color, dotSpacing = 8, dotSize = 2 }) {
|
|
|
9487
10018
|
if (i % 2 === 1) continue;
|
|
9488
10019
|
const t = i / numDots;
|
|
9489
10020
|
dots.push(
|
|
9490
|
-
|
|
10021
|
+
React13.createElement("div", {
|
|
9491
10022
|
key: `dash-${i}`,
|
|
9492
10023
|
style: {
|
|
9493
10024
|
position: "absolute",
|
|
@@ -9504,7 +10035,7 @@ function DashedLine({ x1, y1, x2, y2, color, dotSpacing = 8, dotSize = 2 }) {
|
|
|
9504
10035
|
return dots;
|
|
9505
10036
|
}
|
|
9506
10037
|
function Legend({ items, c, title }) {
|
|
9507
|
-
return
|
|
10038
|
+
return React13.createElement(
|
|
9508
10039
|
"div",
|
|
9509
10040
|
{
|
|
9510
10041
|
style: {
|
|
@@ -9517,7 +10048,7 @@ function Legend({ items, c, title }) {
|
|
|
9517
10048
|
padding: `${densityOf(c).s(14)}px ${densityOf(c).s(16)}px`
|
|
9518
10049
|
}
|
|
9519
10050
|
},
|
|
9520
|
-
title &&
|
|
10051
|
+
title && React13.createElement("div", {
|
|
9521
10052
|
style: {
|
|
9522
10053
|
fontSize: densityOf(c).f(11),
|
|
9523
10054
|
fontWeight: 700,
|
|
@@ -9528,13 +10059,13 @@ function Legend({ items, c, title }) {
|
|
|
9528
10059
|
}
|
|
9529
10060
|
}, title),
|
|
9530
10061
|
...items.map(
|
|
9531
|
-
(item, i) =>
|
|
10062
|
+
(item, i) => React13.createElement(
|
|
9532
10063
|
"div",
|
|
9533
10064
|
{
|
|
9534
10065
|
key: `legend-${i}`,
|
|
9535
10066
|
style: { display: "flex", alignItems: "center", gap: 8 }
|
|
9536
10067
|
},
|
|
9537
|
-
|
|
10068
|
+
React13.createElement("div", {
|
|
9538
10069
|
style: {
|
|
9539
10070
|
width: 16,
|
|
9540
10071
|
height: item.style === "dashed" ? 0 : 2,
|
|
@@ -9544,7 +10075,7 @@ function Legend({ items, c, title }) {
|
|
|
9544
10075
|
} : {}
|
|
9545
10076
|
}
|
|
9546
10077
|
}),
|
|
9547
|
-
|
|
10078
|
+
React13.createElement("div", {
|
|
9548
10079
|
style: {
|
|
9549
10080
|
fontSize: densityOf(c).f(11),
|
|
9550
10081
|
color: c.textMuted,
|
|
@@ -9557,7 +10088,7 @@ function Legend({ items, c, title }) {
|
|
|
9557
10088
|
}
|
|
9558
10089
|
|
|
9559
10090
|
// src/primitives/board.ts
|
|
9560
|
-
import
|
|
10091
|
+
import React14 from "react";
|
|
9561
10092
|
var CANVAS_ITEM_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.canvas-item");
|
|
9562
10093
|
function dimension(value, name) {
|
|
9563
10094
|
if (value !== void 0 && (!Number.isFinite(value) || value <= 0 || value > 8192)) {
|
|
@@ -9566,7 +10097,7 @@ function dimension(value, name) {
|
|
|
9566
10097
|
return value;
|
|
9567
10098
|
}
|
|
9568
10099
|
function Board({ children, c, width = 960, height = 540, background }) {
|
|
9569
|
-
return
|
|
10100
|
+
return React14.createElement("div", { style: {
|
|
9570
10101
|
display: "flex",
|
|
9571
10102
|
position: "relative",
|
|
9572
10103
|
width: dimension(width, "Board width"),
|
|
@@ -9578,15 +10109,15 @@ function Board({ children, c, width = 960, height = 540, background }) {
|
|
|
9578
10109
|
}
|
|
9579
10110
|
function CanvasItem({ children, x, y, width, height }) {
|
|
9580
10111
|
if (!Number.isFinite(x) || !Number.isFinite(y)) throw new Error("CanvasItem x and y must be finite numbers.");
|
|
9581
|
-
const sizedChildren =
|
|
9582
|
-
if (!
|
|
10112
|
+
const sizedChildren = React14.Children.map(children, (child) => {
|
|
10113
|
+
if (!React14.isValidElement(child)) return child;
|
|
9583
10114
|
if (width !== void 0 && height !== void 0 && isCanvasChart(child.type)) {
|
|
9584
|
-
const chart =
|
|
9585
|
-
return
|
|
10115
|
+
const chart = React14.cloneElement(child, { width: child.props.width ?? width, height: child.props.height ?? height });
|
|
10116
|
+
return React14.createElement(CanvasChartFit, { width, height, __vizmaticTextScope: child.props.__vizmaticTextScope }, chart);
|
|
9586
10117
|
}
|
|
9587
|
-
return
|
|
10118
|
+
return React14.cloneElement(child, { ...width !== void 0 ? { width } : {}, ...height !== void 0 ? { height } : {} });
|
|
9588
10119
|
});
|
|
9589
|
-
return
|
|
10120
|
+
return React14.createElement("div", { style: {
|
|
9590
10121
|
display: "flex",
|
|
9591
10122
|
position: "absolute",
|
|
9592
10123
|
left: x,
|
|
@@ -9599,14 +10130,14 @@ function CanvasItem({ children, x, y, width, height }) {
|
|
|
9599
10130
|
Object.defineProperty(CanvasItem, CANVAS_ITEM_COMPONENT, { value: true });
|
|
9600
10131
|
|
|
9601
10132
|
// src/primitives/science-math-physics.ts
|
|
9602
|
-
import
|
|
10133
|
+
import React15 from "react";
|
|
9603
10134
|
var MAX_SVG_SIZE = 4096;
|
|
9604
10135
|
var FONT_SIZE = 13;
|
|
9605
10136
|
function finite(value, name) {
|
|
9606
10137
|
if (!Number.isFinite(value)) throw new TypeError(`${name} must be finite.`);
|
|
9607
10138
|
return value;
|
|
9608
10139
|
}
|
|
9609
|
-
function
|
|
10140
|
+
function positive2(value, name) {
|
|
9610
10141
|
finite(value, name);
|
|
9611
10142
|
if (value <= 0) throw new RangeError(`${name} must be greater than zero.`);
|
|
9612
10143
|
return value;
|
|
@@ -9671,14 +10202,14 @@ function svgShell({ c, width, height, title, ariaLabel, description, children })
|
|
|
9671
10202
|
const d = densityOf(c);
|
|
9672
10203
|
const overlays = [];
|
|
9673
10204
|
const svgChildren = [
|
|
9674
|
-
|
|
9675
|
-
|
|
10205
|
+
React15.createElement("title", { key: "title" }, title),
|
|
10206
|
+
React15.createElement("desc", { key: "description" }, description)
|
|
9676
10207
|
];
|
|
9677
10208
|
for (const [index, child] of children.entries()) {
|
|
9678
|
-
if (
|
|
10209
|
+
if (React15.isValidElement(child) && child.type === "text") {
|
|
9679
10210
|
const textProps = child.props;
|
|
9680
|
-
const text =
|
|
9681
|
-
overlays.push(
|
|
10211
|
+
const text = React15.Children.toArray(textProps.children).map((part) => String(part)).join("");
|
|
10212
|
+
overlays.push(React15.createElement(SvgMathText, {
|
|
9682
10213
|
key: `label-${index}`,
|
|
9683
10214
|
text,
|
|
9684
10215
|
x: textProps.x,
|
|
@@ -9695,7 +10226,7 @@ function svgShell({ c, width, height, title, ariaLabel, description, children })
|
|
|
9695
10226
|
}
|
|
9696
10227
|
}
|
|
9697
10228
|
if (!UNNAMED_TITLES.has(title)) {
|
|
9698
|
-
overlays.unshift(
|
|
10229
|
+
overlays.unshift(React15.createElement(SvgMathText, {
|
|
9699
10230
|
key: "diagram-title",
|
|
9700
10231
|
text: title,
|
|
9701
10232
|
x: 0,
|
|
@@ -9708,7 +10239,7 @@ function svgShell({ c, width, height, title, ariaLabel, description, children })
|
|
|
9708
10239
|
dominantBaseline: "auto"
|
|
9709
10240
|
}));
|
|
9710
10241
|
}
|
|
9711
|
-
return
|
|
10242
|
+
return React15.createElement(
|
|
9712
10243
|
"div",
|
|
9713
10244
|
{
|
|
9714
10245
|
role: "img",
|
|
@@ -9716,7 +10247,7 @@ function svgShell({ c, width, height, title, ariaLabel, description, children })
|
|
|
9716
10247
|
"aria-description": description,
|
|
9717
10248
|
style: { position: "relative", width, height, display: "flex", flexShrink: 0 }
|
|
9718
10249
|
},
|
|
9719
|
-
|
|
10250
|
+
React15.createElement("svg", {
|
|
9720
10251
|
width,
|
|
9721
10252
|
height,
|
|
9722
10253
|
viewBox: `0 0 ${width} ${height}`,
|
|
@@ -9737,7 +10268,7 @@ function mapNumberLine(value, min, max, width, padding = 56) {
|
|
|
9737
10268
|
finite(width, "NumberLine width");
|
|
9738
10269
|
finite(padding, "NumberLine padding");
|
|
9739
10270
|
if (padding < 0) throw new RangeError("NumberLine padding cannot be negative.");
|
|
9740
|
-
|
|
10271
|
+
positive2(width - padding * 2, "NumberLine drawable width");
|
|
9741
10272
|
if (value < min || value > max) throw new RangeError("NumberLine value must lie within its domain.");
|
|
9742
10273
|
return padding + (value - min) / range * (width - padding * 2);
|
|
9743
10274
|
}
|
|
@@ -9790,9 +10321,9 @@ function NumberLine({
|
|
|
9790
10321
|
const x = (value) => mapNumberLine(value, min, max, width);
|
|
9791
10322
|
const axisY = Math.round(height * (interval && height < 220 ? 0.45 : 0.56));
|
|
9792
10323
|
const elements = [
|
|
9793
|
-
|
|
9794
|
-
|
|
9795
|
-
|
|
10324
|
+
React15.createElement("line", { key: "axis", x1: 56, y1: axisY, x2: width - 56, y2: axisY, stroke: c.textSecondary, strokeWidth: densityOf(c).w(2) }),
|
|
10325
|
+
React15.createElement("path", { key: "left-arrow", d: `M 56 ${axisY} l 9 -5 v 10 z`, fill: c.textSecondary }),
|
|
10326
|
+
React15.createElement("path", { key: "right-arrow", d: `M ${width - 56} ${axisY} l -9 -5 v 10 z`, fill: c.textSecondary })
|
|
9796
10327
|
];
|
|
9797
10328
|
if (interval) {
|
|
9798
10329
|
const fromX = x(interval.from);
|
|
@@ -9802,21 +10333,21 @@ function NumberLine({
|
|
|
9802
10333
|
const includeTo = interval.includeTo !== false;
|
|
9803
10334
|
const intervalY = axisY + 52;
|
|
9804
10335
|
elements.push(
|
|
9805
|
-
|
|
9806
|
-
|
|
9807
|
-
|
|
10336
|
+
React15.createElement("line", { key: "interval", x1: fromX, y1: intervalY, x2: toX, y2: intervalY, stroke: color, strokeWidth: densityOf(c).w(8), strokeLinecap: "round", opacity: 0.62 }),
|
|
10337
|
+
React15.createElement("circle", { key: "interval-from", cx: fromX, cy: intervalY, r: 7, fill: includeFrom ? color : c.bgSubtle, stroke: color, strokeWidth: densityOf(c).w(3) }),
|
|
10338
|
+
React15.createElement("circle", { key: "interval-to", cx: toX, cy: intervalY, r: 7, fill: includeTo ? color : c.bgSubtle, stroke: color, strokeWidth: densityOf(c).w(3) })
|
|
9808
10339
|
);
|
|
9809
10340
|
if (interval.label) {
|
|
9810
10341
|
const label = interval.label;
|
|
9811
10342
|
const labelX = clamp2((fromX + toX) / 2, 56 + textWidth(label) / 2, width - 56 - textWidth(label) / 2);
|
|
9812
|
-
elements.push(
|
|
10343
|
+
elements.push(React15.createElement("text", { key: "interval-label", x: labelX, y: axisY + 82, textAnchor: "middle", fill: c.textSecondary, fontFamily: c.fontSans, fontSize: FONT_SIZE }, label));
|
|
9813
10344
|
}
|
|
9814
10345
|
}
|
|
9815
10346
|
for (const [index, tick] of resolvedTicks.entries()) {
|
|
9816
10347
|
const tickX = x(tick.value);
|
|
9817
10348
|
elements.push(
|
|
9818
|
-
|
|
9819
|
-
|
|
10349
|
+
React15.createElement("line", { key: `tick-${index}`, x1: tickX, y1: axisY - 9, x2: tickX, y2: axisY + 9, stroke: c.textSecondary, strokeWidth: densityOf(c).w(2) }),
|
|
10350
|
+
React15.createElement("text", { key: `tick-label-${index}`, x: tickX, y: axisY + 34, textAnchor: "middle", fill: c.textSecondary, fontFamily: c.fontMono, fontSize: 12 }, tick.label ?? formatNumber(tick.value))
|
|
9820
10351
|
);
|
|
9821
10352
|
}
|
|
9822
10353
|
markers.forEach((marker, index) => {
|
|
@@ -9826,9 +10357,9 @@ function NumberLine({
|
|
|
9826
10357
|
const labelY = Math.max(66, axisY - 54 - lane * 30);
|
|
9827
10358
|
const labelX = clamp2(markerX, 56 + textWidth(marker.label, 12) / 2, width - 56 - textWidth(marker.label, 12) / 2);
|
|
9828
10359
|
elements.push(
|
|
9829
|
-
|
|
9830
|
-
|
|
9831
|
-
|
|
10360
|
+
React15.createElement("line", { key: `marker-line-${marker.id}`, x1: markerX, y1: axisY - 4, x2: markerX, y2: labelY + 7, stroke: color, strokeWidth: densityOf(c).w(1.5), strokeDasharray: "4 4", opacity: 0.8 }),
|
|
10361
|
+
React15.createElement("circle", { key: `marker-point-${marker.id}`, cx: markerX, cy: axisY, r: 7, fill: color, stroke: c.bgCard, strokeWidth: densityOf(c).w(2) }),
|
|
10362
|
+
React15.createElement("text", { key: `marker-label-${marker.id}`, x: labelX, y: labelY, textAnchor: "middle", fill: c.textPrimary, fontFamily: c.fontSans, fontSize: 12, fontWeight: 650 }, marker.label)
|
|
9832
10363
|
);
|
|
9833
10364
|
});
|
|
9834
10365
|
const intervalDescription = interval ? ` The highlighted interval is ${interval.includeFrom === false ? "(" : "["}${formatNumber(interval.from)}, ${formatNumber(interval.to)}${interval.includeTo === false ? ")" : "]"}${interval.label ? `, labeled ${interval.label}` : ""}.` : "";
|
|
@@ -9903,7 +10434,7 @@ function GeometryDiagram({
|
|
|
9903
10434
|
}
|
|
9904
10435
|
if (angle.label !== void 0) labelText(angle.label, `GeometryDiagram angle ${index} label`, 32);
|
|
9905
10436
|
if (angle.radius !== void 0) {
|
|
9906
|
-
|
|
10437
|
+
positive2(angle.radius, `GeometryDiagram angle ${index} radius`);
|
|
9907
10438
|
if (angle.radius > 120) throw new RangeError(`GeometryDiagram angle ${index} radius cannot exceed 120 pixels.`);
|
|
9908
10439
|
}
|
|
9909
10440
|
colorValue(angle.color, c.accent, `GeometryDiagram angle ${index} color`);
|
|
@@ -9933,7 +10464,7 @@ function GeometryDiagram({
|
|
|
9933
10464
|
const from = map(pointById.get(segment.from));
|
|
9934
10465
|
const to = map(pointById.get(segment.to));
|
|
9935
10466
|
const color = colorValue(segment.color, c.secondary, `GeometryDiagram segment ${index} color`);
|
|
9936
|
-
elements.push(
|
|
10467
|
+
elements.push(React15.createElement("line", {
|
|
9937
10468
|
key: `segment-${index}`,
|
|
9938
10469
|
x1: from.x,
|
|
9939
10470
|
y1: from.y,
|
|
@@ -9956,7 +10487,7 @@ function GeometryDiagram({
|
|
|
9956
10487
|
const clearance = 8 + Math.abs(normalX) * halfWidth + Math.abs(normalY) * FONT_SIZE * 0.45;
|
|
9957
10488
|
const labelX = clamp2(midX + normalX * clearance, 24 + halfWidth, width - 24 - halfWidth);
|
|
9958
10489
|
const labelY = clamp2(midY + normalY * clearance + FONT_SIZE * 0.35, 58, height - 22);
|
|
9959
|
-
elements.push(
|
|
10490
|
+
elements.push(React15.createElement("text", { key: `segment-label-${index}`, x: labelX, y: labelY, textAnchor: "middle", fill: c.textSecondary, fontFamily: c.fontSans, fontSize: FONT_SIZE }, segment.label));
|
|
9960
10491
|
}
|
|
9961
10492
|
});
|
|
9962
10493
|
angles.forEach((angle, index) => {
|
|
@@ -9975,17 +10506,17 @@ function GeometryDiagram({
|
|
|
9975
10506
|
});
|
|
9976
10507
|
const path = arc.map((point, part) => `${part === 0 ? "M" : "L"} ${point.x.toFixed(2)} ${point.y.toFixed(2)}`).join(" ");
|
|
9977
10508
|
const color = colorValue(angle.color, c.accent, `GeometryDiagram angle ${index} color`);
|
|
9978
|
-
elements.push(
|
|
10509
|
+
elements.push(React15.createElement("path", { key: `angle-${index}`, d: path, fill: "none", stroke: color, strokeWidth: densityOf(c).w(2.5), strokeLinecap: "round" }));
|
|
9979
10510
|
if (angle.label) {
|
|
9980
10511
|
const middle = a1 + delta / 2;
|
|
9981
10512
|
const labelX = clamp2(v.x + (radius + 18) * Math.cos(middle), 28 + textWidth(angle.label) / 2, width - 28 - textWidth(angle.label) / 2);
|
|
9982
10513
|
const labelY = clamp2(v.y - (radius + 18) * Math.sin(middle) + 4, 58, height - 20);
|
|
9983
|
-
elements.push(
|
|
10514
|
+
elements.push(React15.createElement("text", { key: `angle-label-${index}`, x: labelX, y: labelY, textAnchor: "middle", fill: c.textPrimary, fontFamily: c.fontSans, fontSize: FONT_SIZE, fontWeight: 650 }, angle.label));
|
|
9984
10515
|
}
|
|
9985
10516
|
});
|
|
9986
10517
|
points.forEach((point) => {
|
|
9987
10518
|
const position2 = map(point);
|
|
9988
|
-
elements.push(
|
|
10519
|
+
elements.push(React15.createElement("circle", { key: `point-${point.id}`, cx: position2.x, cy: position2.y, r: 5.5, fill: c.primary, stroke: c.bgCard, strokeWidth: densityOf(c).w(2) }));
|
|
9989
10520
|
if (point.label) {
|
|
9990
10521
|
const label = point.label;
|
|
9991
10522
|
const labelWidth = textWidth(label);
|
|
@@ -9994,7 +10525,7 @@ function GeometryDiagram({
|
|
|
9994
10525
|
const baseX = position2.x + (placeRight ? 12 : -12);
|
|
9995
10526
|
const labelX = boundedTextX(baseX, width, label, placeRight ? "start" : "end");
|
|
9996
10527
|
const labelY = clamp2(awayY > 0 ? position2.y + FONT_SIZE + 6 : position2.y - 10, 58, height - 20);
|
|
9997
|
-
elements.push(
|
|
10528
|
+
elements.push(React15.createElement("text", {
|
|
9998
10529
|
key: `point-label-${point.id}`,
|
|
9999
10530
|
x: labelX,
|
|
10000
10531
|
y: labelY,
|
|
@@ -10054,9 +10585,9 @@ function FreeBodyDiagram({
|
|
|
10054
10585
|
if (!Number.isFinite(scale) || scale <= 0) throw new RangeError("FreeBodyDiagram vector magnitudes cannot be mapped into the viewport.");
|
|
10055
10586
|
const mapVector = (x, y) => ({ x: center2.x + x * scale, y: center2.y - y * scale });
|
|
10056
10587
|
const elements = [
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10588
|
+
React15.createElement("line", { key: "x-axis", x1: center2.x - available - 28, y1: center2.y, x2: center2.x + available + 28, y2: center2.y, stroke: c.borderSubtle, strokeWidth: densityOf(c).w(1.3) }),
|
|
10589
|
+
React15.createElement("line", { key: "y-axis", x1: center2.x, y1: center2.y - available - 28, x2: center2.x, y2: center2.y + available + 28, stroke: c.borderSubtle, strokeWidth: densityOf(c).w(1.3) }),
|
|
10590
|
+
React15.createElement("circle", { key: "body", cx: center2.x, cy: center2.y, r: 6, fill: c.bgCard, stroke: c.textPrimary, strokeWidth: densityOf(c).w(2) })
|
|
10060
10591
|
];
|
|
10061
10592
|
forces.forEach((force) => {
|
|
10062
10593
|
const color = colorValue(force.color, c.secondary, `FreeBodyDiagram force "${force.id}" color`);
|
|
@@ -10064,15 +10595,15 @@ function FreeBodyDiagram({
|
|
|
10064
10595
|
if (showComponents) {
|
|
10065
10596
|
const xEnd = mapVector(force.x, 0);
|
|
10066
10597
|
const yStart = mapVector(force.x, 0);
|
|
10067
|
-
if (force.x !== 0) elements.push(
|
|
10068
|
-
if (force.y !== 0) elements.push(
|
|
10598
|
+
if (force.x !== 0) elements.push(React15.createElement("line", { key: `component-x-${force.id}`, x1: center2.x, y1: center2.y, x2: xEnd.x, y2: xEnd.y, stroke: color, strokeWidth: densityOf(c).w(1.6), strokeDasharray: "5 5", opacity: 0.56 }));
|
|
10599
|
+
if (force.y !== 0) elements.push(React15.createElement("line", { key: `component-y-${force.id}`, x1: yStart.x, y1: yStart.y, x2: end.x, y2: end.y, stroke: color, strokeWidth: densityOf(c).w(1.6), strokeDasharray: "5 5", opacity: 0.56 }));
|
|
10069
10600
|
}
|
|
10070
10601
|
elements.push(arrow(center2, end, color, `force-${force.id}`, 3));
|
|
10071
10602
|
const direction = Math.sign(end.x - center2.x) || 1;
|
|
10072
10603
|
const anchor = direction > 0 ? "start" : "end";
|
|
10073
10604
|
const labelX = boundedTextX(end.x + direction * 12, width, force.label, anchor, 20);
|
|
10074
10605
|
const labelY = clamp2(end.y - 11, 60, height - 20);
|
|
10075
|
-
elements.push(
|
|
10606
|
+
elements.push(React15.createElement("text", { key: `force-label-${force.id}`, x: labelX, y: labelY, textAnchor: anchor, fill: c.textPrimary, fontFamily: c.fontSans, fontSize: FONT_SIZE, fontWeight: 650 }, force.label));
|
|
10076
10607
|
});
|
|
10077
10608
|
if (showResultant && (resultant.x !== 0 || resultant.y !== 0)) {
|
|
10078
10609
|
const end = mapVector(resultant.x, resultant.y);
|
|
@@ -10080,7 +10611,7 @@ function FreeBodyDiagram({
|
|
|
10080
10611
|
const label = `R = ${formatNumber(resultant.magnitude)}`;
|
|
10081
10612
|
const direction = Math.sign(end.x - center2.x) || 1;
|
|
10082
10613
|
const anchor = direction > 0 ? "start" : "end";
|
|
10083
|
-
elements.push(
|
|
10614
|
+
elements.push(React15.createElement("text", {
|
|
10084
10615
|
key: "resultant-label",
|
|
10085
10616
|
x: boundedTextX(end.x + direction * 12, width, label, anchor, 20),
|
|
10086
10617
|
y: clamp2(end.y + 20, 60, height - 20),
|
|
@@ -10091,11 +10622,11 @@ function FreeBodyDiagram({
|
|
|
10091
10622
|
fontWeight: 700
|
|
10092
10623
|
}, label));
|
|
10093
10624
|
} else if (showResultant) {
|
|
10094
|
-
elements.push(
|
|
10625
|
+
elements.push(React15.createElement("text", { key: "zero-resultant", x: center2.x + 38, y: center2.y + 38, fill: c.textPrimary, fontFamily: c.fontSans, fontSize: FONT_SIZE, fontWeight: 700 }, "R = 0"));
|
|
10095
10626
|
}
|
|
10096
10627
|
elements.push(
|
|
10097
|
-
|
|
10098
|
-
|
|
10628
|
+
React15.createElement("text", { key: "positive-x", x: width - 42, y: center2.y - 8, textAnchor: "end", fill: c.textSecondary, fontFamily: c.fontMono, fontSize: 12 }, "+x"),
|
|
10629
|
+
React15.createElement("text", { key: "positive-y", x: center2.x - 12, y: 72, textAnchor: "end", fill: c.textSecondary, fontFamily: c.fontMono, fontSize: 12 }, "+y")
|
|
10099
10630
|
);
|
|
10100
10631
|
return svgShell({ c, width, height, title, ariaLabel, description: `${forces.length} physical force vectors use one scale. The resultant is the vector sum ${formatNumber(resultant.x)} x plus ${formatNumber(resultant.y)} y. The vertical axis points upward in physical coordinates.`, children: elements });
|
|
10101
10632
|
}
|
|
@@ -10107,20 +10638,20 @@ function arrow(start, end, color, key, strokeWidth) {
|
|
|
10107
10638
|
const angle = Math.atan2(dy, dx);
|
|
10108
10639
|
const left = { x: end.x - head * Math.cos(angle - Math.PI / 6), y: end.y - head * Math.sin(angle - Math.PI / 6) };
|
|
10109
10640
|
const right = { x: end.x - head * Math.cos(angle + Math.PI / 6), y: end.y - head * Math.sin(angle + Math.PI / 6) };
|
|
10110
|
-
return
|
|
10641
|
+
return React15.createElement(
|
|
10111
10642
|
"g",
|
|
10112
10643
|
{
|
|
10113
10644
|
key,
|
|
10114
10645
|
"data-vector-role": key === "resultant" ? "resultant" : "force",
|
|
10115
10646
|
"data-vector-id": key.startsWith("force-") ? key.slice("force-".length) : void 0
|
|
10116
10647
|
},
|
|
10117
|
-
|
|
10118
|
-
|
|
10648
|
+
React15.createElement("line", { x1: start.x, y1: start.y, x2: end.x, y2: end.y, stroke: color, strokeWidth, strokeLinecap: "round" }),
|
|
10649
|
+
React15.createElement("path", { d: `M ${left.x} ${left.y} L ${end.x} ${end.y} L ${right.x} ${right.y}`, fill: "none", stroke: color, strokeWidth, strokeLinecap: "round", strokeLinejoin: "round" })
|
|
10119
10650
|
);
|
|
10120
10651
|
}
|
|
10121
10652
|
function validateWave(wave, index, c) {
|
|
10122
|
-
|
|
10123
|
-
|
|
10653
|
+
positive2(wave.amplitude, `WaveDiagram wave ${index} amplitude`);
|
|
10654
|
+
positive2(wave.wavelength, `WaveDiagram wave ${index} wavelength`);
|
|
10124
10655
|
finite(wave.phase ?? 0, `WaveDiagram wave ${index} phase`);
|
|
10125
10656
|
finite(wave.speed ?? 0, `WaveDiagram wave ${index} speed`);
|
|
10126
10657
|
if (wave.label !== void 0) labelText(wave.label, `WaveDiagram wave ${index} label`, 22);
|
|
@@ -10215,28 +10746,28 @@ function WaveDiagram({
|
|
|
10215
10746
|
const gridX = sx(xValue);
|
|
10216
10747
|
const gridY = sy(yValue);
|
|
10217
10748
|
elements.push(
|
|
10218
|
-
|
|
10219
|
-
|
|
10220
|
-
|
|
10221
|
-
|
|
10749
|
+
React15.createElement("line", { key: `grid-x-${index}`, x1: gridX, y1: plot.top, x2: gridX, y2: plot.bottom, stroke: c.borderSubtle, strokeWidth: densityOf(c).w(1) }),
|
|
10750
|
+
React15.createElement("line", { key: `grid-y-${index}`, x1: plot.left, y1: gridY, x2: plot.right, y2: gridY, stroke: c.borderSubtle, strokeWidth: densityOf(c).w(1) }),
|
|
10751
|
+
React15.createElement("text", { key: `x-label-${index}`, x: gridX, y: plot.bottom + 22, textAnchor: "middle", fill: c.textSecondary, fontFamily: c.fontMono, fontSize: 11 }, formatNumber(xValue)),
|
|
10752
|
+
React15.createElement("text", { key: `y-label-${index}`, x: plot.left - 10, y: gridY + 4, textAnchor: "end", fill: c.textSecondary, fontFamily: c.fontMono, fontSize: 11 }, formatNumber(yValue))
|
|
10222
10753
|
);
|
|
10223
10754
|
}
|
|
10224
10755
|
elements.push(
|
|
10225
|
-
|
|
10226
|
-
|
|
10227
|
-
|
|
10228
|
-
|
|
10229
|
-
|
|
10756
|
+
React15.createElement("line", { key: "x-axis", x1: plot.left, y1: sy(0), x2: plot.right, y2: sy(0), stroke: c.textSecondary, strokeWidth: densityOf(c).w(1.7) }),
|
|
10757
|
+
React15.createElement("line", { key: "y-axis", x1: plot.left, y1: plot.top, x2: plot.left, y2: plot.bottom, stroke: c.textSecondary, strokeWidth: densityOf(c).w(1.7) }),
|
|
10758
|
+
React15.createElement("text", { key: "axis-x-label", x: plot.right, y: height - 18, textAnchor: "end", fill: c.textSecondary, fontFamily: c.fontSans, fontSize: 12 }, "position x"),
|
|
10759
|
+
React15.createElement("text", { key: "axis-y-label", x: plot.left + 8, y: plot.top - 9, fill: c.textSecondary, fontFamily: c.fontSans, fontSize: 12 }, "displacement y"),
|
|
10760
|
+
React15.createElement("text", { key: "time-label", x: 24, y: 60, fill: c.textSecondary, fontFamily: c.fontMono, fontSize: 12 }, `t = ${formatNumber(time)}`)
|
|
10230
10761
|
);
|
|
10231
10762
|
const pathFor = (points) => points.map((point, index) => `${index === 0 ? "M" : "L"} ${sx(point.x).toFixed(2)} ${sy(point.y).toFixed(2)}`).join(" ");
|
|
10232
10763
|
if (showComponents) {
|
|
10233
10764
|
samples.forEach((waveSamples, index) => {
|
|
10234
10765
|
const wave = waves[index];
|
|
10235
10766
|
const color = colorValue(wave.color, c.secondary, `WaveDiagram wave ${index} color`);
|
|
10236
|
-
elements.push(
|
|
10767
|
+
elements.push(React15.createElement("path", { key: `component-${index}`, d: pathFor(waveSamples), fill: "none", stroke: color, strokeWidth: densityOf(c).w(2), opacity: showSum ? 0.68 : 1, strokeLinecap: "round", strokeLinejoin: "round" }));
|
|
10237
10768
|
});
|
|
10238
10769
|
}
|
|
10239
|
-
if (showSum) elements.push(
|
|
10770
|
+
if (showSum) elements.push(React15.createElement("path", { key: "sum", d: pathFor(sumSamples), fill: "none", stroke: c.textPrimary, strokeWidth: densityOf(c).w(3.5), strokeLinecap: "round", strokeLinejoin: "round" }));
|
|
10240
10771
|
waves.forEach((wave, index) => {
|
|
10241
10772
|
const label = wave.label ?? `wave ${index + 1}`;
|
|
10242
10773
|
const color = colorValue(wave.color, c.secondary, `WaveDiagram wave ${index} color`);
|
|
@@ -10244,7 +10775,7 @@ function WaveDiagram({
|
|
|
10244
10775
|
const row = index % 4;
|
|
10245
10776
|
const legendX = plot.left + column * (plot.right - plot.left) / 2;
|
|
10246
10777
|
const legendY = plot.top - 58 + row * 14;
|
|
10247
|
-
elements.push(
|
|
10778
|
+
elements.push(React15.createElement("line", {
|
|
10248
10779
|
key: `legend-swatch-${index}`,
|
|
10249
10780
|
x1: legendX,
|
|
10250
10781
|
y1: legendY - 4,
|
|
@@ -10254,7 +10785,7 @@ function WaveDiagram({
|
|
|
10254
10785
|
strokeWidth: densityOf(c).w(3),
|
|
10255
10786
|
strokeLinecap: "round"
|
|
10256
10787
|
}));
|
|
10257
|
-
elements.push(
|
|
10788
|
+
elements.push(React15.createElement("text", {
|
|
10258
10789
|
key: `legend-${index}`,
|
|
10259
10790
|
x: boundedTextX(legendX + 16, width, label, "start", 20, 11),
|
|
10260
10791
|
y: legendY,
|
|
@@ -10264,15 +10795,15 @@ function WaveDiagram({
|
|
|
10264
10795
|
fontWeight: 650
|
|
10265
10796
|
}, label));
|
|
10266
10797
|
});
|
|
10267
|
-
if (showSum) elements.push(
|
|
10798
|
+
if (showSum) elements.push(React15.createElement("text", { key: "sum-legend", x: width - 24, y: 60, textAnchor: "end", fill: c.textPrimary, fontFamily: c.fontSans, fontSize: 12, fontWeight: 750 }, "sum"));
|
|
10268
10799
|
if (probeX !== void 0) {
|
|
10269
10800
|
const probeY = waves.reduce((sum, wave) => sum + waveValue(wave, probeX, time), 0);
|
|
10270
10801
|
const probePosition = { x: sx(probeX), y: sy(probeY) };
|
|
10271
10802
|
const label = `\u03A3y = ${formatNumber(probeY)}`;
|
|
10272
10803
|
elements.push(
|
|
10273
|
-
|
|
10274
|
-
|
|
10275
|
-
|
|
10804
|
+
React15.createElement("line", { key: "probe-line", x1: probePosition.x, y1: plot.top, x2: probePosition.x, y2: plot.bottom, stroke: c.warning, strokeWidth: densityOf(c).w(1.5), strokeDasharray: "5 5" }),
|
|
10805
|
+
React15.createElement("circle", { key: "probe-point", cx: probePosition.x, cy: probePosition.y, r: 6, fill: c.warning, stroke: c.bgCard, strokeWidth: densityOf(c).w(2) }),
|
|
10806
|
+
React15.createElement("text", { key: "probe-label", x: clamp2(probePosition.x + 10, plot.left + 8, plot.right - textWidth(label)), y: clamp2(probePosition.y - 12, plot.top + 40, plot.bottom - 10), fill: c.textPrimary, fontFamily: c.fontSans, fontSize: 12, fontWeight: 650 }, label)
|
|
10276
10807
|
);
|
|
10277
10808
|
}
|
|
10278
10809
|
const summary = waves.map((wave, index) => `${wave.label ?? `wave ${index + 1}`} (A=${formatNumber(wave.amplitude)}, \u03BB=${formatNumber(wave.wavelength)}, \u03C6=${formatNumber(wave.phase ?? 0)}, v=${formatNumber(wave.speed ?? 0)})`).join("; ");
|
|
@@ -10280,9 +10811,9 @@ function WaveDiagram({
|
|
|
10280
10811
|
}
|
|
10281
10812
|
|
|
10282
10813
|
// src/primitives/science-chemistry.ts
|
|
10283
|
-
import
|
|
10814
|
+
import React16 from "react";
|
|
10284
10815
|
function overlayText(key, props) {
|
|
10285
|
-
return
|
|
10816
|
+
return React16.createElement(React16.Fragment, { key }, SvgMathText(props));
|
|
10286
10817
|
}
|
|
10287
10818
|
var ELEMENTS = /* @__PURE__ */ new Set([
|
|
10288
10819
|
"H",
|
|
@@ -10534,7 +11065,7 @@ function MoleculeDiagram({
|
|
|
10534
11065
|
const bondNodes = bonds.flatMap((bond, bondIndex) => {
|
|
10535
11066
|
const from = points.get(bond.from);
|
|
10536
11067
|
const to = points.get(bond.to);
|
|
10537
|
-
return bondSegments(from, to, bond.order).map((segment, segmentIndex) =>
|
|
11068
|
+
return bondSegments(from, to, bond.order).map((segment, segmentIndex) => React16.createElement("line", {
|
|
10538
11069
|
key: `bond-${bondIndex}-${segmentIndex}`,
|
|
10539
11070
|
x1: segment.x1,
|
|
10540
11071
|
y1: segment.y1,
|
|
@@ -10554,10 +11085,10 @@ function MoleculeDiagram({
|
|
|
10554
11085
|
const atomNodes = atoms.map((atom) => {
|
|
10555
11086
|
const point = points.get(atom.id);
|
|
10556
11087
|
const accent = atomColor(atom.element, c);
|
|
10557
|
-
return
|
|
11088
|
+
return React16.createElement(
|
|
10558
11089
|
"g",
|
|
10559
11090
|
{ key: atom.id, "data-atom-id": atom.id, "data-element": atom.element },
|
|
10560
|
-
|
|
11091
|
+
React16.createElement("circle", { cx: point.x, cy: point.y, r: 19, fill: c.bgCard, stroke: accent, strokeWidth: densityOf(c).w(2) })
|
|
10561
11092
|
);
|
|
10562
11093
|
});
|
|
10563
11094
|
const textNodes = atoms.flatMap((atom) => {
|
|
@@ -10570,7 +11101,7 @@ function MoleculeDiagram({
|
|
|
10570
11101
|
...atom.label ? [overlayText(`atom-${atom.id}-label`, { text: atom.label, x: point.x, y: labelY, fill: c.textSecondary, fontSize: densityOf(c).f(10), fontFamily: c.fontSans, textAnchor: "middle" })] : []
|
|
10571
11102
|
];
|
|
10572
11103
|
});
|
|
10573
|
-
const geometry =
|
|
11104
|
+
const geometry = React16.createElement(
|
|
10574
11105
|
"svg",
|
|
10575
11106
|
{
|
|
10576
11107
|
width: svgWidth,
|
|
@@ -10579,11 +11110,11 @@ function MoleculeDiagram({
|
|
|
10579
11110
|
"aria-hidden": true,
|
|
10580
11111
|
style: { position: "absolute", left: 0, top: 0, display: "block" }
|
|
10581
11112
|
},
|
|
10582
|
-
|
|
11113
|
+
React16.createElement("rect", { x: 0, y: 0, width: svgWidth, height: svgHeight, rx: 14, fill: c.bgCard, stroke: c.borderSubtle }),
|
|
10583
11114
|
...bondNodes,
|
|
10584
11115
|
...atomNodes
|
|
10585
11116
|
);
|
|
10586
|
-
return
|
|
11117
|
+
return React16.createElement(
|
|
10587
11118
|
"div",
|
|
10588
11119
|
{
|
|
10589
11120
|
role: "img",
|
|
@@ -10672,7 +11203,7 @@ function reactionBalance(reactants, products) {
|
|
|
10672
11203
|
return { status: balanced ? "balanced" : "unbalanced", balanced, elementDeltas: deltas, chargeDelta };
|
|
10673
11204
|
}
|
|
10674
11205
|
function equationTerm(term, index, c) {
|
|
10675
|
-
return
|
|
11206
|
+
return React16.createElement(
|
|
10676
11207
|
"span",
|
|
10677
11208
|
{
|
|
10678
11209
|
key: `term-${index}-${term.formula}`,
|
|
@@ -10686,22 +11217,22 @@ function equationTerm(term, index, c) {
|
|
|
10686
11217
|
color: c.textPrimary
|
|
10687
11218
|
}
|
|
10688
11219
|
},
|
|
10689
|
-
term.coefficient && term.coefficient !== 1 ?
|
|
10690
|
-
|
|
10691
|
-
term.state ?
|
|
11220
|
+
term.coefficient && term.coefficient !== 1 ? React16.createElement("span", { style: { color: getReadableColor("primary", c), fontWeight: 700, marginRight: 5 } }, `${term.coefficient}`) : null,
|
|
11221
|
+
React16.createElement("span", { style: { overflowWrap: "anywhere" } }, term.formula),
|
|
11222
|
+
term.state ? React16.createElement("span", { style: { marginLeft: 5, color: c.textSecondary, fontSize: "0.9em" } }, `(${term.state})`) : null
|
|
10692
11223
|
);
|
|
10693
11224
|
}
|
|
10694
11225
|
function equationSide(terms, label, c) {
|
|
10695
11226
|
const children = [];
|
|
10696
11227
|
terms.forEach((term, index) => {
|
|
10697
|
-
if (index > 0) children.push(
|
|
11228
|
+
if (index > 0) children.push(React16.createElement("span", {
|
|
10698
11229
|
key: `plus-${index}`,
|
|
10699
11230
|
style: { color: c.textSecondary, padding: "0 7px", flex: "0 0 auto" },
|
|
10700
11231
|
"aria-hidden": true
|
|
10701
11232
|
}, "+"));
|
|
10702
11233
|
children.push(equationTerm(term, index, c));
|
|
10703
11234
|
});
|
|
10704
|
-
return
|
|
11235
|
+
return React16.createElement("div", {
|
|
10705
11236
|
role: "group",
|
|
10706
11237
|
"aria-label": label,
|
|
10707
11238
|
style: {
|
|
@@ -10733,7 +11264,7 @@ function ReactionEquation({
|
|
|
10733
11264
|
const balance = reactionBalance(reactants, products);
|
|
10734
11265
|
const accessibleEquation = `${reactants.map((term) => `${term.coefficient && term.coefficient !== 1 ? `${term.coefficient} ` : ""}${term.formula}${term.state ? ` (${term.state})` : ""}`).join(" + ")} ${reversible ? "reversibly yields" : "yields"} ${products.map((term) => `${term.coefficient && term.coefficient !== 1 ? `${term.coefficient} ` : ""}${term.formula}${term.state ? ` (${term.state})` : ""}`).join(" + ")}`;
|
|
10735
11266
|
const balanceText = balance.status === "unavailable" ? "Balance unavailable: provide a complete composition map for every term." : balance.balanced ? "Balanced by supplied composition and charge." : `Not balanced by supplied composition and charge: ${Object.entries(balance.elementDeltas).filter(([, delta]) => delta !== 0).map(([element, delta]) => `${element} ${delta > 0 ? "+" : ""}${delta}`).join(", ") || "elements conserved"}, charge ${balance.chargeDelta > 0 ? "+" : ""}${balance.chargeDelta}.`;
|
|
10736
|
-
return
|
|
11267
|
+
return React16.createElement(
|
|
10737
11268
|
"div",
|
|
10738
11269
|
{
|
|
10739
11270
|
role: "img",
|
|
@@ -10754,20 +11285,20 @@ function ReactionEquation({
|
|
|
10754
11285
|
fontFamily: c.fontSans
|
|
10755
11286
|
}
|
|
10756
11287
|
},
|
|
10757
|
-
|
|
11288
|
+
React16.createElement(
|
|
10758
11289
|
"div",
|
|
10759
11290
|
{
|
|
10760
11291
|
style: { display: "flex", alignItems: "center", gap: 12, minWidth: 0 }
|
|
10761
11292
|
},
|
|
10762
11293
|
equationSide(reactants, "Reactants", c),
|
|
10763
|
-
|
|
11294
|
+
React16.createElement("span", {
|
|
10764
11295
|
style: { flex: "0 0 auto", color: c.primaryLight, fontSize: densityOf(c).f(26), fontWeight: 700, padding: "0 2px" },
|
|
10765
11296
|
"aria-hidden": true
|
|
10766
11297
|
}, reversible ? "\u21CC" : "\u2192"),
|
|
10767
11298
|
equationSide(products, "Products", c)
|
|
10768
11299
|
),
|
|
10769
|
-
conditions !== void 0 && conditions.length > 0 ?
|
|
10770
|
-
|
|
11300
|
+
conditions !== void 0 && conditions.length > 0 ? React16.createElement("div", { style: { color: c.textSecondary, fontSize: densityOf(c).f(13) } }, `Conditions: ${conditions}`) : null,
|
|
11301
|
+
React16.createElement("div", {
|
|
10771
11302
|
style: {
|
|
10772
11303
|
paddingTop: 8,
|
|
10773
11304
|
borderTop: `1px solid ${c.borderSubtle}`,
|
|
@@ -10803,12 +11334,12 @@ function measurement(x, y1, y2, color, key, label) {
|
|
|
10803
11334
|
const top = Math.min(y1, y2);
|
|
10804
11335
|
const bottom = Math.max(y1, y2);
|
|
10805
11336
|
const cap = 5;
|
|
10806
|
-
return
|
|
11337
|
+
return React16.createElement(
|
|
10807
11338
|
"g",
|
|
10808
11339
|
{ key, "data-measurement": label, "aria-hidden": true },
|
|
10809
|
-
|
|
10810
|
-
|
|
10811
|
-
|
|
11340
|
+
React16.createElement("line", { x1: x, y1: top, x2: x, y2: bottom, stroke: color, strokeWidth: densityOf().w(1.5), strokeDasharray: "3 3" }),
|
|
11341
|
+
React16.createElement("line", { x1: x - cap, y1: top, x2: x + cap, y2: top, stroke: color, strokeWidth: densityOf().w(1.5) }),
|
|
11342
|
+
React16.createElement("line", { x1: x - cap, y1: bottom, x2: x + cap, y2: bottom, stroke: color, strokeWidth: densityOf().w(1.5) })
|
|
10812
11343
|
);
|
|
10813
11344
|
}
|
|
10814
11345
|
function ReactionEnergyDiagram({
|
|
@@ -10889,19 +11420,19 @@ function ReactionEnergyDiagram({
|
|
|
10889
11420
|
const revealWidth = progress === 0 ? 0 : (x1 - x0) * progress + 8;
|
|
10890
11421
|
const gridValues = [scaleMin, (scaleMin + scaleMax) / 2, scaleMax];
|
|
10891
11422
|
const svgNodes = [
|
|
10892
|
-
|
|
10893
|
-
|
|
11423
|
+
React16.createElement("rect", { key: "background", x: 0, y: 0, width: svgWidth, height: svgHeight, rx: 14, fill: c.bgCard, stroke: c.borderSubtle }),
|
|
11424
|
+
React16.createElement(
|
|
10894
11425
|
"defs",
|
|
10895
11426
|
{ key: "reveal-defs" },
|
|
10896
|
-
|
|
11427
|
+
React16.createElement(
|
|
10897
11428
|
"clipPath",
|
|
10898
11429
|
{ id: revealClipId, clipPathUnits: "userSpaceOnUse" },
|
|
10899
|
-
|
|
11430
|
+
React16.createElement("rect", { x: x0 - 4, y: plotTop, width: revealWidth, height: plotBottom - plotTop })
|
|
10900
11431
|
)
|
|
10901
11432
|
),
|
|
10902
|
-
|
|
10903
|
-
|
|
10904
|
-
...gridValues.map((value, index) =>
|
|
11433
|
+
React16.createElement("line", { key: "y-axis", x1: plotLeft, y1: plotTop, x2: plotLeft, y2: plotBottom, stroke: c.borderLight, strokeWidth: densityOf(c).w(1.4) }),
|
|
11434
|
+
React16.createElement("line", { key: "x-axis", x1: plotLeft, y1: plotBottom, x2: plotRight, y2: plotBottom, stroke: c.borderLight, strokeWidth: densityOf(c).w(1.4) }),
|
|
11435
|
+
...gridValues.map((value, index) => React16.createElement("line", {
|
|
10905
11436
|
key: `grid-${index}`,
|
|
10906
11437
|
x1: plotLeft,
|
|
10907
11438
|
y1: yFor(value),
|
|
@@ -10911,7 +11442,7 @@ function ReactionEnergyDiagram({
|
|
|
10911
11442
|
strokeWidth: densityOf(c).w(1),
|
|
10912
11443
|
strokeDasharray: "3 5"
|
|
10913
11444
|
})),
|
|
10914
|
-
|
|
11445
|
+
React16.createElement("path", {
|
|
10915
11446
|
key: "uncatalyzed-path",
|
|
10916
11447
|
d: path,
|
|
10917
11448
|
fill: "none",
|
|
@@ -10923,7 +11454,7 @@ function ReactionEnergyDiagram({
|
|
|
10923
11454
|
"data-energy-path": "uncatalyzed",
|
|
10924
11455
|
"data-progress": progress
|
|
10925
11456
|
}),
|
|
10926
|
-
catalyzedPath === void 0 ? null :
|
|
11457
|
+
catalyzedPath === void 0 ? null : React16.createElement("path", {
|
|
10927
11458
|
key: "catalyzed-path",
|
|
10928
11459
|
d: catalyzedPath,
|
|
10929
11460
|
fill: "none",
|
|
@@ -10941,7 +11472,7 @@ function ReactionEnergyDiagram({
|
|
|
10941
11472
|
];
|
|
10942
11473
|
const overlayNodes = [
|
|
10943
11474
|
overlayText("title", { text: `${chartTitle} \xB7 ${unit}`, x: svgWidth / 2, y: 24, fill: c.textPrimary, fontSize: densityOf(c).f(16), fontFamily: c.fontSans, fontWeight: 700 }),
|
|
10944
|
-
|
|
11475
|
+
React16.createElement("div", {
|
|
10945
11476
|
key: "energy-label",
|
|
10946
11477
|
style: {
|
|
10947
11478
|
position: "absolute",
|
|
@@ -10963,7 +11494,7 @@ function ReactionEnergyDiagram({
|
|
|
10963
11494
|
...catalyzedActivation === void 0 ? [] : [overlayText("catalyzed-activation-value", { text: `Ea (catalyzed) = ${energyText(catalyzedActivation)} ${unit}`, x: svgWidth / 2, y: svgHeight - 39, fill: getReadableColor("positive", c), fontSize: densityOf(c).f(12), fontFamily: c.fontSans })],
|
|
10964
11495
|
overlayText("delta-value", { text: `\u0394E = ${signedEnergyText(delta)} ${unit}`, x: svgWidth / 2, y: svgHeight - 21, fill: getReadableColor("secondary", c), fontSize: densityOf(c).f(12), fontFamily: c.fontSans })
|
|
10965
11496
|
];
|
|
10966
|
-
const geometry =
|
|
11497
|
+
const geometry = React16.createElement(
|
|
10967
11498
|
"svg",
|
|
10968
11499
|
{
|
|
10969
11500
|
width: svgWidth,
|
|
@@ -10974,7 +11505,7 @@ function ReactionEnergyDiagram({
|
|
|
10974
11505
|
},
|
|
10975
11506
|
...svgNodes
|
|
10976
11507
|
);
|
|
10977
|
-
return
|
|
11508
|
+
return React16.createElement("div", {
|
|
10978
11509
|
role: "img",
|
|
10979
11510
|
"aria-label": ariaLabel ?? `${chartTitle} (${unit})`,
|
|
10980
11511
|
"aria-description": desc,
|
|
@@ -10985,7 +11516,7 @@ function ReactionEnergyDiagram({
|
|
|
10985
11516
|
}
|
|
10986
11517
|
|
|
10987
11518
|
// src/primitives/science-ai.ts
|
|
10988
|
-
import
|
|
11519
|
+
import React17 from "react";
|
|
10989
11520
|
|
|
10990
11521
|
// src/teaching-math.ts
|
|
10991
11522
|
function finite2(value, name) {
|
|
@@ -11200,11 +11731,11 @@ function AttentionMatrix({
|
|
|
11200
11731
|
const text = (key, value, x, y, size = 14, fill = c.textPrimary, anchor = "middle", background) => {
|
|
11201
11732
|
const label = SvgMathText({ text: value, x, y, fill, fontSize: size, fontFamily: c.fontSans, fontWeight: 500, textAnchor: anchor, dominantBaseline: "alphabetic" });
|
|
11202
11733
|
const style = label.props.style;
|
|
11203
|
-
return
|
|
11734
|
+
return React17.cloneElement(label, { key, ...background ? { style: { ...style, backgroundColor: background } } : {} });
|
|
11204
11735
|
};
|
|
11205
11736
|
const marks = [
|
|
11206
|
-
|
|
11207
|
-
|
|
11737
|
+
React17.createElement("title", { key: "title" }, title),
|
|
11738
|
+
React17.createElement("desc", { key: "description" }, "Rows are queries and columns are keys. Visible rows sum to one. Crosses denote masked keys. Values are attention probabilities, not explanations of model reasoning."),
|
|
11208
11739
|
text("heading", title, 22, 30, 20, c.textPrimary, "start"),
|
|
11209
11740
|
text("keys", "KEYS", left + (width - left - right) / 2, 58, 12, c.textSecondary),
|
|
11210
11741
|
text("query-heading", "QUERY", 22, 81, 12, c.textSecondary, "start"),
|
|
@@ -11219,7 +11750,7 @@ function AttentionMatrix({
|
|
|
11219
11750
|
const masked = mask?.[i][j] === false;
|
|
11220
11751
|
const selected = activeQuery === i && (activeKey === void 0 || activeKey === j);
|
|
11221
11752
|
const fill = masked ? c.bgCardAlt : compositeColor(withColorAlpha(c.primary, 0.12 + 0.88 * weight), c.bg);
|
|
11222
|
-
marks.push(
|
|
11753
|
+
marks.push(React17.createElement("rect", {
|
|
11223
11754
|
key: `cell-${i}-${j}`,
|
|
11224
11755
|
x: x + 2,
|
|
11225
11756
|
y: y + 2,
|
|
@@ -11232,7 +11763,7 @@ function AttentionMatrix({
|
|
|
11232
11763
|
}));
|
|
11233
11764
|
if (masked) {
|
|
11234
11765
|
const centerX = x + cellWidth / 2, centerY = y + cellHeight / 2;
|
|
11235
|
-
marks.push(
|
|
11766
|
+
marks.push(React17.createElement("path", { key: `mask-${i}-${j}`, d: `M${centerX - 4},${centerY - 4}l8,8m-8,0l8,-8`, stroke: c.textMuted, strokeWidth: 1.4 }));
|
|
11236
11767
|
} else {
|
|
11237
11768
|
const label = weight.toFixed(2);
|
|
11238
11769
|
if (cellWidth >= 38 && cellHeight >= 24) marks.push(text(`value-${i}-${j}`, label, x + cellWidth / 2, y + cellHeight / 2 + 5, 14, getReadableTextColor(fill, c, c.bg), "middle", fill));
|
|
@@ -11242,11 +11773,11 @@ function AttentionMatrix({
|
|
|
11242
11773
|
marks.push(text(`sum-${i}`, total.toFixed(0), width - 30, y + cellHeight / 2 + 5, 14, c.textSecondary));
|
|
11243
11774
|
});
|
|
11244
11775
|
marks.push(text("footer", "Probability per query \xB7 \xD7 masked \xB7 shared color scale 0\u20131", 22, height - 22, 13, c.textSecondary, "start"));
|
|
11245
|
-
const isLabel = (node) =>
|
|
11246
|
-
return
|
|
11776
|
+
const isLabel = (node) => React17.isValidElement(node) && node.type === "div";
|
|
11777
|
+
return React17.createElement(
|
|
11247
11778
|
"div",
|
|
11248
11779
|
{ role: "img", "aria-label": title, style: { position: "relative", display: "flex", width, height, backgroundColor: c.bg, flexShrink: 0 } },
|
|
11249
|
-
|
|
11780
|
+
React17.createElement("svg", { width, height, viewBox: `0 0 ${width} ${height}` }, ...marks.filter((node) => !isLabel(node))),
|
|
11250
11781
|
...marks.filter(isLabel)
|
|
11251
11782
|
);
|
|
11252
11783
|
}
|
|
@@ -11279,7 +11810,7 @@ function transposeMatrix(matrix) {
|
|
|
11279
11810
|
}
|
|
11280
11811
|
|
|
11281
11812
|
// src/primitives/image-tensor.ts
|
|
11282
|
-
import
|
|
11813
|
+
import React18 from "react";
|
|
11283
11814
|
var MAX_IMAGE_AXIS = 128;
|
|
11284
11815
|
var MAX_IMAGE_PIXELS = 1024;
|
|
11285
11816
|
var MAX_COMPONENT_SIZE = 32768;
|
|
@@ -11388,7 +11919,7 @@ function PixelGrid({
|
|
|
11388
11919
|
const rgb = channel === "red" ? [pixel[0], 0, 0] : channel === "green" ? [0, pixel[1], 0] : channel === "blue" ? [0, 0, pixel[2]] : pixel;
|
|
11389
11920
|
return `rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`;
|
|
11390
11921
|
};
|
|
11391
|
-
const cells = pixels.flatMap((row, rowIndex) => row.map((pixel, columnIndex) =>
|
|
11922
|
+
const cells = pixels.flatMap((row, rowIndex) => row.map((pixel, columnIndex) => React18.createElement("rect", {
|
|
11392
11923
|
key: `pixel-${rowIndex}-${columnIndex}`,
|
|
11393
11924
|
x: offsetX + columnIndex * pixelSize,
|
|
11394
11925
|
y: offsetY + rowIndex * pixelSize,
|
|
@@ -11399,7 +11930,7 @@ function PixelGrid({
|
|
|
11399
11930
|
const strokeWidth = pixelSize * 0.16;
|
|
11400
11931
|
const marks = [...cells];
|
|
11401
11932
|
if (region) {
|
|
11402
|
-
marks.push(
|
|
11933
|
+
marks.push(React18.createElement("rect", {
|
|
11403
11934
|
key: "region-highlight",
|
|
11404
11935
|
x: offsetX + region.column * pixelSize + strokeWidth / 2,
|
|
11405
11936
|
y: offsetY + region.row * pixelSize + strokeWidth / 2,
|
|
@@ -11412,7 +11943,7 @@ function PixelGrid({
|
|
|
11412
11943
|
}));
|
|
11413
11944
|
}
|
|
11414
11945
|
if (activeCell) {
|
|
11415
|
-
marks.push(
|
|
11946
|
+
marks.push(React18.createElement("rect", {
|
|
11416
11947
|
key: "active-cell-highlight",
|
|
11417
11948
|
x: offsetX + activeCell.column * pixelSize + strokeWidth / 2,
|
|
11418
11949
|
y: offsetY + activeCell.row * pixelSize + strokeWidth / 2,
|
|
@@ -11424,11 +11955,11 @@ function PixelGrid({
|
|
|
11424
11955
|
}));
|
|
11425
11956
|
}
|
|
11426
11957
|
const channelLabel = channel === "rgb" ? "RGB" : `${channel} channel`;
|
|
11427
|
-
return
|
|
11958
|
+
return React18.createElement("div", {
|
|
11428
11959
|
role: "img",
|
|
11429
11960
|
"aria-label": `${shape.rows} by ${shape.columns} pixel image, ${channelLabel}`,
|
|
11430
11961
|
style: { position: "relative", display: "flex", width, height, backgroundColor: c.bgCard, flexShrink: 0 }
|
|
11431
|
-
},
|
|
11962
|
+
}, React18.createElement("svg", {
|
|
11432
11963
|
width,
|
|
11433
11964
|
height,
|
|
11434
11965
|
viewBox: `0 0 ${width} ${height}`,
|
|
@@ -12296,7 +12827,7 @@ function nonnegative(value, name) {
|
|
|
12296
12827
|
finite3(value, name);
|
|
12297
12828
|
if (value < 0) throw new Error(`${name} must be nonnegative`);
|
|
12298
12829
|
}
|
|
12299
|
-
function
|
|
12830
|
+
function positive3(value, name) {
|
|
12300
12831
|
finite3(value, name);
|
|
12301
12832
|
if (value <= 0) throw new Error(`${name} must be positive`);
|
|
12302
12833
|
}
|
|
@@ -12307,17 +12838,17 @@ function normalizedOpacity(value, name = "Canvas opacity") {
|
|
|
12307
12838
|
function validateBounds(bounds4) {
|
|
12308
12839
|
finite3(bounds4.x, "Canvas x");
|
|
12309
12840
|
finite3(bounds4.y, "Canvas y");
|
|
12310
|
-
|
|
12311
|
-
|
|
12841
|
+
positive3(bounds4.width, "Canvas width");
|
|
12842
|
+
positive3(bounds4.height, "Canvas height");
|
|
12312
12843
|
nonnegative(bounds4.radius ?? 14, "Canvas radius");
|
|
12313
12844
|
}
|
|
12314
12845
|
function layoutTokenRow(values, options = {}) {
|
|
12315
12846
|
const { advance = 24, gap = 16, minWidth = 64, paddingX = 17, width } = options;
|
|
12316
12847
|
nonnegative(advance, "Token advance");
|
|
12317
12848
|
nonnegative(gap, "Token gap");
|
|
12318
|
-
|
|
12849
|
+
positive3(minWidth, "Token minimum width");
|
|
12319
12850
|
nonnegative(paddingX, "Token horizontal padding");
|
|
12320
|
-
if (width !== void 0)
|
|
12851
|
+
if (width !== void 0) positive3(width, "Token width");
|
|
12321
12852
|
if (options.x !== void 0) finite3(options.x, "Token x");
|
|
12322
12853
|
if (options.centerX !== void 0) finite3(options.centerX, "Token center x");
|
|
12323
12854
|
const items = values.map((value) => {
|
|
@@ -12361,7 +12892,7 @@ function createCanvasComponents(painter) {
|
|
|
12361
12892
|
}
|
|
12362
12893
|
function card(options) {
|
|
12363
12894
|
const { label, x, y, width, height, fontSize = 32, font = "sans", textColor, baselineOffset = fontSize * 0.34, labelOpacity = 1 } = options;
|
|
12364
|
-
|
|
12895
|
+
positive3(fontSize, "Canvas font size");
|
|
12365
12896
|
finite3(baselineOffset, "Canvas text baseline offset");
|
|
12366
12897
|
const labelAlpha = normalizedOpacity(labelOpacity, "Canvas label opacity");
|
|
12367
12898
|
return panel(options, () => {
|
|
@@ -12374,7 +12905,7 @@ function createCanvasComponents(painter) {
|
|
|
12374
12905
|
const { values, x, y, cellSize = 112, gap = 8, inset = 0, format = String, style = {}, cellStyle } = options;
|
|
12375
12906
|
finite3(x, "Matrix x");
|
|
12376
12907
|
finite3(y, "Matrix y");
|
|
12377
|
-
|
|
12908
|
+
positive3(cellSize, "Matrix cell size");
|
|
12378
12909
|
nonnegative(gap, "Matrix gap");
|
|
12379
12910
|
finite3(inset, "Matrix inset");
|
|
12380
12911
|
if (gap >= cellSize) throw new Error("Matrix gap must be smaller than cell size");
|
|
@@ -12405,7 +12936,7 @@ function createCanvasComponents(painter) {
|
|
|
12405
12936
|
function tokenRow(options) {
|
|
12406
12937
|
const { values, y, height = 68, reveal = 1, opacity = 1, ...style } = options;
|
|
12407
12938
|
finite3(y, "Token row y");
|
|
12408
|
-
|
|
12939
|
+
positive3(height, "Token height");
|
|
12409
12940
|
finite3(reveal, "Token reveal");
|
|
12410
12941
|
const alpha3 = normalizedOpacity(opacity);
|
|
12411
12942
|
const items = layoutTokenRow(values, options);
|
|
@@ -12422,7 +12953,7 @@ function createCanvasComponents(painter) {
|
|
|
12422
12953
|
function particle(options) {
|
|
12423
12954
|
const { points, progress, radius = 9, fill, stroke, strokeWidth = 3 } = options;
|
|
12424
12955
|
finite3(progress, "Particle progress");
|
|
12425
|
-
|
|
12956
|
+
positive3(radius, "Particle radius");
|
|
12426
12957
|
nonnegative(strokeWidth, "Particle stroke width");
|
|
12427
12958
|
if (progress <= 0 || progress >= 1) return null;
|
|
12428
12959
|
const point = pointAlongPath(points, progress);
|
|
@@ -12517,14 +13048,14 @@ function createTeachingTransfer(painter) {
|
|
|
12517
13048
|
}
|
|
12518
13049
|
|
|
12519
13050
|
// src/teaching-grid.ts
|
|
12520
|
-
function
|
|
13051
|
+
function positive4(value, name) {
|
|
12521
13052
|
if (!Number.isFinite(value) || value <= 0) throw new Error(`${name} must be finite and positive`);
|
|
12522
13053
|
}
|
|
12523
13054
|
function layoutCellGrid(options) {
|
|
12524
13055
|
const { x, y, width, height, rows, columns } = options;
|
|
12525
13056
|
if (![x, y, x + width, y + height].every(Number.isFinite)) throw new Error("Grid bounds must be finite");
|
|
12526
|
-
|
|
12527
|
-
|
|
13057
|
+
positive4(width, "Grid width");
|
|
13058
|
+
positive4(height, "Grid height");
|
|
12528
13059
|
if (![rows, columns, rows * columns].every(Number.isSafeInteger) || rows <= 0 || columns <= 0) {
|
|
12529
13060
|
throw new Error("Grid rows and columns must be positive safe integers");
|
|
12530
13061
|
}
|
|
@@ -12566,9 +13097,9 @@ function createTeachingGrid(painter) {
|
|
|
12566
13097
|
textColor = "#FFFFFF",
|
|
12567
13098
|
padding = 4
|
|
12568
13099
|
} = options;
|
|
12569
|
-
|
|
13100
|
+
positive4(lineWidth, "Grid line width");
|
|
12570
13101
|
if (lineWidth >= Math.min(width / columns, height / rows)) throw new Error("Grid line width must be smaller than a cell");
|
|
12571
|
-
|
|
13102
|
+
positive4(fontSize, "Grid font size");
|
|
12572
13103
|
if (!Number.isFinite(padding) || padding < 0) throw new Error("Grid padding must be finite and nonnegative");
|
|
12573
13104
|
if (labels && (labels.length !== rows || labels.some((row) => row.length !== columns))) {
|
|
12574
13105
|
throw new Error("Grid labels must match rows and columns");
|
|
@@ -12995,14 +13526,14 @@ function weightedVectorState(options) {
|
|
|
12995
13526
|
total: [...prefix2]
|
|
12996
13527
|
};
|
|
12997
13528
|
}
|
|
12998
|
-
function
|
|
13529
|
+
function positive5(value, name) {
|
|
12999
13530
|
if (finite4(value, name) <= 0) throw new Error(`${name} must be positive`);
|
|
13000
13531
|
}
|
|
13001
13532
|
function bounds2(value, name) {
|
|
13002
13533
|
finite4(value.x, `${name} x`);
|
|
13003
13534
|
finite4(value.y, `${name} y`);
|
|
13004
|
-
|
|
13005
|
-
|
|
13535
|
+
positive5(value.width, `${name} width`);
|
|
13536
|
+
positive5(value.height, `${name} height`);
|
|
13006
13537
|
}
|
|
13007
13538
|
function createTeachingVectorAccumulation(painter) {
|
|
13008
13539
|
return (options) => {
|
|
@@ -13023,9 +13554,9 @@ function createTeachingVectorAccumulation(painter) {
|
|
|
13023
13554
|
} = options;
|
|
13024
13555
|
bounds2(plot.bounds, "Vector plot");
|
|
13025
13556
|
bounds2(ledger, "Vector ledger");
|
|
13026
|
-
|
|
13027
|
-
|
|
13028
|
-
|
|
13557
|
+
positive5(fontSize, "Vector font size");
|
|
13558
|
+
positive5(width, "Vector stroke width");
|
|
13559
|
+
positive5(endpointRadius, "Vector endpoint radius");
|
|
13029
13560
|
finite4(completedOpacity, "Completed vector opacity");
|
|
13030
13561
|
if (completedOpacity < 0 || completedOpacity > 1) throw new Error("Completed vector opacity must lie between zero and one");
|
|
13031
13562
|
const [x0, x1] = plot.xDomain, [y0, y1] = plot.yDomain;
|
|
@@ -13745,7 +14276,14 @@ function createTeachingTokenHistory(painter) {
|
|
|
13745
14276
|
const progress = state.moving.progress;
|
|
13746
14277
|
const settle = Math.max(0, (progress - 0.65) / 0.35);
|
|
13747
14278
|
const grow = Math.max(0, (progress - 0.8) / 0.2);
|
|
13748
|
-
const
|
|
14279
|
+
const measuredWidth = painter.measureText?.(String(state.moving.token.token), fontSize, "mono");
|
|
14280
|
+
if (measuredWidth !== void 0 && (!Number.isFinite(measuredWidth) || measuredWidth < 0)) {
|
|
14281
|
+
throw new Error("Token history measured text width must be finite and nonnegative");
|
|
14282
|
+
}
|
|
14283
|
+
const copyWidth = Math.min(from.width, Math.max(
|
|
14284
|
+
fontSize * 3,
|
|
14285
|
+
measuredWidth === void 0 ? from.width : measuredWidth + 10
|
|
14286
|
+
));
|
|
13749
14287
|
const copyHeight = Math.min(from.height, fontSize * 1.8);
|
|
13750
14288
|
const movingWidth = copyWidth + (from.width - copyWidth) * grow;
|
|
13751
14289
|
const movingHeight = copyHeight + (from.height - copyHeight) * grow;
|
|
@@ -13778,15 +14316,15 @@ var PANEL = "#18283B";
|
|
|
13778
14316
|
function finite6(value, name) {
|
|
13779
14317
|
if (!Number.isFinite(value)) throw new Error(`${name} must be finite`);
|
|
13780
14318
|
}
|
|
13781
|
-
function
|
|
14319
|
+
function positive6(value, name) {
|
|
13782
14320
|
finite6(value, name);
|
|
13783
14321
|
if (value <= 0) throw new Error(`${name} must be positive`);
|
|
13784
14322
|
}
|
|
13785
14323
|
function boundsOf(options) {
|
|
13786
14324
|
finite6(options.x, "Teaching x");
|
|
13787
14325
|
finite6(options.y, "Teaching y");
|
|
13788
|
-
|
|
13789
|
-
|
|
14326
|
+
positive6(options.width, "Teaching width");
|
|
14327
|
+
positive6(options.height, "Teaching height");
|
|
13790
14328
|
return { x: options.x, y: options.y, width: options.width, height: options.height };
|
|
13791
14329
|
}
|
|
13792
14330
|
function amount(value, name = "Teaching progress") {
|
|
@@ -13822,7 +14360,7 @@ function createTeachingCanvas(painter) {
|
|
|
13822
14360
|
}
|
|
13823
14361
|
const { x, y, width, height } = bounds4;
|
|
13824
14362
|
const { color = INK, gridColor, fontSize = 28, xTicks = [], yTicks = [], formatX = String, formatY = String } = options;
|
|
13825
|
-
|
|
14363
|
+
positive6(fontSize, "Axis font size");
|
|
13826
14364
|
xTicks.forEach((tick) => finite6(tick, "Axis x tick"));
|
|
13827
14365
|
yTicks.forEach((tick) => finite6(tick, "Axis y tick"));
|
|
13828
14366
|
const plot = {
|
|
@@ -13863,7 +14401,7 @@ function createTeachingCanvas(painter) {
|
|
|
13863
14401
|
}
|
|
13864
14402
|
function curve(options) {
|
|
13865
14403
|
const { plot, points, color, width = 4, progress = 1 } = options;
|
|
13866
|
-
|
|
14404
|
+
positive6(width, "Curve width");
|
|
13867
14405
|
const mapped = points.map((point) => plot.point(point.x, point.y));
|
|
13868
14406
|
const visible = tracePolyline(mapped, progress);
|
|
13869
14407
|
if (visible.length > 1) painter.path(visible, { color, width, clip: plot.bounds });
|
|
@@ -13871,10 +14409,10 @@ function createTeachingCanvas(painter) {
|
|
|
13871
14409
|
}
|
|
13872
14410
|
function scatter(options) {
|
|
13873
14411
|
const { plot, points, color = ACCENT, radius = 7, opacity = 1 } = options;
|
|
13874
|
-
|
|
14412
|
+
positive6(radius, "Scatter radius");
|
|
13875
14413
|
const alpha3 = amount(opacity, "Scatter opacity");
|
|
13876
14414
|
const projected = points.map((point) => {
|
|
13877
|
-
|
|
14415
|
+
positive6(point.radius ?? radius, "Scatter point radius");
|
|
13878
14416
|
return {
|
|
13879
14417
|
...plot.point(point.x, point.y),
|
|
13880
14418
|
radius: point.radius ?? radius,
|
|
@@ -13896,7 +14434,7 @@ function createTeachingCanvas(painter) {
|
|
|
13896
14434
|
const bounds4 = boundsOf(options);
|
|
13897
14435
|
const { x, y, width, height } = bounds4;
|
|
13898
14436
|
const { values, labels, colors: colors2, color = ACCENT, progress = 1, showValues = false, format = String, fontSize = 28, gap = 20 } = options;
|
|
13899
|
-
|
|
14437
|
+
positive6(fontSize, "Bar font size");
|
|
13900
14438
|
finite6(gap, "Bar gap");
|
|
13901
14439
|
if (gap < 0) throw new Error("Bar gap must be nonnegative");
|
|
13902
14440
|
values.forEach((value) => {
|
|
@@ -13907,12 +14445,12 @@ function createTeachingCanvas(painter) {
|
|
|
13907
14445
|
if (colors2 && colors2.length !== values.length) throw new Error("Bar colors must match values");
|
|
13908
14446
|
const maximumValue = values.reduce((maximum2, value) => Math.max(maximum2, value), 0);
|
|
13909
14447
|
const maximum = options.max ?? (maximumValue || 1);
|
|
13910
|
-
|
|
14448
|
+
positive6(maximum, "Bar maximum");
|
|
13911
14449
|
if (maximum < maximumValue) throw new Error("Bar maximum must contain every value");
|
|
13912
14450
|
const reveal = amount(progress);
|
|
13913
14451
|
if (!values.length) return { bars: [], slots: [], bounds: bounds4 };
|
|
13914
14452
|
const barWidth = (width - gap * (values.length - 1)) / values.length;
|
|
13915
|
-
|
|
14453
|
+
positive6(barWidth, "Bar width after gaps");
|
|
13916
14454
|
const shapes = [];
|
|
13917
14455
|
const slots = [];
|
|
13918
14456
|
values.forEach((value, index) => {
|
|
@@ -13933,7 +14471,7 @@ function createTeachingCanvas(painter) {
|
|
|
13933
14471
|
for (const node of nodes) {
|
|
13934
14472
|
if (!node.id || Object.hasOwn(descriptors, node.id)) throw new Error("Flow node IDs must be nonempty and unique");
|
|
13935
14473
|
const bounds4 = boundsOf(node);
|
|
13936
|
-
|
|
14474
|
+
positive6(node.fontSize ?? 30, "Flow node font size");
|
|
13937
14475
|
finite6(node.radius ?? 14, "Flow node radius");
|
|
13938
14476
|
if ((node.radius ?? 14) < 0) throw new Error("Flow node radius must be nonnegative");
|
|
13939
14477
|
descriptors[node.id] = { ...bounds4, radius: node.radius ?? 14 };
|
|
@@ -13942,7 +14480,7 @@ function createTeachingCanvas(painter) {
|
|
|
13942
14480
|
if (!Object.hasOwn(descriptors, edge.from) || !Object.hasOwn(descriptors, edge.to)) throw new Error("Flow edge must reference existing nodes");
|
|
13943
14481
|
if (edge.from === edge.to) throw new Error("Flow edges must connect distinct nodes");
|
|
13944
14482
|
if (edge.progress !== void 0) amount(edge.progress);
|
|
13945
|
-
if (edge.width !== void 0)
|
|
14483
|
+
if (edge.width !== void 0) positive6(edge.width, "Flow edge width");
|
|
13946
14484
|
for (const gap of [edge.gap, edge.fromGap, edge.toGap]) {
|
|
13947
14485
|
if (gap !== void 0) finite6(gap, "Flow edge gap");
|
|
13948
14486
|
}
|
|
@@ -14183,7 +14721,7 @@ function morphPolyline(from, to, progress, options = {}) {
|
|
|
14183
14721
|
}
|
|
14184
14722
|
|
|
14185
14723
|
// src/scene-renderer.ts
|
|
14186
|
-
import
|
|
14724
|
+
import React19 from "react";
|
|
14187
14725
|
import { readFile, mkdir as mkdir2, open, rename, rm } from "fs/promises";
|
|
14188
14726
|
import { createReadStream } from "fs";
|
|
14189
14727
|
import { dirname as dirname2, join, resolve } from "path";
|
|
@@ -14287,11 +14825,11 @@ function serializeSvg(node, budget, depth = 0) {
|
|
|
14287
14825
|
if (node === null || node === void 0 || typeof node === "boolean") return "";
|
|
14288
14826
|
if (typeof node === "string" || typeof node === "number") return emit(xml(node));
|
|
14289
14827
|
if (Array.isArray(node)) return node.map((child) => serializeSvg(child, budget, depth + 1)).join("");
|
|
14290
|
-
if (!
|
|
14291
|
-
if (node.type ===
|
|
14828
|
+
if (!React19.isValidElement(node)) throw new Error("Invalid resolved SVG child.");
|
|
14829
|
+
if (node.type === React19.Fragment) return serializeSvg(node.props.children, budget, depth + 1);
|
|
14292
14830
|
if (node.type === SvgMathText) {
|
|
14293
14831
|
const { text, x, y, fill, fontSize = 13, fontFamily = "JetBrains Mono", fontWeight = 700, textAnchor = "middle", dominantBaseline = "middle", opacity = 1 } = node.props;
|
|
14294
|
-
return serializeSvg(
|
|
14832
|
+
return serializeSvg(React19.createElement("text", { x, y, fill, fontSize, fontFamily, fontWeight, textAnchor, dominantBaseline, opacity }, String(text)), budget, depth + 1);
|
|
14295
14833
|
}
|
|
14296
14834
|
if (typeof node.type === "function") {
|
|
14297
14835
|
return serializeSvg(node.type(node.props), budget, depth + 1);
|
|
@@ -14320,10 +14858,10 @@ function graphToReact(value, theme) {
|
|
|
14320
14858
|
const props = Object.fromEntries(Object.entries(value.props).map(([name, prop]) => [name, convertProp(prop)]));
|
|
14321
14859
|
const component = trustedComponents[value.type];
|
|
14322
14860
|
if (component) props.c ??= theme;
|
|
14323
|
-
return
|
|
14861
|
+
return React19.createElement(component ?? value.type, props, ...value.children.map((child) => graphToReact(child, theme)));
|
|
14324
14862
|
}
|
|
14325
14863
|
function renderSvgImage(element, assets, width, height, budget, outputScale = 1, includePng = true) {
|
|
14326
|
-
const root =
|
|
14864
|
+
const root = React19.cloneElement(element, { xmlns: "http://www.w3.org/2000/svg", width, height });
|
|
14327
14865
|
const svg = serializeSvg(root, budget);
|
|
14328
14866
|
const image = new Resvg2(svg, {
|
|
14329
14867
|
font: { loadSystemFonts: false, fontFiles: assets.fontFiles, defaultFontFamily: "Inter" },
|
|
@@ -14336,7 +14874,7 @@ function renderSvgImage(element, assets, width, height, budget, outputScale = 1,
|
|
|
14336
14874
|
function rasterizeNestedSvg(node, assets, defaultWidth, defaultHeight, budget) {
|
|
14337
14875
|
if (++budget.nodes > SCENE_LIMITS.nodes * 16) throw new Error("Resolved scene exceeds its host element budget.");
|
|
14338
14876
|
if (Array.isArray(node)) return node.map((child) => rasterizeNestedSvg(child, assets, defaultWidth, defaultHeight, budget));
|
|
14339
|
-
if (!
|
|
14877
|
+
if (!React19.isValidElement(node)) return node;
|
|
14340
14878
|
if (node.type === "svg") {
|
|
14341
14879
|
const width = typeof node.props.width === "number" ? node.props.width : defaultWidth;
|
|
14342
14880
|
const height = typeof node.props.height === "number" ? node.props.height : defaultHeight;
|
|
@@ -14349,7 +14887,7 @@ function rasterizeNestedSvg(node, assets, defaultWidth, defaultHeight, budget) {
|
|
|
14349
14887
|
throw new Error("Nested SVG rasterization exceeds the per-frame pixel or image budget.");
|
|
14350
14888
|
}
|
|
14351
14889
|
const { png } = renderSvgImage(node, assets, width, height, budget);
|
|
14352
|
-
return
|
|
14890
|
+
return React19.createElement("img", {
|
|
14353
14891
|
width,
|
|
14354
14892
|
height,
|
|
14355
14893
|
src: `data:image/png;base64,${Buffer.from(png).toString("base64")}`,
|
|
@@ -14358,20 +14896,20 @@ function rasterizeNestedSvg(node, assets, defaultWidth, defaultHeight, budget) {
|
|
|
14358
14896
|
}
|
|
14359
14897
|
if (typeof node.type === "function") return rasterizeNestedSvg(node.type(node.props), assets, defaultWidth, defaultHeight, budget);
|
|
14360
14898
|
validateResolvedSceneResources(node.props);
|
|
14361
|
-
return
|
|
14899
|
+
return React19.cloneElement(node, {}, rasterizeNestedSvg(node.props.children, assets, defaultWidth, defaultHeight, budget));
|
|
14362
14900
|
}
|
|
14363
14901
|
async function renderPreparedFrame(prepared, assets, time, outputScale, includePng) {
|
|
14364
14902
|
const evaluated = await prepared.evaluate(time);
|
|
14365
14903
|
const { width, height, theme } = prepared.request;
|
|
14366
14904
|
const c = getThemeColors(theme);
|
|
14367
14905
|
let element = graphToReact(evaluated.graph, c);
|
|
14368
|
-
if (
|
|
14369
|
-
const image = renderSvgImage(
|
|
14370
|
-
children: [
|
|
14906
|
+
if (React19.isValidElement(element) && element.type === "svg") {
|
|
14907
|
+
const image = renderSvgImage(React19.cloneElement(element, {
|
|
14908
|
+
children: [React19.createElement("rect", { key: "__scene_background", width, height, fill: c.bg }), element.props.children]
|
|
14371
14909
|
}), assets, width, height, { pixels: 0, count: 0, nodes: 0, svgBytes: 0 }, outputScale, includePng);
|
|
14372
14910
|
return image;
|
|
14373
14911
|
}
|
|
14374
|
-
element =
|
|
14912
|
+
element = React19.createElement("div", { style: { display: "flex", position: "relative", width, height, backgroundColor: c.bg, fontFamily: "Inter", color: c.textPrimary } }, element);
|
|
14375
14913
|
return withRenderContext({ background: "theme" }, async () => {
|
|
14376
14914
|
element = rasterizeNestedSvg(element, assets, width, height, { pixels: 0, count: 0, nodes: 0, svgBytes: 0 });
|
|
14377
14915
|
const accessible = prepareAccessibleSvg(element);
|
|
@@ -15939,6 +16477,7 @@ export {
|
|
|
15939
16477
|
DonutChart,
|
|
15940
16478
|
DotPoint,
|
|
15941
16479
|
ELEMENT_SYMBOLS,
|
|
16480
|
+
EntityRelationshipDiagram,
|
|
15942
16481
|
EquationCard,
|
|
15943
16482
|
FactRows,
|
|
15944
16483
|
Flow,
|
|
@@ -16014,7 +16553,9 @@ export {
|
|
|
16014
16553
|
byteDifferenceState,
|
|
16015
16554
|
cameraSvgTransform,
|
|
16016
16555
|
canvas,
|
|
16556
|
+
captionsToSrt,
|
|
16017
16557
|
categoricalSampling,
|
|
16558
|
+
chapterMetadata,
|
|
16018
16559
|
checkFrame,
|
|
16019
16560
|
colors,
|
|
16020
16561
|
compareByteSequences,
|