@seed-ship/mcp-ui-solid 6.23.0 → 6.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +167 -0
- package/README.md +154 -2
- package/dist/components/ActionGroupRenderer.cjs +6 -6
- package/dist/components/ActionGroupRenderer.cjs.map +1 -1
- package/dist/components/ActionGroupRenderer.js +6 -6
- package/dist/components/ActionGroupRenderer.js.map +1 -1
- package/dist/components/AutocompleteDropdown.cjs +6 -6
- package/dist/components/AutocompleteDropdown.cjs.map +1 -1
- package/dist/components/AutocompleteDropdown.js +6 -6
- package/dist/components/AutocompleteDropdown.js.map +1 -1
- package/dist/components/AutocompleteFormField.cjs +6 -5
- package/dist/components/AutocompleteFormField.cjs.map +1 -1
- package/dist/components/AutocompleteFormField.d.ts.map +1 -1
- package/dist/components/AutocompleteFormField.js +6 -5
- package/dist/components/AutocompleteFormField.js.map +1 -1
- package/dist/components/ChartJSRenderer.cjs +406 -70
- package/dist/components/ChartJSRenderer.cjs.map +1 -1
- package/dist/components/ChartJSRenderer.d.ts.map +1 -1
- package/dist/components/ChartJSRenderer.js +407 -71
- package/dist/components/ChartJSRenderer.js.map +1 -1
- package/dist/components/ChatPrompt.cjs +5 -5
- package/dist/components/ChatPrompt.cjs.map +1 -1
- package/dist/components/ChatPrompt.js +5 -5
- package/dist/components/ChatPrompt.js.map +1 -1
- package/dist/components/ComponentToolbar.cjs +5 -5
- package/dist/components/ComponentToolbar.cjs.map +1 -1
- package/dist/components/ComponentToolbar.js +5 -5
- package/dist/components/ComponentToolbar.js.map +1 -1
- package/dist/components/DegradedFallback.cjs +35 -3
- package/dist/components/DegradedFallback.cjs.map +1 -1
- package/dist/components/DegradedFallback.d.ts +7 -0
- package/dist/components/DegradedFallback.d.ts.map +1 -1
- package/dist/components/DegradedFallback.js +35 -3
- package/dist/components/DegradedFallback.js.map +1 -1
- package/dist/components/ExpandableWrapper.cjs +10 -7
- package/dist/components/ExpandableWrapper.cjs.map +1 -1
- package/dist/components/ExpandableWrapper.d.ts.map +1 -1
- package/dist/components/ExpandableWrapper.js +10 -7
- package/dist/components/ExpandableWrapper.js.map +1 -1
- package/dist/components/FormFieldRenderer.cjs +13 -12
- package/dist/components/FormFieldRenderer.cjs.map +1 -1
- package/dist/components/FormFieldRenderer.d.ts.map +1 -1
- package/dist/components/FormFieldRenderer.js +13 -12
- package/dist/components/FormFieldRenderer.js.map +1 -1
- package/dist/components/FormRenderer.cjs +1 -1
- package/dist/components/FormRenderer.cjs.map +1 -1
- package/dist/components/FormRenderer.js +1 -1
- package/dist/components/FormRenderer.js.map +1 -1
- package/dist/components/GenerativeUIErrorBoundary.cjs +1 -1
- package/dist/components/GenerativeUIErrorBoundary.cjs.map +1 -1
- package/dist/components/GenerativeUIErrorBoundary.js +1 -1
- package/dist/components/GenerativeUIErrorBoundary.js.map +1 -1
- package/dist/components/GhostText.cjs +2 -2
- package/dist/components/GhostText.cjs.map +1 -1
- package/dist/components/GhostText.js +2 -2
- package/dist/components/GhostText.js.map +1 -1
- package/dist/components/GraphRenderer.cjs +100 -29
- package/dist/components/GraphRenderer.cjs.map +1 -1
- package/dist/components/GraphRenderer.d.ts +1 -1
- package/dist/components/GraphRenderer.d.ts.map +1 -1
- package/dist/components/GraphRenderer.js +100 -29
- package/dist/components/GraphRenderer.js.map +1 -1
- package/dist/components/MissingValue.cjs +43 -0
- package/dist/components/MissingValue.cjs.map +1 -0
- package/dist/components/MissingValue.d.ts +27 -0
- package/dist/components/MissingValue.d.ts.map +1 -0
- package/dist/components/MissingValue.js +43 -0
- package/dist/components/MissingValue.js.map +1 -0
- package/dist/components/ModalRenderer.cjs +39 -31
- package/dist/components/ModalRenderer.cjs.map +1 -1
- package/dist/components/ModalRenderer.d.ts.map +1 -1
- package/dist/components/ModalRenderer.js +40 -32
- package/dist/components/ModalRenderer.js.map +1 -1
- package/dist/components/PortalDropdownMenu.cjs +6 -3
- package/dist/components/PortalDropdownMenu.cjs.map +1 -1
- package/dist/components/PortalDropdownMenu.d.ts.map +1 -1
- package/dist/components/PortalDropdownMenu.js +7 -4
- package/dist/components/PortalDropdownMenu.js.map +1 -1
- package/dist/components/ScratchpadPanel.cjs +38 -44
- package/dist/components/ScratchpadPanel.cjs.map +1 -1
- package/dist/components/ScratchpadPanel.d.ts.map +1 -1
- package/dist/components/ScratchpadPanel.js +38 -44
- package/dist/components/ScratchpadPanel.js.map +1 -1
- package/dist/components/UIResourceRenderer.cjs +255 -217
- package/dist/components/UIResourceRenderer.cjs.map +1 -1
- package/dist/components/UIResourceRenderer.d.ts.map +1 -1
- package/dist/components/UIResourceRenderer.js +255 -217
- package/dist/components/UIResourceRenderer.js.map +1 -1
- package/dist/components/chart-data-table.cjs +30 -5
- package/dist/components/chart-data-table.cjs.map +1 -1
- package/dist/components/chart-data-table.d.ts +18 -1
- package/dist/components/chart-data-table.d.ts.map +1 -1
- package/dist/components/chart-data-table.js +30 -5
- package/dist/components/chart-data-table.js.map +1 -1
- package/dist/components/chart-missing-plugin.cjs +194 -0
- package/dist/components/chart-missing-plugin.cjs.map +1 -0
- package/dist/components/chart-missing-plugin.d.ts +129 -0
- package/dist/components/chart-missing-plugin.d.ts.map +1 -0
- package/dist/components/chart-missing-plugin.js +194 -0
- package/dist/components/chart-missing-plugin.js.map +1 -0
- package/dist/context/MCPUIStringsContext.cjs +12 -1
- package/dist/context/MCPUIStringsContext.cjs.map +1 -1
- package/dist/context/MCPUIStringsContext.d.ts +62 -0
- package/dist/context/MCPUIStringsContext.d.ts.map +1 -1
- package/dist/context/MCPUIStringsContext.js +12 -1
- package/dist/context/MCPUIStringsContext.js.map +1 -1
- package/dist/services/component-registry.cjs +9 -2
- package/dist/services/component-registry.cjs.map +1 -1
- package/dist/services/component-registry.d.ts.map +1 -1
- package/dist/services/component-registry.js +9 -2
- package/dist/services/component-registry.js.map +1 -1
- package/dist/services/validation.cjs +31 -8
- package/dist/services/validation.cjs.map +1 -1
- package/dist/services/validation.d.ts.map +1 -1
- package/dist/services/validation.js +31 -8
- package/dist/services/validation.js.map +1 -1
- package/dist/types/index.d.ts +14 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/degraded-projections.cjs +19 -3
- package/dist/utils/degraded-projections.cjs.map +1 -1
- package/dist/utils/degraded-projections.d.ts +22 -2
- package/dist/utils/degraded-projections.d.ts.map +1 -1
- package/dist/utils/degraded-projections.js +19 -3
- package/dist/utils/degraded-projections.js.map +1 -1
- package/dist/utils/math-markdown.cjs +1 -1
- package/dist/utils/math-markdown.cjs.map +1 -1
- package/dist/utils/math-markdown.js +1 -1
- package/dist/utils/math-markdown.js.map +1 -1
- package/dist/utils/missing-value.cjs +60 -0
- package/dist/utils/missing-value.cjs.map +1 -0
- package/dist/utils/missing-value.d.ts +79 -0
- package/dist/utils/missing-value.d.ts.map +1 -0
- package/dist/utils/missing-value.js +60 -0
- package/dist/utils/missing-value.js.map +1 -0
- package/dist/utils/theme.cjs +91 -0
- package/dist/utils/theme.cjs.map +1 -0
- package/dist/utils/theme.d.ts +11 -0
- package/dist/utils/theme.d.ts.map +1 -0
- package/dist/utils/theme.js +91 -0
- package/dist/utils/theme.js.map +1 -0
- package/docs/SECURITY-DEPENDENCIES.md +81 -0
- package/docs/THEMING.md +205 -0
- package/package.json +7 -5
- package/src/components/ActionGroupRenderer.tsx +6 -6
- package/src/components/AutocompleteDropdown.tsx +17 -17
- package/src/components/AutocompleteFormField.tsx +10 -9
- package/src/components/ChartJSRenderer.tsx +609 -212
- package/src/components/ChatPrompt.tsx +16 -16
- package/src/components/ComponentToolbar.tsx +5 -5
- package/src/components/DegradedFallback.tsx +33 -11
- package/src/components/ExpandableWrapper.tsx +15 -11
- package/src/components/FormFieldRenderer.tsx +52 -51
- package/src/components/FormRenderer.tsx +12 -12
- package/src/components/GenerativeUIErrorBoundary.tsx +6 -6
- package/src/components/GhostText.tsx +7 -7
- package/src/components/GraphRenderer.tsx +83 -67
- package/src/components/MissingValue.tsx +61 -0
- package/src/components/ModalRenderer.tsx +11 -5
- package/src/components/PortalDropdownMenu.tsx +6 -2
- package/src/components/ScratchpadPanel.tsx +144 -141
- package/src/components/UIResourceRenderer.tsx +143 -110
- package/src/components/chart-data-table.ts +50 -6
- package/src/components/chart-missing-plugin.ts +336 -0
- package/src/context/MCPUIStringsContext.tsx +76 -0
- package/src/services/component-registry.ts +10 -2
- package/src/services/validation.ts +44 -9
- package/src/styles/autocomplete.css +53 -53
- package/src/types/index.ts +13 -1
- package/src/utils/degraded-projections.ts +44 -4
- package/src/utils/math-markdown.ts +1 -1
- package/src/utils/missing-value.ts +127 -0
- package/src/utils/theme.ts +101 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Missing values in a Chart.js chart (v6.24.0) — everything the renderer adds
|
|
3
|
+
* to its Chart.js config when a payload says a value is MISSING (`null`).
|
|
4
|
+
*
|
|
5
|
+
* The rule: absence is never zero. Chart.js already keeps the slot of a `null`
|
|
6
|
+
* (no label dropped) and draws nothing for it; what it does not do is make the
|
|
7
|
+
* absence READABLE. A null bar is a zero-height bar that is skipped when
|
|
8
|
+
* drawn, a null line point is a hole the line may bridge (`spanGaps`), and the
|
|
9
|
+
* legend, tooltip and axis know nothing of either. This module supplies:
|
|
10
|
+
*
|
|
11
|
+
* - {@link createMissingValuesPlugin} — a PER-CHART plugin (never
|
|
12
|
+
* `Chart.register`ed, so it can leak into no other chart) that outlines a
|
|
13
|
+
* dashed stub where a bar should have been (not on stacked or overlaid
|
|
14
|
+
* bars, whose baseline belongs to another series), and says "no data" on a
|
|
15
|
+
* chart with nothing to draw;
|
|
16
|
+
* - {@link createMissingLegendGenerator} — marks a fully-missing series in the
|
|
17
|
+
* legend;
|
|
18
|
+
* - {@link createTooltipLabel} — names a missing value, and appends the unit;
|
|
19
|
+
* - {@link withDatasetsNoGapSpan} — the shallow-cloned data with
|
|
20
|
+
* `spanGaps: false`;
|
|
21
|
+
* - {@link applyUnitAxisTitle} — the unit as the value axis title.
|
|
22
|
+
*
|
|
23
|
+
* Runtime-free on purpose (no `solid-js`, no `chart.js` import): the renderer
|
|
24
|
+
* hands in the Chart.js pieces it loaded and the chrome strings (lazily, as
|
|
25
|
+
* getters, so a late locale change is honoured at draw time). Every function
|
|
26
|
+
* is defensive — a drawing hook that throws would blank the whole chart.
|
|
27
|
+
*
|
|
28
|
+
* Chart.js 4.5.1 facts this relies on (verified in `dist/chart.js`):
|
|
29
|
+
* - a bar whose parsed value is `null` gets `base = head = vScale.getBasePixel()`
|
|
30
|
+
* and no `skip` flag (BarController.updateElements), and `BarController.draw`
|
|
31
|
+
* skips it (`getParsed(i)[vScale.axis] !== null`) — so nothing is painted;
|
|
32
|
+
* - the bar element still carries its true index-axis thickness (`width` for a
|
|
33
|
+
* vertical bar, `height` for a horizontal one).
|
|
34
|
+
*/
|
|
35
|
+
import type { MCPUIStrings } from '../context/MCPUIStringsContext';
|
|
36
|
+
type Strings = Required<MCPUIStrings>;
|
|
37
|
+
/** Length, in px along the value axis, of the dashed stub of a missing bar. */
|
|
38
|
+
export declare const MISSING_BAR_STUB_LENGTH = 12;
|
|
39
|
+
/** Stroke of the stub when the dataset names no border colour. */
|
|
40
|
+
export declare const MISSING_BAR_FALLBACK_COLOR = "#9ca3af";
|
|
41
|
+
/** Colour of the centred "no data" text. */
|
|
42
|
+
export declare const NO_DATA_TEXT_COLOR = "#6b7280";
|
|
43
|
+
/**
|
|
44
|
+
* The category of convention line a chart shows under its canvas:
|
|
45
|
+
* `'gaps'` (a line breaks), `'bars'` (a dashed outline stands in for the
|
|
46
|
+
* bar) or `'omitted'` (nothing is drawn: scatter, bubble, stacked bars).
|
|
47
|
+
*/
|
|
48
|
+
export type MissingNoteKind = 'gaps' | 'bars' | 'omitted';
|
|
49
|
+
/**
|
|
50
|
+
* Whether a bar chart's bars are stacked or overlaid (`stacked` on either
|
|
51
|
+
* axis). A missing bar there has no slot of its own at the baseline — the
|
|
52
|
+
* baseline belongs to the series below — so no dashed outline is drawn.
|
|
53
|
+
*/
|
|
54
|
+
export declare function isStackedChart(options: any): boolean;
|
|
55
|
+
/** Which convention note a chart gets: how ITS missing values are drawn. */
|
|
56
|
+
export declare function missingNoteKind(chartType: string | undefined, options?: any): MissingNoteKind;
|
|
57
|
+
/**
|
|
58
|
+
* Chart.js data with every dataset shallow-cloned and `spanGaps: false`, so a
|
|
59
|
+
* line breaks at a missing value instead of joining its neighbours. Never
|
|
60
|
+
* mutates its input; `labels` and every other key are carried by reference.
|
|
61
|
+
*/
|
|
62
|
+
export declare function withDatasetsNoGapSpan<D extends {
|
|
63
|
+
datasets?: unknown;
|
|
64
|
+
}>(data: D): D;
|
|
65
|
+
type LegendGenerator = (chart: any) => any[];
|
|
66
|
+
/**
|
|
67
|
+
* Wraps a Chart.js legend label generator so a fully-missing dataset reads
|
|
68
|
+
* `"{series} (no data)"` (`strings.chartLegendNoData`). Every other item is
|
|
69
|
+
* passed through untouched.
|
|
70
|
+
*/
|
|
71
|
+
export declare function createMissingLegendGenerator(base: LegendGenerator, fullyMissing: readonly boolean[], getStrings: () => Strings): LegendGenerator;
|
|
72
|
+
/** Whether a Chart.js tooltip item stands for a missing value. */
|
|
73
|
+
export declare function isMissingTooltipItem(item: any): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Tooltip `label` callback: names a missing value (`"{series}: Missing
|
|
76
|
+
* value"`) and, with a `unit`, appends it to a present one. Otherwise it is
|
|
77
|
+
* Chart.js's default composition (dataset label, `": "`, formatted value) —
|
|
78
|
+
* including its `mode: 'dataset'` branch, which prefixes the CATEGORY label
|
|
79
|
+
* instead, since every item of that tooltip belongs to the same dataset.
|
|
80
|
+
* Hence a regular function: Chart.js calls it with the tooltip as `this`.
|
|
81
|
+
*
|
|
82
|
+
* `unit` is left off scatter and bubble tooltips: their formatted value is the
|
|
83
|
+
* pair `(x, y)`, to which one unit does not belong.
|
|
84
|
+
*/
|
|
85
|
+
export declare function createTooltipLabel(getStrings: () => Strings, unit: string | undefined, chartType: string | undefined): (this: any, item: any) => string;
|
|
86
|
+
/**
|
|
87
|
+
* Sets the chart's `unit` as the title of its value axis, in place on the
|
|
88
|
+
* `options` object the renderer just built (never on the payload's).
|
|
89
|
+
*
|
|
90
|
+
* Only bar, line, scatter and bubble have a value axis to title. The value
|
|
91
|
+
* axis is `y`, or `x` when the index axis is `y` (a horizontal bar or line).
|
|
92
|
+
* An existing `scales[axis].title` is the payload's own word and is kept; the
|
|
93
|
+
* rest of the scale config (a `timeAxis` block sets `scales.x`) is kept too.
|
|
94
|
+
*/
|
|
95
|
+
export declare function applyUnitAxisTitle(options: any, chartType: string | undefined, unit: string | undefined): void;
|
|
96
|
+
export interface MissingValuesPluginOptions {
|
|
97
|
+
/** At least one dataset and every one of them has no observed value. */
|
|
98
|
+
allMissing: boolean;
|
|
99
|
+
/** Lazy: read at draw time. */
|
|
100
|
+
getNoDataText: () => string;
|
|
101
|
+
/** Lazy: `Chart.defaults.font.family`, when the build exposes it. */
|
|
102
|
+
getFontFamily?: () => string | undefined;
|
|
103
|
+
/** Lazy host theme override; omission retains the historical grey. */
|
|
104
|
+
getTextColor?: () => string | undefined;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Draws a dashed outline stub for every missing bar of every visible,
|
|
108
|
+
* non-stacked bar dataset, so a missing value is a visible mark, not a bar
|
|
109
|
+
* that "is" zero.
|
|
110
|
+
*
|
|
111
|
+
* The stub sits on the value-axis base, as thick as the bar would have been,
|
|
112
|
+
* and runs {@link MISSING_BAR_STUB_LENGTH}px toward the middle of the chart
|
|
113
|
+
* area (up from a bottom baseline, down from a top one, right from a left
|
|
114
|
+
* one). Clipped to the chart area.
|
|
115
|
+
*/
|
|
116
|
+
export declare function drawMissingBarStubs(chart: any): void;
|
|
117
|
+
/** Draws `text` centred in the chart area (a chart with nothing to plot). */
|
|
118
|
+
export declare function drawNoDataText(chart: any, text: string, fontFamily?: string, color?: string): void;
|
|
119
|
+
/**
|
|
120
|
+
* The per-chart plugin object. Passed as `config.plugins = [plugin]`: Chart.js
|
|
121
|
+
* scopes it to that one chart. Both hooks swallow their own errors — a
|
|
122
|
+
* decoration must never take the chart down.
|
|
123
|
+
*/
|
|
124
|
+
export declare function createMissingValuesPlugin(options: MissingValuesPluginOptions): {
|
|
125
|
+
id: string;
|
|
126
|
+
afterDatasetsDraw(chart: any): void;
|
|
127
|
+
};
|
|
128
|
+
export {};
|
|
129
|
+
//# sourceMappingURL=chart-missing-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-missing-plugin.d.ts","sourceRoot":"","sources":["../../src/components/chart-missing-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAInE,KAAK,OAAO,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;AAEtC,+EAA+E;AAC/E,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,kEAAkE;AAClE,eAAO,MAAM,0BAA0B,YAAY,CAAC;AACpD,4CAA4C;AAC5C,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAM5C;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAEpD;AAED,4EAA4E;AAC5E,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,eAAe,CAI7F;AAID;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAWlF;AAID,KAAK,eAAe,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,EAAE,C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 @@
|
|
|
1
|
+
import { formatMCPUIString } from "../utils/format-string.js";
|
|
2
|
+
import { isMissingChartValue } from "../utils/missing-value.js";
|
|
3
|
+
const MISSING_BAR_STUB_LENGTH = 12;
|
|
4
|
+
const MISSING_BAR_FALLBACK_COLOR = "#9ca3af";
|
|
5
|
+
const NO_DATA_TEXT_COLOR = "#6b7280";
|
|
6
|
+
const STUB_DASH = [4, 3];
|
|
7
|
+
const POINT_CHART_TYPES = /* @__PURE__ */ new Set(["scatter", "bubble"]);
|
|
8
|
+
function isStackedChart(options) {
|
|
9
|
+
var _a, _b, _c, _d;
|
|
10
|
+
return Boolean(((_b = (_a = options == null ? void 0 : options.scales) == null ? void 0 : _a.x) == null ? void 0 : _b.stacked) || ((_d = (_c = options == null ? void 0 : options.scales) == null ? void 0 : _c.y) == null ? void 0 : _d.stacked));
|
|
11
|
+
}
|
|
12
|
+
function missingNoteKind(chartType, options) {
|
|
13
|
+
if (chartType === "bar") return isStackedChart(options) ? "omitted" : "bars";
|
|
14
|
+
if (chartType === "scatter" || chartType === "bubble") return "omitted";
|
|
15
|
+
return "gaps";
|
|
16
|
+
}
|
|
17
|
+
function withDatasetsNoGapSpan(data) {
|
|
18
|
+
const datasets = Array.isArray(data == null ? void 0 : data.datasets) ? data.datasets : null;
|
|
19
|
+
if (!datasets) return data;
|
|
20
|
+
return {
|
|
21
|
+
...data,
|
|
22
|
+
datasets: datasets.map(
|
|
23
|
+
(dataset) => dataset !== null && typeof dataset === "object" ? { ...dataset, spanGaps: false } : dataset
|
|
24
|
+
)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function createMissingLegendGenerator(base, fullyMissing, getStrings) {
|
|
28
|
+
return function generateLabels(chart) {
|
|
29
|
+
const items = base.call(this, chart);
|
|
30
|
+
if (!Array.isArray(items)) return items;
|
|
31
|
+
return items.map((item) => {
|
|
32
|
+
const index = item == null ? void 0 : item.datasetIndex;
|
|
33
|
+
if (typeof index !== "number" || !fullyMissing[index]) return item;
|
|
34
|
+
const text = typeof item.text === "string" ? item.text : String(item.text ?? "");
|
|
35
|
+
return {
|
|
36
|
+
...item,
|
|
37
|
+
text: formatMCPUIString(getStrings().chartLegendNoData, { series: text })
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function isMissingTooltipItem(item) {
|
|
43
|
+
var _a, _b, _c, _d;
|
|
44
|
+
if (item === null || item === void 0) return false;
|
|
45
|
+
if (item.raw === null || item.raw === void 0 || isMissingChartValue(item.raw)) return true;
|
|
46
|
+
const parsed = item.parsed;
|
|
47
|
+
if (parsed !== null && typeof parsed === "object") {
|
|
48
|
+
const chartType = (_b = (_a = item.chart) == null ? void 0 : _a.config) == null ? void 0 : _b.type;
|
|
49
|
+
const valueKey = chartType === "radar" ? "r" : ((_d = (_c = item.chart) == null ? void 0 : _c.options) == null ? void 0 : _d.indexAxis) === "y" ? "x" : "y";
|
|
50
|
+
if (valueKey in parsed && parsed[valueKey] === null) return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
function createTooltipLabel(getStrings, unit, chartType) {
|
|
55
|
+
const applyUnit = unit !== void 0 && !POINT_CHART_TYPES.has(chartType ?? "");
|
|
56
|
+
return function label(item) {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
const strings = getStrings();
|
|
59
|
+
const prefixLabel = ((_a = this == null ? void 0 : this.options) == null ? void 0 : _a.mode) === "dataset" ? item == null ? void 0 : item.label : (_b = item == null ? void 0 : item.dataset) == null ? void 0 : _b.label;
|
|
60
|
+
const prefix = typeof prefixLabel === "string" && prefixLabel !== "" ? `${prefixLabel}: ` : "";
|
|
61
|
+
if (isMissingTooltipItem(item)) return `${prefix}${strings.missingValue}`;
|
|
62
|
+
const formatted = item == null ? void 0 : item.formattedValue;
|
|
63
|
+
if (formatted === null || formatted === void 0) return prefix;
|
|
64
|
+
const value = applyUnit ? formatMCPUIString(strings.chartValueWithUnit, { value: formatted, unit }) : String(formatted);
|
|
65
|
+
return `${prefix}${value}`;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function applyUnitAxisTitle(options, chartType, unit) {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
if (unit === void 0) return;
|
|
71
|
+
if (chartType !== "bar" && chartType !== "line" && !POINT_CHART_TYPES.has(chartType ?? "")) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const horizontal = (chartType === "bar" || chartType === "line") && (options == null ? void 0 : options.indexAxis) === "y";
|
|
75
|
+
const axis = horizontal ? "x" : "y";
|
|
76
|
+
if (((_b = (_a = options.scales) == null ? void 0 : _a[axis]) == null ? void 0 : _b.title) !== void 0) return;
|
|
77
|
+
options.scales = {
|
|
78
|
+
...options.scales,
|
|
79
|
+
[axis]: { ...(_c = options.scales) == null ? void 0 : _c[axis], title: { display: true, text: unit } }
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function colorAt(color, index) {
|
|
83
|
+
if (typeof color === "string" && color !== "") return color;
|
|
84
|
+
if (Array.isArray(color) && color.length > 0) {
|
|
85
|
+
const picked = color[index % color.length];
|
|
86
|
+
return typeof picked === "string" && picked !== "" ? picked : void 0;
|
|
87
|
+
}
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
function drawMissingBarStubs(chart) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
const ctx = chart == null ? void 0 : chart.ctx;
|
|
93
|
+
const area = chart == null ? void 0 : chart.chartArea;
|
|
94
|
+
const datasets = (_a = chart == null ? void 0 : chart.data) == null ? void 0 : _a.datasets;
|
|
95
|
+
if (!ctx || !area || !Array.isArray(datasets)) return;
|
|
96
|
+
const left = area.left;
|
|
97
|
+
const top = area.top;
|
|
98
|
+
const right = area.right ?? left + (area.width ?? 0);
|
|
99
|
+
const bottom = area.bottom ?? top + (area.height ?? 0);
|
|
100
|
+
let saved = false;
|
|
101
|
+
datasets.forEach((dataset, datasetIndex) => {
|
|
102
|
+
var _a2, _b2, _c, _d, _e, _f, _g;
|
|
103
|
+
const meta = (_a2 = chart.getDatasetMeta) == null ? void 0 : _a2.call(chart, datasetIndex);
|
|
104
|
+
if (!meta) return;
|
|
105
|
+
const isBar = meta.type === "bar" || ((_c = (_b2 = meta.controller) == null ? void 0 : _b2.constructor) == null ? void 0 : _c.id) === "bar";
|
|
106
|
+
if (!isBar) return;
|
|
107
|
+
if (((_e = (_d = meta.vScale) == null ? void 0 : _d.options) == null ? void 0 : _e.stacked) || ((_g = (_f = meta.iScale) == null ? void 0 : _f.options) == null ? void 0 : _g.stacked)) return;
|
|
108
|
+
if (typeof chart.isDatasetVisible === "function" && !chart.isDatasetVisible(datasetIndex)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const values = Array.isArray(dataset == null ? void 0 : dataset.data) ? dataset.data : [];
|
|
112
|
+
const elements = Array.isArray(meta.data) ? meta.data : [];
|
|
113
|
+
values.forEach((value, index) => {
|
|
114
|
+
var _a3;
|
|
115
|
+
if (!isMissingChartValue(value)) return;
|
|
116
|
+
const element = elements[index];
|
|
117
|
+
if (!element) return;
|
|
118
|
+
const props = ((_a3 = element.getProps) == null ? void 0 : _a3.call(element, ["x", "y", "base", "width", "height"], true)) ?? element;
|
|
119
|
+
const { x, y, base, width, height } = props;
|
|
120
|
+
if (![x, y, base].every((n) => Number.isFinite(n))) return;
|
|
121
|
+
const horizontal = element.horizontal === true;
|
|
122
|
+
const thickness = horizontal ? height : width;
|
|
123
|
+
if (!Number.isFinite(thickness) || thickness <= 0) return;
|
|
124
|
+
let rect;
|
|
125
|
+
if (horizontal) {
|
|
126
|
+
const dir = base < (left + right) / 2 ? 1 : -1;
|
|
127
|
+
rect = [Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), y - thickness / 2, MISSING_BAR_STUB_LENGTH, thickness];
|
|
128
|
+
} else {
|
|
129
|
+
const dir = base > (top + bottom) / 2 ? -1 : 1;
|
|
130
|
+
rect = [x - thickness / 2, Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), thickness, MISSING_BAR_STUB_LENGTH];
|
|
131
|
+
}
|
|
132
|
+
if (!saved) {
|
|
133
|
+
ctx.save();
|
|
134
|
+
ctx.beginPath();
|
|
135
|
+
ctx.rect(left, top, right - left, bottom - top);
|
|
136
|
+
ctx.clip();
|
|
137
|
+
saved = true;
|
|
138
|
+
}
|
|
139
|
+
ctx.strokeStyle = colorAt(dataset == null ? void 0 : dataset.borderColor, index) ?? MISSING_BAR_FALLBACK_COLOR;
|
|
140
|
+
ctx.lineWidth = 1;
|
|
141
|
+
ctx.setLineDash(STUB_DASH);
|
|
142
|
+
ctx.strokeRect(...rect);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
if (saved) {
|
|
146
|
+
(_b = ctx.setLineDash) == null ? void 0 : _b.call(ctx, []);
|
|
147
|
+
ctx.restore();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function drawNoDataText(chart, text, fontFamily, color) {
|
|
151
|
+
const ctx = chart == null ? void 0 : chart.ctx;
|
|
152
|
+
const area = chart == null ? void 0 : chart.chartArea;
|
|
153
|
+
if (!ctx || !area || !text) return;
|
|
154
|
+
const cx = (area.left + (area.right ?? area.left + (area.width ?? 0))) / 2;
|
|
155
|
+
const cy = (area.top + (area.bottom ?? area.top + (area.height ?? 0))) / 2;
|
|
156
|
+
ctx.save();
|
|
157
|
+
ctx.font = `12px ${fontFamily || "sans-serif"}`;
|
|
158
|
+
ctx.fillStyle = color || NO_DATA_TEXT_COLOR;
|
|
159
|
+
ctx.textAlign = "center";
|
|
160
|
+
ctx.textBaseline = "middle";
|
|
161
|
+
ctx.fillText(text, cx, cy);
|
|
162
|
+
ctx.restore();
|
|
163
|
+
}
|
|
164
|
+
function createMissingValuesPlugin(options) {
|
|
165
|
+
return {
|
|
166
|
+
id: "mcpuiMissingValues",
|
|
167
|
+
afterDatasetsDraw(chart) {
|
|
168
|
+
var _a, _b;
|
|
169
|
+
try {
|
|
170
|
+
drawMissingBarStubs(chart);
|
|
171
|
+
if (options.allMissing) {
|
|
172
|
+
drawNoDataText(chart, options.getNoDataText(), (_a = options.getFontFamily) == null ? void 0 : _a.call(options), (_b = options.getTextColor) == null ? void 0 : _b.call(options));
|
|
173
|
+
}
|
|
174
|
+
} catch {
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export {
|
|
180
|
+
MISSING_BAR_FALLBACK_COLOR,
|
|
181
|
+
MISSING_BAR_STUB_LENGTH,
|
|
182
|
+
NO_DATA_TEXT_COLOR,
|
|
183
|
+
applyUnitAxisTitle,
|
|
184
|
+
createMissingLegendGenerator,
|
|
185
|
+
createMissingValuesPlugin,
|
|
186
|
+
createTooltipLabel,
|
|
187
|
+
drawMissingBarStubs,
|
|
188
|
+
drawNoDataText,
|
|
189
|
+
isMissingTooltipItem,
|
|
190
|
+
isStackedChart,
|
|
191
|
+
missingNoteKind,
|
|
192
|
+
withDatasetsNoGapSpan
|
|
193
|
+
};
|
|
194
|
+
//# sourceMappingURL=chart-missing-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-missing-plugin.js","sources":["../../src/components/chart-missing-plugin.ts"],"sourcesContent":["/**\n * Missing values in a Chart.js chart (v6.24.0) — everything the renderer adds\n * to its Chart.js config when a payload says a value is MISSING (`null`).\n *\n * The rule: absence is never zero. Chart.js already keeps the slot of a `null`\n * (no label dropped) and draws nothing for it; what it does not do is make the\n * absence READABLE. A null bar is a zero-height bar that is skipped when\n * drawn, a null line point is a hole the line may bridge (`spanGaps`), and the\n * legend, tooltip and axis know nothing of either. This module supplies:\n *\n * - {@link createMissingValuesPlugin} — a PER-CHART plugin (never\n * `Chart.register`ed, so it can leak into no other chart) that outlines a\n * dashed stub where a bar should have been (not on stacked or overlaid\n * bars, whose baseline belongs to another series), and says \"no data\" on a\n * chart with nothing to draw;\n * - {@link createMissingLegendGenerator} — marks a fully-missing series in the\n * legend;\n * - {@link createTooltipLabel} — names a missing value, and appends the unit;\n * - {@link withDatasetsNoGapSpan} — the shallow-cloned data with\n * `spanGaps: false`;\n * - {@link applyUnitAxisTitle} — the unit as the value axis title.\n *\n * Runtime-free on purpose (no `solid-js`, no `chart.js` import): the renderer\n * hands in the Chart.js pieces it loaded and the chrome strings (lazily, as\n * getters, so a late locale change is honoured at draw time). Every function\n * is defensive — a drawing hook that throws would blank the whole chart.\n *\n * Chart.js 4.5.1 facts this relies on (verified in `dist/chart.js`):\n * - a bar whose parsed value is `null` gets `base = head = vScale.getBasePixel()`\n * and no `skip` flag (BarController.updateElements), and `BarController.draw`\n * skips it (`getParsed(i)[vScale.axis] !== null`) — so nothing is painted;\n * - the bar element still carries its true index-axis thickness (`width` for a\n * vertical bar, `height` for a horizontal one).\n */\n\nimport type { MCPUIStrings } from '../context/MCPUIStringsContext';\nimport { formatMCPUIString } from '../utils/format-string';\nimport { isMissingChartValue } from '../utils/missing-value';\n\ntype Strings = Required<MCPUIStrings>;\n\n/** Length, in px along the value axis, of the dashed stub of a missing bar. */\nexport const MISSING_BAR_STUB_LENGTH = 12;\n/** Stroke of the stub when the dataset names no border colour. */\nexport const MISSING_BAR_FALLBACK_COLOR = '#9ca3af';\n/** Colour of the centred \"no data\" text. */\nexport const NO_DATA_TEXT_COLOR = '#6b7280';\nconst STUB_DASH = [4, 3];\n\n/** Chart types whose value axis is `y` and whose points are `{x, y}`. */\nconst POINT_CHART_TYPES = new Set(['scatter', 'bubble']);\n\n/**\n * The category of convention line a chart shows under its canvas:\n * `'gaps'` (a line breaks), `'bars'` (a dashed outline stands in for the\n * bar) or `'omitted'` (nothing is drawn: scatter, bubble, stacked bars).\n */\nexport type MissingNoteKind = 'gaps' | 'bars' | 'omitted';\n\n/**\n * Whether a bar chart's bars are stacked or overlaid (`stacked` on either\n * axis). A missing bar there has no slot of its own at the baseline — the\n * baseline belongs to the series below — so no dashed outline is drawn.\n */\nexport function isStackedChart(options: any): boolean {\n return Boolean(options?.scales?.x?.stacked || options?.scales?.y?.stacked);\n}\n\n/** Which convention note a chart gets: how ITS missing values are drawn. */\nexport function missingNoteKind(chartType: string | undefined, options?: any): MissingNoteKind {\n if (chartType === 'bar') return isStackedChart(options) ? 'omitted' : 'bars';\n if (chartType === 'scatter' || chartType === 'bubble') return 'omitted';\n return 'gaps';\n}\n\n// ─── Data ──────────────────────────────────────────────────────────────────\n\n/**\n * Chart.js data with every dataset shallow-cloned and `spanGaps: false`, so a\n * line breaks at a missing value instead of joining its neighbours. Never\n * mutates its input; `labels` and every other key are carried by reference.\n */\nexport function withDatasetsNoGapSpan<D extends { datasets?: unknown }>(data: D): D {\n const datasets = Array.isArray(data?.datasets) ? data.datasets : null;\n if (!datasets) return data;\n return {\n ...data,\n datasets: datasets.map((dataset: unknown) =>\n dataset !== null && typeof dataset === 'object'\n ? { ...(dataset as object), spanGaps: false }\n : dataset\n ),\n };\n}\n\n// ─── Legend ────────────────────────────────────────────────────────────────\n\ntype LegendGenerator = (chart: any) => any[];\n\n/**\n * Wraps a Chart.js legend label generator so a fully-missing dataset reads\n * `\"{series} (no data)\"` (`strings.chartLegendNoData`). Every other item is\n * passed through untouched.\n */\nexport function createMissingLegendGenerator(\n base: LegendGenerator,\n fullyMissing: readonly boolean[],\n getStrings: () => Strings\n): LegendGenerator {\n return function generateLabels(this: unknown, chart: any) {\n const items = base.call(this, chart);\n if (!Array.isArray(items)) return items;\n return items.map((item) => {\n const index = item?.datasetIndex;\n if (typeof index !== 'number' || !fullyMissing[index]) return item;\n const text = typeof item.text === 'string' ? item.text : String(item.text ?? '');\n return {\n ...item,\n text: formatMCPUIString(getStrings().chartLegendNoData, { series: text }),\n };\n });\n };\n}\n\n// ─── Tooltip ───────────────────────────────────────────────────────────────\n\n/** Whether a Chart.js tooltip item stands for a missing value. */\nexport function isMissingTooltipItem(item: any): boolean {\n if (item === null || item === undefined) return false;\n if (item.raw === null || item.raw === undefined || isMissingChartValue(item.raw)) return true;\n const parsed = item.parsed;\n if (parsed !== null && typeof parsed === 'object') {\n const chartType = item.chart?.config?.type;\n const valueKey =\n chartType === 'radar' ? 'r' : item.chart?.options?.indexAxis === 'y' ? 'x' : 'y';\n if (valueKey in parsed && parsed[valueKey] === null) return true;\n }\n return false;\n}\n\n/**\n * Tooltip `label` callback: names a missing value (`\"{series}: Missing\n * value\"`) and, with a `unit`, appends it to a present one. Otherwise it is\n * Chart.js's default composition (dataset label, `\": \"`, formatted value) —\n * including its `mode: 'dataset'` branch, which prefixes the CATEGORY label\n * instead, since every item of that tooltip belongs to the same dataset.\n * Hence a regular function: Chart.js calls it with the tooltip as `this`.\n *\n * `unit` is left off scatter and bubble tooltips: their formatted value is the\n * pair `(x, y)`, to which one unit does not belong.\n */\nexport function createTooltipLabel(\n getStrings: () => Strings,\n unit: string | undefined,\n chartType: string | undefined\n): (this: any, item: any) => string {\n const applyUnit = unit !== undefined && !POINT_CHART_TYPES.has(chartType ?? '');\n return function label(this: any, item: any) {\n const strings = getStrings();\n const prefixLabel = this?.options?.mode === 'dataset' ? item?.label : item?.dataset?.label;\n const prefix = typeof prefixLabel === 'string' && prefixLabel !== '' ? `${prefixLabel}: ` : '';\n\n if (isMissingTooltipItem(item)) return `${prefix}${strings.missingValue}`;\n\n const formatted = item?.formattedValue;\n if (formatted === null || formatted === undefined) return prefix;\n const value = applyUnit\n ? formatMCPUIString(strings.chartValueWithUnit, { value: formatted, unit: unit as string })\n : String(formatted);\n return `${prefix}${value}`;\n };\n}\n\n// ─── Axis ──────────────────────────────────────────────────────────────────\n\n/**\n * Sets the chart's `unit` as the title of its value axis, in place on the\n * `options` object the renderer just built (never on the payload's).\n *\n * Only bar, line, scatter and bubble have a value axis to title. The value\n * axis is `y`, or `x` when the index axis is `y` (a horizontal bar or line).\n * An existing `scales[axis].title` is the payload's own word and is kept; the\n * rest of the scale config (a `timeAxis` block sets `scales.x`) is kept too.\n */\nexport function applyUnitAxisTitle(\n options: any,\n chartType: string | undefined,\n unit: string | undefined\n): void {\n if (unit === undefined) return;\n if (chartType !== 'bar' && chartType !== 'line' && !POINT_CHART_TYPES.has(chartType ?? '')) {\n return;\n }\n const horizontal = (chartType === 'bar' || chartType === 'line') && options?.indexAxis === 'y';\n const axis = horizontal ? 'x' : 'y';\n if (options.scales?.[axis]?.title !== undefined) return;\n options.scales = {\n ...options.scales,\n [axis]: { ...options.scales?.[axis], title: { display: true, text: unit } },\n };\n}\n\n// ─── Plugin ────────────────────────────────────────────────────────────────\n\nexport interface MissingValuesPluginOptions {\n /** At least one dataset and every one of them has no observed value. */\n allMissing: boolean;\n /** Lazy: read at draw time. */\n getNoDataText: () => string;\n /** Lazy: `Chart.defaults.font.family`, when the build exposes it. */\n getFontFamily?: () => string | undefined;\n /** Lazy host theme override; omission retains the historical grey. */\n getTextColor?: () => string | undefined;\n}\n\n/** A dataset colour for entry `index`, as a string, or `undefined`. */\nfunction colorAt(color: unknown, index: number): string | undefined {\n if (typeof color === 'string' && color !== '') return color;\n if (Array.isArray(color) && color.length > 0) {\n const picked = color[index % color.length];\n return typeof picked === 'string' && picked !== '' ? picked : undefined;\n }\n return undefined;\n}\n\n/**\n * Draws a dashed outline stub for every missing bar of every visible,\n * non-stacked bar dataset, so a missing value is a visible mark, not a bar\n * that \"is\" zero.\n *\n * The stub sits on the value-axis base, as thick as the bar would have been,\n * and runs {@link MISSING_BAR_STUB_LENGTH}px toward the middle of the chart\n * area (up from a bottom baseline, down from a top one, right from a left\n * one). Clipped to the chart area.\n */\nexport function drawMissingBarStubs(chart: any): void {\n const ctx = chart?.ctx;\n const area = chart?.chartArea;\n const datasets = chart?.data?.datasets;\n if (!ctx || !area || !Array.isArray(datasets)) return;\n\n const left = area.left;\n const top = area.top;\n const right = area.right ?? left + (area.width ?? 0);\n const bottom = area.bottom ?? top + (area.height ?? 0);\n\n let saved = false;\n datasets.forEach((dataset: any, datasetIndex: number) => {\n const meta = chart.getDatasetMeta?.(datasetIndex);\n if (!meta) return;\n const isBar = meta.type === 'bar' || meta.controller?.constructor?.id === 'bar';\n if (!isBar) return;\n // Stacked or overlaid bars: the baseline under a missing segment is the\n // series below, so an outline there would point at the wrong series.\n if (meta.vScale?.options?.stacked || meta.iScale?.options?.stacked) return;\n if (typeof chart.isDatasetVisible === 'function' && !chart.isDatasetVisible(datasetIndex)) {\n return;\n }\n const values: unknown[] = Array.isArray(dataset?.data) ? dataset.data : [];\n const elements: any[] = Array.isArray(meta.data) ? meta.data : [];\n\n values.forEach((value, index) => {\n if (!isMissingChartValue(value)) return;\n const element = elements[index];\n if (!element) return;\n const props = element.getProps?.(['x', 'y', 'base', 'width', 'height'], true) ?? element;\n const { x, y, base, width, height } = props;\n if (![x, y, base].every((n) => Number.isFinite(n))) return;\n const horizontal = element.horizontal === true;\n const thickness = horizontal ? height : width;\n if (!Number.isFinite(thickness) || thickness <= 0) return;\n\n let rect: [number, number, number, number];\n if (horizontal) {\n const dir = base < (left + right) / 2 ? 1 : -1;\n rect = [Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), y - thickness / 2, MISSING_BAR_STUB_LENGTH, thickness];\n } else {\n const dir = base > (top + bottom) / 2 ? -1 : 1;\n rect = [x - thickness / 2, Math.min(base, base + dir * MISSING_BAR_STUB_LENGTH), thickness, MISSING_BAR_STUB_LENGTH];\n }\n\n if (!saved) {\n ctx.save();\n ctx.beginPath();\n ctx.rect(left, top, right - left, bottom - top);\n ctx.clip();\n saved = true;\n }\n ctx.strokeStyle = colorAt(dataset?.borderColor, index) ?? MISSING_BAR_FALLBACK_COLOR;\n ctx.lineWidth = 1;\n ctx.setLineDash(STUB_DASH);\n ctx.strokeRect(...rect);\n });\n });\n if (saved) {\n ctx.setLineDash?.([]);\n ctx.restore();\n }\n}\n\n/** Draws `text` centred in the chart area (a chart with nothing to plot). */\nexport function drawNoDataText(chart: any, text: string, fontFamily?: string, color?: string): void {\n const ctx = chart?.ctx;\n const area = chart?.chartArea;\n if (!ctx || !area || !text) return;\n const cx = (area.left + (area.right ?? area.left + (area.width ?? 0))) / 2;\n const cy = (area.top + (area.bottom ?? area.top + (area.height ?? 0))) / 2;\n ctx.save();\n ctx.font = `12px ${fontFamily || 'sans-serif'}`;\n ctx.fillStyle = color || NO_DATA_TEXT_COLOR;\n ctx.textAlign = 'center';\n ctx.textBaseline = 'middle';\n ctx.fillText(text, cx, cy);\n ctx.restore();\n}\n\n/**\n * The per-chart plugin object. Passed as `config.plugins = [plugin]`: Chart.js\n * scopes it to that one chart. Both hooks swallow their own errors — a\n * decoration must never take the chart down.\n */\nexport function createMissingValuesPlugin(options: MissingValuesPluginOptions) {\n return {\n id: 'mcpuiMissingValues',\n afterDatasetsDraw(chart: any) {\n try {\n drawMissingBarStubs(chart);\n if (options.allMissing) {\n drawNoDataText(chart, options.getNoDataText(), options.getFontFamily?.(), options.getTextColor?.());\n }\n } catch {\n // Cosmetic layer: never break the chart.\n }\n },\n };\n}\n"],"names":["_a","_b"],"mappings":";;AA0CO,MAAM,0BAA0B;AAEhC,MAAM,6BAA6B;AAEnC,MAAM,qBAAqB;AAClC,MAAM,YAAY,CAAC,GAAG,CAAC;AAGvB,MAAM,oBAAoB,oBAAI,IAAI,CAAC,WAAW,QAAQ,CAAC;AAchD,SAAS,eAAe,SAAuB;;AACpD,SAAO,UAAQ,8CAAS,WAAT,mBAAiB,MAAjB,mBAAoB,cAAW,8CAAS,WAAT,mBAAiB,MAAjB,mBAAoB,QAAO;AAC3E;AAGO,SAAS,gBAAgB,WAA+B,SAAgC;AAC7F,MAAI,cAAc,MAAO,QAAO,eAAe,OAAO,IAAI,YAAY;AACtE,MAAI,cAAc,aAAa,cAAc,SAAU,QAAO;AAC9D,SAAO;AACT;AASO,SAAS,sBAAwD,MAAY;AAClF,QAAM,WAAW,MAAM,QAAQ,6BAAM,QAAQ,IAAI,KAAK,WAAW;AACjE,MAAI,CAAC,SAAU,QAAO;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,SAAS;AAAA,MAAI,CAAC,YACtB,YA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AACzB,MAAI,YAAY;AAChB,MAAI,eAAe;AACnB,MAAI,SAAS,MAAM,IAAI,EAAE;AACzB,MAAI,QAAA;AACN;AAOO,SAAS,0BAA0B,SAAqC;AAC7E,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,kBAAkB,OAAY;;AAC5B,UAAI;AACF,4BAAoB,KAAK;AACzB,YAAI,QAAQ,YAAY;AACtB,yBAAe,OAAO,QAAQ,cAAA,IAAiB,aAAQ,kBAAR,mCAA2B,aAAQ,iBAAR,gCAAwB;AAAA,QACpG;AAAA,MACF,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EAAA;AAEJ;"}
|
|
@@ -289,7 +289,18 @@ const DEFAULT_MCPUI_STRINGS = {
|
|
|
289
289
|
zoomIn: "Zoom in",
|
|
290
290
|
zoomOut: "Zoom out",
|
|
291
291
|
zoomReset: "Reset zoom",
|
|
292
|
-
zoomLevel: "Zoom {percent}%"
|
|
292
|
+
zoomLevel: "Zoom {percent}%",
|
|
293
|
+
// ── 6.24.0 — missing values ────────────────────────────────
|
|
294
|
+
missingValue: "Missing value",
|
|
295
|
+
missingValueLegend: "“{marker}” marks a missing value.",
|
|
296
|
+
chartMissingGaps: "Breaks in a line mark missing values.",
|
|
297
|
+
chartMissingBars: "Dashed outlines mark missing values.",
|
|
298
|
+
chartMissingPoints: "Missing values are not plotted.",
|
|
299
|
+
chartSeriesNoData: "No data for {series}.",
|
|
300
|
+
chartLegendNoData: "{series} (no data)",
|
|
301
|
+
chartValueWithUnit: "{value} {unit}",
|
|
302
|
+
chartLabelWithUnit: "{label} ({unit})",
|
|
303
|
+
chartMissingUnsupported: "This chart type cannot show missing values."
|
|
293
304
|
};
|
|
294
305
|
const MCPUIStringsContext = solidJs.createContext(DEFAULT_MCPUI_STRINGS);
|
|
295
306
|
const resolvedLocales = /* @__PURE__ */ new Map();
|