contour-ds 1.7.2 → 1.8.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/README.md +80 -11
- package/dist/agent-rules.json +16 -0
- package/dist/build-manifest.json +181 -104
- package/dist/contour-wc-content.esm.js +5125 -0
- package/dist/contour-wc-content.esm.min.js +1 -0
- package/dist/contour-wc-dashboard.esm.js +8654 -0
- package/dist/contour-wc-dashboard.esm.min.js +1 -0
- package/dist/contour-wc-data.esm.js +8260 -0
- package/dist/contour-wc-data.esm.min.js +1 -0
- package/dist/contour-wc-docs.esm.js +4305 -0
- package/dist/contour-wc-docs.esm.min.js +1 -0
- package/dist/contour-wc-feedback.esm.js +4917 -0
- package/dist/contour-wc-feedback.esm.min.js +1 -0
- package/dist/contour-wc-forms.esm.js +5688 -0
- package/dist/contour-wc-forms.esm.min.js +1 -0
- package/dist/contour-wc-interaction.esm.js +4580 -0
- package/dist/contour-wc-interaction.esm.min.js +1 -0
- package/dist/contour-wc-layout.esm.js +4174 -0
- package/dist/contour-wc-layout.esm.min.js +1 -0
- package/dist/contour-wc-map.esm.js +5205 -0
- package/dist/contour-wc-map.esm.min.js +1 -0
- package/dist/contour-wc-misc.esm.js +4264 -0
- package/dist/contour-wc-misc.esm.min.js +1 -0
- package/dist/contour-wc-navigation.esm.js +5844 -0
- package/dist/contour-wc-navigation.esm.min.js +1 -0
- package/dist/contour-wc-ui.esm.js +9009 -0
- package/dist/contour-wc-ui.esm.min.js +1 -0
- package/dist/contour-wc.esm.js +6109 -1641
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +6108 -1641
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.code-snippets +4512 -0
- package/dist/contour.components.json +2597 -799
- package/dist/contour.css +5275 -4050
- package/dist/contour.d.ts +560 -1085
- package/dist/contour.esm.js +7 -0
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +10311 -0
- package/dist/contour.js +7 -0
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +420 -0
- package/dist/contour.single.html +17 -0
- package/dist/contour.single.min.css +1 -0
- package/dist/contour.tokens.json +940 -902
- package/dist/contour.vue.d.ts +418 -0
- package/dist/contour.web-types.json +10703 -0
- package/dist/custom-elements.json +30708 -0
- package/dist/docs/actions.md +3 -2
- package/dist/docs/affordances.md +23 -9
- package/dist/docs/apireference.md +1 -1
- package/dist/docs/colour.md +1 -1
- package/dist/docs/componentindex.md +6 -2
- package/dist/docs/data.md +7 -2
- package/dist/docs/docs.md +9 -2
- package/dist/docs/feedback.md +1 -1
- package/dist/docs/field.md +1 -1
- package/dist/docs/forms.md +1 -1
- package/dist/docs/index.json +22 -20
- package/dist/docs/install.md +1 -1
- package/dist/docs/landing.md +1 -1
- package/dist/docs/mapengine.md +19 -2
- package/dist/docs/motion.md +1 -1
- package/dist/docs/navigation.md +1 -1
- package/dist/docs/overlays.md +1 -1
- package/dist/docs/overview.md +1 -1
- package/dist/docs/patterns.md +2 -2
- package/dist/docs/playground.md +22 -2
- package/dist/docs/principles.md +1 -1
- package/dist/docs/recipes.md +13 -8
- package/dist/docs/space.md +1 -1
- package/dist/docs/status.md +14 -2
- package/dist/docs/surfaces.md +1 -1
- package/dist/docs/theming.md +1 -1
- package/dist/docs/type.md +1 -1
- package/dist/docs/webcomponents.md +17 -3
- 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/wc/behaviours.mjs +45 -57
- package/dist/wc/content.mjs +263 -63
- package/dist/wc/core.mjs +390 -71
- package/dist/wc/dashboard.mjs +220 -13
- package/dist/wc/data.mjs +1075 -460
- package/dist/wc/docs.mjs +105 -12
- package/dist/wc/feedback.mjs +63 -14
- package/dist/wc/forms.mjs +733 -104
- package/dist/wc/index.mjs +9 -2
- package/dist/wc/interaction.mjs +182 -28
- package/dist/wc/layout.mjs +95 -25
- package/dist/wc/map.mjs +185 -118
- package/dist/wc/misc.mjs +124 -24
- package/dist/wc/navigation.mjs +384 -115
- package/dist/wc/shadow.mjs +94 -18
- package/dist/wc/states.mjs +21 -3
- package/dist/wc/svg.mjs +104 -0
- package/dist/wc/ui.mjs +1988 -476
- package/integrations/README.md +2 -0
- package/integrations/ai/CLAUDE.md +3 -3
- package/integrations/frameworks/README.md +235 -0
- package/integrations/native/style-dictionary.config.json +1 -1
- package/integrations/tailwind/contour-theme.css +5 -6
- package/package.json +53 -24
package/dist/wc/data.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ContourBase, define, onDispose, formatValue, contourId } from './core.mjs';
|
|
1
|
+
import { ContourBase, define, onDispose, formatValue, contourId, navKey, isRtl, cssLength , warnBadJson, labelText } from './core.mjs';
|
|
2
2
|
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates, remoteInvalidate, watchViewport } from './states.mjs';
|
|
3
|
-
import { donutSlices, barRects, smoothPath, polylinePoints } from './svg.mjs';
|
|
3
|
+
import { donutSlices, barRects, smoothPath, polylinePoints, contourPaths } from './svg.mjs';
|
|
4
4
|
/**
|
|
5
5
|
* Readout: web component wrapper.
|
|
6
6
|
* Attributes: `rows`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `format`, `locale`.
|
|
@@ -40,7 +40,7 @@ class ContourReadout extends ContourBase {
|
|
|
40
40
|
}
|
|
41
41
|
this.appendChild(row);
|
|
42
42
|
});
|
|
43
|
-
} catch (e) {
|
|
43
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
44
44
|
} else if (!rows && !authored.length) {
|
|
45
45
|
renderEmpty(this, "readout");
|
|
46
46
|
}
|
|
@@ -152,11 +152,11 @@ class ContourKpi extends ContourBase {
|
|
|
152
152
|
define("contour-kpi", ContourKpi);
|
|
153
153
|
/**
|
|
154
154
|
* Table: web component wrapper.
|
|
155
|
-
* Attributes: `columns`, `rows`, `page`, `page-size`, `sort`, `sort-dir`, `virtual`, `empty`, `loading`, `error`, `retry`, `skeleton`, `persist`.
|
|
155
|
+
* Attributes: `columns`, `rows`, `page`, `page-size`, `sort`, `sort-dir`, `virtual`, `title`, `empty`, `loading`, `error`, `retry`, `skeleton`, `persist`.
|
|
156
156
|
*/
|
|
157
157
|
class ContourTable extends ContourBase {
|
|
158
158
|
static get updateMode() { return "keyed"; }
|
|
159
|
-
static get observed() { return ["columns", "rows", "page", "page-size", "sort", "sort-dir", "virtual", "empty", "loading", "error", "retry", "skeleton", "persist"]; }
|
|
159
|
+
static get observed() { return ["columns", "rows", "page", "page-size", "sort", "sort-dir", "virtual", "title", "empty", "loading", "error", "retry", "skeleton", "persist"]; }
|
|
160
160
|
static get properties() { return { columns: { attribute: "columns" }, rows: { attribute: "rows" }, page: { attribute: "page", type: Number }, pageSize: { attribute: "page-size", type: Number } }; }
|
|
161
161
|
_cellValue(cell) {
|
|
162
162
|
if (cell === null || cell === undefined) return "";
|
|
@@ -172,149 +172,22 @@ class ContourTable extends ContourBase {
|
|
|
172
172
|
return String(av).localeCompare(String(bv), undefined, { numeric: true });
|
|
173
173
|
}
|
|
174
174
|
render() {
|
|
175
|
-
this.setAttribute("role", "region");
|
|
176
|
-
|
|
175
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
176
|
+
// An authored label names the table; "Table" is the fallback.
|
|
177
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Table");
|
|
178
|
+
wireStates(this);
|
|
179
|
+
loadRemote(this, "rows");
|
|
180
|
+
if (renderStates(this, "table")) return;
|
|
177
181
|
// The host is not a <table>, so it carries no table rule. The scroller the
|
|
178
182
|
// reflow contract requires is a real block element inside it.
|
|
179
183
|
const columns = this.getAttribute("columns");
|
|
180
|
-
const rows = this
|
|
184
|
+
const rows = remoteData(this, "rows");
|
|
181
185
|
// Slot composition: an authored table wins over the JSON attributes.
|
|
182
186
|
const authored = Array.from(this.children).filter((n) => !n.classList || !n.classList.contains("c-table-wrap"));
|
|
183
187
|
if (columns && rows && !authored.length) {
|
|
184
188
|
try {
|
|
185
189
|
const cols = JSON.parse(columns);
|
|
186
190
|
const data = JSON.parse(rows);
|
|
187
|
-
// Loading state: show a spinner row instead of data.
|
|
188
|
-
if (this.hasAttribute("loading")) {
|
|
189
|
-
const wrap = this.ensure(".c-table-wrap", () => { const el = document.createElement("div"); el.className = "c-table-wrap"; return el; });
|
|
190
|
-
const colsKey = JSON.stringify(cols);
|
|
191
|
-
const table = (wrap.querySelector("table.c-table") && this._tableCols === colsKey)
|
|
192
|
-
? wrap.querySelector("table.c-table")
|
|
193
|
-
: (() => {
|
|
194
|
-
const t = document.createElement("table");
|
|
195
|
-
t.className = "c-table";
|
|
196
|
-
const thead = document.createElement("thead");
|
|
197
|
-
const tr = document.createElement("tr");
|
|
198
|
-
cols.forEach((c) => {
|
|
199
|
-
const colLabel = typeof c === "string" ? c : (c.label || c.title || c);
|
|
200
|
-
const th = document.createElement("th");
|
|
201
|
-
th.textContent = colLabel;
|
|
202
|
-
tr.appendChild(th);
|
|
203
|
-
});
|
|
204
|
-
thead.appendChild(tr);
|
|
205
|
-
t.appendChild(thead);
|
|
206
|
-
t.appendChild(document.createElement("tbody"));
|
|
207
|
-
return t;
|
|
208
|
-
})();
|
|
209
|
-
this._tableCols = colsKey;
|
|
210
|
-
const tbody = table.querySelector("tbody");
|
|
211
|
-
tbody.innerHTML = "";
|
|
212
|
-
const tr = document.createElement("tr");
|
|
213
|
-
const td = document.createElement("td");
|
|
214
|
-
td.colSpan = cols.length;
|
|
215
|
-
td.style.textAlign = "center";
|
|
216
|
-
td.style.color = "var(--color-text-muted)";
|
|
217
|
-
td.textContent = this.getAttribute("loading") || "Loading…";
|
|
218
|
-
tr.appendChild(td);
|
|
219
|
-
tbody.appendChild(tr);
|
|
220
|
-
if (table.parentNode !== wrap) { wrap.innerHTML = ""; wrap.appendChild(table); }
|
|
221
|
-
if (wrap.parentNode !== this) this.appendChild(wrap);
|
|
222
|
-
const footer = this.querySelector(".c-table__pagination");
|
|
223
|
-
if (footer) footer.remove();
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
if (this.hasAttribute("error")) {
|
|
227
|
-
const wrap = this.ensure(".c-table-wrap", () => { const el = document.createElement("div"); el.className = "c-table-wrap"; return el; });
|
|
228
|
-
const colsKey = JSON.stringify(cols);
|
|
229
|
-
const table = (wrap.querySelector("table.c-table") && this._tableCols === colsKey)
|
|
230
|
-
? wrap.querySelector("table.c-table")
|
|
231
|
-
: (() => {
|
|
232
|
-
const t = document.createElement("table");
|
|
233
|
-
t.className = "c-table";
|
|
234
|
-
const thead = document.createElement("thead");
|
|
235
|
-
const tr = document.createElement("tr");
|
|
236
|
-
cols.forEach((c) => {
|
|
237
|
-
const colLabel = typeof c === "string" ? c : (c.label || c.title || c);
|
|
238
|
-
const th = document.createElement("th");
|
|
239
|
-
th.textContent = colLabel;
|
|
240
|
-
tr.appendChild(th);
|
|
241
|
-
});
|
|
242
|
-
thead.appendChild(tr);
|
|
243
|
-
t.appendChild(thead);
|
|
244
|
-
t.appendChild(document.createElement("tbody"));
|
|
245
|
-
return t;
|
|
246
|
-
})();
|
|
247
|
-
this._tableCols = colsKey;
|
|
248
|
-
const tbody = table.querySelector("tbody");
|
|
249
|
-
tbody.innerHTML = "";
|
|
250
|
-
const tr = document.createElement("tr");
|
|
251
|
-
const td = document.createElement("td");
|
|
252
|
-
td.colSpan = cols.length;
|
|
253
|
-
td.textContent = this.getAttribute("error") || "Error";
|
|
254
|
-
td.style.textAlign = "center";
|
|
255
|
-
td.style.color = "var(--color-danger, var(--color-text))";
|
|
256
|
-
if (this.hasAttribute("retry")) {
|
|
257
|
-
const btn = document.createElement("button");
|
|
258
|
-
btn.className = "c-btn c-btn--ghost c-btn--sm";
|
|
259
|
-
btn.type = "button";
|
|
260
|
-
btn.textContent = this.getAttribute("retry") || "Retry";
|
|
261
|
-
btn.classList.add("u-ms-sm");
|
|
262
|
-
btn.dataset.action = "retry";
|
|
263
|
-
td.appendChild(btn);
|
|
264
|
-
}
|
|
265
|
-
tr.appendChild(td);
|
|
266
|
-
tbody.appendChild(tr);
|
|
267
|
-
if (table.parentNode !== wrap) { wrap.innerHTML = ""; wrap.appendChild(table); }
|
|
268
|
-
if (wrap.parentNode !== this) this.appendChild(wrap);
|
|
269
|
-
const footer = this.querySelector(".c-table__pagination");
|
|
270
|
-
if (footer) footer.remove();
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
if (this.hasAttribute("skeleton")) {
|
|
274
|
-
const wrap = this.ensure(".c-table-wrap", () => { const el = document.createElement("div"); el.className = "c-table-wrap"; return el; });
|
|
275
|
-
const colsKey = JSON.stringify(cols);
|
|
276
|
-
const table = (wrap.querySelector("table.c-table") && this._tableCols === colsKey)
|
|
277
|
-
? wrap.querySelector("table.c-table")
|
|
278
|
-
: (() => {
|
|
279
|
-
const t = document.createElement("table");
|
|
280
|
-
t.className = "c-table";
|
|
281
|
-
const thead = document.createElement("thead");
|
|
282
|
-
const tr = document.createElement("tr");
|
|
283
|
-
cols.forEach((c) => {
|
|
284
|
-
const colLabel = typeof c === "string" ? c : (c.label || c.title || c);
|
|
285
|
-
const th = document.createElement("th");
|
|
286
|
-
th.textContent = colLabel;
|
|
287
|
-
tr.appendChild(th);
|
|
288
|
-
});
|
|
289
|
-
thead.appendChild(tr);
|
|
290
|
-
t.appendChild(thead);
|
|
291
|
-
t.appendChild(document.createElement("tbody"));
|
|
292
|
-
return t;
|
|
293
|
-
})();
|
|
294
|
-
this._tableCols = colsKey;
|
|
295
|
-
const tbody = table.querySelector("tbody");
|
|
296
|
-
tbody.innerHTML = "";
|
|
297
|
-
const count = Math.min(5, Math.max(1, parseInt(this.getAttribute("skeleton") || "3", 10) || 3));
|
|
298
|
-
for (let i = 0; i < count; i++) {
|
|
299
|
-
const tr = document.createElement("tr");
|
|
300
|
-
cols.forEach(() => {
|
|
301
|
-
const td = document.createElement("td");
|
|
302
|
-
const sk = document.createElement("span");
|
|
303
|
-
sk.className = "c-skeleton";
|
|
304
|
-
sk.style.display = "inline-block";
|
|
305
|
-
sk.style.inlineSize = "60%";
|
|
306
|
-
sk.style.blockSize = "0.8rem";
|
|
307
|
-
td.appendChild(sk);
|
|
308
|
-
tr.appendChild(td);
|
|
309
|
-
});
|
|
310
|
-
tbody.appendChild(tr);
|
|
311
|
-
}
|
|
312
|
-
if (table.parentNode !== wrap) { wrap.innerHTML = ""; wrap.appendChild(table); }
|
|
313
|
-
if (wrap.parentNode !== this) this.appendChild(wrap);
|
|
314
|
-
const footer = this.querySelector(".c-table__pagination");
|
|
315
|
-
if (footer) footer.remove();
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
191
|
// Initialise sort state from attributes on first render.
|
|
319
192
|
if (this._sortCol === undefined) {
|
|
320
193
|
const sortAttr = this.getAttribute("sort");
|
|
@@ -381,6 +254,10 @@ class ContourTable extends ContourBase {
|
|
|
381
254
|
this._page = page;
|
|
382
255
|
this._totalPages = totalPages;
|
|
383
256
|
this._pageSize = pageSize;
|
|
257
|
+
// Keep the row objects in memory instead of serializing each one into
|
|
258
|
+
// a data-row attribute: the JSON duplicated the data the component
|
|
259
|
+
// already holds and bloated every row.
|
|
260
|
+
this._rowData = pageData;
|
|
384
261
|
|
|
385
262
|
const wrap = this.ensure(".c-table-wrap", () => { const el = document.createElement("div"); el.className = "c-table-wrap"; return el; });
|
|
386
263
|
// Reuse the existing table when columns are unchanged, rebuilding
|
|
@@ -391,6 +268,14 @@ class ContourTable extends ContourBase {
|
|
|
391
268
|
: (() => {
|
|
392
269
|
const t = document.createElement("table");
|
|
393
270
|
t.className = "c-table";
|
|
271
|
+
// A table needs a caption: the host's region label is outside the
|
|
272
|
+
// table, so a reader who enters it hears column headers with no
|
|
273
|
+
// statement of what the table is. Visually hidden keeps the block
|
|
274
|
+
// layout unchanged.
|
|
275
|
+
const captionEl = document.createElement("caption");
|
|
276
|
+
captionEl.className = "visually-hidden";
|
|
277
|
+
captionEl.textContent = this.getAttribute("title") || this.getAttribute("aria-label") || "Table";
|
|
278
|
+
t.appendChild(captionEl);
|
|
394
279
|
const thead = document.createElement("thead");
|
|
395
280
|
const tr = document.createElement("tr");
|
|
396
281
|
cols.forEach((c, i) => {
|
|
@@ -405,6 +290,9 @@ class ContourTable extends ContourBase {
|
|
|
405
290
|
inp.type = "search";
|
|
406
291
|
inp.className = "c-table__filter-input";
|
|
407
292
|
inp.placeholder = colLabel;
|
|
293
|
+
// A placeholder is not a label: a reader who tabs into the
|
|
294
|
+
// filter hears "edit text" with no column name. Name it.
|
|
295
|
+
inp.setAttribute("aria-label", "Filter " + colLabel);
|
|
408
296
|
inp.dataset.filterIndex = String(i);
|
|
409
297
|
if (this._filters && this._filters[i]) inp.value = this._filters[i];
|
|
410
298
|
th.appendChild(inp);
|
|
@@ -456,7 +344,7 @@ class ContourTable extends ContourBase {
|
|
|
456
344
|
const tbody = table.querySelector("tbody");
|
|
457
345
|
tbody.innerHTML = "";
|
|
458
346
|
const useVirtual = this.hasAttribute("virtual") && !usePaging && pageData.length > 100;
|
|
459
|
-
const rowHeight = 36;
|
|
347
|
+
const rowHeight = this._measuredRowHeight || cssLength("--data-grid-row-height", 36);
|
|
460
348
|
const windowSize = 30;
|
|
461
349
|
const overscan = 10;
|
|
462
350
|
let windowStart = 0;
|
|
@@ -493,7 +381,10 @@ class ContourTable extends ContourBase {
|
|
|
493
381
|
visibleData.forEach((row, ri) => {
|
|
494
382
|
const tr = document.createElement("tr");
|
|
495
383
|
tr.dataset.rowIndex = String(windowStart + ri);
|
|
496
|
-
|
|
384
|
+
// One tab stop per grid, not one per row: every row is -1 and the
|
|
385
|
+
// arrow keys move a roving tabindex. A 1,000-row table was 1,000
|
|
386
|
+
// tab stops before this.
|
|
387
|
+
tr.setAttribute("tabindex", "-1");
|
|
497
388
|
cols.forEach((c, ci) => {
|
|
498
389
|
const isSelect = (typeof c === "object" && c !== null && c.select);
|
|
499
390
|
const td = document.createElement("td");
|
|
@@ -513,6 +404,26 @@ class ContourTable extends ContourBase {
|
|
|
513
404
|
});
|
|
514
405
|
}
|
|
515
406
|
if (useVirtual) addSpacer(Math.max(0, pageData.length - windowStart - visibleData.length) * rowHeight);
|
|
407
|
+
// Keep exactly one row in the tab order: the first rendered row when
|
|
408
|
+
// none is active yet, so the grid is a single tab stop.
|
|
409
|
+
if (!tbody.querySelector('tr[tabindex="0"]')) {
|
|
410
|
+
const first = tbody.querySelector("tr[data-row-index]");
|
|
411
|
+
if (first) first.setAttribute("tabindex", "0");
|
|
412
|
+
}
|
|
413
|
+
// Measure a real row so the virtual window uses the rendered height,
|
|
414
|
+
// not a guess: the old fixed 36px disagreed with the measured 64.1px,
|
|
415
|
+
// so the spacers and the scroll math were both wrong.
|
|
416
|
+
if (!this._measuredRowHeight && !this._measuringRow) {
|
|
417
|
+
const firstRow = tbody.querySelector("tr[data-row-index]");
|
|
418
|
+
const h = firstRow ? firstRow.getBoundingClientRect().height : 0;
|
|
419
|
+
if (h > 0) {
|
|
420
|
+
this._measuredRowHeight = h;
|
|
421
|
+
if (Math.abs(h - rowHeight) > 1) {
|
|
422
|
+
this._measuringRow = true;
|
|
423
|
+
requestAnimationFrame(() => { this._measuringRow = false; this.render(); });
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
516
427
|
if (table.parentNode !== wrap) {
|
|
517
428
|
wrap.innerHTML = "";
|
|
518
429
|
wrap.appendChild(table);
|
|
@@ -535,15 +446,15 @@ class ContourTable extends ContourBase {
|
|
|
535
446
|
const prev = document.createElement("button");
|
|
536
447
|
prev.className = "c-btn c-btn--ghost c-btn--sm";
|
|
537
448
|
prev.type = "button";
|
|
538
|
-
prev.textContent = "Previous";
|
|
449
|
+
prev.textContent = labelText(this, "prev", "Previous");
|
|
539
450
|
prev.disabled = page <= 1;
|
|
540
451
|
prev.dataset.action = "prev";
|
|
541
452
|
const info = document.createElement("span");
|
|
542
|
-
info.textContent =
|
|
453
|
+
info.textContent = `${labelText(this, "page", "Page")} ${page} ${labelText(this, "of", "of")} ${totalPages}`;
|
|
543
454
|
const next = document.createElement("button");
|
|
544
455
|
next.className = "c-btn c-btn--ghost c-btn--sm";
|
|
545
456
|
next.type = "button";
|
|
546
|
-
next.textContent = "Next";
|
|
457
|
+
next.textContent = labelText(this, "next", "Next");
|
|
547
458
|
next.disabled = page >= totalPages;
|
|
548
459
|
next.dataset.action = "next";
|
|
549
460
|
footer.appendChild(prev);
|
|
@@ -553,7 +464,9 @@ class ContourTable extends ContourBase {
|
|
|
553
464
|
const footer = this.querySelector(".c-table__pagination");
|
|
554
465
|
if (footer) footer.remove();
|
|
555
466
|
}
|
|
556
|
-
} catch (e) {
|
|
467
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
468
|
+
} else if (!rows && !authored.length) {
|
|
469
|
+
renderEmpty(this, "table");
|
|
557
470
|
}
|
|
558
471
|
}
|
|
559
472
|
enhance() {
|
|
@@ -569,6 +482,7 @@ class ContourTable extends ContourBase {
|
|
|
569
482
|
this._sortDir = 1;
|
|
570
483
|
}
|
|
571
484
|
this.dispatchEvent(new CustomEvent("contour:sort", { bubbles: true, composed: true, detail: { column: idx, direction: this._sortDir === 1 ? "ascending" : "descending" } }));
|
|
485
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { sort: idx, sortDir: this._sortDir === 1 ? "ascending" : "descending" } } }));
|
|
572
486
|
this.requestRender();
|
|
573
487
|
};
|
|
574
488
|
this.addEventListener("click", (e) => {
|
|
@@ -592,14 +506,15 @@ class ContourTable extends ContourBase {
|
|
|
592
506
|
if (!Number.isFinite(page) || page < 1) page = 1;
|
|
593
507
|
if (action === "prev" && page > 1) page -= 1;
|
|
594
508
|
if (action === "next") page += 1;
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
509
|
+
this._page = page;
|
|
510
|
+
this._pageAttrLast = String(page);
|
|
511
|
+
// Reflect the page on the host so consumers can key off the attribute
|
|
512
|
+
// (D-04). Marked internal so the resulting render preserves _page
|
|
513
|
+
// instead of nulling it (B3-01).
|
|
514
|
+
this._pageInternal = true;
|
|
515
|
+
this.setAttribute("page", String(page));
|
|
516
|
+
this.dispatchEvent(new CustomEvent("contour:page", { bubbles: true, composed: true, detail: { page } }));
|
|
517
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { page } } }));
|
|
603
518
|
const persist = this.getAttribute("persist");
|
|
604
519
|
if (persist === "storage" && this.id) { try { localStorage.setItem("contour-table:" + this.id, String(page)); } catch (e) {} }
|
|
605
520
|
else if (persist === "url") { try { const url = new URL(window.location.href); url.searchParams.set("c-table", String(page)); window.history.replaceState(null, "", url.toString()); } catch (e) {} }
|
|
@@ -622,6 +537,7 @@ class ContourTable extends ContourBase {
|
|
|
622
537
|
if (!this._filters) this._filters = {};
|
|
623
538
|
this._filters[idx] = inp.value;
|
|
624
539
|
this.requestRender();
|
|
540
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { column: idx, value: inp.value } } }));
|
|
625
541
|
});
|
|
626
542
|
this.addEventListener("scroll", (e) => {
|
|
627
543
|
if (!this.hasAttribute("virtual") || !e.target || !e.target.classList || !e.target.classList.contains("c-table-wrap")) return;
|
|
@@ -638,6 +554,7 @@ class ContourTable extends ContourBase {
|
|
|
638
554
|
if (!Number.isFinite(idx)) return;
|
|
639
555
|
if (cb.checked) this._selectedRows.add(idx); else this._selectedRows.delete(idx);
|
|
640
556
|
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { rows: Array.from(this._selectedRows) } }));
|
|
557
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { selectedRows: Array.from(this._selectedRows) } } }));
|
|
641
558
|
return;
|
|
642
559
|
}
|
|
643
560
|
const all = e.target && e.target.closest ? e.target.closest(".c-table__select-all") : null;
|
|
@@ -646,6 +563,7 @@ class ContourTable extends ContourBase {
|
|
|
646
563
|
cbs.forEach((c) => { c.checked = all.checked; });
|
|
647
564
|
this._selectedRows = new Set(all.checked ? cbs.map((c) => Number(c.dataset.rowIndex)) : []);
|
|
648
565
|
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { rows: Array.from(this._selectedRows) } }));
|
|
566
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { selectedRows: Array.from(this._selectedRows) } } }));
|
|
649
567
|
}
|
|
650
568
|
});
|
|
651
569
|
// Map-linked table (CARTO-inspired): emit contour:hover on row hover so a
|
|
@@ -668,15 +586,55 @@ class ContourTable extends ContourBase {
|
|
|
668
586
|
this._hoveredRow = null;
|
|
669
587
|
this.dispatchEvent(new CustomEvent("contour:leave", { bubbles: true, composed: true, detail: {} }));
|
|
670
588
|
});
|
|
589
|
+
// Map-linked table (R16-17): click-to-zoom on a row emits contour:zoom so
|
|
590
|
+
// a map consumer can zoom to the corresponding feature. Contour stays
|
|
591
|
+
// engine-agnostic: it only announces the row index and data.
|
|
592
|
+
this.addEventListener("click", (e) => {
|
|
593
|
+
const tr = e.target && e.target.closest ? e.target.closest("tbody tr") : null;
|
|
594
|
+
if (!tr || !this.contains(tr)) return;
|
|
595
|
+
const idx = Number(tr.dataset.rowIndex);
|
|
596
|
+
if (!Number.isFinite(idx)) return;
|
|
597
|
+
const rowData = (this._rowData && this._rowData[idx]) || null;
|
|
598
|
+
this.dispatchEvent(new CustomEvent("contour:zoom", { bubbles: true, composed: true, detail: { row: idx, index: idx, data: rowData } }));
|
|
599
|
+
});
|
|
671
600
|
this.addEventListener("keydown", (e) => {
|
|
672
|
-
if (e.key !== "Enter" && e.key !== " ") return;
|
|
673
601
|
const tr = e.target && e.target.closest ? e.target.closest("tbody tr") : null;
|
|
674
602
|
if (!tr || !this.contains(tr)) return;
|
|
675
|
-
e.preventDefault();
|
|
676
603
|
const idx = Number(tr.dataset.rowIndex);
|
|
677
604
|
if (!Number.isFinite(idx)) return;
|
|
605
|
+
// Roving tabindex: arrows move the single tab stop, Home/End jump.
|
|
606
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "Home" || e.key === "End") {
|
|
607
|
+
const rows = Array.from(this.querySelectorAll("tbody tr[data-row-index]"));
|
|
608
|
+
const at = rows.indexOf(tr);
|
|
609
|
+
let next = at;
|
|
610
|
+
if (e.key === "ArrowDown") next = Math.min(rows.length - 1, at + 1);
|
|
611
|
+
else if (e.key === "ArrowUp") next = Math.max(0, at - 1);
|
|
612
|
+
else if (e.key === "Home") next = 0;
|
|
613
|
+
else if (e.key === "End") next = rows.length - 1;
|
|
614
|
+
if (next !== at && rows[next]) {
|
|
615
|
+
e.preventDefault();
|
|
616
|
+
rows.forEach((r) => r.setAttribute("tabindex", "-1"));
|
|
617
|
+
rows[next].setAttribute("tabindex", "0");
|
|
618
|
+
try { rows[next].focus(); } catch (err) {}
|
|
619
|
+
}
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
if (e.key !== "Enter" && e.key !== " ") return;
|
|
623
|
+
e.preventDefault();
|
|
678
624
|
this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true, detail: { row: idx } }));
|
|
679
625
|
});
|
|
626
|
+
// Cross-filter contract (R16-16): clear-all resets table sort/page/filter state.
|
|
627
|
+
this.addEventListener("contour:clear-all", () => {
|
|
628
|
+
let changed = false;
|
|
629
|
+
if (this.hasAttribute("sort")) { this.removeAttribute("sort"); changed = true; }
|
|
630
|
+
if (this.hasAttribute("sort-dir")) { this.removeAttribute("sort-dir"); changed = true; }
|
|
631
|
+
if (this.hasAttribute("page")) { this.removeAttribute("page"); changed = true; }
|
|
632
|
+
if (this._filters && Object.keys(this._filters).length) { this._filters = {}; changed = true; }
|
|
633
|
+
if (changed) {
|
|
634
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { sort: null, sortDir: null, page: null, filters: null } } }));
|
|
635
|
+
this.requestRender();
|
|
636
|
+
}
|
|
637
|
+
});
|
|
680
638
|
}
|
|
681
639
|
}
|
|
682
640
|
define("contour-table", ContourTable);
|
|
@@ -688,18 +646,167 @@ class ContourDataTable extends ContourTable {
|
|
|
688
646
|
}
|
|
689
647
|
}
|
|
690
648
|
define("contour-data-table", ContourDataTable);
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Coerce a histogram bin into the published shape.
|
|
652
|
+
*
|
|
653
|
+
* A bin may arrive from the author (`series[].bins`) or be pushed by a binder
|
|
654
|
+
* (`chart.bins = …`). Both go through here so `bins` reads back the same way
|
|
655
|
+
* whichever door it came through, and a malformed entry is dropped rather than
|
|
656
|
+
* rendered as NaN geometry.
|
|
657
|
+
*/
|
|
658
|
+
const normalizeChartBin = (bin) => {
|
|
659
|
+
if (!bin || typeof bin !== "object") return null;
|
|
660
|
+
const x0 = Number(bin.x0);
|
|
661
|
+
const x1 = Number(bin.x1);
|
|
662
|
+
const count = Number(bin.count);
|
|
663
|
+
if (!Number.isFinite(x0) || !Number.isFinite(x1) || !Number.isFinite(count)) return null;
|
|
664
|
+
const out = { x0, x1, count };
|
|
665
|
+
const normalized = Number(bin.normalized);
|
|
666
|
+
if (Number.isFinite(normalized)) out.normalized = normalized;
|
|
667
|
+
return out;
|
|
668
|
+
};
|
|
669
|
+
|
|
691
670
|
/**
|
|
692
671
|
* Chart: web component wrapper.
|
|
693
672
|
* Attributes: `series`, `axis`, `empty`, `loading`, `error`, `retry`, `skeleton`, `zoomable`, `data-table`, `brush`, `brush-min`, `brush-max`, `brush-start`, `brush-end`.
|
|
694
673
|
*/
|
|
695
674
|
class ContourChart extends ContourBase {
|
|
696
675
|
static get updateMode() { return "keyed"; }
|
|
697
|
-
static get observed() { return ["series", "axis", "empty", "loading", "error", "retry", "skeleton", "zoomable", "data-table", "brush", "brush-min", "brush-max", "brush-start", "brush-end", "note"]; }
|
|
698
|
-
static get properties() { return { series: { attribute: "series" }, axis: { attribute: "axis" }, zoomable: { attribute: "zoomable", type: Boolean }, brush: { attribute: "brush", type: Boolean }, note: { attribute: "note" } }; }
|
|
676
|
+
static get observed() { return ["series", "axis", "color", "empty", "loading", "error", "retry", "skeleton", "zoomable", "data-table", "brush", "brush-min", "brush-max", "brush-start", "brush-end", "note", "bucket-count", "limit-values"]; }
|
|
677
|
+
static get properties() { return { series: { attribute: "series" }, axis: { attribute: "axis" }, color: { attribute: "color" }, zoomable: { attribute: "zoomable", type: Boolean }, brush: { attribute: "brush", type: Boolean }, note: { attribute: "note" }, "bucket-count": { attribute: "bucket-count" }, "limit-values": { attribute: "limit-values" } }; }
|
|
678
|
+
// Bindable histogram contract (R18-68). A histogram consumer drives a widget
|
|
679
|
+
// by assigning `bins` / `backgroundData` and reading `range`; libreship's
|
|
680
|
+
// `bindHistogram` is the one this was written against, and it writes those
|
|
681
|
+
// three as JS properties, not attributes. These accessors are the widget's
|
|
682
|
+
// side of that contract: a push re-renders, and a read returns the bins
|
|
683
|
+
// actually drawn rather than the last thing someone assigned.
|
|
684
|
+
get bins() {
|
|
685
|
+
const pushed = this._pushedBins;
|
|
686
|
+
return (pushed && pushed.length ? pushed : this._renderedBins || []).map((b) => ({ ...b }));
|
|
687
|
+
}
|
|
688
|
+
set bins(value) {
|
|
689
|
+
this._pushedBins = Array.isArray(value) ? value.map(normalizeChartBin).filter(Boolean) : [];
|
|
690
|
+
this.requestRender();
|
|
691
|
+
}
|
|
692
|
+
get backgroundData() {
|
|
693
|
+
const pushed = this._pushedBackground;
|
|
694
|
+
return (pushed && pushed.length ? pushed : this._renderedBackground || []).map((b) => ({ ...b }));
|
|
695
|
+
}
|
|
696
|
+
set backgroundData(value) {
|
|
697
|
+
this._pushedBackground = Array.isArray(value) ? value.map(normalizeChartBin).filter(Boolean) : [];
|
|
698
|
+
this.requestRender();
|
|
699
|
+
}
|
|
700
|
+
// `range` is a JS property, not an attribute write: the chart observes
|
|
701
|
+
// brush/brush-start/brush-end, so a setter that called `setAttribute` on
|
|
702
|
+
// itself would fire the callback that renders it (wc-contract's re-entrancy
|
|
703
|
+
// rule). The override is consumed by render() and never reflected back into
|
|
704
|
+
// attributes, which stay the author's.
|
|
705
|
+
_showsBrush() {
|
|
706
|
+
return this.hasAttribute("brush") || this._rangeOverride !== undefined;
|
|
707
|
+
}
|
|
708
|
+
get range() {
|
|
709
|
+
const override = this._rangeOverride;
|
|
710
|
+
if (override !== undefined) return override ? override.slice() : null;
|
|
711
|
+
if (!this.hasAttribute("brush")) return null;
|
|
712
|
+
const start = parseFloat(this.getAttribute("brush-start"));
|
|
713
|
+
const end = parseFloat(this.getAttribute("brush-end"));
|
|
714
|
+
return Number.isFinite(start) && Number.isFinite(end) ? [start, end] : null;
|
|
715
|
+
}
|
|
716
|
+
set range(value) {
|
|
717
|
+
if (value == null) {
|
|
718
|
+
this._rangeOverride = null;
|
|
719
|
+
this.requestRender();
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
const pair = Array.isArray(value) ? value : [value, value];
|
|
723
|
+
const start = Number(pair[0]);
|
|
724
|
+
const end = Number(pair[1]);
|
|
725
|
+
if (!Number.isFinite(start) || !Number.isFinite(end)) return;
|
|
726
|
+
this._rangeOverride = [start, end];
|
|
727
|
+
this.requestRender();
|
|
728
|
+
}
|
|
729
|
+
_axisLabel() {
|
|
730
|
+
const raw = this.getAttribute("axis");
|
|
731
|
+
if (!raw) return "";
|
|
732
|
+
try {
|
|
733
|
+
const parsed = JSON.parse(raw);
|
|
734
|
+
if (parsed && typeof parsed === "object") return parsed.label || parsed.title || parsed.name || "";
|
|
735
|
+
return String(parsed);
|
|
736
|
+
} catch (e) { return raw; }
|
|
737
|
+
}
|
|
738
|
+
_axisConfig() {
|
|
739
|
+
const raw = this.getAttribute("axis");
|
|
740
|
+
if (!raw) return null;
|
|
741
|
+
try {
|
|
742
|
+
const parsed = JSON.parse(raw);
|
|
743
|
+
return (parsed && typeof parsed === "object") ? parsed : null;
|
|
744
|
+
} catch (e) { return null; }
|
|
745
|
+
}
|
|
746
|
+
_valueDomain() {
|
|
747
|
+
const series = this.getAttribute("series");
|
|
748
|
+
if (!series) return null;
|
|
749
|
+
try {
|
|
750
|
+
const parsed = JSON.parse(series);
|
|
751
|
+
let min = Infinity, max = -Infinity;
|
|
752
|
+
(Array.isArray(parsed) ? parsed : []).forEach((s) => {
|
|
753
|
+
if (s && Array.isArray(s.values)) s.values.forEach((v) => {
|
|
754
|
+
const n = Number(v);
|
|
755
|
+
if (Number.isFinite(n)) { if (n < min) min = n; if (n > max) max = n; }
|
|
756
|
+
});
|
|
757
|
+
});
|
|
758
|
+
return Number.isFinite(min) && Number.isFinite(max) ? [min, max] : null;
|
|
759
|
+
} catch (e) { return null; }
|
|
760
|
+
}
|
|
761
|
+
_renderValueAxis() {
|
|
762
|
+
const ax = this.querySelector(".c-chart__axis");
|
|
763
|
+
if (!ax) return;
|
|
764
|
+
const cfg = this._axisConfig();
|
|
765
|
+
const y = cfg && cfg.y;
|
|
766
|
+
const domain = (y && y.domain) || this._valueDomain();
|
|
767
|
+
if (!domain) { ax.textContent = this._axisLabel(); return; }
|
|
768
|
+
const chart = (typeof window !== "undefined" && window.Contour && window.Contour.chart) || null;
|
|
769
|
+
const ticks = (y && y.ticks) || (chart && chart.ticks ? chart.ticks(domain[0], domain[1], 5) : [domain[0], domain[1]]);
|
|
770
|
+
const format = (y && y.format) || ((v) => String(v));
|
|
771
|
+
ax.textContent = "";
|
|
772
|
+
ticks.forEach((t) => {
|
|
773
|
+
const span = document.createElement("span");
|
|
774
|
+
span.className = "c-chart__tick";
|
|
775
|
+
span.textContent = typeof format === "function" ? format(t) : String(t);
|
|
776
|
+
ax.appendChild(span);
|
|
777
|
+
});
|
|
778
|
+
this.style.setProperty("--chart-ticks", String(ticks.length));
|
|
779
|
+
}
|
|
780
|
+
_renderLegend() {
|
|
781
|
+
const series = this.getAttribute("series");
|
|
782
|
+
if (!series) return;
|
|
783
|
+
try {
|
|
784
|
+
const parsed = JSON.parse(series);
|
|
785
|
+
const labelled = (Array.isArray(parsed) ? parsed : []).filter((s) => s && s.label);
|
|
786
|
+
let legend = this.querySelector(".c-chart__legend");
|
|
787
|
+
if (!labelled.length) { if (legend) legend.remove(); return; }
|
|
788
|
+
if (!legend) { legend = document.createElement("div"); legend.className = "c-chart__legend"; this.appendChild(legend); }
|
|
789
|
+
legend.textContent = "";
|
|
790
|
+
labelled.forEach((s, i) => {
|
|
791
|
+
const item = document.createElement("span");
|
|
792
|
+
item.className = "c-chart__legend-item";
|
|
793
|
+
const swatch = document.createElement("span");
|
|
794
|
+
swatch.className = "c-chart__legend-swatch";
|
|
795
|
+
swatch.style.setProperty("--c", this.getAttribute("color") || `var(--chart-${i + 1})`);
|
|
796
|
+
item.appendChild(swatch);
|
|
797
|
+
item.appendChild(document.createTextNode(s.label));
|
|
798
|
+
legend.appendChild(item);
|
|
799
|
+
});
|
|
800
|
+
} catch (e) { /* ignore */ }
|
|
801
|
+
}
|
|
699
802
|
render() {
|
|
700
803
|
this.classList.add("c-chart");
|
|
701
|
-
|
|
702
|
-
|
|
804
|
+
// A chart with brush handles has focusable descendants, which role="img"
|
|
805
|
+
// forbids (an img is a leaf). A named group exposes the marks and keeps
|
|
806
|
+
// the controls reachable; the data table remains the alternative.
|
|
807
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
808
|
+
if (!this.hasAttribute("aria-roledescription")) this.setAttribute("aria-roledescription", "chart");
|
|
809
|
+
if (this.getAttribute("axis") && !this.hasAttribute("aria-label")) this.setAttribute("aria-label", this._axisLabel());
|
|
703
810
|
if (this.hasAttribute("loading")) {
|
|
704
811
|
const plot = this.ensure(".c-chart__plot", () => { const el = document.createElement("div"); el.className = "c-chart__plot"; return el; });
|
|
705
812
|
plot.innerHTML = "";
|
|
@@ -714,7 +821,7 @@ class ContourChart extends ContourBase {
|
|
|
714
821
|
const axis = this.getAttribute("axis");
|
|
715
822
|
if (axis) {
|
|
716
823
|
const ax = this.ensure(".c-chart__axis", () => { const el = document.createElement("div"); el.className = "c-chart__axis"; return el; });
|
|
717
|
-
ax.textContent =
|
|
824
|
+
ax.textContent = this._axisLabel();
|
|
718
825
|
}
|
|
719
826
|
return;
|
|
720
827
|
}
|
|
@@ -741,7 +848,7 @@ class ContourChart extends ContourBase {
|
|
|
741
848
|
const axis = this.getAttribute("axis");
|
|
742
849
|
if (axis) {
|
|
743
850
|
const ax = this.ensure(".c-chart__axis", () => { const el = document.createElement("div"); el.className = "c-chart__axis"; return el; });
|
|
744
|
-
ax.textContent =
|
|
851
|
+
ax.textContent = this._axisLabel();
|
|
745
852
|
}
|
|
746
853
|
return;
|
|
747
854
|
}
|
|
@@ -761,19 +868,31 @@ class ContourChart extends ContourBase {
|
|
|
761
868
|
const axis = this.getAttribute("axis");
|
|
762
869
|
if (axis) {
|
|
763
870
|
const ax = this.ensure(".c-chart__axis", () => { const el = document.createElement("div"); el.className = "c-chart__axis"; return el; });
|
|
764
|
-
ax.textContent =
|
|
871
|
+
ax.textContent = this._axisLabel();
|
|
765
872
|
}
|
|
766
873
|
return;
|
|
767
874
|
}
|
|
768
875
|
const axis = this.getAttribute("axis");
|
|
769
876
|
if (axis) {
|
|
770
877
|
const ax = this.ensure(".c-chart__axis", () => { const el = document.createElement("div"); el.className = "c-chart__axis"; return el; });
|
|
771
|
-
ax.textContent =
|
|
878
|
+
ax.textContent = this._axisLabel();
|
|
772
879
|
} else {
|
|
773
880
|
const ax = this.querySelector(".c-chart__axis");
|
|
774
881
|
if (ax) ax.remove();
|
|
775
882
|
}
|
|
776
|
-
|
|
883
|
+
// Value axis: when `axis` is {y:{domain,ticks,format}} (or the series
|
|
884
|
+
// carries values), print the ticks and publish --chart-ticks.
|
|
885
|
+
this._renderValueAxis();
|
|
886
|
+
// Legend from series[].label, so a chart with named series is readable
|
|
887
|
+
// without the consumer hand-building a legend.
|
|
888
|
+
this._renderLegend();
|
|
889
|
+
// A bindable histogram may be driven by `bins` alone: a binder pushes the
|
|
890
|
+
// engine's distribution rather than serialising a `series` attribute, so with
|
|
891
|
+
// no series declared the pushed bins become the series this render reads.
|
|
892
|
+
let series = this.getAttribute("series");
|
|
893
|
+
if (!series && this._pushedBins && this._pushedBins.length) {
|
|
894
|
+
series = JSON.stringify([{ type: "histogram", bins: this._pushedBins }]);
|
|
895
|
+
}
|
|
777
896
|
if (series) {
|
|
778
897
|
let parsed = null;
|
|
779
898
|
try {
|
|
@@ -782,12 +901,19 @@ const series = this.getAttribute("series");
|
|
|
782
901
|
plot.innerHTML = "";
|
|
783
902
|
// Structured series: an item may carry `values` plus a `type`
|
|
784
903
|
// ("donut" | "histogram" | "line") instead of a pre-computed `d`
|
|
785
|
-
// path
|
|
786
|
-
//
|
|
787
|
-
|
|
904
|
+
// path, or carry pre-binned `bins` instead of raw `values`. The
|
|
905
|
+
// helpers in svg.mjs turn those into geometry so a consumer does
|
|
906
|
+
// not have to hand-compute arc or bar math.
|
|
907
|
+
const hasStructured = parsed.some((s) => s && (Array.isArray(s.values) || Array.isArray(s.bins)));
|
|
788
908
|
if (hasStructured) {
|
|
789
|
-
|
|
790
|
-
|
|
909
|
+
// Each structured render rebuilds the published bins from the
|
|
910
|
+
// series it draws; without this a chart switched from a histogram
|
|
911
|
+
// to a line keeps reporting the old distribution.
|
|
912
|
+
this._renderedBins = [];
|
|
913
|
+
this._renderedBackground = [];
|
|
914
|
+
parsed.forEach((s, i) => {
|
|
915
|
+
const layerColor = this.getAttribute("color");
|
|
916
|
+
const color = layerColor || `var(--chart-${i + 1})`;
|
|
791
917
|
if (s.type === "donut") {
|
|
792
918
|
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
793
919
|
svg.setAttribute("viewBox", "0 0 200 200");
|
|
@@ -805,12 +931,20 @@ const series = this.getAttribute("series");
|
|
|
805
931
|
svg.appendChild(path);
|
|
806
932
|
});
|
|
807
933
|
plot.appendChild(svg);
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
barRects(
|
|
934
|
+
} else if (s.type === "bar") {
|
|
935
|
+
// A bar series is the histogram's geometry without the
|
|
936
|
+
// bucketing: one rect per value, in value order. The
|
|
937
|
+
// histogram branch bins its input into equal-width buckets
|
|
938
|
+
// and plots the counts, which is a different question, so
|
|
939
|
+
// `bar` cannot be folded into it. `barRects()` already
|
|
940
|
+
// normalises the values against the plot box, so the only
|
|
941
|
+
// difference here is that `plotVals` is the series itself.
|
|
942
|
+
const vals = Array.isArray(s.values) ? s.values : [];
|
|
943
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
944
|
+
svg.setAttribute("viewBox", "0 0 300 120");
|
|
945
|
+
svg.setAttribute("preserveAspectRatio", "none");
|
|
946
|
+
svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
|
|
947
|
+
barRects(vals).forEach((r, ri) => {
|
|
814
948
|
const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
815
949
|
rect.setAttribute("class", "c-chart__bar");
|
|
816
950
|
rect.setAttribute("data-series", String(i + 1));
|
|
@@ -818,15 +952,100 @@ const series = this.getAttribute("series");
|
|
|
818
952
|
rect.setAttribute("x", r.x);
|
|
819
953
|
rect.setAttribute("y", r.y);
|
|
820
954
|
rect.setAttribute("width", r.width);
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
955
|
+
rect.setAttribute("height", r.height);
|
|
956
|
+
rect.setAttribute("title", String(vals[ri]));
|
|
957
|
+
rect.setAttribute("aria-label", "Series " + (i + 1) + ": " + String(vals[ri]));
|
|
958
|
+
rect.setAttribute("tabindex", "0");
|
|
959
|
+
rect.setAttribute("role", "button");
|
|
960
|
+
rect.dataset.index = String(ri);
|
|
961
|
+
svg.appendChild(rect);
|
|
828
962
|
});
|
|
829
|
-
|
|
963
|
+
plot.appendChild(svg);
|
|
964
|
+
} else if (s.type === "histogram") {
|
|
965
|
+
// R16-23: bucket-count / limit-values controls.
|
|
966
|
+
// `limit-values` truncates the input array; `bucket-count`
|
|
967
|
+
// bins values into equal-width buckets and renders the
|
|
968
|
+
// per-bucket counts as bars. R18-68 adds the other door: a
|
|
969
|
+
// series may arrive pre-binned (`bins`) or be pushed whole by
|
|
970
|
+
// a binder, and either way the boundaries are published as
|
|
971
|
+
// `chart.bins` so a consumer can read them back.
|
|
972
|
+
let vals = Array.isArray(s.values) ? s.values.slice() : [];
|
|
973
|
+
const limitValues = parseInt(this.getAttribute("limit-values") || "0", 10);
|
|
974
|
+
if (limitValues > 0) vals = vals.slice(0, limitValues);
|
|
975
|
+
const bucketCount = parseInt(this.getAttribute("bucket-count") || "0", 10);
|
|
976
|
+
const pushedBins = this._pushedBins && this._pushedBins.length ? this._pushedBins : null;
|
|
977
|
+
const declaredBins = Array.isArray(s.bins) ? s.bins.map(normalizeChartBin).filter(Boolean) : null;
|
|
978
|
+
let bins = pushedBins || (declaredBins && declaredBins.length ? declaredBins : null);
|
|
979
|
+
let plotVals = vals;
|
|
980
|
+
if (!bins && bucketCount > 0 && vals.length) {
|
|
981
|
+
const nums = vals.map((v) => Number(v) || 0);
|
|
982
|
+
const min = Math.min.apply(null, nums);
|
|
983
|
+
const max = Math.max.apply(null, nums);
|
|
984
|
+
const range = max - min || 1;
|
|
985
|
+
const width = range / bucketCount;
|
|
986
|
+
const buckets = new Array(bucketCount).fill(0);
|
|
987
|
+
nums.forEach((v) => {
|
|
988
|
+
const bi = Math.min(bucketCount - 1, Math.floor((v - min) / width));
|
|
989
|
+
buckets[bi] += 1;
|
|
990
|
+
});
|
|
991
|
+
plotVals = buckets;
|
|
992
|
+
bins = buckets.map((count, bi) => ({ x0: min + bi * width, x1: min + (bi + 1) * width, count }));
|
|
993
|
+
}
|
|
994
|
+
if (bins) plotVals = bins.map((b) => b.count);
|
|
995
|
+
// Raw values with no bucket count have no boundaries to
|
|
996
|
+
// publish: those bars are counts at index positions, not a
|
|
997
|
+
// distribution over a domain, so `bins` stays empty and the
|
|
998
|
+
// consumer is told there is nothing to map a range onto.
|
|
999
|
+
this._renderedBins = bins ? bins.slice() : [];
|
|
1000
|
+
const pushedBackground = this._pushedBackground && this._pushedBackground.length ? this._pushedBackground : null;
|
|
1001
|
+
const declaredBackground = Array.isArray(s.background) ? s.background.map(normalizeChartBin).filter(Boolean) : null;
|
|
1002
|
+
const background = pushedBackground || (declaredBackground && declaredBackground.length ? declaredBackground : []);
|
|
1003
|
+
this._renderedBackground = background.slice();
|
|
1004
|
+
const backgroundVals = background.map((b) => Number(b.count) || 0);
|
|
1005
|
+
let sharedMax = 1;
|
|
1006
|
+
if (backgroundVals.length) {
|
|
1007
|
+
plotVals.concat(backgroundVals).forEach((v) => { const n = Number(v) || 0; if (n > sharedMax) sharedMax = n; });
|
|
1008
|
+
}
|
|
1009
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1010
|
+
svg.setAttribute("viewBox", "0 0 300 120");
|
|
1011
|
+
svg.setAttribute("preserveAspectRatio", "none");
|
|
1012
|
+
svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
|
|
1013
|
+
if (backgroundVals.length) {
|
|
1014
|
+
// Context bars: the unfiltered distribution behind the
|
|
1015
|
+
// selection. Deliberately not focusable and not announced —
|
|
1016
|
+
// they are the backdrop the marks are read against, and a
|
|
1017
|
+
// second set of stops would double the tab sequence.
|
|
1018
|
+
barRects(backgroundVals, { max: sharedMax }).forEach((r) => {
|
|
1019
|
+
const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
1020
|
+
rect.setAttribute("class", "c-chart__bar");
|
|
1021
|
+
rect.setAttribute("data-context", "");
|
|
1022
|
+
rect.setAttribute("aria-hidden", "true");
|
|
1023
|
+
rect.style.setProperty("--c", color);
|
|
1024
|
+
rect.setAttribute("x", r.x);
|
|
1025
|
+
rect.setAttribute("y", r.y);
|
|
1026
|
+
rect.setAttribute("width", r.width);
|
|
1027
|
+
rect.setAttribute("height", r.height);
|
|
1028
|
+
svg.appendChild(rect);
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
barRects(plotVals, backgroundVals.length ? { max: sharedMax } : undefined).forEach((r, ri) => {
|
|
1032
|
+
const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
1033
|
+
rect.setAttribute("class", "c-chart__bar");
|
|
1034
|
+
rect.setAttribute("data-series", String(i + 1));
|
|
1035
|
+
rect.style.setProperty("--c", color);
|
|
1036
|
+
rect.setAttribute("x", r.x);
|
|
1037
|
+
rect.setAttribute("y", r.y);
|
|
1038
|
+
rect.setAttribute("width", r.width);
|
|
1039
|
+
rect.setAttribute("height", r.height);
|
|
1040
|
+
const markValue = bins ? bins[ri].count : (Array.isArray(s.values) ? s.values[ri] : ri);
|
|
1041
|
+
rect.setAttribute("title", String(markValue));
|
|
1042
|
+
rect.setAttribute("aria-label", "Series " + (i + 1) + ": " + String(markValue));
|
|
1043
|
+
rect.setAttribute("tabindex", "0");
|
|
1044
|
+
rect.setAttribute("role", "button");
|
|
1045
|
+
rect.dataset.index = String(ri);
|
|
1046
|
+
svg.appendChild(rect);
|
|
1047
|
+
});
|
|
1048
|
+
plot.appendChild(svg);
|
|
830
1049
|
} else if (s.type === "scatter") {
|
|
831
1050
|
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
832
1051
|
svg.setAttribute("viewBox", "0 0 300 120");
|
|
@@ -909,7 +1128,7 @@ const series = this.getAttribute("series");
|
|
|
909
1128
|
});
|
|
910
1129
|
plot.appendChild(svg);
|
|
911
1130
|
}
|
|
912
|
-
} catch (e) {
|
|
1131
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
913
1132
|
// Styled tooltip element (positioned via --chart-tip-*).
|
|
914
1133
|
const tip = this.ensure(".c-chart__tooltip", () => { const el = document.createElement("div"); el.className = "c-chart__tooltip"; el.setAttribute("role", "tooltip"); el.setAttribute("hidden", ""); return el; });
|
|
915
1134
|
tip.setAttribute("hidden", "");
|
|
@@ -925,15 +1144,23 @@ const series = this.getAttribute("series");
|
|
|
925
1144
|
this.appendChild(table);
|
|
926
1145
|
}
|
|
927
1146
|
table.innerHTML = "";
|
|
1147
|
+
// A caption names the table: a reader who lands on it hears what it
|
|
1148
|
+
// holds before the first cell, not "table, 5 rows, 3 columns".
|
|
1149
|
+
const title = this.getAttribute("title") || this.getAttribute("aria-label") || labelText(this, "chart-data", "Chart data");
|
|
1150
|
+
const cap = document.createElement("caption");
|
|
1151
|
+
cap.textContent = title;
|
|
1152
|
+
table.appendChild(cap);
|
|
928
1153
|
const thead = document.createElement("thead");
|
|
929
1154
|
const hr = document.createElement("tr");
|
|
930
1155
|
const h = document.createElement("th");
|
|
931
|
-
h.
|
|
1156
|
+
h.setAttribute("scope", "col");
|
|
1157
|
+
h.textContent = labelText(this, "series", "Series");
|
|
932
1158
|
hr.appendChild(h);
|
|
933
1159
|
const maxLen = parsed.reduce((m, s) => Math.max(m, Array.isArray(s.values) ? s.values.length : (Array.isArray(s) ? s.length : 0)), 0);
|
|
934
1160
|
for (let i = 0; i < maxLen; i++) {
|
|
935
1161
|
const th = document.createElement("th");
|
|
936
|
-
th.
|
|
1162
|
+
th.setAttribute("scope", "col");
|
|
1163
|
+
th.textContent = labelText(this, "value", "Value") + " " + (i + 1);
|
|
937
1164
|
hr.appendChild(th);
|
|
938
1165
|
}
|
|
939
1166
|
thead.appendChild(hr);
|
|
@@ -942,7 +1169,8 @@ const series = this.getAttribute("series");
|
|
|
942
1169
|
parsed.forEach((s, si) => {
|
|
943
1170
|
const vals = Array.isArray(s.values) ? s.values : (Array.isArray(s) ? s : []);
|
|
944
1171
|
const tr = document.createElement("tr");
|
|
945
|
-
const td0 = document.createElement("
|
|
1172
|
+
const td0 = document.createElement("th");
|
|
1173
|
+
td0.setAttribute("scope", "row");
|
|
946
1174
|
td0.textContent = s.label || ("Series " + (si + 1));
|
|
947
1175
|
tr.appendChild(td0);
|
|
948
1176
|
for (let i = 0; i < maxLen; i++) {
|
|
@@ -957,13 +1185,25 @@ const series = this.getAttribute("series");
|
|
|
957
1185
|
const old = this.querySelector(".c-chart__data-table");
|
|
958
1186
|
if (old) old.remove();
|
|
959
1187
|
}
|
|
960
|
-
if (this.
|
|
1188
|
+
if (this._showsBrush()) {
|
|
961
1189
|
const brush = this.ensure("contour-brush", () => document.createElement("contour-brush"));
|
|
962
|
-
brush
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1190
|
+
// A binned histogram's brush is in data units, so the track
|
|
1191
|
+
// defaults to the bins' own extent; a consumer that supplies
|
|
1192
|
+
// brush-min/brush-max still wins. Without this a binder's
|
|
1193
|
+
// `range` would be positioned against a 0–100 track it never set.
|
|
1194
|
+
const drawnBins = this._renderedBins || [];
|
|
1195
|
+
const trackMin = this.getAttribute("brush-min") || (drawnBins.length ? String(drawnBins[0].x0) : "0");
|
|
1196
|
+
const trackMax = this.getAttribute("brush-max") || (drawnBins.length ? String(drawnBins[drawnBins.length - 1].x1) : "100");
|
|
1197
|
+
const override = Array.isArray(this._rangeOverride) ? this._rangeOverride : null;
|
|
1198
|
+
// `range = null` means "no constraint": the brush keeps its
|
|
1199
|
+
// affordance and shows the full track, rather than vanishing.
|
|
1200
|
+
const cleared = this._rangeOverride === null;
|
|
1201
|
+
brush.setAttribute("min", trackMin);
|
|
1202
|
+
brush.setAttribute("max", trackMax);
|
|
1203
|
+
brush.setAttribute("start", override ? String(override[0]) : cleared ? trackMin : (this.getAttribute("brush-start") || trackMin));
|
|
1204
|
+
brush.setAttribute("end", override ? String(override[1]) : cleared ? trackMax : (this.getAttribute("brush-end") || trackMax));
|
|
1205
|
+
const plotEl = this.querySelector(".c-chart__plot");
|
|
1206
|
+
if (brush.previousElementSibling !== plotEl) this.insertBefore(brush, plotEl ? plotEl.nextSibling : null);
|
|
967
1207
|
} else {
|
|
968
1208
|
const brush = this.querySelector("contour-brush");
|
|
969
1209
|
if (brush) brush.remove();
|
|
@@ -977,6 +1217,10 @@ const series = this.getAttribute("series");
|
|
|
977
1217
|
noteEl.remove();
|
|
978
1218
|
}
|
|
979
1219
|
} else {
|
|
1220
|
+
// No series: nothing is drawn, so nothing is published either. A
|
|
1221
|
+
// consumer reading `bins` must see the empty state, not the last one.
|
|
1222
|
+
this._renderedBins = [];
|
|
1223
|
+
this._renderedBackground = [];
|
|
980
1224
|
const plot = this.ensure(".c-chart__plot", () => { const el = document.createElement("div"); el.className = "c-chart__plot"; return el; });
|
|
981
1225
|
plot.innerHTML = "";
|
|
982
1226
|
const empty = document.createElement("div");
|
|
@@ -1000,23 +1244,36 @@ const series = this.getAttribute("series");
|
|
|
1000
1244
|
enhance() {
|
|
1001
1245
|
if (this._wiredChart) return;
|
|
1002
1246
|
this._wiredChart = true;
|
|
1003
|
-
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
1004
1247
|
// Series toggle responding to legend (F-10): hide/show series when a
|
|
1005
|
-
// legend item is toggled.
|
|
1006
|
-
|
|
1007
|
-
|
|
1248
|
+
// legend item is toggled. The legend may be a sibling of the chart, so
|
|
1249
|
+
// listen on the shared parent (which catches both a child and a sibling
|
|
1250
|
+
// legend) and match by key, data-key, or the item's index.
|
|
1251
|
+
const legendHost = this.parentElement || document;
|
|
1252
|
+
const onLegendToggle = (e) => {
|
|
1253
|
+
const key = e && e.detail && (e.detail.key != null ? e.detail.key : e.detail.label);
|
|
1254
|
+
const index = e && e.detail && e.detail.index;
|
|
1008
1255
|
const pressed = e && e.detail && e.detail.pressed;
|
|
1009
|
-
if (key == null) return;
|
|
1256
|
+
if (key == null && index == null) return;
|
|
1010
1257
|
const nodes = this.querySelectorAll("[data-series]");
|
|
1011
1258
|
nodes.forEach((n) => {
|
|
1012
1259
|
const s = n.getAttribute("data-series");
|
|
1013
|
-
|
|
1014
|
-
n.
|
|
1015
|
-
|
|
1260
|
+
const match = String(s) === String(key)
|
|
1261
|
+
|| n.getAttribute("data-key") === String(key)
|
|
1262
|
+
|| (index != null && String(s) === String(index + 1));
|
|
1263
|
+
if (match) n.style.display = pressed === false ? "none" : "";
|
|
1016
1264
|
});
|
|
1017
|
-
}
|
|
1265
|
+
};
|
|
1266
|
+
legendHost.addEventListener("contour:legend-toggle", onLegendToggle);
|
|
1267
|
+
onDispose(this, () => legendHost.removeEventListener("contour:legend-toggle", onLegendToggle));
|
|
1018
1268
|
this.addEventListener("contour:brush-end", (e) => {
|
|
1019
|
-
if (!this.
|
|
1269
|
+
if (!this._showsBrush() || !e.target || !e.target.matches("contour-brush")) return;
|
|
1270
|
+
// The brush moves its own attributes, so a chart already driven through the
|
|
1271
|
+
// `range` property records the new pair here; an author-driven chart stays
|
|
1272
|
+
// attribute-only and reads the brush itself. `undefined` is the switch:
|
|
1273
|
+
// once the property has been written, drags keep it current.
|
|
1274
|
+
if (this._rangeOverride !== undefined && e.detail && Array.isArray(e.detail.range)) {
|
|
1275
|
+
this._rangeOverride = e.detail.range.slice();
|
|
1276
|
+
}
|
|
1020
1277
|
this.dispatchEvent(new CustomEvent("contour:select", {
|
|
1021
1278
|
bubbles: true,
|
|
1022
1279
|
composed: true,
|
|
@@ -1136,24 +1393,23 @@ const series = this.getAttribute("series");
|
|
|
1136
1393
|
return;
|
|
1137
1394
|
}
|
|
1138
1395
|
const point = e.target && e.target.closest ? e.target.closest(".c-chart__point") : null;
|
|
1139
|
-
if (point
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
const idx = points.indexOf(point);
|
|
1149
|
-
const next = e.key === "ArrowRight" ? Math.min(idx + 1, points.length - 1) : Math.max(idx - 1, 0);
|
|
1150
|
-
if (next !== idx && points[next]) {
|
|
1151
|
-
points.forEach((p, i) => p.setAttribute("tabindex", i === next ? "0" : "-1"));
|
|
1152
|
-
try { points[next].focus(); } catch (err) {}
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1396
|
+
if (!point || !plot2.contains(point)) return;
|
|
1397
|
+
const series = parseInt(point.getAttribute("data-series") || "1", 10);
|
|
1398
|
+
const points = Array.from(plot2.querySelectorAll('.c-chart__point[data-series="' + series + '"]'));
|
|
1399
|
+
const idx = points.indexOf(point);
|
|
1400
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
1401
|
+
e.preventDefault();
|
|
1402
|
+
const index = parseInt(point.dataset.index || "0", 10);
|
|
1403
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series, index } }));
|
|
1404
|
+
return;
|
|
1155
1405
|
}
|
|
1156
|
-
|
|
1406
|
+
navKey(e, points, {
|
|
1407
|
+
wrap: false,
|
|
1408
|
+
rtl: isRtl(this),
|
|
1409
|
+
onNavigate: (i) => points.forEach((p, j) => p.setAttribute("tabindex", j === i ? "0" : "-1")),
|
|
1410
|
+
onKey: () => {}
|
|
1411
|
+
});
|
|
1412
|
+
});
|
|
1157
1413
|
this.addEventListener("keydown", (e) => {
|
|
1158
1414
|
// Only the host itself drives series switching; marks handle their own
|
|
1159
1415
|
// keys (B3-03). Without this gate one Enter fires contour:select twice.
|
|
@@ -1181,6 +1437,14 @@ const series = this.getAttribute("series");
|
|
|
1181
1437
|
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: next } }));
|
|
1182
1438
|
}
|
|
1183
1439
|
});
|
|
1440
|
+
// Cross-filter contract (R16-16): clear-all resets chart brush state.
|
|
1441
|
+
this.addEventListener("contour:clear-all", () => {
|
|
1442
|
+
if (this.hasAttribute("brush")) {
|
|
1443
|
+
this.removeAttribute("brush");
|
|
1444
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "chart", filter: { brush: null } } }));
|
|
1445
|
+
this.requestRender();
|
|
1446
|
+
}
|
|
1447
|
+
});
|
|
1184
1448
|
}
|
|
1185
1449
|
}
|
|
1186
1450
|
define("contour-chart", ContourChart);
|
|
@@ -1218,9 +1482,22 @@ class ContourComparison extends ContourBase {
|
|
|
1218
1482
|
const p = this.querySelector(".c-comparison__pane:not(.c-comparison__pane--before)");
|
|
1219
1483
|
if (p) p.textContent = afterLabel;
|
|
1220
1484
|
}
|
|
1485
|
+
// Labels (CARTO-inspired): overlay the before/after text on each pane.
|
|
1486
|
+
const beforePane = this.querySelector(".c-comparison__pane--before");
|
|
1487
|
+
if (beforePane) {
|
|
1488
|
+
let lbl = beforePane.querySelector(".c-comparison__label--before");
|
|
1489
|
+
if (!lbl) { lbl = document.createElement("span"); lbl.className = "c-comparison__label c-comparison__label--before"; beforePane.appendChild(lbl); }
|
|
1490
|
+
lbl.textContent = beforeLabel;
|
|
1491
|
+
}
|
|
1492
|
+
const afterPane = this.querySelector(".c-comparison__pane:not(.c-comparison__pane--before)");
|
|
1493
|
+
if (afterPane) {
|
|
1494
|
+
let lbl = afterPane.querySelector(".c-comparison__label--after");
|
|
1495
|
+
if (!lbl) { lbl = document.createElement("span"); lbl.className = "c-comparison__label c-comparison__label--after"; afterPane.appendChild(lbl); }
|
|
1496
|
+
lbl.textContent = afterLabel;
|
|
1497
|
+
}
|
|
1221
1498
|
const divider = this.getAttribute("divider");
|
|
1222
1499
|
if (divider !== null) {
|
|
1223
|
-
const d = this.ensure(".c-comparison__divider", () => { const el = document.createElement("div"); el.className = "c-comparison__divider"; el.setAttribute("role", "
|
|
1500
|
+
const d = this.ensure(".c-comparison__divider", () => { const el = document.createElement("div"); el.className = "c-comparison__divider"; el.setAttribute("role", "slider"); el.setAttribute("aria-orientation", "vertical"); el.setAttribute("aria-valuemin", "0"); el.setAttribute("aria-valuemax", "100"); el.setAttribute("aria-valuenow", "50"); el.setAttribute("aria-label", "Comparison divider"); el.setAttribute("tabindex", "0"); return el; });
|
|
1224
1501
|
if (divider) d.textContent = divider;
|
|
1225
1502
|
} else {
|
|
1226
1503
|
const d = this.querySelector(".c-comparison__divider");
|
|
@@ -1235,6 +1512,8 @@ class ContourComparison extends ContourBase {
|
|
|
1235
1512
|
const clamped = Math.max(0, Math.min(100, pct));
|
|
1236
1513
|
this.style.setProperty("--comparison-pos", clamped + "%");
|
|
1237
1514
|
this.setAttribute("value", String(Math.round(clamped)));
|
|
1515
|
+
const divider = this.querySelector(".c-comparison__divider");
|
|
1516
|
+
if (divider) divider.setAttribute("aria-valuenow", String(Math.round(clamped)));
|
|
1238
1517
|
this.dispatchEvent(new CustomEvent("contour:drag", { bubbles: true, composed: true, detail: { value: clamped } }));
|
|
1239
1518
|
};
|
|
1240
1519
|
let dragging = false;
|
|
@@ -1274,8 +1553,8 @@ class ContourStreamingChart extends ContourBase {
|
|
|
1274
1553
|
static get properties() { return { line: { attribute: "line" }, dot: { attribute: "dot" }, interval: { attribute: "interval", type: Number }, pause: { attribute: "pause", type: Boolean }, src: { attribute: "src" } }; }
|
|
1275
1554
|
render() {
|
|
1276
1555
|
this.classList.add("c-streaming-chart");
|
|
1277
|
-
this.setAttribute("role", "img");
|
|
1278
|
-
this.setAttribute("aria-label", "Streaming chart");
|
|
1556
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
1557
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Streaming chart");
|
|
1279
1558
|
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
1280
1559
|
wireStates(this);
|
|
1281
1560
|
loadRemote(this, "line");
|
|
@@ -1660,6 +1939,7 @@ class ContourGauge extends ContourBase {
|
|
|
1660
1939
|
} else {
|
|
1661
1940
|
valueEl.removeAttribute("aria-labelledby");
|
|
1662
1941
|
if (heading) valueEl.setAttribute("aria-label", heading);
|
|
1942
|
+
else valueEl.setAttribute("aria-label", valueEl.textContent || "Gauge");
|
|
1663
1943
|
}
|
|
1664
1944
|
// band word
|
|
1665
1945
|
const bandEl = this.querySelector(".c-gauge__band");
|
|
@@ -1688,8 +1968,8 @@ class ContourAxis extends ContourBase {
|
|
|
1688
1968
|
static get properties() { return { orientation: { attribute: "orientation" }, values: { attribute: "values" }, ticks: { attribute: "ticks" }, format: { attribute: "format" }, locale: { attribute: "locale" }, padding: { attribute: "padding" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
|
|
1689
1969
|
render() {
|
|
1690
1970
|
this.classList.add("c-axis");
|
|
1691
|
-
this.setAttribute("role", "img");
|
|
1692
|
-
this.setAttribute("aria-label", "Axis");
|
|
1971
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
1972
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Axis");
|
|
1693
1973
|
const orientation = this.getAttribute("orientation") || "horizontal";
|
|
1694
1974
|
this.classList.toggle("c-axis--horizontal", orientation === "horizontal");
|
|
1695
1975
|
this.classList.toggle("c-axis--vertical", orientation === "vertical");
|
|
@@ -1737,6 +2017,14 @@ define("contour-axis", ContourAxis);
|
|
|
1737
2017
|
class ContourBrush extends ContourBase {
|
|
1738
2018
|
static get observed() { return ["start", "end", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1739
2019
|
static get properties() { return { start: { attribute: "start" }, end: { attribute: "end" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
|
|
2020
|
+
// The selection as a numeric pair in the track's own units. `start`/`end`
|
|
2021
|
+
// stay the attribute strings they have always been; `range` is the shape a
|
|
2022
|
+
// cross-filter consumer wants, and libreship's histogram binder reads it.
|
|
2023
|
+
_rangeValue() {
|
|
2024
|
+
const start = parseFloat(this.getAttribute("start"));
|
|
2025
|
+
const end = parseFloat(this.getAttribute("end"));
|
|
2026
|
+
return Number.isFinite(start) && Number.isFinite(end) ? [start, end] : null;
|
|
2027
|
+
}
|
|
1740
2028
|
render() {
|
|
1741
2029
|
this.classList.add("c-brush");
|
|
1742
2030
|
this.setAttribute("role", "group");
|
|
@@ -1778,7 +2066,7 @@ class ContourBrush extends ContourBase {
|
|
|
1778
2066
|
const handle = e.target && e.target.classList && e.target.classList.contains("c-brush__handle") ? e.target : null;
|
|
1779
2067
|
dragging = handle ? (handle.classList.contains("c-brush__handle--start") ? "start" : "end") : "move";
|
|
1780
2068
|
try { this.setPointerCapture(e.pointerId); } catch (err) {}
|
|
1781
|
-
this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: { value: this.getAttribute("start"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
|
|
2069
|
+
this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: { value: this.getAttribute("start"), start: this.getAttribute("start"), end: this.getAttribute("end"), range: this._rangeValue() } }));
|
|
1782
2070
|
});
|
|
1783
2071
|
this.addEventListener("pointermove", (e) => {
|
|
1784
2072
|
if (!dragging) return;
|
|
@@ -1811,7 +2099,7 @@ class ContourBrush extends ContourBase {
|
|
|
1811
2099
|
if (eh) eh.style.insetInlineStart = (((ne - mn) / range) * 100) + "%";
|
|
1812
2100
|
// stash pending values
|
|
1813
2101
|
this._brushPending = { start: ns, end: ne };
|
|
1814
|
-
this.dispatchEvent(new CustomEvent("contour:brush", { bubbles: true, composed: true, detail: { start: ns, end: ne, value: ns } }));
|
|
2102
|
+
this.dispatchEvent(new CustomEvent("contour:brush", { bubbles: true, composed: true, detail: { start: ns, end: ne, value: ns, range: [ns, ne] } }));
|
|
1815
2103
|
});
|
|
1816
2104
|
this.addEventListener("pointerup", (e) => {
|
|
1817
2105
|
if (!dragging) return;
|
|
@@ -1822,15 +2110,24 @@ class ContourBrush extends ContourBase {
|
|
|
1822
2110
|
this.setAttribute("end", String(p.end));
|
|
1823
2111
|
this._brushPending = null;
|
|
1824
2112
|
}
|
|
1825
|
-
this.dispatchEvent(new CustomEvent("contour:brush-end", { bubbles: true, composed: true, detail: { value: this.getAttribute("end"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
|
|
1826
|
-
this.dispatchEvent(new CustomEvent("contour:brush", { bubbles: true, composed: true, detail: { start: this.getAttribute("start"), end: this.getAttribute("end"), value: this.getAttribute("end") } }));
|
|
2113
|
+
this.dispatchEvent(new CustomEvent("contour:brush-end", { bubbles: true, composed: true, detail: { value: this.getAttribute("end"), start: this.getAttribute("start"), end: this.getAttribute("end"), range: this._rangeValue() } }));
|
|
2114
|
+
this.dispatchEvent(new CustomEvent("contour:brush", { bubbles: true, composed: true, detail: { start: this.getAttribute("start"), end: this.getAttribute("end"), value: this.getAttribute("end"), range: this._rangeValue() } }));
|
|
1827
2115
|
});
|
|
1828
2116
|
// Keyboard: Enter/Space emits brush-start/brush-end (WC-P1-08).
|
|
1829
2117
|
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
1830
2118
|
this.addEventListener("keydown", (e) => {
|
|
1831
2119
|
if (e.key === "Enter" || e.key === " ") {
|
|
1832
2120
|
e.preventDefault();
|
|
1833
|
-
this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: { value: this.getAttribute("start"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
|
|
2121
|
+
this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: { value: this.getAttribute("start"), start: this.getAttribute("start"), end: this.getAttribute("end"), range: this._rangeValue() } }));
|
|
2122
|
+
}
|
|
2123
|
+
});
|
|
2124
|
+
// Cross-filter contract (R16-16): clear-all resets brush range.
|
|
2125
|
+
this.addEventListener("contour:clear-all", () => {
|
|
2126
|
+
if (this.hasAttribute("start") || this.hasAttribute("end")) {
|
|
2127
|
+
this.removeAttribute("start");
|
|
2128
|
+
this.removeAttribute("end");
|
|
2129
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "brush", filter: { start: null, end: null } } }));
|
|
2130
|
+
this.requestRender();
|
|
1834
2131
|
}
|
|
1835
2132
|
});
|
|
1836
2133
|
}
|
|
@@ -1845,8 +2142,10 @@ class ContourStackedBar extends ContourBase {
|
|
|
1845
2142
|
static get properties() { return { segments: { attribute: "segments" }, values: { attribute: "values" }, colors: { attribute: "colors" }, src: { attribute: "src" }, normalize: { attribute: "normalize" } }; }
|
|
1846
2143
|
render() {
|
|
1847
2144
|
this.classList.add("c-stacked-bar");
|
|
1848
|
-
|
|
1849
|
-
|
|
2145
|
+
// The bar carries a listbox of selectable segments; role=img would make
|
|
2146
|
+
// every one of them presentational. A named group exposes them.
|
|
2147
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
2148
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Stacked bar");
|
|
1850
2149
|
wireStates(this);
|
|
1851
2150
|
loadRemote(this, ["segments", "values"]);
|
|
1852
2151
|
if (renderStates(this, "stacked-bar")) return;
|
|
@@ -1890,7 +2189,7 @@ define("contour-stacked-bar", ContourStackedBar);
|
|
|
1890
2189
|
* Attributes: `items`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `search`.
|
|
1891
2190
|
*/
|
|
1892
2191
|
class ContourCategory extends ContourBase {
|
|
1893
|
-
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "
|
|
2192
|
+
static get observed() { return ["items", "search", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "note", "limit", "sort"]; }
|
|
1894
2193
|
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, search: { attribute: "search" }, note: { attribute: "note" }, limit: { attribute: "limit" }, sort: { attribute: "sort" } }; }
|
|
1895
2194
|
render() {
|
|
1896
2195
|
this.classList.add("c-category");
|
|
@@ -1988,18 +2287,35 @@ class ContourCategory extends ContourBase {
|
|
|
1988
2287
|
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx, label: item.querySelector(".c-category__label") ? item.querySelector(".c-category__label").textContent : item.textContent.trim() } }));
|
|
1989
2288
|
return;
|
|
1990
2289
|
}
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2290
|
+
navKey(e, all, {
|
|
2291
|
+
wrap: false,
|
|
2292
|
+
homeEnd: true,
|
|
2293
|
+
rtl: isRtl(this),
|
|
2294
|
+
onNavigate: (i) => all.forEach((it, j) => it.setAttribute("tabindex", j === i ? "0" : "-1")),
|
|
2295
|
+
onKey: () => {
|
|
2296
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
2297
|
+
const idx2 = all.indexOf(document.activeElement);
|
|
2298
|
+
all.forEach((o, j) => o.setAttribute("aria-selected", j === idx2 ? "true" : "false"));
|
|
2299
|
+
this.dispatchEvent(new CustomEvent("contour:select", {
|
|
2300
|
+
bubbles: true,
|
|
2301
|
+
composed: true,
|
|
2302
|
+
detail: {
|
|
2303
|
+
index: idx2,
|
|
2304
|
+
label: document.activeElement.querySelector(".c-category__label")
|
|
2305
|
+
? document.activeElement.querySelector(".c-category__label").textContent
|
|
2306
|
+
: document.activeElement.textContent.trim()
|
|
2307
|
+
}
|
|
2308
|
+
}));
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
});
|
|
2312
|
+
});
|
|
2313
|
+
// Cross-filter contract (R16-16): clear-all resets search filter.
|
|
2314
|
+
this.addEventListener("contour:clear-all", () => {
|
|
2315
|
+
if (this.hasAttribute("search")) {
|
|
2316
|
+
this.removeAttribute("search");
|
|
2317
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "category", filter: { search: null } } }));
|
|
2318
|
+
}
|
|
2003
2319
|
});
|
|
2004
2320
|
}
|
|
2005
2321
|
}
|
|
@@ -2009,12 +2325,14 @@ define("contour-category", ContourCategory);
|
|
|
2009
2325
|
* Attributes: `value`, `values`, `items`, `label`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `brownout`, `brownout-level`.
|
|
2010
2326
|
*/
|
|
2011
2327
|
class ContourDonut extends ContourBase {
|
|
2012
|
-
static get observed() { return ["value", "values", "items", "label", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level", "note"]; }
|
|
2013
|
-
static get properties() { return { value: { attribute: "value" }, values: { attribute: "values" }, items: { attribute: "items" }, label: { attribute: "label" }, src: { attribute: "src" }, note: { attribute: "note" } }; }
|
|
2328
|
+
static get observed() { return ["value", "values", "items", "label", "color", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level", "note"]; }
|
|
2329
|
+
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" } }; }
|
|
2014
2330
|
render() {
|
|
2015
2331
|
this.classList.add("c-donut");
|
|
2016
|
-
|
|
2017
|
-
|
|
2332
|
+
// The donut renders a list of segments beside the ring; an image role
|
|
2333
|
+
// would flatten that list out of the accessibility tree.
|
|
2334
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
2335
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Donut chart");
|
|
2018
2336
|
wireStates(this);
|
|
2019
2337
|
loadRemote(this, ["items", "values"]);
|
|
2020
2338
|
if (renderStates(this, "donut")) return;
|
|
@@ -2041,6 +2359,7 @@ class ContourDonut extends ContourBase {
|
|
|
2041
2359
|
const values = items.map((it) => (typeof it === "object" ? (it.value || 0) : Number(it) || 0));
|
|
2042
2360
|
const total = values.reduce((a, b) => a + b, 0) || 1;
|
|
2043
2361
|
const brownoutLevel = this.brownoutLevel();
|
|
2362
|
+
const layerColor = this.getAttribute("color");
|
|
2044
2363
|
const shedRing = this.shed("ring", 3);
|
|
2045
2364
|
if (!shedRing) {
|
|
2046
2365
|
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
@@ -2053,7 +2372,7 @@ class ContourDonut extends ContourBase {
|
|
|
2053
2372
|
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
2054
2373
|
circle.setAttribute("cx", "16"); circle.setAttribute("cy", "16"); circle.setAttribute("r", "12");
|
|
2055
2374
|
circle.setAttribute("fill", "none");
|
|
2056
|
-
circle.setAttribute("stroke", (typeof it === "object" && it.color
|
|
2375
|
+
circle.setAttribute("stroke", layerColor || (typeof it === "object" && it.color ? it.color : "var(--chart-" + ((i % 8) + 1) + ")"));
|
|
2057
2376
|
circle.setAttribute("stroke-width", "6");
|
|
2058
2377
|
const circ = 2 * Math.PI * 12;
|
|
2059
2378
|
circle.setAttribute("stroke-dasharray", (pct * circ) + " " + (circ - pct * circ));
|
|
@@ -2083,8 +2402,8 @@ class ContourDonut extends ContourBase {
|
|
|
2083
2402
|
row.setAttribute("role", "listitem");
|
|
2084
2403
|
const sw = document.createElement("span");
|
|
2085
2404
|
sw.className = "c-donut__swatch";
|
|
2086
|
-
sw.style.background = (typeof it === "object" && it.color
|
|
2087
|
-
if (sw.style.background) sw.dataset.color = (typeof it === "object" && it.color
|
|
2405
|
+
sw.style.background = layerColor || (typeof it === "object" && it.color ? it.color : "var(--chart-" + ((i % 8) + 1) + ")");
|
|
2406
|
+
if (sw.style.background) sw.dataset.color = layerColor || (typeof it === "object" && it.color ? it.color : sw.style.background);
|
|
2088
2407
|
row.appendChild(sw);
|
|
2089
2408
|
const lbl = document.createElement("span");
|
|
2090
2409
|
lbl.textContent = (typeof it === "object" ? (it.label || "") : String(it)) + " — " + values[i];
|
|
@@ -2110,74 +2429,104 @@ define("contour-donut", ContourDonut);
|
|
|
2110
2429
|
* Attributes: `values`, `points`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `annotations`.
|
|
2111
2430
|
*/
|
|
2112
2431
|
class ContourTimeSeries extends ContourBase {
|
|
2113
|
-
static get observed() { return ["values", "points", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "annotations", "note"
|
|
2114
|
-
static get properties() { return { values: { attribute: "values" }, points: { attribute: "points" },
|
|
2432
|
+
static get observed() { return ["values", "points", "series", "style", "title", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "annotations", "note"]; }
|
|
2433
|
+
static get properties() { return { values: { attribute: "values" }, points: { attribute: "points" }, series: { attribute: "series" }, style: { attribute: "style" }, src: { attribute: "src" }, annotations: { attribute: "annotations" }, note: { attribute: "note" } }; }
|
|
2115
2434
|
render() {
|
|
2116
2435
|
this.classList.add("c-time-series");
|
|
2117
|
-
|
|
2118
|
-
|
|
2436
|
+
// Points and bars are focusable marks (roving tabindex below); role=img
|
|
2437
|
+
// hides them. A named group keeps the name and exposes the marks.
|
|
2438
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
2439
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Time series");
|
|
2119
2440
|
wireStates(this);
|
|
2120
|
-
loadRemote(this, ["values", "points"]);
|
|
2441
|
+
loadRemote(this, ["values", "points", "series"]);
|
|
2121
2442
|
if (renderStates(this, "time-series")) return;
|
|
2122
2443
|
Array.from(this.querySelectorAll(".c-time-series__plot, .c-time-series__axis")).forEach((n) => n.remove());
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
const
|
|
2444
|
+
// Series management (R16-21): support multiple series via `series` JSON
|
|
2445
|
+
// attribute, with per-series style (line|bar), color binding, and
|
|
2446
|
+
// interval control. Falls back to single `values` attribute for
|
|
2447
|
+
// backward compatibility.
|
|
2448
|
+
let series = [];
|
|
2449
|
+
const sAttr = this.getAttribute("series");
|
|
2450
|
+
if (sAttr) { try { series = JSON.parse(sAttr); } catch (e) { series = []; } }
|
|
2451
|
+
const remote = remoteData(this, "series");
|
|
2452
|
+
if (Array.isArray(remote)) series = remote;
|
|
2453
|
+
// Backward compat: single `values` attribute becomes one series.
|
|
2454
|
+
if (!series.length) {
|
|
2455
|
+
let values = [];
|
|
2456
|
+
const vAttr = this.getAttribute("values");
|
|
2457
|
+
if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map(Number); } }
|
|
2458
|
+
if (values.length) {
|
|
2459
|
+
series = [{ label: "Series 1", values, style: this.getAttribute("style") || "bar", color: "var(--chart-1)" }];
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
const max = series.reduce((m, s) => { const v = Array.isArray(s.values) ? Math.max(...s.values, 0) : 0; return Math.max(m, v); }, 1);
|
|
2463
|
+
const min = series.reduce((m, s) => { const v = Array.isArray(s.values) ? Math.min(...s.values, 0) : 0; return Math.min(m, v); }, 0);
|
|
2129
2464
|
const plot = document.createElement("div");
|
|
2130
2465
|
plot.className = "c-time-series__plot";
|
|
2131
2466
|
plot.setAttribute("part", "plot");
|
|
2132
|
-
|
|
2133
|
-
const
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2467
|
+
series.forEach((s, si) => {
|
|
2468
|
+
const values = Array.isArray(s.values) ? s.values : [];
|
|
2469
|
+
const style = s.style || "bar";
|
|
2470
|
+
const color = s.color || `var(--chart-${((si % 8) + 1)})`;
|
|
2471
|
+
const label = s.label || `Series ${si + 1}`;
|
|
2472
|
+
if (style === "line") {
|
|
2473
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
2474
|
+
svg.setAttribute("viewBox", "0 0 300 120");
|
|
2475
|
+
svg.setAttribute("preserveAspectRatio", "none");
|
|
2476
|
+
svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
|
|
2477
|
+
const range = (max - min) || 1;
|
|
2478
|
+
const n = values.length || 1;
|
|
2479
|
+
const pts = values.map((v, i) => {
|
|
2480
|
+
const x = (i / Math.max(1, n - 1)) * 300;
|
|
2481
|
+
const y = 120 - ((v - min) / range) * 120;
|
|
2482
|
+
return x.toFixed(2) + "," + y.toFixed(2);
|
|
2483
|
+
}).join(" ");
|
|
2484
|
+
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
2485
|
+
path.setAttribute("class", "c-time-series__line");
|
|
2486
|
+
path.setAttribute("data-series", String(si));
|
|
2487
|
+
path.setAttribute("d", "M " + pts.replace(/ /g, " L "));
|
|
2488
|
+
path.style.stroke = color;
|
|
2489
|
+
path.style.fill = "none";
|
|
2490
|
+
path.style.strokeWidth = "2";
|
|
2491
|
+
svg.appendChild(path);
|
|
2492
|
+
// point markers
|
|
2493
|
+
values.forEach((v, i) => {
|
|
2494
|
+
const x = (i / Math.max(1, n - 1)) * 300;
|
|
2495
|
+
const y = 120 - ((v - min) / range) * 120;
|
|
2496
|
+
const c = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
2497
|
+
c.setAttribute("class", "c-time-series__point");
|
|
2498
|
+
c.setAttribute("data-series", String(si));
|
|
2499
|
+
c.setAttribute("data-index", String(i));
|
|
2500
|
+
c.setAttribute("cx", x.toFixed(2));
|
|
2501
|
+
c.setAttribute("cy", y.toFixed(2));
|
|
2502
|
+
c.setAttribute("r", "3");
|
|
2503
|
+
c.setAttribute("tabindex", i === 0 && si === 0 ? "0" : "-1");
|
|
2504
|
+
c.setAttribute("role", "button");
|
|
2505
|
+
c.setAttribute("title", String(v));
|
|
2506
|
+
c.setAttribute("aria-label", label + ": " + String(v));
|
|
2507
|
+
svg.appendChild(c);
|
|
2508
|
+
});
|
|
2509
|
+
plot.appendChild(svg);
|
|
2510
|
+
} else {
|
|
2511
|
+
values.forEach((v, i) => {
|
|
2512
|
+
const bar = document.createElement("div");
|
|
2513
|
+
bar.className = "c-time-series__bar";
|
|
2514
|
+
bar.setAttribute("data-series", String(si));
|
|
2515
|
+
bar.setAttribute("data-index", String(i));
|
|
2516
|
+
bar.style.blockSize = ((v / max) * 100) + "%";
|
|
2517
|
+
bar.style.background = color;
|
|
2518
|
+
bar.setAttribute("title", String(v));
|
|
2519
|
+
// A clickable, focusable mark is a button, not an image; the point
|
|
2520
|
+
// marks above already carry this role.
|
|
2521
|
+
bar.setAttribute("role", "button");
|
|
2522
|
+
bar.setAttribute("aria-label", label + ": " + String(v));
|
|
2523
|
+
bar.setAttribute("tabindex", i === 0 && si === 0 ? "0" : "-1");
|
|
2524
|
+
plot.appendChild(bar);
|
|
2525
|
+
});
|
|
2526
|
+
}
|
|
2527
|
+
});
|
|
2179
2528
|
this.appendChild(plot);
|
|
2180
|
-
if (!values.length) renderEmpty(this, "time-series");
|
|
2529
|
+
if (!series.length || !series.some((s) => Array.isArray(s.values) && s.values.length)) renderEmpty(this, "time-series");
|
|
2181
2530
|
const note = this.getAttribute("note");
|
|
2182
2531
|
let noteEl = this.querySelector(".c-time-series__note");
|
|
2183
2532
|
if (note) {
|
|
@@ -2191,12 +2540,23 @@ class ContourTimeSeries extends ContourBase {
|
|
|
2191
2540
|
if (this._wiredTimeSeries) return;
|
|
2192
2541
|
this._wiredTimeSeries = true;
|
|
2193
2542
|
const bars = () => Array.from(this.querySelectorAll(".c-time-series__bar"));
|
|
2543
|
+
const points = () => Array.from(this.querySelectorAll(".c-time-series__point"));
|
|
2194
2544
|
this.addEventListener("click", (e) => {
|
|
2195
2545
|
const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
|
|
2196
2546
|
if (!bar || !this.contains(bar)) return;
|
|
2197
|
-
const
|
|
2198
|
-
|
|
2547
|
+
const seriesIdx = Number(bar.dataset.series || "0");
|
|
2548
|
+
const idx = Number(bar.dataset.index || "0");
|
|
2549
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: seriesIdx, index: idx, value: bar.getAttribute("title") } }));
|
|
2550
|
+
return;
|
|
2199
2551
|
});
|
|
2552
|
+
const pointClick = (e) => {
|
|
2553
|
+
const point = e.target && e.target.closest ? e.target.closest(".c-time-series__point") : null;
|
|
2554
|
+
if (!point || !this.contains(point)) return;
|
|
2555
|
+
const seriesIdx = Number(point.dataset.series || "0");
|
|
2556
|
+
const idx = Number(point.dataset.index || "0");
|
|
2557
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: seriesIdx, index: idx, value: point.getAttribute("title") } }));
|
|
2558
|
+
};
|
|
2559
|
+
this.addEventListener("click", pointClick);
|
|
2200
2560
|
this.addEventListener("keydown", (e) => {
|
|
2201
2561
|
const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
|
|
2202
2562
|
if (!bar || !this.contains(bar)) return;
|
|
@@ -2204,18 +2564,17 @@ class ContourTimeSeries extends ContourBase {
|
|
|
2204
2564
|
const idx = all.indexOf(bar);
|
|
2205
2565
|
if (e.key === "Enter" || e.key === " ") {
|
|
2206
2566
|
e.preventDefault();
|
|
2207
|
-
|
|
2567
|
+
const seriesIdx = Number(bar.dataset.series || "0");
|
|
2568
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: seriesIdx, index: idx, value: bar.getAttribute("title") } }));
|
|
2208
2569
|
return;
|
|
2209
2570
|
}
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
all.forEach((b, i) => b.setAttribute("tabindex", i === next ? "0" : "-1"));
|
|
2218
|
-
try { all[next].focus(); } catch (err) {}
|
|
2571
|
+
navKey(e, all, {
|
|
2572
|
+
wrap: false,
|
|
2573
|
+
homeEnd: true,
|
|
2574
|
+
rtl: isRtl(this),
|
|
2575
|
+
onNavigate: (i) => all.forEach((b, j) => b.setAttribute("tabindex", j === i ? "0" : "-1")),
|
|
2576
|
+
onKey: () => {}
|
|
2577
|
+
});
|
|
2219
2578
|
});
|
|
2220
2579
|
// focus tooltip
|
|
2221
2580
|
this.addEventListener("focusin", (e) => {
|
|
@@ -2224,6 +2583,11 @@ class ContourTimeSeries extends ContourBase {
|
|
|
2224
2583
|
const tip = this.querySelector(".c-time-series__tooltip");
|
|
2225
2584
|
if (tip) { tip.textContent = bar.getAttribute("title"); tip.removeAttribute("hidden"); }
|
|
2226
2585
|
}
|
|
2586
|
+
const point = e.target && e.target.closest ? e.target.closest(".c-time-series__point") : null;
|
|
2587
|
+
if (point && this.contains(point)) {
|
|
2588
|
+
const tip = this.querySelector(".c-time-series__tooltip");
|
|
2589
|
+
if (tip) { tip.textContent = point.getAttribute("title"); tip.removeAttribute("hidden"); }
|
|
2590
|
+
}
|
|
2227
2591
|
});
|
|
2228
2592
|
this.addEventListener("focusout", (e) => {
|
|
2229
2593
|
const tip = this.querySelector(".c-time-series__tooltip");
|
|
@@ -2362,6 +2726,7 @@ class ContourPivot extends ContourBase {
|
|
|
2362
2726
|
this.setAttribute("filter", fi.value);
|
|
2363
2727
|
this.render();
|
|
2364
2728
|
this.dispatchEvent(new CustomEvent("contour:filter", { bubbles: true, composed: true, detail: { query: fi.value } }));
|
|
2729
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "pivot", filter: { filter: fi.value } } }));
|
|
2365
2730
|
}
|
|
2366
2731
|
});
|
|
2367
2732
|
this.addEventListener("change", (e) => {
|
|
@@ -2389,6 +2754,13 @@ class ContourPivot extends ContourBase {
|
|
|
2389
2754
|
else if (e.key === "End") target = cell.parentElement.children[cell.parentElement.children.length - 1];
|
|
2390
2755
|
if (target) { e.preventDefault(); try { target.focus(); } catch (err) {} }
|
|
2391
2756
|
});
|
|
2757
|
+
// Cross-filter contract (R16-16): clear-all resets pivot filter.
|
|
2758
|
+
this.addEventListener("contour:clear-all", () => {
|
|
2759
|
+
if (this.hasAttribute("filter")) {
|
|
2760
|
+
this.removeAttribute("filter");
|
|
2761
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "pivot", filter: { filter: null } } }));
|
|
2762
|
+
}
|
|
2763
|
+
});
|
|
2392
2764
|
}
|
|
2393
2765
|
}
|
|
2394
2766
|
define("contour-pivot", ContourPivot);
|
|
@@ -2421,6 +2793,13 @@ class ContourBrownout extends ContourBase {
|
|
|
2421
2793
|
const level = this.getAttribute("level") || "0";
|
|
2422
2794
|
this.dataset.level = level;
|
|
2423
2795
|
this.setAttribute("data-level", level);
|
|
2796
|
+
// Decorative bar (visual indicator of the brownout level).
|
|
2797
|
+
let deco = this.querySelector(".c-brownout__decorative");
|
|
2798
|
+
if (!deco) { deco = document.createElement("span"); deco.className = "c-brownout__decorative"; deco.setAttribute("aria-hidden", "true"); this.appendChild(deco); }
|
|
2799
|
+
// Label (text description of the level).
|
|
2800
|
+
let lbl = this.querySelector(".c-brownout__label");
|
|
2801
|
+
if (!lbl) { lbl = document.createElement("span"); lbl.className = "c-brownout__label"; this.appendChild(lbl); }
|
|
2802
|
+
lbl.textContent = "Level " + level;
|
|
2424
2803
|
}
|
|
2425
2804
|
enhance() {}
|
|
2426
2805
|
}
|
|
@@ -2455,7 +2834,7 @@ class ContourInstrument extends ContourBase {
|
|
|
2455
2834
|
item.appendChild(val);
|
|
2456
2835
|
this.appendChild(item);
|
|
2457
2836
|
});
|
|
2458
|
-
} catch (e) {
|
|
2837
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
2459
2838
|
} else {
|
|
2460
2839
|
renderEmpty(this, "instrument");
|
|
2461
2840
|
}
|
|
@@ -2576,18 +2955,78 @@ class ContourBivariateLegend extends ContourBivariate {
|
|
|
2576
2955
|
static get observed() { return ["size", "axis-x", "axis-y", "colors", "selected"]; }
|
|
2577
2956
|
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" }, selected: { attribute: "selected" } }; }
|
|
2578
2957
|
render() {
|
|
2579
|
-
super.render();
|
|
2580
2958
|
this.classList.add("c-bivariate-legend");
|
|
2959
|
+
this.setAttribute("role", "group");
|
|
2960
|
+
this.setAttribute("aria-label", "Bivariate legend");
|
|
2961
|
+
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
2962
|
+
const matrix = this.ensure(".c-bivariate-legend__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate-legend__matrix"; return el; });
|
|
2963
|
+
matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
|
|
2964
|
+
matrix.style.gridTemplateRows = `repeat(${size}, 1fr)`;
|
|
2965
|
+
// Slot composition: authored cells win over the generated grid.
|
|
2966
|
+
const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains("c-bivariate-legend__cell"));
|
|
2967
|
+
if (!authored.length) {
|
|
2968
|
+
matrix.innerHTML = "";
|
|
2969
|
+
let colors = [];
|
|
2970
|
+
const cAttr = this.getAttribute("colors");
|
|
2971
|
+
if (cAttr) { try { colors = JSON.parse(cAttr); } catch (e) { colors = []; } }
|
|
2972
|
+
for (let r = 0; r < size; r++) {
|
|
2973
|
+
for (let c = 0; c < size; c++) {
|
|
2974
|
+
const cell = document.createElement("div");
|
|
2975
|
+
cell.className = "c-bivariate-legend__cell";
|
|
2976
|
+
cell.setAttribute("role", "button");
|
|
2977
|
+
cell.setAttribute("tabindex", "0");
|
|
2978
|
+
cell.setAttribute("aria-label", "Cell " + c + "," + r);
|
|
2979
|
+
// Palette runs from bottom-left (low/low) to top-right (high/high):
|
|
2980
|
+
// reverse the row order so the first palette row sits at the bottom.
|
|
2981
|
+
const srcIndex = (size - 1 - r) * size + c;
|
|
2982
|
+
if (colors[srcIndex]) { cell.style.background = colors[srcIndex]; cell.dataset.color = colors[srcIndex]; }
|
|
2983
|
+
matrix.appendChild(cell);
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
// selected highlight
|
|
2987
|
+
const sel = this.getAttribute("selected");
|
|
2988
|
+
if (sel) {
|
|
2989
|
+
const parts = sel.split(",");
|
|
2990
|
+
const sr = parseInt(parts[0], 10);
|
|
2991
|
+
const sc = parseInt(parts[1], 10);
|
|
2992
|
+
const cells = Array.from(matrix.querySelectorAll(".c-bivariate-legend__cell"));
|
|
2993
|
+
cells.forEach((cell, i) => {
|
|
2994
|
+
const rr = Math.floor(i / size);
|
|
2995
|
+
const cc = i % size;
|
|
2996
|
+
if (rr === sr && cc === sc) cell.setAttribute("data-selected", "");
|
|
2997
|
+
else cell.removeAttribute("data-selected");
|
|
2998
|
+
});
|
|
2999
|
+
}
|
|
3000
|
+
// aria-live region
|
|
3001
|
+
let live = this.querySelector(".c-bivariate-legend__live");
|
|
3002
|
+
if (!live) { live = document.createElement("div"); live.className = "c-bivariate-legend__live"; live.setAttribute("aria-live", "polite"); live.style.position = "absolute"; live.style.width = "1px"; live.style.height = "1px"; live.style.overflow = "hidden"; live.style.clip = "rect(0,0,0,0)"; this.appendChild(live); }
|
|
3003
|
+
}
|
|
3004
|
+
const axisX = this.getAttribute("axis-x");
|
|
3005
|
+
if (axisX) {
|
|
3006
|
+
const ax = this.ensure(".c-bivariate-legend__axis--x", () => { const el = document.createElement("div"); el.className = "c-bivariate-legend__axis c-bivariate-legend__axis--x"; return el; });
|
|
3007
|
+
ax.textContent = axisX;
|
|
3008
|
+
} else {
|
|
3009
|
+
const ax = this.querySelector(".c-bivariate-legend__axis--x");
|
|
3010
|
+
if (ax) ax.remove();
|
|
3011
|
+
}
|
|
3012
|
+
const axisY = this.getAttribute("axis-y");
|
|
3013
|
+
if (axisY) {
|
|
3014
|
+
const ay = this.ensure(".c-bivariate-legend__axis--y", () => { const el = document.createElement("div"); el.className = "c-bivariate-legend__axis c-bivariate-legend__axis--y"; return el; });
|
|
3015
|
+
ay.textContent = axisY;
|
|
3016
|
+
} else {
|
|
3017
|
+
const ay = this.querySelector(".c-bivariate-legend__axis--y");
|
|
3018
|
+
if (ay) ay.remove();
|
|
3019
|
+
}
|
|
2581
3020
|
}
|
|
2582
3021
|
enhance() {
|
|
2583
3022
|
if (this._wiredBivLegend) return;
|
|
2584
3023
|
this._wiredBivLegend = true;
|
|
2585
3024
|
const selectCell = (cell) => {
|
|
2586
|
-
const matrix = this.querySelector(".c-
|
|
2587
|
-
const cells = Array.from(matrix ? matrix.querySelectorAll(".c-
|
|
3025
|
+
const matrix = this.querySelector(".c-bivariate-legend__matrix");
|
|
3026
|
+
const cells = Array.from(matrix ? matrix.querySelectorAll(".c-bivariate-legend__cell") : []);
|
|
2588
3027
|
const idx = cells.indexOf(cell);
|
|
2589
3028
|
if (idx < 0) return;
|
|
2590
|
-
const size = Math.min(
|
|
3029
|
+
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
2591
3030
|
const row = Math.floor(idx / size);
|
|
2592
3031
|
const col = idx % size;
|
|
2593
3032
|
cells.forEach((cell, i) => {
|
|
@@ -2599,16 +3038,21 @@ class ContourBivariateLegend extends ContourBivariate {
|
|
|
2599
3038
|
this.dispatchEvent(new CustomEvent("contour:select", { detail: { row, col }, bubbles: true, composed: true }));
|
|
2600
3039
|
};
|
|
2601
3040
|
this.addEventListener("click", (e) => {
|
|
2602
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-
|
|
3041
|
+
const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate-legend__cell") : null;
|
|
2603
3042
|
if (cell && this.contains(cell)) selectCell(cell);
|
|
2604
3043
|
});
|
|
2605
3044
|
this.addEventListener("keydown", (e) => {
|
|
2606
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-
|
|
3045
|
+
const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate-legend__cell") : null;
|
|
2607
3046
|
if (!cell || !this.contains(cell)) return;
|
|
2608
3047
|
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); selectCell(cell); }
|
|
2609
3048
|
});
|
|
2610
3049
|
}
|
|
2611
|
-
clear() {
|
|
3050
|
+
clear() {
|
|
3051
|
+
this.removeAttribute("selected");
|
|
3052
|
+
const cells = Array.from(this.querySelectorAll(".c-bivariate-legend__cell"));
|
|
3053
|
+
cells.forEach((c) => c.removeAttribute("data-selected"));
|
|
3054
|
+
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true }));
|
|
3055
|
+
}
|
|
2612
3056
|
}
|
|
2613
3057
|
define("contour-bivariate-legend", ContourBivariateLegend);
|
|
2614
3058
|
/**
|
|
@@ -2691,6 +3135,19 @@ class ContourThreshold extends ContourBase {
|
|
|
2691
3135
|
else this.removeAttribute("data-state");
|
|
2692
3136
|
if (label) this.setAttribute("aria-label", label);
|
|
2693
3137
|
}
|
|
3138
|
+
enhance() {
|
|
3139
|
+
if (this._wiredThreshold) return;
|
|
3140
|
+
this._wiredThreshold = true;
|
|
3141
|
+
// Cross-filter contract (R16-16): clear-all resets threshold norm/target.
|
|
3142
|
+
this.addEventListener("contour:clear-all", () => {
|
|
3143
|
+
if (this.hasAttribute("norm") || this.hasAttribute("value")) {
|
|
3144
|
+
this.removeAttribute("norm");
|
|
3145
|
+
this.removeAttribute("value");
|
|
3146
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "threshold", filter: { norm: null, value: null } } }));
|
|
3147
|
+
this.requestRender();
|
|
3148
|
+
}
|
|
3149
|
+
});
|
|
3150
|
+
}
|
|
2694
3151
|
}
|
|
2695
3152
|
define("contour-threshold", ContourThreshold);
|
|
2696
3153
|
/**
|
|
@@ -2738,10 +3195,12 @@ class ContourMetricsFull extends ContourBase {
|
|
|
2738
3195
|
* Attributes: `title`, `ramp`, `scale`, `items`, `method`, `norm`, `selectable`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `glyphs`, `thresholds`, `breaks`, `no-data-color`, `size`, `table`, `classification`, `audit`, `continuous`, `ends`, `caption`.
|
|
2739
3196
|
*/
|
|
2740
3197
|
class ContourLegend extends ContourBase {
|
|
2741
|
-
static get observed() { return ["title", "ramp", "scale", "items", "method", "norm", "selectable", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "glyphs", "thresholds", "breaks", "no-data-color", "size", "table", "classification", "audit", "continuous", "ends", "caption"]; }
|
|
2742
|
-
static get properties() { return { title: { attribute: "title" }, ramp: { attribute: "ramp" }, scale: { attribute: "scale" }, items: { attribute: "items" }, method: { attribute: "method" }, norm: { attribute: "norm" }, selectable: { attribute: "selectable", type: Boolean }, src: { attribute: "src" } }; }
|
|
3198
|
+
static get observed() { return ["title", "ramp", "scale", "items", "method", "norm", "selectable", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "glyphs", "thresholds", "breaks", "no-data-color", "no-data-label", "size", "table", "classification", "audit", "continuous", "ends", "caption", "graduated"]; }
|
|
3199
|
+
static get properties() { return { title: { attribute: "title" }, ramp: { attribute: "ramp" }, scale: { attribute: "scale" }, items: { attribute: "items" }, method: { attribute: "method" }, norm: { attribute: "norm" }, selectable: { attribute: "selectable", type: Boolean }, src: { attribute: "src" }, graduated: { attribute: "graduated", type: Boolean } }; }
|
|
2743
3200
|
render() {
|
|
2744
3201
|
this.classList.add("c-legend");
|
|
3202
|
+
const graduated = this.hasAttribute("graduated");
|
|
3203
|
+
if (graduated) this.classList.add("c-legend--graduated");
|
|
2745
3204
|
const continuous = this.hasAttribute("continuous");
|
|
2746
3205
|
if (continuous || this.hasAttribute("selectable")) {
|
|
2747
3206
|
this.setAttribute("role", "group");
|
|
@@ -2782,7 +3241,8 @@ class ContourLegend extends ContourBase {
|
|
|
2782
3241
|
if (this.hasAttribute("selectable")) {
|
|
2783
3242
|
list.setAttribute("role", "group");
|
|
2784
3243
|
} else {
|
|
2785
|
-
|
|
3244
|
+
// Host already has role="list"; inner container should be generic
|
|
3245
|
+
list.removeAttribute("role");
|
|
2786
3246
|
}
|
|
2787
3247
|
if (title) list.setAttribute("aria-label", title);
|
|
2788
3248
|
list.innerHTML = "";
|
|
@@ -2797,13 +3257,28 @@ class ContourLegend extends ContourBase {
|
|
|
2797
3257
|
item.setAttribute("aria-pressed", "true");
|
|
2798
3258
|
item.dataset.key = key;
|
|
2799
3259
|
} else {
|
|
2800
|
-
item.setAttribute("role", "
|
|
2801
|
-
|
|
3260
|
+
item.setAttribute("role", "listitem");
|
|
3261
|
+
// aria-selected is not valid on role="listitem"; omit for non-selectable legends
|
|
2802
3262
|
}
|
|
2803
3263
|
const sw = document.createElement("span");
|
|
2804
|
-
|
|
3264
|
+
if (graduated) {
|
|
3265
|
+
sw.className = "c-legend__swatch c-legend__swatch--graduated";
|
|
3266
|
+
const gSize = it && it.size != null ? it.size : (it && it.value != null ? it.value : 1);
|
|
3267
|
+
const sizePx = Math.max(6, Math.min(24, parseFloat(gSize) * 4));
|
|
3268
|
+
sw.style.inlineSize = sizePx + "px";
|
|
3269
|
+
sw.style.blockSize = sizePx + "px";
|
|
3270
|
+
} else {
|
|
3271
|
+
sw.className = "c-legend__swatch";
|
|
3272
|
+
}
|
|
2805
3273
|
if (it && it.color) { sw.style.background = it.color; sw.dataset.color = it.color; }
|
|
2806
3274
|
item.appendChild(sw);
|
|
3275
|
+
// graduated break label
|
|
3276
|
+
if (graduated && (it && it.break != null)) {
|
|
3277
|
+
const bl = document.createElement("span");
|
|
3278
|
+
bl.className = "c-legend__break-label";
|
|
3279
|
+
bl.textContent = String(it.break);
|
|
3280
|
+
item.appendChild(bl);
|
|
3281
|
+
}
|
|
2807
3282
|
// geometry glyph
|
|
2808
3283
|
const glyphShape = (it && (it.shape || it.marker || it.glyph)) || this.getAttribute("glyphs");
|
|
2809
3284
|
if (glyphShape) {
|
|
@@ -2838,7 +3313,7 @@ class ContourLegend extends ContourBase {
|
|
|
2838
3313
|
}
|
|
2839
3314
|
list.appendChild(item);
|
|
2840
3315
|
});
|
|
2841
|
-
} catch (e) {
|
|
3316
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
2842
3317
|
} else {
|
|
2843
3318
|
const list = this.querySelector(".c-legend__items");
|
|
2844
3319
|
if (list) list.remove();
|
|
@@ -2867,11 +3342,13 @@ class ContourLegend extends ContourBase {
|
|
|
2867
3342
|
}
|
|
2868
3343
|
// no-data entry from palette / no-data-color
|
|
2869
3344
|
const ndColor = this.getAttribute("no-data-color");
|
|
3345
|
+
const ndLabel = this.getAttribute("no-data-label") || "No data";
|
|
2870
3346
|
if (ndColor) {
|
|
2871
3347
|
let nd = this.querySelector(".c-legend__no-data");
|
|
2872
3348
|
if (!nd) { nd = document.createElement("div"); nd.className = "c-legend__no-data"; this.appendChild(nd); }
|
|
2873
3349
|
nd.setAttribute("part", "no-data");
|
|
2874
|
-
nd.
|
|
3350
|
+
nd.setAttribute("aria-label", ndLabel);
|
|
3351
|
+
nd.textContent = ndLabel;
|
|
2875
3352
|
const glyph = document.createElement("span");
|
|
2876
3353
|
glyph.className = "glyph";
|
|
2877
3354
|
glyph.style.background = ndColor;
|
|
@@ -2933,7 +3410,7 @@ class ContourLegend extends ContourBase {
|
|
|
2933
3410
|
let det = this.querySelector(".c-legend__table-wrap");
|
|
2934
3411
|
if (!det) { det = document.createElement("details"); det.className = "c-legend__table-wrap"; this.appendChild(det); }
|
|
2935
3412
|
det.innerHTML = "";
|
|
2936
|
-
const sum = document.createElement("summary"); sum.textContent = "Data table"; det.appendChild(sum);
|
|
3413
|
+
const sum = document.createElement("summary"); sum.textContent = labelText(this, "data-table", "Data table"); det.appendChild(sum);
|
|
2937
3414
|
const tbl = document.createElement("table"); tbl.className = "c-legend__table";
|
|
2938
3415
|
const tbody = document.createElement("tbody");
|
|
2939
3416
|
parsed.forEach((row) => {
|
|
@@ -3009,22 +3486,17 @@ class ContourLegend extends ContourBase {
|
|
|
3009
3486
|
enhance() {
|
|
3010
3487
|
if (this._wiredLegend) return;
|
|
3011
3488
|
this._wiredLegend = true;
|
|
3489
|
+
const selectable = this.hasAttribute("selectable");
|
|
3012
3490
|
this.addEventListener("click", (e) => {
|
|
3491
|
+
if (!selectable) return;
|
|
3013
3492
|
const btn = e.target && e.target.closest ? e.target.closest(".c-legend__item") : null;
|
|
3014
3493
|
if (!btn || !this.contains(btn)) return;
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
btn.setAttribute("aria-pressed", String(pressed));
|
|
3020
|
-
selected = pressed;
|
|
3021
|
-
} else {
|
|
3022
|
-
const selected2 = btn.getAttribute("aria-selected") !== "true";
|
|
3023
|
-
btn.setAttribute("aria-selected", String(selected2));
|
|
3024
|
-
selected = selected2;
|
|
3025
|
-
}
|
|
3494
|
+
const pressed = btn.getAttribute("aria-pressed") !== "true";
|
|
3495
|
+
btn.setAttribute("aria-pressed", String(pressed));
|
|
3496
|
+
const items = Array.from(this.querySelectorAll(".c-legend__item"));
|
|
3497
|
+
const index = items.indexOf(btn);
|
|
3026
3498
|
this.dispatchEvent(new CustomEvent("contour:legend-toggle", {
|
|
3027
|
-
detail: { label: btn.textContent.trim(), key: btn.dataset.key || btn.textContent.trim(), pressed
|
|
3499
|
+
detail: { label: btn.textContent.trim(), key: btn.dataset.key || btn.textContent.trim(), pressed, index },
|
|
3028
3500
|
bubbles: true,
|
|
3029
3501
|
composed: true,
|
|
3030
3502
|
}));
|
|
@@ -3047,47 +3519,64 @@ class ContourLegend extends ContourBase {
|
|
|
3047
3519
|
this.dispatchEvent(new CustomEvent("contour:break-change", { detail: { value: t.value }, bubbles: true, composed: true }));
|
|
3048
3520
|
}
|
|
3049
3521
|
});
|
|
3050
|
-
// keyboard nav (listbox)
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
const ii = (start + i) % items.length;
|
|
3077
|
-
const txt = (items[ii].textContent || "").trim().toLowerCase();
|
|
3078
|
-
if (txt.startsWith(e.key.toLowerCase())) {
|
|
3079
|
-
e.preventDefault();
|
|
3080
|
-
items[ii].focus();
|
|
3081
|
-
items.forEach((o,j)=>o.setAttribute("tabindex", j===ii?"0":"-1"));
|
|
3082
|
-
break;
|
|
3522
|
+
// keyboard nav (listbox) - only for selectable legends
|
|
3523
|
+
if (selectable) {
|
|
3524
|
+
this.addEventListener("keydown", (e) => {
|
|
3525
|
+
const items = Array.from(this.querySelectorAll(".c-legend__item"));
|
|
3526
|
+
if (!items.length) return;
|
|
3527
|
+
const active = document.activeElement;
|
|
3528
|
+
const idx = items.indexOf(active);
|
|
3529
|
+
if (e.key === "Escape") {
|
|
3530
|
+
// clear selection
|
|
3531
|
+
items.forEach((o) => o.setAttribute("aria-pressed", "false"));
|
|
3532
|
+
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true }));
|
|
3533
|
+
return;
|
|
3534
|
+
}
|
|
3535
|
+
if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
3536
|
+
// type-ahead
|
|
3537
|
+
if (items.length > 7) {
|
|
3538
|
+
const start = idx >= 0 ? idx + 1 : 0;
|
|
3539
|
+
for (let i = 0; i < items.length; i++) {
|
|
3540
|
+
const ii = (start + i) % items.length;
|
|
3541
|
+
const txt = (items[ii].textContent || "").trim().toLowerCase();
|
|
3542
|
+
if (txt.startsWith(e.key.toLowerCase())) {
|
|
3543
|
+
e.preventDefault();
|
|
3544
|
+
items[ii].focus();
|
|
3545
|
+
items.forEach((o,j)=>o.setAttribute("tabindex", j===ii?"0":"-1"));
|
|
3546
|
+
break;
|
|
3547
|
+
}
|
|
3083
3548
|
}
|
|
3084
3549
|
}
|
|
3550
|
+
return;
|
|
3085
3551
|
}
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3552
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
3553
|
+
e.preventDefault();
|
|
3554
|
+
if (active && active.classList.contains("c-legend__item")) {
|
|
3555
|
+
active.click();
|
|
3556
|
+
}
|
|
3557
|
+
return;
|
|
3090
3558
|
}
|
|
3559
|
+
navKey(e, items, {
|
|
3560
|
+
wrap: true,
|
|
3561
|
+
homeEnd: true,
|
|
3562
|
+
rtl: isRtl(this),
|
|
3563
|
+
onNavigate: (i) => items.forEach((o, j) => o.setAttribute("tabindex", j === i ? "0" : "-1")),
|
|
3564
|
+
onKey: () => {}
|
|
3565
|
+
});
|
|
3566
|
+
});
|
|
3567
|
+
}
|
|
3568
|
+
// Cross-filter contract (R16-16): clear-all resets legend selection.
|
|
3569
|
+
this.addEventListener("contour:clear-all", () => {
|
|
3570
|
+
const items = Array.from(this.querySelectorAll(".c-legend__item"));
|
|
3571
|
+
let changed = false;
|
|
3572
|
+
items.forEach((o) => {
|
|
3573
|
+
if (o.getAttribute("role") === "button" && o.getAttribute("aria-pressed") === "true") {
|
|
3574
|
+
o.setAttribute("aria-pressed", "false");
|
|
3575
|
+
changed = true;
|
|
3576
|
+
}
|
|
3577
|
+
});
|
|
3578
|
+
if (changed) {
|
|
3579
|
+
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "legend", filter: { selection: null } } }));
|
|
3091
3580
|
}
|
|
3092
3581
|
});
|
|
3093
3582
|
}
|
|
@@ -3176,24 +3665,27 @@ class ContourTimeline extends ContourBase {
|
|
|
3176
3665
|
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
3177
3666
|
render() {
|
|
3178
3667
|
this.classList.add("c-timeline");
|
|
3179
|
-
|
|
3668
|
+
// Native list semantics: an <ol> with <li> items, not a role="list" on a
|
|
3669
|
+
// <div> recreating the platform's list numbering and association.
|
|
3670
|
+
let list = this.querySelector(".c-timeline__list");
|
|
3671
|
+
if (!list) { list = document.createElement("ol"); list.className = "c-timeline__list"; list.setAttribute("aria-label", this.getAttribute("aria-label") || "Timeline"); this.appendChild(list); }
|
|
3180
3672
|
wireStates(this);
|
|
3181
3673
|
loadRemote(this, "items");
|
|
3182
3674
|
if (renderStates(this, "timeline")) return;
|
|
3183
3675
|
const authored = Array.from(this.children).filter((n) => n.classList && n.classList.contains("c-timeline__item"));
|
|
3184
3676
|
const items = remoteData(this, "items");
|
|
3185
3677
|
if (items && !authored.length) {
|
|
3186
|
-
Array.from(
|
|
3678
|
+
Array.from(list.querySelectorAll(".c-timeline__item")).forEach((n) => n.remove());
|
|
3187
3679
|
try {
|
|
3188
3680
|
const parsed = JSON.parse(items);
|
|
3189
3681
|
parsed.forEach((it) => {
|
|
3190
|
-
const item = document.createElement("
|
|
3682
|
+
const item = document.createElement("li");
|
|
3191
3683
|
item.className = "c-timeline__item";
|
|
3192
|
-
item.setAttribute("role", "listitem");
|
|
3193
3684
|
item.setAttribute("tabindex", "-1");
|
|
3194
3685
|
if (it.time) {
|
|
3195
3686
|
const t = document.createElement("time");
|
|
3196
3687
|
t.className = "c-timeline__time";
|
|
3688
|
+
t.setAttribute("datetime", String(it.time));
|
|
3197
3689
|
t.textContent = it.time;
|
|
3198
3690
|
item.appendChild(t);
|
|
3199
3691
|
}
|
|
@@ -3209,9 +3701,9 @@ class ContourTimeline extends ContourBase {
|
|
|
3209
3701
|
tx.textContent = it.text;
|
|
3210
3702
|
item.appendChild(tx);
|
|
3211
3703
|
}
|
|
3212
|
-
|
|
3704
|
+
list.appendChild(item);
|
|
3213
3705
|
});
|
|
3214
|
-
} catch (e) {
|
|
3706
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
3215
3707
|
} else if (!authored.length) {
|
|
3216
3708
|
renderEmpty(this, "timeline");
|
|
3217
3709
|
}
|
|
@@ -3228,26 +3720,11 @@ class ContourTimeline extends ContourBase {
|
|
|
3228
3720
|
const idx = items.indexOf(item);
|
|
3229
3721
|
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx } }));
|
|
3230
3722
|
});
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
let next = -1;
|
|
3237
|
-
if (e.key === "ArrowDown") next = Math.min(idx + 1, items.length - 1);
|
|
3238
|
-
else if (e.key === "ArrowUp") next = Math.max(idx - 1, 0);
|
|
3239
|
-
else if (e.key === "Home") next = 0;
|
|
3240
|
-
else if (e.key === "End") next = items.length - 1;
|
|
3241
|
-
else if (e.key === "Enter" || e.key === " ") {
|
|
3242
|
-
e.preventDefault();
|
|
3243
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx } }));
|
|
3244
|
-
return;
|
|
3245
|
-
}
|
|
3246
|
-
if (next < 0 || next === idx) return;
|
|
3247
|
-
e.preventDefault();
|
|
3248
|
-
items.forEach((it, i) => it.setAttribute("tabindex", i === next ? "0" : "-1"));
|
|
3249
|
-
try { items[next].focus(); } catch (err) {}
|
|
3250
|
-
});
|
|
3723
|
+
this.addEventListener("keydown", (e) => {
|
|
3724
|
+
const items = Array.from(this.querySelectorAll(".c-timeline__item"));
|
|
3725
|
+
if (!items.length) return;
|
|
3726
|
+
navKey(e, items, { wrap: false, homeEnd: true, onNavigate: (i) => items.forEach((it, j) => it.setAttribute("tabindex", j === i ? "0" : "-1")), onKey: () => { if (e.key === "Enter" || e.key === " ") this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: items.indexOf(document.activeElement) } })); } });
|
|
3727
|
+
});
|
|
3251
3728
|
}
|
|
3252
3729
|
}
|
|
3253
3730
|
define("contour-timeline", ContourTimeline);
|
|
@@ -3272,6 +3749,17 @@ class ContourHeatmap extends ContourBase {
|
|
|
3272
3749
|
const cols = Math.ceil(Math.sqrt(authoredCells.length));
|
|
3273
3750
|
this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
|
|
3274
3751
|
this.style.inlineSize = "16rem";
|
|
3752
|
+
// Wrap authored cells in rows so gridcells have a required row parent
|
|
3753
|
+
let row = null;
|
|
3754
|
+
let col = 0;
|
|
3755
|
+
const newRow = () => { row = document.createElement("div"); row.setAttribute("role", "row"); this.appendChild(row); col = 0; };
|
|
3756
|
+
newRow();
|
|
3757
|
+
authoredCells.forEach((cell) => {
|
|
3758
|
+
cell.setAttribute("role", "gridcell");
|
|
3759
|
+
row.appendChild(cell);
|
|
3760
|
+
col++;
|
|
3761
|
+
if (col === cols) newRow();
|
|
3762
|
+
});
|
|
3275
3763
|
} else {
|
|
3276
3764
|
Array.from(this.querySelectorAll(".c-heatmap__cell")).forEach((n) => n.remove());
|
|
3277
3765
|
const count = Math.min(200, Math.max(0, parseInt(this.getAttribute("cells") || this.getAttribute("count") || "0", 10) || 0));
|
|
@@ -3281,15 +3769,21 @@ class ContourHeatmap extends ContourBase {
|
|
|
3281
3769
|
if (count > 0) {
|
|
3282
3770
|
let values = [];
|
|
3283
3771
|
try { values = JSON.parse(this.getAttribute("values") || "[]"); } catch (e) { values = []; }
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3772
|
+
let row = null;
|
|
3773
|
+
let col = 0;
|
|
3774
|
+
const newRow = () => { row = document.createElement("div"); row.setAttribute("role", "row"); this.appendChild(row); col = 0; };
|
|
3775
|
+
newRow();
|
|
3776
|
+
for (let i = 0; i < count; i++) {
|
|
3777
|
+
const cell = document.createElement("div");
|
|
3778
|
+
cell.className = "c-heatmap__cell";
|
|
3779
|
+
cell.setAttribute("role", "gridcell");
|
|
3780
|
+
cell.setAttribute("tabindex", i === 0 ? "0" : "-1");
|
|
3781
|
+
cell.dataset.index = String(i);
|
|
3782
|
+
if (values[i] !== undefined) cell.setAttribute("title", String(values[i]));
|
|
3783
|
+
row.appendChild(cell);
|
|
3784
|
+
col++;
|
|
3785
|
+
if (col === cols && i < count - 1) newRow();
|
|
3786
|
+
}
|
|
3293
3787
|
const tip = this.ensure(".c-heatmap__tooltip", () => { const el = document.createElement("div"); el.className = "c-heatmap__tooltip"; el.setAttribute("role", "tooltip"); el.setAttribute("hidden", ""); return el; });
|
|
3294
3788
|
tip.setAttribute("hidden", "");
|
|
3295
3789
|
} else if (!authoredCells.length) {
|
|
@@ -3324,7 +3818,7 @@ class ContourHeatmap extends ContourBase {
|
|
|
3324
3818
|
if (!cell || !this.contains(cell)) { tip.setAttribute("hidden", ""); return; }
|
|
3325
3819
|
const title = cell.getAttribute("title");
|
|
3326
3820
|
if (title) tip.textContent = title;
|
|
3327
|
-
else tip.textContent = "Cell " + (cell.dataset.index || "");
|
|
3821
|
+
else tip.textContent = labelText(this, "cell", "Cell") + " " + (cell.dataset.index || "");
|
|
3328
3822
|
const rect = this.getBoundingClientRect();
|
|
3329
3823
|
const cr = cell.getBoundingClientRect();
|
|
3330
3824
|
this.style.position = this.style.position || "relative";
|
|
@@ -3569,50 +4063,63 @@ class ContourChartGrid extends ContourBase {
|
|
|
3569
4063
|
define("contour-chart-grid", ContourChartGrid);
|
|
3570
4064
|
/**
|
|
3571
4065
|
* Contour Plot: web component wrapper.
|
|
3572
|
-
* Attributes: `
|
|
4066
|
+
* Attributes: `values` (row-major 2D field), `levels`, `label`.
|
|
3573
4067
|
*/
|
|
3574
4068
|
class ContourContourPlot extends ContourBase {
|
|
3575
|
-
static get observed() { return ["
|
|
3576
|
-
static get properties() { return {
|
|
4069
|
+
static get observed() { return ["values", "levels", "label"]; }
|
|
4070
|
+
static get properties() { return { values: { attribute: "values" }, levels: { attribute: "levels" }, label: { attribute: "label" } }; }
|
|
3577
4071
|
render() {
|
|
3578
4072
|
this.classList.add("c-contour-plot");
|
|
3579
|
-
this.setAttribute("role", "img");
|
|
3580
|
-
this.setAttribute("aria-label", "Contour plot");
|
|
3581
|
-
const axis = this.getAttribute("axis");
|
|
3582
|
-
if (axis) {
|
|
3583
|
-
let svg = this.querySelector("svg");
|
|
3584
|
-
if (!svg) {
|
|
3585
|
-
svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
3586
|
-
svg.setAttribute("viewBox", "0 0 100 100");
|
|
3587
|
-
svg.setAttribute("aria-hidden", "true");
|
|
3588
|
-
this.appendChild(svg);
|
|
3589
|
-
}
|
|
3590
|
-
let ax = svg.querySelector(".c-contour-plot__axis");
|
|
3591
|
-
if (!ax) {
|
|
3592
|
-
ax = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
3593
|
-
ax.setAttribute("class", "c-contour-plot__axis");
|
|
3594
|
-
svg.appendChild(ax);
|
|
3595
|
-
}
|
|
3596
|
-
}
|
|
4073
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
3597
4074
|
const label = this.getAttribute("label");
|
|
3598
|
-
if (label)
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
4075
|
+
if (label || !this.hasAttribute("aria-label")) this.setAttribute("aria-label", label || "Contour plot");
|
|
4076
|
+
const valuesAttr = this.getAttribute("values");
|
|
4077
|
+
const levelsAttr = this.getAttribute("levels");
|
|
4078
|
+
let grid = null;
|
|
4079
|
+
if (valuesAttr) { try { grid = JSON.parse(valuesAttr); } catch (e) { grid = null; } }
|
|
4080
|
+
let levels = [0.3, 0.5, 0.7];
|
|
4081
|
+
if (levelsAttr) { try { const l = JSON.parse(levelsAttr); if (Array.isArray(l) && l.length) levels = l; } catch (e) { /* keep defaults */ } }
|
|
4082
|
+
|
|
4083
|
+
let svg = this.querySelector("svg");
|
|
4084
|
+
if (!svg) {
|
|
4085
|
+
svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
4086
|
+
svg.setAttribute("class", "c-contour-plot__svg");
|
|
4087
|
+
svg.setAttribute("aria-hidden", "true");
|
|
4088
|
+
this.appendChild(svg);
|
|
4089
|
+
}
|
|
4090
|
+
// Clear previous contours so a re-render cannot stack a second set.
|
|
4091
|
+
Array.from(svg.querySelectorAll(".c-contour-plot__contour")).forEach((n) => n.remove());
|
|
4092
|
+
|
|
4093
|
+
if (Array.isArray(grid) && grid.length > 1 && Array.isArray(grid[0]) && grid[0].length > 1) {
|
|
4094
|
+
const draw = () => {
|
|
4095
|
+
const w = this.clientWidth || 300;
|
|
4096
|
+
const h = this.clientHeight || 300;
|
|
4097
|
+
svg.setAttribute("viewBox", `0 0 ${w} ${h}`);
|
|
4098
|
+
svg.querySelectorAll(".c-contour-plot__contour").forEach((n) => n.remove());
|
|
4099
|
+
contourPaths(grid, levels, w, h).forEach((line, li) => {
|
|
4100
|
+
if (!line.d) return;
|
|
4101
|
+
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
4102
|
+
path.setAttribute("d", line.d);
|
|
4103
|
+
path.setAttribute("class", "c-contour-plot__contour" + (li > 0 ? " c-contour-plot__contour--level-" + (li + 1) : ""));
|
|
4104
|
+
svg.appendChild(path);
|
|
4105
|
+
});
|
|
4106
|
+
};
|
|
4107
|
+
draw();
|
|
4108
|
+
// Re-render on resize so pixel-space paths track the container.
|
|
4109
|
+
if (typeof ResizeObserver !== "undefined" && !this._contourResize) {
|
|
4110
|
+
this._contourResize = new ResizeObserver(() => draw());
|
|
4111
|
+
this._contourResize.observe(this);
|
|
4112
|
+
onDispose(this, () => { this._contourResize.disconnect(); this._contourResize = null; });
|
|
3611
4113
|
}
|
|
3612
|
-
|
|
4114
|
+
} else if (!Array.isArray(grid)) {
|
|
4115
|
+
const empty = document.createElement("div");
|
|
4116
|
+
empty.className = "c-contour-plot__empty";
|
|
4117
|
+
empty.textContent = this.getAttribute("empty") || "No field";
|
|
4118
|
+
this.appendChild(empty);
|
|
3613
4119
|
}
|
|
3614
4120
|
}
|
|
3615
4121
|
}
|
|
4122
|
+
define("contour-contour-plot", ContourContourPlot);
|
|
3616
4123
|
/**
|
|
3617
4124
|
* Error Boundary: web component wrapper.
|
|
3618
4125
|
* Attributes: `fallback`, `error`.
|
|
@@ -3654,6 +4161,7 @@ class ContourErrorBoundary extends ContourBase {
|
|
|
3654
4161
|
e.stopPropagation();
|
|
3655
4162
|
const msg = (e && e.error && e.error.message) ? e.error.message : (e && e.message) ? e.message : "Unknown error";
|
|
3656
4163
|
this.setAttribute("error", msg);
|
|
4164
|
+
this.dispatchEvent(new CustomEvent("contour:error", { bubbles: true, composed: true, detail: { message: msg } }));
|
|
3657
4165
|
}, true);
|
|
3658
4166
|
}
|
|
3659
4167
|
}
|
|
@@ -3664,6 +4172,8 @@ class ContourDataExport extends ContourBase {
|
|
|
3664
4172
|
static get properties() { return { data: { attribute: "data" }, format: { attribute: "format" }, filename: { attribute: "filename" }, label: { attribute: "label" } }; }
|
|
3665
4173
|
render() {
|
|
3666
4174
|
this.classList.add("c-data-export");
|
|
4175
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
4176
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Data export");
|
|
3667
4177
|
const fmt = (this.getAttribute("format") || "json").toLowerCase();
|
|
3668
4178
|
const btn = this.ensure(".c-data-export__btn", () => {
|
|
3669
4179
|
const b = document.createElement("button");
|
|
@@ -3706,3 +4216,108 @@ class ContourDataExport extends ContourBase {
|
|
|
3706
4216
|
}
|
|
3707
4217
|
}
|
|
3708
4218
|
define("contour-data-export", ContourDataExport);
|
|
4219
|
+
|
|
4220
|
+
// Query builder: a list of field/operator/value rows with AND/OR connectors,
|
|
4221
|
+
// a remove button per row, and an Add rule button. The component renders the
|
|
4222
|
+
// rows from a `query` JSON attribute and emits contour:change with the
|
|
4223
|
+
// serialised query.
|
|
4224
|
+
class ContourQueryBuilder extends ContourBase {
|
|
4225
|
+
static get observed() { return ["query", "fields"]; }
|
|
4226
|
+
static get properties() { return { query: { attribute: "query" }, fields: { attribute: "fields" } }; }
|
|
4227
|
+
render() {
|
|
4228
|
+
this.classList.add("c-query-builder");
|
|
4229
|
+
const fields = this.getAttribute("fields");
|
|
4230
|
+
let fieldList = [];
|
|
4231
|
+
if (fields) { try { fieldList = JSON.parse(fields); } catch (e) { fieldList = []; } }
|
|
4232
|
+
const query = this.getAttribute("query");
|
|
4233
|
+
let rules = [];
|
|
4234
|
+
if (query) { try { rules = JSON.parse(query); } catch (e) { rules = []; } }
|
|
4235
|
+
const list = this.ensure(".c-query-builder__list", () => { const el = document.createElement("div"); el.className = "c-query-builder__list"; return el; });
|
|
4236
|
+
Array.from(list.querySelectorAll(".c-query-builder__row, .c-query-builder__connector")).forEach((n) => n.remove());
|
|
4237
|
+
rules.forEach((rule, i) => {
|
|
4238
|
+
// Connector between rows (AND/OR).
|
|
4239
|
+
if (i > 0) {
|
|
4240
|
+
const conn = document.createElement("div");
|
|
4241
|
+
conn.className = "c-query-builder__connector";
|
|
4242
|
+
const sel = document.createElement("select");
|
|
4243
|
+
sel.className = "c-query-builder__op";
|
|
4244
|
+
sel.setAttribute("aria-label", "Connector " + i);
|
|
4245
|
+
["AND", "OR"].forEach((c) => {
|
|
4246
|
+
const opt = document.createElement("option");
|
|
4247
|
+
opt.value = c; opt.textContent = c;
|
|
4248
|
+
if (c === (rule.connector || "AND")) opt.selected = true;
|
|
4249
|
+
sel.appendChild(opt);
|
|
4250
|
+
});
|
|
4251
|
+
conn.appendChild(sel);
|
|
4252
|
+
list.appendChild(conn);
|
|
4253
|
+
}
|
|
4254
|
+
const row = document.createElement("div");
|
|
4255
|
+
row.className = "c-query-builder__row";
|
|
4256
|
+
const field = document.createElement("select");
|
|
4257
|
+
field.className = "c-query-builder__field";
|
|
4258
|
+
field.setAttribute("aria-label", "Field " + (i + 1));
|
|
4259
|
+
fieldList.forEach((f) => {
|
|
4260
|
+
const opt = document.createElement("option");
|
|
4261
|
+
opt.value = typeof f === "string" ? f : (f.value || f.label || "");
|
|
4262
|
+
opt.textContent = typeof f === "string" ? f : (f.label || f.value || "");
|
|
4263
|
+
if (opt.value === rule.field) opt.selected = true;
|
|
4264
|
+
field.appendChild(opt);
|
|
4265
|
+
});
|
|
4266
|
+
const op = document.createElement("select");
|
|
4267
|
+
op.className = "c-query-builder__op";
|
|
4268
|
+
op.setAttribute("aria-label", "Operator " + (i + 1));
|
|
4269
|
+
["=", "!=", ">", "<", "contains"].forEach((o) => {
|
|
4270
|
+
const opt = document.createElement("option");
|
|
4271
|
+
opt.value = o; opt.textContent = o;
|
|
4272
|
+
if (o === rule.op) opt.selected = true;
|
|
4273
|
+
op.appendChild(opt);
|
|
4274
|
+
});
|
|
4275
|
+
const val = document.createElement("input");
|
|
4276
|
+
val.className = "c-query-builder__value";
|
|
4277
|
+
val.type = "text";
|
|
4278
|
+
val.value = rule.value || "";
|
|
4279
|
+
val.setAttribute("aria-label", "Value " + (i + 1));
|
|
4280
|
+
const remove = document.createElement("button");
|
|
4281
|
+
remove.type = "button";
|
|
4282
|
+
remove.className = "c-btn c-btn--sm c-btn--ghost c-query-builder__remove";
|
|
4283
|
+
remove.setAttribute("aria-label", "Remove rule " + (i + 1));
|
|
4284
|
+
remove.textContent = "×";
|
|
4285
|
+
row.appendChild(field); row.appendChild(op); row.appendChild(val); row.appendChild(remove);
|
|
4286
|
+
list.appendChild(row);
|
|
4287
|
+
});
|
|
4288
|
+
const add = this.ensure(".c-query-builder__add", () => { const b = document.createElement("button"); b.type = "button"; b.className = "c-btn c-btn--sm c-query-builder__add"; return b; });
|
|
4289
|
+
add.textContent = labelText(this, "add-rule", "Add rule");
|
|
4290
|
+
if (add.parentNode !== this) this.appendChild(add);
|
|
4291
|
+
}
|
|
4292
|
+
enhance() {
|
|
4293
|
+
if (this._wiredQueryBuilder) return;
|
|
4294
|
+
this._wiredQueryBuilder = true;
|
|
4295
|
+
this.addEventListener("click", (e) => {
|
|
4296
|
+
const t = e.target;
|
|
4297
|
+
if (t && t.closest && t.closest(".c-query-builder__add")) {
|
|
4298
|
+
const rows = Array.from(this.querySelectorAll(".c-query-builder__row")).map((r) => ({
|
|
4299
|
+
field: r.querySelector(".c-query-builder__field")?.value || "",
|
|
4300
|
+
op: r.querySelector(".c-query-builder__op")?.value || "=",
|
|
4301
|
+
value: r.querySelector(".c-query-builder__value")?.value || "",
|
|
4302
|
+
}));
|
|
4303
|
+
rows.push({ field: "", op: "=", value: "" });
|
|
4304
|
+
this.setAttribute("query", JSON.stringify(rows));
|
|
4305
|
+
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { query: rows } }));
|
|
4306
|
+
}
|
|
4307
|
+
if (t && t.closest && t.closest(".c-query-builder__remove")) {
|
|
4308
|
+
const row = t.closest(".c-query-builder__row");
|
|
4309
|
+
if (!row) return;
|
|
4310
|
+
const rows = Array.from(this.querySelectorAll(".c-query-builder__row")).map((r) => ({
|
|
4311
|
+
field: r.querySelector(".c-query-builder__field")?.value || "",
|
|
4312
|
+
op: r.querySelector(".c-query-builder__op")?.value || "=",
|
|
4313
|
+
value: r.querySelector(".c-query-builder__value")?.value || "",
|
|
4314
|
+
}));
|
|
4315
|
+
const idx = Array.from(this.querySelectorAll(".c-query-builder__row")).indexOf(row);
|
|
4316
|
+
if (idx >= 0) rows.splice(idx, 1);
|
|
4317
|
+
this.setAttribute("query", JSON.stringify(rows));
|
|
4318
|
+
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { query: rows } }));
|
|
4319
|
+
}
|
|
4320
|
+
});
|
|
4321
|
+
}
|
|
4322
|
+
}
|
|
4323
|
+
define("contour-query-builder", ContourQueryBuilder);
|