contour-ds 1.1.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/agent-rules.json +5 -1
- package/dist/build-manifest.json +93 -92
- package/dist/contour-wc.esm.js +4113 -480
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +4115 -478
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.components.json +2597 -135
- package/dist/contour.css +625 -27
- package/dist/contour.d.ts +109 -61
- package/dist/contour.esm.js +16 -0
- package/dist/contour.js +16 -0
- package/dist/contour.min.css +1 -1
- package/dist/contour.tokens.json +37 -0
- package/dist/docs/actions.md +6 -2
- package/dist/docs/affordances.md +19 -3
- package/dist/docs/colour.md +2 -2
- package/dist/docs/componentindex.md +39 -0
- package/dist/docs/data.md +38 -3
- package/dist/docs/docs.md +6 -2
- package/dist/docs/feedback.md +13 -3
- package/dist/docs/field.md +7 -2
- package/dist/docs/forms.md +35 -3
- package/dist/docs/index.json +32 -76
- package/dist/docs/install.md +4 -2
- package/dist/docs/landing.md +3 -2
- package/dist/docs/mapengine.md +9 -3
- package/dist/docs/motion.md +5 -2
- package/dist/docs/navigation.md +10 -3
- package/dist/docs/overlays.md +26 -3
- package/dist/docs/overview.md +2 -2
- package/dist/docs/patterns.md +38 -3
- package/dist/docs/playground.md +5 -2
- package/dist/docs/principles.md +2 -2
- package/dist/docs/recipes.md +7 -3
- package/dist/docs/space.md +2 -2
- package/dist/docs/status.md +19 -3
- package/dist/docs/surfaces.md +7 -3
- package/dist/docs/theming.md +5 -2
- package/dist/docs/type.md +2 -2
- package/dist/docs/webcomponents.md +26 -3
- package/dist/map-chrome.mapbox.css +4 -4
- package/dist/map-chrome.maplibre.css +4 -4
- 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 +69 -11
- package/dist/wc/content.mjs +163 -8
- package/dist/wc/core.mjs +145 -34
- package/dist/wc/dashboard.mjs +69 -4
- package/dist/wc/data.mjs +866 -115
- package/dist/wc/docs.mjs +1 -0
- package/dist/wc/feedback.mjs +75 -13
- package/dist/wc/forms.mjs +371 -34
- package/dist/wc/index.mjs +7 -3
- package/dist/wc/interaction.mjs +11 -6
- package/dist/wc/map.mjs +121 -38
- package/dist/wc/misc.mjs +29 -1
- package/dist/wc/navigation.mjs +424 -75
- package/dist/wc/registration.mjs +8 -4
- package/dist/wc/shadow.mjs +29 -12
- package/dist/wc/states.mjs +15 -0
- package/dist/wc/svg.mjs +10 -0
- package/dist/wc/ui.mjs +1710 -126
- package/package.json +39 -6
package/dist/wc/data.mjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { ContourBase, define, onDispose, formatValue, contourId } from './core.mjs';
|
|
2
2
|
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates, remoteInvalidate, watchViewport } from './states.mjs';
|
|
3
3
|
import { donutSlices, barRects, smoothPath, polylinePoints } from './svg.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* Readout: web component wrapper.
|
|
6
|
+
* Attributes: `rows`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `format`, `locale`.
|
|
7
|
+
*/
|
|
4
8
|
class ContourReadout extends ContourBase {
|
|
5
9
|
static get observed() { return ["rows", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "format", "locale"]; }
|
|
6
10
|
static get properties() { return { rows: { attribute: "rows" }, format: { attribute: "format" }, locale: { attribute: "locale" }, src: { attribute: "src" } }; }
|
|
@@ -25,7 +29,7 @@ class ContourReadout extends ContourBase {
|
|
|
25
29
|
const val = document.createElement("span");
|
|
26
30
|
val.className = "c-readout__value" + (r.primary ? " c-readout__value--primary" : "") + (r.accent ? " c-readout__value--accent" : "") + (r.coord ? " c-readout__value--coord" : "");
|
|
27
31
|
val.setAttribute("aria-live", "polite");
|
|
28
|
-
val.textContent = formatValue(r.value || r[1], this.getAttribute("format"), this.getAttribute("locale"));
|
|
32
|
+
val.textContent = formatValue(r.value || r[1], this.getAttribute("format"), this.getAttribute("locale"), (r.unit !== undefined ? r.unit : this.getAttribute("unit")));
|
|
29
33
|
row.appendChild(key);
|
|
30
34
|
row.appendChild(val);
|
|
31
35
|
if (r.order) {
|
|
@@ -43,6 +47,10 @@ class ContourReadout extends ContourBase {
|
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
define("contour-readout", ContourReadout);
|
|
50
|
+
/**
|
|
51
|
+
* Kpi: web component wrapper.
|
|
52
|
+
* Attributes: `value`, `label`, `delta`, `direction`, `note`, `variant`, `unit`, `format`, `locale`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `thresholds`, `threshold`, `sparkline`, `polarity`.
|
|
53
|
+
*/
|
|
46
54
|
class ContourKpi extends ContourBase {
|
|
47
55
|
static get observed() { return ["value", "label", "delta", "direction", "note", "variant", "unit", "format", "locale", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "thresholds", "threshold", "sparkline", "polarity"]; }
|
|
48
56
|
static get properties() {
|
|
@@ -61,7 +69,7 @@ class ContourKpi extends ContourBase {
|
|
|
61
69
|
if (variant) this.classList.add("c-kpi--" + variant);
|
|
62
70
|
if (value) {
|
|
63
71
|
const v = this.ensure(".c-kpi__value", () => { const el = document.createElement("div"); el.className = "c-kpi__value"; el.setAttribute("aria-live", "polite"); return el; });
|
|
64
|
-
v.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
|
|
72
|
+
v.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"), this.getAttribute("unit"));
|
|
65
73
|
} else {
|
|
66
74
|
const v = this.querySelector(".c-kpi__value");
|
|
67
75
|
if (v) v.remove();
|
|
@@ -142,7 +150,12 @@ class ContourKpi extends ContourBase {
|
|
|
142
150
|
}
|
|
143
151
|
}
|
|
144
152
|
define("contour-kpi", ContourKpi);
|
|
153
|
+
/**
|
|
154
|
+
* Table: web component wrapper.
|
|
155
|
+
* Attributes: `columns`, `rows`, `page`, `page-size`, `sort`, `sort-dir`, `virtual`, `empty`, `loading`, `error`, `retry`, `skeleton`, `persist`.
|
|
156
|
+
*/
|
|
145
157
|
class ContourTable extends ContourBase {
|
|
158
|
+
static get updateMode() { return "keyed"; }
|
|
146
159
|
static get observed() { return ["columns", "rows", "page", "page-size", "sort", "sort-dir", "virtual", "empty", "loading", "error", "retry", "skeleton", "persist"]; }
|
|
147
160
|
static get properties() { return { columns: { attribute: "columns" }, rows: { attribute: "rows" }, page: { attribute: "page", type: Number }, pageSize: { attribute: "page-size", type: Number } }; }
|
|
148
161
|
_cellValue(cell) {
|
|
@@ -159,6 +172,8 @@ class ContourTable extends ContourBase {
|
|
|
159
172
|
return String(av).localeCompare(String(bv), undefined, { numeric: true });
|
|
160
173
|
}
|
|
161
174
|
render() {
|
|
175
|
+
this.setAttribute("role", "region");
|
|
176
|
+
this.setAttribute("aria-label", "Table");
|
|
162
177
|
// The host is not a <table>, so it carries no table rule. The scroller the
|
|
163
178
|
// reflow contract requires is a real block element inside it.
|
|
164
179
|
const columns = this.getAttribute("columns");
|
|
@@ -440,7 +455,32 @@ class ContourTable extends ContourBase {
|
|
|
440
455
|
});
|
|
441
456
|
const tbody = table.querySelector("tbody");
|
|
442
457
|
tbody.innerHTML = "";
|
|
443
|
-
|
|
458
|
+
const useVirtual = this.hasAttribute("virtual") && !usePaging && pageData.length > 100;
|
|
459
|
+
const rowHeight = 36;
|
|
460
|
+
const windowSize = 30;
|
|
461
|
+
const overscan = 10;
|
|
462
|
+
let windowStart = 0;
|
|
463
|
+
let visibleData = pageData;
|
|
464
|
+
if (useVirtual) {
|
|
465
|
+
const maxStart = Math.max(0, pageData.length - windowSize);
|
|
466
|
+
windowStart = Math.min(maxStart, Math.max(0, Math.floor(wrap.scrollTop / rowHeight) - overscan));
|
|
467
|
+
visibleData = pageData.slice(windowStart, windowStart + windowSize + overscan * 2);
|
|
468
|
+
table.setAttribute("aria-rowcount", String(pageData.length + 1));
|
|
469
|
+
} else {
|
|
470
|
+
table.removeAttribute("aria-rowcount");
|
|
471
|
+
}
|
|
472
|
+
const addSpacer = (height) => {
|
|
473
|
+
const tr = document.createElement("tr");
|
|
474
|
+
tr.setAttribute("aria-hidden", "true");
|
|
475
|
+
const td = document.createElement("td");
|
|
476
|
+
td.colSpan = cols.length;
|
|
477
|
+
td.style.blockSize = `${height}px`;
|
|
478
|
+
td.style.padding = "0";
|
|
479
|
+
tr.appendChild(td);
|
|
480
|
+
tbody.appendChild(tr);
|
|
481
|
+
};
|
|
482
|
+
if (useVirtual) addSpacer(windowStart * rowHeight);
|
|
483
|
+
if (visibleData.length === 0) {
|
|
444
484
|
const tr = document.createElement("tr");
|
|
445
485
|
const td = document.createElement("td");
|
|
446
486
|
td.colSpan = cols.length;
|
|
@@ -450,8 +490,10 @@ class ContourTable extends ContourBase {
|
|
|
450
490
|
tr.appendChild(td);
|
|
451
491
|
tbody.appendChild(tr);
|
|
452
492
|
} else {
|
|
453
|
-
|
|
493
|
+
visibleData.forEach((row, ri) => {
|
|
454
494
|
const tr = document.createElement("tr");
|
|
495
|
+
tr.dataset.rowIndex = String(windowStart + ri);
|
|
496
|
+
tr.setAttribute("tabindex", "0");
|
|
455
497
|
cols.forEach((c, ci) => {
|
|
456
498
|
const isSelect = (typeof c === "object" && c !== null && c.select);
|
|
457
499
|
const td = document.createElement("td");
|
|
@@ -459,8 +501,8 @@ class ContourTable extends ContourBase {
|
|
|
459
501
|
const cb = document.createElement("input");
|
|
460
502
|
cb.type = "checkbox";
|
|
461
503
|
cb.className = "c-table__row-select";
|
|
462
|
-
cb.dataset.rowIndex = String(ri);
|
|
463
|
-
if (this._selectedRows && this._selectedRows.has(ri)) cb.checked = true;
|
|
504
|
+
cb.dataset.rowIndex = String(windowStart + ri);
|
|
505
|
+
if (this._selectedRows && this._selectedRows.has(windowStart + ri)) cb.checked = true;
|
|
464
506
|
td.appendChild(cb);
|
|
465
507
|
} else {
|
|
466
508
|
td.textContent = this._cellValue(row[ci]);
|
|
@@ -470,21 +512,17 @@ class ContourTable extends ContourBase {
|
|
|
470
512
|
tbody.appendChild(tr);
|
|
471
513
|
});
|
|
472
514
|
}
|
|
515
|
+
if (useVirtual) addSpacer(Math.max(0, pageData.length - windowStart - visibleData.length) * rowHeight);
|
|
473
516
|
if (table.parentNode !== wrap) {
|
|
474
517
|
wrap.innerHTML = "";
|
|
475
518
|
wrap.appendChild(table);
|
|
476
519
|
}
|
|
477
520
|
if (wrap.parentNode !== this) this.appendChild(wrap);
|
|
478
|
-
// Optional
|
|
479
|
-
// large datasets, without a JS scroll handler. Opt-in via `virtual`.
|
|
521
|
+
// Optional fixed-row DOM windowing for large datasets. Opt-in via `virtual`.
|
|
480
522
|
if (this.hasAttribute("virtual")) {
|
|
481
523
|
wrap.style.maxHeight = wrap.style.maxHeight || "24rem";
|
|
482
524
|
wrap.style.overflow = "auto";
|
|
483
525
|
table.classList.add("c-table--virtual");
|
|
484
|
-
Array.from(tbody.querySelectorAll("tr")).forEach((tr) => {
|
|
485
|
-
tr.style.contentVisibility = "auto";
|
|
486
|
-
tr.style.containIntrinsicSize = "auto 2rem";
|
|
487
|
-
});
|
|
488
526
|
} else {
|
|
489
527
|
wrap.style.maxHeight = "";
|
|
490
528
|
wrap.style.overflow = "";
|
|
@@ -585,6 +623,12 @@ class ContourTable extends ContourBase {
|
|
|
585
623
|
this._filters[idx] = inp.value;
|
|
586
624
|
this.requestRender();
|
|
587
625
|
});
|
|
626
|
+
this.addEventListener("scroll", (e) => {
|
|
627
|
+
if (!this.hasAttribute("virtual") || !e.target || !e.target.classList || !e.target.classList.contains("c-table-wrap")) return;
|
|
628
|
+
if (this._tableVirtualRaf) return;
|
|
629
|
+
const run = () => { this._tableVirtualRaf = 0; this.requestRender(); };
|
|
630
|
+
this._tableVirtualRaf = typeof requestAnimationFrame === "function" ? requestAnimationFrame(run) : setTimeout(run, 16);
|
|
631
|
+
}, true);
|
|
588
632
|
// Row selection (F-09): track checked rows and emit contour:select.
|
|
589
633
|
this._selectedRows = this._selectedRows || new Set();
|
|
590
634
|
this.addEventListener("change", (e) => {
|
|
@@ -604,12 +648,54 @@ class ContourTable extends ContourBase {
|
|
|
604
648
|
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { rows: Array.from(this._selectedRows) } }));
|
|
605
649
|
}
|
|
606
650
|
});
|
|
651
|
+
// Map-linked table (CARTO-inspired): emit contour:hover on row hover so a
|
|
652
|
+
// consumer can highlight/zoom the corresponding feature on the map.
|
|
653
|
+
// Contour stays engine-agnostic: it only announces the row.
|
|
654
|
+
this.addEventListener("mouseover", (e) => {
|
|
655
|
+
const tr = e.target && e.target.closest ? e.target.closest("tbody tr") : null;
|
|
656
|
+
if (!tr || !this.contains(tr)) return;
|
|
657
|
+
const idx = Number(tr.dataset.rowIndex);
|
|
658
|
+
if (!Number.isFinite(idx)) return;
|
|
659
|
+
if (this._hoveredRow === idx) return;
|
|
660
|
+
this._hoveredRow = idx;
|
|
661
|
+
this.dispatchEvent(new CustomEvent("contour:hover", { bubbles: true, composed: true, detail: { row: idx } }));
|
|
662
|
+
});
|
|
663
|
+
this.addEventListener("mouseout", (e) => {
|
|
664
|
+
const tr = e.target && e.target.closest ? e.target.closest("tbody tr") : null;
|
|
665
|
+
if (!tr || !this.contains(tr)) return;
|
|
666
|
+
const related = e.relatedTarget && e.relatedTarget.closest ? e.relatedTarget.closest("tbody tr") : null;
|
|
667
|
+
if (related === tr) return;
|
|
668
|
+
this._hoveredRow = null;
|
|
669
|
+
this.dispatchEvent(new CustomEvent("contour:leave", { bubbles: true, composed: true, detail: {} }));
|
|
670
|
+
});
|
|
671
|
+
this.addEventListener("keydown", (e) => {
|
|
672
|
+
if (e.key !== "Enter" && e.key !== " ") return;
|
|
673
|
+
const tr = e.target && e.target.closest ? e.target.closest("tbody tr") : null;
|
|
674
|
+
if (!tr || !this.contains(tr)) return;
|
|
675
|
+
e.preventDefault();
|
|
676
|
+
const idx = Number(tr.dataset.rowIndex);
|
|
677
|
+
if (!Number.isFinite(idx)) return;
|
|
678
|
+
this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true, detail: { row: idx } }));
|
|
679
|
+
});
|
|
607
680
|
}
|
|
608
681
|
}
|
|
609
682
|
define("contour-table", ContourTable);
|
|
683
|
+
class ContourDataTable extends ContourTable {
|
|
684
|
+
render() {
|
|
685
|
+
super.render();
|
|
686
|
+
this.classList.add("c-data-table");
|
|
687
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Data table");
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
define("contour-data-table", ContourDataTable);
|
|
691
|
+
/**
|
|
692
|
+
* Chart: web component wrapper.
|
|
693
|
+
* Attributes: `series`, `axis`, `empty`, `loading`, `error`, `retry`, `skeleton`, `zoomable`, `data-table`, `brush`, `brush-min`, `brush-max`, `brush-start`, `brush-end`.
|
|
694
|
+
*/
|
|
610
695
|
class ContourChart extends ContourBase {
|
|
611
|
-
static get
|
|
612
|
-
|
|
696
|
+
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" } }; }
|
|
613
699
|
render() {
|
|
614
700
|
this.classList.add("c-chart");
|
|
615
701
|
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
@@ -689,8 +775,9 @@ class ContourChart extends ContourBase {
|
|
|
689
775
|
}
|
|
690
776
|
const series = this.getAttribute("series");
|
|
691
777
|
if (series) {
|
|
778
|
+
let parsed = null;
|
|
692
779
|
try {
|
|
693
|
-
|
|
780
|
+
parsed = JSON.parse(series);
|
|
694
781
|
const plot = this.ensure(".c-chart__plot", () => { const el = document.createElement("div"); el.className = "c-chart__plot"; return el; });
|
|
695
782
|
plot.innerHTML = "";
|
|
696
783
|
// Structured series: an item may carry `values` plus a `type`
|
|
@@ -713,6 +800,8 @@ const series = this.getAttribute("series");
|
|
|
713
800
|
path.style.setProperty("--c", color);
|
|
714
801
|
path.setAttribute("d", sl.path);
|
|
715
802
|
path.setAttribute("title", String(s.values[si]));
|
|
803
|
+
path.setAttribute("aria-label", "Series " + (i + 1) + ": " + String(s.values[si]));
|
|
804
|
+
path.setAttribute("role", "img");
|
|
716
805
|
svg.appendChild(path);
|
|
717
806
|
});
|
|
718
807
|
plot.appendChild(svg);
|
|
@@ -731,13 +820,48 @@ const series = this.getAttribute("series");
|
|
|
731
820
|
rect.setAttribute("width", r.width);
|
|
732
821
|
rect.setAttribute("height", r.height);
|
|
733
822
|
rect.setAttribute("title", String(s.values[ri]));
|
|
734
|
-
rect.setAttribute("aria-label", String(s.values[ri]));
|
|
823
|
+
rect.setAttribute("aria-label", "Series " + (i + 1) + ": " + String(s.values[ri]));
|
|
735
824
|
rect.setAttribute("tabindex", "0");
|
|
736
825
|
rect.setAttribute("role", "button");
|
|
737
826
|
rect.dataset.index = String(ri);
|
|
738
827
|
svg.appendChild(rect);
|
|
739
828
|
});
|
|
740
829
|
plot.appendChild(svg);
|
|
830
|
+
} else if (s.type === "scatter") {
|
|
831
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
832
|
+
svg.setAttribute("viewBox", "0 0 300 120");
|
|
833
|
+
svg.setAttribute("preserveAspectRatio", "none");
|
|
834
|
+
svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
|
|
835
|
+
const pts = (Array.isArray(s.values) ? s.values : []).map((v) => {
|
|
836
|
+
if (Array.isArray(v)) return { x: Number(v[0]) || 0, y: Number(v[1]) || 0 };
|
|
837
|
+
return { x: Number(v && v.x) || 0, y: Number(v && v.y) || 0 };
|
|
838
|
+
});
|
|
839
|
+
const xs = pts.map((p) => p.x);
|
|
840
|
+
const ys = pts.map((p) => p.y);
|
|
841
|
+
const minX = xs.length ? Math.min.apply(null, xs) : 0;
|
|
842
|
+
const maxX = xs.length ? Math.max.apply(null, xs) : 1;
|
|
843
|
+
const minY = ys.length ? Math.min.apply(null, ys) : 0;
|
|
844
|
+
const maxY = ys.length ? Math.max.apply(null, ys) : 1;
|
|
845
|
+
const xRange = (maxX - minX) || 1;
|
|
846
|
+
const yRange = (maxY - minY) || 1;
|
|
847
|
+
pts.forEach((p, pi) => {
|
|
848
|
+
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
849
|
+
circle.setAttribute("class", "c-chart__point");
|
|
850
|
+
circle.setAttribute("data-series", String(i + 1));
|
|
851
|
+
circle.setAttribute("data-index", String(pi));
|
|
852
|
+
circle.style.setProperty("--c", color);
|
|
853
|
+
const cx = ((p.x - minX) / xRange) * 300;
|
|
854
|
+
const cy = 120 - ((p.y - minY) / yRange) * 120;
|
|
855
|
+
circle.setAttribute("cx", cx.toFixed(2));
|
|
856
|
+
circle.setAttribute("cy", cy.toFixed(2));
|
|
857
|
+
circle.setAttribute("r", "3");
|
|
858
|
+
circle.setAttribute("tabindex", pi === 0 ? "0" : "-1");
|
|
859
|
+
circle.setAttribute("role", "button");
|
|
860
|
+
circle.setAttribute("title", p.x + ", " + p.y);
|
|
861
|
+
circle.setAttribute("aria-label", "Series " + (i + 1) + ": " + p.x + ", " + p.y);
|
|
862
|
+
svg.appendChild(circle);
|
|
863
|
+
});
|
|
864
|
+
plot.appendChild(svg);
|
|
741
865
|
} else {
|
|
742
866
|
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
743
867
|
svg.setAttribute("viewBox", "0 0 300 120");
|
|
@@ -763,7 +887,7 @@ const series = this.getAttribute("series");
|
|
|
763
887
|
circle.setAttribute("tabindex", pi === 0 ? "0" : "-1");
|
|
764
888
|
circle.setAttribute("role", "button");
|
|
765
889
|
circle.setAttribute("title", String(s.values[pi]));
|
|
766
|
-
circle.setAttribute("aria-label", String(s.values[pi]));
|
|
890
|
+
circle.setAttribute("aria-label", "Series " + (i + 1) + ": " + String(s.values[pi]));
|
|
767
891
|
svg.appendChild(circle);
|
|
768
892
|
});
|
|
769
893
|
plot.appendChild(svg);
|
|
@@ -789,6 +913,69 @@ const series = this.getAttribute("series");
|
|
|
789
913
|
// Styled tooltip element (positioned via --chart-tip-*).
|
|
790
914
|
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; });
|
|
791
915
|
tip.setAttribute("hidden", "");
|
|
916
|
+
// Accessible data-table fallback (R12-18): opt-in via `data-table`
|
|
917
|
+
// attribute. Renders a visually-hidden table of the series values so
|
|
918
|
+
// screen readers and no-JS consumers can read the data behind the
|
|
919
|
+
// graphic. The graphic remains the primary presentation.
|
|
920
|
+
if (this.hasAttribute("data-table")) {
|
|
921
|
+
let table = this.querySelector(".c-chart__data-table");
|
|
922
|
+
if (!table) {
|
|
923
|
+
table = document.createElement("table");
|
|
924
|
+
table.className = "c-chart__data-table visually-hidden";
|
|
925
|
+
this.appendChild(table);
|
|
926
|
+
}
|
|
927
|
+
table.innerHTML = "";
|
|
928
|
+
const thead = document.createElement("thead");
|
|
929
|
+
const hr = document.createElement("tr");
|
|
930
|
+
const h = document.createElement("th");
|
|
931
|
+
h.textContent = "Series";
|
|
932
|
+
hr.appendChild(h);
|
|
933
|
+
const maxLen = parsed.reduce((m, s) => Math.max(m, Array.isArray(s.values) ? s.values.length : (Array.isArray(s) ? s.length : 0)), 0);
|
|
934
|
+
for (let i = 0; i < maxLen; i++) {
|
|
935
|
+
const th = document.createElement("th");
|
|
936
|
+
th.textContent = "Value " + (i + 1);
|
|
937
|
+
hr.appendChild(th);
|
|
938
|
+
}
|
|
939
|
+
thead.appendChild(hr);
|
|
940
|
+
table.appendChild(thead);
|
|
941
|
+
const tbody = document.createElement("tbody");
|
|
942
|
+
parsed.forEach((s, si) => {
|
|
943
|
+
const vals = Array.isArray(s.values) ? s.values : (Array.isArray(s) ? s : []);
|
|
944
|
+
const tr = document.createElement("tr");
|
|
945
|
+
const td0 = document.createElement("td");
|
|
946
|
+
td0.textContent = s.label || ("Series " + (si + 1));
|
|
947
|
+
tr.appendChild(td0);
|
|
948
|
+
for (let i = 0; i < maxLen; i++) {
|
|
949
|
+
const td = document.createElement("td");
|
|
950
|
+
td.textContent = vals[i] != null ? String(vals[i]) : "";
|
|
951
|
+
tr.appendChild(td);
|
|
952
|
+
}
|
|
953
|
+
tbody.appendChild(tr);
|
|
954
|
+
});
|
|
955
|
+
table.appendChild(tbody);
|
|
956
|
+
} else {
|
|
957
|
+
const old = this.querySelector(".c-chart__data-table");
|
|
958
|
+
if (old) old.remove();
|
|
959
|
+
}
|
|
960
|
+
if (this.hasAttribute("brush")) {
|
|
961
|
+
const brush = this.ensure("contour-brush", () => document.createElement("contour-brush"));
|
|
962
|
+
brush.setAttribute("min", this.getAttribute("brush-min") || "0");
|
|
963
|
+
brush.setAttribute("max", this.getAttribute("brush-max") || "100");
|
|
964
|
+
brush.setAttribute("start", this.getAttribute("brush-start") || this.getAttribute("brush-min") || "0");
|
|
965
|
+
brush.setAttribute("end", this.getAttribute("brush-end") || this.getAttribute("brush-max") || "100");
|
|
966
|
+
if (brush.previousElementSibling !== plot) this.appendChild(brush);
|
|
967
|
+
} else {
|
|
968
|
+
const brush = this.querySelector("contour-brush");
|
|
969
|
+
if (brush) brush.remove();
|
|
970
|
+
}
|
|
971
|
+
const note = this.getAttribute("note");
|
|
972
|
+
let noteEl = this.querySelector(".c-chart__note");
|
|
973
|
+
if (note) {
|
|
974
|
+
if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-chart__note"; this.appendChild(noteEl); }
|
|
975
|
+
noteEl.textContent = note;
|
|
976
|
+
} else if (noteEl) {
|
|
977
|
+
noteEl.remove();
|
|
978
|
+
}
|
|
792
979
|
} else {
|
|
793
980
|
const plot = this.ensure(".c-chart__plot", () => { const el = document.createElement("div"); el.className = "c-chart__plot"; return el; });
|
|
794
981
|
plot.innerHTML = "";
|
|
@@ -800,6 +987,14 @@ const series = this.getAttribute("series");
|
|
|
800
987
|
empty.style.height = "100%";
|
|
801
988
|
empty.style.color = "var(--color-text-muted)";
|
|
802
989
|
plot.appendChild(empty);
|
|
990
|
+
const note = this.getAttribute("note");
|
|
991
|
+
let noteEl2 = this.querySelector(".c-chart__note");
|
|
992
|
+
if (note) {
|
|
993
|
+
if (!noteEl2) { noteEl2 = document.createElement("div"); noteEl2.className = "c-chart__note"; this.appendChild(noteEl2); }
|
|
994
|
+
noteEl2.textContent = note;
|
|
995
|
+
} else if (noteEl2) {
|
|
996
|
+
noteEl2.remove();
|
|
997
|
+
}
|
|
803
998
|
}
|
|
804
999
|
}
|
|
805
1000
|
enhance() {
|
|
@@ -820,6 +1015,14 @@ const series = this.getAttribute("series");
|
|
|
820
1015
|
}
|
|
821
1016
|
});
|
|
822
1017
|
});
|
|
1018
|
+
this.addEventListener("contour:brush-end", (e) => {
|
|
1019
|
+
if (!this.hasAttribute("brush") || !e.target || !e.target.matches("contour-brush")) return;
|
|
1020
|
+
this.dispatchEvent(new CustomEvent("contour:select", {
|
|
1021
|
+
bubbles: true,
|
|
1022
|
+
composed: true,
|
|
1023
|
+
detail: e.detail,
|
|
1024
|
+
}));
|
|
1025
|
+
});
|
|
823
1026
|
// Zoom/pan (F-10 deferred): wheel to zoom, drag to pan, double-click to reset.
|
|
824
1027
|
if (this.hasAttribute("zoomable")) {
|
|
825
1028
|
let zoom = 1, panX = 0, panY = 0;
|
|
@@ -841,13 +1044,16 @@ const series = this.getAttribute("series");
|
|
|
841
1044
|
dragging = true; startX = e.clientX; startY = e.clientY; startPanX = panX; startPanY = panY;
|
|
842
1045
|
this.style.cursor = "grabbing";
|
|
843
1046
|
});
|
|
844
|
-
|
|
1047
|
+
const onMove = (e) => {
|
|
845
1048
|
if (!dragging) return;
|
|
846
1049
|
panX = startPanX + (e.clientX - startX);
|
|
847
1050
|
panY = startPanY + (e.clientY - startY);
|
|
848
1051
|
apply();
|
|
849
|
-
}
|
|
850
|
-
|
|
1052
|
+
};
|
|
1053
|
+
const onUp = () => { if (dragging) { dragging = false; this.style.cursor = ""; } };
|
|
1054
|
+
window.addEventListener("mousemove", onMove);
|
|
1055
|
+
window.addEventListener("mouseup", onUp);
|
|
1056
|
+
onDispose(this, () => { window.removeEventListener("mousemove", onMove); window.removeEventListener("mouseup", onUp); });
|
|
851
1057
|
this.addEventListener("dblclick", () => { zoom = 1; panX = 0; panY = 0; apply(); });
|
|
852
1058
|
}
|
|
853
1059
|
// Tooltip: show on hover of a mark.
|
|
@@ -978,11 +1184,17 @@ const series = this.getAttribute("series");
|
|
|
978
1184
|
}
|
|
979
1185
|
}
|
|
980
1186
|
define("contour-chart", ContourChart);
|
|
1187
|
+
/**
|
|
1188
|
+
* Comparison: web component wrapper.
|
|
1189
|
+
* Attributes: `divider`, `value`, `before`, `after`.
|
|
1190
|
+
*/
|
|
981
1191
|
class ContourComparison extends ContourBase {
|
|
982
1192
|
static get observed() { return ["divider", "value", "before", "after"]; }
|
|
983
1193
|
static get properties() { return { divider: { attribute: "divider" }, value: { attribute: "value" }, before: { attribute: "before" }, after: { attribute: "after" } }; }
|
|
984
1194
|
render() {
|
|
985
1195
|
this.classList.add("c-comparison");
|
|
1196
|
+
this.setAttribute("role", "group");
|
|
1197
|
+
this.setAttribute("aria-label", "Comparison");
|
|
986
1198
|
if (!this.style.blockSize) this.style.blockSize = "12rem";
|
|
987
1199
|
this.style.setProperty("--comparison-pos", (this.getAttribute("value") || "50") + "%");
|
|
988
1200
|
// Ensure two panes exist.
|
|
@@ -1033,6 +1245,7 @@ class ContourComparison extends ContourBase {
|
|
|
1033
1245
|
setPos(pct);
|
|
1034
1246
|
};
|
|
1035
1247
|
const onUp = () => { dragging = false; window.removeEventListener("mousemove", onMove); window.removeEventListener("mouseup", onUp); };
|
|
1248
|
+
onDispose(this, () => { dragging = false; window.removeEventListener("mousemove", onMove); window.removeEventListener("mouseup", onUp); });
|
|
1036
1249
|
this.addEventListener("mousedown", (e) => {
|
|
1037
1250
|
const d = divider();
|
|
1038
1251
|
if (!d || !d.contains(e.target)) return;
|
|
@@ -1051,11 +1264,19 @@ class ContourComparison extends ContourBase {
|
|
|
1051
1264
|
}
|
|
1052
1265
|
}
|
|
1053
1266
|
define("contour-comparison", ContourComparison);
|
|
1267
|
+
/**
|
|
1268
|
+
* Streaming Chart: web component wrapper.
|
|
1269
|
+
* Attributes: `line`, `dot`, `interval`, `pause`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
1270
|
+
*/
|
|
1054
1271
|
class ContourStreamingChart extends ContourBase {
|
|
1272
|
+
static get updateMode() { return "keyed"; }
|
|
1055
1273
|
static get observed() { return ["line", "dot", "interval", "pause", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1056
1274
|
static get properties() { return { line: { attribute: "line" }, dot: { attribute: "dot" }, interval: { attribute: "interval", type: Number }, pause: { attribute: "pause", type: Boolean }, src: { attribute: "src" } }; }
|
|
1057
1275
|
render() {
|
|
1058
1276
|
this.classList.add("c-streaming-chart");
|
|
1277
|
+
this.setAttribute("role", "img");
|
|
1278
|
+
this.setAttribute("aria-label", "Streaming chart");
|
|
1279
|
+
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
1059
1280
|
wireStates(this);
|
|
1060
1281
|
loadRemote(this, "line");
|
|
1061
1282
|
if (renderStates(this, "streaming-chart")) return;
|
|
@@ -1112,7 +1333,7 @@ class ContourStreamingChart extends ContourBase {
|
|
|
1112
1333
|
// own 1 s floor so the two cannot disagree.
|
|
1113
1334
|
const sync = () => {
|
|
1114
1335
|
const seconds = parseFloat(this.getAttribute("interval") || "");
|
|
1115
|
-
const want = Number.isFinite(seconds) && seconds > 0 && !this.hasAttribute("pause") && this._viewVisible !== false;
|
|
1336
|
+
const want = Number.isFinite(seconds) && seconds > 0 && !this.hasAttribute("pause") && !this._streamPausedByUser && this._viewVisible !== false;
|
|
1116
1337
|
if (want === this._streamRunning) return;
|
|
1117
1338
|
this._streamRunning = want;
|
|
1118
1339
|
if (this._streamTimer !== undefined) { clearInterval(this._streamTimer); this._streamTimer = undefined; }
|
|
@@ -1144,9 +1365,25 @@ class ContourStreamingChart extends ContourBase {
|
|
|
1144
1365
|
this._wiredStream = true;
|
|
1145
1366
|
this._streamFrame = 0;
|
|
1146
1367
|
onDispose(this, () => { if (this._streamTimer !== undefined) { clearInterval(this._streamTimer); this._streamTimer = undefined; } });
|
|
1368
|
+
// Keyboard: Space/Enter toggles pause (BY-08 keyboard contract).
|
|
1369
|
+
// Uses an internal flag so the toggle does not re-enter render.
|
|
1370
|
+
this._streamPausedByUser = false;
|
|
1371
|
+
this.addEventListener("keydown", (e) => {
|
|
1372
|
+
if (e.key === " " || e.key === "Enter") {
|
|
1373
|
+
e.preventDefault();
|
|
1374
|
+
this._streamPausedByUser = !this._streamPausedByUser;
|
|
1375
|
+
if (this._streamPausedByUser) this.setAttribute("data-user-paused", "");
|
|
1376
|
+
else this.removeAttribute("data-user-paused");
|
|
1377
|
+
sync();
|
|
1378
|
+
}
|
|
1379
|
+
});
|
|
1147
1380
|
}
|
|
1148
1381
|
}
|
|
1149
1382
|
define("contour-streaming-chart", ContourStreamingChart);
|
|
1383
|
+
/**
|
|
1384
|
+
* Meter: web component wrapper.
|
|
1385
|
+
* Attributes: `value`, `label`, `variant`, `min`, `max`, `low`, `high`, `optimum`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
1386
|
+
*/
|
|
1150
1387
|
class ContourMeter extends ContourBase {
|
|
1151
1388
|
static get observed() { return ["value", "label", "variant", "min", "max", "low", "high", "optimum", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1152
1389
|
static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, variant: { attribute: "variant" }, min: { attribute: "min" }, max: { attribute: "max" }, low: { attribute: "low" }, high: { attribute: "high" }, optimum: { attribute: "optimum" }, src: { attribute: "src" } }; }
|
|
@@ -1164,11 +1401,13 @@ class ContourMeter extends ContourBase {
|
|
|
1164
1401
|
renderEmpty(this, "meter");
|
|
1165
1402
|
return;
|
|
1166
1403
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1404
|
+
if (rValue === null) {
|
|
1405
|
+
this.style.removeProperty("--meter-value");
|
|
1406
|
+
} else {
|
|
1407
|
+
const num = parseFloat(rValue);
|
|
1408
|
+
if (Number.isFinite(num)) this.style.setProperty("--meter-value", rValue);
|
|
1409
|
+
else this.style.removeProperty("--meter-value");
|
|
1410
|
+
}
|
|
1172
1411
|
const core = this.ensure(".c-meter__core", () => { const el = document.createElement("span"); el.className = "c-meter__core"; return el; });
|
|
1173
1412
|
let val = core.querySelector(".c-meter__value");
|
|
1174
1413
|
if (!val) { val = document.createElement("span"); val.className = "c-meter__value"; core.appendChild(val); }
|
|
@@ -1200,6 +1439,10 @@ class ContourMeter extends ContourBase {
|
|
|
1200
1439
|
}
|
|
1201
1440
|
}
|
|
1202
1441
|
define("contour-meter", ContourMeter);
|
|
1442
|
+
/**
|
|
1443
|
+
* Delta: web component wrapper.
|
|
1444
|
+
* Attributes: `value`, `direction`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
1445
|
+
*/
|
|
1203
1446
|
class ContourDelta extends ContourBase {
|
|
1204
1447
|
static get observed() { return ["value", "direction", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1205
1448
|
static get properties() { return { value: { attribute: "value" }, direction: { attribute: "direction" }, src: { attribute: "src" } }; }
|
|
@@ -1228,6 +1471,10 @@ class ContourDelta extends ContourBase {
|
|
|
1228
1471
|
}
|
|
1229
1472
|
}
|
|
1230
1473
|
define("contour-delta", ContourDelta);
|
|
1474
|
+
/**
|
|
1475
|
+
* Stat: web component wrapper.
|
|
1476
|
+
* Attributes: `value`, `label`, `delta`, `unit`, `format`, `locale`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
1477
|
+
*/
|
|
1231
1478
|
class ContourStat extends ContourBase {
|
|
1232
1479
|
static get observed() { return ["value", "label", "delta", "unit", "format", "locale", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1233
1480
|
static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, delta: { attribute: "delta" }, unit: { attribute: "unit" }, format: { attribute: "format" }, locale: { attribute: "locale" }, src: { attribute: "src" } }; }
|
|
@@ -1241,7 +1488,7 @@ class ContourStat extends ContourBase {
|
|
|
1241
1488
|
const delta = this.getAttribute("delta");
|
|
1242
1489
|
if (value) {
|
|
1243
1490
|
const v = this.ensure(".c-stat__value", () => { const el = document.createElement("div"); el.className = "c-stat__value"; el.setAttribute("aria-live", "polite"); return el; });
|
|
1244
|
-
v.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
|
|
1491
|
+
v.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"), this.getAttribute("unit"));
|
|
1245
1492
|
} else {
|
|
1246
1493
|
const v = this.querySelector(".c-stat__value");
|
|
1247
1494
|
if (v) v.remove();
|
|
@@ -1278,6 +1525,10 @@ class ContourStat extends ContourBase {
|
|
|
1278
1525
|
}
|
|
1279
1526
|
}
|
|
1280
1527
|
define("contour-stat", ContourStat);
|
|
1528
|
+
/**
|
|
1529
|
+
* Gauge: web component wrapper.
|
|
1530
|
+
* Attributes: `value`, `min`, `max`, `heading`, `thresholds`, `format`, `locale`, `unit`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `brownout`, `brownout-level`, `no-data-message`, `show-header`, `description`.
|
|
1531
|
+
*/
|
|
1281
1532
|
class ContourGauge extends ContourBase {
|
|
1282
1533
|
static get observed() { return ["value", "min", "max", "heading", "thresholds", "format", "locale", "unit", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level", "no-data-message", "show-header", "description"]; }
|
|
1283
1534
|
static get properties() { return { value: { attribute: "value" }, min: { attribute: "min" }, max: { attribute: "max" }, heading: { attribute: "heading" }, thresholds: { attribute: "thresholds" }, format: { attribute: "format" }, locale: { attribute: "locale" }, unit: { attribute: "unit" }, src: { attribute: "src" }, brownout: { attribute: "brownout" } }; }
|
|
@@ -1370,17 +1621,18 @@ class ContourGauge extends ContourBase {
|
|
|
1370
1621
|
dial.appendChild(z);
|
|
1371
1622
|
}
|
|
1372
1623
|
}
|
|
1373
|
-
// needle
|
|
1374
|
-
const
|
|
1624
|
+
// needle (pivot at dial centre 50,90; 0 -> left, 100 -> right)
|
|
1625
|
+
const ratio = (num - min) / (max - min || 1);
|
|
1626
|
+
const angle = Math.PI * (1 - ratio);
|
|
1375
1627
|
const needle = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
1376
1628
|
needle.setAttribute("class", "c-gauge__needle needle");
|
|
1377
|
-
needle.setAttribute("x1", "50"); needle.setAttribute("y1", "
|
|
1378
|
-
needle.setAttribute("x2", String(50 + 35 * Math.cos(angle
|
|
1379
|
-
needle.setAttribute("y2", String(
|
|
1629
|
+
needle.setAttribute("x1", "50"); needle.setAttribute("y1", "90");
|
|
1630
|
+
needle.setAttribute("x2", String(50 + 35 * Math.cos(angle)));
|
|
1631
|
+
needle.setAttribute("y2", String(90 - 35 * Math.sin(angle)));
|
|
1380
1632
|
dial.appendChild(needle);
|
|
1381
1633
|
const hub = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
1382
1634
|
hub.setAttribute("class", "c-gauge__hub hub");
|
|
1383
|
-
hub.setAttribute("cx", "50"); hub.setAttribute("cy", "
|
|
1635
|
+
hub.setAttribute("cx", "50"); hub.setAttribute("cy", "90"); hub.setAttribute("r", "4");
|
|
1384
1636
|
dial.appendChild(hub);
|
|
1385
1637
|
}
|
|
1386
1638
|
// value element (meter)
|
|
@@ -1427,11 +1679,17 @@ class ContourGauge extends ContourBase {
|
|
|
1427
1679
|
enhance() {}
|
|
1428
1680
|
}
|
|
1429
1681
|
define("contour-gauge", ContourGauge);
|
|
1682
|
+
/**
|
|
1683
|
+
* Axis: web component wrapper.
|
|
1684
|
+
* Attributes: `orientation`, `values`, `ticks`, `format`, `locale`, `padding`, `min`, `max`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
1685
|
+
*/
|
|
1430
1686
|
class ContourAxis extends ContourBase {
|
|
1431
1687
|
static get observed() { return ["orientation", "values", "ticks", "format", "locale", "padding", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1432
1688
|
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" } }; }
|
|
1433
1689
|
render() {
|
|
1434
1690
|
this.classList.add("c-axis");
|
|
1691
|
+
this.setAttribute("role", "img");
|
|
1692
|
+
this.setAttribute("aria-label", "Axis");
|
|
1435
1693
|
const orientation = this.getAttribute("orientation") || "horizontal";
|
|
1436
1694
|
this.classList.toggle("c-axis--horizontal", orientation === "horizontal");
|
|
1437
1695
|
this.classList.toggle("c-axis--vertical", orientation === "vertical");
|
|
@@ -1472,11 +1730,17 @@ class ContourAxis extends ContourBase {
|
|
|
1472
1730
|
enhance() {}
|
|
1473
1731
|
}
|
|
1474
1732
|
define("contour-axis", ContourAxis);
|
|
1733
|
+
/**
|
|
1734
|
+
* Brush: web component wrapper.
|
|
1735
|
+
* Attributes: `start`, `end`, `min`, `max`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
1736
|
+
*/
|
|
1475
1737
|
class ContourBrush extends ContourBase {
|
|
1476
1738
|
static get observed() { return ["start", "end", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1477
1739
|
static get properties() { return { start: { attribute: "start" }, end: { attribute: "end" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
|
|
1478
1740
|
render() {
|
|
1479
1741
|
this.classList.add("c-brush");
|
|
1742
|
+
this.setAttribute("role", "group");
|
|
1743
|
+
this.setAttribute("aria-label", "Brush selection");
|
|
1480
1744
|
wireStates(this);
|
|
1481
1745
|
loadRemote(this, []);
|
|
1482
1746
|
if (renderStates(this, "brush")) return;
|
|
@@ -1502,20 +1766,85 @@ class ContourBrush extends ContourBase {
|
|
|
1502
1766
|
enhance() {
|
|
1503
1767
|
if (this._wiredBrush) return;
|
|
1504
1768
|
this._wiredBrush = true;
|
|
1769
|
+
let dragging = null;
|
|
1770
|
+
const min = () => parseFloat(this.getAttribute("min") || "0");
|
|
1771
|
+
const max = () => parseFloat(this.getAttribute("max") || "100");
|
|
1772
|
+
const toValue = (clientX) => {
|
|
1773
|
+
const r = this.getBoundingClientRect();
|
|
1774
|
+
const ratio = Math.max(0, Math.min(1, (clientX - r.left) / (r.width || 1)));
|
|
1775
|
+
return min() + ratio * (max() - min());
|
|
1776
|
+
};
|
|
1505
1777
|
this.addEventListener("pointerdown", (e) => {
|
|
1778
|
+
const handle = e.target && e.target.classList && e.target.classList.contains("c-brush__handle") ? e.target : null;
|
|
1779
|
+
dragging = handle ? (handle.classList.contains("c-brush__handle--start") ? "start" : "end") : "move";
|
|
1780
|
+
try { this.setPointerCapture(e.pointerId); } catch (err) {}
|
|
1506
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") } }));
|
|
1507
1782
|
});
|
|
1783
|
+
this.addEventListener("pointermove", (e) => {
|
|
1784
|
+
if (!dragging) return;
|
|
1785
|
+
const v = toValue(e.clientX);
|
|
1786
|
+
const mn = min(), mx = max(), range = mx - mn || 1;
|
|
1787
|
+
const sel = this.querySelector(".c-brush__selection");
|
|
1788
|
+
let ns = parseFloat(this.getAttribute("start") || "0");
|
|
1789
|
+
let ne = parseFloat(this.getAttribute("end") || "100");
|
|
1790
|
+
if (dragging === "start") {
|
|
1791
|
+
ns = Math.min(v, ne);
|
|
1792
|
+
} else if (dragging === "end") {
|
|
1793
|
+
ne = Math.max(v, ns);
|
|
1794
|
+
} else {
|
|
1795
|
+
const width = ne - ns;
|
|
1796
|
+
ns = v - width / 2;
|
|
1797
|
+
ne = v + width / 2;
|
|
1798
|
+
if (ns < mn) { ne += mn - ns; ns = mn; }
|
|
1799
|
+
if (ne > mx) { ns -= ne - mx; ne = mx; }
|
|
1800
|
+
}
|
|
1801
|
+
ns = Math.max(mn, Math.min(mx, ns));
|
|
1802
|
+
ne = Math.max(mn, Math.min(mx, ne));
|
|
1803
|
+
// update DOM directly to avoid re-render during drag
|
|
1804
|
+
if (sel) {
|
|
1805
|
+
sel.style.insetInlineStart = (((ns - mn) / range) * 100) + "%";
|
|
1806
|
+
sel.style.inlineSize = (((ne - ns) / range) * 100) + "%";
|
|
1807
|
+
}
|
|
1808
|
+
const sh = this.querySelector(".c-brush__handle--start");
|
|
1809
|
+
const eh = this.querySelector(".c-brush__handle--end");
|
|
1810
|
+
if (sh) sh.style.insetInlineStart = (((ns - mn) / range) * 100) + "%";
|
|
1811
|
+
if (eh) eh.style.insetInlineStart = (((ne - mn) / range) * 100) + "%";
|
|
1812
|
+
// stash pending values
|
|
1813
|
+
this._brushPending = { start: ns, end: ne };
|
|
1814
|
+
});
|
|
1508
1815
|
this.addEventListener("pointerup", (e) => {
|
|
1816
|
+
if (!dragging) return;
|
|
1817
|
+
dragging = null;
|
|
1818
|
+
const p = this._brushPending;
|
|
1819
|
+
if (p) {
|
|
1820
|
+
this.setAttribute("start", String(p.start));
|
|
1821
|
+
this.setAttribute("end", String(p.end));
|
|
1822
|
+
this._brushPending = null;
|
|
1823
|
+
}
|
|
1509
1824
|
this.dispatchEvent(new CustomEvent("contour:brush-end", { bubbles: true, composed: true, detail: { value: this.getAttribute("end"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
|
|
1510
1825
|
});
|
|
1826
|
+
// Keyboard: Enter/Space emits brush-start/brush-end (WC-P1-08).
|
|
1827
|
+
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
1828
|
+
this.addEventListener("keydown", (e) => {
|
|
1829
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
1830
|
+
e.preventDefault();
|
|
1831
|
+
this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: { value: this.getAttribute("start"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
|
|
1832
|
+
}
|
|
1833
|
+
});
|
|
1511
1834
|
}
|
|
1512
1835
|
}
|
|
1513
1836
|
define("contour-brush", ContourBrush);
|
|
1837
|
+
/**
|
|
1838
|
+
* Stacked Bar: web component wrapper.
|
|
1839
|
+
* Attributes: `segments`, `values`, `colors`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `normalize`.
|
|
1840
|
+
*/
|
|
1514
1841
|
class ContourStackedBar extends ContourBase {
|
|
1515
1842
|
static get observed() { return ["segments", "values", "colors", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "normalize"]; }
|
|
1516
1843
|
static get properties() { return { segments: { attribute: "segments" }, values: { attribute: "values" }, colors: { attribute: "colors" }, src: { attribute: "src" }, normalize: { attribute: "normalize" } }; }
|
|
1517
1844
|
render() {
|
|
1518
1845
|
this.classList.add("c-stacked-bar");
|
|
1846
|
+
this.setAttribute("role", "img");
|
|
1847
|
+
this.setAttribute("aria-label", "Stacked bar");
|
|
1519
1848
|
wireStates(this);
|
|
1520
1849
|
loadRemote(this, ["segments", "values"]);
|
|
1521
1850
|
if (renderStates(this, "stacked-bar")) return;
|
|
@@ -1553,12 +1882,17 @@ class ContourStackedBar extends ContourBase {
|
|
|
1553
1882
|
enhance() {}
|
|
1554
1883
|
}
|
|
1555
1884
|
define("contour-stacked-bar", ContourStackedBar);
|
|
1885
|
+
/**
|
|
1886
|
+
* Category: web component wrapper.
|
|
1887
|
+
* Attributes: `items`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `search`.
|
|
1888
|
+
*/
|
|
1556
1889
|
class ContourCategory extends ContourBase {
|
|
1557
|
-
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "search"]; }
|
|
1558
|
-
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, search: { attribute: "search" } }; }
|
|
1890
|
+
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "search", "note", "limit", "sort"]; }
|
|
1891
|
+
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, search: { attribute: "search" }, note: { attribute: "note" }, limit: { attribute: "limit" }, sort: { attribute: "sort" } }; }
|
|
1559
1892
|
render() {
|
|
1560
1893
|
this.classList.add("c-category");
|
|
1561
1894
|
this.setAttribute("role", "listbox");
|
|
1895
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Category");
|
|
1562
1896
|
wireStates(this);
|
|
1563
1897
|
loadRemote(this, ["items"]);
|
|
1564
1898
|
if (renderStates(this, "category")) return;
|
|
@@ -1577,6 +1911,20 @@ class ContourCategory extends ContourBase {
|
|
|
1577
1911
|
const iAttr = this.getAttribute("items");
|
|
1578
1912
|
if (iAttr) { try { items = JSON.parse(iAttr); } catch (e) { items = []; } }
|
|
1579
1913
|
}
|
|
1914
|
+
// Top-N + sort (CARTO-inspired): optional `limit` and `sort` attributes.
|
|
1915
|
+
const sort = this.getAttribute("sort") || "value-desc";
|
|
1916
|
+
items.sort((a, b) => {
|
|
1917
|
+
const va = (typeof a === "object") ? (a.value || 0) : (Number(a) || 0);
|
|
1918
|
+
const vb = (typeof b === "object") ? (b.value || 0) : (Number(b) || 0);
|
|
1919
|
+
const la = (typeof a === "object") ? (a.label || a.name || "") : String(a);
|
|
1920
|
+
const lb = (typeof b === "object") ? (b.label || b.name || "") : String(b);
|
|
1921
|
+
if (sort === "value-asc") return va - vb;
|
|
1922
|
+
if (sort === "alpha-asc") return String(la).localeCompare(String(lb));
|
|
1923
|
+
if (sort === "alpha-desc") return String(lb).localeCompare(String(la));
|
|
1924
|
+
return vb - va; // value-desc (default)
|
|
1925
|
+
});
|
|
1926
|
+
const limit = parseInt(this.getAttribute("limit") || "0", 10);
|
|
1927
|
+
if (limit > 0) items = items.slice(0, limit);
|
|
1580
1928
|
const max = items.reduce((m, it) => Math.max(m, (typeof it === "object" ? (it.value || 0) : Number(it) || 0)), 0) || 1;
|
|
1581
1929
|
items.forEach((it, idx) => {
|
|
1582
1930
|
const value = (typeof it === "object") ? (it.value || 0) : (Number(it) || 0);
|
|
@@ -1585,6 +1933,7 @@ class ContourCategory extends ContourBase {
|
|
|
1585
1933
|
item.className = "c-category__item";
|
|
1586
1934
|
item.setAttribute("role", "option");
|
|
1587
1935
|
item.setAttribute("aria-selected", "false");
|
|
1936
|
+
item.setAttribute("tabindex", idx === 0 ? "0" : "-1");
|
|
1588
1937
|
const lbl = document.createElement("span");
|
|
1589
1938
|
lbl.className = "c-category__label";
|
|
1590
1939
|
lbl.textContent = label;
|
|
@@ -1603,15 +1952,66 @@ class ContourCategory extends ContourBase {
|
|
|
1603
1952
|
this.appendChild(item);
|
|
1604
1953
|
});
|
|
1605
1954
|
if (!items.length) renderEmpty(this, "category");
|
|
1955
|
+
const note = this.getAttribute("note");
|
|
1956
|
+
let noteEl = this.querySelector(".c-category__note");
|
|
1957
|
+
if (note) {
|
|
1958
|
+
if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-category__note"; this.appendChild(noteEl); }
|
|
1959
|
+
noteEl.textContent = note;
|
|
1960
|
+
} else if (noteEl) {
|
|
1961
|
+
noteEl.remove();
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
enhance() {
|
|
1965
|
+
if (this._wiredCategory) return;
|
|
1966
|
+
this._wiredCategory = true;
|
|
1967
|
+
const items = () => Array.from(this.querySelectorAll(".c-category__item"));
|
|
1968
|
+
const showTip = (e) => {};
|
|
1969
|
+
this.addEventListener("click", (e) => {
|
|
1970
|
+
const item = e.target && e.target.closest ? e.target.closest(".c-category__item") : null;
|
|
1971
|
+
if (!item || !this.contains(item)) return;
|
|
1972
|
+
const all = items();
|
|
1973
|
+
const idx = all.indexOf(item);
|
|
1974
|
+
all.forEach((o, i) => o.setAttribute("aria-selected", i === idx ? "true" : "false"));
|
|
1975
|
+
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() } }));
|
|
1976
|
+
});
|
|
1977
|
+
this.addEventListener("keydown", (e) => {
|
|
1978
|
+
const item = e.target && e.target.closest ? e.target.closest(".c-category__item") : null;
|
|
1979
|
+
if (!item || !this.contains(item)) return;
|
|
1980
|
+
const all = items();
|
|
1981
|
+
const idx = all.indexOf(item);
|
|
1982
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
1983
|
+
e.preventDefault();
|
|
1984
|
+
all.forEach((o, i) => o.setAttribute("aria-selected", i === idx ? "true" : "false"));
|
|
1985
|
+
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() } }));
|
|
1986
|
+
return;
|
|
1987
|
+
}
|
|
1988
|
+
let next = -1;
|
|
1989
|
+
const rtl = (this.getAttribute("dir") || document.documentElement.getAttribute("dir") || "").toLowerCase() === "rtl";
|
|
1990
|
+
if (e.key === "ArrowDown") next = Math.min(idx + 1, all.length - 1);
|
|
1991
|
+
else if (e.key === "ArrowUp") next = Math.max(idx - 1, 0);
|
|
1992
|
+
else if (e.key === "ArrowRight") next = rtl ? Math.max(idx - 1, 0) : Math.min(idx + 1, all.length - 1);
|
|
1993
|
+
else if (e.key === "ArrowLeft") next = rtl ? Math.min(idx + 1, all.length - 1) : Math.max(idx - 1, 0);
|
|
1994
|
+
else if (e.key === "Home") next = 0;
|
|
1995
|
+
else if (e.key === "End") next = all.length - 1;
|
|
1996
|
+
if (next < 0 || next === idx) return;
|
|
1997
|
+
e.preventDefault();
|
|
1998
|
+
all.forEach((c, i) => c.setAttribute("tabindex", i === next ? "0" : "-1"));
|
|
1999
|
+
try { all[next].focus(); } catch (err) {}
|
|
2000
|
+
});
|
|
1606
2001
|
}
|
|
1607
|
-
enhance() {}
|
|
1608
2002
|
}
|
|
1609
2003
|
define("contour-category", ContourCategory);
|
|
2004
|
+
/**
|
|
2005
|
+
* Donut: web component wrapper.
|
|
2006
|
+
* Attributes: `value`, `values`, `items`, `label`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `brownout`, `brownout-level`.
|
|
2007
|
+
*/
|
|
1610
2008
|
class ContourDonut extends ContourBase {
|
|
1611
|
-
static get observed() { return ["value", "values", "items", "label", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level"]; }
|
|
1612
|
-
static get properties() { return { value: { attribute: "value" }, values: { attribute: "values" }, items: { attribute: "items" }, label: { attribute: "label" }, src: { attribute: "src" } }; }
|
|
2009
|
+
static get observed() { return ["value", "values", "items", "label", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level", "note"]; }
|
|
2010
|
+
static get properties() { return { value: { attribute: "value" }, values: { attribute: "values" }, items: { attribute: "items" }, label: { attribute: "label" }, src: { attribute: "src" }, note: { attribute: "note" } }; }
|
|
1613
2011
|
render() {
|
|
1614
2012
|
this.classList.add("c-donut");
|
|
2013
|
+
this.setAttribute("role", "img");
|
|
2014
|
+
this.setAttribute("aria-label", "Donut chart");
|
|
1615
2015
|
wireStates(this);
|
|
1616
2016
|
loadRemote(this, ["items", "values"]);
|
|
1617
2017
|
if (renderStates(this, "donut")) return;
|
|
@@ -1687,15 +2087,29 @@ class ContourDonut extends ContourBase {
|
|
|
1687
2087
|
});
|
|
1688
2088
|
this.appendChild(list);
|
|
1689
2089
|
if (!items.length) renderEmpty(this, "donut");
|
|
2090
|
+
const note = this.getAttribute("note");
|
|
2091
|
+
let noteEl = this.querySelector(".c-donut__note");
|
|
2092
|
+
if (note) {
|
|
2093
|
+
if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-donut__note"; this.appendChild(noteEl); }
|
|
2094
|
+
noteEl.textContent = note;
|
|
2095
|
+
} else if (noteEl) {
|
|
2096
|
+
noteEl.remove();
|
|
2097
|
+
}
|
|
1690
2098
|
}
|
|
1691
2099
|
enhance() {}
|
|
1692
2100
|
}
|
|
1693
2101
|
define("contour-donut", ContourDonut);
|
|
2102
|
+
/**
|
|
2103
|
+
* Time Series: web component wrapper.
|
|
2104
|
+
* Attributes: `values`, `points`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `annotations`.
|
|
2105
|
+
*/
|
|
1694
2106
|
class ContourTimeSeries extends ContourBase {
|
|
1695
|
-
static get observed() { return ["values", "points", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "annotations"]; }
|
|
1696
|
-
static get properties() { return { values: { attribute: "values" }, points: { attribute: "points" }, src: { attribute: "src" }, annotations: { attribute: "annotations" } }; }
|
|
2107
|
+
static get observed() { return ["values", "points", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "annotations", "note", "style"]; }
|
|
2108
|
+
static get properties() { return { values: { attribute: "values" }, points: { attribute: "points" }, src: { attribute: "src" }, annotations: { attribute: "annotations" }, note: { attribute: "note" }, style: { attribute: "style" } }; }
|
|
1697
2109
|
render() {
|
|
1698
2110
|
this.classList.add("c-time-series");
|
|
2111
|
+
this.setAttribute("role", "img");
|
|
2112
|
+
this.setAttribute("aria-label", "Time series");
|
|
1699
2113
|
wireStates(this);
|
|
1700
2114
|
loadRemote(this, ["values", "points"]);
|
|
1701
2115
|
if (renderStates(this, "time-series")) return;
|
|
@@ -1704,66 +2118,278 @@ class ContourTimeSeries extends ContourBase {
|
|
|
1704
2118
|
const vAttr = this.getAttribute("values");
|
|
1705
2119
|
if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map(Number); } }
|
|
1706
2120
|
const max = Math.max(...values, 1);
|
|
2121
|
+
const min = Math.min(...values, 0);
|
|
2122
|
+
const style = this.getAttribute("style") || "bar";
|
|
1707
2123
|
const plot = document.createElement("div");
|
|
1708
2124
|
plot.className = "c-time-series__plot";
|
|
1709
2125
|
plot.setAttribute("part", "plot");
|
|
1710
|
-
|
|
1711
|
-
const
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
2126
|
+
if (style === "line") {
|
|
2127
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
2128
|
+
svg.setAttribute("viewBox", "0 0 300 120");
|
|
2129
|
+
svg.setAttribute("preserveAspectRatio", "none");
|
|
2130
|
+
svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
|
|
2131
|
+
const range = (max - min) || 1;
|
|
2132
|
+
const n = values.length || 1;
|
|
2133
|
+
const pts = values.map((v, i) => {
|
|
2134
|
+
const x = (i / Math.max(1, n - 1)) * 300;
|
|
2135
|
+
const y = 120 - ((v - min) / range) * 120;
|
|
2136
|
+
return x.toFixed(2) + "," + y.toFixed(2);
|
|
2137
|
+
}).join(" ");
|
|
2138
|
+
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
2139
|
+
path.setAttribute("class", "c-time-series__line");
|
|
2140
|
+
path.setAttribute("d", "M " + pts.replace(/ /g, " L "));
|
|
2141
|
+
path.style.stroke = "var(--chart-1)";
|
|
2142
|
+
path.style.fill = "none";
|
|
2143
|
+
path.style.strokeWidth = "2";
|
|
2144
|
+
svg.appendChild(path);
|
|
2145
|
+
// point markers
|
|
2146
|
+
values.forEach((v, i) => {
|
|
2147
|
+
const x = (i / Math.max(1, n - 1)) * 300;
|
|
2148
|
+
const y = 120 - ((v - min) / range) * 120;
|
|
2149
|
+
const c = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
2150
|
+
c.setAttribute("class", "c-time-series__point");
|
|
2151
|
+
c.setAttribute("cx", x.toFixed(2));
|
|
2152
|
+
c.setAttribute("cy", y.toFixed(2));
|
|
2153
|
+
c.setAttribute("r", "3");
|
|
2154
|
+
c.setAttribute("tabindex", i === 0 ? "0" : "-1");
|
|
2155
|
+
c.setAttribute("role", "button");
|
|
2156
|
+
c.setAttribute("title", String(v));
|
|
2157
|
+
c.setAttribute("aria-label", "Value " + v);
|
|
2158
|
+
svg.appendChild(c);
|
|
2159
|
+
});
|
|
2160
|
+
plot.appendChild(svg);
|
|
2161
|
+
} else {
|
|
2162
|
+
values.forEach((v, i) => {
|
|
2163
|
+
const bar = document.createElement("div");
|
|
2164
|
+
bar.className = "c-time-series__bar";
|
|
2165
|
+
bar.style.blockSize = ((v / max) * 100) + "%";
|
|
2166
|
+
bar.setAttribute("title", String(v));
|
|
2167
|
+
bar.setAttribute("role", "img");
|
|
2168
|
+
bar.setAttribute("aria-label", "Value " + v);
|
|
2169
|
+
bar.setAttribute("tabindex", i === 0 ? "0" : "-1");
|
|
2170
|
+
plot.appendChild(bar);
|
|
2171
|
+
});
|
|
2172
|
+
}
|
|
1717
2173
|
this.appendChild(plot);
|
|
1718
2174
|
if (!values.length) renderEmpty(this, "time-series");
|
|
2175
|
+
const note = this.getAttribute("note");
|
|
2176
|
+
let noteEl = this.querySelector(".c-time-series__note");
|
|
2177
|
+
if (note) {
|
|
2178
|
+
if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-time-series__note"; this.appendChild(noteEl); }
|
|
2179
|
+
noteEl.textContent = note;
|
|
2180
|
+
} else if (noteEl) {
|
|
2181
|
+
noteEl.remove();
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
enhance() {
|
|
2185
|
+
if (this._wiredTimeSeries) return;
|
|
2186
|
+
this._wiredTimeSeries = true;
|
|
2187
|
+
const bars = () => Array.from(this.querySelectorAll(".c-time-series__bar"));
|
|
2188
|
+
this.addEventListener("click", (e) => {
|
|
2189
|
+
const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
|
|
2190
|
+
if (!bar || !this.contains(bar)) return;
|
|
2191
|
+
const idx = bars().indexOf(bar);
|
|
2192
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx, value: bar.getAttribute("title") } }));
|
|
2193
|
+
});
|
|
2194
|
+
this.addEventListener("keydown", (e) => {
|
|
2195
|
+
const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
|
|
2196
|
+
if (!bar || !this.contains(bar)) return;
|
|
2197
|
+
const all = bars();
|
|
2198
|
+
const idx = all.indexOf(bar);
|
|
2199
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
2200
|
+
e.preventDefault();
|
|
2201
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx, value: bar.getAttribute("title") } }));
|
|
2202
|
+
return;
|
|
2203
|
+
}
|
|
2204
|
+
let next = -1;
|
|
2205
|
+
if (e.key === "ArrowRight" || e.key === "ArrowDown") next = Math.min(idx + 1, all.length - 1);
|
|
2206
|
+
else if (e.key === "ArrowLeft" || e.key === "ArrowUp") next = Math.max(idx - 1, 0);
|
|
2207
|
+
else if (e.key === "Home") next = 0;
|
|
2208
|
+
else if (e.key === "End") next = all.length - 1;
|
|
2209
|
+
if (next < 0 || next === idx) return;
|
|
2210
|
+
e.preventDefault();
|
|
2211
|
+
all.forEach((b, i) => b.setAttribute("tabindex", i === next ? "0" : "-1"));
|
|
2212
|
+
try { all[next].focus(); } catch (err) {}
|
|
2213
|
+
});
|
|
2214
|
+
// focus tooltip
|
|
2215
|
+
this.addEventListener("focusin", (e) => {
|
|
2216
|
+
const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
|
|
2217
|
+
if (bar && this.contains(bar)) {
|
|
2218
|
+
const tip = this.querySelector(".c-time-series__tooltip");
|
|
2219
|
+
if (tip) { tip.textContent = bar.getAttribute("title"); tip.removeAttribute("hidden"); }
|
|
2220
|
+
}
|
|
2221
|
+
});
|
|
2222
|
+
this.addEventListener("focusout", (e) => {
|
|
2223
|
+
const tip = this.querySelector(".c-time-series__tooltip");
|
|
2224
|
+
if (tip && !this.contains(e.relatedTarget)) tip.setAttribute("hidden", "");
|
|
2225
|
+
});
|
|
1719
2226
|
}
|
|
1720
|
-
enhance() {}
|
|
1721
2227
|
}
|
|
1722
2228
|
define("contour-time-series", ContourTimeSeries);
|
|
2229
|
+
/**
|
|
2230
|
+
* Pivot: web component wrapper.
|
|
2231
|
+
* Attributes: `rows`, `columns`, `values`, `data`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
2232
|
+
*/
|
|
1723
2233
|
class ContourPivot extends ContourBase {
|
|
1724
2234
|
static get observed() { return ["rows", "columns", "values", "data", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1725
|
-
static get properties() { return { rows: { attribute: "rows" }, columns: { attribute: "columns" }, values: { attribute: "values" }, data: { attribute: "data" }, src: { attribute: "src" } }; }
|
|
2235
|
+
static get properties() { return { rows: { attribute: "rows" }, columns: { attribute: "columns" }, values: { attribute: "values" }, data: { attribute: "data" }, src: { attribute: "src" }, filter: { attribute: "filter" }, aggregate: { attribute: "aggregate" } }; }
|
|
2236
|
+
_aggregateFn(name) {
|
|
2237
|
+
const n = (name || "sum").toLowerCase();
|
|
2238
|
+
if (n === "avg" || n === "average" || n === "mean") return (vals) => vals.length ? vals.reduce((a,b)=>a+b,0)/vals.length : 0;
|
|
2239
|
+
if (n === "count") return (vals) => vals.length;
|
|
2240
|
+
if (n === "min") return (vals) => vals.length ? Math.min(...vals) : 0;
|
|
2241
|
+
if (n === "max") return (vals) => vals.length ? Math.max(...vals) : 0;
|
|
2242
|
+
return (vals) => vals.reduce((a,b)=>a+b,0);
|
|
2243
|
+
}
|
|
1726
2244
|
render() {
|
|
1727
2245
|
this.classList.add("c-pivot");
|
|
1728
2246
|
wireStates(this);
|
|
1729
2247
|
loadRemote(this, ["data"]);
|
|
1730
2248
|
if (renderStates(this, "pivot")) return;
|
|
1731
|
-
Array.from(this.querySelectorAll("table")).forEach((n) => n.remove());
|
|
2249
|
+
Array.from(this.querySelectorAll("table, .c-pivot__toolbar")).forEach((n) => n.remove());
|
|
1732
2250
|
let data = [];
|
|
1733
2251
|
const dAttr = this.getAttribute("data");
|
|
1734
2252
|
if (dAttr) { try { data = JSON.parse(dAttr); } catch (e) { data = []; } }
|
|
1735
|
-
const rows = this.getAttribute("rows") ? this.getAttribute("rows").split(",") : [];
|
|
1736
|
-
const cols = this.getAttribute("columns") ? this.getAttribute("columns").split(",") : [];
|
|
2253
|
+
const rows = this.getAttribute("rows") ? this.getAttribute("rows").split(",").map((s)=>s.trim()).filter(Boolean) : [];
|
|
2254
|
+
const cols = this.getAttribute("columns") ? this.getAttribute("columns").split(",").map((s)=>s.trim()).filter(Boolean) : [];
|
|
2255
|
+
const aggName = this.getAttribute("aggregate") || "sum";
|
|
2256
|
+
const aggFn = this._aggregateFn(aggName);
|
|
2257
|
+
const filterQ = (this.getAttribute("filter") || "").toLowerCase().trim();
|
|
2258
|
+
// Toolbar: filter input + aggregate selector.
|
|
2259
|
+
const toolbar = document.createElement("div");
|
|
2260
|
+
toolbar.className = "c-pivot__toolbar";
|
|
2261
|
+
toolbar.style.display = "flex";
|
|
2262
|
+
toolbar.style.gap = "0.5rem";
|
|
2263
|
+
toolbar.style.marginBlockEnd = "0.5rem";
|
|
2264
|
+
const filterInput = document.createElement("input");
|
|
2265
|
+
filterInput.type = "search";
|
|
2266
|
+
filterInput.className = "c-input c-pivot__filter";
|
|
2267
|
+
filterInput.placeholder = "Filter…";
|
|
2268
|
+
filterInput.value = this.getAttribute("filter") || "";
|
|
2269
|
+
filterInput.setAttribute("aria-label", "Filter pivot");
|
|
2270
|
+
const aggSelect = document.createElement("select");
|
|
2271
|
+
aggSelect.className = "c-select c-pivot__aggregate";
|
|
2272
|
+
aggSelect.setAttribute("aria-label", "Aggregation");
|
|
2273
|
+
["sum","avg","count","min","max"].forEach((a) => {
|
|
2274
|
+
const opt = document.createElement("option");
|
|
2275
|
+
opt.value = a; opt.textContent = a;
|
|
2276
|
+
if (a === aggName) opt.selected = true;
|
|
2277
|
+
aggSelect.appendChild(opt);
|
|
2278
|
+
});
|
|
2279
|
+
toolbar.appendChild(filterInput);
|
|
2280
|
+
toolbar.appendChild(aggSelect);
|
|
2281
|
+
this.appendChild(toolbar);
|
|
2282
|
+
// Filter rows/cols.
|
|
2283
|
+
let visibleRows = rows;
|
|
2284
|
+
let visibleCols = cols;
|
|
2285
|
+
if (filterQ) {
|
|
2286
|
+
visibleRows = rows.filter((r) => r.toLowerCase().includes(filterQ) || data.some((d) => d.row === r && String(d.value).toLowerCase().includes(filterQ)));
|
|
2287
|
+
visibleCols = cols.filter((c) => c.toLowerCase().includes(filterQ) || data.some((d) => d.col === c && String(d.value).toLowerCase().includes(filterQ)));
|
|
2288
|
+
if (!visibleRows.length) visibleRows = rows;
|
|
2289
|
+
if (!visibleCols.length) visibleCols = cols;
|
|
2290
|
+
}
|
|
1737
2291
|
const table = document.createElement("table");
|
|
2292
|
+
table.setAttribute("role", "grid");
|
|
2293
|
+
table.setAttribute("aria-rowcount", String(visibleRows.length + 1));
|
|
2294
|
+
table.setAttribute("aria-colcount", String(visibleCols.length + 1));
|
|
1738
2295
|
const thead = document.createElement("thead");
|
|
1739
2296
|
const hr = document.createElement("tr");
|
|
1740
2297
|
const corner = document.createElement("th");
|
|
1741
2298
|
corner.textContent = "";
|
|
2299
|
+
corner.setAttribute("role", "columnheader");
|
|
1742
2300
|
hr.appendChild(corner);
|
|
1743
|
-
|
|
2301
|
+
visibleCols.forEach((c) => { const th = document.createElement("th"); th.textContent = c; th.setAttribute("role", "columnheader"); th.setAttribute("tabindex", "0"); hr.appendChild(th); });
|
|
1744
2302
|
thead.appendChild(hr);
|
|
1745
2303
|
table.appendChild(thead);
|
|
1746
2304
|
const tbody = document.createElement("tbody");
|
|
1747
|
-
|
|
2305
|
+
visibleRows.forEach((r) => {
|
|
1748
2306
|
const tr = document.createElement("tr");
|
|
2307
|
+
tr.setAttribute("role", "row");
|
|
1749
2308
|
const th = document.createElement("th");
|
|
1750
|
-
th.textContent = r
|
|
2309
|
+
th.textContent = r;
|
|
2310
|
+
th.setAttribute("role", "rowheader");
|
|
2311
|
+
th.setAttribute("tabindex", "0");
|
|
1751
2312
|
tr.appendChild(th);
|
|
1752
|
-
|
|
2313
|
+
visibleCols.forEach((c) => {
|
|
1753
2314
|
const td = document.createElement("td");
|
|
1754
|
-
|
|
1755
|
-
td.
|
|
2315
|
+
td.setAttribute("role", "gridcell");
|
|
2316
|
+
td.setAttribute("tabindex", "0");
|
|
2317
|
+
const cellData = data.filter((d) => d.row === r && d.col === c);
|
|
2318
|
+
const vals = cellData.map((d) => Number(d.value)).filter((n) => Number.isFinite(n));
|
|
2319
|
+
if (cellData.length && vals.length === cellData.length && vals.length) {
|
|
2320
|
+
const v = aggFn(vals);
|
|
2321
|
+
td.textContent = Number.isInteger(v) ? String(v) : v.toFixed(2);
|
|
2322
|
+
} else if (cellData.length) {
|
|
2323
|
+
td.textContent = cellData.map((d) => d.value).join(", ");
|
|
2324
|
+
} else {
|
|
2325
|
+
td.textContent = "";
|
|
2326
|
+
}
|
|
1756
2327
|
tr.appendChild(td);
|
|
1757
2328
|
});
|
|
1758
2329
|
tbody.appendChild(tr);
|
|
1759
2330
|
});
|
|
1760
2331
|
table.appendChild(tbody);
|
|
1761
2332
|
this.appendChild(table);
|
|
1762
|
-
if (!data.length && !rows.length) renderEmpty(this, "pivot");
|
|
2333
|
+
if (!data.length && !rows.length && !cols.length) renderEmpty(this, "pivot");
|
|
2334
|
+
}
|
|
2335
|
+
enhance() {
|
|
2336
|
+
if (this._wiredPivot) return;
|
|
2337
|
+
this._wiredPivot = true;
|
|
2338
|
+
this.addEventListener("click", (e) => {
|
|
2339
|
+
const th = e.target && e.target.closest ? e.target.closest("th") : null;
|
|
2340
|
+
const td = e.target && e.target.closest ? e.target.closest("td") : null;
|
|
2341
|
+
const filterInput = e.target && e.target.closest ? e.target.closest(".c-pivot__filter") : null;
|
|
2342
|
+
const aggSelect = e.target && e.target.closest ? e.target.closest(".c-pivot__aggregate") : null;
|
|
2343
|
+
if (filterInput) return;
|
|
2344
|
+
if (aggSelect) return;
|
|
2345
|
+
if (th && this.contains(th) && th.parentElement && th.parentElement.parentElement && th.parentElement.parentElement.tagName === "THEAD") {
|
|
2346
|
+
this.dispatchEvent(new CustomEvent("contour:sort", { bubbles: true, composed: true, detail: { column: th.textContent.trim() } }));
|
|
2347
|
+
return;
|
|
2348
|
+
}
|
|
2349
|
+
if (td && this.contains(td)) {
|
|
2350
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { value: td.textContent } }));
|
|
2351
|
+
}
|
|
2352
|
+
});
|
|
2353
|
+
this.addEventListener("input", (e) => {
|
|
2354
|
+
const fi = e.target && e.target.closest ? e.target.closest(".c-pivot__filter") : null;
|
|
2355
|
+
if (fi && this.contains(fi)) {
|
|
2356
|
+
this.setAttribute("filter", fi.value);
|
|
2357
|
+
this.render();
|
|
2358
|
+
this.dispatchEvent(new CustomEvent("contour:filter", { bubbles: true, composed: true, detail: { query: fi.value } }));
|
|
2359
|
+
}
|
|
2360
|
+
});
|
|
2361
|
+
this.addEventListener("change", (e) => {
|
|
2362
|
+
const as = e.target && e.target.closest ? e.target.closest(".c-pivot__aggregate") : null;
|
|
2363
|
+
if (as && this.contains(as)) {
|
|
2364
|
+
this.setAttribute("aggregate", as.value);
|
|
2365
|
+
this.render();
|
|
2366
|
+
this.dispatchEvent(new CustomEvent("contour:aggregate", { bubbles: true, composed: true, detail: { aggregate: as.value } }));
|
|
2367
|
+
}
|
|
2368
|
+
});
|
|
2369
|
+
this.addEventListener("keydown", (e) => {
|
|
2370
|
+
const cell = e.target && e.target.closest ? e.target.closest("th, td") : null;
|
|
2371
|
+
if (!cell || !this.contains(cell)) return;
|
|
2372
|
+
const table = this.querySelector("table");
|
|
2373
|
+
if (!table) return;
|
|
2374
|
+
const rows = Array.from(table.querySelectorAll("tr"));
|
|
2375
|
+
const ri = rows.indexOf(cell.parentElement);
|
|
2376
|
+
const ci = Array.from(cell.parentElement.children).indexOf(cell);
|
|
2377
|
+
let target = null;
|
|
2378
|
+
if (e.key === "ArrowRight") target = cell.parentElement.children[ci + 1];
|
|
2379
|
+
else if (e.key === "ArrowLeft") target = cell.parentElement.children[ci - 1];
|
|
2380
|
+
else if (e.key === "ArrowDown") target = rows[ri + 1] && rows[ri + 1].children[ci];
|
|
2381
|
+
else if (e.key === "ArrowUp") target = rows[ri - 1] && rows[ri - 1].children[ci];
|
|
2382
|
+
else if (e.key === "Home") target = cell.parentElement.children[0];
|
|
2383
|
+
else if (e.key === "End") target = cell.parentElement.children[cell.parentElement.children.length - 1];
|
|
2384
|
+
if (target) { e.preventDefault(); try { target.focus(); } catch (err) {} }
|
|
2385
|
+
});
|
|
1763
2386
|
}
|
|
1764
|
-
enhance() {}
|
|
1765
2387
|
}
|
|
1766
2388
|
define("contour-pivot", ContourPivot);
|
|
2389
|
+
/**
|
|
2390
|
+
* Widget State: web component wrapper.
|
|
2391
|
+
* Attributes: `loading`, `error`, `empty`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
2392
|
+
*/
|
|
1767
2393
|
class ContourWidgetState extends ContourBase {
|
|
1768
2394
|
static get observed() { return ["loading", "error", "empty", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1769
2395
|
static get properties() { return { loading: { attribute: "loading" }, error: { attribute: "error" }, empty: { attribute: "empty" }, retry: { attribute: "retry" }, src: { attribute: "src" } }; }
|
|
@@ -1777,6 +2403,10 @@ class ContourWidgetState extends ContourBase {
|
|
|
1777
2403
|
enhance() {}
|
|
1778
2404
|
}
|
|
1779
2405
|
define("contour-widget-state", ContourWidgetState);
|
|
2406
|
+
/**
|
|
2407
|
+
* Brownout: web component wrapper.
|
|
2408
|
+
* Attributes: `level`.
|
|
2409
|
+
*/
|
|
1780
2410
|
class ContourBrownout extends ContourBase {
|
|
1781
2411
|
static get observed() { return ["level"]; }
|
|
1782
2412
|
static get properties() { return { level: { attribute: "level" } }; }
|
|
@@ -1789,6 +2419,10 @@ class ContourBrownout extends ContourBase {
|
|
|
1789
2419
|
enhance() {}
|
|
1790
2420
|
}
|
|
1791
2421
|
define("contour-brownout", ContourBrownout);
|
|
2422
|
+
/**
|
|
2423
|
+
* Instrument: web component wrapper.
|
|
2424
|
+
* Attributes: `rows`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
2425
|
+
*/
|
|
1792
2426
|
class ContourInstrument extends ContourBase {
|
|
1793
2427
|
static get observed() { return ["rows", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1794
2428
|
static get properties() { return { rows: { attribute: "rows" }, src: { attribute: "src" } }; }
|
|
@@ -1822,11 +2456,17 @@ class ContourInstrument extends ContourBase {
|
|
|
1822
2456
|
}
|
|
1823
2457
|
}
|
|
1824
2458
|
define("contour-instrument", ContourInstrument);
|
|
2459
|
+
/**
|
|
2460
|
+
* Bivariate: web component wrapper.
|
|
2461
|
+
* Attributes: `size`, `axis-x`, `axis-y`, `colors`, `selected`.
|
|
2462
|
+
*/
|
|
1825
2463
|
class ContourBivariate extends ContourBase {
|
|
1826
2464
|
static get observed() { return ["size", "axis-x", "axis-y", "colors", "selected"]; }
|
|
1827
2465
|
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" }, selected: { attribute: "selected" } }; }
|
|
1828
2466
|
render() {
|
|
1829
2467
|
this.classList.add("c-bivariate");
|
|
2468
|
+
this.setAttribute("role", "group");
|
|
2469
|
+
this.setAttribute("aria-label", "Bivariate legend");
|
|
1830
2470
|
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
1831
2471
|
const matrix = this.ensure(".c-bivariate__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate__matrix"; return el; });
|
|
1832
2472
|
matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
|
|
@@ -1926,60 +2566,19 @@ class ContourBivariate extends ContourBase {
|
|
|
1926
2566
|
}
|
|
1927
2567
|
}
|
|
1928
2568
|
define("contour-bivariate", ContourBivariate);
|
|
1929
|
-
class ContourBivariateLegend extends
|
|
2569
|
+
class ContourBivariateLegend extends ContourBivariate {
|
|
1930
2570
|
static get observed() { return ["size", "axis-x", "axis-y", "colors", "selected"]; }
|
|
1931
2571
|
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" }, selected: { attribute: "selected" } }; }
|
|
1932
2572
|
render() {
|
|
2573
|
+
super.render();
|
|
1933
2574
|
this.classList.add("c-bivariate-legend");
|
|
1934
|
-
const size = Math.min(8, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
1935
|
-
const matrix = this.ensure(".c-bivariate-legend__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate-legend__matrix"; return el; });
|
|
1936
|
-
matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
|
|
1937
|
-
// Slotted content support: authored cells win over the generated grid.
|
|
1938
|
-
const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains("c-bivariate-legend__cell"));
|
|
1939
|
-
if (!authored.length) {
|
|
1940
|
-
matrix.innerHTML = "";
|
|
1941
|
-
let colors = [];
|
|
1942
|
-
const cAttr = this.getAttribute("colors");
|
|
1943
|
-
if (cAttr) { try { colors = JSON.parse(cAttr); } catch (e) { colors = []; } }
|
|
1944
|
-
for (let i = 0; i < size * size; i++) {
|
|
1945
|
-
const cell = document.createElement("div");
|
|
1946
|
-
cell.className = "c-bivariate-legend__cell";
|
|
1947
|
-
cell.setAttribute("role", "button");
|
|
1948
|
-
cell.setAttribute("tabindex", "0");
|
|
1949
|
-
const x = i % size;
|
|
1950
|
-
const y = Math.floor(i / size);
|
|
1951
|
-
cell.setAttribute("aria-label", "Cell " + x + "," + y);
|
|
1952
|
-
if (colors[i]) cell.style.background = colors[i];
|
|
1953
|
-
else cell.style.background = "var(--chart-" + ((i % 8) + 1) + ")";
|
|
1954
|
-
matrix.appendChild(cell);
|
|
1955
|
-
}
|
|
1956
|
-
// aria-live
|
|
1957
|
-
let live = this.querySelector(".c-bivariate-legend__live");
|
|
1958
|
-
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); }
|
|
1959
|
-
}
|
|
1960
|
-
const axisX = this.getAttribute("axis-x");
|
|
1961
|
-
const ax = this.querySelector(".c-bivariate-legend__axis--x");
|
|
1962
|
-
if (axisX) {
|
|
1963
|
-
const el = ax || this.ensure(".c-bivariate-legend__axis--x", () => { const e = document.createElement("div"); e.className = "c-bivariate-legend__axis c-bivariate-legend__axis--x"; return e; });
|
|
1964
|
-
el.textContent = axisX;
|
|
1965
|
-
} else if (ax) {
|
|
1966
|
-
ax.remove();
|
|
1967
|
-
}
|
|
1968
|
-
const axisY = this.getAttribute("axis-y");
|
|
1969
|
-
const ay = this.querySelector(".c-bivariate-legend__axis--y");
|
|
1970
|
-
if (axisY) {
|
|
1971
|
-
const el = ay || this.ensure(".c-bivariate-legend__axis--y", () => { const e = document.createElement("div"); e.className = "c-bivariate-legend__axis c-bivariate-legend__axis--y"; return e; });
|
|
1972
|
-
el.textContent = axisY;
|
|
1973
|
-
} else if (ay) {
|
|
1974
|
-
ay.remove();
|
|
1975
|
-
}
|
|
1976
2575
|
}
|
|
1977
2576
|
enhance() {
|
|
1978
2577
|
if (this._wiredBivLegend) return;
|
|
1979
2578
|
this._wiredBivLegend = true;
|
|
1980
2579
|
const selectCell = (cell) => {
|
|
1981
|
-
const matrix = this.querySelector(".c-
|
|
1982
|
-
const cells = Array.from(matrix ? matrix.querySelectorAll(".c-
|
|
2580
|
+
const matrix = this.querySelector(".c-bivariate__matrix");
|
|
2581
|
+
const cells = Array.from(matrix ? matrix.querySelectorAll(".c-bivariate__cell") : []);
|
|
1983
2582
|
const idx = cells.indexOf(cell);
|
|
1984
2583
|
if (idx < 0) return;
|
|
1985
2584
|
const size = Math.min(8, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
@@ -1994,11 +2593,11 @@ class ContourBivariateLegend extends ContourBase {
|
|
|
1994
2593
|
this.dispatchEvent(new CustomEvent("contour:select", { detail: { row, col }, bubbles: true, composed: true }));
|
|
1995
2594
|
};
|
|
1996
2595
|
this.addEventListener("click", (e) => {
|
|
1997
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-
|
|
2596
|
+
const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate__cell") : null;
|
|
1998
2597
|
if (cell && this.contains(cell)) selectCell(cell);
|
|
1999
2598
|
});
|
|
2000
2599
|
this.addEventListener("keydown", (e) => {
|
|
2001
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-
|
|
2600
|
+
const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate__cell") : null;
|
|
2002
2601
|
if (!cell || !this.contains(cell)) return;
|
|
2003
2602
|
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); selectCell(cell); }
|
|
2004
2603
|
});
|
|
@@ -2006,6 +2605,10 @@ class ContourBivariateLegend extends ContourBase {
|
|
|
2006
2605
|
clear() { this.removeAttribute("selected"); this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true })); }
|
|
2007
2606
|
}
|
|
2008
2607
|
define("contour-bivariate-legend", ContourBivariateLegend);
|
|
2608
|
+
/**
|
|
2609
|
+
* Survey: web component wrapper.
|
|
2610
|
+
* Attributes: `date`, `instrument`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
2611
|
+
*/
|
|
2009
2612
|
class ContourSurvey extends ContourBase {
|
|
2010
2613
|
static get observed() { return ["date", "instrument", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2011
2614
|
static get properties() { return { date: { attribute: "date" }, instrument: { attribute: "instrument" }, src: { attribute: "src" } }; }
|
|
@@ -2043,6 +2646,10 @@ class ContourSurvey extends ContourBase {
|
|
|
2043
2646
|
}
|
|
2044
2647
|
}
|
|
2045
2648
|
define("contour-survey", ContourSurvey);
|
|
2649
|
+
/**
|
|
2650
|
+
* Threshold: web component wrapper.
|
|
2651
|
+
* Attributes: `label`, `norm`, `state`, `value`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
2652
|
+
*/
|
|
2046
2653
|
class ContourThreshold extends ContourBase {
|
|
2047
2654
|
static get observed() { return ["label", "norm", "state", "value", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2048
2655
|
static get properties() { return { label: { attribute: "label" }, norm: { attribute: "norm" }, state: { attribute: "state" }, value: { attribute: "value" }, src: { attribute: "src" } }; }
|
|
@@ -2080,6 +2687,10 @@ class ContourThreshold extends ContourBase {
|
|
|
2080
2687
|
}
|
|
2081
2688
|
}
|
|
2082
2689
|
define("contour-threshold", ContourThreshold);
|
|
2690
|
+
/**
|
|
2691
|
+
* Metrics Full: web component wrapper.
|
|
2692
|
+
* Attributes: `items`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
2693
|
+
*/
|
|
2083
2694
|
class ContourMetricsFull extends ContourBase {
|
|
2084
2695
|
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2085
2696
|
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
@@ -2114,6 +2725,10 @@ class ContourMetricsFull extends ContourBase {
|
|
|
2114
2725
|
enhance() { wireStates(this); }
|
|
2115
2726
|
}
|
|
2116
2727
|
define("contour-metrics", ContourMetricsFull);
|
|
2728
|
+
/**
|
|
2729
|
+
* Legend: web component wrapper.
|
|
2730
|
+
* 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`.
|
|
2731
|
+
*/
|
|
2117
2732
|
class ContourLegend extends ContourBase {
|
|
2118
2733
|
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"]; }
|
|
2119
2734
|
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" } }; }
|
|
@@ -2126,7 +2741,18 @@ class ContourLegend extends ContourBase {
|
|
|
2126
2741
|
// aria-pressed, and the sheet's existing `.c-legend--interactive` rules
|
|
2127
2742
|
// (hover, dim when pressed=false) apply.
|
|
2128
2743
|
const selectable = this.hasAttribute("selectable");
|
|
2129
|
-
|
|
2744
|
+
// Slotted content support: authored .c-legend__item children take
|
|
2745
|
+
// precedence over the JSON `items` attribute.
|
|
2746
|
+
const authoredLegendItems = Array.from(this.querySelectorAll(":scope > .c-legend__item"));
|
|
2747
|
+
let items = remoteData(this, "items");
|
|
2748
|
+
if (authoredLegendItems.length) {
|
|
2749
|
+
items = JSON.stringify(authoredLegendItems.map((el) => {
|
|
2750
|
+
const sw = el.querySelector(".c-legend__swatch");
|
|
2751
|
+
const lbl = el.querySelector(".c-legend__label") || el;
|
|
2752
|
+
return { label: lbl ? lbl.textContent.trim() : el.textContent.trim(), color: sw ? sw.style.background || undefined : undefined };
|
|
2753
|
+
}));
|
|
2754
|
+
authoredLegendItems.forEach((el) => el.remove());
|
|
2755
|
+
}
|
|
2130
2756
|
const title = this.getAttribute("title");
|
|
2131
2757
|
if (title) {
|
|
2132
2758
|
const t = this.ensure(".c-legend__title", () => { const el = document.createElement("div"); el.className = "c-legend__title"; return el; });
|
|
@@ -2138,8 +2764,8 @@ class ContourLegend extends ContourBase {
|
|
|
2138
2764
|
if (items) {
|
|
2139
2765
|
try {
|
|
2140
2766
|
const parsed = JSON.parse(items);
|
|
2141
|
-
const list = this.ensure(".c-legend__items", () => { const el = document.createElement("div"); el.className = "c-legend__items";
|
|
2142
|
-
list.setAttribute("role", "listbox");
|
|
2767
|
+
const list = this.ensure(".c-legend__items", () => { const el = document.createElement("div"); el.className = "c-legend__items"; return el; });
|
|
2768
|
+
list.setAttribute("role", selectable ? "group" : "listbox");
|
|
2143
2769
|
if (title) list.setAttribute("aria-label", title);
|
|
2144
2770
|
list.innerHTML = "";
|
|
2145
2771
|
parsed.forEach((it) => {
|
|
@@ -2147,13 +2773,15 @@ class ContourLegend extends ContourBase {
|
|
|
2147
2773
|
const key = typeof it === "string" ? it : (it.key || it.label || String(it));
|
|
2148
2774
|
const item = document.createElement(selectable ? "button" : "div");
|
|
2149
2775
|
item.className = "c-legend__item";
|
|
2150
|
-
item.setAttribute("role", "option");
|
|
2151
|
-
item.setAttribute("aria-selected", "false");
|
|
2152
2776
|
item.setAttribute("tabindex", "-1");
|
|
2153
2777
|
if (selectable) {
|
|
2154
2778
|
item.type = "button";
|
|
2779
|
+
item.setAttribute("role", "button");
|
|
2155
2780
|
item.setAttribute("aria-pressed", "true");
|
|
2156
2781
|
item.dataset.key = key;
|
|
2782
|
+
} else {
|
|
2783
|
+
item.setAttribute("role", "option");
|
|
2784
|
+
item.setAttribute("aria-selected", "false");
|
|
2157
2785
|
}
|
|
2158
2786
|
const sw = document.createElement("span");
|
|
2159
2787
|
sw.className = "c-legend__swatch";
|
|
@@ -2368,7 +2996,6 @@ class ContourLegend extends ContourBase {
|
|
|
2368
2996
|
if (!btn || !this.contains(btn)) return;
|
|
2369
2997
|
const pressed = btn.getAttribute("aria-pressed") !== "true";
|
|
2370
2998
|
btn.setAttribute("aria-pressed", String(pressed));
|
|
2371
|
-
btn.setAttribute("aria-selected", String(pressed));
|
|
2372
2999
|
this.dispatchEvent(new CustomEvent("contour:legend-toggle", {
|
|
2373
3000
|
detail: { label: btn.textContent.trim(), key: btn.dataset.key || btn.textContent.trim(), pressed },
|
|
2374
3001
|
bubbles: true,
|
|
@@ -2412,7 +3039,7 @@ class ContourLegend extends ContourBase {
|
|
|
2412
3039
|
if (items.length > 4) { e.preventDefault(); const last = items[items.length-1]; last.focus(); items.forEach((o)=>o.setAttribute("tabindex", o===last?"0":"-1")); }
|
|
2413
3040
|
} else if (e.key === "Escape") {
|
|
2414
3041
|
// clear selection
|
|
2415
|
-
items.forEach((o) => o.setAttribute("aria-selected", "false"));
|
|
3042
|
+
items.forEach((o) => { if (o.getAttribute("role") === "option") o.setAttribute("aria-selected", "false"); else o.setAttribute("aria-pressed", "false"); });
|
|
2416
3043
|
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true }));
|
|
2417
3044
|
} else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
2418
3045
|
// type-ahead
|
|
@@ -2439,11 +3066,17 @@ class ContourLegend extends ContourBase {
|
|
|
2439
3066
|
}
|
|
2440
3067
|
}
|
|
2441
3068
|
define("contour-legend", ContourLegend);
|
|
3069
|
+
/**
|
|
3070
|
+
* Measure: web component wrapper.
|
|
3071
|
+
* Attributes: `label`, `value`, `point`, `line`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3072
|
+
*/
|
|
2442
3073
|
class ContourMeasure extends ContourBase {
|
|
2443
3074
|
static get observed() { return ["label", "value", "point", "line", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2444
3075
|
static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, point: { attribute: "point" }, line: { attribute: "line" }, src: { attribute: "src" } }; }
|
|
2445
3076
|
render() {
|
|
2446
3077
|
this.classList.add("c-measure");
|
|
3078
|
+
this.setAttribute("role", "group");
|
|
3079
|
+
this.setAttribute("aria-label", "Measure");
|
|
2447
3080
|
wireStates(this);
|
|
2448
3081
|
loadRemote(this, ["label", "value", "point", "line"]);
|
|
2449
3082
|
if (renderStates(this, "measure")) return;
|
|
@@ -2495,13 +3128,28 @@ class ContourMeasure extends ContourBase {
|
|
|
2495
3128
|
if (ln) ln.remove();
|
|
2496
3129
|
}
|
|
2497
3130
|
}
|
|
3131
|
+
enhance() {
|
|
3132
|
+
if (this._wiredMeasure) return;
|
|
3133
|
+
this._wiredMeasure = true;
|
|
3134
|
+
this.addEventListener("change", (e) => {
|
|
3135
|
+
const sel = e.target && e.target.closest ? e.target.closest(".c-measure__unit-select") : null;
|
|
3136
|
+
if (sel && this.contains(sel)) {
|
|
3137
|
+
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { unit: sel.value } }));
|
|
3138
|
+
}
|
|
3139
|
+
});
|
|
3140
|
+
}
|
|
2498
3141
|
}
|
|
2499
3142
|
define("contour-measure", ContourMeasure);
|
|
3143
|
+
/**
|
|
3144
|
+
* Timeline: web component wrapper.
|
|
3145
|
+
* Attributes: `items`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3146
|
+
*/
|
|
2500
3147
|
class ContourTimeline extends ContourBase {
|
|
2501
3148
|
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2502
3149
|
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
2503
3150
|
render() {
|
|
2504
3151
|
this.classList.add("c-timeline");
|
|
3152
|
+
this.setAttribute("role", "list");
|
|
2505
3153
|
wireStates(this);
|
|
2506
3154
|
loadRemote(this, "items");
|
|
2507
3155
|
if (renderStates(this, "timeline")) return;
|
|
@@ -2514,6 +3162,8 @@ class ContourTimeline extends ContourBase {
|
|
|
2514
3162
|
parsed.forEach((it) => {
|
|
2515
3163
|
const item = document.createElement("div");
|
|
2516
3164
|
item.className = "c-timeline__item";
|
|
3165
|
+
item.setAttribute("role", "listitem");
|
|
3166
|
+
item.setAttribute("tabindex", "-1");
|
|
2517
3167
|
if (it.time) {
|
|
2518
3168
|
const t = document.createElement("time");
|
|
2519
3169
|
t.className = "c-timeline__time";
|
|
@@ -2542,15 +3192,49 @@ class ContourTimeline extends ContourBase {
|
|
|
2542
3192
|
enhance() {
|
|
2543
3193
|
if (this._wiredTimeline) return;
|
|
2544
3194
|
this._wiredTimeline = true;
|
|
3195
|
+
const items = Array.from(this.querySelectorAll(".c-timeline__item"));
|
|
3196
|
+
items.forEach((it, i) => it.setAttribute("tabindex", i === 0 ? "0" : "-1"));
|
|
3197
|
+
this.addEventListener("click", (e) => {
|
|
3198
|
+
const item = e.target && e.target.closest ? e.target.closest(".c-timeline__item") : null;
|
|
3199
|
+
if (!item || !this.contains(item)) return;
|
|
3200
|
+
const items = Array.from(this.querySelectorAll(".c-timeline__item"));
|
|
3201
|
+
const idx = items.indexOf(item);
|
|
3202
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx } }));
|
|
3203
|
+
});
|
|
3204
|
+
this.addEventListener("keydown", (e) => {
|
|
3205
|
+
const items = Array.from(this.querySelectorAll(".c-timeline__item"));
|
|
3206
|
+
if (!items.length) return;
|
|
3207
|
+
const active = this.querySelector(".c-timeline__item:focus") || items[0];
|
|
3208
|
+
const idx = items.indexOf(active);
|
|
3209
|
+
let next = -1;
|
|
3210
|
+
if (e.key === "ArrowDown") next = Math.min(idx + 1, items.length - 1);
|
|
3211
|
+
else if (e.key === "ArrowUp") next = Math.max(idx - 1, 0);
|
|
3212
|
+
else if (e.key === "Home") next = 0;
|
|
3213
|
+
else if (e.key === "End") next = items.length - 1;
|
|
3214
|
+
else if (e.key === "Enter" || e.key === " ") {
|
|
3215
|
+
e.preventDefault();
|
|
3216
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx } }));
|
|
3217
|
+
return;
|
|
3218
|
+
}
|
|
3219
|
+
if (next < 0 || next === idx) return;
|
|
3220
|
+
e.preventDefault();
|
|
3221
|
+
items.forEach((it, i) => it.setAttribute("tabindex", i === next ? "0" : "-1"));
|
|
3222
|
+
try { items[next].focus(); } catch (err) {}
|
|
3223
|
+
});
|
|
2545
3224
|
}
|
|
2546
3225
|
}
|
|
2547
3226
|
define("contour-timeline", ContourTimeline);
|
|
3227
|
+
/**
|
|
3228
|
+
* Heatmap: web component wrapper.
|
|
3229
|
+
* Attributes: `cells`, `count`, `legend`, `empty`, `loading`, `values`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3230
|
+
*/
|
|
2548
3231
|
class ContourHeatmap extends ContourBase {
|
|
2549
3232
|
static get observed() { return ["cells", "count", "legend", "empty", "loading", "values", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2550
3233
|
static get properties() { return { cells: { attribute: "cells" }, count: { attribute: "count" }, legend: { attribute: "legend" }, src: { attribute: "src" } }; }
|
|
2551
3234
|
render() {
|
|
2552
3235
|
this.classList.add("c-heatmap");
|
|
2553
3236
|
if (!this.hasAttribute("role")) this.setAttribute("role", "grid");
|
|
3237
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Heatmap");
|
|
2554
3238
|
wireStates(this);
|
|
2555
3239
|
loadRemote(this, "cells");
|
|
2556
3240
|
if (renderStates(this, "heatmap")) return;
|
|
@@ -2673,11 +3357,17 @@ class ContourHeatmap extends ContourBase {
|
|
|
2673
3357
|
}
|
|
2674
3358
|
}
|
|
2675
3359
|
define("contour-heatmap", ContourHeatmap);
|
|
3360
|
+
/**
|
|
3361
|
+
* Compare: web component wrapper.
|
|
3362
|
+
* Attributes: `no`, `text`, `yes`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3363
|
+
*/
|
|
2676
3364
|
class ContourCompare extends ContourBase {
|
|
2677
3365
|
static get observed() { return ["no", "text", "yes", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2678
3366
|
static get properties() { return { no: { attribute: "no" }, text: { attribute: "text" }, yes: { attribute: "yes" }, src: { attribute: "src" } }; }
|
|
2679
3367
|
render() {
|
|
2680
3368
|
this.classList.add("c-compare");
|
|
3369
|
+
this.setAttribute("role", "group");
|
|
3370
|
+
this.setAttribute("aria-label", "Comparison");
|
|
2681
3371
|
this.style.padding = "var(--space-md)";
|
|
2682
3372
|
wireStates(this);
|
|
2683
3373
|
loadRemote(this, ["no", "text", "yes"]);
|
|
@@ -2710,6 +3400,10 @@ class ContourCompare extends ContourBase {
|
|
|
2710
3400
|
}
|
|
2711
3401
|
}
|
|
2712
3402
|
define("contour-compare", ContourCompare);
|
|
3403
|
+
/**
|
|
3404
|
+
* Sparkline: web component wrapper.
|
|
3405
|
+
* Attributes: `points`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3406
|
+
*/
|
|
2713
3407
|
class ContourSparkline extends ContourBase {
|
|
2714
3408
|
static get observed() { return ["points", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2715
3409
|
static get properties() { return { points: { attribute: "points" }, src: { attribute: "src" } }; }
|
|
@@ -2821,11 +3515,18 @@ class ContourSparkline extends ContourBase {
|
|
|
2821
3515
|
}
|
|
2822
3516
|
}
|
|
2823
3517
|
define("contour-sparkline", ContourSparkline);
|
|
3518
|
+
/**
|
|
3519
|
+
* Chart Grid: web component wrapper.
|
|
3520
|
+
* Attributes: `title`, `series`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3521
|
+
*/
|
|
2824
3522
|
class ContourChartGrid extends ContourBase {
|
|
3523
|
+
static get updateMode() { return "keyed"; }
|
|
2825
3524
|
static get observed() { return ["title", "series", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2826
3525
|
static get properties() { return { title: { attribute: "title" }, series: { attribute: "series" }, src: { attribute: "src" } }; }
|
|
2827
3526
|
render() {
|
|
2828
3527
|
this.classList.add("c-chart-grid");
|
|
3528
|
+
this.setAttribute("role", "group");
|
|
3529
|
+
this.setAttribute("aria-label", "Chart grid");
|
|
2829
3530
|
wireStates(this);
|
|
2830
3531
|
loadRemote(this, "series");
|
|
2831
3532
|
if (renderStates(this, "chart-grid")) return;
|
|
@@ -2839,11 +3540,17 @@ class ContourChartGrid extends ContourBase {
|
|
|
2839
3540
|
}
|
|
2840
3541
|
}
|
|
2841
3542
|
define("contour-chart-grid", ContourChartGrid);
|
|
3543
|
+
/**
|
|
3544
|
+
* Contour Plot: web component wrapper.
|
|
3545
|
+
* Attributes: `axis`, `label`.
|
|
3546
|
+
*/
|
|
2842
3547
|
class ContourContourPlot extends ContourBase {
|
|
2843
3548
|
static get observed() { return ["axis", "label"]; }
|
|
2844
3549
|
static get properties() { return { axis: { attribute: "axis" }, label: { attribute: "label" } }; }
|
|
2845
3550
|
render() {
|
|
2846
3551
|
this.classList.add("c-contour-plot");
|
|
3552
|
+
this.setAttribute("role", "img");
|
|
3553
|
+
this.setAttribute("aria-label", "Contour plot");
|
|
2847
3554
|
const axis = this.getAttribute("axis");
|
|
2848
3555
|
if (axis) {
|
|
2849
3556
|
let svg = this.querySelector("svg");
|
|
@@ -2879,4 +3586,48 @@ class ContourContourPlot extends ContourBase {
|
|
|
2879
3586
|
}
|
|
2880
3587
|
}
|
|
2881
3588
|
}
|
|
2882
|
-
|
|
3589
|
+
/**
|
|
3590
|
+
* Error Boundary: web component wrapper.
|
|
3591
|
+
* Attributes: `fallback`, `error`.
|
|
3592
|
+
*/
|
|
3593
|
+
class ContourErrorBoundary extends ContourBase {
|
|
3594
|
+
static get observed() { return ["fallback", "error"]; }
|
|
3595
|
+
static get properties() { return { fallback: { attribute: "fallback" }, error: { attribute: "error" } }; }
|
|
3596
|
+
render() {
|
|
3597
|
+
this.classList.add("c-error-boundary");
|
|
3598
|
+
this.setAttribute("role", "region");
|
|
3599
|
+
this.setAttribute("aria-live", "polite");
|
|
3600
|
+
const err = this.getAttribute("error");
|
|
3601
|
+
if (err) {
|
|
3602
|
+
this.dataset.state = "error";
|
|
3603
|
+
// Hide authored children, show fallback.
|
|
3604
|
+
Array.from(this.children).forEach((c) => { if (!c.hasAttribute("data-fallback")) c.style.display = "none"; });
|
|
3605
|
+
let fb = this.querySelector("[data-fallback]");
|
|
3606
|
+
if (!fb) {
|
|
3607
|
+
fb = document.createElement("div");
|
|
3608
|
+
fb.className = "c-error-boundary__fallback";
|
|
3609
|
+
fb.dataset.fallback = "";
|
|
3610
|
+
fb.textContent = this.getAttribute("fallback") || "Something went wrong.";
|
|
3611
|
+
this.appendChild(fb);
|
|
3612
|
+
} else {
|
|
3613
|
+
fb.textContent = this.getAttribute("fallback") || fb.textContent || "Something went wrong.";
|
|
3614
|
+
}
|
|
3615
|
+
} else {
|
|
3616
|
+
this.dataset.state = "ready";
|
|
3617
|
+
Array.from(this.children).forEach((c) => { c.style.display = ""; });
|
|
3618
|
+
const fb = this.querySelector("[data-fallback]");
|
|
3619
|
+
if (fb) fb.remove();
|
|
3620
|
+
}
|
|
3621
|
+
}
|
|
3622
|
+
enhance() {
|
|
3623
|
+
if (this._wiredErrorBoundary) return;
|
|
3624
|
+
this._wiredErrorBoundary = true;
|
|
3625
|
+
// Catch errors thrown by descendants during render/event handling.
|
|
3626
|
+
this.addEventListener("error", (e) => {
|
|
3627
|
+
e.stopPropagation();
|
|
3628
|
+
const msg = (e && e.error && e.error.message) ? e.error.message : (e && e.message) ? e.message : "Unknown error";
|
|
3629
|
+
this.setAttribute("error", msg);
|
|
3630
|
+
}, true);
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
define("contour-error-boundary", ContourErrorBoundary);
|