contour-ds 1.8.1 → 1.9.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/README.md +227 -378
- package/dist/agent-cookbook.json +960 -0
- package/dist/agent-examples.json +65 -0
- package/dist/agent-map-wiring.json +152 -0
- package/dist/build-manifest.json +320 -179
- package/dist/contour-wc-content.esm.js +479 -3665
- package/dist/contour-wc-content.esm.min.js +1 -1
- package/dist/contour-wc-core.esm.js +3724 -0
- package/dist/contour-wc-core.esm.min.js +1 -0
- package/dist/contour-wc-dashboard.esm.js +2713 -4381
- package/dist/contour-wc-dashboard.esm.min.js +1 -1
- package/dist/contour-wc-data.esm.js +2658 -4346
- package/dist/contour-wc-data.esm.min.js +1 -1
- package/dist/contour-wc-docs.esm.js +218 -3547
- package/dist/contour-wc-docs.esm.min.js +1 -1
- package/dist/contour-wc-feedback.esm.js +483 -3658
- package/dist/contour-wc-feedback.esm.min.js +1 -1
- package/dist/contour-wc-forms.esm.js +503 -3754
- package/dist/contour-wc-forms.esm.min.js +1 -1
- package/dist/contour-wc-interaction.esm.js +379 -3616
- package/dist/contour-wc-interaction.esm.min.js +1 -1
- package/dist/contour-wc-layout.esm.js +234 -3563
- package/dist/contour-wc-layout.esm.min.js +1 -1
- package/dist/contour-wc-map.esm.js +949 -3743
- package/dist/contour-wc-map.esm.min.js +1 -1
- package/dist/contour-wc-misc.esm.js +237 -3556
- package/dist/contour-wc-misc.esm.min.js +1 -1
- package/dist/contour-wc-navigation.esm.js +2235 -5237
- package/dist/contour-wc-navigation.esm.min.js +1 -1
- package/dist/contour-wc-ui.esm.js +4638 -7128
- package/dist/contour-wc-ui.esm.min.js +1 -1
- package/dist/contour-wc.esm.js +11971 -7727
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +11971 -7727
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.a11y.json +402 -0
- package/dist/contour.code-snippets +96 -74
- package/dist/contour.components.json +2591 -741
- package/dist/contour.css +2624 -1888
- package/dist/contour.d.ts +421 -228
- package/dist/contour.esm.js +433 -18
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +1231 -199
- package/dist/contour.js +433 -18
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +100 -98
- package/dist/contour.single.html +2 -2
- package/dist/contour.single.min.css +1 -1
- package/dist/contour.themes.json +56 -12
- package/dist/contour.tokens.json +482 -255
- package/dist/contour.vue.d.ts +100 -98
- package/dist/contour.web-types.json +1226 -226
- package/dist/custom-elements.json +7649 -2237
- package/dist/docs/actions.md +15 -6
- package/dist/docs/affordances.md +18 -96
- package/dist/docs/apireference.md +9 -5
- package/dist/docs/colour.md +10 -4
- package/dist/docs/componentindex.md +9 -26
- package/dist/docs/data.md +36 -60
- package/dist/docs/docs.md +10 -12
- package/dist/docs/feedback.md +30 -12
- package/dist/docs/field.md +28 -13
- package/dist/docs/forms.md +35 -19
- package/dist/docs/index.json +63 -56
- package/dist/docs/install.md +12 -7
- package/dist/docs/landing.md +7 -4
- package/dist/docs/mapengine.md +18 -13
- package/dist/docs/motion.md +12 -6
- package/dist/docs/navigation.md +31 -7
- package/dist/docs/overlays.md +32 -25
- package/dist/docs/overview.md +3 -2
- package/dist/docs/patterns.md +19 -9
- package/dist/docs/playground.md +9 -22
- package/dist/docs/principles.md +8 -6
- package/dist/docs/recipes.md +113 -14
- package/dist/docs/space.md +10 -6
- package/dist/docs/status.md +12 -25
- package/dist/docs/surfaces.md +17 -22
- package/dist/docs/theming.md +18 -32
- package/dist/docs/type.md +12 -5
- package/dist/docs/webcomponents.md +66 -38
- package/dist/hljs.css +1 -20
- package/dist/map-chrome.mapbox.css +68 -92
- package/dist/map-chrome.maplibre.css +68 -92
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/svg/icons.svg +367 -0
- package/dist/wc/behaviours.mjs +190 -148
- package/dist/wc/content.mjs +273 -129
- package/dist/wc/core.mjs +598 -395
- package/dist/wc/dashboard.mjs +64 -44
- package/dist/wc/data-chart.mjs +1333 -0
- package/dist/wc/data-export.mjs +391 -0
- package/dist/wc/data-gauge.mjs +779 -0
- package/dist/wc/data-geo.mjs +696 -0
- package/dist/wc/data-glyphs.mjs +133 -0
- package/dist/wc/data-legend.mjs +431 -0
- package/dist/wc/data-readout.mjs +227 -0
- package/dist/wc/data-series.mjs +1004 -0
- package/dist/wc/data-table.mjs +751 -0
- package/dist/wc/data.mjs +15 -4322
- package/dist/wc/docs.mjs +12 -11
- package/dist/wc/feedback.mjs +277 -122
- package/dist/wc/forms-controls.mjs +635 -0
- package/dist/wc/forms-field.mjs +547 -0
- package/dist/wc/forms-groups.mjs +347 -0
- package/dist/wc/forms-input.mjs +292 -0
- package/dist/wc/forms.mjs +10 -1751
- package/dist/wc/glyph.mjs +204 -0
- package/dist/wc/index.mjs +11 -9
- package/dist/wc/interaction.mjs +173 -80
- package/dist/wc/layout.mjs +28 -27
- package/dist/wc/map.mjs +743 -207
- package/dist/wc/misc.mjs +31 -20
- package/dist/wc/navigation-menu.mjs +735 -0
- package/dist/wc/navigation-shell.mjs +495 -0
- package/dist/wc/navigation-tree.mjs +995 -0
- package/dist/wc/navigation.mjs +9 -1905
- package/dist/wc/registration.mjs +1 -8
- package/dist/wc/shadow.mjs +206 -110
- package/dist/wc/states.mjs +54 -75
- package/dist/wc/svg.mjs +118 -47
- package/dist/wc/ui-atoms.mjs +608 -0
- package/dist/wc/ui-data.mjs +1404 -0
- package/dist/wc/ui-feedback.mjs +419 -0
- package/dist/wc/ui-inputs.mjs +1570 -0
- package/dist/wc/ui-menus.mjs +307 -0
- package/dist/wc/ui-overlays.mjs +1605 -0
- package/integrations/README.md +23 -5
- package/integrations/ai/CLAUDE.md +3 -0
- package/integrations/ai/COPILOT.md +14 -0
- package/integrations/ai/GEMINI.md +14 -0
- package/integrations/ai/WINDSURF.md +14 -0
- package/integrations/ai/v0-prompt.md +13 -1
- package/integrations/native/README.md +0 -3
- package/integrations/tailwind/contour-theme.css +66 -7
- package/integrations/validate-markup.mjs +172 -0
- package/package.json +77 -42
- package/dist/wc/ui.mjs +0 -5072
|
@@ -0,0 +1,1004 @@
|
|
|
1
|
+
import { ContourBase, define, onDispose, formatValue, contourId, navKey, isRtl, cssLength , safeColor, warnBadJson, labelText } from './core.mjs';
|
|
2
|
+
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates, remoteInvalidate, watchViewport, parseArrayAttr, stateLabel } from './states.mjs';
|
|
3
|
+
import { donutSlices, barRects, smoothPath, polylinePoints, contourPaths } from './svg.mjs';
|
|
4
|
+
import { paintDonutGlyph, paintSparklineGlyph, paintPurityRing } from './glyph.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Donut: web component wrapper.
|
|
8
|
+
* Attributes: `value`, `values`, `items`, `label`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `brownout`, `brownout-level`.
|
|
9
|
+
*/
|
|
10
|
+
class ContourDonut extends ContourBase {
|
|
11
|
+
static get observed() { return ["value", "values", "items", "label", "color", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level", "note", "cache-key", "no-cache"]; }
|
|
12
|
+
static get properties() { return { value: { attribute: "value" }, values: { attribute: "values" }, items: { attribute: "items" }, label: { attribute: "label" }, color: { attribute: "color" }, src: { attribute: "src" }, note: { attribute: "note" } }; }
|
|
13
|
+
render() {
|
|
14
|
+
this.classList.add("c-donut");
|
|
15
|
+
// The donut renders a list of segments beside the ring; an image role
|
|
16
|
+
// would flatten that list out of the accessibility tree.
|
|
17
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
18
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "donut-chart", "Donut chart"));
|
|
19
|
+
wireStates(this);
|
|
20
|
+
loadRemote(this, ["items", "values"]);
|
|
21
|
+
if (renderStates(this, "donut")) return;
|
|
22
|
+
Array.from(this.querySelectorAll(".c-donut__ring, .c-donut__center, .c-donut__list, .c-donut__empty")).forEach((n) => n.remove());
|
|
23
|
+
// Slotted content support: authored .c-donut__item children take precedence over the JSON `items` attribute, so consumers can compose legend rows by hand instead of serialising them into an attribute.
|
|
24
|
+
const authoredItems = Array.from(this.querySelectorAll(":scope > .c-donut__item"));
|
|
25
|
+
let items = [];
|
|
26
|
+
if (authoredItems.length) {
|
|
27
|
+
authoredItems.forEach((el) => {
|
|
28
|
+
const sw = el.querySelector(".c-donut__swatch");
|
|
29
|
+
const lbl = el.querySelector("span:last-child");
|
|
30
|
+
const text = lbl ? lbl.textContent : el.textContent;
|
|
31
|
+
const match = text.match(/—\s*(\d+(?:\.\d+)?)$/);
|
|
32
|
+
items.push({ label: text.replace(/—\s*\d+(?:\.\d+)?$/, "").trim(), value: match ? Number(match[1]) : 0, color: sw ? (sw.dataset && sw.dataset.color) || sw.style.background : undefined });
|
|
33
|
+
});
|
|
34
|
+
// remove authored items from DOM (they will be regenerated below)
|
|
35
|
+
authoredItems.forEach((el) => el.remove());
|
|
36
|
+
} else {
|
|
37
|
+
const iAttr = this.getAttribute("items");
|
|
38
|
+
if (iAttr) { items = parseArrayAttr(this, "items", warnBadJson); }
|
|
39
|
+
}
|
|
40
|
+
const values = items.map((it) => (typeof it === "object" ? (it.value || 0) : Number(it) || 0));
|
|
41
|
+
// R31-51: the centre total is the sum of the positive slices, matching
|
|
42
|
+
// donutSlices(); a negative value is not a slice and must not shrink it.
|
|
43
|
+
const total = values.reduce((a, b) => a + (b > 0 ? b : 0), 0) || 1;
|
|
44
|
+
const brownoutLevel = this.brownoutLevel();
|
|
45
|
+
const layerColor = this.getAttribute("color");
|
|
46
|
+
const shedRing = this.shed("ring", 3);
|
|
47
|
+
if (!shedRing) {
|
|
48
|
+
// Filled annular slices (not stroked circles): old ring drew outline circles (monochrome, no per-slice colour); arcPath() produces real annulus sectors with own --c.
|
|
49
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
50
|
+
svg.setAttribute("class", "c-donut__ring");
|
|
51
|
+
svg.setAttribute("viewBox", "0 0 32 32");
|
|
52
|
+
svg.setAttribute("role", "img");
|
|
53
|
+
const ringLabel = this.getAttribute("label") || "Donut chart";
|
|
54
|
+
svg.setAttribute("aria-label", ringLabel);
|
|
55
|
+
const slices = donutSlices(values, { cx: 16, cy: 16, r: 15, inner: 9, gap: 0.03 });
|
|
56
|
+
slices.forEach((sl, si) => {
|
|
57
|
+
const it = items[sl.index];
|
|
58
|
+
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
59
|
+
path.setAttribute("class", "c-donut__slice");
|
|
60
|
+
path.setAttribute("d", sl.path);
|
|
61
|
+
path.setAttribute("fill", "var(--c, var(--chart-1))");
|
|
62
|
+
path.style.setProperty("--c", safeColor(layerColor || (typeof it === "object" && it.color ? it.color : "var(--chart-" + ((sl.index % 8) + 1) + ")")) || "var(--chart-1)");
|
|
63
|
+
path.dataset.index = String(sl.index);
|
|
64
|
+
const lbl = (typeof it === "object" ? (it.label || "") : String(it)) + " — " + sl.value;
|
|
65
|
+
path.setAttribute("data-title", lbl);
|
|
66
|
+
path.setAttribute("aria-label", lbl);
|
|
67
|
+
// Roving tabindex from first render: one tab stop for ring (not per slice); arrow handler roves it, avoiding 12 tab stops for 12-slice donut.
|
|
68
|
+
path.setAttribute("tabindex", si === 0 ? "0" : "-1");
|
|
69
|
+
path.setAttribute("role", "button");
|
|
70
|
+
svg.appendChild(path);
|
|
71
|
+
});
|
|
72
|
+
this.appendChild(svg);
|
|
73
|
+
}
|
|
74
|
+
const center = document.createElement("div");
|
|
75
|
+
center.className = "c-donut__center";
|
|
76
|
+
// R24-36: use ?? so value="0" is not treated as missing
|
|
77
|
+
center.textContent = this.getAttribute("value") ?? String(total);
|
|
78
|
+
this.appendChild(center);
|
|
79
|
+
// text list
|
|
80
|
+
const list = document.createElement("div");
|
|
81
|
+
list.className = "c-donut__list";
|
|
82
|
+
list.setAttribute("role", "list");
|
|
83
|
+
items.forEach((it, i) => {
|
|
84
|
+
const row = document.createElement("div");
|
|
85
|
+
row.className = "c-donut__item";
|
|
86
|
+
row.setAttribute("role", "listitem");
|
|
87
|
+
const sw = document.createElement("span");
|
|
88
|
+
sw.className = "c-donut__swatch";
|
|
89
|
+
sw.style.background = safeColor(layerColor || (typeof it === "object" && it.color ? it.color : "var(--chart-" + ((i % 8) + 1) + ")"));
|
|
90
|
+
if (sw.style.background) sw.dataset.color = layerColor || (typeof it === "object" && it.color ? it.color : sw.style.background);
|
|
91
|
+
row.appendChild(sw);
|
|
92
|
+
const lbl = document.createElement("span");
|
|
93
|
+
lbl.textContent = (typeof it === "object" ? (it.label || "") : String(it)) + " — " + values[i];
|
|
94
|
+
row.appendChild(lbl);
|
|
95
|
+
list.appendChild(row);
|
|
96
|
+
});
|
|
97
|
+
this.appendChild(list);
|
|
98
|
+
if (!items.length) renderEmpty(this, "donut");
|
|
99
|
+
const note = this.getAttribute("note");
|
|
100
|
+
let noteEl = this.querySelector(".c-donut__note");
|
|
101
|
+
if (note) {
|
|
102
|
+
if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-donut__note"; this.appendChild(noteEl); }
|
|
103
|
+
noteEl.textContent = note;
|
|
104
|
+
} else if (noteEl) {
|
|
105
|
+
noteEl.remove();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
enhance() {
|
|
109
|
+
if (this._wiredDonut) return;
|
|
110
|
+
this._wiredDonut = true;
|
|
111
|
+
// Slices are focusable marks needing keyboard contract (roving tabindex, arrows, Enter/Space) like bar/point marks.
|
|
112
|
+
const slices = () => Array.from(this.querySelectorAll(".c-donut__slice"));
|
|
113
|
+
const activate = (s) => {
|
|
114
|
+
const idx = Number(s.dataset.index);
|
|
115
|
+
if (!Number.isFinite(idx)) return;
|
|
116
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: 1, index: idx, value: s.getAttribute("data-title") || s.getAttribute("title") } }));
|
|
117
|
+
};
|
|
118
|
+
this.addEventListener("keydown", (e) => {
|
|
119
|
+
const s = e.target && e.target.closest ? e.target.closest(".c-donut__slice") : null;
|
|
120
|
+
if (!s || !this.contains(s)) return;
|
|
121
|
+
const list = slices();
|
|
122
|
+
const idx = list.indexOf(s);
|
|
123
|
+
let next = -1;
|
|
124
|
+
if (e.key === "ArrowRight" || e.key === "ArrowDown") next = Math.min(idx + 1, list.length - 1);
|
|
125
|
+
else if (e.key === "ArrowLeft" || e.key === "ArrowUp") next = Math.max(idx - 1, 0);
|
|
126
|
+
else if (e.key === "Home") next = 0;
|
|
127
|
+
else if (e.key === "End") next = list.length - 1;
|
|
128
|
+
else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); activate(s); return; }
|
|
129
|
+
if (next >= 0 && next !== idx) {
|
|
130
|
+
e.preventDefault();
|
|
131
|
+
list.forEach((c, i) => c.setAttribute("tabindex", i === next ? "0" : "-1"));
|
|
132
|
+
try { list[next].focus(); } catch (err) {}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
this.addEventListener("click", (e) => {
|
|
136
|
+
const s = e.target && e.target.closest ? e.target.closest(".c-donut__slice") : null;
|
|
137
|
+
if (s && this.contains(s)) activate(s);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
define("contour-donut", ContourDonut);
|
|
142
|
+
/**
|
|
143
|
+
* Time Series: web component wrapper.
|
|
144
|
+
* Attributes: `values`, `points`, `series-style`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
145
|
+
* R24-35: `annotations` was declared in observed/properties but never read in render(), so it was
|
|
146
|
+
* dropped from both.
|
|
147
|
+
*/
|
|
148
|
+
class ContourTimeSeries extends ContourBase {
|
|
149
|
+
static get observed() { return ["values", "points", "series", "series-style", "title", "brownout", "brownout-level", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "note", "cache-key", "no-cache"]; }
|
|
150
|
+
static get properties() { return { values: { attribute: "values" }, points: { attribute: "points" }, series: { attribute: "series" }, src: { attribute: "src" }, note: { attribute: "note" } }; }
|
|
151
|
+
render() {
|
|
152
|
+
this.classList.add("c-time-series");
|
|
153
|
+
// Points and bars are focusable marks (roving tabindex below); role=img
|
|
154
|
+
// hides them. A named group keeps the name and exposes the marks.
|
|
155
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
156
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Time series");
|
|
157
|
+
wireStates(this);
|
|
158
|
+
loadRemote(this, ["values", "points", "series"]);
|
|
159
|
+
if (renderStates(this, "time-series")) return;
|
|
160
|
+
// R24-87: ensure tooltip exists for focus/hover; id for aria-describedby
|
|
161
|
+
this.ensure(".c-time-series__tooltip", () => { const el = document.createElement("div"); el.className = "c-time-series__tooltip"; el.setAttribute("role", "tooltip"); el.setAttribute("hidden", ""); el.id = contourId("timeseries-tip"); return el; });
|
|
162
|
+
Array.from(this.querySelectorAll(".c-time-series__plot, .c-time-series__axis")).forEach((n) => n.remove());
|
|
163
|
+
// Series management (R16-21): multiple series via series JSON with per-series style/color/interval; falls back to single values attribute.
|
|
164
|
+
let series = [];
|
|
165
|
+
const sAttr = this.getAttribute("series");
|
|
166
|
+
if (sAttr) { series = parseArrayAttr(this, "series", warnBadJson); }
|
|
167
|
+
const remote = remoteData(this, "series");
|
|
168
|
+
if (Array.isArray(remote)) series = remote;
|
|
169
|
+
// Backward compat: single `values` attribute becomes one series.
|
|
170
|
+
if (!series.length) {
|
|
171
|
+
let values = [];
|
|
172
|
+
const vAttr = this.getAttribute("values");
|
|
173
|
+
if (vAttr) { values = parseArrayAttr(this, "values", warnBadJson); }
|
|
174
|
+
if (values.length) {
|
|
175
|
+
// `style` is global inline-CSS attr; reading it as chart style clobbered CSS. Namespaced `series-style` is the door now; legacy `style` honoured only when value is exactly a style keyword.
|
|
176
|
+
const legacy = (this.getAttribute("style") || "").trim().toLowerCase();
|
|
177
|
+
const seriesStyle = this.getAttribute("series-style") || ((legacy === "line" || legacy === "bar") ? legacy : "bar");
|
|
178
|
+
series = [{ label: "Series 1", values, style: seriesStyle, color: "var(--chart-1)" }];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const max = series.reduce((m, s) => { const v = Array.isArray(s.values) ? Math.max(...s.values, 0) : 0; return Math.max(m, v); }, 1);
|
|
182
|
+
const min = series.reduce((m, s) => { const v = Array.isArray(s.values) ? Math.min(...s.values, 0) : 0; return Math.min(m, v); }, 0);
|
|
183
|
+
const plot = document.createElement("div");
|
|
184
|
+
plot.className = "c-time-series__plot";
|
|
185
|
+
plot.setAttribute("part", "plot");
|
|
186
|
+
// R31-55: grouped bars are interleaved by index, not concatenated per
|
|
187
|
+
// series. The old loop appended every series-1 bar, then every series-2
|
|
188
|
+
// bar (order 1:0,1:1,1:2,2:0…), so a reader saw one series' full run
|
|
189
|
+
// before the next. Bars are queued per index and appended index-major.
|
|
190
|
+
const barQueue = [];
|
|
191
|
+
series.forEach((s, si) => {
|
|
192
|
+
const values = Array.isArray(s.values) ? s.values : [];
|
|
193
|
+
const style = s.style || "bar";
|
|
194
|
+
const color = s.color || `var(--chart-${((si % 8) + 1)})`;
|
|
195
|
+
const label = s.label || `Series ${si + 1}`;
|
|
196
|
+
if (style === "line") {
|
|
197
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
198
|
+
svg.setAttribute("viewBox", "0 0 300 120");
|
|
199
|
+
svg.setAttribute("preserveAspectRatio", "none");
|
|
200
|
+
svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
|
|
201
|
+
const range = (max - min) || 1;
|
|
202
|
+
const n = values.length || 1;
|
|
203
|
+
const pts = values.map((v, i) => {
|
|
204
|
+
const x = (i / Math.max(1, n - 1)) * 300;
|
|
205
|
+
const y = 120 - ((v - min) / range) * 120;
|
|
206
|
+
return x.toFixed(2) + "," + y.toFixed(2);
|
|
207
|
+
}).join(" ");
|
|
208
|
+
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
209
|
+
path.setAttribute("class", "c-time-series__line");
|
|
210
|
+
// R24-30: 1-based series index, matching the chart family and the [data-series="1..8"] dash rules. The old 0-based value left series 0 with no rule (solid) and shifted every other series by one.
|
|
211
|
+
path.setAttribute("data-series", String(si + 1));
|
|
212
|
+
path.setAttribute("d", "M " + pts.replace(/ /g, " L "));
|
|
213
|
+
path.style.stroke = color;
|
|
214
|
+
path.style.fill = "none";
|
|
215
|
+
path.style.strokeWidth = "2";
|
|
216
|
+
svg.appendChild(path);
|
|
217
|
+
// point markers
|
|
218
|
+
values.forEach((v, i) => {
|
|
219
|
+
const x = (i / Math.max(1, n - 1)) * 300;
|
|
220
|
+
const y = 120 - ((v - min) / range) * 120;
|
|
221
|
+
const c = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
222
|
+
c.setAttribute("class", "c-time-series__point");
|
|
223
|
+
c.setAttribute("data-series", String(si + 1));
|
|
224
|
+
c.setAttribute("data-index", String(i));
|
|
225
|
+
c.setAttribute("cx", x.toFixed(2));
|
|
226
|
+
c.setAttribute("cy", y.toFixed(2));
|
|
227
|
+
c.setAttribute("r", "3");
|
|
228
|
+
c.setAttribute("tabindex", i === 0 && si === 0 ? "0" : "-1");
|
|
229
|
+
c.setAttribute("role", "button");
|
|
230
|
+
c.setAttribute("data-title", String(v));
|
|
231
|
+
c.setAttribute("aria-label", label + ": " + String(v));
|
|
232
|
+
svg.appendChild(c);
|
|
233
|
+
});
|
|
234
|
+
plot.appendChild(svg);
|
|
235
|
+
} else {
|
|
236
|
+
values.forEach((v, i) => {
|
|
237
|
+
const bar = document.createElement("div");
|
|
238
|
+
bar.className = "c-time-series__bar";
|
|
239
|
+
bar.setAttribute("data-series", String(si + 1));
|
|
240
|
+
bar.setAttribute("data-index", String(i));
|
|
241
|
+
bar.style.blockSize = ((v / max) * 100) + "%";
|
|
242
|
+
bar.style.background = safeColor(color);
|
|
243
|
+
bar.setAttribute("data-title", String(v));
|
|
244
|
+
// Clickable focusable mark is a button (not image); point marks carry same role.
|
|
245
|
+
bar.setAttribute("role", "button");
|
|
246
|
+
bar.setAttribute("aria-label", label + ": " + String(v));
|
|
247
|
+
bar.setAttribute("tabindex", i === 0 && si === 0 ? "0" : "-1");
|
|
248
|
+
(barQueue[i] || (barQueue[i] = [])).push(bar);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
// R31-55: append bars index-major (i outer, series inner) so grouped
|
|
253
|
+
// series read 1:0,2:0,1:1,2:1… instead of 1:0,1:1,2:0,2:1.
|
|
254
|
+
barQueue.forEach((group) => { if (group) group.forEach((bar) => plot.appendChild(bar)); });
|
|
255
|
+
this.appendChild(plot);
|
|
256
|
+
// R31-55: an index/time x-axis so a reader can map a bar to its x. Uses
|
|
257
|
+
// the first series' x values when present, else the index.
|
|
258
|
+
const firstSeries = series.find((s) => Array.isArray(s.values) && s.values.length);
|
|
259
|
+
const axisLen = firstSeries ? firstSeries.values.length : 0;
|
|
260
|
+
if (axisLen > 1) {
|
|
261
|
+
const axis = document.createElement("div");
|
|
262
|
+
axis.className = "c-time-series__axis";
|
|
263
|
+
const xs = firstSeries.x;
|
|
264
|
+
[0, Math.floor((axisLen - 1) / 2), axisLen - 1]
|
|
265
|
+
.filter((v, i, a) => v >= 0 && a.indexOf(v) === i)
|
|
266
|
+
.forEach((idx) => {
|
|
267
|
+
const tick = document.createElement("span");
|
|
268
|
+
tick.className = "c-time-series__tick";
|
|
269
|
+
tick.textContent = (Array.isArray(xs) && xs[idx] != null) ? String(xs[idx]) : String(idx);
|
|
270
|
+
axis.appendChild(tick);
|
|
271
|
+
});
|
|
272
|
+
this.appendChild(axis);
|
|
273
|
+
}
|
|
274
|
+
if (!series.length || !series.some((s) => Array.isArray(s.values) && s.values.length)) renderEmpty(this, "time-series");
|
|
275
|
+
// R25-03: the note is chrome (shed ≥2); an authored axis row is chrome too and sheds at marks-only (≥3). The bars/points are the marks and survive every level.
|
|
276
|
+
const note = this.getAttribute("note");
|
|
277
|
+
let noteEl = this.querySelector(".c-time-series__note");
|
|
278
|
+
if (note && !this.shed("note", 2)) {
|
|
279
|
+
if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-time-series__note"; this.appendChild(noteEl); }
|
|
280
|
+
noteEl.textContent = note;
|
|
281
|
+
} else if (noteEl) {
|
|
282
|
+
noteEl.remove();
|
|
283
|
+
}
|
|
284
|
+
const tsAxis = this.querySelector(".c-time-series__axis");
|
|
285
|
+
if (tsAxis) tsAxis.style.display = this.shed("axis", 3) ? "none" : "";
|
|
286
|
+
}
|
|
287
|
+
enhance() {
|
|
288
|
+
if (this._wiredTimeSeries) return;
|
|
289
|
+
this._wiredTimeSeries = true;
|
|
290
|
+
const bars = () => Array.from(this.querySelectorAll(".c-time-series__bar"));
|
|
291
|
+
const points = () => Array.from(this.querySelectorAll(".c-time-series__point"));
|
|
292
|
+
this.addEventListener("click", (e) => {
|
|
293
|
+
const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
|
|
294
|
+
if (!bar || !this.contains(bar)) return;
|
|
295
|
+
const seriesIdx = Number(bar.dataset.series || "0");
|
|
296
|
+
const idx = Number(bar.dataset.index || "0");
|
|
297
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: seriesIdx, index: idx, value: bar.getAttribute("data-title") || bar.getAttribute("title") } }));
|
|
298
|
+
return;
|
|
299
|
+
});
|
|
300
|
+
const pointClick = (e) => {
|
|
301
|
+
const point = e.target && e.target.closest ? e.target.closest(".c-time-series__point") : null;
|
|
302
|
+
if (!point || !this.contains(point)) return;
|
|
303
|
+
const seriesIdx = Number(point.dataset.series || "0");
|
|
304
|
+
const idx = Number(point.dataset.index || "0");
|
|
305
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: seriesIdx, index: idx, value: point.getAttribute("data-title") || point.getAttribute("title") } }));
|
|
306
|
+
};
|
|
307
|
+
this.addEventListener("click", pointClick);
|
|
308
|
+
this.addEventListener("keydown", (e) => {
|
|
309
|
+
const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
|
|
310
|
+
const point = e.target && e.target.closest ? e.target.closest(".c-time-series__point") : null;
|
|
311
|
+
const mark = bar || point;
|
|
312
|
+
if (!mark || !this.contains(mark)) return;
|
|
313
|
+
const all = bar ? bars() : points();
|
|
314
|
+
const idx = all.indexOf(mark);
|
|
315
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
316
|
+
e.preventDefault();
|
|
317
|
+
const seriesIdx = Number(mark.dataset.series || "0");
|
|
318
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: seriesIdx, index: idx, value: mark.getAttribute("data-title") || mark.getAttribute("title") } }));
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
navKey(e, all, {
|
|
322
|
+
wrap: false,
|
|
323
|
+
homeEnd: true,
|
|
324
|
+
rtl: isRtl(this),
|
|
325
|
+
onNavigate: (i) => all.forEach((b, j) => b.setAttribute("tabindex", j === i ? "0" : "-1")),
|
|
326
|
+
onKey: () => {}
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
// focus tooltip
|
|
330
|
+
this.addEventListener("focusin", (e) => {
|
|
331
|
+
const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
|
|
332
|
+
if (bar && this.contains(bar)) {
|
|
333
|
+
const tip = this.querySelector(".c-time-series__tooltip");
|
|
334
|
+
if (tip) { tip.textContent = bar.getAttribute("data-title") || bar.getAttribute("title"); tip.removeAttribute("hidden"); if (tip.id) bar.setAttribute("aria-describedby", tip.id); }
|
|
335
|
+
}
|
|
336
|
+
const point = e.target && e.target.closest ? e.target.closest(".c-time-series__point") : null;
|
|
337
|
+
if (point && this.contains(point)) {
|
|
338
|
+
const tip = this.querySelector(".c-time-series__tooltip");
|
|
339
|
+
if (tip) { tip.textContent = point.getAttribute("data-title") || point.getAttribute("title"); tip.removeAttribute("hidden"); if (tip.id) point.setAttribute("aria-describedby", tip.id); }
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
this.addEventListener("focusout", (e) => {
|
|
343
|
+
const mark = (e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null) || (e.target && e.target.closest ? e.target.closest(".c-time-series__point") : null);
|
|
344
|
+
if (mark && this.contains(mark)) mark.removeAttribute("aria-describedby");
|
|
345
|
+
const tip = this.querySelector(".c-time-series__tooltip");
|
|
346
|
+
if (tip && !this.contains(e.relatedTarget)) tip.setAttribute("hidden", "");
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
define("contour-time-series", ContourTimeSeries);
|
|
351
|
+
/**
|
|
352
|
+
* Pivot: web component wrapper.
|
|
353
|
+
* Attributes: `rows`, `columns`, `values`, `data`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
354
|
+
*/
|
|
355
|
+
class ContourPivot extends ContourBase {
|
|
356
|
+
static get observed() { return ["rows", "columns", "values", "data", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "filter", "aggregate", "cache-key", "no-cache"]; }
|
|
357
|
+
static get properties() { return { rows: { attribute: "rows" }, columns: { attribute: "columns" }, values: { attribute: "values" }, data: { attribute: "data" }, src: { attribute: "src" }, filter: { attribute: "filter" }, aggregate: { attribute: "aggregate" } }; }
|
|
358
|
+
_aggregateFn(name) {
|
|
359
|
+
const n = (name || "sum").toLowerCase();
|
|
360
|
+
if (n === "avg" || n === "average" || n === "mean") return (vals) => vals.length ? vals.reduce((a,b)=>a+b,0)/vals.length : 0;
|
|
361
|
+
if (n === "count") return (vals) => vals.length;
|
|
362
|
+
if (n === "min") return (vals) => vals.length ? Math.min(...vals) : 0;
|
|
363
|
+
if (n === "max") return (vals) => vals.length ? Math.max(...vals) : 0;
|
|
364
|
+
return (vals) => vals.reduce((a,b)=>a+b,0);
|
|
365
|
+
}
|
|
366
|
+
render() {
|
|
367
|
+
this.classList.add("c-pivot");
|
|
368
|
+
wireStates(this);
|
|
369
|
+
loadRemote(this, ["data"]);
|
|
370
|
+
if (renderStates(this, "pivot")) return;
|
|
371
|
+
Array.from(this.querySelectorAll("table, .c-pivot__wrap, .c-pivot__toolbar, .c-pivot__empty")).forEach((n) => n.remove());
|
|
372
|
+
let data = [];
|
|
373
|
+
const dAttr = this.getAttribute("data");
|
|
374
|
+
if (dAttr) { try { data = JSON.parse(dAttr); } catch (e) { warnBadJson(this, "data", e); data = []; } }
|
|
375
|
+
const rows = this.getAttribute("rows") ? this.getAttribute("rows").split(",").map((s)=>s.trim()).filter(Boolean) : [];
|
|
376
|
+
const cols = this.getAttribute("columns") ? this.getAttribute("columns").split(",").map((s)=>s.trim()).filter(Boolean) : [];
|
|
377
|
+
const aggName = this.getAttribute("aggregate") || "sum";
|
|
378
|
+
const aggFn = this._aggregateFn(aggName);
|
|
379
|
+
const filterQ = (this.getAttribute("filter") || "").toLowerCase().trim();
|
|
380
|
+
// Toolbar: filter input + aggregate selector.
|
|
381
|
+
const toolbar = document.createElement("div");
|
|
382
|
+
toolbar.className = "c-pivot__toolbar";
|
|
383
|
+
toolbar.style.display = "flex";
|
|
384
|
+
const filterInput = document.createElement("input");
|
|
385
|
+
filterInput.type = "search";
|
|
386
|
+
filterInput.className = "c-input c-pivot__filter";
|
|
387
|
+
filterInput.placeholder = labelText(this, "filter", "Filter…");
|
|
388
|
+
filterInput.value = this.getAttribute("filter") || "";
|
|
389
|
+
filterInput.setAttribute("aria-label", labelText(this, "filter-pivot", "Filter pivot"));
|
|
390
|
+
const aggSelect = document.createElement("select");
|
|
391
|
+
aggSelect.className = "c-select c-pivot__aggregate";
|
|
392
|
+
aggSelect.setAttribute("aria-label", labelText(this, "aggregation", "Aggregation"));
|
|
393
|
+
["sum","avg","count","min","max"].forEach((a) => {
|
|
394
|
+
const opt = document.createElement("option");
|
|
395
|
+
opt.value = a; opt.textContent = a;
|
|
396
|
+
if (a === aggName) opt.selected = true;
|
|
397
|
+
aggSelect.appendChild(opt);
|
|
398
|
+
});
|
|
399
|
+
toolbar.appendChild(filterInput);
|
|
400
|
+
toolbar.appendChild(aggSelect);
|
|
401
|
+
this.appendChild(toolbar);
|
|
402
|
+
// Filter rows/cols.
|
|
403
|
+
let visibleRows = rows;
|
|
404
|
+
let visibleCols = cols;
|
|
405
|
+
if (filterQ) {
|
|
406
|
+
visibleRows = rows.filter((r) => r.toLowerCase().includes(filterQ) || data.some((d) => d.row === r && String(d.value).toLowerCase().includes(filterQ)));
|
|
407
|
+
visibleCols = cols.filter((c) => c.toLowerCase().includes(filterQ) || data.some((d) => d.col === c && String(d.value).toLowerCase().includes(filterQ)));
|
|
408
|
+
}
|
|
409
|
+
if (!data.length && !rows.length && !cols.length) {
|
|
410
|
+
renderEmpty(this, "pivot");
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (filterQ && (!visibleRows.length || !visibleCols.length)) {
|
|
414
|
+
const empty = document.createElement("div");
|
|
415
|
+
empty.className = "c-pivot__empty";
|
|
416
|
+
empty.setAttribute("role", "status");
|
|
417
|
+
empty.textContent = this.getAttribute("empty") || labelText(this, "empty", "No matching data");
|
|
418
|
+
this.appendChild(empty);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
// R31-59: a column-header click actually sorts the rows by that column's
|
|
422
|
+
// aggregate (toggling desc/asc). The element only emitted contour:sort
|
|
423
|
+
// before, so the header looked interactive and did nothing.
|
|
424
|
+
if (this._pivotSort && this._pivotSort.col) {
|
|
425
|
+
const sortCol = this._pivotSort.col;
|
|
426
|
+
const sortDir = this._pivotSort.dir === "asc" ? 1 : -1;
|
|
427
|
+
const cellAgg = (row) => aggFn(data.filter((d) => d.row === row && d.col === sortCol).map((d) => Number(d.value)).filter((n) => Number.isFinite(n)));
|
|
428
|
+
visibleRows = visibleRows.slice().sort((ra, rb) => (cellAgg(ra) - cellAgg(rb)) * sortDir);
|
|
429
|
+
}
|
|
430
|
+
const wrap = document.createElement("div");
|
|
431
|
+
wrap.className = "c-table-wrap c-pivot__wrap";
|
|
432
|
+
const table = document.createElement("table");
|
|
433
|
+
table.className = "c-table c-pivot__table";
|
|
434
|
+
table.setAttribute("role", "grid");
|
|
435
|
+
table.setAttribute("aria-rowcount", String(visibleRows.length + 1));
|
|
436
|
+
table.setAttribute("aria-colcount", String(visibleCols.length + 1));
|
|
437
|
+
const thead = document.createElement("thead");
|
|
438
|
+
const hr = document.createElement("tr");
|
|
439
|
+
const corner = document.createElement("th");
|
|
440
|
+
corner.textContent = "";
|
|
441
|
+
corner.setAttribute("role", "columnheader");
|
|
442
|
+
corner.setAttribute("aria-label", labelText(this, "row", "Row"));
|
|
443
|
+
hr.appendChild(corner);
|
|
444
|
+
let firstCellSeeded = false;
|
|
445
|
+
visibleCols.forEach((c) => {
|
|
446
|
+
const th = document.createElement("th");
|
|
447
|
+
th.textContent = c;
|
|
448
|
+
th.setAttribute("role", "columnheader");
|
|
449
|
+
th.setAttribute("tabindex", firstCellSeeded ? "-1" : "0");
|
|
450
|
+
firstCellSeeded = true;
|
|
451
|
+
hr.appendChild(th);
|
|
452
|
+
});
|
|
453
|
+
thead.appendChild(hr);
|
|
454
|
+
table.appendChild(thead);
|
|
455
|
+
const tbody = document.createElement("tbody");
|
|
456
|
+
visibleRows.forEach((r) => {
|
|
457
|
+
const tr = document.createElement("tr");
|
|
458
|
+
tr.setAttribute("role", "row");
|
|
459
|
+
const th = document.createElement("th");
|
|
460
|
+
th.textContent = r;
|
|
461
|
+
th.setAttribute("role", "rowheader");
|
|
462
|
+
th.setAttribute("tabindex", firstCellSeeded ? "-1" : "0");
|
|
463
|
+
firstCellSeeded = true;
|
|
464
|
+
tr.appendChild(th);
|
|
465
|
+
visibleCols.forEach((c) => {
|
|
466
|
+
const td = document.createElement("td");
|
|
467
|
+
td.setAttribute("role", "gridcell");
|
|
468
|
+
td.setAttribute("tabindex", "-1");
|
|
469
|
+
td.dataset.row = r;
|
|
470
|
+
td.dataset.col = c;
|
|
471
|
+
const cellData = data.filter((d) => d.row === r && d.col === c);
|
|
472
|
+
const vals = cellData.map((d) => Number(d.value)).filter((n) => Number.isFinite(n));
|
|
473
|
+
if (cellData.length && vals.length === cellData.length && vals.length) {
|
|
474
|
+
const v = aggFn(vals);
|
|
475
|
+
td.textContent = Number.isInteger(v) ? String(v) : v.toFixed(2);
|
|
476
|
+
} else if (cellData.length) {
|
|
477
|
+
td.textContent = cellData.map((d) => d.value).join(", ");
|
|
478
|
+
} else {
|
|
479
|
+
td.textContent = "";
|
|
480
|
+
}
|
|
481
|
+
if (!td.textContent.trim()) td.setAttribute("aria-label", labelText(this, "empty", "Empty"));
|
|
482
|
+
tr.appendChild(td);
|
|
483
|
+
});
|
|
484
|
+
tbody.appendChild(tr);
|
|
485
|
+
});
|
|
486
|
+
table.appendChild(tbody);
|
|
487
|
+
wrap.appendChild(table);
|
|
488
|
+
this.appendChild(wrap);
|
|
489
|
+
}
|
|
490
|
+
enhance() {
|
|
491
|
+
if (this._wiredPivot) return;
|
|
492
|
+
this._wiredPivot = true;
|
|
493
|
+
this.addEventListener("click", (e) => {
|
|
494
|
+
const th = e.target && e.target.closest ? e.target.closest("th") : null;
|
|
495
|
+
const td = e.target && e.target.closest ? e.target.closest("td") : null;
|
|
496
|
+
const filterInput = e.target && e.target.closest ? e.target.closest(".c-pivot__filter") : null;
|
|
497
|
+
const aggSelect = e.target && e.target.closest ? e.target.closest(".c-pivot__aggregate") : null;
|
|
498
|
+
if (filterInput) return;
|
|
499
|
+
if (aggSelect) return;
|
|
500
|
+
if (th && this.contains(th) && th.parentElement && th.parentElement.parentElement && th.parentElement.parentElement.tagName === "THEAD") {
|
|
501
|
+
const col = th.textContent.trim();
|
|
502
|
+
if (col) {
|
|
503
|
+
// R31-59: sort rows by this column, toggling direction on repeat.
|
|
504
|
+
const cur = this._pivotSort;
|
|
505
|
+
this._pivotSort = { col, dir: cur && cur.col === col && cur.dir === "desc" ? "asc" : "desc" };
|
|
506
|
+
this.requestRender();
|
|
507
|
+
}
|
|
508
|
+
this.dispatchEvent(new CustomEvent("contour:sort", { bubbles: true, composed: true, detail: { column: col } }));
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
if (td && this.contains(td)) {
|
|
512
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { row: td.dataset.row || "", col: td.dataset.col || "", value: td.textContent } }));
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
this.addEventListener("input", (e) => {
|
|
516
|
+
const fi = e.target && e.target.closest ? e.target.closest(".c-pivot__filter") : null;
|
|
517
|
+
if (fi && this.contains(fi)) {
|
|
518
|
+
// setAttribute re-renders (filter in observed); extra this.render() caused double render and focus loss to body (DW-3).
|
|
519
|
+
this.setAttribute("filter", fi.value);
|
|
520
|
+
this.dispatchEvent(new CustomEvent("contour:filter", { bubbles: true, composed: true, detail: { query: fi.value } }));
|
|
521
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "pivot", filter: { filter: fi.value } } }));
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
this.addEventListener("change", (e) => {
|
|
525
|
+
const as = e.target && e.target.closest ? e.target.closest(".c-pivot__aggregate") : null;
|
|
526
|
+
if (as && this.contains(as)) {
|
|
527
|
+
// Same reason as the filter input: the attribute write re-renders.
|
|
528
|
+
this.setAttribute("aggregate", as.value);
|
|
529
|
+
this.dispatchEvent(new CustomEvent("contour:aggregate", { bubbles: true, composed: true, detail: { aggregate: as.value } }));
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
this.addEventListener("keydown", (e) => {
|
|
533
|
+
const cell = e.target && e.target.closest ? e.target.closest("th, td") : null;
|
|
534
|
+
if (!cell || !this.contains(cell)) return;
|
|
535
|
+
const table = this.querySelector("table");
|
|
536
|
+
if (!table) return;
|
|
537
|
+
const rows = Array.from(table.querySelectorAll("tr"));
|
|
538
|
+
const ri = rows.indexOf(cell.parentElement);
|
|
539
|
+
const ci = Array.from(cell.parentElement.children).indexOf(cell);
|
|
540
|
+
let target = null;
|
|
541
|
+
if (e.key === "ArrowRight") target = cell.parentElement.children[ci + 1];
|
|
542
|
+
else if (e.key === "ArrowLeft") target = cell.parentElement.children[ci - 1];
|
|
543
|
+
else if (e.key === "ArrowDown") target = rows[ri + 1] && rows[ri + 1].children[ci];
|
|
544
|
+
else if (e.key === "ArrowUp") target = rows[ri - 1] && rows[ri - 1].children[ci];
|
|
545
|
+
else if (e.key === "Home") target = cell.parentElement.children[0];
|
|
546
|
+
else if (e.key === "End") target = cell.parentElement.children[cell.parentElement.children.length - 1];
|
|
547
|
+
if (target) { e.preventDefault(); try { target.focus(); } catch (err) {} }
|
|
548
|
+
});
|
|
549
|
+
// Cross-filter contract (R16-16): clear-all resets pivot filter.
|
|
550
|
+
this.addEventListener("contour:clear-all", () => {
|
|
551
|
+
if (this.hasAttribute("filter")) {
|
|
552
|
+
this.removeAttribute("filter");
|
|
553
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "pivot", filter: { filter: null } } }));
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
define("contour-pivot", ContourPivot);
|
|
559
|
+
/**
|
|
560
|
+
* Widget State: web component wrapper.
|
|
561
|
+
* Attributes: `loading`, `error`, `empty`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
562
|
+
*/
|
|
563
|
+
class ContourWidgetState extends ContourBase {
|
|
564
|
+
static get observed() { return ["loading", "error", "empty", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
565
|
+
static get properties() { return { loading: { attribute: "loading" }, error: { attribute: "error" }, empty: { attribute: "empty" }, retry: { attribute: "retry" }, src: { attribute: "src" } }; }
|
|
566
|
+
render() {
|
|
567
|
+
this.classList.add("c-widget-state");
|
|
568
|
+
wireStates(this);
|
|
569
|
+
loadRemote(this, []);
|
|
570
|
+
if (renderStates(this, "widget-state")) return;
|
|
571
|
+
// if no state, render slotted content (already in DOM)
|
|
572
|
+
}
|
|
573
|
+
enhance() {}
|
|
574
|
+
}
|
|
575
|
+
define("contour-widget-state", ContourWidgetState);
|
|
576
|
+
/**
|
|
577
|
+
* Brownout: web component wrapper.
|
|
578
|
+
* Attributes: `level`.
|
|
579
|
+
*
|
|
580
|
+
* A level indicator AND a shed surface for its light-DOM children (R25-03,
|
|
581
|
+
* owner decision D2). A child hides when the level reaches its shed
|
|
582
|
+
* threshold: `data-shed="N"` sets the threshold, the default is 2 (the
|
|
583
|
+
* chart-family chrome threshold), and `data-essential` marks a child that
|
|
584
|
+
* survives every level. The element's own indicator chrome (decorative bar,
|
|
585
|
+
* "Level N" label) is never shed by this rule — the CSS hides the bar at
|
|
586
|
+
* level 3. Shedding is display-only and reversible: the child's prior inline
|
|
587
|
+
* display is restored when the level drops.
|
|
588
|
+
*/
|
|
589
|
+
class ContourBrownout extends ContourBase {
|
|
590
|
+
static get observed() { return ["level"]; }
|
|
591
|
+
static get properties() { return { level: { attribute: "level" } }; }
|
|
592
|
+
render() {
|
|
593
|
+
this.classList.add("c-brownout");
|
|
594
|
+
const level = this.getAttribute("level") || "0";
|
|
595
|
+
this.dataset.level = level;
|
|
596
|
+
this.setAttribute("data-level", level);
|
|
597
|
+
// Decorative bar (visual indicator of the brownout level).
|
|
598
|
+
let deco = this.querySelector(".c-brownout__decorative");
|
|
599
|
+
if (!deco) { deco = document.createElement("span"); deco.className = "c-brownout__decorative"; deco.setAttribute("aria-hidden", "true"); this.appendChild(deco); }
|
|
600
|
+
// Label (text description of the level).
|
|
601
|
+
let lbl = this.querySelector(".c-brownout__label");
|
|
602
|
+
if (!lbl) { lbl = document.createElement("span"); lbl.className = "c-brownout__label"; this.appendChild(lbl); }
|
|
603
|
+
lbl.textContent = labelText(this, "level", "Level") + " " + level;
|
|
604
|
+
// Child shed surface. The prior inline display is remembered per node
|
|
605
|
+
// so restoring never clobbers an author's own inline display value.
|
|
606
|
+
const lvl = parseInt(level, 10) || 0;
|
|
607
|
+
if (!this._shedDisplay) this._shedDisplay = new WeakMap();
|
|
608
|
+
Array.from(this.children).forEach((child) => {
|
|
609
|
+
if (child.classList.contains("c-brownout__decorative") || child.classList.contains("c-brownout__label")) return;
|
|
610
|
+
const threshold = parseInt(child.getAttribute("data-shed") || "2", 10);
|
|
611
|
+
const hide = !child.hasAttribute("data-essential") && Number.isFinite(threshold) && lvl >= threshold;
|
|
612
|
+
if (hide) {
|
|
613
|
+
if (!this._shedDisplay.has(child)) this._shedDisplay.set(child, child.style.display);
|
|
614
|
+
child.style.display = "none";
|
|
615
|
+
} else if (this._shedDisplay.has(child)) {
|
|
616
|
+
child.style.display = this._shedDisplay.get(child);
|
|
617
|
+
this._shedDisplay.delete(child);
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
enhance() {}
|
|
622
|
+
}
|
|
623
|
+
define("contour-brownout", ContourBrownout);
|
|
624
|
+
/**
|
|
625
|
+
* Instrument: web component wrapper.
|
|
626
|
+
* Attributes: `rows`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
627
|
+
*/
|
|
628
|
+
class ContourInstrument extends ContourBase {
|
|
629
|
+
static get observed() { return ["rows", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
630
|
+
static get properties() { return { rows: { attribute: "rows" }, src: { attribute: "src" } }; }
|
|
631
|
+
render() {
|
|
632
|
+
this.classList.add("c-instrument");
|
|
633
|
+
wireStates(this);
|
|
634
|
+
loadRemote(this, "rows");
|
|
635
|
+
if (renderStates(this, "instrument")) return;
|
|
636
|
+
const rows = remoteData(this, "rows");
|
|
637
|
+
// The block's two parts are `__item` and `__value`: the label is the text the item opens with, and the value is the span inside it. There is no `__row` and no `__key` — the separators between items are CSS `::before`.
|
|
638
|
+
Array.from(this.querySelectorAll(".c-instrument__item")).forEach((n) => n.remove());
|
|
639
|
+
if (rows) {
|
|
640
|
+
try {
|
|
641
|
+
const parsed = JSON.parse(rows);
|
|
642
|
+
parsed.forEach((r) => {
|
|
643
|
+
const item = document.createElement("span");
|
|
644
|
+
item.className = "c-instrument__item";
|
|
645
|
+
item.appendChild(document.createTextNode(String(r.key || r[0] || "")));
|
|
646
|
+
const val = document.createElement("span");
|
|
647
|
+
val.className = "c-instrument__value";
|
|
648
|
+
val.textContent = r.value || r[1] || "";
|
|
649
|
+
item.appendChild(val);
|
|
650
|
+
this.appendChild(item);
|
|
651
|
+
});
|
|
652
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
653
|
+
} else {
|
|
654
|
+
renderEmpty(this, "instrument");
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
define("contour-instrument", ContourInstrument);
|
|
659
|
+
/**
|
|
660
|
+
* Bivariate: web component wrapper.
|
|
661
|
+
* Attributes: `size`, `axis-x`, `axis-y`, `colors`, `selected`.
|
|
662
|
+
*/
|
|
663
|
+
class ContourBivariate extends ContourBase {
|
|
664
|
+
static get observed() { return ["size", "axis-x", "axis-y", "colors", "selected"]; }
|
|
665
|
+
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" }, selected: { attribute: "selected" } }; }
|
|
666
|
+
|
|
667
|
+
// Hooks overridden by contour-bivariate-legend:
|
|
668
|
+
get _bvBlock() { return "c-bivariate"; }
|
|
669
|
+
get _bvDefaultAxisX() { return "Income"; }
|
|
670
|
+
get _bvDefaultAxisY() { return "Density"; }
|
|
671
|
+
get _bvLiveClassName() { return `${this._bvBlock}__live`; }
|
|
672
|
+
get _bvLiveInlineStyles() { return true; }
|
|
673
|
+
get _bvAnnounce() { return false; }
|
|
674
|
+
|
|
675
|
+
render() {
|
|
676
|
+
this.classList.add(this._bvBlock);
|
|
677
|
+
this.setAttribute("role", "group");
|
|
678
|
+
// R24-36: avoid clobbering author-provided aria-label; track auto-set value
|
|
679
|
+
const name = "Bivariate legend";
|
|
680
|
+
const currentAria = this.getAttribute("aria-label");
|
|
681
|
+
if (currentAria === null || currentAria === this._lastAutoAria) {
|
|
682
|
+
this.setAttribute("aria-label", name);
|
|
683
|
+
this._lastAutoAria = name;
|
|
684
|
+
}
|
|
685
|
+
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") ?? "3", 10) ?? 3));
|
|
686
|
+
// R24-33: name the axes the reader actually gets.
|
|
687
|
+
const axisYName = this.getAttribute("axis-y") ?? this._bvDefaultAxisY;
|
|
688
|
+
const axisXName = this.getAttribute("axis-x") ?? this._bvDefaultAxisX;
|
|
689
|
+
const matrix = this.ensure(`.${this._bvBlock}__matrix`, () => { const el = document.createElement("div"); el.className = `${this._bvBlock}__matrix`; return el; });
|
|
690
|
+
matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
|
|
691
|
+
matrix.style.gridTemplateRows = `repeat(${size}, 1fr)`;
|
|
692
|
+
// Slot composition: authored cells win over the generated grid.
|
|
693
|
+
const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains(`${this._bvBlock}__cell`));
|
|
694
|
+
if (!authored.length) {
|
|
695
|
+
matrix.innerHTML = "";
|
|
696
|
+
let colors = parseArrayAttr(this, "colors", warnBadJson);
|
|
697
|
+
// Default two-hue ramp (blue×red) when no colors attribute is provided, so a no-colors instance still encodes a bivariate relationship rather than rendering a uniform surface-2 matrix.
|
|
698
|
+
if (!colors.length) {
|
|
699
|
+
const defaultRamp = ["#e8e8e8","#b5c0da","#2a5a99","#e4acac","#b07f99","#2d3a6b","#c85a5a","#994d6e","#2a1a30"];
|
|
700
|
+
colors = defaultRamp.slice(0, size * size);
|
|
701
|
+
}
|
|
702
|
+
for (let r = 0; r < size; r++) {
|
|
703
|
+
for (let c = 0; c < size; c++) {
|
|
704
|
+
const cell = document.createElement("div");
|
|
705
|
+
cell.className = `${this._bvBlock}__cell`;
|
|
706
|
+
cell.setAttribute("role", "button");
|
|
707
|
+
// R24-33: roving tabindex — one tab stop for the whole matrix, not one per cell. A 12×12 grid was 144 tab stops; ArrowRight moves focus to the next cell and rewrites the single "0" onto it.
|
|
708
|
+
cell.setAttribute("tabindex", (r === 0 && c === 0) ? "0" : "-1");
|
|
709
|
+
// Name axes reader gets: "Density 2 of 3, Income 2 of 3". Rows count from bottom matching palette order.
|
|
710
|
+
const rowFromBottom = size - r;
|
|
711
|
+
cell.setAttribute("aria-label", `${axisYName} ${rowFromBottom} of ${size}, ${axisXName} ${c + 1} of ${size}`);
|
|
712
|
+
// Palette runs from bottom-left (low/low) to top-right (high/high):
|
|
713
|
+
// reverse the row order so the first palette row sits at the bottom.
|
|
714
|
+
const srcIndex = (size - 1 - r) * size + c;
|
|
715
|
+
if (colors[srcIndex]) { const cellColor = safeColor(colors[srcIndex]); if (cellColor) { cell.style.background = cellColor; cell.dataset.color = cellColor; } }
|
|
716
|
+
matrix.appendChild(cell);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
// selected highlight
|
|
720
|
+
const sel = this.getAttribute("selected");
|
|
721
|
+
if (sel) {
|
|
722
|
+
const parts = sel.split(",");
|
|
723
|
+
const sr = parseInt(parts[0], 10);
|
|
724
|
+
const sc = parseInt(parts[1], 10);
|
|
725
|
+
const cells = Array.from(matrix.querySelectorAll(`.${this._bvBlock}__cell`));
|
|
726
|
+
cells.forEach((cell, i) => {
|
|
727
|
+
const rr = Math.floor(i / size);
|
|
728
|
+
const cc = i % size;
|
|
729
|
+
// matrix is row-major in DOM? cells appended row by row r then c, so index = r*size+c
|
|
730
|
+
if (rr === sr && cc === sc) cell.setAttribute("data-selected", "");
|
|
731
|
+
else cell.removeAttribute("data-selected");
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
// aria-live region
|
|
735
|
+
let live = this.querySelector(`.${this._bvBlock}__live`);
|
|
736
|
+
if (!live) {
|
|
737
|
+
live = document.createElement("div");
|
|
738
|
+
live.className = this._bvLiveClassName;
|
|
739
|
+
live.setAttribute("aria-live", "polite");
|
|
740
|
+
if (this._bvLiveInlineStyles) {
|
|
741
|
+
live.style.position = "absolute";
|
|
742
|
+
live.style.width = "1px";
|
|
743
|
+
live.style.height = "1px";
|
|
744
|
+
live.style.overflow = "hidden";
|
|
745
|
+
live.style.clip = "rect(0,0,0,0)";
|
|
746
|
+
}
|
|
747
|
+
this.appendChild(live);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
const axisX = this.getAttribute("axis-x");
|
|
751
|
+
if (axisX) {
|
|
752
|
+
const ax = this.ensure(`.${this._bvBlock}__axis--x`, () => { const el = document.createElement("div"); el.className = `${this._bvBlock}__axis ${this._bvBlock}__axis--x`; return el; });
|
|
753
|
+
ax.textContent = axisX;
|
|
754
|
+
} else {
|
|
755
|
+
const ax = this.querySelector(`.${this._bvBlock}__axis--x`);
|
|
756
|
+
if (ax) ax.remove();
|
|
757
|
+
}
|
|
758
|
+
const axisY = this.getAttribute("axis-y");
|
|
759
|
+
if (axisY) {
|
|
760
|
+
const ay = this.ensure(`.${this._bvBlock}__axis--y`, () => { const el = document.createElement("div"); el.className = `${this._bvBlock}__axis ${this._bvBlock}__axis--y`; return el; });
|
|
761
|
+
ay.textContent = axisY;
|
|
762
|
+
} else {
|
|
763
|
+
const ay = this.querySelector(`.${this._bvBlock}__axis--y`);
|
|
764
|
+
if (ay) ay.remove();
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
enhance() {
|
|
768
|
+
if (this._wiredBivariate) return;
|
|
769
|
+
this._wiredBivariate = true;
|
|
770
|
+
const selectCell = (cell) => {
|
|
771
|
+
const matrix = this.querySelector(`.${this._bvBlock}__matrix`);
|
|
772
|
+
const cells = Array.from(matrix ? matrix.querySelectorAll(`.${this._bvBlock}__cell`) : []);
|
|
773
|
+
const idx = cells.indexOf(cell);
|
|
774
|
+
if (idx < 0) return;
|
|
775
|
+
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
776
|
+
const row = Math.floor(idx / size);
|
|
777
|
+
const col = idx % size;
|
|
778
|
+
cells.forEach((cell, i) => {
|
|
779
|
+
const rr = Math.floor(i / size);
|
|
780
|
+
const cc = i % size;
|
|
781
|
+
if (rr === row && cc === col) cell.setAttribute("data-selected", "");
|
|
782
|
+
else cell.removeAttribute("data-selected");
|
|
783
|
+
});
|
|
784
|
+
if (this._bvAnnounce) {
|
|
785
|
+
const live = this.querySelector(`.${this._bvBlock}__live`);
|
|
786
|
+
if (live) live.textContent = cell.getAttribute("aria-label") || "";
|
|
787
|
+
}
|
|
788
|
+
this.dispatchEvent(new CustomEvent("contour:select", { detail: { row, col }, bubbles: true, composed: true }));
|
|
789
|
+
};
|
|
790
|
+
this.addEventListener("click", (e) => {
|
|
791
|
+
const cell = e.target && e.target.closest ? e.target.closest(`.${this._bvBlock}__cell`) : null;
|
|
792
|
+
if (cell && this.contains(cell)) selectCell(cell);
|
|
793
|
+
});
|
|
794
|
+
// R24-33: roving arrow-key nav. Matrix renders one tabindex=0 (top-left), rest -1; ArrowRight/Down advance, ArrowLeft/Up retreat, Home/End jump corners. Without: nine cells = nine tab stops, no way between.
|
|
795
|
+
this.addEventListener("keydown", (e) => {
|
|
796
|
+
const cell = e.target && e.target.closest ? e.target.closest(`.${this._bvBlock}__cell`) : null;
|
|
797
|
+
if (!cell || !this.contains(cell)) return;
|
|
798
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
799
|
+
e.preventDefault();
|
|
800
|
+
selectCell(cell);
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
const matrix = this.querySelector(`.${this._bvBlock}__matrix`);
|
|
804
|
+
if (!matrix) return;
|
|
805
|
+
const cells = Array.from(matrix.querySelectorAll(`.${this._bvBlock}__cell`));
|
|
806
|
+
const idx = cells.indexOf(cell);
|
|
807
|
+
if (idx < 0) return;
|
|
808
|
+
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
809
|
+
const row = Math.floor(idx / size);
|
|
810
|
+
const col = idx % size;
|
|
811
|
+
let nr = row, nc = col;
|
|
812
|
+
if (e.key === "ArrowRight") nc = Math.min(size - 1, col + 1);
|
|
813
|
+
else if (e.key === "ArrowLeft") nc = Math.max(0, col - 1);
|
|
814
|
+
else if (e.key === "ArrowDown") nr = Math.min(size - 1, row + 1);
|
|
815
|
+
else if (e.key === "ArrowUp") nr = Math.max(0, row - 1);
|
|
816
|
+
else if (e.key === "Home") { nr = 0; nc = 0; }
|
|
817
|
+
else if (e.key === "End") { nr = size - 1; nc = size - 1; }
|
|
818
|
+
else return;
|
|
819
|
+
e.preventDefault();
|
|
820
|
+
const next = cells[nr * size + nc];
|
|
821
|
+
if (!next) return;
|
|
822
|
+
cells.forEach((c, i) => c.setAttribute("tabindex", i === nr * size + nc ? "0" : "-1"));
|
|
823
|
+
try { next.focus(); } catch (err) {}
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
clear() {
|
|
827
|
+
this.removeAttribute("selected");
|
|
828
|
+
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true }));
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
define("contour-bivariate", ContourBivariate);
|
|
832
|
+
class ContourBivariateLegend extends ContourBivariate {
|
|
833
|
+
static get observed() { return ["size", "axis-x", "axis-y", "colors", "selected"]; }
|
|
834
|
+
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" }, selected: { attribute: "selected" } }; }
|
|
835
|
+
get _bvBlock() { return "c-bivariate-legend"; }
|
|
836
|
+
get _bvDefaultAxisX() { return "X"; }
|
|
837
|
+
get _bvDefaultAxisY() { return "Y"; }
|
|
838
|
+
get _bvLiveClassName() { return "visually-hidden c-bivariate-legend__live"; }
|
|
839
|
+
get _bvLiveInlineStyles() { return false; }
|
|
840
|
+
get _bvAnnounce() { return true; }
|
|
841
|
+
clear() {
|
|
842
|
+
this.removeAttribute("selected");
|
|
843
|
+
const cells = Array.from(this.querySelectorAll(".c-bivariate-legend__cell"));
|
|
844
|
+
cells.forEach((c) => c.removeAttribute("data-selected"));
|
|
845
|
+
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true }));
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
define("contour-bivariate-legend", ContourBivariateLegend);
|
|
849
|
+
/**
|
|
850
|
+
* Survey: web component wrapper.
|
|
851
|
+
* Attributes: `date`, `instrument`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
852
|
+
*/
|
|
853
|
+
class ContourSurvey extends ContourBase {
|
|
854
|
+
static get observed() { return ["date", "instrument", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
855
|
+
static get properties() { return { date: { attribute: "date" }, instrument: { attribute: "instrument" }, src: { attribute: "src" } }; }
|
|
856
|
+
render() {
|
|
857
|
+
this.classList.add("c-survey");
|
|
858
|
+
wireStates(this);
|
|
859
|
+
loadRemote(this, "date");
|
|
860
|
+
if (renderStates(this, "survey")) return;
|
|
861
|
+
const date = remoteData(this, "date");
|
|
862
|
+
Array.from(this.childNodes).forEach((n) => {
|
|
863
|
+
if (n.nodeType === Node.TEXT_NODE) { if (n.textContent.trim() === "Surveyed" || n.textContent.trim() === "·") n.remove(); }
|
|
864
|
+
else if (n.classList && (n.classList.contains("c-survey__value") || n.classList.contains("c-survey__sep"))) n.remove();
|
|
865
|
+
});
|
|
866
|
+
const rDate = date || (this._remoteData && this._remoteData.date);
|
|
867
|
+
const instrument = this.getAttribute("instrument") || (this._remoteData && this._remoteData.instrument);
|
|
868
|
+
if (!rDate) {
|
|
869
|
+
renderEmpty(this, "survey");
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
const v = document.createElement("span");
|
|
873
|
+
v.className = "c-survey__value";
|
|
874
|
+
v.textContent = rDate;
|
|
875
|
+
this.appendChild(document.createTextNode("Surveyed "));
|
|
876
|
+
this.appendChild(v);
|
|
877
|
+
if (instrument) {
|
|
878
|
+
const sep = document.createElement("span");
|
|
879
|
+
sep.className = "c-survey__sep";
|
|
880
|
+
sep.textContent = "·";
|
|
881
|
+
this.appendChild(sep);
|
|
882
|
+
const v2 = document.createElement("span");
|
|
883
|
+
v2.className = "c-survey__value";
|
|
884
|
+
v2.textContent = instrument;
|
|
885
|
+
this.appendChild(v2);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
define("contour-survey", ContourSurvey);
|
|
890
|
+
/**
|
|
891
|
+
* Threshold: web component wrapper.
|
|
892
|
+
* Attributes: `label`, `norm`, `state`, `value`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
893
|
+
*/
|
|
894
|
+
class ContourThreshold extends ContourBase {
|
|
895
|
+
static get observed() { return ["label", "norm", "state", "value", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
896
|
+
static get properties() { return { label: { attribute: "label" }, norm: { attribute: "norm" }, state: { attribute: "state" }, value: { attribute: "value" }, src: { attribute: "src" } }; }
|
|
897
|
+
render() {
|
|
898
|
+
this.classList.add("c-threshold");
|
|
899
|
+
// R24-34: the bar is a meter, not a generic bar — it exposes its value
|
|
900
|
+
// against its target so a screen reader can announce "70% of target".
|
|
901
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "meter");
|
|
902
|
+
wireStates(this);
|
|
903
|
+
loadRemote(this, "value");
|
|
904
|
+
if (renderStates(this, "threshold")) return;
|
|
905
|
+
const pct = (v) => { const n = Number(v); if (!Number.isFinite(n)) return String(v); return (n <= 1 ? n * 100 : n) + "%"; };
|
|
906
|
+
const rValue = remoteData(this, "value") || (this._remoteData && this._remoteData.value);
|
|
907
|
+
const target = this.getAttribute("norm") || (this._remoteData && this._remoteData.norm);
|
|
908
|
+
const state = this.getAttribute("state") || (this._remoteData && this._remoteData.state);
|
|
909
|
+
const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
|
|
910
|
+
if (!rValue && !target && !label) {
|
|
911
|
+
renderEmpty(this, "threshold");
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
// R24-34: publish meter value range. fill=value, target=goal (both numbers) → announces real percentage, not bare string.
|
|
915
|
+
// R31-57: clamp aria-valuenow into [0,100] (a value of 150 with max 100 is
|
|
916
|
+
// invalid ARIA and the fill was invisible), and fold the target into the
|
|
917
|
+
// announced value text so "150 of goal 100" is spoken, not just "150".
|
|
918
|
+
const numValue = Number(rValue);
|
|
919
|
+
if (Number.isFinite(numValue)) {
|
|
920
|
+
const clamped = Math.min(100, Math.max(0, numValue));
|
|
921
|
+
this.setAttribute("aria-valuenow", String(clamped));
|
|
922
|
+
this.setAttribute("aria-valuemin", "0");
|
|
923
|
+
this.setAttribute("aria-valuemax", "100");
|
|
924
|
+
} else {
|
|
925
|
+
this.removeAttribute("aria-valuenow");
|
|
926
|
+
this.removeAttribute("aria-valuemin");
|
|
927
|
+
this.removeAttribute("aria-valuemax");
|
|
928
|
+
}
|
|
929
|
+
const spoken = [label, Number.isFinite(numValue) ? String(numValue) : null, target ? (labelText(this, "target", "target") + " " + target) : null].filter(Boolean).join(", ");
|
|
930
|
+
if (spoken) this.setAttribute("aria-valuetext", spoken);
|
|
931
|
+
else this.removeAttribute("aria-valuetext");
|
|
932
|
+
if (rValue) {
|
|
933
|
+
const v = this.ensure(".c-threshold__fill", () => { const el = document.createElement("span"); el.className = "c-threshold__fill"; return el; });
|
|
934
|
+
v.style.setProperty("--value", pct(rValue));
|
|
935
|
+
} else {
|
|
936
|
+
const v = this.querySelector(".c-threshold__fill");
|
|
937
|
+
if (v) v.remove();
|
|
938
|
+
}
|
|
939
|
+
if (target) {
|
|
940
|
+
const t = this.ensure(".c-threshold__target", () => { const el = document.createElement("span"); el.className = "c-threshold__target"; return el; });
|
|
941
|
+
t.style.setProperty("--target", pct(target));
|
|
942
|
+
} else {
|
|
943
|
+
const t = this.querySelector(".c-threshold__target");
|
|
944
|
+
if (t) t.remove();
|
|
945
|
+
}
|
|
946
|
+
if (state) this.setAttribute("data-state", state);
|
|
947
|
+
else this.removeAttribute("data-state");
|
|
948
|
+
if (label) this.setAttribute("aria-label", label);
|
|
949
|
+
}
|
|
950
|
+
enhance() {
|
|
951
|
+
if (this._wiredThreshold) return;
|
|
952
|
+
this._wiredThreshold = true;
|
|
953
|
+
// Cross-filter contract (R16-16): clear-all resets threshold norm/target.
|
|
954
|
+
this.addEventListener("contour:clear-all", () => {
|
|
955
|
+
if (this.hasAttribute("norm") || this.hasAttribute("value")) {
|
|
956
|
+
this.removeAttribute("norm");
|
|
957
|
+
this.removeAttribute("value");
|
|
958
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "threshold", filter: { norm: null, value: null } } }));
|
|
959
|
+
this.requestRender();
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
define("contour-threshold", ContourThreshold);
|
|
965
|
+
/**
|
|
966
|
+
* Metrics Full: web component wrapper.
|
|
967
|
+
* Attributes: `items`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
968
|
+
*/
|
|
969
|
+
class ContourMetricsFull extends ContourBase {
|
|
970
|
+
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
971
|
+
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
972
|
+
render() {
|
|
973
|
+
this.classList.add("c-metrics");
|
|
974
|
+
this.setAttribute("role", "list");
|
|
975
|
+
wireStates(this);
|
|
976
|
+
loadRemote(this, "items");
|
|
977
|
+
if (renderStates(this, "metrics")) return;
|
|
978
|
+
const items = remoteData(this, "items");
|
|
979
|
+
// Drop previously generated items so re-render doesn't stack.
|
|
980
|
+
Array.from(this.querySelectorAll(".c-metrics__item")).forEach((n) => n.remove());
|
|
981
|
+
let parsed = null;
|
|
982
|
+
if (items) { try { parsed = JSON.parse(items); } catch (e) { parsed = null; } }
|
|
983
|
+
if (Array.isArray(parsed) && parsed.length) {
|
|
984
|
+
parsed.forEach((it) => {
|
|
985
|
+
const item = document.createElement("div");
|
|
986
|
+
item.className = "c-metrics__item";
|
|
987
|
+
item.setAttribute("role", "listitem");
|
|
988
|
+
const v = document.createElement("div");
|
|
989
|
+
v.className = "c-metrics__value";
|
|
990
|
+
v.textContent = (typeof it === "object" && it !== null) ? (it.value ?? it.v ?? "") : String(it);
|
|
991
|
+
const l = document.createElement("div");
|
|
992
|
+
l.className = "c-metrics__label";
|
|
993
|
+
l.textContent = (typeof it === "object" && it !== null) ? (it.label ?? it.l ?? "") : "";
|
|
994
|
+
item.appendChild(v);
|
|
995
|
+
item.appendChild(l);
|
|
996
|
+
this.appendChild(item);
|
|
997
|
+
});
|
|
998
|
+
} else if (!items) {
|
|
999
|
+
renderEmpty(this, "metrics");
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
enhance() { wireStates(this); }
|
|
1003
|
+
}
|
|
1004
|
+
define("contour-metrics", ContourMetricsFull);
|