@littlepress/renderer-web 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +20 -0
- package/README.md +229 -2
- package/dist/answer/answerComponents.d.ts +107 -0
- package/dist/answer/answerComponents.js +637 -0
- package/dist/answer/download.d.ts +63 -0
- package/dist/answer/download.js +109 -0
- package/dist/answer/downloadExport.d.ts +44 -0
- package/dist/answer/downloadExport.js +266 -0
- package/dist/answer/hostValues.d.ts +28 -0
- package/dist/answer/hostValues.js +379 -0
- package/dist/answer/mapComponent.d.ts +6 -0
- package/dist/answer/mapComponent.js +213 -0
- package/dist/answer/math.d.ts +57 -0
- package/dist/answer/math.js +168 -0
- package/dist/answer/surfaceStream.d.ts +51 -0
- package/dist/answer/surfaceStream.js +260 -0
- package/dist/answer/tableLayout.d.ts +42 -0
- package/dist/answer/tableLayout.js +89 -0
- package/dist/controls/ActionFeedback.d.ts +5 -0
- package/dist/controls/ActionFeedback.js +43 -0
- package/dist/controls/actionDispatch.d.ts +51 -0
- package/dist/controls/actionDispatch.js +211 -0
- package/dist/controls/actionOutcome.generated.d.ts +64 -0
- package/dist/controls/actionOutcome.generated.js +64 -0
- package/dist/controls/calculationPublisher.d.ts +14 -0
- package/dist/controls/calculationPublisher.js +6 -0
- package/dist/controls/calculations.d.ts +20 -0
- package/dist/controls/calculations.generated.d.ts +73 -0
- package/dist/controls/calculations.generated.js +85 -0
- package/dist/controls/calculations.js +208 -0
- package/dist/controls/controlState.d.ts +84 -0
- package/dist/controls/controlState.js +256 -0
- package/dist/controls/fieldMessages.d.ts +41 -0
- package/dist/controls/fieldMessages.js +81 -0
- package/dist/controls/fieldValidation.d.ts +19 -0
- package/dist/controls/fieldValidation.js +98 -0
- package/dist/controls/formComponents.d.ts +23 -0
- package/dist/controls/formComponents.js +738 -0
- package/dist/controls/formProgress.d.ts +63 -0
- package/dist/controls/formProgress.js +122 -0
- package/dist/controls/inputDrafts.d.ts +55 -0
- package/dist/controls/inputDrafts.js +183 -0
- package/dist/controls/inputValidation.d.ts +33 -0
- package/dist/controls/inputValidation.js +119 -0
- package/dist/controls/localWrites.d.ts +9 -0
- package/dist/controls/localWrites.js +29 -0
- package/dist/core/A2uiSurface.d.ts +13 -0
- package/dist/core/A2uiSurface.js +15 -0
- package/dist/core/AtlasIcon.d.ts +18 -0
- package/dist/core/AtlasIcon.js +22 -0
- package/dist/core/AtlasMedia.d.ts +22 -0
- package/dist/core/AtlasMedia.js +45 -0
- package/dist/core/Carousel.d.ts +61 -0
- package/dist/core/Carousel.js +183 -0
- package/dist/core/CoreMedia.d.ts +19 -0
- package/dist/core/CoreMedia.js +25 -0
- package/dist/core/FoundationA2uiSurface.d.ts +86 -0
- package/dist/core/FoundationA2uiSurface.js +440 -0
- package/dist/core/ImagePreview.d.ts +42 -0
- package/dist/core/ImagePreview.js +73 -0
- package/dist/core/LucideIcon.d.ts +19 -0
- package/dist/core/LucideIcon.js +42 -0
- package/dist/core/SurfaceLink.d.ts +35 -0
- package/dist/core/SurfaceLink.js +60 -0
- package/dist/core/appearance/aegis.d.ts +49 -0
- package/dist/core/appearance/aegis.js +34 -0
- package/dist/core/appearance/colour.d.ts +24 -0
- package/dist/core/appearance/colour.js +103 -0
- package/dist/core/appearance/css.d.ts +17 -0
- package/dist/core/appearance/css.js +153 -0
- package/dist/core/appearance/presets.generated.d.ts +4 -0
- package/dist/core/appearance/presets.generated.js +1184 -0
- package/dist/core/appearance/react.d.ts +29 -0
- package/dist/core/appearance/react.js +110 -0
- package/dist/core/appearance/resolve.d.ts +76 -0
- package/dist/core/appearance/resolve.js +127 -0
- package/dist/core/appearance/textScale.d.ts +11 -0
- package/dist/core/appearance/textScale.js +51 -0
- package/dist/core/appearance/theme.d.ts +138 -0
- package/dist/core/appearance/theme.js +274 -0
- package/dist/core/baseComponents.d.ts +53 -0
- package/dist/core/baseComponents.js +480 -0
- package/dist/core/binding.d.ts +46 -0
- package/dist/core/binding.js +118 -0
- package/dist/core/bundle.d.ts +23 -0
- package/dist/core/bundle.js +75 -0
- package/dist/core/catalog/catalog-index.generated.d.ts +44 -0
- package/dist/core/catalog/catalog-index.generated.js +79 -0
- package/dist/core/catalog/icons.generated.d.ts +6 -0
- package/dist/core/catalog/icons.generated.js +1788 -0
- package/dist/core/catalog.d.ts +6 -0
- package/dist/core/catalog.generated.d.ts +50 -0
- package/dist/core/catalog.generated.js +2174 -0
- package/dist/core/catalog.js +8 -0
- package/dist/core/chartRows.d.ts +7 -0
- package/dist/core/chartRows.js +38 -0
- package/dist/core/component-support.d.ts +39 -0
- package/dist/core/component-support.js +127 -0
- package/dist/core/components/actions.d.ts +4 -0
- package/dist/core/components/actions.js +21 -0
- package/dist/core/components/cards.d.ts +9 -0
- package/dist/core/components/cards.js +227 -0
- package/dist/core/components/charts.d.ts +18 -0
- package/dist/core/components/charts.js +412 -0
- package/dist/core/components/comparisonTable.d.ts +50 -0
- package/dist/core/components/comparisonTable.js +89 -0
- package/dist/core/components/content.d.ts +13 -0
- package/dist/core/components/content.js +108 -0
- package/dist/core/components/seriesCharts.d.ts +531 -0
- package/dist/core/components/seriesCharts.js +1053 -0
- package/dist/core/components/stepFlow.d.ts +7 -0
- package/dist/core/components/stepFlow.js +13 -0
- package/dist/core/components.full.d.ts +10 -0
- package/dist/core/components.full.js +41 -0
- package/dist/core/context.d.ts +207 -0
- package/dist/core/context.js +172 -0
- package/dist/core/coverage.d.ts +30 -0
- package/dist/core/coverage.js +93 -0
- package/dist/core/foundation.d.ts +21 -0
- package/dist/core/foundation.js +22 -0
- package/dist/core/fullTheme.d.ts +5 -0
- package/dist/core/fullTheme.js +9 -0
- package/dist/core/iconNodes.generated.d.ts +7 -0
- package/dist/core/iconNodes.generated.js +5 -0
- package/dist/core/lucideIcons.d.ts +5 -0
- package/dist/core/lucideIcons.js +7 -0
- package/dist/core/messages.d.ts +111 -0
- package/dist/core/messages.js +134 -0
- package/dist/core/pointer.d.ts +17 -0
- package/dist/core/pointer.js +104 -0
- package/dist/core/registry.d.ts +12 -0
- package/dist/core/registry.js +114 -0
- package/dist/core/runtime.d.ts +8 -0
- package/dist/core/runtime.js +6 -0
- package/dist/core/state.d.ts +73 -0
- package/dist/core/state.js +274 -0
- package/dist/core/surfaceMotion.d.ts +5 -0
- package/dist/core/surfaceMotion.js +46 -0
- package/dist/core/theme.d.ts +5 -0
- package/dist/core/theme.js +7 -0
- package/dist/core/useSurfaceImage.d.ts +20 -0
- package/dist/core/useSurfaceImage.js +65 -0
- package/dist/graph/RelationshipGraph.d.ts +14 -0
- package/dist/graph/RelationshipGraph.js +206 -0
- package/dist/graph/model.d.ts +20 -0
- package/dist/graph/model.js +36 -0
- package/dist/graph/program/assets.d.ts +3 -0
- package/dist/graph/program/assets.js +3 -0
- package/dist/graph/program/bridge.d.ts +6 -0
- package/dist/graph/program/bridge.generated.d.ts +136 -0
- package/dist/graph/program/bridge.generated.js +1 -0
- package/dist/graph/program/bridge.js +24 -0
- package/dist/graph/program/bridge.schema.json +717 -0
- package/dist/graph/program/bridgeValidator.cjs +2 -0
- package/dist/graph/program/bridgeValidator.d.cts +4 -0
- package/dist/graph/program/runner.d.ts +1 -0
- package/dist/graph/program/runner.html +2193 -0
- package/dist/graph/program/runner.js +157 -0
- package/dist/graph/program/runtime-manifest.json +1 -0
- package/dist/graph/program/view.d.ts +11 -0
- package/dist/graph/program/view.js +210 -0
- package/dist/graph/program/worker.d.ts +1 -0
- package/dist/graph/program/worker.js +2186 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +45 -0
- package/dist/internal/dsh.d.ts +4 -0
- package/dist/internal/dsh.js +3 -0
- package/dist/internal/relationship-graph.d.ts +4 -0
- package/dist/internal/relationship-graph.js +7202 -0
- package/dist/page/layoutComponents.d.ts +6 -0
- package/dist/page/layoutComponents.js +123 -0
- package/dist/page/layoutGeometry.d.ts +68 -0
- package/dist/page/layoutGeometry.js +174 -0
- package/dist/page/pageFormat.d.ts +34 -0
- package/dist/page/pageFormat.js +119 -0
- package/dist/page/printFit.d.ts +81 -0
- package/dist/page/printFit.js +338 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.js +2 -0
- package/dist/report/locate.d.ts +42 -0
- package/dist/report/locate.js +34 -0
- package/dist/styles/renderer.css +4580 -0
- package/licenses/LUCIDE-LICENSE.txt +43 -0
- package/licenses/QUICKJS-EMSCRIPTEN-LICENSE.txt +21 -0
- package/licenses/QUICKJS-VARIANT-LICENSE.txt +47 -0
- package/package.json +68 -3
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { isRecord, resolveStringList, } from "../foundation.js";
|
|
3
|
+
import { accessibilityLabel, numberFromRecord, printPart, recordValue, records, stringFromRecord, text, withFallback, } from "../component-support.js";
|
|
4
|
+
import { RADAR_LABEL_LINE, SCATTER_LABEL_LIMIT, SERIES_DASH, areaBands, areaChartModel, axisPercent, barChartModel, barRows, chartTable, edgeTicks, endpointSeries, formatChartNumber, lineChartModel, linePaths, orderedTone, pieSlices, radarGrid, radarLayout, radarPoints, radarValueColumn, radialTracks, readSeriesChart, readScatterChart, roundedBarEnd, rowLabelLayout, SCATTER_MARK_BOX, SCATTER_MARK_PATHS, scatterMark, scatterTable, scatterXTicks, scatterAxisPercent, scatterLabels, scatterPoints, showsLegend, showsPointMarkers, showsValueAxis, showsValueLabels, widestValueLabel, } from "./seriesCharts.js";
|
|
5
|
+
import { cellText, cellTone, columnAlignment, columnUnit, numericColumns } from "./comparisonTable.js";
|
|
6
|
+
function percent(value, maximum = 100) {
|
|
7
|
+
if (value === null || maximum <= 0)
|
|
8
|
+
return 0;
|
|
9
|
+
return Math.max(0, Math.min((value / maximum) * 100, 100));
|
|
10
|
+
}
|
|
11
|
+
/** The optional overline above a component's title, in the contract's kicker role. */
|
|
12
|
+
function Kicker({ component, context }) {
|
|
13
|
+
const kicker = text(component, "kicker", context);
|
|
14
|
+
return kicker ? _jsx("p", { className: "lp-kicker", ...printPart(component, "kicker", "clamp"), children: kicker }) : null;
|
|
15
|
+
}
|
|
16
|
+
/** The line plot's viewBox, shared by every chart that stretches it. */
|
|
17
|
+
const TREND_VIEWBOX = { width: 320, height: 124 };
|
|
18
|
+
/**
|
|
19
|
+
* Where a point marker sits inside the stretched plot box.
|
|
20
|
+
*
|
|
21
|
+
* `preserveAspectRatio="none"` is what lets the plot fill the card's width, but
|
|
22
|
+
* it scales a circle drawn inside it into an ellipse — 2.65 times wider than
|
|
23
|
+
* tall at 848px. The markers are therefore HTML, placed in the plot's own
|
|
24
|
+
* viewBox coordinates as a percentage and sized in px, so they stay round at
|
|
25
|
+
* every width while the line, the gridlines and the endpoint labels keep the
|
|
26
|
+
* geometry they have always had.
|
|
27
|
+
*/
|
|
28
|
+
function markerPlacement(x, y, radius) {
|
|
29
|
+
return {
|
|
30
|
+
left: `${((x / TREND_VIEWBOX.width) * 100).toFixed(4)}%`,
|
|
31
|
+
top: `${((y / TREND_VIEWBOX.height) * 100).toFixed(4)}%`,
|
|
32
|
+
"--lp-marker-size": `${radius * 2}px`,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/* ------------------------------------------------- multi-series charts */
|
|
36
|
+
/*
|
|
37
|
+
* One bar chart and one line chart each draw one or several series, in one
|
|
38
|
+
* chart language: a row grid with an 8px square-ended track on surface-2 for
|
|
39
|
+
* horizontal bars, one plot box with hairline rules for lines and areas, and
|
|
40
|
+
* the meta type for labels and values. One unnamed series draws with no legend
|
|
41
|
+
* and labels its values directly. Extra series add a legend, a dash pattern
|
|
42
|
+
* per line, and — only when direct labels no longer fit — a value axis.
|
|
43
|
+
*/
|
|
44
|
+
/** The line plot box, shared so line and area charts use one geometry. */
|
|
45
|
+
const LINE_PLOT = { x: 18, y: 18, width: 284, height: 84 };
|
|
46
|
+
/** The scatter plot in percentages: the markers are positioned, not drawn in SVG. */
|
|
47
|
+
const SCATTER_PLOT = { x: 6, y: 6, width: 88, height: 88 };
|
|
48
|
+
function seriesModel(component, context) {
|
|
49
|
+
return readSeriesChart(records(component, context, "items", "series"), {
|
|
50
|
+
labelField: text(component, "labelField", context),
|
|
51
|
+
seriesFields: resolveStringList(component.seriesFields, context.binding, context.valueFunctions),
|
|
52
|
+
seriesLabels: resolveStringList(component.seriesLabels, context.binding, context.valueFunctions),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function hasSeriesNames(component, context) {
|
|
56
|
+
return resolveStringList(component.seriesLabels, context.binding, context.valueFunctions).length > 0;
|
|
57
|
+
}
|
|
58
|
+
function tickVariables(model, value) {
|
|
59
|
+
return { "--lp-tick": `${axisPercent(model, value)}%` };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Series names always read as text, never as a bare colour chip. Lines repeat
|
|
63
|
+
* their dash pattern in the swatch so the legend matches what is drawn. The
|
|
64
|
+
* unit rides on the names when no axis carries it, so it never floats alone.
|
|
65
|
+
*/
|
|
66
|
+
function SeriesLegend({ component, model, unit, stroke, marks = false, }) {
|
|
67
|
+
return (_jsx("div", { className: "lp-series-legend", children: model.series.map((entry) => (_jsxs("span", { className: `lp-series-key lp-series-${entry.index + 1}`, children: [marks ? (_jsx(ScatterMarkSvg, { className: "lp-series-swatch lp-scatter-swatch", seriesIndex: entry.index })) : stroke ? (_jsx("svg", { className: "lp-series-swatch", viewBox: "0 0 18 8", "aria-hidden": "true", children: _jsx("line", { className: "lp-series-stroke", x1: "0", y1: "4", x2: "18", y2: "4", strokeDasharray: SERIES_DASH[entry.index] }) })) : (_jsx("i", { className: "lp-series-chip", "aria-hidden": "true" })), _jsx("span", { ...printPart(component, "legend", "clamp"), children: unit ? `${entry.label} (${unit})` : entry.label })] }, entry.field))) }));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The text alternative for the drawing. Multi-series values can never all be
|
|
71
|
+
* visible, so every row and series is repeated here in full.
|
|
72
|
+
*
|
|
73
|
+
* The clip class goes on a block wrapper, never on the table itself: `display:
|
|
74
|
+
* table` treats `width` as a minimum, so a 1px rule cannot shrink a data table —
|
|
75
|
+
* it grows to its content (measured 1228px) and widens any host that does not
|
|
76
|
+
* clip. A block element does shrink, and the table inside keeps its table
|
|
77
|
+
* semantics, so assistive technology still reads the rows.
|
|
78
|
+
*/
|
|
79
|
+
function SeriesTable({ model, unit, summary }) {
|
|
80
|
+
return _jsx(ChartDataTable, { table: chartTable(model, unit), summary: summary });
|
|
81
|
+
}
|
|
82
|
+
function ChartDataTable({ table, summary }) {
|
|
83
|
+
return (_jsx("div", { className: "a2ui-visually-hidden", children: _jsxs("table", { children: [summary ? _jsx("caption", { children: summary }) : null, _jsx("thead", { children: _jsx("tr", { children: table.columns.map((column, index) => (_jsx("th", { scope: "col", children: column }, `column-${index}`))) }) }), _jsx("tbody", { children: table.rows.map((row, rowIndex) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: row.label }), row.cells.map((cell, cellIndex) => (_jsx("td", { children: cell }, `cell-${rowIndex}-${cellIndex}`)))] }, `row-${rowIndex}`))) })] }) }));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The value axis: hairline ticks down the leading edge of the plot. The ticks
|
|
87
|
+
* are positioned, so a hidden copy of the widest one gives the gutter a real
|
|
88
|
+
* width and keeps every label inside the card's content box.
|
|
89
|
+
*/
|
|
90
|
+
function SeriesAxis({ model }) {
|
|
91
|
+
const labels = model.ticks.map(formatChartNumber);
|
|
92
|
+
const widest = labels.reduce((longest, label) => (label.length > longest.length ? label : longest), labels[0]);
|
|
93
|
+
return (_jsxs("div", { className: "lp-series-axis", children: [_jsx("span", { className: "lp-series-tick lp-series-gutter", "aria-hidden": "true", children: widest }), model.ticks.map((tick) => (_jsx("span", { className: "lp-series-tick", style: tickVariables(model, tick), children: formatChartNumber(tick) }, `tick-${tick}`)))] }));
|
|
94
|
+
}
|
|
95
|
+
function SeriesGrid({ model }) {
|
|
96
|
+
return (_jsx(_Fragment, { children: model.ticks.map((tick) => (_jsx("i", { className: `lp-series-gridline${tick === 0 ? " zero" : ""}`, style: tickVariables(model, tick) }, `grid-${tick}`))) }));
|
|
97
|
+
}
|
|
98
|
+
/** The class that rounds a column's free end; the end on the zero line stays square. */
|
|
99
|
+
function barEndClass(row, segment, variant) {
|
|
100
|
+
const end = roundedBarEnd(row, segment, variant);
|
|
101
|
+
return end ? ` round-${end}` : "";
|
|
102
|
+
}
|
|
103
|
+
/** One lane: an 8px track on surface-2, with the fill inside it. */
|
|
104
|
+
function SeriesLane({ segments, seriesIndex }) {
|
|
105
|
+
return (_jsx("span", { className: "lp-signal-track", children: segments.map((segment) => (_jsx("i", { className: `lp-series-${segment.seriesIndex + 1}${seriesIndex === undefined ? " stacked" : ""}`, style: {
|
|
106
|
+
"--lp-bar-start": `${segment.startPercent}%`,
|
|
107
|
+
"--lp-bar-size": `${segment.sizePercent}%`,
|
|
108
|
+
} }, `fill-${segment.seriesIndex}`))) }));
|
|
109
|
+
}
|
|
110
|
+
const renderBarChart = (component, context) => {
|
|
111
|
+
const model = seriesModel(component, context);
|
|
112
|
+
const variant = text(component, "variant", context) === "stacked" ? "stacked" : "grouped";
|
|
113
|
+
// The labels decide the layout: one that cannot fit whole words across two
|
|
114
|
+
// centred lines turns the chart sideways, where each category has a row.
|
|
115
|
+
const labelLayout = model ? rowLabelLayout(model.labels) : "flat";
|
|
116
|
+
const sideways = text(component, "orientation", context) === "horizontal";
|
|
117
|
+
const horizontal = sideways || labelLayout === "horizontal";
|
|
118
|
+
const named = hasSeriesNames(component, context);
|
|
119
|
+
const title = text(component, "title", context) ?? text(component, "heading", context);
|
|
120
|
+
const unit = text(component, "unit", context);
|
|
121
|
+
const summary = text(component, "summary", context);
|
|
122
|
+
const caption = text(component, "caption", context);
|
|
123
|
+
const plot = model ? barChartModel(model, variant) : null;
|
|
124
|
+
const layout = { variant, horizontal, named };
|
|
125
|
+
const rows = plot ? barRows(plot, variant) : [];
|
|
126
|
+
const direct = model !== null && showsValueLabels(model, layout);
|
|
127
|
+
const axis = model !== null && showsValueAxis(model, layout);
|
|
128
|
+
// A sideways chart the author did not ask for got there because its labels
|
|
129
|
+
// are long, so the label column follows the text instead of a fixed share.
|
|
130
|
+
const wideLabels = !sideways && labelLayout === "horizontal";
|
|
131
|
+
const legend = model !== null && showsLegend(model, named);
|
|
132
|
+
return withFallback(component, model !== null, model && plot ? (_jsxs("figure", { className: `lp-chart-frame lp-series-chart lp-series-chart-bar ${variant}${wideLabels ? " labels-wide" : ""}`, "aria-label": accessibilityLabel(component, context) ?? title ?? "Bar chart", children: [title ? _jsx("p", { className: "lp-heading", ...printPart(component, "title", "clamp"), children: title }) : null, legend ? _jsx(SeriesLegend, { component: component, model: model, unit: unit, stroke: false }) : null, horizontal ? (_jsxs("div", { className: "lp-signal-bars lp-series-rows", "aria-hidden": "true", style: { "--lp-series-columns": variant === "stacked" ? 1 : model.series.length }, children: [rows.map((row, rowIndex) => (_jsxs("div", { className: "lp-signal-row lp-series-row", children: [_jsx("span", { className: "lp-meta", ...printPart(component, "barLabel", "clamp"), children: row.label }), _jsx("span", { className: "lp-series-lanes", children: variant === "stacked" ? (_jsx(SeriesLane, { segments: row.segments })) : (model.series.map((entry) => {
|
|
133
|
+
const segment = row.segments.find((item) => item.seriesIndex === entry.index);
|
|
134
|
+
return _jsx(SeriesLane, { seriesIndex: entry.index, segments: segment ? [segment] : [] }, `lane-${entry.index}`);
|
|
135
|
+
})) }), direct ? (_jsx("span", { className: "lp-series-values", children: model.series.map((entry) => {
|
|
136
|
+
const segment = row.segments.find((item) => item.seriesIndex === entry.index);
|
|
137
|
+
return (_jsx("b", { className: "lp-meta", ...printPart(component, "valueLabel", "clamp"), children: segment ? formatChartNumber(segment.value) : "" }, `value-${entry.index}`));
|
|
138
|
+
}) })) : null] }, `row-${rowIndex}`))), axis ? (_jsxs("div", { className: "lp-series-scale", children: [_jsx("span", {}), _jsx("span", { className: "lp-series-scale-track", children: edgeTicks(plot).map((tick) => (_jsx("span", { className: "lp-series-tick", style: tickVariables(plot, tick), children: formatChartNumber(tick) }, `scale-${tick}`))) }), unit ? _jsx("span", { className: "lp-series-unit", ...printPart(component, "unit", "clamp"), children: unit }) : null] })) : null] })) : (_jsxs("div", { className: `lp-series-plot vertical${axis ? "" : " bare"}${direct ? " labelled" : ""}`, "aria-hidden": "true", style: {
|
|
139
|
+
"--lp-series-count": model.labels.length,
|
|
140
|
+
"--lp-series-columns": variant === "stacked" ? 1 : model.series.length,
|
|
141
|
+
"--lp-value-chars": direct ? widestValueLabel(rows) : 0,
|
|
142
|
+
}, children: [!legend && unit ? (_jsx("span", { className: "lp-series-unit", ...printPart(component, "unit", "clamp"), children: unit })) : null, axis ? _jsx(SeriesAxis, { model: plot }) : null, _jsxs("div", { className: "lp-series-area", children: [_jsx(SeriesGrid, { model: plot }), _jsx("div", { className: "lp-series-bands", children: rows.map((row, rowIndex) => (_jsx("div", { className: "lp-series-band", children: variant === "stacked" ? (_jsx("span", { className: "lp-series-slot", children: row.segments.map((segment) => (_jsx("span", { className: `lp-series-bar lp-series-${segment.seriesIndex + 1} stacked${barEndClass(row, segment, variant)}`, style: {
|
|
143
|
+
"--lp-bar-start": `${segment.startPercent}%`,
|
|
144
|
+
"--lp-bar-size": `${segment.sizePercent}%`,
|
|
145
|
+
} }, `segment-${segment.seriesIndex}`))) })) : (model.series.map((entry) => {
|
|
146
|
+
const segment = row.segments.find((item) => item.seriesIndex === entry.index);
|
|
147
|
+
return (_jsx("span", { className: "lp-series-slot", children: segment ? (_jsx("span", { className: `lp-series-bar lp-series-${entry.index + 1}${barEndClass(row, segment, variant)}`, style: {
|
|
148
|
+
"--lp-bar-start": `${segment.startPercent}%`,
|
|
149
|
+
"--lp-bar-size": `${segment.sizePercent}%`,
|
|
150
|
+
}, children: direct ? _jsx("b", { className: "lp-meta", children: formatChartNumber(segment.value) }) : null })) : null }, `slot-${entry.index}`));
|
|
151
|
+
})) }, `band-${rowIndex}`))) })] }), _jsx("div", { className: "lp-series-row-labels", children: model.labels.map((label, index) => (_jsx("span", { className: "lp-meta", ...printPart(component, "barLabel", "clamp"), children: label }, `label-${index}`))) })] })), _jsx(SeriesTable, { model: model, unit: unit, summary: summary }), caption ? _jsx("figcaption", { className: "lp-caption", ...printPart(component, "caption", "clamp"), children: caption }) : null] })) : null);
|
|
152
|
+
};
|
|
153
|
+
const renderLineChart = (component, context) => {
|
|
154
|
+
const base = seriesModel(component, context);
|
|
155
|
+
const model = base ? lineChartModel(base) : null;
|
|
156
|
+
const named = hasSeriesNames(component, context);
|
|
157
|
+
const title = text(component, "title", context) ?? text(component, "heading", context);
|
|
158
|
+
const unit = text(component, "unit", context);
|
|
159
|
+
const summary = text(component, "summary", context);
|
|
160
|
+
const caption = text(component, "caption", context);
|
|
161
|
+
const lines = model ? linePaths(model, LINE_PLOT) : [];
|
|
162
|
+
const everyMarker = model === null || showsPointMarkers(model);
|
|
163
|
+
const legend = model !== null && showsLegend(model, named);
|
|
164
|
+
const endpoints = model ? endpointSeries(model) : [];
|
|
165
|
+
const single = model !== null && model.series.length === 1;
|
|
166
|
+
const first = model?.labels[0];
|
|
167
|
+
const last = model?.labels[model.labels.length - 1];
|
|
168
|
+
return withFallback(component, model !== null && model.labels.length >= 2, model ? (_jsxs("figure", { className: "lp-chart-frame lp-trend lp-series-chart lp-series-chart-line", "aria-label": accessibilityLabel(component, context) ?? title ?? "Line chart", children: [title ? _jsx("p", { className: "lp-heading", ...printPart(component, "title", "clamp"), children: title }) : null, legend ? _jsx(SeriesLegend, { component: component, model: model, unit: unit, stroke: true }) : null, _jsxs("div", { className: "lp-trend-plot-box", "aria-hidden": "true", children: [_jsxs("svg", { className: "lp-trend-plot", viewBox: "0 0 320 124", preserveAspectRatio: "none", children: [_jsx("line", { className: "lp-chart-grid", x1: "18", y1: "18", x2: "302", y2: "18" }), _jsx("line", { className: "lp-chart-grid", x1: "18", y1: "60", x2: "302", y2: "60" }), _jsx("line", { className: "lp-chart-grid", x1: "18", y1: "102", x2: "302", y2: "102" }), lines.map((line) => (_jsx("path", { className: "lp-chart-line-underlay", d: line.path }, `underlay-${line.seriesIndex}`))), lines.map((line) => (_jsx("path", { className: single ? "lp-chart-line accent" : `lp-chart-line lp-series-stroke lp-series-${line.seriesIndex + 1}`, strokeDasharray: SERIES_DASH[line.seriesIndex], d: line.path }, `line-${line.seriesIndex}`)))] }), lines.flatMap((line) => line.points.map((point, index) => {
|
|
169
|
+
const last = index === line.points.length - 1;
|
|
170
|
+
if (!everyMarker && index !== 0 && !last)
|
|
171
|
+
return null;
|
|
172
|
+
return (_jsx("i", { className: single ? `lp-chart-marker ${last ? "accent" : "variant"}` : `lp-chart-marker lp-series-${line.seriesIndex + 1}`, style: markerPlacement(point.x, point.y, last ? 4 : 2.75) }, `point-${line.seriesIndex}-${index}`));
|
|
173
|
+
}))] }), first && last ? (_jsx("div", { className: "lp-trend-endpoints lp-series-endpoints", "aria-hidden": "true", children: [[first, 0], [last, -1]].map(([rowLabel, at], side) => (_jsxs("span", { children: [endpoints.map((entry) => {
|
|
174
|
+
const value = at === 0 ? entry.values[0] : entry.values[entry.values.length - 1];
|
|
175
|
+
// One series needs no attribution; more than one must say
|
|
176
|
+
// which line the number is.
|
|
177
|
+
return single ? (_jsx("b", { children: value === null || value === undefined ? "—" : formatChartNumber(value) }, `value-${entry.field}`)) : (_jsxs("span", { className: "lp-series-endpoint", children: [_jsx("b", { className: `lp-series-${entry.index + 1}`, children: value === null || value === undefined ? "—" : formatChartNumber(value) }), _jsx("small", { children: entry.label })] }, `value-${entry.field}`));
|
|
178
|
+
}), _jsx("small", { children: rowLabel })] }, `side-${side}`))) })) : null, _jsx(SeriesTable, { model: model, unit: unit, summary: summary }), caption ? _jsx("figcaption", { className: "lp-caption", ...printPart(component, "caption", "clamp"), children: caption }) : null] })) : null);
|
|
179
|
+
};
|
|
180
|
+
const renderAreaChart = (component, context) => {
|
|
181
|
+
const base = seriesModel(component, context);
|
|
182
|
+
const variant = text(component, "variant", context) === "stacked" ? "stacked" : "overlay";
|
|
183
|
+
const model = base ? areaChartModel(base, variant) : null;
|
|
184
|
+
const named = hasSeriesNames(component, context);
|
|
185
|
+
const title = text(component, "title", context) ?? text(component, "heading", context);
|
|
186
|
+
const unit = text(component, "unit", context);
|
|
187
|
+
const summary = text(component, "summary", context);
|
|
188
|
+
const caption = text(component, "caption", context);
|
|
189
|
+
const bands = model ? areaBands(model, variant, LINE_PLOT) : [];
|
|
190
|
+
const legend = model !== null && showsLegend(model, named);
|
|
191
|
+
const endpoints = model ? endpointSeries(model) : [];
|
|
192
|
+
const single = model !== null && model.series.length === 1;
|
|
193
|
+
const first = model?.labels[0];
|
|
194
|
+
const last = model?.labels[model.labels.length - 1];
|
|
195
|
+
return withFallback(component, model !== null && model.labels.length >= 2, model ? (_jsxs("figure", { className: `lp-chart-frame lp-trend lp-series-chart lp-series-chart-area ${variant}`, "aria-label": accessibilityLabel(component, context) ?? title ?? "Area chart", children: [title ? _jsx("p", { className: "lp-heading", ...printPart(component, "title", "clamp"), children: title }) : null, legend ? _jsx(SeriesLegend, { component: component, model: model, unit: unit, stroke: true }) : null, _jsxs("svg", { className: "lp-trend-plot", viewBox: "0 0 320 124", preserveAspectRatio: "none", "aria-hidden": "true", children: [_jsx("line", { className: "lp-chart-grid", x1: "18", y1: "18", x2: "302", y2: "18" }), _jsx("line", { className: "lp-chart-grid", x1: "18", y1: "60", x2: "302", y2: "60" }), _jsx("line", { className: "lp-chart-grid", x1: "18", y1: "102", x2: "302", y2: "102" }), bands.map((band) => band.areas.map((area, runIndex) => (_jsx("path", { className: `lp-series-area lp-series-${band.seriesIndex + 1}`, d: area }, `fill-${band.seriesIndex}-${runIndex}`)))), bands.map((band) => band.lines.map((line, runIndex) => (_jsx("path", { className: "lp-series-seam", d: line }, `seam-${band.seriesIndex}-${runIndex}`)))), bands.map((band) => band.lines.map((line, runIndex) => (_jsx("path", { className: `lp-chart-line lp-series-stroke lp-series-${band.seriesIndex + 1}`, strokeDasharray: SERIES_DASH[band.seriesIndex], d: line }, `edge-${band.seriesIndex}-${runIndex}`))))] }), first && last ? (_jsx("div", { className: "lp-trend-endpoints lp-series-endpoints", "aria-hidden": "true", children: [[first, 0], [last, -1]].map(([rowLabel, at], side) => (_jsxs("span", { children: [endpoints.map((entry) => {
|
|
196
|
+
const value = at === 0 ? entry.values[0] : entry.values[entry.values.length - 1];
|
|
197
|
+
return single ? (_jsx("b", { children: value === null || value === undefined ? "—" : formatChartNumber(value) }, `value-${entry.field}`)) : (_jsxs("span", { className: "lp-series-endpoint", children: [_jsx("b", { className: `lp-series-${entry.index + 1}`, children: value === null || value === undefined ? "—" : formatChartNumber(value) }), _jsx("small", { children: entry.label })] }, `value-${entry.field}`));
|
|
198
|
+
}), _jsx("small", { children: rowLabel })] }, `side-${side}`))) })) : null, _jsx(SeriesTable, { model: model, unit: unit, summary: summary }), caption ? _jsx("figcaption", { className: "lp-caption", ...printPart(component, "caption", "clamp"), children: caption }) : null] })) : null);
|
|
199
|
+
};
|
|
200
|
+
/** One scatter marker: its series' shape inside a 12px box, ringed in the surface colour. */
|
|
201
|
+
function ScatterMarkSvg({ className, seriesIndex, style }) {
|
|
202
|
+
const box = SCATTER_MARK_BOX;
|
|
203
|
+
return (_jsx("svg", { className: className, viewBox: `${-box} ${-box} ${box * 2} ${box * 2}`, "aria-hidden": "true", style: style, children: _jsx("path", { className: "lp-scatter-mark-shape", d: SCATTER_MARK_PATHS[scatterMark(seriesIndex)] }) }));
|
|
204
|
+
}
|
|
205
|
+
function scatterModel(component, context) {
|
|
206
|
+
return readScatterChart(records(component, context, "items", "series"), {
|
|
207
|
+
labelField: text(component, "labelField", context),
|
|
208
|
+
seriesFields: resolveStringList(component.seriesFields, context.binding, context.valueFunctions),
|
|
209
|
+
seriesLabels: resolveStringList(component.seriesLabels, context.binding, context.valueFunctions),
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function scatterTickVariables(axis, value) {
|
|
213
|
+
return { "--lp-tick": `${scatterAxisPercent(axis, value)}%` };
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The scatter chart (S47): two value axes, the line chart's hairline rules
|
|
217
|
+
* across the plot, and one marker per row and series. One unnamed series draws
|
|
218
|
+
* accent circles with no legend; several series each take a series colour and
|
|
219
|
+
* their own marker shape, so colour is never the only difference.
|
|
220
|
+
*/
|
|
221
|
+
const renderScatterChart = (component, context) => {
|
|
222
|
+
const model = scatterModel(component, context);
|
|
223
|
+
const named = hasSeriesNames(component, context);
|
|
224
|
+
const title = text(component, "title", context) ?? text(component, "heading", context);
|
|
225
|
+
const unit = text(component, "unit", context);
|
|
226
|
+
const summary = text(component, "summary", context);
|
|
227
|
+
const caption = text(component, "caption", context);
|
|
228
|
+
const xName = text(component, "xAxisLabel", context);
|
|
229
|
+
const legend = model !== null && (model.series.length > 1 || named);
|
|
230
|
+
const single = model !== null && model.series.length === 1 && !named;
|
|
231
|
+
return withFallback(component, model !== null, model ? (_jsxs("figure", { className: "lp-chart-frame lp-series-chart lp-series-chart-scatter", "aria-label": accessibilityLabel(component, context) ?? title ?? "Scatter chart", children: [title ? _jsx("p", { className: "lp-heading", ...printPart(component, "title", "clamp"), children: title }) : null, legend ? _jsx(SeriesLegend, { component: component, model: model, unit: unit, stroke: false, marks: true }) : null, _jsxs("div", { className: "lp-series-plot vertical lp-scatter-axes", "aria-hidden": "true", children: [!legend && unit ? (_jsx("span", { className: "lp-series-unit", ...printPart(component, "unit", "clamp"), children: unit })) : null, _jsx(SeriesAxis, { model: model.y }), _jsxs("div", { className: "lp-series-area", children: [_jsx(SeriesGrid, { model: model.y }), _jsx("div", { className: "lp-scatter-points", children: model.points.map((point) => (_jsx(ScatterMarkSvg, { className: `lp-scatter-mark ${single ? "accent" : `lp-series-${point.seriesIndex + 1}`}`, seriesIndex: point.seriesIndex, style: { left: `${point.left.toFixed(4)}%`, bottom: `${point.bottom.toFixed(4)}%` } }, `point-${point.seriesIndex}-${point.rowIndex}`))) })] }), _jsx("div", { className: "lp-series-scale-track lp-scatter-x-ticks", children: scatterXTicks(model.x).map((tick) => (_jsx("span", { className: `lp-series-tick ${tick.align}`, style: scatterTickVariables(model.x, tick.value), children: tick.label }, `x-${tick.value}`))) }), xName ? (_jsx("span", { className: "lp-series-unit lp-scatter-x-name", ...printPart(component, "axisLabel", "clamp"), children: xName })) : null] }), _jsx(ChartDataTable, { table: scatterTable(model, xName ?? text(component, "labelField", context) ?? "label", unit), summary: summary }), caption ? _jsx("figcaption", { className: "lp-caption", ...printPart(component, "caption", "clamp"), children: caption }) : null] })) : null);
|
|
232
|
+
};
|
|
233
|
+
const renderPieChart = (component, context) => {
|
|
234
|
+
const model = seriesModel(component, context);
|
|
235
|
+
const donut = text(component, "variant", context) === "donut";
|
|
236
|
+
const title = text(component, "title", context) ?? text(component, "heading", context);
|
|
237
|
+
const unit = text(component, "unit", context);
|
|
238
|
+
const summary = text(component, "summary", context);
|
|
239
|
+
const caption = text(component, "caption", context);
|
|
240
|
+
const slices = model ? pieSlices(model, donut) : [];
|
|
241
|
+
return withFallback(component, slices.length > 0, model ? (_jsxs("figure", { className: `lp-chart-frame lp-series-chart lp-pie-chart ${donut ? "donut" : "pie"}`, "aria-label": accessibilityLabel(component, context) ?? title ?? "Share chart", children: [title ? _jsx("p", { className: "lp-heading", ...printPart(component, "title", "clamp"), children: title }) : null, _jsxs("div", { className: "lp-pie-body", "aria-hidden": "true", children: [_jsx("svg", { className: "lp-pie-plot", viewBox: "0 0 100 100", children: slices.map((slice) => {
|
|
242
|
+
const tone = orderedTone(slice.index);
|
|
243
|
+
return (_jsx("path", { className: `lp-pie-slice lp-series-${tone.series}${tone.dim ? " dim" : ""}`, d: slice.path }, `slice-${slice.index}`));
|
|
244
|
+
}) }), _jsxs("div", { className: "lp-pie-labels", children: [unit ? _jsx("span", { className: "lp-series-unit", ...printPart(component, "unit", "clamp"), children: unit }) : null, slices.map((slice) => {
|
|
245
|
+
const tone = orderedTone(slice.index);
|
|
246
|
+
return (_jsxs("span", { className: `lp-pie-label lp-series-${tone.series}${tone.dim ? " dim" : ""}`, children: [_jsx("i", { className: "lp-series-chip" }), _jsx("span", { ...printPart(component, "sliceLabel", "clamp"), children: slice.label }), _jsx("b", { className: "lp-meta", children: formatChartNumber(slice.value) })] }, `label-${slice.index}`));
|
|
247
|
+
})] })] }), _jsx(SeriesTable, { model: model, unit: unit, summary: summary }), caption ? _jsx("figcaption", { className: "lp-caption", ...printPart(component, "caption", "clamp"), children: caption }) : null] })) : null);
|
|
248
|
+
};
|
|
249
|
+
function radarPolygon(points) {
|
|
250
|
+
return points.map((point) => `${point.x.toFixed(2)},${point.y.toFixed(2)}`).join(" ");
|
|
251
|
+
}
|
|
252
|
+
/** SVG's own name for the alignment the placement model chose. */
|
|
253
|
+
const RADAR_TEXT_ANCHOR = { start: "start", middle: "middle", end: "end" };
|
|
254
|
+
/**
|
|
255
|
+
* The radar's drawing: a hairline grid, the faces the caller passes in, and one
|
|
256
|
+
* axis name outside every vertex.
|
|
257
|
+
*
|
|
258
|
+
* The box is laid out at one user unit per pixel and capped at its own width, so
|
|
259
|
+
* the names render at the size `radarLayout` measured them at instead of being
|
|
260
|
+
* scaled with the card. Names are drawn inside the SVG because that is the only
|
|
261
|
+
* way they can be positioned against the geometry without a second measuring
|
|
262
|
+
* pass in the browser, and this renderer produces static markup.
|
|
263
|
+
*/
|
|
264
|
+
function RadarPlot({ layout, count, children }) {
|
|
265
|
+
const grid = radarGrid(count, layout.radius, layout.centre);
|
|
266
|
+
return (_jsx("div", { className: "lp-radar-visual", "aria-hidden": "true", children: _jsxs("svg", { className: "lp-chart lp-radar-plot", viewBox: `0 0 ${layout.width} ${layout.height}`, width: layout.width, height: layout.height, children: [grid.rings.map((ring, index) => (_jsx("polygon", { className: "lp-chart-grid", fill: "none", points: radarPolygon(ring) }, `ring-${index}`))), grid.spokes.map((spoke, index) => (_jsx("line", { className: "lp-chart-grid", x1: layout.centre.x, y1: layout.centre.y, x2: spoke.x.toFixed(2), y2: spoke.y.toFixed(2) }, `spoke-${index}`))), children, layout.labels.map((label) => (_jsx("text", { className: "lp-radar-axis", x: label.x.toFixed(2), y: label.top.toFixed(2), textAnchor: RADAR_TEXT_ANCHOR[label.anchor], dominantBaseline: "hanging", children: label.lines.map((line, index) => (_jsx("tspan", { x: label.x.toFixed(2), dy: index === 0 ? 1 : RADAR_LABEL_LINE, children: line }, `line-${index}`))) }, `axis-${label.index}`)))] }) }));
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Every axis named with its own score, the way the share and ring charts name
|
|
270
|
+
* every slice and track.
|
|
271
|
+
*
|
|
272
|
+
* A radar's numbers are its vertices, and a vertex carries no number a reader
|
|
273
|
+
* can read off the drawing: six axes across two series is twelve values that
|
|
274
|
+
* used to live only in the hidden table. The column heads repeat the series
|
|
275
|
+
* names in the legend's order, because two bare columns of numbers cannot say
|
|
276
|
+
* which vendor they belong to, and the numbers stay in ink — the series colours
|
|
277
|
+
* are drawn to clear a 3:1 shape contrast, not the 4.5:1 that text needs.
|
|
278
|
+
*/
|
|
279
|
+
function RadarValues({ component, model, unit, }) {
|
|
280
|
+
const table = chartTable(model, null);
|
|
281
|
+
return (_jsxs("div", { className: "lp-radar-values", "aria-hidden": "true", style: {
|
|
282
|
+
"--lp-radar-columns": model.series.length,
|
|
283
|
+
"--lp-radar-column": `${radarValueColumn(model)}px`,
|
|
284
|
+
}, children: [unit ? _jsx("span", { className: "lp-series-unit", ...printPart(component, "unit", "clamp"), children: unit }) : null, model.series.length > 1 ? (_jsxs("span", { className: "lp-radar-value head", children: [_jsx("span", {}), model.series.map((entry) => (_jsx("b", { ...printPart(component, "legend", "clamp"), children: entry.label }, `head-${entry.field}`)))] })) : null, table.rows.map((row, rowIndex) => (_jsxs("span", { className: "lp-radar-value", children: [_jsx("span", { ...printPart(component, "axisLabel", "clamp"), children: row.label }), row.cells.map((cell, cellIndex) => (_jsx("b", { children: cell }, `cell-${rowIndex}-${cellIndex}`)))] }, `row-${rowIndex}`)))] }));
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* The radar (S16). Every axis is a row and every series a named field, exactly
|
|
288
|
+
* as the other charts read their data. A second series is told apart by a dash
|
|
289
|
+
* pattern and a lighter fill, not by colour; every axis is named at its own
|
|
290
|
+
* vertex and valued in the list below.
|
|
291
|
+
*/
|
|
292
|
+
function renderRadar(component, context, model) {
|
|
293
|
+
const title = text(component, "title", context) ?? text(component, "heading", context);
|
|
294
|
+
const unit = text(component, "unit", context);
|
|
295
|
+
const summary = text(component, "summary", context);
|
|
296
|
+
const caption = text(component, "caption", context);
|
|
297
|
+
const named = hasSeriesNames(component, context);
|
|
298
|
+
const legend = showsLegend(model, named);
|
|
299
|
+
const layout = radarLayout(model.labels);
|
|
300
|
+
return withFallback(component, model.labels.length >= 3, _jsxs("figure", { className: "lp-chart-frame lp-radar lp-series-chart lp-series-chart-radar", "aria-label": accessibilityLabel(component, context) ?? title ?? "Radar chart", children: [_jsx(Kicker, { component: component, context: context }), title ? _jsx("p", { className: "lp-heading", ...printPart(component, "title", "clamp"), children: title }) : null, legend ? _jsx(SeriesLegend, { component: component, model: model, unit: unit, stroke: true }) : null, _jsx(RadarPlot, { layout: layout, count: model.labels.length, children: [...model.series].reverse().map((entry) => (_jsx("polygon", { className: `lp-radar-face lp-series-${entry.index + 1}`, strokeDasharray: SERIES_DASH[entry.index], points: radarPolygon(radarPoints(entry.values, layout.radius, layout.centre)) }, `face-${entry.field}`))) }), layout.row ? (_jsx("div", { className: "lp-chart-legend", "aria-hidden": "true", children: model.labels.map((label, index) => (_jsx("span", { ...printPart(component, "axisLabel", "clamp"), children: label }, `axis-${index}`))) })) : null, _jsx(RadarValues, { component: component, model: model, unit: legend ? null : unit }), _jsx(SeriesTable, { model: model, unit: unit, summary: summary }), caption ? _jsx("figcaption", { className: "lp-caption", ...printPart(component, "caption", "clamp"), children: caption }) : null] }));
|
|
301
|
+
}
|
|
302
|
+
const renderRadarInsightChart = (component, context) => {
|
|
303
|
+
// Without seriesFields there is nothing to read, so the catalog fallback runs,
|
|
304
|
+
// as for every chart that names its series.
|
|
305
|
+
const model = seriesModel(component, context);
|
|
306
|
+
return model ? renderRadar(component, context, model) : withFallback(component, false, null);
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* The quadrant map (S17) as a scatter: a plot sized from the two named fields,
|
|
310
|
+
* with an optional third read as the marker weight. Quadrant tint
|
|
311
|
+
* belongs to `variant="quadrant"` alone, and nothing is hidden behind a hover —
|
|
312
|
+
* up to eight points are named on the plot, and the table always names them all.
|
|
313
|
+
*/
|
|
314
|
+
function renderScatterPlot(component, context, model) {
|
|
315
|
+
const title = text(component, "title", context) ?? text(component, "heading", context);
|
|
316
|
+
const unit = text(component, "unit", context);
|
|
317
|
+
const summary = text(component, "summary", context);
|
|
318
|
+
const caption = text(component, "caption", context);
|
|
319
|
+
const quadrant = text(component, "variant", context) === "quadrant";
|
|
320
|
+
const points = scatterPoints(model, SCATTER_PLOT);
|
|
321
|
+
// Past the limit the plot stops naming points at all; under it, a name is
|
|
322
|
+
// drawn only where it fits, and the hidden table names every point either way.
|
|
323
|
+
const names = points.length <= SCATTER_LABEL_LIMIT ? scatterLabels(points) : [];
|
|
324
|
+
const [across, up] = model.series;
|
|
325
|
+
// The two axes of a scatter measure two different things, so one `unit` cannot
|
|
326
|
+
// name both: gluing it onto each axis produced "Effort (story points, weighted
|
|
327
|
+
// score, accounts)". The series names are the axis names, and the compiler drops
|
|
328
|
+
// `unit` for this kind rather than letting a replayed bundle re-introduce it.
|
|
329
|
+
const axisName = (entry, fallback) => entry?.label ?? fallback;
|
|
330
|
+
return withFallback(component, points.length > 0, _jsxs("figure", { className: "lp-chart-frame lp-series-chart lp-scatter-chart", "aria-label": accessibilityLabel(component, context) ?? title ?? "Scatter chart", children: [_jsx(Kicker, { component: component, context: context }), title ? _jsx("p", { className: "lp-heading", ...printPart(component, "title", "clamp"), children: title }) : null, _jsxs("div", { className: `lp-quadrant-plot lp-scatter-plot${quadrant ? " quadrant" : ""}`, "aria-hidden": "true", children: [_jsx("span", { className: "lp-quadrant-x", ...printPart(component, "axisLabel", "clamp"), children: axisName(across, "X axis") }), _jsx("span", { className: "lp-quadrant-y", ...printPart(component, "axisLabel", "clamp"), children: axisName(up, "Y axis") }), points.map((point) => (_jsx("span", { className: "lp-scatter-point lp-series-1", style: {
|
|
331
|
+
left: `${point.x}%`,
|
|
332
|
+
bottom: `${100 - point.y}%`,
|
|
333
|
+
"--lp-point-size": `${point.radius * 2}px`,
|
|
334
|
+
} }, `point-${point.index}`))), names.map((name) => {
|
|
335
|
+
const point = points[points.findIndex((item) => item.index === name.index)];
|
|
336
|
+
const part = printPart(component, "pointLabel", "clamp");
|
|
337
|
+
return (_jsx("span", { className: `lp-scatter-name${name.below ? " below" : ""}${name.align === "center" ? "" : ` ${name.align}`}`, ...part, style: {
|
|
338
|
+
...part.style,
|
|
339
|
+
left: `${point.x}%`,
|
|
340
|
+
bottom: `${100 - point.y}%`,
|
|
341
|
+
"--lp-name-gap": `${name.gap}px`,
|
|
342
|
+
}, children: name.label }, `name-${name.index}`));
|
|
343
|
+
})] }), _jsx(SeriesTable, { model: model, unit: unit, summary: summary }), caption ? _jsx("figcaption", { className: "lp-caption", ...printPart(component, "caption", "clamp"), children: caption }) : null] }));
|
|
344
|
+
}
|
|
345
|
+
const renderQuadrantMap = (component, context) => {
|
|
346
|
+
// Without seriesFields there is nothing to read, so the catalog fallback runs,
|
|
347
|
+
// as for every chart that names its series.
|
|
348
|
+
const model = seriesModel(component, context);
|
|
349
|
+
return model ? renderScatterPlot(component, context, model) : withFallback(component, false, null);
|
|
350
|
+
};
|
|
351
|
+
const renderRadialBarChart = (component, context) => {
|
|
352
|
+
const model = seriesModel(component, context);
|
|
353
|
+
const title = text(component, "title", context) ?? text(component, "heading", context);
|
|
354
|
+
const unit = text(component, "unit", context);
|
|
355
|
+
const summary = text(component, "summary", context);
|
|
356
|
+
const caption = text(component, "caption", context);
|
|
357
|
+
const tracks = model ? radialTracks(model) : [];
|
|
358
|
+
return withFallback(component, tracks.length > 0, model ? (_jsxs("figure", { className: "lp-chart-frame lp-series-chart lp-radial-chart", "aria-label": accessibilityLabel(component, context) ?? title ?? "Radial chart", children: [title ? _jsx("p", { className: "lp-heading", ...printPart(component, "title", "clamp"), children: title }) : null, _jsxs("div", { className: "lp-pie-body", "aria-hidden": "true", children: [_jsxs("svg", { className: "lp-pie-plot", viewBox: "0 0 100 100", children: [tracks.map((track) => (_jsx("circle", { className: "lp-radial-track", cx: "50", cy: "50", r: track.radius }, `track-${track.index}`))), tracks.map((track) => (_jsx("path", { className: `lp-radial-arc lp-series-${orderedTone(track.index).series}`, d: track.path }, `arc-${track.index}`)))] }), _jsxs("div", { className: "lp-pie-labels", children: [unit ? _jsx("span", { className: "lp-series-unit", ...printPart(component, "unit", "clamp"), children: unit }) : null, tracks.map((track) => (_jsxs("span", { className: `lp-pie-label lp-series-${orderedTone(track.index).series}`, children: [_jsx("i", { className: "lp-series-chip" }), _jsx("span", { ...printPart(component, "trackLabel", "clamp"), children: track.label }), _jsx("b", { className: "lp-meta", children: formatChartNumber(track.value) })] }, `label-${track.index}`)))] })] }), _jsx(SeriesTable, { model: model, unit: unit, summary: summary }), caption ? _jsx("figcaption", { className: "lp-caption", ...printPart(component, "caption", "clamp"), children: caption }) : null] })) : null);
|
|
359
|
+
};
|
|
360
|
+
const renderDivergingBarChart = (component, context) => {
|
|
361
|
+
const poles = recordValue(component, "poles", context) ?? {};
|
|
362
|
+
const leftPole = stringFromRecord(poles, "left", "negative") ?? "Left";
|
|
363
|
+
const rightPole = stringFromRecord(poles, "right", "positive") ?? "Right";
|
|
364
|
+
const pairs = records(component, context, "items", "pairs").slice(0, 6);
|
|
365
|
+
const title = text(component, "title", context) ?? text(component, "heading", context);
|
|
366
|
+
const caption = text(component, "caption", context);
|
|
367
|
+
const unit = text(component, "unit", context);
|
|
368
|
+
const maximum = Math.max(1, ...pairs.flatMap((pair) => [numberFromRecord(pair, "left") ?? 0, numberFromRecord(pair, "right") ?? 0]));
|
|
369
|
+
return withFallback(component, pairs.length > 0, _jsxs("figure", { className: "lp-chart-frame lp-diverging", "aria-label": accessibilityLabel(component, context) ?? "Diverging bar chart", children: [_jsx(Kicker, { component: component, context: context }), title ? _jsx("p", { className: "lp-title", ...printPart(component, "title", "clamp"), children: title }) : null, unit ? _jsx("span", { className: "lp-series-unit", ...printPart(component, "unit", "clamp"), children: unit }) : null, _jsxs("div", { className: "lp-diverging-poles", children: [_jsx("span", { ...printPart(component, "poleLabel", "clamp"), children: leftPole }), _jsx("span", { ...printPart(component, "poleLabel", "clamp"), children: rightPole })] }), pairs.map((pair, index) => {
|
|
370
|
+
const label = stringFromRecord(pair, "label", "name") ?? `Pair ${index + 1}`;
|
|
371
|
+
const left = numberFromRecord(pair, "left") ?? 0;
|
|
372
|
+
const right = numberFromRecord(pair, "right") ?? 0;
|
|
373
|
+
return (_jsxs("div", { className: "lp-diverging-row", children: [_jsxs("span", { className: "lp-diverging-left", children: [_jsx("i", { style: { width: `${percent(left, maximum)}%` } }), _jsx("b", { children: formatChartNumber(left) })] }), _jsx("span", { className: "lp-meta", ...printPart(component, "rowLabel", "clamp"), children: label }), _jsxs("span", { className: "lp-diverging-right", children: [_jsx("i", { style: { width: `${percent(right, maximum)}%` } }), _jsx("b", { children: formatChartNumber(right) })] })] }, `${label}-${index}`));
|
|
374
|
+
}), caption ? _jsx("figcaption", { className: "lp-caption", ...printPart(component, "caption", "clamp"), children: caption }) : null] }));
|
|
375
|
+
};
|
|
376
|
+
/** The catalog allows 1-10 columns and 1-50 rows and the server refuses anything
|
|
377
|
+
* larger, so the renderer draws every row and column it is given: a nine-row channel
|
|
378
|
+
* table grows downwards and never scrolls vertically, and columns that do not fit
|
|
379
|
+
* scroll sideways beside a pinned row-label column (2026-09-23). */
|
|
380
|
+
/** The class that lines a value column's header and cells up the same way. */
|
|
381
|
+
function alignmentClass(numeric, index) {
|
|
382
|
+
return columnAlignment(numeric, index) === "end" ? "numeric" : "text";
|
|
383
|
+
}
|
|
384
|
+
const renderComparisonTable = (component, context) => {
|
|
385
|
+
const columns = records(component, context, "columns", "cols");
|
|
386
|
+
const rows = records(component, context, "items", "rows");
|
|
387
|
+
const caption = text(component, "caption", context);
|
|
388
|
+
const numeric = numericColumns(rows, Math.max(columns.length, ...rows.map((row) => (Array.isArray(row.cells) ? row.cells.length : 0))));
|
|
389
|
+
// The scroll region is named only when the component carries a name. The caption
|
|
390
|
+
// is a disclosure sentence, not a name, so an unnamed table leaves the scroller a
|
|
391
|
+
// plain focus stop rather than an anonymous group.
|
|
392
|
+
const label = accessibilityLabel(component, context) ?? text(component, "label", context);
|
|
393
|
+
return withFallback(component, rows.length > 0, _jsxs("figure", { className: "lp-comparison-table", "aria-label": accessibilityLabel(component, context), children: [_jsx(Kicker, { component: component, context: context }), _jsx("div", { className: "lp-comparison-scroll", tabIndex: 0, ...(label ? { role: "group", "aria-label": label } : {}), children: _jsxs("table", { style: { "--lp-table-columns": columns.length }, children: [columns.length > 0 ? (_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col" }), columns.map((column, index) => {
|
|
394
|
+
const unit = columnUnit(column);
|
|
395
|
+
return (_jsxs("th", { scope: "col", className: alignmentClass(numeric, index), children: [_jsx("span", { ...printPart(component, "colHeader", "clamp"), children: stringFromRecord(column, "label", "title", "name") ?? `Column ${index + 1}` }), unit ? (_jsxs("span", { className: "lp-comparison-unit", children: [_jsx("span", { className: "a2ui-visually-hidden", children: " (" }), _jsx("span", { ...printPart(component, "colUnit", "clamp"), children: unit }), _jsx("span", { className: "a2ui-visually-hidden", children: ")" })] })) : null] }, `column-${index}`));
|
|
396
|
+
})] }) })) : null, _jsx("tbody", { children: rows.map((row, rowIndex) => {
|
|
397
|
+
const rawCells = row.cells;
|
|
398
|
+
const cells = Array.isArray(rawCells) ? rawCells : [];
|
|
399
|
+
return (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: _jsx("span", { ...printPart(component, "rowLabel", "clamp"), children: stringFromRecord(row, "label", "title", "name") ?? `Row ${rowIndex + 1}` }) }), cells.map((cell, cellIndex) => {
|
|
400
|
+
const record = isRecord(cell) ? cell : null;
|
|
401
|
+
const previous = record ? cellText(record.previous) : null;
|
|
402
|
+
const tone = cellTone(cell);
|
|
403
|
+
const classes = [
|
|
404
|
+
record?.highlight === true ? "highlight" : "",
|
|
405
|
+
alignmentClass(numeric, cellIndex),
|
|
406
|
+
].filter(Boolean).join(" ");
|
|
407
|
+
const value = (_jsx("span", { ...printPart(component, "cell", "clamp"), children: (record ? cellText(record.value) ?? cellText(record.label) : cellText(cell)) ?? "" }));
|
|
408
|
+
return (_jsxs("td", { className: classes || undefined, children: [tone ? _jsx("span", { className: "lp-comparison-tone", "data-tone": tone, children: value }) : value, previous !== null ? (_jsxs("span", { className: "lp-comparison-previous", ...printPart(component, "cellPrevious", "clamp"), children: [_jsx("span", { className: "a2ui-visually-hidden", children: "previous: " }), previous] })) : null] }, `cell-${rowIndex}-${cellIndex}`));
|
|
409
|
+
})] }, `row-${rowIndex}`));
|
|
410
|
+
}) })] }) }), caption ? _jsx("figcaption", { className: "lp-caption", ...printPart(component, "caption", "clamp"), children: caption }) : null] }));
|
|
411
|
+
};
|
|
412
|
+
export { renderBarChart, renderLineChart, renderAreaChart, renderPieChart, renderScatterChart, renderRadialBarChart, renderRadarInsightChart, renderQuadrantMap, renderDivergingBarChart, renderComparisonTable, };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cell reading for the comparison table, kept free of JSX so it can be tested.
|
|
3
|
+
*
|
|
4
|
+
* The catalog allows a cell `value` (and `previous`) to be text, a number or a
|
|
5
|
+
* boolean. A JSON number is printed the way a chart prints its values
|
|
6
|
+
* (`formatChartNumber`: "12,400", "−620", no rounding); text is drawn exactly as
|
|
7
|
+
* written, with no unit conversion. Compose and SwiftUI print through the same
|
|
8
|
+
* rule (`displayNumber`).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The text a cell field, or a metric strip value, is drawn as, or null when there
|
|
12
|
+
* is nothing to draw. Numbers are grouped with commas and take a true minus sign;
|
|
13
|
+
* strings and booleans are printed as sent.
|
|
14
|
+
*/
|
|
15
|
+
export declare function cellText(value: unknown): string | null;
|
|
16
|
+
/** The status tones a cell may carry: the chip tone set (`ui-chip`, `LPChip_Default`). */
|
|
17
|
+
export declare const CELL_TONES: readonly ["default", "accent", "info", "positive", "warning", "danger"];
|
|
18
|
+
export type CellTone = (typeof CELL_TONES)[number];
|
|
19
|
+
/**
|
|
20
|
+
* A cell's status tone, or null when it has none. The server refuses any other
|
|
21
|
+
* value; a hand-written or older surface that still carries one is drawn plain
|
|
22
|
+
* rather than guessed at. The tone only colours the cell: its text has to say
|
|
23
|
+
* the state ("Submitted", "Missing"), so nothing is lost without colour.
|
|
24
|
+
*/
|
|
25
|
+
export declare function cellTone(cell: unknown): CellTone | null;
|
|
26
|
+
/**
|
|
27
|
+
* A column's unit ("SGD", "%", "days"), or null when it has none. It is display
|
|
28
|
+
* only: it never changes the values, and whether the column lines up at the end
|
|
29
|
+
* still depends only on its values being JSON numbers.
|
|
30
|
+
*/
|
|
31
|
+
export declare function columnUnit(column: unknown): string | null;
|
|
32
|
+
/** A cell's `value`: a record's field, or the cell itself when it is a bare scalar. */
|
|
33
|
+
export declare function cellValue(cell: unknown): unknown;
|
|
34
|
+
/** Where a value column's text sits in its box: at the line's end for numbers, centred otherwise. */
|
|
35
|
+
export type ColumnAlignment = "end" | "center";
|
|
36
|
+
/**
|
|
37
|
+
* How one value column lines up. The header and every cell of the column use the
|
|
38
|
+
* same answer, so a header always sits over its values: a numeric column puts
|
|
39
|
+
* both at the end of the line (the right in a left-to-right page, the left in a
|
|
40
|
+
* right-to-left one), a text column centres both. The pinned row-label column is
|
|
41
|
+
* not a value column; it stays at the start.
|
|
42
|
+
*/
|
|
43
|
+
export declare function columnAlignment(numeric: readonly boolean[], index: number): ColumnAlignment;
|
|
44
|
+
/**
|
|
45
|
+
* Which columns hold numbers. A column is numeric when it has at least one value
|
|
46
|
+
* and every value present in it is a JSON number; a missing cell does not count
|
|
47
|
+
* against it, a numeric-looking string ("12,000", "3.1%") does. Numeric columns
|
|
48
|
+
* are right-aligned with tabular figures, header included, so digits line up.
|
|
49
|
+
*/
|
|
50
|
+
export declare function numericColumns(rows: readonly unknown[], columnCount: number): boolean[];
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cell reading for the comparison table, kept free of JSX so it can be tested.
|
|
3
|
+
*
|
|
4
|
+
* The catalog allows a cell `value` (and `previous`) to be text, a number or a
|
|
5
|
+
* boolean. A JSON number is printed the way a chart prints its values
|
|
6
|
+
* (`formatChartNumber`: "12,400", "−620", no rounding); text is drawn exactly as
|
|
7
|
+
* written, with no unit conversion. Compose and SwiftUI print through the same
|
|
8
|
+
* rule (`displayNumber`).
|
|
9
|
+
*/
|
|
10
|
+
import { formatChartNumber } from "./seriesCharts.js";
|
|
11
|
+
/**
|
|
12
|
+
* The text a cell field, or a metric strip value, is drawn as, or null when there
|
|
13
|
+
* is nothing to draw. Numbers are grouped with commas and take a true minus sign;
|
|
14
|
+
* strings and booleans are printed as sent.
|
|
15
|
+
*/
|
|
16
|
+
export function cellText(value) {
|
|
17
|
+
if (typeof value === "string")
|
|
18
|
+
return value.length > 0 ? value : null;
|
|
19
|
+
if (typeof value === "number")
|
|
20
|
+
return Number.isFinite(value) ? formatChartNumber(value) : null;
|
|
21
|
+
if (typeof value === "boolean")
|
|
22
|
+
return String(value);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
/** The status tones a cell may carry: the chip tone set (`ui-chip`, `LPChip_Default`). */
|
|
26
|
+
export const CELL_TONES = ["default", "accent", "info", "positive", "warning", "danger"];
|
|
27
|
+
/**
|
|
28
|
+
* A cell's status tone, or null when it has none. The server refuses any other
|
|
29
|
+
* value; a hand-written or older surface that still carries one is drawn plain
|
|
30
|
+
* rather than guessed at. The tone only colours the cell: its text has to say
|
|
31
|
+
* the state ("Submitted", "Missing"), so nothing is lost without colour.
|
|
32
|
+
*/
|
|
33
|
+
export function cellTone(cell) {
|
|
34
|
+
if (cell === null || typeof cell !== "object" || Array.isArray(cell))
|
|
35
|
+
return null;
|
|
36
|
+
const tone = cell.tone;
|
|
37
|
+
return typeof tone === "string" && CELL_TONES.includes(tone) ? tone : null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A column's unit ("SGD", "%", "days"), or null when it has none. It is display
|
|
41
|
+
* only: it never changes the values, and whether the column lines up at the end
|
|
42
|
+
* still depends only on its values being JSON numbers.
|
|
43
|
+
*/
|
|
44
|
+
export function columnUnit(column) {
|
|
45
|
+
if (column === null || typeof column !== "object" || Array.isArray(column))
|
|
46
|
+
return null;
|
|
47
|
+
const unit = column.unit;
|
|
48
|
+
return typeof unit === "string" && unit.trim().length > 0 ? unit : null;
|
|
49
|
+
}
|
|
50
|
+
/** A cell's `value`: a record's field, or the cell itself when it is a bare scalar. */
|
|
51
|
+
export function cellValue(cell) {
|
|
52
|
+
if (cell !== null && typeof cell === "object" && !Array.isArray(cell)) {
|
|
53
|
+
return cell.value;
|
|
54
|
+
}
|
|
55
|
+
return cell;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* How one value column lines up. The header and every cell of the column use the
|
|
59
|
+
* same answer, so a header always sits over its values: a numeric column puts
|
|
60
|
+
* both at the end of the line (the right in a left-to-right page, the left in a
|
|
61
|
+
* right-to-left one), a text column centres both. The pinned row-label column is
|
|
62
|
+
* not a value column; it stays at the start.
|
|
63
|
+
*/
|
|
64
|
+
export function columnAlignment(numeric, index) {
|
|
65
|
+
return numeric[index] === true ? "end" : "center";
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Which columns hold numbers. A column is numeric when it has at least one value
|
|
69
|
+
* and every value present in it is a JSON number; a missing cell does not count
|
|
70
|
+
* against it, a numeric-looking string ("12,000", "3.1%") does. Numeric columns
|
|
71
|
+
* are right-aligned with tabular figures, header included, so digits line up.
|
|
72
|
+
*/
|
|
73
|
+
export function numericColumns(rows, columnCount) {
|
|
74
|
+
return Array.from({ length: columnCount }, (_unused, index) => {
|
|
75
|
+
let seen = false;
|
|
76
|
+
for (const row of rows) {
|
|
77
|
+
const cells = row !== null && typeof row === "object" ? row.cells : undefined;
|
|
78
|
+
if (!Array.isArray(cells) || index >= cells.length)
|
|
79
|
+
continue;
|
|
80
|
+
const value = cellValue(cells[index]);
|
|
81
|
+
if (value === null || value === undefined)
|
|
82
|
+
continue;
|
|
83
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
84
|
+
return false;
|
|
85
|
+
seen = true;
|
|
86
|
+
}
|
|
87
|
+
return seen;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ComponentRenderer } from "../runtime.tsx";
|
|
2
|
+
declare const renderArticleHeader: ComponentRenderer;
|
|
3
|
+
declare const renderStoryCover: ComponentRenderer;
|
|
4
|
+
declare const renderLede: ComponentRenderer;
|
|
5
|
+
declare const renderBodyProse: ComponentRenderer;
|
|
6
|
+
declare const renderPullQuote: ComponentRenderer;
|
|
7
|
+
declare const renderFeatureImage: ComponentRenderer;
|
|
8
|
+
declare const renderNumberedSection: ComponentRenderer;
|
|
9
|
+
/** card_group: term cards with kicker, heading, and items[{title, body}]. */
|
|
10
|
+
declare const renderQuoteWall: ComponentRenderer;
|
|
11
|
+
declare const renderMediaGallery: ComponentRenderer;
|
|
12
|
+
declare const renderTranscriptExcerpt: ComponentRenderer;
|
|
13
|
+
export { renderArticleHeader, renderStoryCover, renderLede, renderBodyProse, renderPullQuote, renderFeatureImage, renderNumberedSection, renderQuoteWall, renderMediaGallery, renderTranscriptExcerpt, };
|