contour-ds 1.8.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +227 -378
- package/dist/agent-cookbook.json +960 -0
- package/dist/agent-examples.json +65 -0
- package/dist/agent-map-wiring.json +152 -0
- package/dist/build-manifest.json +320 -179
- package/dist/contour-wc-content.esm.js +479 -3665
- package/dist/contour-wc-content.esm.min.js +1 -1
- package/dist/contour-wc-core.esm.js +3724 -0
- package/dist/contour-wc-core.esm.min.js +1 -0
- package/dist/contour-wc-dashboard.esm.js +2713 -4381
- package/dist/contour-wc-dashboard.esm.min.js +1 -1
- package/dist/contour-wc-data.esm.js +2658 -4346
- package/dist/contour-wc-data.esm.min.js +1 -1
- package/dist/contour-wc-docs.esm.js +218 -3547
- package/dist/contour-wc-docs.esm.min.js +1 -1
- package/dist/contour-wc-feedback.esm.js +483 -3658
- package/dist/contour-wc-feedback.esm.min.js +1 -1
- package/dist/contour-wc-forms.esm.js +503 -3754
- package/dist/contour-wc-forms.esm.min.js +1 -1
- package/dist/contour-wc-interaction.esm.js +379 -3616
- package/dist/contour-wc-interaction.esm.min.js +1 -1
- package/dist/contour-wc-layout.esm.js +234 -3563
- package/dist/contour-wc-layout.esm.min.js +1 -1
- package/dist/contour-wc-map.esm.js +949 -3743
- package/dist/contour-wc-map.esm.min.js +1 -1
- package/dist/contour-wc-misc.esm.js +237 -3556
- package/dist/contour-wc-misc.esm.min.js +1 -1
- package/dist/contour-wc-navigation.esm.js +2235 -5237
- package/dist/contour-wc-navigation.esm.min.js +1 -1
- package/dist/contour-wc-ui.esm.js +4638 -7128
- package/dist/contour-wc-ui.esm.min.js +1 -1
- package/dist/contour-wc.esm.js +11971 -7727
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +11971 -7727
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.a11y.json +402 -0
- package/dist/contour.code-snippets +96 -74
- package/dist/contour.components.json +2591 -741
- package/dist/contour.css +2624 -1888
- package/dist/contour.d.ts +421 -228
- package/dist/contour.esm.js +433 -18
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +1231 -199
- package/dist/contour.js +433 -18
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +100 -98
- package/dist/contour.single.html +2 -2
- package/dist/contour.single.min.css +1 -1
- package/dist/contour.themes.json +56 -12
- package/dist/contour.tokens.json +482 -255
- package/dist/contour.vue.d.ts +100 -98
- package/dist/contour.web-types.json +1226 -226
- package/dist/custom-elements.json +7649 -2237
- package/dist/docs/actions.md +15 -6
- package/dist/docs/affordances.md +18 -96
- package/dist/docs/apireference.md +9 -5
- package/dist/docs/colour.md +10 -4
- package/dist/docs/componentindex.md +9 -26
- package/dist/docs/data.md +36 -60
- package/dist/docs/docs.md +10 -12
- package/dist/docs/feedback.md +30 -12
- package/dist/docs/field.md +28 -13
- package/dist/docs/forms.md +35 -19
- package/dist/docs/index.json +63 -56
- package/dist/docs/install.md +12 -7
- package/dist/docs/landing.md +7 -4
- package/dist/docs/mapengine.md +18 -13
- package/dist/docs/motion.md +12 -6
- package/dist/docs/navigation.md +31 -7
- package/dist/docs/overlays.md +32 -25
- package/dist/docs/overview.md +3 -2
- package/dist/docs/patterns.md +19 -9
- package/dist/docs/playground.md +9 -22
- package/dist/docs/principles.md +8 -6
- package/dist/docs/recipes.md +113 -14
- package/dist/docs/space.md +10 -6
- package/dist/docs/status.md +12 -25
- package/dist/docs/surfaces.md +17 -22
- package/dist/docs/theming.md +18 -32
- package/dist/docs/type.md +12 -5
- package/dist/docs/webcomponents.md +66 -38
- package/dist/hljs.css +1 -20
- package/dist/map-chrome.mapbox.css +68 -92
- package/dist/map-chrome.maplibre.css +68 -92
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/svg/icons.svg +367 -0
- package/dist/wc/behaviours.mjs +190 -148
- package/dist/wc/content.mjs +273 -129
- package/dist/wc/core.mjs +598 -395
- package/dist/wc/dashboard.mjs +64 -44
- package/dist/wc/data-chart.mjs +1333 -0
- package/dist/wc/data-export.mjs +391 -0
- package/dist/wc/data-gauge.mjs +779 -0
- package/dist/wc/data-geo.mjs +696 -0
- package/dist/wc/data-glyphs.mjs +133 -0
- package/dist/wc/data-legend.mjs +431 -0
- package/dist/wc/data-readout.mjs +227 -0
- package/dist/wc/data-series.mjs +1004 -0
- package/dist/wc/data-table.mjs +751 -0
- package/dist/wc/data.mjs +15 -4322
- package/dist/wc/docs.mjs +12 -11
- package/dist/wc/feedback.mjs +277 -122
- package/dist/wc/forms-controls.mjs +635 -0
- package/dist/wc/forms-field.mjs +547 -0
- package/dist/wc/forms-groups.mjs +347 -0
- package/dist/wc/forms-input.mjs +292 -0
- package/dist/wc/forms.mjs +10 -1751
- package/dist/wc/glyph.mjs +204 -0
- package/dist/wc/index.mjs +11 -9
- package/dist/wc/interaction.mjs +173 -80
- package/dist/wc/layout.mjs +28 -27
- package/dist/wc/map.mjs +743 -207
- package/dist/wc/misc.mjs +31 -20
- package/dist/wc/navigation-menu.mjs +735 -0
- package/dist/wc/navigation-shell.mjs +495 -0
- package/dist/wc/navigation-tree.mjs +995 -0
- package/dist/wc/navigation.mjs +9 -1905
- package/dist/wc/registration.mjs +1 -8
- package/dist/wc/shadow.mjs +206 -110
- package/dist/wc/states.mjs +54 -75
- package/dist/wc/svg.mjs +118 -47
- package/dist/wc/ui-atoms.mjs +608 -0
- package/dist/wc/ui-data.mjs +1404 -0
- package/dist/wc/ui-feedback.mjs +419 -0
- package/dist/wc/ui-inputs.mjs +1570 -0
- package/dist/wc/ui-menus.mjs +307 -0
- package/dist/wc/ui-overlays.mjs +1605 -0
- package/integrations/README.md +23 -5
- package/integrations/ai/CLAUDE.md +3 -0
- package/integrations/ai/COPILOT.md +14 -0
- package/integrations/ai/GEMINI.md +14 -0
- package/integrations/ai/WINDSURF.md +14 -0
- package/integrations/ai/v0-prompt.md +13 -1
- package/integrations/native/README.md +0 -3
- package/integrations/tailwind/contour-theme.css +66 -7
- package/integrations/validate-markup.mjs +172 -0
- package/package.json +77 -42
- package/dist/wc/ui.mjs +0 -5072
package/dist/wc/data.mjs
CHANGED
|
@@ -1,4323 +1,16 @@
|
|
|
1
|
-
import { ContourBase, define, onDispose, formatValue, contourId, navKey, isRtl, cssLength , warnBadJson, labelText } from './core.mjs';
|
|
2
|
-
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates, remoteInvalidate, watchViewport } from './states.mjs';
|
|
3
|
-
import { donutSlices, barRects, smoothPath, polylinePoints, contourPaths } from './svg.mjs';
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (rows && !authored.length) {
|
|
21
|
-
try {
|
|
22
|
-
const parsed = JSON.parse(rows);
|
|
23
|
-
parsed.forEach((r) => {
|
|
24
|
-
const row = document.createElement("div");
|
|
25
|
-
row.className = "c-readout__row";
|
|
26
|
-
const key = document.createElement("span");
|
|
27
|
-
key.className = "c-readout__key";
|
|
28
|
-
key.textContent = r.key || r[0];
|
|
29
|
-
const val = document.createElement("span");
|
|
30
|
-
val.className = "c-readout__value" + (r.primary ? " c-readout__value--primary" : "") + (r.accent ? " c-readout__value--accent" : "") + (r.coord ? " c-readout__value--coord" : "");
|
|
31
|
-
val.setAttribute("aria-live", "polite");
|
|
32
|
-
val.textContent = formatValue(r.value || r[1], this.getAttribute("format"), this.getAttribute("locale"), (r.unit !== undefined ? r.unit : this.getAttribute("unit")));
|
|
33
|
-
row.appendChild(key);
|
|
34
|
-
row.appendChild(val);
|
|
35
|
-
if (r.order) {
|
|
36
|
-
const ord = document.createElement("span");
|
|
37
|
-
ord.className = "c-readout__order";
|
|
38
|
-
ord.textContent = r.order;
|
|
39
|
-
row.appendChild(ord);
|
|
40
|
-
}
|
|
41
|
-
this.appendChild(row);
|
|
42
|
-
});
|
|
43
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
44
|
-
} else if (!rows && !authored.length) {
|
|
45
|
-
renderEmpty(this, "readout");
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
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
|
-
*/
|
|
54
|
-
class ContourKpi extends ContourBase {
|
|
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"]; }
|
|
56
|
-
static get properties() {
|
|
57
|
-
return { value: { attribute: "value" }, label: { attribute: "label" }, delta: { attribute: "delta" }, direction: { attribute: "direction" }, note: { attribute: "note" }, variant: { attribute: "variant" }, unit: { attribute: "unit" }, format: { attribute: "format" }, locale: { attribute: "locale" }, thresholds: { attribute: "thresholds" }, threshold: { attribute: "threshold" }, sparkline: { attribute: "sparkline" }, polarity: { attribute: "polarity" } };
|
|
58
|
-
}
|
|
59
|
-
render() {
|
|
60
|
-
this.classList.add("c-kpi");
|
|
61
|
-
wireStates(this);
|
|
62
|
-
loadRemote(this, ["value", "label"]);
|
|
63
|
-
if (renderStates(this, "kpi")) return;
|
|
64
|
-
const value = remoteData(this, "value");
|
|
65
|
-
const label = remoteData(this, "label");
|
|
66
|
-
const delta = this.getAttribute("delta");
|
|
67
|
-
const variant = this.getAttribute("variant");
|
|
68
|
-
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-kpi--")) this.classList.remove(c); });
|
|
69
|
-
if (variant) this.classList.add("c-kpi--" + variant);
|
|
70
|
-
if (value) {
|
|
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; });
|
|
72
|
-
v.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"), this.getAttribute("unit"));
|
|
73
|
-
} else {
|
|
74
|
-
const v = this.querySelector(".c-kpi__value");
|
|
75
|
-
if (v) v.remove();
|
|
76
|
-
}
|
|
77
|
-
if (label) {
|
|
78
|
-
const h = this.ensure(".c-kpi__head", () => { const el = document.createElement("div"); el.className = "c-kpi__head"; return el; });
|
|
79
|
-
let l = h.querySelector(".c-kpi__label");
|
|
80
|
-
if (!l) { l = document.createElement("div"); l.className = "c-kpi__label"; h.appendChild(l); }
|
|
81
|
-
l.textContent = label;
|
|
82
|
-
if (h.parentNode !== this) this.insertBefore(h, this.firstChild);
|
|
83
|
-
} else {
|
|
84
|
-
const h = this.querySelector(".c-kpi__head");
|
|
85
|
-
if (h) h.remove();
|
|
86
|
-
}
|
|
87
|
-
if (delta) {
|
|
88
|
-
const f = this.ensure(".c-kpi__foot", () => { const el = document.createElement("div"); el.className = "c-kpi__foot"; return el; });
|
|
89
|
-
const d = f.querySelector(".c-delta") || document.createElement("span");
|
|
90
|
-
if (!d.parentNode) f.insertBefore(d, f.firstChild);
|
|
91
|
-
const dir = this.getAttribute("direction") || "up";
|
|
92
|
-
const polarity = this.getAttribute("polarity") || "neutral";
|
|
93
|
-
let tone = "neutral";
|
|
94
|
-
if (polarity === "good") tone = (dir === "up") ? "good" : "bad";
|
|
95
|
-
else if (polarity === "bad") tone = (dir === "up") ? "bad" : "good";
|
|
96
|
-
d.className = "c-delta c-delta--" + dir + " c-delta--" + tone;
|
|
97
|
-
d.textContent = delta;
|
|
98
|
-
} else {
|
|
99
|
-
const d = this.querySelector(".c-kpi__foot .c-delta");
|
|
100
|
-
if (d) d.remove();
|
|
101
|
-
}
|
|
102
|
-
const note = this.getAttribute("note");
|
|
103
|
-
if (note) {
|
|
104
|
-
const f = this.ensure(".c-kpi__foot", () => { const el = document.createElement("div"); el.className = "c-kpi__foot"; return el; });
|
|
105
|
-
const n = f.querySelector(".c-kpi__note") || (() => { const el = document.createElement("span"); el.className = "c-kpi__note"; f.appendChild(el); return el; })();
|
|
106
|
-
n.textContent = note;
|
|
107
|
-
} else {
|
|
108
|
-
const n = this.querySelector(".c-kpi__note");
|
|
109
|
-
if (n) n.remove();
|
|
110
|
-
}
|
|
111
|
-
const unit = this.getAttribute("unit");
|
|
112
|
-
const v = this.querySelector(".c-kpi__value");
|
|
113
|
-
if (v) {
|
|
114
|
-
if (unit) {
|
|
115
|
-
let u = v.querySelector(".c-kpi__unit");
|
|
116
|
-
if (!u) { u = document.createElement("span"); u.className = "c-kpi__unit"; v.appendChild(u); }
|
|
117
|
-
u.textContent = unit;
|
|
118
|
-
} else {
|
|
119
|
-
const u = v.querySelector(".c-kpi__unit");
|
|
120
|
-
if (u) u.remove();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
// threshold badge
|
|
124
|
-
const threshold = this.getAttribute("threshold") || this.getAttribute("thresholds");
|
|
125
|
-
if (threshold) {
|
|
126
|
-
const f = this.ensure(".c-kpi__foot", () => { const el = document.createElement("div"); el.className = "c-kpi__foot"; return el; });
|
|
127
|
-
let badge = f.querySelector(".c-kpi__threshold-badge");
|
|
128
|
-
if (!badge) { badge = document.createElement("span"); badge.className = "c-kpi__threshold-badge"; f.appendChild(badge); }
|
|
129
|
-
badge.textContent = threshold;
|
|
130
|
-
badge.setAttribute("part", "threshold-badge");
|
|
131
|
-
} else {
|
|
132
|
-
const b = this.querySelector(".c-kpi__threshold-badge");
|
|
133
|
-
if (b) b.remove();
|
|
134
|
-
}
|
|
135
|
-
// remove orphaned foot container when no children remain
|
|
136
|
-
const foot = this.querySelector(".c-kpi__foot");
|
|
137
|
-
if (foot && !foot.querySelector(".c-delta, .c-kpi__note, .c-kpi__threshold-badge")) foot.remove();
|
|
138
|
-
// sparkline canvas
|
|
139
|
-
const spark = this.getAttribute("sparkline");
|
|
140
|
-
if (spark) {
|
|
141
|
-
let canvas = this.querySelector(".c-kpi__sparkline-canvas");
|
|
142
|
-
if (!canvas) { canvas = document.createElement("canvas"); canvas.className = "c-kpi__sparkline-canvas"; canvas.setAttribute("part", "sparkline-canvas"); this.appendChild(canvas); }
|
|
143
|
-
} else {
|
|
144
|
-
const c = this.querySelector(".c-kpi__sparkline-canvas");
|
|
145
|
-
if (c) c.remove();
|
|
146
|
-
}
|
|
147
|
-
if (!value && !label) {
|
|
148
|
-
renderEmpty(this, "kpi");
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
define("contour-kpi", ContourKpi);
|
|
153
|
-
/**
|
|
154
|
-
* Table: web component wrapper.
|
|
155
|
-
* Attributes: `columns`, `rows`, `page`, `page-size`, `sort`, `sort-dir`, `virtual`, `title`, `empty`, `loading`, `error`, `retry`, `skeleton`, `persist`.
|
|
156
|
-
*/
|
|
157
|
-
class ContourTable extends ContourBase {
|
|
158
|
-
static get updateMode() { return "keyed"; }
|
|
159
|
-
static get observed() { return ["columns", "rows", "page", "page-size", "sort", "sort-dir", "virtual", "title", "empty", "loading", "error", "retry", "skeleton", "persist"]; }
|
|
160
|
-
static get properties() { return { columns: { attribute: "columns" }, rows: { attribute: "rows" }, page: { attribute: "page", type: Number }, pageSize: { attribute: "page-size", type: Number } }; }
|
|
161
|
-
_cellValue(cell) {
|
|
162
|
-
if (cell === null || cell === undefined) return "";
|
|
163
|
-
if (typeof cell === "object") return cell.value !== undefined ? cell.value : (cell.label !== undefined ? cell.label : JSON.stringify(cell));
|
|
164
|
-
return cell;
|
|
165
|
-
}
|
|
166
|
-
_compare(a, b, type) {
|
|
167
|
-
const av = this._cellValue(a);
|
|
168
|
-
const bv = this._cellValue(b);
|
|
169
|
-
if (type === "number" || type === "numeric") {
|
|
170
|
-
return (parseFloat(av) || 0) - (parseFloat(bv) || 0);
|
|
171
|
-
}
|
|
172
|
-
return String(av).localeCompare(String(bv), undefined, { numeric: true });
|
|
173
|
-
}
|
|
174
|
-
render() {
|
|
175
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
176
|
-
// An authored label names the table; "Table" is the fallback.
|
|
177
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Table");
|
|
178
|
-
wireStates(this);
|
|
179
|
-
loadRemote(this, "rows");
|
|
180
|
-
if (renderStates(this, "table")) return;
|
|
181
|
-
// The host is not a <table>, so it carries no table rule. The scroller the
|
|
182
|
-
// reflow contract requires is a real block element inside it.
|
|
183
|
-
const columns = this.getAttribute("columns");
|
|
184
|
-
const rows = remoteData(this, "rows");
|
|
185
|
-
// Slot composition: an authored table wins over the JSON attributes.
|
|
186
|
-
const authored = Array.from(this.children).filter((n) => !n.classList || !n.classList.contains("c-table-wrap"));
|
|
187
|
-
if (columns && rows && !authored.length) {
|
|
188
|
-
try {
|
|
189
|
-
const cols = JSON.parse(columns);
|
|
190
|
-
const data = JSON.parse(rows);
|
|
191
|
-
// Initialise sort state from attributes on first render.
|
|
192
|
-
if (this._sortCol === undefined) {
|
|
193
|
-
const sortAttr = this.getAttribute("sort");
|
|
194
|
-
if (sortAttr !== null) {
|
|
195
|
-
const idx = Number(sortAttr);
|
|
196
|
-
this._sortCol = Number.isFinite(idx) ? idx : cols.findIndex((c) => (typeof c === "object" && c && (c.label || c.title || c) === sortAttr));
|
|
197
|
-
if (this._sortCol < 0) this._sortCol = null;
|
|
198
|
-
} else {
|
|
199
|
-
this._sortCol = null;
|
|
200
|
-
}
|
|
201
|
-
const dirAttr = this.getAttribute("sort-dir");
|
|
202
|
-
this._sortDir = dirAttr === "descending" || dirAttr === "desc" ? -1 : 1;
|
|
203
|
-
}
|
|
204
|
-
// Apply sort.
|
|
205
|
-
let working = Array.isArray(data) ? data.slice() : [];
|
|
206
|
-
if (this._sortCol !== null && this._sortCol !== undefined && this._sortCol >= 0 && this._sortCol < cols.length) {
|
|
207
|
-
const col = this._sortCol;
|
|
208
|
-
const dir = this._sortDir || 1;
|
|
209
|
-
const colSpec = cols[col];
|
|
210
|
-
const type = (typeof colSpec === "object" && colSpec && colSpec.sortType) ? colSpec.sortType : "text";
|
|
211
|
-
working.sort((a, b) => this._compare(a && a[col], b && b[col], type) * dir);
|
|
212
|
-
}
|
|
213
|
-
// Column filters (F-09): narrow `working` by each active filter.
|
|
214
|
-
if (!this._filters) this._filters = {};
|
|
215
|
-
const activeFilters = Object.keys(this._filters).filter((k) => this._filters[k]);
|
|
216
|
-
if (activeFilters.length) {
|
|
217
|
-
working = working.filter((row) => activeFilters.every((k) => {
|
|
218
|
-
const ci = Number(k);
|
|
219
|
-
const q = String(this._filters[ci] || "").toLowerCase();
|
|
220
|
-
if (!q) return true;
|
|
221
|
-
return String(this._cellValue(row[ci])).toLowerCase().includes(q);
|
|
222
|
-
}));
|
|
223
|
-
}
|
|
224
|
-
// Pagination.
|
|
225
|
-
const pageSizeRaw = this.getAttribute("page-size");
|
|
226
|
-
const pageSize = pageSizeRaw !== null ? parseInt(pageSizeRaw, 10) : NaN;
|
|
227
|
-
const usePaging = Number.isFinite(pageSize) && pageSize > 0;
|
|
228
|
-
// Sync internal page state with external attribute changes.
|
|
229
|
-
let pageAttr = this.getAttribute("page");
|
|
230
|
-
if (this.getAttribute("persist") && this.id) {
|
|
231
|
-
const mode = this.getAttribute("persist");
|
|
232
|
-
let stored = null;
|
|
233
|
-
if (mode === "storage") { try { stored = localStorage.getItem("contour-table:" + this.id); } catch (e) {} }
|
|
234
|
-
else if (mode === "url") { try { stored = new URLSearchParams(window.location.search).get("c-table"); } catch (e) {} }
|
|
235
|
-
if (stored !== null) pageAttr = stored;
|
|
236
|
-
}
|
|
237
|
-
if (this._pageInternal) {
|
|
238
|
-
this._pageInternal = false;
|
|
239
|
-
this._pageAttrLast = pageAttr;
|
|
240
|
-
} else if (pageAttr !== this._pageAttrLast) {
|
|
241
|
-
this._page = null;
|
|
242
|
-
this._pageAttrLast = pageAttr;
|
|
243
|
-
}
|
|
244
|
-
let page = this._page !== null ? this._page : (parseInt(pageAttr || "1", 10));
|
|
245
|
-
if (!Number.isFinite(page) || page < 1) page = 1;
|
|
246
|
-
let totalPages = 1;
|
|
247
|
-
let pageData = working;
|
|
248
|
-
if (usePaging) {
|
|
249
|
-
totalPages = Math.max(1, Math.ceil(working.length / pageSize));
|
|
250
|
-
if (page > totalPages) page = totalPages;
|
|
251
|
-
const start = (page - 1) * pageSize;
|
|
252
|
-
pageData = working.slice(start, start + pageSize);
|
|
253
|
-
}
|
|
254
|
-
this._page = page;
|
|
255
|
-
this._totalPages = totalPages;
|
|
256
|
-
this._pageSize = pageSize;
|
|
257
|
-
// Keep the row objects in memory instead of serializing each one into
|
|
258
|
-
// a data-row attribute: the JSON duplicated the data the component
|
|
259
|
-
// already holds and bloated every row.
|
|
260
|
-
this._rowData = pageData;
|
|
261
|
-
|
|
262
|
-
const wrap = this.ensure(".c-table-wrap", () => { const el = document.createElement("div"); el.className = "c-table-wrap"; return el; });
|
|
263
|
-
// Reuse the existing table when columns are unchanged, rebuilding
|
|
264
|
-
// only the body. This avoids O(n) DOM churn on row-only updates.
|
|
265
|
-
const colsKey = JSON.stringify(cols);
|
|
266
|
-
const table = (wrap.querySelector("table.c-table") && this._tableCols === colsKey)
|
|
267
|
-
? wrap.querySelector("table.c-table")
|
|
268
|
-
: (() => {
|
|
269
|
-
const t = document.createElement("table");
|
|
270
|
-
t.className = "c-table";
|
|
271
|
-
// A table needs a caption: the host's region label is outside the
|
|
272
|
-
// table, so a reader who enters it hears column headers with no
|
|
273
|
-
// statement of what the table is. Visually hidden keeps the block
|
|
274
|
-
// layout unchanged.
|
|
275
|
-
const captionEl = document.createElement("caption");
|
|
276
|
-
captionEl.className = "visually-hidden";
|
|
277
|
-
captionEl.textContent = this.getAttribute("title") || this.getAttribute("aria-label") || "Table";
|
|
278
|
-
t.appendChild(captionEl);
|
|
279
|
-
const thead = document.createElement("thead");
|
|
280
|
-
const tr = document.createElement("tr");
|
|
281
|
-
cols.forEach((c, i) => {
|
|
282
|
-
const colLabel = typeof c === "string" ? c : (c.label || c.title || c);
|
|
283
|
-
const th = document.createElement("th");
|
|
284
|
-
const sortable = (typeof c === "object" && c !== null && c.sort);
|
|
285
|
-
const isSelect = (typeof c === "object" && c !== null && c.select);
|
|
286
|
-
const isFilter = (typeof c === "object" && c !== null && c.filter);
|
|
287
|
-
if (isFilter) {
|
|
288
|
-
th.className = (th.className + " c-table__filter").trim();
|
|
289
|
-
const inp = document.createElement("input");
|
|
290
|
-
inp.type = "search";
|
|
291
|
-
inp.className = "c-table__filter-input";
|
|
292
|
-
inp.placeholder = colLabel;
|
|
293
|
-
// A placeholder is not a label: a reader who tabs into the
|
|
294
|
-
// filter hears "edit text" with no column name. Name it.
|
|
295
|
-
inp.setAttribute("aria-label", "Filter " + colLabel);
|
|
296
|
-
inp.dataset.filterIndex = String(i);
|
|
297
|
-
if (this._filters && this._filters[i]) inp.value = this._filters[i];
|
|
298
|
-
th.appendChild(inp);
|
|
299
|
-
} else if (isSelect) {
|
|
300
|
-
th.className = (th.className + " c-table__select").trim();
|
|
301
|
-
const cb = document.createElement("input");
|
|
302
|
-
cb.type = "checkbox";
|
|
303
|
-
cb.className = "c-table__select-all";
|
|
304
|
-
cb.setAttribute("aria-label", "Select all rows");
|
|
305
|
-
th.appendChild(cb);
|
|
306
|
-
} else if (sortable) {
|
|
307
|
-
th.setAttribute("aria-sort", (this._sortCol === i)
|
|
308
|
-
? (this._sortDir === -1 ? "descending" : "ascending")
|
|
309
|
-
: "none");
|
|
310
|
-
const wrapEl = document.createElement("span");
|
|
311
|
-
wrapEl.className = "c-table__sort";
|
|
312
|
-
wrapEl.textContent = colLabel;
|
|
313
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
314
|
-
svg.setAttribute("aria-hidden", "true");
|
|
315
|
-
svg.innerHTML = '<use href="#i-chevron-down" />';
|
|
316
|
-
wrapEl.appendChild(svg);
|
|
317
|
-
th.appendChild(wrapEl);
|
|
318
|
-
} else if (typeof c === "object" && c !== null && c.pinned) {
|
|
319
|
-
th.className = "c-table__pinned";
|
|
320
|
-
th.textContent = colLabel;
|
|
321
|
-
} else {
|
|
322
|
-
th.textContent = colLabel;
|
|
323
|
-
}
|
|
324
|
-
if (sortable) {
|
|
325
|
-
th.setAttribute("tabindex", "0");
|
|
326
|
-
th.setAttribute("role", "columnheader");
|
|
327
|
-
th.dataset.sortIndex = String(i);
|
|
328
|
-
}
|
|
329
|
-
tr.appendChild(th);
|
|
330
|
-
});
|
|
331
|
-
thead.appendChild(tr);
|
|
332
|
-
t.appendChild(thead);
|
|
333
|
-
t.appendChild(document.createElement("tbody"));
|
|
334
|
-
return t;
|
|
335
|
-
})();
|
|
336
|
-
this._tableCols = colsKey;
|
|
337
|
-
// Keep sort indicators in sync even when the table element is reused.
|
|
338
|
-
cols.forEach((c, i) => {
|
|
339
|
-
if (typeof c === "object" && c !== null && c.sort) {
|
|
340
|
-
const th = table.querySelector("thead tr th:nth-child(" + (i + 1) + ")");
|
|
341
|
-
if (th) th.setAttribute("aria-sort", (this._sortCol === i) ? (this._sortDir === -1 ? "descending" : "ascending") : "none");
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
const tbody = table.querySelector("tbody");
|
|
345
|
-
tbody.innerHTML = "";
|
|
346
|
-
const useVirtual = this.hasAttribute("virtual") && !usePaging && pageData.length > 100;
|
|
347
|
-
const rowHeight = this._measuredRowHeight || cssLength("--data-grid-row-height", 36);
|
|
348
|
-
const windowSize = 30;
|
|
349
|
-
const overscan = 10;
|
|
350
|
-
let windowStart = 0;
|
|
351
|
-
let visibleData = pageData;
|
|
352
|
-
if (useVirtual) {
|
|
353
|
-
const maxStart = Math.max(0, pageData.length - windowSize);
|
|
354
|
-
windowStart = Math.min(maxStart, Math.max(0, Math.floor(wrap.scrollTop / rowHeight) - overscan));
|
|
355
|
-
visibleData = pageData.slice(windowStart, windowStart + windowSize + overscan * 2);
|
|
356
|
-
table.setAttribute("aria-rowcount", String(pageData.length + 1));
|
|
357
|
-
} else {
|
|
358
|
-
table.removeAttribute("aria-rowcount");
|
|
359
|
-
}
|
|
360
|
-
const addSpacer = (height) => {
|
|
361
|
-
const tr = document.createElement("tr");
|
|
362
|
-
tr.setAttribute("aria-hidden", "true");
|
|
363
|
-
const td = document.createElement("td");
|
|
364
|
-
td.colSpan = cols.length;
|
|
365
|
-
td.style.blockSize = `${height}px`;
|
|
366
|
-
td.style.padding = "0";
|
|
367
|
-
tr.appendChild(td);
|
|
368
|
-
tbody.appendChild(tr);
|
|
369
|
-
};
|
|
370
|
-
if (useVirtual) addSpacer(windowStart * rowHeight);
|
|
371
|
-
if (visibleData.length === 0) {
|
|
372
|
-
const tr = document.createElement("tr");
|
|
373
|
-
const td = document.createElement("td");
|
|
374
|
-
td.colSpan = cols.length;
|
|
375
|
-
td.textContent = this.getAttribute("empty") || "No data";
|
|
376
|
-
td.style.textAlign = "center";
|
|
377
|
-
td.style.color = "var(--color-text-muted)";
|
|
378
|
-
tr.appendChild(td);
|
|
379
|
-
tbody.appendChild(tr);
|
|
380
|
-
} else {
|
|
381
|
-
visibleData.forEach((row, ri) => {
|
|
382
|
-
const tr = document.createElement("tr");
|
|
383
|
-
tr.dataset.rowIndex = String(windowStart + ri);
|
|
384
|
-
// One tab stop per grid, not one per row: every row is -1 and the
|
|
385
|
-
// arrow keys move a roving tabindex. A 1,000-row table was 1,000
|
|
386
|
-
// tab stops before this.
|
|
387
|
-
tr.setAttribute("tabindex", "-1");
|
|
388
|
-
cols.forEach((c, ci) => {
|
|
389
|
-
const isSelect = (typeof c === "object" && c !== null && c.select);
|
|
390
|
-
const td = document.createElement("td");
|
|
391
|
-
if (isSelect) {
|
|
392
|
-
const cb = document.createElement("input");
|
|
393
|
-
cb.type = "checkbox";
|
|
394
|
-
cb.className = "c-table__row-select";
|
|
395
|
-
cb.dataset.rowIndex = String(windowStart + ri);
|
|
396
|
-
if (this._selectedRows && this._selectedRows.has(windowStart + ri)) cb.checked = true;
|
|
397
|
-
td.appendChild(cb);
|
|
398
|
-
} else {
|
|
399
|
-
td.textContent = this._cellValue(row[ci]);
|
|
400
|
-
}
|
|
401
|
-
tr.appendChild(td);
|
|
402
|
-
});
|
|
403
|
-
tbody.appendChild(tr);
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
if (useVirtual) addSpacer(Math.max(0, pageData.length - windowStart - visibleData.length) * rowHeight);
|
|
407
|
-
// Keep exactly one row in the tab order: the first rendered row when
|
|
408
|
-
// none is active yet, so the grid is a single tab stop.
|
|
409
|
-
if (!tbody.querySelector('tr[tabindex="0"]')) {
|
|
410
|
-
const first = tbody.querySelector("tr[data-row-index]");
|
|
411
|
-
if (first) first.setAttribute("tabindex", "0");
|
|
412
|
-
}
|
|
413
|
-
// Measure a real row so the virtual window uses the rendered height,
|
|
414
|
-
// not a guess: the old fixed 36px disagreed with the measured 64.1px,
|
|
415
|
-
// so the spacers and the scroll math were both wrong.
|
|
416
|
-
if (!this._measuredRowHeight && !this._measuringRow) {
|
|
417
|
-
const firstRow = tbody.querySelector("tr[data-row-index]");
|
|
418
|
-
const h = firstRow ? firstRow.getBoundingClientRect().height : 0;
|
|
419
|
-
if (h > 0) {
|
|
420
|
-
this._measuredRowHeight = h;
|
|
421
|
-
if (Math.abs(h - rowHeight) > 1) {
|
|
422
|
-
this._measuringRow = true;
|
|
423
|
-
requestAnimationFrame(() => { this._measuringRow = false; this.render(); });
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
if (table.parentNode !== wrap) {
|
|
428
|
-
wrap.innerHTML = "";
|
|
429
|
-
wrap.appendChild(table);
|
|
430
|
-
}
|
|
431
|
-
if (wrap.parentNode !== this) this.appendChild(wrap);
|
|
432
|
-
// Optional fixed-row DOM windowing for large datasets. Opt-in via `virtual`.
|
|
433
|
-
if (this.hasAttribute("virtual")) {
|
|
434
|
-
wrap.style.maxHeight = wrap.style.maxHeight || "24rem";
|
|
435
|
-
wrap.style.overflow = "auto";
|
|
436
|
-
table.classList.add("c-table--virtual");
|
|
437
|
-
} else {
|
|
438
|
-
wrap.style.maxHeight = "";
|
|
439
|
-
wrap.style.overflow = "";
|
|
440
|
-
table.classList.remove("c-table--virtual");
|
|
441
|
-
}
|
|
442
|
-
// Pagination footer.
|
|
443
|
-
if (usePaging) {
|
|
444
|
-
const footer = this.ensure(".c-table__pagination", () => { const el = document.createElement("div"); el.className = "c-table__pagination"; return el; });
|
|
445
|
-
footer.innerHTML = "";
|
|
446
|
-
const prev = document.createElement("button");
|
|
447
|
-
prev.className = "c-btn c-btn--ghost c-btn--sm";
|
|
448
|
-
prev.type = "button";
|
|
449
|
-
prev.textContent = labelText(this, "prev", "Previous");
|
|
450
|
-
prev.disabled = page <= 1;
|
|
451
|
-
prev.dataset.action = "prev";
|
|
452
|
-
const info = document.createElement("span");
|
|
453
|
-
info.textContent = `${labelText(this, "page", "Page")} ${page} ${labelText(this, "of", "of")} ${totalPages}`;
|
|
454
|
-
const next = document.createElement("button");
|
|
455
|
-
next.className = "c-btn c-btn--ghost c-btn--sm";
|
|
456
|
-
next.type = "button";
|
|
457
|
-
next.textContent = labelText(this, "next", "Next");
|
|
458
|
-
next.disabled = page >= totalPages;
|
|
459
|
-
next.dataset.action = "next";
|
|
460
|
-
footer.appendChild(prev);
|
|
461
|
-
footer.appendChild(info);
|
|
462
|
-
footer.appendChild(next);
|
|
463
|
-
} else {
|
|
464
|
-
const footer = this.querySelector(".c-table__pagination");
|
|
465
|
-
if (footer) footer.remove();
|
|
466
|
-
}
|
|
467
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
468
|
-
} else if (!rows && !authored.length) {
|
|
469
|
-
renderEmpty(this, "table");
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
enhance() {
|
|
473
|
-
if (this._wiredTable) return;
|
|
474
|
-
this._wiredTable = true;
|
|
475
|
-
const handleSort = (th) => {
|
|
476
|
-
const idx = Number(th.dataset.sortIndex);
|
|
477
|
-
if (!Number.isFinite(idx)) return;
|
|
478
|
-
if (this._sortCol === idx) {
|
|
479
|
-
this._sortDir = (this._sortDir === 1) ? -1 : 1;
|
|
480
|
-
} else {
|
|
481
|
-
this._sortCol = idx;
|
|
482
|
-
this._sortDir = 1;
|
|
483
|
-
}
|
|
484
|
-
this.dispatchEvent(new CustomEvent("contour:sort", { bubbles: true, composed: true, detail: { column: idx, direction: this._sortDir === 1 ? "ascending" : "descending" } }));
|
|
485
|
-
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { sort: idx, sortDir: this._sortDir === 1 ? "ascending" : "descending" } } }));
|
|
486
|
-
this.requestRender();
|
|
487
|
-
};
|
|
488
|
-
this.addEventListener("click", (e) => {
|
|
489
|
-
const retryBtn = e.target && e.target.closest ? e.target.closest('button[data-action="retry"]') : null;
|
|
490
|
-
if (retryBtn && this.contains(retryBtn)) {
|
|
491
|
-
e.preventDefault();
|
|
492
|
-
this.dispatchEvent(new CustomEvent("contour:retry", { detail: { src: this.getAttribute("src") }, bubbles: true, composed: true }));
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
const th = e.target && e.target.closest ? e.target.closest("th[aria-sort]") : null;
|
|
496
|
-
if (th && this.contains(th)) {
|
|
497
|
-
e.preventDefault();
|
|
498
|
-
handleSort(th);
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-table__pagination button") : null;
|
|
502
|
-
if (btn && this.contains(btn)) {
|
|
503
|
-
e.preventDefault();
|
|
504
|
-
const action = btn.dataset.action;
|
|
505
|
-
let page = this._page !== null ? this._page : (parseInt(this.getAttribute("page") || "1", 10));
|
|
506
|
-
if (!Number.isFinite(page) || page < 1) page = 1;
|
|
507
|
-
if (action === "prev" && page > 1) page -= 1;
|
|
508
|
-
if (action === "next") page += 1;
|
|
509
|
-
this._page = page;
|
|
510
|
-
this._pageAttrLast = String(page);
|
|
511
|
-
// Reflect the page on the host so consumers can key off the attribute
|
|
512
|
-
// (D-04). Marked internal so the resulting render preserves _page
|
|
513
|
-
// instead of nulling it (B3-01).
|
|
514
|
-
this._pageInternal = true;
|
|
515
|
-
this.setAttribute("page", String(page));
|
|
516
|
-
this.dispatchEvent(new CustomEvent("contour:page", { bubbles: true, composed: true, detail: { page } }));
|
|
517
|
-
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { page } } }));
|
|
518
|
-
const persist = this.getAttribute("persist");
|
|
519
|
-
if (persist === "storage" && this.id) { try { localStorage.setItem("contour-table:" + this.id, String(page)); } catch (e) {} }
|
|
520
|
-
else if (persist === "url") { try { const url = new URL(window.location.href); url.searchParams.set("c-table", String(page)); window.history.replaceState(null, "", url.toString()); } catch (e) {} }
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
this.addEventListener("keydown", (e) => {
|
|
524
|
-
if (e.key !== "Enter" && e.key !== " ") return;
|
|
525
|
-
const th = e.target && e.target.closest ? e.target.closest("th[aria-sort]") : null;
|
|
526
|
-
if (th && this.contains(th)) {
|
|
527
|
-
e.preventDefault();
|
|
528
|
-
handleSort(th);
|
|
529
|
-
}
|
|
530
|
-
});
|
|
531
|
-
// Column filter (F-09): re-render on filter input change.
|
|
532
|
-
this.addEventListener("input", (e) => {
|
|
533
|
-
const inp = e.target && e.target.closest ? e.target.closest(".c-table__filter-input") : null;
|
|
534
|
-
if (!inp || !this.contains(inp)) return;
|
|
535
|
-
const idx = Number(inp.dataset.filterIndex);
|
|
536
|
-
if (!Number.isFinite(idx)) return;
|
|
537
|
-
if (!this._filters) this._filters = {};
|
|
538
|
-
this._filters[idx] = inp.value;
|
|
539
|
-
this.requestRender();
|
|
540
|
-
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { column: idx, value: inp.value } } }));
|
|
541
|
-
});
|
|
542
|
-
this.addEventListener("scroll", (e) => {
|
|
543
|
-
if (!this.hasAttribute("virtual") || !e.target || !e.target.classList || !e.target.classList.contains("c-table-wrap")) return;
|
|
544
|
-
if (this._tableVirtualRaf) return;
|
|
545
|
-
const run = () => { this._tableVirtualRaf = 0; this.requestRender(); };
|
|
546
|
-
this._tableVirtualRaf = typeof requestAnimationFrame === "function" ? requestAnimationFrame(run) : setTimeout(run, 16);
|
|
547
|
-
}, true);
|
|
548
|
-
// Row selection (F-09): track checked rows and emit contour:select.
|
|
549
|
-
this._selectedRows = this._selectedRows || new Set();
|
|
550
|
-
this.addEventListener("change", (e) => {
|
|
551
|
-
const cb = e.target && e.target.closest ? e.target.closest(".c-table__row-select") : null;
|
|
552
|
-
if (cb && this.contains(cb)) {
|
|
553
|
-
const idx = Number(cb.dataset.rowIndex);
|
|
554
|
-
if (!Number.isFinite(idx)) return;
|
|
555
|
-
if (cb.checked) this._selectedRows.add(idx); else this._selectedRows.delete(idx);
|
|
556
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { rows: Array.from(this._selectedRows) } }));
|
|
557
|
-
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { selectedRows: Array.from(this._selectedRows) } } }));
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
const all = e.target && e.target.closest ? e.target.closest(".c-table__select-all") : null;
|
|
561
|
-
if (all && this.contains(all)) {
|
|
562
|
-
const cbs = Array.from(this.querySelectorAll(".c-table__row-select"));
|
|
563
|
-
cbs.forEach((c) => { c.checked = all.checked; });
|
|
564
|
-
this._selectedRows = new Set(all.checked ? cbs.map((c) => Number(c.dataset.rowIndex)) : []);
|
|
565
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { rows: Array.from(this._selectedRows) } }));
|
|
566
|
-
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { selectedRows: Array.from(this._selectedRows) } } }));
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
|
-
// Map-linked table (CARTO-inspired): emit contour:hover on row hover so a
|
|
570
|
-
// consumer can highlight/zoom the corresponding feature on the map.
|
|
571
|
-
// Contour stays engine-agnostic: it only announces the row.
|
|
572
|
-
this.addEventListener("mouseover", (e) => {
|
|
573
|
-
const tr = e.target && e.target.closest ? e.target.closest("tbody tr") : null;
|
|
574
|
-
if (!tr || !this.contains(tr)) return;
|
|
575
|
-
const idx = Number(tr.dataset.rowIndex);
|
|
576
|
-
if (!Number.isFinite(idx)) return;
|
|
577
|
-
if (this._hoveredRow === idx) return;
|
|
578
|
-
this._hoveredRow = idx;
|
|
579
|
-
this.dispatchEvent(new CustomEvent("contour:hover", { bubbles: true, composed: true, detail: { row: idx } }));
|
|
580
|
-
});
|
|
581
|
-
this.addEventListener("mouseout", (e) => {
|
|
582
|
-
const tr = e.target && e.target.closest ? e.target.closest("tbody tr") : null;
|
|
583
|
-
if (!tr || !this.contains(tr)) return;
|
|
584
|
-
const related = e.relatedTarget && e.relatedTarget.closest ? e.relatedTarget.closest("tbody tr") : null;
|
|
585
|
-
if (related === tr) return;
|
|
586
|
-
this._hoveredRow = null;
|
|
587
|
-
this.dispatchEvent(new CustomEvent("contour:leave", { bubbles: true, composed: true, detail: {} }));
|
|
588
|
-
});
|
|
589
|
-
// Map-linked table (R16-17): click-to-zoom on a row emits contour:zoom so
|
|
590
|
-
// a map consumer can zoom to the corresponding feature. Contour stays
|
|
591
|
-
// engine-agnostic: it only announces the row index and data.
|
|
592
|
-
this.addEventListener("click", (e) => {
|
|
593
|
-
const tr = e.target && e.target.closest ? e.target.closest("tbody tr") : null;
|
|
594
|
-
if (!tr || !this.contains(tr)) return;
|
|
595
|
-
const idx = Number(tr.dataset.rowIndex);
|
|
596
|
-
if (!Number.isFinite(idx)) return;
|
|
597
|
-
const rowData = (this._rowData && this._rowData[idx]) || null;
|
|
598
|
-
this.dispatchEvent(new CustomEvent("contour:zoom", { bubbles: true, composed: true, detail: { row: idx, index: idx, data: rowData } }));
|
|
599
|
-
});
|
|
600
|
-
this.addEventListener("keydown", (e) => {
|
|
601
|
-
const tr = e.target && e.target.closest ? e.target.closest("tbody tr") : null;
|
|
602
|
-
if (!tr || !this.contains(tr)) return;
|
|
603
|
-
const idx = Number(tr.dataset.rowIndex);
|
|
604
|
-
if (!Number.isFinite(idx)) return;
|
|
605
|
-
// Roving tabindex: arrows move the single tab stop, Home/End jump.
|
|
606
|
-
if (e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "Home" || e.key === "End") {
|
|
607
|
-
const rows = Array.from(this.querySelectorAll("tbody tr[data-row-index]"));
|
|
608
|
-
const at = rows.indexOf(tr);
|
|
609
|
-
let next = at;
|
|
610
|
-
if (e.key === "ArrowDown") next = Math.min(rows.length - 1, at + 1);
|
|
611
|
-
else if (e.key === "ArrowUp") next = Math.max(0, at - 1);
|
|
612
|
-
else if (e.key === "Home") next = 0;
|
|
613
|
-
else if (e.key === "End") next = rows.length - 1;
|
|
614
|
-
if (next !== at && rows[next]) {
|
|
615
|
-
e.preventDefault();
|
|
616
|
-
rows.forEach((r) => r.setAttribute("tabindex", "-1"));
|
|
617
|
-
rows[next].setAttribute("tabindex", "0");
|
|
618
|
-
try { rows[next].focus(); } catch (err) {}
|
|
619
|
-
}
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
|
-
if (e.key !== "Enter" && e.key !== " ") return;
|
|
623
|
-
e.preventDefault();
|
|
624
|
-
this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true, detail: { row: idx } }));
|
|
625
|
-
});
|
|
626
|
-
// Cross-filter contract (R16-16): clear-all resets table sort/page/filter state.
|
|
627
|
-
this.addEventListener("contour:clear-all", () => {
|
|
628
|
-
let changed = false;
|
|
629
|
-
if (this.hasAttribute("sort")) { this.removeAttribute("sort"); changed = true; }
|
|
630
|
-
if (this.hasAttribute("sort-dir")) { this.removeAttribute("sort-dir"); changed = true; }
|
|
631
|
-
if (this.hasAttribute("page")) { this.removeAttribute("page"); changed = true; }
|
|
632
|
-
if (this._filters && Object.keys(this._filters).length) { this._filters = {}; changed = true; }
|
|
633
|
-
if (changed) {
|
|
634
|
-
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { sort: null, sortDir: null, page: null, filters: null } } }));
|
|
635
|
-
this.requestRender();
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
define("contour-table", ContourTable);
|
|
641
|
-
class ContourDataTable extends ContourTable {
|
|
642
|
-
render() {
|
|
643
|
-
super.render();
|
|
644
|
-
this.classList.add("c-data-table");
|
|
645
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Data table");
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
define("contour-data-table", ContourDataTable);
|
|
649
|
-
|
|
650
|
-
/**
|
|
651
|
-
* Coerce a histogram bin into the published shape.
|
|
652
|
-
*
|
|
653
|
-
* A bin may arrive from the author (`series[].bins`) or be pushed by a binder
|
|
654
|
-
* (`chart.bins = …`). Both go through here so `bins` reads back the same way
|
|
655
|
-
* whichever door it came through, and a malformed entry is dropped rather than
|
|
656
|
-
* rendered as NaN geometry.
|
|
657
|
-
*/
|
|
658
|
-
const normalizeChartBin = (bin) => {
|
|
659
|
-
if (!bin || typeof bin !== "object") return null;
|
|
660
|
-
const x0 = Number(bin.x0);
|
|
661
|
-
const x1 = Number(bin.x1);
|
|
662
|
-
const count = Number(bin.count);
|
|
663
|
-
if (!Number.isFinite(x0) || !Number.isFinite(x1) || !Number.isFinite(count)) return null;
|
|
664
|
-
const out = { x0, x1, count };
|
|
665
|
-
const normalized = Number(bin.normalized);
|
|
666
|
-
if (Number.isFinite(normalized)) out.normalized = normalized;
|
|
667
|
-
return out;
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
/**
|
|
671
|
-
* Chart: web component wrapper.
|
|
672
|
-
* Attributes: `series`, `axis`, `empty`, `loading`, `error`, `retry`, `skeleton`, `zoomable`, `data-table`, `brush`, `brush-min`, `brush-max`, `brush-start`, `brush-end`.
|
|
673
|
-
*/
|
|
674
|
-
class ContourChart extends ContourBase {
|
|
675
|
-
static get updateMode() { return "keyed"; }
|
|
676
|
-
static get observed() { return ["series", "axis", "color", "empty", "loading", "error", "retry", "skeleton", "zoomable", "data-table", "brush", "brush-min", "brush-max", "brush-start", "brush-end", "note", "bucket-count", "limit-values"]; }
|
|
677
|
-
static get properties() { return { series: { attribute: "series" }, axis: { attribute: "axis" }, color: { attribute: "color" }, zoomable: { attribute: "zoomable", type: Boolean }, brush: { attribute: "brush", type: Boolean }, note: { attribute: "note" }, "bucket-count": { attribute: "bucket-count" }, "limit-values": { attribute: "limit-values" } }; }
|
|
678
|
-
// Bindable histogram contract (R18-68). A histogram consumer drives a widget
|
|
679
|
-
// by assigning `bins` / `backgroundData` and reading `range`; libreship's
|
|
680
|
-
// `bindHistogram` is the one this was written against, and it writes those
|
|
681
|
-
// three as JS properties, not attributes. These accessors are the widget's
|
|
682
|
-
// side of that contract: a push re-renders, and a read returns the bins
|
|
683
|
-
// actually drawn rather than the last thing someone assigned.
|
|
684
|
-
get bins() {
|
|
685
|
-
const pushed = this._pushedBins;
|
|
686
|
-
return (pushed && pushed.length ? pushed : this._renderedBins || []).map((b) => ({ ...b }));
|
|
687
|
-
}
|
|
688
|
-
set bins(value) {
|
|
689
|
-
this._pushedBins = Array.isArray(value) ? value.map(normalizeChartBin).filter(Boolean) : [];
|
|
690
|
-
this.requestRender();
|
|
691
|
-
}
|
|
692
|
-
get backgroundData() {
|
|
693
|
-
const pushed = this._pushedBackground;
|
|
694
|
-
return (pushed && pushed.length ? pushed : this._renderedBackground || []).map((b) => ({ ...b }));
|
|
695
|
-
}
|
|
696
|
-
set backgroundData(value) {
|
|
697
|
-
this._pushedBackground = Array.isArray(value) ? value.map(normalizeChartBin).filter(Boolean) : [];
|
|
698
|
-
this.requestRender();
|
|
699
|
-
}
|
|
700
|
-
// `range` is a JS property, not an attribute write: the chart observes
|
|
701
|
-
// brush/brush-start/brush-end, so a setter that called `setAttribute` on
|
|
702
|
-
// itself would fire the callback that renders it (wc-contract's re-entrancy
|
|
703
|
-
// rule). The override is consumed by render() and never reflected back into
|
|
704
|
-
// attributes, which stay the author's.
|
|
705
|
-
_showsBrush() {
|
|
706
|
-
return this.hasAttribute("brush") || this._rangeOverride !== undefined;
|
|
707
|
-
}
|
|
708
|
-
get range() {
|
|
709
|
-
const override = this._rangeOverride;
|
|
710
|
-
if (override !== undefined) return override ? override.slice() : null;
|
|
711
|
-
if (!this.hasAttribute("brush")) return null;
|
|
712
|
-
const start = parseFloat(this.getAttribute("brush-start"));
|
|
713
|
-
const end = parseFloat(this.getAttribute("brush-end"));
|
|
714
|
-
return Number.isFinite(start) && Number.isFinite(end) ? [start, end] : null;
|
|
715
|
-
}
|
|
716
|
-
set range(value) {
|
|
717
|
-
if (value == null) {
|
|
718
|
-
this._rangeOverride = null;
|
|
719
|
-
this.requestRender();
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
722
|
-
const pair = Array.isArray(value) ? value : [value, value];
|
|
723
|
-
const start = Number(pair[0]);
|
|
724
|
-
const end = Number(pair[1]);
|
|
725
|
-
if (!Number.isFinite(start) || !Number.isFinite(end)) return;
|
|
726
|
-
this._rangeOverride = [start, end];
|
|
727
|
-
this.requestRender();
|
|
728
|
-
}
|
|
729
|
-
_axisLabel() {
|
|
730
|
-
const raw = this.getAttribute("axis");
|
|
731
|
-
if (!raw) return "";
|
|
732
|
-
try {
|
|
733
|
-
const parsed = JSON.parse(raw);
|
|
734
|
-
if (parsed && typeof parsed === "object") return parsed.label || parsed.title || parsed.name || "";
|
|
735
|
-
return String(parsed);
|
|
736
|
-
} catch (e) { return raw; }
|
|
737
|
-
}
|
|
738
|
-
_axisConfig() {
|
|
739
|
-
const raw = this.getAttribute("axis");
|
|
740
|
-
if (!raw) return null;
|
|
741
|
-
try {
|
|
742
|
-
const parsed = JSON.parse(raw);
|
|
743
|
-
return (parsed && typeof parsed === "object") ? parsed : null;
|
|
744
|
-
} catch (e) { return null; }
|
|
745
|
-
}
|
|
746
|
-
_valueDomain() {
|
|
747
|
-
const series = this.getAttribute("series");
|
|
748
|
-
if (!series) return null;
|
|
749
|
-
try {
|
|
750
|
-
const parsed = JSON.parse(series);
|
|
751
|
-
let min = Infinity, max = -Infinity;
|
|
752
|
-
(Array.isArray(parsed) ? parsed : []).forEach((s) => {
|
|
753
|
-
if (s && Array.isArray(s.values)) s.values.forEach((v) => {
|
|
754
|
-
const n = Number(v);
|
|
755
|
-
if (Number.isFinite(n)) { if (n < min) min = n; if (n > max) max = n; }
|
|
756
|
-
});
|
|
757
|
-
});
|
|
758
|
-
return Number.isFinite(min) && Number.isFinite(max) ? [min, max] : null;
|
|
759
|
-
} catch (e) { return null; }
|
|
760
|
-
}
|
|
761
|
-
_renderValueAxis() {
|
|
762
|
-
const ax = this.querySelector(".c-chart__axis");
|
|
763
|
-
if (!ax) return;
|
|
764
|
-
const cfg = this._axisConfig();
|
|
765
|
-
const y = cfg && cfg.y;
|
|
766
|
-
const domain = (y && y.domain) || this._valueDomain();
|
|
767
|
-
if (!domain) { ax.textContent = this._axisLabel(); return; }
|
|
768
|
-
const chart = (typeof window !== "undefined" && window.Contour && window.Contour.chart) || null;
|
|
769
|
-
const ticks = (y && y.ticks) || (chart && chart.ticks ? chart.ticks(domain[0], domain[1], 5) : [domain[0], domain[1]]);
|
|
770
|
-
const format = (y && y.format) || ((v) => String(v));
|
|
771
|
-
ax.textContent = "";
|
|
772
|
-
ticks.forEach((t) => {
|
|
773
|
-
const span = document.createElement("span");
|
|
774
|
-
span.className = "c-chart__tick";
|
|
775
|
-
span.textContent = typeof format === "function" ? format(t) : String(t);
|
|
776
|
-
ax.appendChild(span);
|
|
777
|
-
});
|
|
778
|
-
this.style.setProperty("--chart-ticks", String(ticks.length));
|
|
779
|
-
}
|
|
780
|
-
_renderLegend() {
|
|
781
|
-
const series = this.getAttribute("series");
|
|
782
|
-
if (!series) return;
|
|
783
|
-
try {
|
|
784
|
-
const parsed = JSON.parse(series);
|
|
785
|
-
const labelled = (Array.isArray(parsed) ? parsed : []).filter((s) => s && s.label);
|
|
786
|
-
let legend = this.querySelector(".c-chart__legend");
|
|
787
|
-
if (!labelled.length) { if (legend) legend.remove(); return; }
|
|
788
|
-
if (!legend) { legend = document.createElement("div"); legend.className = "c-chart__legend"; this.appendChild(legend); }
|
|
789
|
-
legend.textContent = "";
|
|
790
|
-
labelled.forEach((s, i) => {
|
|
791
|
-
const item = document.createElement("span");
|
|
792
|
-
item.className = "c-chart__legend-item";
|
|
793
|
-
const swatch = document.createElement("span");
|
|
794
|
-
swatch.className = "c-chart__legend-swatch";
|
|
795
|
-
swatch.style.setProperty("--c", this.getAttribute("color") || `var(--chart-${i + 1})`);
|
|
796
|
-
item.appendChild(swatch);
|
|
797
|
-
item.appendChild(document.createTextNode(s.label));
|
|
798
|
-
legend.appendChild(item);
|
|
799
|
-
});
|
|
800
|
-
} catch (e) { /* ignore */ }
|
|
801
|
-
}
|
|
802
|
-
render() {
|
|
803
|
-
this.classList.add("c-chart");
|
|
804
|
-
// A chart with brush handles has focusable descendants, which role="img"
|
|
805
|
-
// forbids (an img is a leaf). A named group exposes the marks and keeps
|
|
806
|
-
// the controls reachable; the data table remains the alternative.
|
|
807
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
808
|
-
if (!this.hasAttribute("aria-roledescription")) this.setAttribute("aria-roledescription", "chart");
|
|
809
|
-
if (this.getAttribute("axis") && !this.hasAttribute("aria-label")) this.setAttribute("aria-label", this._axisLabel());
|
|
810
|
-
if (this.hasAttribute("loading")) {
|
|
811
|
-
const plot = this.ensure(".c-chart__plot", () => { const el = document.createElement("div"); el.className = "c-chart__plot"; return el; });
|
|
812
|
-
plot.innerHTML = "";
|
|
813
|
-
const loading = document.createElement("div");
|
|
814
|
-
loading.className = "c-chart__loading";
|
|
815
|
-
loading.textContent = this.getAttribute("loading") || "Loading…";
|
|
816
|
-
loading.style.display = "grid";
|
|
817
|
-
loading.style.placeItems = "center";
|
|
818
|
-
loading.style.height = "100%";
|
|
819
|
-
loading.style.color = "var(--color-text-muted)";
|
|
820
|
-
plot.appendChild(loading);
|
|
821
|
-
const axis = this.getAttribute("axis");
|
|
822
|
-
if (axis) {
|
|
823
|
-
const ax = this.ensure(".c-chart__axis", () => { const el = document.createElement("div"); el.className = "c-chart__axis"; return el; });
|
|
824
|
-
ax.textContent = this._axisLabel();
|
|
825
|
-
}
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
if (this.hasAttribute("error")) {
|
|
829
|
-
const plot = this.ensure(".c-chart__plot", () => { const el = document.createElement("div"); el.className = "c-chart__plot"; return el; });
|
|
830
|
-
plot.innerHTML = "";
|
|
831
|
-
const err = document.createElement("div");
|
|
832
|
-
err.className = "c-chart__error";
|
|
833
|
-
err.textContent = this.getAttribute("error") || "Error";
|
|
834
|
-
err.style.display = "grid";
|
|
835
|
-
err.style.placeItems = "center";
|
|
836
|
-
err.style.height = "100%";
|
|
837
|
-
err.style.color = "var(--color-danger, var(--color-text))";
|
|
838
|
-
if (this.hasAttribute("retry")) {
|
|
839
|
-
const btn = document.createElement("button");
|
|
840
|
-
btn.className = "c-btn c-btn--ghost c-btn--sm";
|
|
841
|
-
btn.type = "button";
|
|
842
|
-
btn.textContent = this.getAttribute("retry") || "Retry";
|
|
843
|
-
btn.dataset.action = "retry";
|
|
844
|
-
btn.classList.add("u-mbs-sm");
|
|
845
|
-
err.appendChild(btn);
|
|
846
|
-
}
|
|
847
|
-
plot.appendChild(err);
|
|
848
|
-
const axis = this.getAttribute("axis");
|
|
849
|
-
if (axis) {
|
|
850
|
-
const ax = this.ensure(".c-chart__axis", () => { const el = document.createElement("div"); el.className = "c-chart__axis"; return el; });
|
|
851
|
-
ax.textContent = this._axisLabel();
|
|
852
|
-
}
|
|
853
|
-
return;
|
|
854
|
-
}
|
|
855
|
-
if (this.hasAttribute("skeleton")) {
|
|
856
|
-
const plot = this.ensure(".c-chart__plot", () => { const el = document.createElement("div"); el.className = "c-chart__plot"; return el; });
|
|
857
|
-
plot.innerHTML = "";
|
|
858
|
-
const count = Math.min(5, Math.max(1, parseInt(this.getAttribute("skeleton") || "3", 10) || 3));
|
|
859
|
-
for (let i = 0; i < count; i++) {
|
|
860
|
-
const sk = document.createElement("div");
|
|
861
|
-
sk.className = "c-skeleton";
|
|
862
|
-
sk.style.display = "block";
|
|
863
|
-
sk.style.inlineSize = "100%";
|
|
864
|
-
sk.style.blockSize = "0.6rem";
|
|
865
|
-
sk.classList.add("u-mbe-2xs");
|
|
866
|
-
plot.appendChild(sk);
|
|
867
|
-
}
|
|
868
|
-
const axis = this.getAttribute("axis");
|
|
869
|
-
if (axis) {
|
|
870
|
-
const ax = this.ensure(".c-chart__axis", () => { const el = document.createElement("div"); el.className = "c-chart__axis"; return el; });
|
|
871
|
-
ax.textContent = this._axisLabel();
|
|
872
|
-
}
|
|
873
|
-
return;
|
|
874
|
-
}
|
|
875
|
-
const axis = this.getAttribute("axis");
|
|
876
|
-
if (axis) {
|
|
877
|
-
const ax = this.ensure(".c-chart__axis", () => { const el = document.createElement("div"); el.className = "c-chart__axis"; return el; });
|
|
878
|
-
ax.textContent = this._axisLabel();
|
|
879
|
-
} else {
|
|
880
|
-
const ax = this.querySelector(".c-chart__axis");
|
|
881
|
-
if (ax) ax.remove();
|
|
882
|
-
}
|
|
883
|
-
// Value axis: when `axis` is {y:{domain,ticks,format}} (or the series
|
|
884
|
-
// carries values), print the ticks and publish --chart-ticks.
|
|
885
|
-
this._renderValueAxis();
|
|
886
|
-
// Legend from series[].label, so a chart with named series is readable
|
|
887
|
-
// without the consumer hand-building a legend.
|
|
888
|
-
this._renderLegend();
|
|
889
|
-
// A bindable histogram may be driven by `bins` alone: a binder pushes the
|
|
890
|
-
// engine's distribution rather than serialising a `series` attribute, so with
|
|
891
|
-
// no series declared the pushed bins become the series this render reads.
|
|
892
|
-
let series = this.getAttribute("series");
|
|
893
|
-
if (!series && this._pushedBins && this._pushedBins.length) {
|
|
894
|
-
series = JSON.stringify([{ type: "histogram", bins: this._pushedBins }]);
|
|
895
|
-
}
|
|
896
|
-
if (series) {
|
|
897
|
-
let parsed = null;
|
|
898
|
-
try {
|
|
899
|
-
parsed = JSON.parse(series);
|
|
900
|
-
const plot = this.ensure(".c-chart__plot", () => { const el = document.createElement("div"); el.className = "c-chart__plot"; return el; });
|
|
901
|
-
plot.innerHTML = "";
|
|
902
|
-
// Structured series: an item may carry `values` plus a `type`
|
|
903
|
-
// ("donut" | "histogram" | "line") instead of a pre-computed `d`
|
|
904
|
-
// path, or carry pre-binned `bins` instead of raw `values`. The
|
|
905
|
-
// helpers in svg.mjs turn those into geometry so a consumer does
|
|
906
|
-
// not have to hand-compute arc or bar math.
|
|
907
|
-
const hasStructured = parsed.some((s) => s && (Array.isArray(s.values) || Array.isArray(s.bins)));
|
|
908
|
-
if (hasStructured) {
|
|
909
|
-
// Each structured render rebuilds the published bins from the
|
|
910
|
-
// series it draws; without this a chart switched from a histogram
|
|
911
|
-
// to a line keeps reporting the old distribution.
|
|
912
|
-
this._renderedBins = [];
|
|
913
|
-
this._renderedBackground = [];
|
|
914
|
-
parsed.forEach((s, i) => {
|
|
915
|
-
const layerColor = this.getAttribute("color");
|
|
916
|
-
const color = layerColor || `var(--chart-${i + 1})`;
|
|
917
|
-
if (s.type === "donut") {
|
|
918
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
919
|
-
svg.setAttribute("viewBox", "0 0 200 200");
|
|
920
|
-
svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
|
|
921
|
-
svg.setAttribute("aria-hidden", "true");
|
|
922
|
-
donutSlices(s.values).forEach((sl, si) => {
|
|
923
|
-
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
924
|
-
path.setAttribute("class", "c-chart__line");
|
|
925
|
-
path.setAttribute("data-series", String(i + 1));
|
|
926
|
-
path.style.setProperty("--c", color);
|
|
927
|
-
path.setAttribute("d", sl.path);
|
|
928
|
-
path.setAttribute("title", String(s.values[si]));
|
|
929
|
-
path.setAttribute("aria-label", "Series " + (i + 1) + ": " + String(s.values[si]));
|
|
930
|
-
path.setAttribute("role", "img");
|
|
931
|
-
svg.appendChild(path);
|
|
932
|
-
});
|
|
933
|
-
plot.appendChild(svg);
|
|
934
|
-
} else if (s.type === "bar") {
|
|
935
|
-
// A bar series is the histogram's geometry without the
|
|
936
|
-
// bucketing: one rect per value, in value order. The
|
|
937
|
-
// histogram branch bins its input into equal-width buckets
|
|
938
|
-
// and plots the counts, which is a different question, so
|
|
939
|
-
// `bar` cannot be folded into it. `barRects()` already
|
|
940
|
-
// normalises the values against the plot box, so the only
|
|
941
|
-
// difference here is that `plotVals` is the series itself.
|
|
942
|
-
const vals = Array.isArray(s.values) ? s.values : [];
|
|
943
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
944
|
-
svg.setAttribute("viewBox", "0 0 300 120");
|
|
945
|
-
svg.setAttribute("preserveAspectRatio", "none");
|
|
946
|
-
svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
|
|
947
|
-
barRects(vals).forEach((r, ri) => {
|
|
948
|
-
const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
949
|
-
rect.setAttribute("class", "c-chart__bar");
|
|
950
|
-
rect.setAttribute("data-series", String(i + 1));
|
|
951
|
-
rect.style.setProperty("--c", color);
|
|
952
|
-
rect.setAttribute("x", r.x);
|
|
953
|
-
rect.setAttribute("y", r.y);
|
|
954
|
-
rect.setAttribute("width", r.width);
|
|
955
|
-
rect.setAttribute("height", r.height);
|
|
956
|
-
rect.setAttribute("title", String(vals[ri]));
|
|
957
|
-
rect.setAttribute("aria-label", "Series " + (i + 1) + ": " + String(vals[ri]));
|
|
958
|
-
rect.setAttribute("tabindex", "0");
|
|
959
|
-
rect.setAttribute("role", "button");
|
|
960
|
-
rect.dataset.index = String(ri);
|
|
961
|
-
svg.appendChild(rect);
|
|
962
|
-
});
|
|
963
|
-
plot.appendChild(svg);
|
|
964
|
-
} else if (s.type === "histogram") {
|
|
965
|
-
// R16-23: bucket-count / limit-values controls.
|
|
966
|
-
// `limit-values` truncates the input array; `bucket-count`
|
|
967
|
-
// bins values into equal-width buckets and renders the
|
|
968
|
-
// per-bucket counts as bars. R18-68 adds the other door: a
|
|
969
|
-
// series may arrive pre-binned (`bins`) or be pushed whole by
|
|
970
|
-
// a binder, and either way the boundaries are published as
|
|
971
|
-
// `chart.bins` so a consumer can read them back.
|
|
972
|
-
let vals = Array.isArray(s.values) ? s.values.slice() : [];
|
|
973
|
-
const limitValues = parseInt(this.getAttribute("limit-values") || "0", 10);
|
|
974
|
-
if (limitValues > 0) vals = vals.slice(0, limitValues);
|
|
975
|
-
const bucketCount = parseInt(this.getAttribute("bucket-count") || "0", 10);
|
|
976
|
-
const pushedBins = this._pushedBins && this._pushedBins.length ? this._pushedBins : null;
|
|
977
|
-
const declaredBins = Array.isArray(s.bins) ? s.bins.map(normalizeChartBin).filter(Boolean) : null;
|
|
978
|
-
let bins = pushedBins || (declaredBins && declaredBins.length ? declaredBins : null);
|
|
979
|
-
let plotVals = vals;
|
|
980
|
-
if (!bins && bucketCount > 0 && vals.length) {
|
|
981
|
-
const nums = vals.map((v) => Number(v) || 0);
|
|
982
|
-
const min = Math.min.apply(null, nums);
|
|
983
|
-
const max = Math.max.apply(null, nums);
|
|
984
|
-
const range = max - min || 1;
|
|
985
|
-
const width = range / bucketCount;
|
|
986
|
-
const buckets = new Array(bucketCount).fill(0);
|
|
987
|
-
nums.forEach((v) => {
|
|
988
|
-
const bi = Math.min(bucketCount - 1, Math.floor((v - min) / width));
|
|
989
|
-
buckets[bi] += 1;
|
|
990
|
-
});
|
|
991
|
-
plotVals = buckets;
|
|
992
|
-
bins = buckets.map((count, bi) => ({ x0: min + bi * width, x1: min + (bi + 1) * width, count }));
|
|
993
|
-
}
|
|
994
|
-
if (bins) plotVals = bins.map((b) => b.count);
|
|
995
|
-
// Raw values with no bucket count have no boundaries to
|
|
996
|
-
// publish: those bars are counts at index positions, not a
|
|
997
|
-
// distribution over a domain, so `bins` stays empty and the
|
|
998
|
-
// consumer is told there is nothing to map a range onto.
|
|
999
|
-
this._renderedBins = bins ? bins.slice() : [];
|
|
1000
|
-
const pushedBackground = this._pushedBackground && this._pushedBackground.length ? this._pushedBackground : null;
|
|
1001
|
-
const declaredBackground = Array.isArray(s.background) ? s.background.map(normalizeChartBin).filter(Boolean) : null;
|
|
1002
|
-
const background = pushedBackground || (declaredBackground && declaredBackground.length ? declaredBackground : []);
|
|
1003
|
-
this._renderedBackground = background.slice();
|
|
1004
|
-
const backgroundVals = background.map((b) => Number(b.count) || 0);
|
|
1005
|
-
let sharedMax = 1;
|
|
1006
|
-
if (backgroundVals.length) {
|
|
1007
|
-
plotVals.concat(backgroundVals).forEach((v) => { const n = Number(v) || 0; if (n > sharedMax) sharedMax = n; });
|
|
1008
|
-
}
|
|
1009
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1010
|
-
svg.setAttribute("viewBox", "0 0 300 120");
|
|
1011
|
-
svg.setAttribute("preserveAspectRatio", "none");
|
|
1012
|
-
svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
|
|
1013
|
-
if (backgroundVals.length) {
|
|
1014
|
-
// Context bars: the unfiltered distribution behind the
|
|
1015
|
-
// selection. Deliberately not focusable and not announced —
|
|
1016
|
-
// they are the backdrop the marks are read against, and a
|
|
1017
|
-
// second set of stops would double the tab sequence.
|
|
1018
|
-
barRects(backgroundVals, { max: sharedMax }).forEach((r) => {
|
|
1019
|
-
const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
1020
|
-
rect.setAttribute("class", "c-chart__bar");
|
|
1021
|
-
rect.setAttribute("data-context", "");
|
|
1022
|
-
rect.setAttribute("aria-hidden", "true");
|
|
1023
|
-
rect.style.setProperty("--c", color);
|
|
1024
|
-
rect.setAttribute("x", r.x);
|
|
1025
|
-
rect.setAttribute("y", r.y);
|
|
1026
|
-
rect.setAttribute("width", r.width);
|
|
1027
|
-
rect.setAttribute("height", r.height);
|
|
1028
|
-
svg.appendChild(rect);
|
|
1029
|
-
});
|
|
1030
|
-
}
|
|
1031
|
-
barRects(plotVals, backgroundVals.length ? { max: sharedMax } : undefined).forEach((r, ri) => {
|
|
1032
|
-
const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
1033
|
-
rect.setAttribute("class", "c-chart__bar");
|
|
1034
|
-
rect.setAttribute("data-series", String(i + 1));
|
|
1035
|
-
rect.style.setProperty("--c", color);
|
|
1036
|
-
rect.setAttribute("x", r.x);
|
|
1037
|
-
rect.setAttribute("y", r.y);
|
|
1038
|
-
rect.setAttribute("width", r.width);
|
|
1039
|
-
rect.setAttribute("height", r.height);
|
|
1040
|
-
const markValue = bins ? bins[ri].count : (Array.isArray(s.values) ? s.values[ri] : ri);
|
|
1041
|
-
rect.setAttribute("title", String(markValue));
|
|
1042
|
-
rect.setAttribute("aria-label", "Series " + (i + 1) + ": " + String(markValue));
|
|
1043
|
-
rect.setAttribute("tabindex", "0");
|
|
1044
|
-
rect.setAttribute("role", "button");
|
|
1045
|
-
rect.dataset.index = String(ri);
|
|
1046
|
-
svg.appendChild(rect);
|
|
1047
|
-
});
|
|
1048
|
-
plot.appendChild(svg);
|
|
1049
|
-
} else if (s.type === "scatter") {
|
|
1050
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1051
|
-
svg.setAttribute("viewBox", "0 0 300 120");
|
|
1052
|
-
svg.setAttribute("preserveAspectRatio", "none");
|
|
1053
|
-
svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
|
|
1054
|
-
const pts = (Array.isArray(s.values) ? s.values : []).map((v) => {
|
|
1055
|
-
if (Array.isArray(v)) return { x: Number(v[0]) || 0, y: Number(v[1]) || 0 };
|
|
1056
|
-
return { x: Number(v && v.x) || 0, y: Number(v && v.y) || 0 };
|
|
1057
|
-
});
|
|
1058
|
-
const xs = pts.map((p) => p.x);
|
|
1059
|
-
const ys = pts.map((p) => p.y);
|
|
1060
|
-
const minX = xs.length ? Math.min.apply(null, xs) : 0;
|
|
1061
|
-
const maxX = xs.length ? Math.max.apply(null, xs) : 1;
|
|
1062
|
-
const minY = ys.length ? Math.min.apply(null, ys) : 0;
|
|
1063
|
-
const maxY = ys.length ? Math.max.apply(null, ys) : 1;
|
|
1064
|
-
const xRange = (maxX - minX) || 1;
|
|
1065
|
-
const yRange = (maxY - minY) || 1;
|
|
1066
|
-
pts.forEach((p, pi) => {
|
|
1067
|
-
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
1068
|
-
circle.setAttribute("class", "c-chart__point");
|
|
1069
|
-
circle.setAttribute("data-series", String(i + 1));
|
|
1070
|
-
circle.setAttribute("data-index", String(pi));
|
|
1071
|
-
circle.style.setProperty("--c", color);
|
|
1072
|
-
const cx = ((p.x - minX) / xRange) * 300;
|
|
1073
|
-
const cy = 120 - ((p.y - minY) / yRange) * 120;
|
|
1074
|
-
circle.setAttribute("cx", cx.toFixed(2));
|
|
1075
|
-
circle.setAttribute("cy", cy.toFixed(2));
|
|
1076
|
-
circle.setAttribute("r", "3");
|
|
1077
|
-
circle.setAttribute("tabindex", pi === 0 ? "0" : "-1");
|
|
1078
|
-
circle.setAttribute("role", "button");
|
|
1079
|
-
circle.setAttribute("title", p.x + ", " + p.y);
|
|
1080
|
-
circle.setAttribute("aria-label", "Series " + (i + 1) + ": " + p.x + ", " + p.y);
|
|
1081
|
-
svg.appendChild(circle);
|
|
1082
|
-
});
|
|
1083
|
-
plot.appendChild(svg);
|
|
1084
|
-
} else {
|
|
1085
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1086
|
-
svg.setAttribute("viewBox", "0 0 300 120");
|
|
1087
|
-
svg.setAttribute("preserveAspectRatio", "none");
|
|
1088
|
-
svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
|
|
1089
|
-
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1090
|
-
path.setAttribute("class", "c-chart__line");
|
|
1091
|
-
path.setAttribute("data-series", String(i + 1));
|
|
1092
|
-
path.style.setProperty("--c", color);
|
|
1093
|
-
path.setAttribute("d", smoothPath(s.values));
|
|
1094
|
-
svg.appendChild(path);
|
|
1095
|
-
// Point markers for keyboard/click access.
|
|
1096
|
-
const pts = polylinePoints(s.values).split(" ").map((p) => p.split(",").map(Number));
|
|
1097
|
-
pts.forEach((pt, pi) => {
|
|
1098
|
-
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
1099
|
-
circle.setAttribute("class", "c-chart__point");
|
|
1100
|
-
circle.setAttribute("data-series", String(i + 1));
|
|
1101
|
-
circle.setAttribute("data-index", String(pi));
|
|
1102
|
-
circle.style.setProperty("--c", color);
|
|
1103
|
-
circle.setAttribute("cx", String(pt[0]));
|
|
1104
|
-
circle.setAttribute("cy", String(pt[1]));
|
|
1105
|
-
circle.setAttribute("r", "3");
|
|
1106
|
-
circle.setAttribute("tabindex", pi === 0 ? "0" : "-1");
|
|
1107
|
-
circle.setAttribute("role", "button");
|
|
1108
|
-
circle.setAttribute("title", String(s.values[pi]));
|
|
1109
|
-
circle.setAttribute("aria-label", "Series " + (i + 1) + ": " + String(s.values[pi]));
|
|
1110
|
-
svg.appendChild(circle);
|
|
1111
|
-
});
|
|
1112
|
-
plot.appendChild(svg);
|
|
1113
|
-
}
|
|
1114
|
-
});
|
|
1115
|
-
} else {
|
|
1116
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1117
|
-
svg.setAttribute("viewBox", "0 0 300 120");
|
|
1118
|
-
svg.setAttribute("preserveAspectRatio", "none");
|
|
1119
|
-
svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
|
|
1120
|
-
svg.setAttribute("aria-hidden", "true");
|
|
1121
|
-
parsed.forEach((s, i) => {
|
|
1122
|
-
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1123
|
-
path.setAttribute("class", "c-chart__line");
|
|
1124
|
-
path.setAttribute("data-series", String(i + 1));
|
|
1125
|
-
path.style.setProperty("--c", `var(--chart-${i + 1})`);
|
|
1126
|
-
path.setAttribute("d", s.d || s);
|
|
1127
|
-
svg.appendChild(path);
|
|
1128
|
-
});
|
|
1129
|
-
plot.appendChild(svg);
|
|
1130
|
-
}
|
|
1131
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1132
|
-
// Styled tooltip element (positioned via --chart-tip-*).
|
|
1133
|
-
const tip = this.ensure(".c-chart__tooltip", () => { const el = document.createElement("div"); el.className = "c-chart__tooltip"; el.setAttribute("role", "tooltip"); el.setAttribute("hidden", ""); return el; });
|
|
1134
|
-
tip.setAttribute("hidden", "");
|
|
1135
|
-
// Accessible data-table fallback (R12-18): opt-in via `data-table`
|
|
1136
|
-
// attribute. Renders a visually-hidden table of the series values so
|
|
1137
|
-
// screen readers and no-JS consumers can read the data behind the
|
|
1138
|
-
// graphic. The graphic remains the primary presentation.
|
|
1139
|
-
if (this.hasAttribute("data-table")) {
|
|
1140
|
-
let table = this.querySelector(".c-chart__data-table");
|
|
1141
|
-
if (!table) {
|
|
1142
|
-
table = document.createElement("table");
|
|
1143
|
-
table.className = "c-chart__data-table visually-hidden";
|
|
1144
|
-
this.appendChild(table);
|
|
1145
|
-
}
|
|
1146
|
-
table.innerHTML = "";
|
|
1147
|
-
// A caption names the table: a reader who lands on it hears what it
|
|
1148
|
-
// holds before the first cell, not "table, 5 rows, 3 columns".
|
|
1149
|
-
const title = this.getAttribute("title") || this.getAttribute("aria-label") || labelText(this, "chart-data", "Chart data");
|
|
1150
|
-
const cap = document.createElement("caption");
|
|
1151
|
-
cap.textContent = title;
|
|
1152
|
-
table.appendChild(cap);
|
|
1153
|
-
const thead = document.createElement("thead");
|
|
1154
|
-
const hr = document.createElement("tr");
|
|
1155
|
-
const h = document.createElement("th");
|
|
1156
|
-
h.setAttribute("scope", "col");
|
|
1157
|
-
h.textContent = labelText(this, "series", "Series");
|
|
1158
|
-
hr.appendChild(h);
|
|
1159
|
-
const maxLen = parsed.reduce((m, s) => Math.max(m, Array.isArray(s.values) ? s.values.length : (Array.isArray(s) ? s.length : 0)), 0);
|
|
1160
|
-
for (let i = 0; i < maxLen; i++) {
|
|
1161
|
-
const th = document.createElement("th");
|
|
1162
|
-
th.setAttribute("scope", "col");
|
|
1163
|
-
th.textContent = labelText(this, "value", "Value") + " " + (i + 1);
|
|
1164
|
-
hr.appendChild(th);
|
|
1165
|
-
}
|
|
1166
|
-
thead.appendChild(hr);
|
|
1167
|
-
table.appendChild(thead);
|
|
1168
|
-
const tbody = document.createElement("tbody");
|
|
1169
|
-
parsed.forEach((s, si) => {
|
|
1170
|
-
const vals = Array.isArray(s.values) ? s.values : (Array.isArray(s) ? s : []);
|
|
1171
|
-
const tr = document.createElement("tr");
|
|
1172
|
-
const td0 = document.createElement("th");
|
|
1173
|
-
td0.setAttribute("scope", "row");
|
|
1174
|
-
td0.textContent = s.label || ("Series " + (si + 1));
|
|
1175
|
-
tr.appendChild(td0);
|
|
1176
|
-
for (let i = 0; i < maxLen; i++) {
|
|
1177
|
-
const td = document.createElement("td");
|
|
1178
|
-
td.textContent = vals[i] != null ? String(vals[i]) : "";
|
|
1179
|
-
tr.appendChild(td);
|
|
1180
|
-
}
|
|
1181
|
-
tbody.appendChild(tr);
|
|
1182
|
-
});
|
|
1183
|
-
table.appendChild(tbody);
|
|
1184
|
-
} else {
|
|
1185
|
-
const old = this.querySelector(".c-chart__data-table");
|
|
1186
|
-
if (old) old.remove();
|
|
1187
|
-
}
|
|
1188
|
-
if (this._showsBrush()) {
|
|
1189
|
-
const brush = this.ensure("contour-brush", () => document.createElement("contour-brush"));
|
|
1190
|
-
// A binned histogram's brush is in data units, so the track
|
|
1191
|
-
// defaults to the bins' own extent; a consumer that supplies
|
|
1192
|
-
// brush-min/brush-max still wins. Without this a binder's
|
|
1193
|
-
// `range` would be positioned against a 0–100 track it never set.
|
|
1194
|
-
const drawnBins = this._renderedBins || [];
|
|
1195
|
-
const trackMin = this.getAttribute("brush-min") || (drawnBins.length ? String(drawnBins[0].x0) : "0");
|
|
1196
|
-
const trackMax = this.getAttribute("brush-max") || (drawnBins.length ? String(drawnBins[drawnBins.length - 1].x1) : "100");
|
|
1197
|
-
const override = Array.isArray(this._rangeOverride) ? this._rangeOverride : null;
|
|
1198
|
-
// `range = null` means "no constraint": the brush keeps its
|
|
1199
|
-
// affordance and shows the full track, rather than vanishing.
|
|
1200
|
-
const cleared = this._rangeOverride === null;
|
|
1201
|
-
brush.setAttribute("min", trackMin);
|
|
1202
|
-
brush.setAttribute("max", trackMax);
|
|
1203
|
-
brush.setAttribute("start", override ? String(override[0]) : cleared ? trackMin : (this.getAttribute("brush-start") || trackMin));
|
|
1204
|
-
brush.setAttribute("end", override ? String(override[1]) : cleared ? trackMax : (this.getAttribute("brush-end") || trackMax));
|
|
1205
|
-
const plotEl = this.querySelector(".c-chart__plot");
|
|
1206
|
-
if (brush.previousElementSibling !== plotEl) this.insertBefore(brush, plotEl ? plotEl.nextSibling : null);
|
|
1207
|
-
} else {
|
|
1208
|
-
const brush = this.querySelector("contour-brush");
|
|
1209
|
-
if (brush) brush.remove();
|
|
1210
|
-
}
|
|
1211
|
-
const note = this.getAttribute("note");
|
|
1212
|
-
let noteEl = this.querySelector(".c-chart__note");
|
|
1213
|
-
if (note) {
|
|
1214
|
-
if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-chart__note"; this.appendChild(noteEl); }
|
|
1215
|
-
noteEl.textContent = note;
|
|
1216
|
-
} else if (noteEl) {
|
|
1217
|
-
noteEl.remove();
|
|
1218
|
-
}
|
|
1219
|
-
} else {
|
|
1220
|
-
// No series: nothing is drawn, so nothing is published either. A
|
|
1221
|
-
// consumer reading `bins` must see the empty state, not the last one.
|
|
1222
|
-
this._renderedBins = [];
|
|
1223
|
-
this._renderedBackground = [];
|
|
1224
|
-
const plot = this.ensure(".c-chart__plot", () => { const el = document.createElement("div"); el.className = "c-chart__plot"; return el; });
|
|
1225
|
-
plot.innerHTML = "";
|
|
1226
|
-
const empty = document.createElement("div");
|
|
1227
|
-
empty.className = "c-chart__empty";
|
|
1228
|
-
empty.textContent = this.getAttribute("empty") || "No data";
|
|
1229
|
-
empty.style.display = "grid";
|
|
1230
|
-
empty.style.placeItems = "center";
|
|
1231
|
-
empty.style.height = "100%";
|
|
1232
|
-
empty.style.color = "var(--color-text-muted)";
|
|
1233
|
-
plot.appendChild(empty);
|
|
1234
|
-
const note = this.getAttribute("note");
|
|
1235
|
-
let noteEl2 = this.querySelector(".c-chart__note");
|
|
1236
|
-
if (note) {
|
|
1237
|
-
if (!noteEl2) { noteEl2 = document.createElement("div"); noteEl2.className = "c-chart__note"; this.appendChild(noteEl2); }
|
|
1238
|
-
noteEl2.textContent = note;
|
|
1239
|
-
} else if (noteEl2) {
|
|
1240
|
-
noteEl2.remove();
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
enhance() {
|
|
1245
|
-
if (this._wiredChart) return;
|
|
1246
|
-
this._wiredChart = true;
|
|
1247
|
-
// Series toggle responding to legend (F-10): hide/show series when a
|
|
1248
|
-
// legend item is toggled. The legend may be a sibling of the chart, so
|
|
1249
|
-
// listen on the shared parent (which catches both a child and a sibling
|
|
1250
|
-
// legend) and match by key, data-key, or the item's index.
|
|
1251
|
-
const legendHost = this.parentElement || document;
|
|
1252
|
-
const onLegendToggle = (e) => {
|
|
1253
|
-
const key = e && e.detail && (e.detail.key != null ? e.detail.key : e.detail.label);
|
|
1254
|
-
const index = e && e.detail && e.detail.index;
|
|
1255
|
-
const pressed = e && e.detail && e.detail.pressed;
|
|
1256
|
-
if (key == null && index == null) return;
|
|
1257
|
-
const nodes = this.querySelectorAll("[data-series]");
|
|
1258
|
-
nodes.forEach((n) => {
|
|
1259
|
-
const s = n.getAttribute("data-series");
|
|
1260
|
-
const match = String(s) === String(key)
|
|
1261
|
-
|| n.getAttribute("data-key") === String(key)
|
|
1262
|
-
|| (index != null && String(s) === String(index + 1));
|
|
1263
|
-
if (match) n.style.display = pressed === false ? "none" : "";
|
|
1264
|
-
});
|
|
1265
|
-
};
|
|
1266
|
-
legendHost.addEventListener("contour:legend-toggle", onLegendToggle);
|
|
1267
|
-
onDispose(this, () => legendHost.removeEventListener("contour:legend-toggle", onLegendToggle));
|
|
1268
|
-
this.addEventListener("contour:brush-end", (e) => {
|
|
1269
|
-
if (!this._showsBrush() || !e.target || !e.target.matches("contour-brush")) return;
|
|
1270
|
-
// The brush moves its own attributes, so a chart already driven through the
|
|
1271
|
-
// `range` property records the new pair here; an author-driven chart stays
|
|
1272
|
-
// attribute-only and reads the brush itself. `undefined` is the switch:
|
|
1273
|
-
// once the property has been written, drags keep it current.
|
|
1274
|
-
if (this._rangeOverride !== undefined && e.detail && Array.isArray(e.detail.range)) {
|
|
1275
|
-
this._rangeOverride = e.detail.range.slice();
|
|
1276
|
-
}
|
|
1277
|
-
this.dispatchEvent(new CustomEvent("contour:select", {
|
|
1278
|
-
bubbles: true,
|
|
1279
|
-
composed: true,
|
|
1280
|
-
detail: e.detail,
|
|
1281
|
-
}));
|
|
1282
|
-
});
|
|
1283
|
-
// Zoom/pan (F-10 deferred): wheel to zoom, drag to pan, double-click to reset.
|
|
1284
|
-
if (this.hasAttribute("zoomable")) {
|
|
1285
|
-
let zoom = 1, panX = 0, panY = 0;
|
|
1286
|
-
const plot = this.querySelector(".c-chart__plot");
|
|
1287
|
-
const apply = () => {
|
|
1288
|
-
if (!plot) return;
|
|
1289
|
-
plot.style.transform = `translate(${panX}px, ${panY}px) scale(${zoom})`;
|
|
1290
|
-
plot.style.transformOrigin = "center center";
|
|
1291
|
-
};
|
|
1292
|
-
this.addEventListener("wheel", (e) => {
|
|
1293
|
-
e.preventDefault();
|
|
1294
|
-
const factor = e.deltaY < 0 ? 1.1 : 0.9;
|
|
1295
|
-
zoom = Math.min(5, Math.max(0.5, zoom * factor));
|
|
1296
|
-
apply();
|
|
1297
|
-
}, { passive: false });
|
|
1298
|
-
let dragging = false, startX = 0, startY = 0, startPanX = 0, startPanY = 0;
|
|
1299
|
-
this.addEventListener("mousedown", (e) => {
|
|
1300
|
-
if (e.button !== 0) return;
|
|
1301
|
-
dragging = true; startX = e.clientX; startY = e.clientY; startPanX = panX; startPanY = panY;
|
|
1302
|
-
this.style.cursor = "grabbing";
|
|
1303
|
-
});
|
|
1304
|
-
const onMove = (e) => {
|
|
1305
|
-
if (!dragging) return;
|
|
1306
|
-
panX = startPanX + (e.clientX - startX);
|
|
1307
|
-
panY = startPanY + (e.clientY - startY);
|
|
1308
|
-
apply();
|
|
1309
|
-
};
|
|
1310
|
-
const onUp = () => { if (dragging) { dragging = false; this.style.cursor = ""; } };
|
|
1311
|
-
window.addEventListener("mousemove", onMove);
|
|
1312
|
-
window.addEventListener("mouseup", onUp);
|
|
1313
|
-
onDispose(this, () => { window.removeEventListener("mousemove", onMove); window.removeEventListener("mouseup", onUp); });
|
|
1314
|
-
this.addEventListener("dblclick", () => { zoom = 1; panX = 0; panY = 0; apply(); });
|
|
1315
|
-
}
|
|
1316
|
-
// Tooltip: show on hover of a mark.
|
|
1317
|
-
// Cache the plot rect across mousemove events: it only changes on
|
|
1318
|
-
// resize/scroll, so re-measuring it on every pixel of movement is
|
|
1319
|
-
// wasted layout work (B3-22). A ResizeObserver invalidates the cache;
|
|
1320
|
-
// scroll invalidates via the same observer-less fallback (recompute).
|
|
1321
|
-
let plotRectCache = null;
|
|
1322
|
-
let plotRectObserver = null;
|
|
1323
|
-
const invalidatePlotRect = () => { plotRectCache = null; };
|
|
1324
|
-
const showTip = (e) => {
|
|
1325
|
-
const plot = this.querySelector(".c-chart__plot");
|
|
1326
|
-
const tip = this.querySelector(".c-chart__tooltip");
|
|
1327
|
-
if (!plot || !tip) return;
|
|
1328
|
-
const mark = e.target && e.target.closest ? e.target.closest(".c-chart__bar, .c-chart__point, .c-chart__line") : null;
|
|
1329
|
-
if (!mark || !plot.contains(mark)) { tip.setAttribute("hidden", ""); return; }
|
|
1330
|
-
const title = mark.getAttribute("title");
|
|
1331
|
-
if (title) tip.textContent = title;
|
|
1332
|
-
if (!plotRectCache) {
|
|
1333
|
-
plotRectCache = plot.getBoundingClientRect();
|
|
1334
|
-
if (!plotRectObserver && typeof ResizeObserver === "function") {
|
|
1335
|
-
plotRectObserver = new ResizeObserver(invalidatePlotRect);
|
|
1336
|
-
plotRectObserver.observe(plot);
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
const rect = plotRectCache;
|
|
1340
|
-
const mr = mark.getBoundingClientRect();
|
|
1341
|
-
const x = mr.left - rect.left + mr.width / 2;
|
|
1342
|
-
const y = mr.top - rect.top;
|
|
1343
|
-
plot.style.setProperty("--chart-tip-inline-start", x + "px");
|
|
1344
|
-
plot.style.setProperty("--chart-tip-block-start", y + "px");
|
|
1345
|
-
tip.removeAttribute("hidden");
|
|
1346
|
-
};
|
|
1347
|
-
const hideTip = () => {
|
|
1348
|
-
const tip = this.querySelector(".c-chart__tooltip");
|
|
1349
|
-
if (tip) tip.setAttribute("hidden", "");
|
|
1350
|
-
};
|
|
1351
|
-
// Host-delegated so the handlers survive re-renders (rule 12).
|
|
1352
|
-
this.addEventListener("mousemove", showTip);
|
|
1353
|
-
this.addEventListener("mouseleave", hideTip);
|
|
1354
|
-
onDispose(this, () => { if (plotRectObserver) { plotRectObserver.disconnect(); plotRectObserver = null; } });
|
|
1355
|
-
// Keyboard path (BY-39): the marks already carry roving tabindex, so a
|
|
1356
|
-
// focused mark shows the same tooltip as a hovered one.
|
|
1357
|
-
this.addEventListener("focusin", (e) => {
|
|
1358
|
-
const mark = e.target && e.target.closest ? e.target.closest(".c-chart__bar, .c-chart__point, .c-chart__line") : null;
|
|
1359
|
-
if (mark && this.contains(mark)) showTip({ target: mark });
|
|
1360
|
-
});
|
|
1361
|
-
this.addEventListener("focusout", (e) => {
|
|
1362
|
-
if (!this.contains(e.relatedTarget)) hideTip();
|
|
1363
|
-
});
|
|
1364
|
-
// Per-bar keyboard/click handling for histogram bars (host-delegated).
|
|
1365
|
-
this.addEventListener("click", (e) => {
|
|
1366
|
-
const plot2 = this.querySelector(".c-chart__plot");
|
|
1367
|
-
if (!plot2) return;
|
|
1368
|
-
const bar = e.target && e.target.closest ? e.target.closest(".c-chart__bar") : null;
|
|
1369
|
-
if (bar && plot2.contains(bar)) {
|
|
1370
|
-
const series = parseInt(bar.getAttribute("data-series") || "1", 10);
|
|
1371
|
-
const index = parseInt(bar.dataset.index || "0", 10);
|
|
1372
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series, index } }));
|
|
1373
|
-
return;
|
|
1374
|
-
}
|
|
1375
|
-
const point = e.target && e.target.closest ? e.target.closest(".c-chart__point") : null;
|
|
1376
|
-
if (point && plot2.contains(point)) {
|
|
1377
|
-
const series = parseInt(point.getAttribute("data-series") || "1", 10);
|
|
1378
|
-
const index = parseInt(point.dataset.index || "0", 10);
|
|
1379
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series, index } }));
|
|
1380
|
-
}
|
|
1381
|
-
});
|
|
1382
|
-
this.addEventListener("keydown", (e) => {
|
|
1383
|
-
const plot2 = this.querySelector(".c-chart__plot");
|
|
1384
|
-
if (!plot2) return;
|
|
1385
|
-
const bar = e.target && e.target.closest ? e.target.closest(".c-chart__bar") : null;
|
|
1386
|
-
if (bar && plot2.contains(bar)) {
|
|
1387
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
1388
|
-
e.preventDefault();
|
|
1389
|
-
const series = parseInt(bar.getAttribute("data-series") || "1", 10);
|
|
1390
|
-
const index = parseInt(bar.dataset.index || "0", 10);
|
|
1391
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series, index } }));
|
|
1392
|
-
}
|
|
1393
|
-
return;
|
|
1394
|
-
}
|
|
1395
|
-
const point = e.target && e.target.closest ? e.target.closest(".c-chart__point") : null;
|
|
1396
|
-
if (!point || !plot2.contains(point)) return;
|
|
1397
|
-
const series = parseInt(point.getAttribute("data-series") || "1", 10);
|
|
1398
|
-
const points = Array.from(plot2.querySelectorAll('.c-chart__point[data-series="' + series + '"]'));
|
|
1399
|
-
const idx = points.indexOf(point);
|
|
1400
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
1401
|
-
e.preventDefault();
|
|
1402
|
-
const index = parseInt(point.dataset.index || "0", 10);
|
|
1403
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series, index } }));
|
|
1404
|
-
return;
|
|
1405
|
-
}
|
|
1406
|
-
navKey(e, points, {
|
|
1407
|
-
wrap: false,
|
|
1408
|
-
rtl: isRtl(this),
|
|
1409
|
-
onNavigate: (i) => points.forEach((p, j) => p.setAttribute("tabindex", j === i ? "0" : "-1")),
|
|
1410
|
-
onKey: () => {}
|
|
1411
|
-
});
|
|
1412
|
-
});
|
|
1413
|
-
this.addEventListener("keydown", (e) => {
|
|
1414
|
-
// Only the host itself drives series switching; marks handle their own
|
|
1415
|
-
// keys (B3-03). Without this gate one Enter fires contour:select twice.
|
|
1416
|
-
if (e.target !== this) return;
|
|
1417
|
-
let seriesCount = 0;
|
|
1418
|
-
try { seriesCount = JSON.parse(this.getAttribute("series") || "[]").length; } catch (e) { seriesCount = 0; }
|
|
1419
|
-
if (seriesCount === 0) return;
|
|
1420
|
-
if (this._activeSeries === undefined) this._activeSeries = 0;
|
|
1421
|
-
let next = this._activeSeries;
|
|
1422
|
-
const rtl = (this.getAttribute("dir") || document.documentElement.getAttribute("dir") || "").toLowerCase() === "rtl";
|
|
1423
|
-
if (e.key === "ArrowRight") next = rtl ? Math.max(this._activeSeries - 1, 0) : Math.min(this._activeSeries + 1, seriesCount - 1);
|
|
1424
|
-
else if (e.key === "ArrowLeft") next = rtl ? Math.min(this._activeSeries + 1, seriesCount - 1) : Math.max(this._activeSeries - 1, 0);
|
|
1425
|
-
else if (e.key === "ArrowDown") next = Math.min(this._activeSeries + 1, seriesCount - 1);
|
|
1426
|
-
else if (e.key === "ArrowUp") next = Math.max(this._activeSeries - 1, 0);
|
|
1427
|
-
else if (e.key === "Home") next = 0;
|
|
1428
|
-
else if (e.key === "End") next = seriesCount - 1;
|
|
1429
|
-
else if (e.key === "Enter" || e.key === " ") {
|
|
1430
|
-
e.preventDefault();
|
|
1431
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: this._activeSeries } }));
|
|
1432
|
-
return;
|
|
1433
|
-
} else return;
|
|
1434
|
-
if (next !== this._activeSeries) {
|
|
1435
|
-
e.preventDefault();
|
|
1436
|
-
this._activeSeries = next;
|
|
1437
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: next } }));
|
|
1438
|
-
}
|
|
1439
|
-
});
|
|
1440
|
-
// Cross-filter contract (R16-16): clear-all resets chart brush state.
|
|
1441
|
-
this.addEventListener("contour:clear-all", () => {
|
|
1442
|
-
if (this.hasAttribute("brush")) {
|
|
1443
|
-
this.removeAttribute("brush");
|
|
1444
|
-
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "chart", filter: { brush: null } } }));
|
|
1445
|
-
this.requestRender();
|
|
1446
|
-
}
|
|
1447
|
-
});
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
define("contour-chart", ContourChart);
|
|
1451
|
-
/**
|
|
1452
|
-
* Comparison: web component wrapper.
|
|
1453
|
-
* Attributes: `divider`, `value`, `before`, `after`.
|
|
1454
|
-
*/
|
|
1455
|
-
class ContourComparison extends ContourBase {
|
|
1456
|
-
static get observed() { return ["divider", "value", "before", "after"]; }
|
|
1457
|
-
static get properties() { return { divider: { attribute: "divider" }, value: { attribute: "value" }, before: { attribute: "before" }, after: { attribute: "after" } }; }
|
|
1458
|
-
render() {
|
|
1459
|
-
this.classList.add("c-comparison");
|
|
1460
|
-
this.setAttribute("role", "group");
|
|
1461
|
-
this.setAttribute("aria-label", "Comparison");
|
|
1462
|
-
if (!this.style.blockSize) this.style.blockSize = "12rem";
|
|
1463
|
-
this.style.setProperty("--comparison-pos", (this.getAttribute("value") || "50") + "%");
|
|
1464
|
-
// Ensure two panes exist.
|
|
1465
|
-
const beforeLabel = this.getAttribute("before") || "Before";
|
|
1466
|
-
const afterLabel = this.getAttribute("after") || "After";
|
|
1467
|
-
if (!this.querySelector(".c-comparison__pane--before")) {
|
|
1468
|
-
const p = document.createElement("div");
|
|
1469
|
-
p.className = "c-comparison__pane c-comparison__pane--before";
|
|
1470
|
-
p.textContent = beforeLabel;
|
|
1471
|
-
this.appendChild(p);
|
|
1472
|
-
} else {
|
|
1473
|
-
const p = this.querySelector(".c-comparison__pane--before");
|
|
1474
|
-
if (p) p.textContent = beforeLabel;
|
|
1475
|
-
}
|
|
1476
|
-
if (!this.querySelector(".c-comparison__pane:not(.c-comparison__pane--before)")) {
|
|
1477
|
-
const p = document.createElement("div");
|
|
1478
|
-
p.className = "c-comparison__pane";
|
|
1479
|
-
p.textContent = afterLabel;
|
|
1480
|
-
this.appendChild(p);
|
|
1481
|
-
} else {
|
|
1482
|
-
const p = this.querySelector(".c-comparison__pane:not(.c-comparison__pane--before)");
|
|
1483
|
-
if (p) p.textContent = afterLabel;
|
|
1484
|
-
}
|
|
1485
|
-
// Labels (CARTO-inspired): overlay the before/after text on each pane.
|
|
1486
|
-
const beforePane = this.querySelector(".c-comparison__pane--before");
|
|
1487
|
-
if (beforePane) {
|
|
1488
|
-
let lbl = beforePane.querySelector(".c-comparison__label--before");
|
|
1489
|
-
if (!lbl) { lbl = document.createElement("span"); lbl.className = "c-comparison__label c-comparison__label--before"; beforePane.appendChild(lbl); }
|
|
1490
|
-
lbl.textContent = beforeLabel;
|
|
1491
|
-
}
|
|
1492
|
-
const afterPane = this.querySelector(".c-comparison__pane:not(.c-comparison__pane--before)");
|
|
1493
|
-
if (afterPane) {
|
|
1494
|
-
let lbl = afterPane.querySelector(".c-comparison__label--after");
|
|
1495
|
-
if (!lbl) { lbl = document.createElement("span"); lbl.className = "c-comparison__label c-comparison__label--after"; afterPane.appendChild(lbl); }
|
|
1496
|
-
lbl.textContent = afterLabel;
|
|
1497
|
-
}
|
|
1498
|
-
const divider = this.getAttribute("divider");
|
|
1499
|
-
if (divider !== null) {
|
|
1500
|
-
const d = this.ensure(".c-comparison__divider", () => { const el = document.createElement("div"); el.className = "c-comparison__divider"; el.setAttribute("role", "slider"); el.setAttribute("aria-orientation", "vertical"); el.setAttribute("aria-valuemin", "0"); el.setAttribute("aria-valuemax", "100"); el.setAttribute("aria-valuenow", "50"); el.setAttribute("aria-label", "Comparison divider"); el.setAttribute("tabindex", "0"); return el; });
|
|
1501
|
-
if (divider) d.textContent = divider;
|
|
1502
|
-
} else {
|
|
1503
|
-
const d = this.querySelector(".c-comparison__divider");
|
|
1504
|
-
if (d) d.remove();
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
enhance() {
|
|
1508
|
-
if (this._wiredComparison) return;
|
|
1509
|
-
this._wiredComparison = true;
|
|
1510
|
-
const divider = () => this.querySelector(".c-comparison__divider");
|
|
1511
|
-
const setPos = (pct) => {
|
|
1512
|
-
const clamped = Math.max(0, Math.min(100, pct));
|
|
1513
|
-
this.style.setProperty("--comparison-pos", clamped + "%");
|
|
1514
|
-
this.setAttribute("value", String(Math.round(clamped)));
|
|
1515
|
-
const divider = this.querySelector(".c-comparison__divider");
|
|
1516
|
-
if (divider) divider.setAttribute("aria-valuenow", String(Math.round(clamped)));
|
|
1517
|
-
this.dispatchEvent(new CustomEvent("contour:drag", { bubbles: true, composed: true, detail: { value: clamped } }));
|
|
1518
|
-
};
|
|
1519
|
-
let dragging = false;
|
|
1520
|
-
const onMove = (e) => {
|
|
1521
|
-
if (!dragging) return;
|
|
1522
|
-
const rect = this.getBoundingClientRect();
|
|
1523
|
-
const pct = ((e.clientX - rect.left) / rect.width) * 100;
|
|
1524
|
-
setPos(pct);
|
|
1525
|
-
};
|
|
1526
|
-
const onUp = () => { dragging = false; window.removeEventListener("mousemove", onMove); window.removeEventListener("mouseup", onUp); };
|
|
1527
|
-
onDispose(this, () => { dragging = false; window.removeEventListener("mousemove", onMove); window.removeEventListener("mouseup", onUp); });
|
|
1528
|
-
this.addEventListener("mousedown", (e) => {
|
|
1529
|
-
const d = divider();
|
|
1530
|
-
if (!d || !d.contains(e.target)) return;
|
|
1531
|
-
dragging = true;
|
|
1532
|
-
window.addEventListener("mousemove", onMove);
|
|
1533
|
-
window.addEventListener("mouseup", onUp);
|
|
1534
|
-
e.preventDefault();
|
|
1535
|
-
});
|
|
1536
|
-
this.addEventListener("keydown", (e) => {
|
|
1537
|
-
const d = divider();
|
|
1538
|
-
if (!d || document.activeElement !== d) return;
|
|
1539
|
-
const cur = parseFloat(this.style.getPropertyValue("--comparison-pos")) || 50;
|
|
1540
|
-
if (e.key === "ArrowLeft") { e.preventDefault(); setPos(cur - 5); }
|
|
1541
|
-
else if (e.key === "ArrowRight") { e.preventDefault(); setPos(cur + 5); }
|
|
1542
|
-
});
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
define("contour-comparison", ContourComparison);
|
|
1546
|
-
/**
|
|
1547
|
-
* Streaming Chart: web component wrapper.
|
|
1548
|
-
* Attributes: `line`, `dot`, `interval`, `pause`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
1549
|
-
*/
|
|
1550
|
-
class ContourStreamingChart extends ContourBase {
|
|
1551
|
-
static get updateMode() { return "keyed"; }
|
|
1552
|
-
static get observed() { return ["line", "dot", "interval", "pause", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1553
|
-
static get properties() { return { line: { attribute: "line" }, dot: { attribute: "dot" }, interval: { attribute: "interval", type: Number }, pause: { attribute: "pause", type: Boolean }, src: { attribute: "src" } }; }
|
|
1554
|
-
render() {
|
|
1555
|
-
this.classList.add("c-streaming-chart");
|
|
1556
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
1557
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Streaming chart");
|
|
1558
|
-
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
1559
|
-
wireStates(this);
|
|
1560
|
-
loadRemote(this, "line");
|
|
1561
|
-
if (renderStates(this, "streaming-chart")) return;
|
|
1562
|
-
const line = remoteData(this, "line");
|
|
1563
|
-
const dot = remoteData(this, "dot");
|
|
1564
|
-
if (!line) {
|
|
1565
|
-
const svg = this.querySelector("svg");
|
|
1566
|
-
if (svg) svg.remove();
|
|
1567
|
-
renderEmpty(this, "streaming-chart");
|
|
1568
|
-
return;
|
|
1569
|
-
}
|
|
1570
|
-
if (line) {
|
|
1571
|
-
let svg = this.querySelector("svg");
|
|
1572
|
-
if (!svg) {
|
|
1573
|
-
svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1574
|
-
svg.setAttribute("viewBox", "0 0 300 192");
|
|
1575
|
-
svg.setAttribute("aria-hidden", "true");
|
|
1576
|
-
this.appendChild(svg);
|
|
1577
|
-
}
|
|
1578
|
-
let path = svg.querySelector(".c-streaming-chart__line");
|
|
1579
|
-
if (!path) {
|
|
1580
|
-
path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1581
|
-
path.setAttribute("class", "c-streaming-chart__line");
|
|
1582
|
-
svg.appendChild(path);
|
|
1583
|
-
}
|
|
1584
|
-
path.setAttribute("d", line);
|
|
1585
|
-
if (dot) {
|
|
1586
|
-
let circle = svg.querySelector(".c-streaming-chart__live-dot");
|
|
1587
|
-
if (!circle) {
|
|
1588
|
-
circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
1589
|
-
circle.setAttribute("class", "c-streaming-chart__live-dot");
|
|
1590
|
-
circle.setAttribute("r", "4");
|
|
1591
|
-
svg.appendChild(circle);
|
|
1592
|
-
}
|
|
1593
|
-
const parts = dot.split(/[ ,]+/);
|
|
1594
|
-
if (parts.length >= 2) {
|
|
1595
|
-
circle.setAttribute("cx", parts[0]);
|
|
1596
|
-
circle.setAttribute("cy", parts[1]);
|
|
1597
|
-
}
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
enhance() {
|
|
1602
|
-
// Stream cadence (BY-40). The layer had no timer at all — the literal
|
|
1603
|
-
// gap the row names — so the chart gets its own `interval` loop rather
|
|
1604
|
-
// than a second clock inside the loader. Each tick emits contour:tick
|
|
1605
|
-
// and, when a src is present, re-validates through the loader's own
|
|
1606
|
-
// cache path (remoteInvalidate + requestRender — the two steps the
|
|
1607
|
-
// loader's refresh tick performs), so the shared cache and abort
|
|
1608
|
-
// semantics stay the loader's. The loader's `refresh` attribute is NOT
|
|
1609
|
-
// written here: an attribute a component writes to itself must never be
|
|
1610
|
-
// observed, or the write re-enters render (measured by the gate).
|
|
1611
|
-
// `pause` stops the loop; `interval` growth is clamped to the loader's
|
|
1612
|
-
// own 1 s floor so the two cannot disagree.
|
|
1613
|
-
const sync = () => {
|
|
1614
|
-
const seconds = parseFloat(this.getAttribute("interval") || "");
|
|
1615
|
-
const want = Number.isFinite(seconds) && seconds > 0 && !this.hasAttribute("pause") && !this._streamPausedByUser && this._viewVisible !== false;
|
|
1616
|
-
if (want === this._streamRunning) return;
|
|
1617
|
-
this._streamRunning = want;
|
|
1618
|
-
if (this._streamTimer !== undefined) { clearInterval(this._streamTimer); this._streamTimer = undefined; }
|
|
1619
|
-
this.dispatchEvent(new CustomEvent("contour:stream-state", { detail: { running: want }, bubbles: true, composed: true }));
|
|
1620
|
-
if (!want) return;
|
|
1621
|
-
this._streamTimer = setInterval(() => {
|
|
1622
|
-
if (!this.isConnected || this.hasAttribute("pause")) return;
|
|
1623
|
-
this._streamFrame += 1;
|
|
1624
|
-
this.dispatchEvent(new CustomEvent("contour:tick", { detail: { frame: this._streamFrame }, bubbles: true, composed: true }));
|
|
1625
|
-
const src = this.getAttribute("src");
|
|
1626
|
-
if (src) { remoteInvalidate(src); this.requestRender(); }
|
|
1627
|
-
}, Math.max(1000, seconds * 1000));
|
|
1628
|
-
};
|
|
1629
|
-
sync();
|
|
1630
|
-
// Pause the stream while the chart is off-screen (B3-22): watchViewport
|
|
1631
|
-
// is the loader's own visibility seam, so the stream reuses it instead of
|
|
1632
|
-
// a second observer. A user-set `pause` still wins; this only adds an
|
|
1633
|
-
// off-screen pause on top.
|
|
1634
|
-
if (!this._wiredStreamView) {
|
|
1635
|
-
this._wiredStreamView = true;
|
|
1636
|
-
this._viewVisible = true;
|
|
1637
|
-
watchViewport(this);
|
|
1638
|
-
this.addEventListener("contour:view-enter", () => { this._viewVisible = true; sync(); });
|
|
1639
|
-
this.addEventListener("contour:view-leave", () => { this._viewVisible = false; sync(); });
|
|
1640
|
-
}
|
|
1641
|
-
// The base re-runs enhance after every render, so interval/pause changes
|
|
1642
|
-
// are picked up by sync() above; the timer itself is owned exactly once.
|
|
1643
|
-
if (this._wiredStream) return;
|
|
1644
|
-
this._wiredStream = true;
|
|
1645
|
-
this._streamFrame = 0;
|
|
1646
|
-
onDispose(this, () => { if (this._streamTimer !== undefined) { clearInterval(this._streamTimer); this._streamTimer = undefined; } });
|
|
1647
|
-
// Keyboard: Space/Enter toggles pause (BY-08 keyboard contract).
|
|
1648
|
-
// Uses an internal flag so the toggle does not re-enter render.
|
|
1649
|
-
this._streamPausedByUser = false;
|
|
1650
|
-
this.addEventListener("keydown", (e) => {
|
|
1651
|
-
if (e.key === " " || e.key === "Enter") {
|
|
1652
|
-
e.preventDefault();
|
|
1653
|
-
this._streamPausedByUser = !this._streamPausedByUser;
|
|
1654
|
-
if (this._streamPausedByUser) this.setAttribute("data-user-paused", "");
|
|
1655
|
-
else this.removeAttribute("data-user-paused");
|
|
1656
|
-
sync();
|
|
1657
|
-
}
|
|
1658
|
-
});
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
define("contour-streaming-chart", ContourStreamingChart);
|
|
1662
|
-
/**
|
|
1663
|
-
* Meter: web component wrapper.
|
|
1664
|
-
* Attributes: `value`, `label`, `variant`, `min`, `max`, `low`, `high`, `optimum`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
1665
|
-
*/
|
|
1666
|
-
class ContourMeter extends ContourBase {
|
|
1667
|
-
static get observed() { return ["value", "label", "variant", "min", "max", "low", "high", "optimum", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1668
|
-
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" } }; }
|
|
1669
|
-
render() {
|
|
1670
|
-
this.classList.add("c-meter");
|
|
1671
|
-
wireStates(this);
|
|
1672
|
-
loadRemote(this, ["value", "label"]);
|
|
1673
|
-
if (renderStates(this, "meter")) return;
|
|
1674
|
-
const rValue = remoteData(this, "value") || (this._remoteData && this._remoteData.value);
|
|
1675
|
-
const label = remoteData(this, "label") || (this._remoteData && this._remoteData.label) || "";
|
|
1676
|
-
const variant = this.getAttribute("variant");
|
|
1677
|
-
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-meter--")) this.classList.remove(c); });
|
|
1678
|
-
if (variant) this.classList.add("c-meter--" + variant);
|
|
1679
|
-
if (!rValue && !label) {
|
|
1680
|
-
renderEmpty(this, "meter");
|
|
1681
|
-
return;
|
|
1682
|
-
}
|
|
1683
|
-
if (rValue === null) {
|
|
1684
|
-
this.style.removeProperty("--meter-value");
|
|
1685
|
-
} else {
|
|
1686
|
-
const num = parseFloat(rValue);
|
|
1687
|
-
if (Number.isFinite(num)) this.style.setProperty("--meter-value", rValue);
|
|
1688
|
-
else this.style.removeProperty("--meter-value");
|
|
1689
|
-
}
|
|
1690
|
-
const core = this.ensure(".c-meter__core", () => { const el = document.createElement("span"); el.className = "c-meter__core"; return el; });
|
|
1691
|
-
let val = core.querySelector(".c-meter__value");
|
|
1692
|
-
if (!val) { val = document.createElement("span"); val.className = "c-meter__value"; core.appendChild(val); }
|
|
1693
|
-
const num = parseFloat(rValue);
|
|
1694
|
-
val.textContent = (Number.isFinite(num) ? Math.round(num * 100) : 0) + "%";
|
|
1695
|
-
if (label) {
|
|
1696
|
-
const lbl = core.querySelector(".c-meter__label") || (() => { const el = document.createElement("span"); el.className = "c-meter__label"; core.appendChild(el); return el; })();
|
|
1697
|
-
lbl.textContent = label;
|
|
1698
|
-
}
|
|
1699
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "meter");
|
|
1700
|
-
if (label && !this.hasAttribute("aria-label")) this.setAttribute("aria-label", label);
|
|
1701
|
-
const ariaValue = rValue === null ? "0" : rValue;
|
|
1702
|
-
const prevVal = this._meterAriaValue;
|
|
1703
|
-
if (!this.hasAttribute("aria-valuenow") || this.getAttribute("aria-valuenow") === prevVal) {
|
|
1704
|
-
this.setAttribute("aria-valuenow", ariaValue);
|
|
1705
|
-
this._meterAriaValue = ariaValue;
|
|
1706
|
-
}
|
|
1707
|
-
const min = this.getAttribute("min");
|
|
1708
|
-
const max = this.getAttribute("max");
|
|
1709
|
-
if (min !== null) this.setAttribute("aria-valuemin", min);
|
|
1710
|
-
else if (!this.hasAttribute("aria-valuemin")) this.setAttribute("aria-valuemin", "0");
|
|
1711
|
-
if (max !== null) this.setAttribute("aria-valuemax", max);
|
|
1712
|
-
else if (!this.hasAttribute("aria-valuemax")) this.setAttribute("aria-valuemax", "1");
|
|
1713
|
-
for (const a of ["low", "high", "optimum"]) {
|
|
1714
|
-
const v = this.getAttribute(a);
|
|
1715
|
-
if (v !== null) this.setAttribute("data-" + a, v);
|
|
1716
|
-
else this.removeAttribute("data-" + a);
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
define("contour-meter", ContourMeter);
|
|
1721
|
-
/**
|
|
1722
|
-
* Delta: web component wrapper.
|
|
1723
|
-
* Attributes: `value`, `direction`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
1724
|
-
*/
|
|
1725
|
-
class ContourDelta extends ContourBase {
|
|
1726
|
-
static get observed() { return ["value", "direction", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1727
|
-
static get properties() { return { value: { attribute: "value" }, direction: { attribute: "direction" }, src: { attribute: "src" } }; }
|
|
1728
|
-
render() {
|
|
1729
|
-
this.classList.add("c-delta");
|
|
1730
|
-
wireStates(this);
|
|
1731
|
-
loadRemote(this, "value");
|
|
1732
|
-
if (renderStates(this, "delta")) return;
|
|
1733
|
-
const value = remoteData(this, "value") || "";
|
|
1734
|
-
Array.from(this.classList).forEach((c) => { if (c.startsWith("c-delta--")) this.classList.remove(c); });
|
|
1735
|
-
const direction = this.getAttribute("direction") || (this._remoteData && this._remoteData.direction) || "up";
|
|
1736
|
-
if (!value) {
|
|
1737
|
-
renderEmpty(this, "delta");
|
|
1738
|
-
return;
|
|
1739
|
-
}
|
|
1740
|
-
this.classList.add("c-delta--" + direction);
|
|
1741
|
-
const icon = { up: "#i-arrow-up", down: "#i-arrow-down", flat: "#i-minus" }[direction] || "#i-arrow-up";
|
|
1742
|
-
this.querySelectorAll("svg").forEach((s) => s.remove());
|
|
1743
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1744
|
-
svg.setAttribute("aria-hidden", "true");
|
|
1745
|
-
const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
|
|
1746
|
-
use.setAttribute("href", icon);
|
|
1747
|
-
svg.appendChild(use);
|
|
1748
|
-
this.appendChild(svg);
|
|
1749
|
-
this.appendChild(document.createTextNode(" " + value));
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
define("contour-delta", ContourDelta);
|
|
1753
|
-
/**
|
|
1754
|
-
* Stat: web component wrapper.
|
|
1755
|
-
* Attributes: `value`, `label`, `delta`, `unit`, `format`, `locale`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
1756
|
-
*/
|
|
1757
|
-
class ContourStat extends ContourBase {
|
|
1758
|
-
static get observed() { return ["value", "label", "delta", "unit", "format", "locale", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1759
|
-
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" } }; }
|
|
1760
|
-
render() {
|
|
1761
|
-
this.classList.add("c-stat");
|
|
1762
|
-
wireStates(this);
|
|
1763
|
-
loadRemote(this, ["value", "label"]);
|
|
1764
|
-
if (renderStates(this, "stat")) return;
|
|
1765
|
-
const value = remoteData(this, "value");
|
|
1766
|
-
const label = remoteData(this, "label");
|
|
1767
|
-
const delta = this.getAttribute("delta");
|
|
1768
|
-
if (value) {
|
|
1769
|
-
const v = this.ensure(".c-stat__value", () => { const el = document.createElement("div"); el.className = "c-stat__value"; el.setAttribute("aria-live", "polite"); return el; });
|
|
1770
|
-
v.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"), this.getAttribute("unit"));
|
|
1771
|
-
} else {
|
|
1772
|
-
const v = this.querySelector(".c-stat__value");
|
|
1773
|
-
if (v) v.remove();
|
|
1774
|
-
}
|
|
1775
|
-
if (label) {
|
|
1776
|
-
const l = this.ensure(".c-stat__label", () => { const el = document.createElement("div"); el.className = "c-stat__label"; return el; });
|
|
1777
|
-
l.textContent = label;
|
|
1778
|
-
} else {
|
|
1779
|
-
const l = this.querySelector(".c-stat__label");
|
|
1780
|
-
if (l) l.remove();
|
|
1781
|
-
}
|
|
1782
|
-
if (delta) {
|
|
1783
|
-
const d = this.ensure(".c-stat__delta", () => { const el = document.createElement("div"); el.className = "c-stat__delta"; return el; });
|
|
1784
|
-
d.textContent = delta;
|
|
1785
|
-
} else {
|
|
1786
|
-
const d = this.querySelector(".c-stat__delta");
|
|
1787
|
-
if (d) d.remove();
|
|
1788
|
-
}
|
|
1789
|
-
const unit = this.getAttribute("unit");
|
|
1790
|
-
const v = this.querySelector(".c-stat__value");
|
|
1791
|
-
if (v) {
|
|
1792
|
-
if (unit) {
|
|
1793
|
-
let u = v.querySelector(".c-stat__unit");
|
|
1794
|
-
if (!u) { u = document.createElement("span"); u.className = "c-stat__unit"; v.appendChild(u); }
|
|
1795
|
-
u.textContent = unit;
|
|
1796
|
-
} else {
|
|
1797
|
-
const u = v.querySelector(".c-stat__unit");
|
|
1798
|
-
if (u) u.remove();
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
|
-
if (!value && !label) {
|
|
1802
|
-
renderEmpty(this, "stat");
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1806
|
-
define("contour-stat", ContourStat);
|
|
1807
|
-
/**
|
|
1808
|
-
* Gauge: web component wrapper.
|
|
1809
|
-
* 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`.
|
|
1810
|
-
*/
|
|
1811
|
-
class ContourGauge extends ContourBase {
|
|
1812
|
-
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"]; }
|
|
1813
|
-
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" } }; }
|
|
1814
|
-
render() {
|
|
1815
|
-
this.classList.add("c-gauge");
|
|
1816
|
-
wireStates(this);
|
|
1817
|
-
loadRemote(this, ["value"]);
|
|
1818
|
-
if (renderStates(this, "gauge")) return;
|
|
1819
|
-
const rawValue = this.getAttribute("value");
|
|
1820
|
-
const num = parseFloat(rawValue);
|
|
1821
|
-
const hasValue = rawValue !== null && rawValue !== "" && Number.isFinite(num);
|
|
1822
|
-
const min = parseFloat(this.getAttribute("min") || "0");
|
|
1823
|
-
const max = parseFloat(this.getAttribute("max") || "100");
|
|
1824
|
-
const heading = this.getAttribute("heading");
|
|
1825
|
-
const showHeader = this.getAttribute("show-header") !== "false";
|
|
1826
|
-
const description = this.getAttribute("description");
|
|
1827
|
-
const noDataMessage = this.getAttribute("no-data-message") || "No readings in view";
|
|
1828
|
-
const brownoutLevel = this.brownoutLevel();
|
|
1829
|
-
// empty state
|
|
1830
|
-
if (!hasValue) {
|
|
1831
|
-
if (heading && showHeader) {
|
|
1832
|
-
const t = this.ensure(".c-gauge__title", () => { const el = document.createElement("div"); el.className = "c-gauge__title"; return el; });
|
|
1833
|
-
t.textContent = heading;
|
|
1834
|
-
}
|
|
1835
|
-
const empty = this.ensure(".c-gauge__empty", () => { const el = document.createElement("div"); el.className = "c-gauge__empty"; el.setAttribute("part", "empty"); return el; });
|
|
1836
|
-
empty.textContent = noDataMessage;
|
|
1837
|
-
// remove dial/value/band if present
|
|
1838
|
-
[".c-gauge__dial", ".c-gauge__value", ".c-gauge__band"].forEach((sel) => { const n = this.querySelector(sel); if (n) n.remove(); });
|
|
1839
|
-
return;
|
|
1840
|
-
}
|
|
1841
|
-
// heading
|
|
1842
|
-
if (heading && showHeader) {
|
|
1843
|
-
const t = this.ensure(".c-gauge__title", () => { const el = document.createElement("div"); el.className = "c-gauge__title"; el.setAttribute("part", "title"); return el; });
|
|
1844
|
-
t.textContent = heading;
|
|
1845
|
-
} else {
|
|
1846
|
-
const t = this.querySelector(".c-gauge__title"); if (t) t.remove();
|
|
1847
|
-
}
|
|
1848
|
-
// thresholds
|
|
1849
|
-
let thresholds = [];
|
|
1850
|
-
const tAttr = this.getAttribute("thresholds");
|
|
1851
|
-
if (tAttr) { try { thresholds = JSON.parse(tAttr); } catch (e) { thresholds = []; } }
|
|
1852
|
-
// band determination
|
|
1853
|
-
let band = null;
|
|
1854
|
-
if (thresholds && thresholds.length) {
|
|
1855
|
-
// thresholds sorted ascending by value
|
|
1856
|
-
const sorted = [...thresholds].sort((a, b) => (a.value || 0) - (b.value || 0));
|
|
1857
|
-
for (let i = sorted.length - 1; i >= 0; i--) {
|
|
1858
|
-
if (num >= (sorted[i].value || 0)) { band = sorted[i]; break; }
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
// dial (unless brownout >= 3)
|
|
1862
|
-
const shedDial = this.shed("dial", 3);
|
|
1863
|
-
let dial = this.querySelector(".c-gauge__dial");
|
|
1864
|
-
if (shedDial) {
|
|
1865
|
-
if (dial) dial.remove();
|
|
1866
|
-
} else {
|
|
1867
|
-
if (!dial) {
|
|
1868
|
-
dial = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1869
|
-
dial.setAttribute("class", "c-gauge__dial");
|
|
1870
|
-
dial.setAttribute("part", "dial");
|
|
1871
|
-
dial.setAttribute("aria-hidden", "true");
|
|
1872
|
-
dial.setAttribute("viewBox", "0 0 100 100");
|
|
1873
|
-
this.appendChild(dial);
|
|
1874
|
-
}
|
|
1875
|
-
// rebuild dial content
|
|
1876
|
-
dial.innerHTML = "";
|
|
1877
|
-
// track arc (semicircle)
|
|
1878
|
-
const track = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1879
|
-
track.setAttribute("class", "c-gauge__track");
|
|
1880
|
-
track.setAttribute("d", "M 10 90 A 40 40 0 0 1 90 90");
|
|
1881
|
-
dial.appendChild(track);
|
|
1882
|
-
// zones: each threshold defines a band from its value to the next
|
|
1883
|
-
// threshold's value (or max), drawn as an arc along the track so the
|
|
1884
|
-
// bands no longer stack on top of one another.
|
|
1885
|
-
if (thresholds && thresholds.length) {
|
|
1886
|
-
const sorted = [...thresholds].sort((a, b) => (a.value || 0) - (b.value || 0));
|
|
1887
|
-
const toPoint = (v) => {
|
|
1888
|
-
const pos = (1 - (v - min) / (max - min || 1)) * Math.PI;
|
|
1889
|
-
return { x: 50 + 40 * Math.cos(pos), y: 90 - 40 * Math.sin(pos) };
|
|
1890
|
-
};
|
|
1891
|
-
for (let i = 0; i < sorted.length; i++) {
|
|
1892
|
-
const v1 = sorted[i].value || 0;
|
|
1893
|
-
const v2 = (i + 1 < sorted.length) ? (sorted[i + 1].value || max) : max;
|
|
1894
|
-
const p1 = toPoint(v1);
|
|
1895
|
-
const p2 = toPoint(v2);
|
|
1896
|
-
const z = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1897
|
-
z.setAttribute("class", "c-gauge__zone");
|
|
1898
|
-
z.setAttribute("stroke", sorted[i].color || "var(--color-primary)");
|
|
1899
|
-
z.setAttribute("d", "M " + p1.x.toFixed(2) + " " + p1.y.toFixed(2) + " A 40 40 0 0 1 " + p2.x.toFixed(2) + " " + p2.y.toFixed(2));
|
|
1900
|
-
dial.appendChild(z);
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
// needle (pivot at dial centre 50,90; 0 -> left, 100 -> right)
|
|
1904
|
-
const ratio = (num - min) / (max - min || 1);
|
|
1905
|
-
const angle = Math.PI * (1 - ratio);
|
|
1906
|
-
const needle = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
1907
|
-
needle.setAttribute("class", "c-gauge__needle needle");
|
|
1908
|
-
needle.setAttribute("x1", "50"); needle.setAttribute("y1", "90");
|
|
1909
|
-
needle.setAttribute("x2", String(50 + 35 * Math.cos(angle)));
|
|
1910
|
-
needle.setAttribute("y2", String(90 - 35 * Math.sin(angle)));
|
|
1911
|
-
dial.appendChild(needle);
|
|
1912
|
-
const hub = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
1913
|
-
hub.setAttribute("class", "c-gauge__hub hub");
|
|
1914
|
-
hub.setAttribute("cx", "50"); hub.setAttribute("cy", "90"); hub.setAttribute("r", "4");
|
|
1915
|
-
dial.appendChild(hub);
|
|
1916
|
-
}
|
|
1917
|
-
// value element (meter)
|
|
1918
|
-
const valueEl = this.ensure(".c-gauge__value", () => { const el = document.createElement("div"); el.className = "c-gauge__value"; el.setAttribute("part", "value"); return el; });
|
|
1919
|
-
valueEl.textContent = formatValue(String(num), this.getAttribute("format"), this.getAttribute("locale")) + (this.getAttribute("unit") ? " " + this.getAttribute("unit") : "");
|
|
1920
|
-
valueEl.setAttribute("role", "meter");
|
|
1921
|
-
valueEl.setAttribute("aria-valuenow", String(num));
|
|
1922
|
-
valueEl.setAttribute("aria-valuemin", String(min));
|
|
1923
|
-
valueEl.setAttribute("aria-valuemax", String(max));
|
|
1924
|
-
if (heading) {
|
|
1925
|
-
// labelledby
|
|
1926
|
-
if (!valueEl.id) valueEl.id = contourId("gauge-value");
|
|
1927
|
-
}
|
|
1928
|
-
if (band) {
|
|
1929
|
-
valueEl.setAttribute("aria-valuetext", num + ", " + (band.label || (">= " + band.value)));
|
|
1930
|
-
} else {
|
|
1931
|
-
valueEl.setAttribute("aria-valuetext", String(num));
|
|
1932
|
-
}
|
|
1933
|
-
// aria-labelledby / aria-label
|
|
1934
|
-
const titleEl = this.querySelector(".c-gauge__title");
|
|
1935
|
-
if (titleEl) {
|
|
1936
|
-
if (!titleEl.id) titleEl.id = contourId("gauge-title");
|
|
1937
|
-
valueEl.setAttribute("aria-labelledby", titleEl.id);
|
|
1938
|
-
valueEl.removeAttribute("aria-label");
|
|
1939
|
-
} else {
|
|
1940
|
-
valueEl.removeAttribute("aria-labelledby");
|
|
1941
|
-
if (heading) valueEl.setAttribute("aria-label", heading);
|
|
1942
|
-
else valueEl.setAttribute("aria-label", valueEl.textContent || "Gauge");
|
|
1943
|
-
}
|
|
1944
|
-
// band word
|
|
1945
|
-
const bandEl = this.querySelector(".c-gauge__band");
|
|
1946
|
-
if (band) {
|
|
1947
|
-
const b = this.ensure(".c-gauge__band", () => { const el = document.createElement("div"); el.className = "c-gauge__band"; el.setAttribute("part", "band"); return el; });
|
|
1948
|
-
b.textContent = band.label || (">= " + band.value);
|
|
1949
|
-
} else {
|
|
1950
|
-
if (bandEl) bandEl.remove();
|
|
1951
|
-
}
|
|
1952
|
-
// description
|
|
1953
|
-
if (description) {
|
|
1954
|
-
let d = this.querySelector(".c-gauge__desc");
|
|
1955
|
-
if (!d) { d = document.createElement("div"); d.className = "c-gauge__desc"; this.appendChild(d); }
|
|
1956
|
-
d.textContent = description;
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
enhance() {}
|
|
1960
|
-
}
|
|
1961
|
-
define("contour-gauge", ContourGauge);
|
|
1962
|
-
/**
|
|
1963
|
-
* Axis: web component wrapper.
|
|
1964
|
-
* Attributes: `orientation`, `values`, `ticks`, `format`, `locale`, `padding`, `min`, `max`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
1965
|
-
*/
|
|
1966
|
-
class ContourAxis extends ContourBase {
|
|
1967
|
-
static get observed() { return ["orientation", "values", "ticks", "format", "locale", "padding", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1968
|
-
static get properties() { return { orientation: { attribute: "orientation" }, values: { attribute: "values" }, ticks: { attribute: "ticks" }, format: { attribute: "format" }, locale: { attribute: "locale" }, padding: { attribute: "padding" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
|
|
1969
|
-
render() {
|
|
1970
|
-
this.classList.add("c-axis");
|
|
1971
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
1972
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Axis");
|
|
1973
|
-
const orientation = this.getAttribute("orientation") || "horizontal";
|
|
1974
|
-
this.classList.toggle("c-axis--horizontal", orientation === "horizontal");
|
|
1975
|
-
this.classList.toggle("c-axis--vertical", orientation === "vertical");
|
|
1976
|
-
if (orientation === "horizontal") this.setAttribute("part", "axis-x");
|
|
1977
|
-
else this.setAttribute("part", "axis-y");
|
|
1978
|
-
wireStates(this);
|
|
1979
|
-
loadRemote(this, ["values"]);
|
|
1980
|
-
if (renderStates(this, "axis")) return;
|
|
1981
|
-
// parse values
|
|
1982
|
-
let values = [];
|
|
1983
|
-
const vAttr = this.getAttribute("values");
|
|
1984
|
-
if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map((x) => x.trim()); } }
|
|
1985
|
-
const ticks = parseInt(this.getAttribute("ticks") || "0", 10) || values.length;
|
|
1986
|
-
// Slotted content support: authored .c-axis__tick children take
|
|
1987
|
-
// precedence over the JSON `values` attribute.
|
|
1988
|
-
const authoredTicks = Array.from(this.querySelectorAll(":scope > .c-axis__tick"));
|
|
1989
|
-
if (authoredTicks.length) {
|
|
1990
|
-
// keep authored ticks, just ensure labels are formatted
|
|
1991
|
-
authoredTicks.forEach((tick) => {
|
|
1992
|
-
const label = tick.querySelector(".c-axis__label");
|
|
1993
|
-
if (label && !label.textContent) label.textContent = tick.textContent;
|
|
1994
|
-
});
|
|
1995
|
-
} else {
|
|
1996
|
-
// clear
|
|
1997
|
-
Array.from(this.querySelectorAll(".c-axis__tick")).forEach((n) => n.remove());
|
|
1998
|
-
const list = values.length ? values : Array.from({ length: ticks }, (_, i) => i);
|
|
1999
|
-
list.forEach((v) => {
|
|
2000
|
-
const tick = document.createElement("span");
|
|
2001
|
-
tick.className = "c-axis__tick";
|
|
2002
|
-
const label = document.createElement("span");
|
|
2003
|
-
label.className = "c-axis__label";
|
|
2004
|
-
label.textContent = formatValue(String(v), this.getAttribute("format"), this.getAttribute("locale"));
|
|
2005
|
-
tick.appendChild(label);
|
|
2006
|
-
this.appendChild(tick);
|
|
2007
|
-
});
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
enhance() {}
|
|
2011
|
-
}
|
|
2012
|
-
define("contour-axis", ContourAxis);
|
|
2013
|
-
/**
|
|
2014
|
-
* Brush: web component wrapper.
|
|
2015
|
-
* Attributes: `start`, `end`, `min`, `max`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
2016
|
-
*/
|
|
2017
|
-
class ContourBrush extends ContourBase {
|
|
2018
|
-
static get observed() { return ["start", "end", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2019
|
-
static get properties() { return { start: { attribute: "start" }, end: { attribute: "end" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
|
|
2020
|
-
// The selection as a numeric pair in the track's own units. `start`/`end`
|
|
2021
|
-
// stay the attribute strings they have always been; `range` is the shape a
|
|
2022
|
-
// cross-filter consumer wants, and libreship's histogram binder reads it.
|
|
2023
|
-
_rangeValue() {
|
|
2024
|
-
const start = parseFloat(this.getAttribute("start"));
|
|
2025
|
-
const end = parseFloat(this.getAttribute("end"));
|
|
2026
|
-
return Number.isFinite(start) && Number.isFinite(end) ? [start, end] : null;
|
|
2027
|
-
}
|
|
2028
|
-
render() {
|
|
2029
|
-
this.classList.add("c-brush");
|
|
2030
|
-
this.setAttribute("role", "group");
|
|
2031
|
-
this.setAttribute("aria-label", "Brush selection");
|
|
2032
|
-
wireStates(this);
|
|
2033
|
-
loadRemote(this, []);
|
|
2034
|
-
if (renderStates(this, "brush")) return;
|
|
2035
|
-
let sel = this.querySelector(".c-brush__selection");
|
|
2036
|
-
if (!sel) { sel = document.createElement("div"); sel.className = "c-brush__selection"; this.appendChild(sel); }
|
|
2037
|
-
const start = parseFloat(this.getAttribute("start") || "0");
|
|
2038
|
-
const end = parseFloat(this.getAttribute("end") || "100");
|
|
2039
|
-
const min = parseFloat(this.getAttribute("min") || "0");
|
|
2040
|
-
const max = parseFloat(this.getAttribute("max") || "100");
|
|
2041
|
-
const range = max - min || 1;
|
|
2042
|
-
const left = ((start - min) / range) * 100;
|
|
2043
|
-
const width = ((end - start) / range) * 100;
|
|
2044
|
-
sel.style.insetInlineStart = left + "%";
|
|
2045
|
-
sel.style.inlineSize = width + "%";
|
|
2046
|
-
// handles
|
|
2047
|
-
["start","end"].forEach((h) => {
|
|
2048
|
-
let handle = this.querySelector(".c-brush__handle--" + h);
|
|
2049
|
-
if (!handle) { handle = document.createElement("div"); handle.className = "c-brush__handle c-brush__handle--" + h; this.appendChild(handle); }
|
|
2050
|
-
const val = h === "start" ? start : end;
|
|
2051
|
-
handle.style.insetInlineStart = (((val - min) / range) * 100) + "%";
|
|
2052
|
-
});
|
|
2053
|
-
}
|
|
2054
|
-
enhance() {
|
|
2055
|
-
if (this._wiredBrush) return;
|
|
2056
|
-
this._wiredBrush = true;
|
|
2057
|
-
let dragging = null;
|
|
2058
|
-
const min = () => parseFloat(this.getAttribute("min") || "0");
|
|
2059
|
-
const max = () => parseFloat(this.getAttribute("max") || "100");
|
|
2060
|
-
const toValue = (clientX) => {
|
|
2061
|
-
const r = this.getBoundingClientRect();
|
|
2062
|
-
const ratio = Math.max(0, Math.min(1, (clientX - r.left) / (r.width || 1)));
|
|
2063
|
-
return min() + ratio * (max() - min());
|
|
2064
|
-
};
|
|
2065
|
-
this.addEventListener("pointerdown", (e) => {
|
|
2066
|
-
const handle = e.target && e.target.classList && e.target.classList.contains("c-brush__handle") ? e.target : null;
|
|
2067
|
-
dragging = handle ? (handle.classList.contains("c-brush__handle--start") ? "start" : "end") : "move";
|
|
2068
|
-
try { this.setPointerCapture(e.pointerId); } catch (err) {}
|
|
2069
|
-
this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: { value: this.getAttribute("start"), start: this.getAttribute("start"), end: this.getAttribute("end"), range: this._rangeValue() } }));
|
|
2070
|
-
});
|
|
2071
|
-
this.addEventListener("pointermove", (e) => {
|
|
2072
|
-
if (!dragging) return;
|
|
2073
|
-
const v = toValue(e.clientX);
|
|
2074
|
-
const mn = min(), mx = max(), range = mx - mn || 1;
|
|
2075
|
-
const sel = this.querySelector(".c-brush__selection");
|
|
2076
|
-
let ns = parseFloat(this.getAttribute("start") || "0");
|
|
2077
|
-
let ne = parseFloat(this.getAttribute("end") || "100");
|
|
2078
|
-
if (dragging === "start") {
|
|
2079
|
-
ns = Math.min(v, ne);
|
|
2080
|
-
} else if (dragging === "end") {
|
|
2081
|
-
ne = Math.max(v, ns);
|
|
2082
|
-
} else {
|
|
2083
|
-
const width = ne - ns;
|
|
2084
|
-
ns = v - width / 2;
|
|
2085
|
-
ne = v + width / 2;
|
|
2086
|
-
if (ns < mn) { ne += mn - ns; ns = mn; }
|
|
2087
|
-
if (ne > mx) { ns -= ne - mx; ne = mx; }
|
|
2088
|
-
}
|
|
2089
|
-
ns = Math.max(mn, Math.min(mx, ns));
|
|
2090
|
-
ne = Math.max(mn, Math.min(mx, ne));
|
|
2091
|
-
// update DOM directly to avoid re-render during drag
|
|
2092
|
-
if (sel) {
|
|
2093
|
-
sel.style.insetInlineStart = (((ns - mn) / range) * 100) + "%";
|
|
2094
|
-
sel.style.inlineSize = (((ne - ns) / range) * 100) + "%";
|
|
2095
|
-
}
|
|
2096
|
-
const sh = this.querySelector(".c-brush__handle--start");
|
|
2097
|
-
const eh = this.querySelector(".c-brush__handle--end");
|
|
2098
|
-
if (sh) sh.style.insetInlineStart = (((ns - mn) / range) * 100) + "%";
|
|
2099
|
-
if (eh) eh.style.insetInlineStart = (((ne - mn) / range) * 100) + "%";
|
|
2100
|
-
// stash pending values
|
|
2101
|
-
this._brushPending = { start: ns, end: ne };
|
|
2102
|
-
this.dispatchEvent(new CustomEvent("contour:brush", { bubbles: true, composed: true, detail: { start: ns, end: ne, value: ns, range: [ns, ne] } }));
|
|
2103
|
-
});
|
|
2104
|
-
this.addEventListener("pointerup", (e) => {
|
|
2105
|
-
if (!dragging) return;
|
|
2106
|
-
dragging = null;
|
|
2107
|
-
const p = this._brushPending;
|
|
2108
|
-
if (p) {
|
|
2109
|
-
this.setAttribute("start", String(p.start));
|
|
2110
|
-
this.setAttribute("end", String(p.end));
|
|
2111
|
-
this._brushPending = null;
|
|
2112
|
-
}
|
|
2113
|
-
this.dispatchEvent(new CustomEvent("contour:brush-end", { bubbles: true, composed: true, detail: { value: this.getAttribute("end"), start: this.getAttribute("start"), end: this.getAttribute("end"), range: this._rangeValue() } }));
|
|
2114
|
-
this.dispatchEvent(new CustomEvent("contour:brush", { bubbles: true, composed: true, detail: { start: this.getAttribute("start"), end: this.getAttribute("end"), value: this.getAttribute("end"), range: this._rangeValue() } }));
|
|
2115
|
-
});
|
|
2116
|
-
// Keyboard: Enter/Space emits brush-start/brush-end (WC-P1-08).
|
|
2117
|
-
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
2118
|
-
this.addEventListener("keydown", (e) => {
|
|
2119
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
2120
|
-
e.preventDefault();
|
|
2121
|
-
this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: { value: this.getAttribute("start"), start: this.getAttribute("start"), end: this.getAttribute("end"), range: this._rangeValue() } }));
|
|
2122
|
-
}
|
|
2123
|
-
});
|
|
2124
|
-
// Cross-filter contract (R16-16): clear-all resets brush range.
|
|
2125
|
-
this.addEventListener("contour:clear-all", () => {
|
|
2126
|
-
if (this.hasAttribute("start") || this.hasAttribute("end")) {
|
|
2127
|
-
this.removeAttribute("start");
|
|
2128
|
-
this.removeAttribute("end");
|
|
2129
|
-
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "brush", filter: { start: null, end: null } } }));
|
|
2130
|
-
this.requestRender();
|
|
2131
|
-
}
|
|
2132
|
-
});
|
|
2133
|
-
}
|
|
2134
|
-
}
|
|
2135
|
-
define("contour-brush", ContourBrush);
|
|
2136
|
-
/**
|
|
2137
|
-
* Stacked Bar: web component wrapper.
|
|
2138
|
-
* Attributes: `segments`, `values`, `colors`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `normalize`.
|
|
2139
|
-
*/
|
|
2140
|
-
class ContourStackedBar extends ContourBase {
|
|
2141
|
-
static get observed() { return ["segments", "values", "colors", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "normalize"]; }
|
|
2142
|
-
static get properties() { return { segments: { attribute: "segments" }, values: { attribute: "values" }, colors: { attribute: "colors" }, src: { attribute: "src" }, normalize: { attribute: "normalize" } }; }
|
|
2143
|
-
render() {
|
|
2144
|
-
this.classList.add("c-stacked-bar");
|
|
2145
|
-
// The bar carries a listbox of selectable segments; role=img would make
|
|
2146
|
-
// every one of them presentational. A named group exposes them.
|
|
2147
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
2148
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Stacked bar");
|
|
2149
|
-
wireStates(this);
|
|
2150
|
-
loadRemote(this, ["segments", "values"]);
|
|
2151
|
-
if (renderStates(this, "stacked-bar")) return;
|
|
2152
|
-
Array.from(this.querySelectorAll(".c-stacked-bar__segment")).forEach((n) => n.remove());
|
|
2153
|
-
// Slotted content support: authored .c-stacked-bar__segment children take
|
|
2154
|
-
// precedence over the JSON `segments` attribute.
|
|
2155
|
-
const authoredSegments = Array.from(this.querySelectorAll(":scope > .c-stacked-bar__segment"));
|
|
2156
|
-
let segments = [];
|
|
2157
|
-
if (authoredSegments.length) {
|
|
2158
|
-
segments = authoredSegments.map((el) => ({
|
|
2159
|
-
label: el.getAttribute("title") || el.textContent || "",
|
|
2160
|
-
value: parseFloat(el.style.inlineSize) || 0,
|
|
2161
|
-
color: (el.dataset && el.dataset.color) || el.style.background || undefined,
|
|
2162
|
-
}));
|
|
2163
|
-
authoredSegments.forEach((el) => el.remove());
|
|
2164
|
-
} else {
|
|
2165
|
-
const sAttr = this.getAttribute("segments");
|
|
2166
|
-
if (sAttr) { try { segments = JSON.parse(sAttr); } catch (e) { segments = []; } }
|
|
2167
|
-
}
|
|
2168
|
-
const values = segments.map((seg) => (typeof seg === "object" ? (seg.value || 0) : Number(seg) || 0));
|
|
2169
|
-
const total = values.reduce((a, b) => a + b, 0) || 1;
|
|
2170
|
-
const normalize = this.hasAttribute("normalize");
|
|
2171
|
-
const denom = normalize ? total : (parseFloat(this.getAttribute("max") || String(total)) || total);
|
|
2172
|
-
segments.forEach((seg, i) => {
|
|
2173
|
-
const v = values[i];
|
|
2174
|
-
const el = document.createElement("div");
|
|
2175
|
-
el.className = "c-stacked-bar__segment";
|
|
2176
|
-
el.style.inlineSize = ((v / denom) * 100) + "%";
|
|
2177
|
-
el.style.background = (typeof seg === "object" && seg.color) ? seg.color : "var(--chart-" + ((i % 8) + 1) + ")";
|
|
2178
|
-
el.dataset.color = (typeof seg === "object" && seg.color) ? seg.color : el.style.background;
|
|
2179
|
-
el.setAttribute("title", (typeof seg === "object" ? (seg.label || "") : "") + " " + v);
|
|
2180
|
-
this.appendChild(el);
|
|
2181
|
-
});
|
|
2182
|
-
if (!segments.length) renderEmpty(this, "stacked-bar");
|
|
2183
|
-
}
|
|
2184
|
-
enhance() {}
|
|
2185
|
-
}
|
|
2186
|
-
define("contour-stacked-bar", ContourStackedBar);
|
|
2187
|
-
/**
|
|
2188
|
-
* Category: web component wrapper.
|
|
2189
|
-
* Attributes: `items`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `search`.
|
|
2190
|
-
*/
|
|
2191
|
-
class ContourCategory extends ContourBase {
|
|
2192
|
-
static get observed() { return ["items", "search", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "note", "limit", "sort"]; }
|
|
2193
|
-
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, search: { attribute: "search" }, note: { attribute: "note" }, limit: { attribute: "limit" }, sort: { attribute: "sort" } }; }
|
|
2194
|
-
render() {
|
|
2195
|
-
this.classList.add("c-category");
|
|
2196
|
-
this.setAttribute("role", "listbox");
|
|
2197
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Category");
|
|
2198
|
-
wireStates(this);
|
|
2199
|
-
loadRemote(this, ["items"]);
|
|
2200
|
-
if (renderStates(this, "category")) return;
|
|
2201
|
-
Array.from(this.querySelectorAll(".c-category__item")).forEach((n) => n.remove());
|
|
2202
|
-
// Slotted content support: authored .c-category__item children take
|
|
2203
|
-
// precedence over the JSON `items` attribute.
|
|
2204
|
-
const authoredItems = Array.from(this.querySelectorAll(":scope > .c-category__item"));
|
|
2205
|
-
let items = [];
|
|
2206
|
-
if (authoredItems.length) {
|
|
2207
|
-
authoredItems.forEach((el) => {
|
|
2208
|
-
const lbl = el.querySelector(".c-category__label");
|
|
2209
|
-
items.push({ label: lbl ? lbl.textContent : el.textContent, value: 0 });
|
|
2210
|
-
});
|
|
2211
|
-
authoredItems.forEach((el) => el.remove());
|
|
2212
|
-
} else {
|
|
2213
|
-
const iAttr = this.getAttribute("items");
|
|
2214
|
-
if (iAttr) { try { items = JSON.parse(iAttr); } catch (e) { items = []; } }
|
|
2215
|
-
}
|
|
2216
|
-
// Top-N + sort (CARTO-inspired): optional `limit` and `sort` attributes.
|
|
2217
|
-
const sort = this.getAttribute("sort") || "value-desc";
|
|
2218
|
-
items.sort((a, b) => {
|
|
2219
|
-
const va = (typeof a === "object") ? (a.value || 0) : (Number(a) || 0);
|
|
2220
|
-
const vb = (typeof b === "object") ? (b.value || 0) : (Number(b) || 0);
|
|
2221
|
-
const la = (typeof a === "object") ? (a.label || a.name || "") : String(a);
|
|
2222
|
-
const lb = (typeof b === "object") ? (b.label || b.name || "") : String(b);
|
|
2223
|
-
if (sort === "value-asc") return va - vb;
|
|
2224
|
-
if (sort === "alpha-asc") return String(la).localeCompare(String(lb));
|
|
2225
|
-
if (sort === "alpha-desc") return String(lb).localeCompare(String(la));
|
|
2226
|
-
return vb - va; // value-desc (default)
|
|
2227
|
-
});
|
|
2228
|
-
const limit = parseInt(this.getAttribute("limit") || "0", 10);
|
|
2229
|
-
if (limit > 0) items = items.slice(0, limit);
|
|
2230
|
-
const max = items.reduce((m, it) => Math.max(m, (typeof it === "object" ? (it.value || 0) : Number(it) || 0)), 0) || 1;
|
|
2231
|
-
items.forEach((it, idx) => {
|
|
2232
|
-
const value = (typeof it === "object") ? (it.value || 0) : (Number(it) || 0);
|
|
2233
|
-
const label = (typeof it === "object") ? (it.label || it.name || "") : String(it);
|
|
2234
|
-
const item = document.createElement("div");
|
|
2235
|
-
item.className = "c-category__item";
|
|
2236
|
-
item.setAttribute("role", "option");
|
|
2237
|
-
item.setAttribute("aria-selected", "false");
|
|
2238
|
-
item.setAttribute("tabindex", idx === 0 ? "0" : "-1");
|
|
2239
|
-
const lbl = document.createElement("span");
|
|
2240
|
-
lbl.className = "c-category__label";
|
|
2241
|
-
lbl.textContent = label;
|
|
2242
|
-
const barWrap = document.createElement("div");
|
|
2243
|
-
barWrap.style.flex = "1";
|
|
2244
|
-
const bar = document.createElement("div");
|
|
2245
|
-
bar.className = "c-category__bar";
|
|
2246
|
-
bar.style.inlineSize = ((value / max) * 100) + "%";
|
|
2247
|
-
barWrap.appendChild(bar);
|
|
2248
|
-
const val = document.createElement("span");
|
|
2249
|
-
val.className = "c-category__value";
|
|
2250
|
-
val.textContent = String(value);
|
|
2251
|
-
item.appendChild(lbl);
|
|
2252
|
-
item.appendChild(barWrap);
|
|
2253
|
-
item.appendChild(val);
|
|
2254
|
-
this.appendChild(item);
|
|
2255
|
-
});
|
|
2256
|
-
if (!items.length) renderEmpty(this, "category");
|
|
2257
|
-
const note = this.getAttribute("note");
|
|
2258
|
-
let noteEl = this.querySelector(".c-category__note");
|
|
2259
|
-
if (note) {
|
|
2260
|
-
if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-category__note"; this.appendChild(noteEl); }
|
|
2261
|
-
noteEl.textContent = note;
|
|
2262
|
-
} else if (noteEl) {
|
|
2263
|
-
noteEl.remove();
|
|
2264
|
-
}
|
|
2265
|
-
}
|
|
2266
|
-
enhance() {
|
|
2267
|
-
if (this._wiredCategory) return;
|
|
2268
|
-
this._wiredCategory = true;
|
|
2269
|
-
const items = () => Array.from(this.querySelectorAll(".c-category__item"));
|
|
2270
|
-
const showTip = (e) => {};
|
|
2271
|
-
this.addEventListener("click", (e) => {
|
|
2272
|
-
const item = e.target && e.target.closest ? e.target.closest(".c-category__item") : null;
|
|
2273
|
-
if (!item || !this.contains(item)) return;
|
|
2274
|
-
const all = items();
|
|
2275
|
-
const idx = all.indexOf(item);
|
|
2276
|
-
all.forEach((o, i) => o.setAttribute("aria-selected", i === idx ? "true" : "false"));
|
|
2277
|
-
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() } }));
|
|
2278
|
-
});
|
|
2279
|
-
this.addEventListener("keydown", (e) => {
|
|
2280
|
-
const item = e.target && e.target.closest ? e.target.closest(".c-category__item") : null;
|
|
2281
|
-
if (!item || !this.contains(item)) return;
|
|
2282
|
-
const all = items();
|
|
2283
|
-
const idx = all.indexOf(item);
|
|
2284
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
2285
|
-
e.preventDefault();
|
|
2286
|
-
all.forEach((o, i) => o.setAttribute("aria-selected", i === idx ? "true" : "false"));
|
|
2287
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx, label: item.querySelector(".c-category__label") ? item.querySelector(".c-category__label").textContent : item.textContent.trim() } }));
|
|
2288
|
-
return;
|
|
2289
|
-
}
|
|
2290
|
-
navKey(e, all, {
|
|
2291
|
-
wrap: false,
|
|
2292
|
-
homeEnd: true,
|
|
2293
|
-
rtl: isRtl(this),
|
|
2294
|
-
onNavigate: (i) => all.forEach((it, j) => it.setAttribute("tabindex", j === i ? "0" : "-1")),
|
|
2295
|
-
onKey: () => {
|
|
2296
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
2297
|
-
const idx2 = all.indexOf(document.activeElement);
|
|
2298
|
-
all.forEach((o, j) => o.setAttribute("aria-selected", j === idx2 ? "true" : "false"));
|
|
2299
|
-
this.dispatchEvent(new CustomEvent("contour:select", {
|
|
2300
|
-
bubbles: true,
|
|
2301
|
-
composed: true,
|
|
2302
|
-
detail: {
|
|
2303
|
-
index: idx2,
|
|
2304
|
-
label: document.activeElement.querySelector(".c-category__label")
|
|
2305
|
-
? document.activeElement.querySelector(".c-category__label").textContent
|
|
2306
|
-
: document.activeElement.textContent.trim()
|
|
2307
|
-
}
|
|
2308
|
-
}));
|
|
2309
|
-
}
|
|
2310
|
-
}
|
|
2311
|
-
});
|
|
2312
|
-
});
|
|
2313
|
-
// Cross-filter contract (R16-16): clear-all resets search filter.
|
|
2314
|
-
this.addEventListener("contour:clear-all", () => {
|
|
2315
|
-
if (this.hasAttribute("search")) {
|
|
2316
|
-
this.removeAttribute("search");
|
|
2317
|
-
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "category", filter: { search: null } } }));
|
|
2318
|
-
}
|
|
2319
|
-
});
|
|
2320
|
-
}
|
|
2321
|
-
}
|
|
2322
|
-
define("contour-category", ContourCategory);
|
|
2323
|
-
/**
|
|
2324
|
-
* Donut: web component wrapper.
|
|
2325
|
-
* Attributes: `value`, `values`, `items`, `label`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `brownout`, `brownout-level`.
|
|
2326
|
-
*/
|
|
2327
|
-
class ContourDonut extends ContourBase {
|
|
2328
|
-
static get observed() { return ["value", "values", "items", "label", "color", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level", "note"]; }
|
|
2329
|
-
static get properties() { return { value: { attribute: "value" }, values: { attribute: "values" }, items: { attribute: "items" }, label: { attribute: "label" }, color: { attribute: "color" }, src: { attribute: "src" }, note: { attribute: "note" } }; }
|
|
2330
|
-
render() {
|
|
2331
|
-
this.classList.add("c-donut");
|
|
2332
|
-
// The donut renders a list of segments beside the ring; an image role
|
|
2333
|
-
// would flatten that list out of the accessibility tree.
|
|
2334
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
2335
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Donut chart");
|
|
2336
|
-
wireStates(this);
|
|
2337
|
-
loadRemote(this, ["items", "values"]);
|
|
2338
|
-
if (renderStates(this, "donut")) return;
|
|
2339
|
-
Array.from(this.querySelectorAll(".c-donut__ring, .c-donut__center, .c-donut__list, .c-donut__empty")).forEach((n) => n.remove());
|
|
2340
|
-
// Slotted content support: authored .c-donut__item children take precedence
|
|
2341
|
-
// over the JSON `items` attribute, so consumers can compose legend rows
|
|
2342
|
-
// by hand instead of serialising them into an attribute.
|
|
2343
|
-
const authoredItems = Array.from(this.querySelectorAll(":scope > .c-donut__item"));
|
|
2344
|
-
let items = [];
|
|
2345
|
-
if (authoredItems.length) {
|
|
2346
|
-
authoredItems.forEach((el) => {
|
|
2347
|
-
const sw = el.querySelector(".c-donut__swatch");
|
|
2348
|
-
const lbl = el.querySelector("span:last-child");
|
|
2349
|
-
const text = lbl ? lbl.textContent : el.textContent;
|
|
2350
|
-
const match = text.match(/—\s*(\d+(?:\.\d+)?)$/);
|
|
2351
|
-
items.push({ label: text.replace(/—\s*\d+(?:\.\d+)?$/, "").trim(), value: match ? Number(match[1]) : 0, color: sw ? (sw.dataset && sw.dataset.color) || sw.style.background : undefined });
|
|
2352
|
-
});
|
|
2353
|
-
// remove authored items from DOM (they will be regenerated below)
|
|
2354
|
-
authoredItems.forEach((el) => el.remove());
|
|
2355
|
-
} else {
|
|
2356
|
-
const iAttr = this.getAttribute("items");
|
|
2357
|
-
if (iAttr) { try { items = JSON.parse(iAttr); } catch (e) { items = []; } }
|
|
2358
|
-
}
|
|
2359
|
-
const values = items.map((it) => (typeof it === "object" ? (it.value || 0) : Number(it) || 0));
|
|
2360
|
-
const total = values.reduce((a, b) => a + b, 0) || 1;
|
|
2361
|
-
const brownoutLevel = this.brownoutLevel();
|
|
2362
|
-
const layerColor = this.getAttribute("color");
|
|
2363
|
-
const shedRing = this.shed("ring", 3);
|
|
2364
|
-
if (!shedRing) {
|
|
2365
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
2366
|
-
svg.setAttribute("class", "c-donut__ring");
|
|
2367
|
-
svg.setAttribute("viewBox", "0 0 32 32");
|
|
2368
|
-
let offset = 0;
|
|
2369
|
-
items.forEach((it, i) => {
|
|
2370
|
-
const v = values[i];
|
|
2371
|
-
const pct = v / total;
|
|
2372
|
-
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
2373
|
-
circle.setAttribute("cx", "16"); circle.setAttribute("cy", "16"); circle.setAttribute("r", "12");
|
|
2374
|
-
circle.setAttribute("fill", "none");
|
|
2375
|
-
circle.setAttribute("stroke", layerColor || (typeof it === "object" && it.color ? it.color : "var(--chart-" + ((i % 8) + 1) + ")"));
|
|
2376
|
-
circle.setAttribute("stroke-width", "6");
|
|
2377
|
-
const circ = 2 * Math.PI * 12;
|
|
2378
|
-
circle.setAttribute("stroke-dasharray", (pct * circ) + " " + (circ - pct * circ));
|
|
2379
|
-
circle.setAttribute("stroke-dashoffset", String(-offset * circ));
|
|
2380
|
-
circle.setAttribute("transform", "rotate(-90 16 16)");
|
|
2381
|
-
svg.appendChild(circle);
|
|
2382
|
-
offset += pct;
|
|
2383
|
-
});
|
|
2384
|
-
// center hole
|
|
2385
|
-
const hole = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
2386
|
-
hole.setAttribute("cx", "16"); hole.setAttribute("cy", "16"); hole.setAttribute("r", "9");
|
|
2387
|
-
hole.setAttribute("fill", "var(--color-surface-0)");
|
|
2388
|
-
svg.appendChild(hole);
|
|
2389
|
-
this.appendChild(svg);
|
|
2390
|
-
}
|
|
2391
|
-
const center = document.createElement("div");
|
|
2392
|
-
center.className = "c-donut__center";
|
|
2393
|
-
center.textContent = this.getAttribute("value") || String(total);
|
|
2394
|
-
this.appendChild(center);
|
|
2395
|
-
// text list
|
|
2396
|
-
const list = document.createElement("div");
|
|
2397
|
-
list.className = "c-donut__list";
|
|
2398
|
-
list.setAttribute("role", "list");
|
|
2399
|
-
items.forEach((it, i) => {
|
|
2400
|
-
const row = document.createElement("div");
|
|
2401
|
-
row.className = "c-donut__item";
|
|
2402
|
-
row.setAttribute("role", "listitem");
|
|
2403
|
-
const sw = document.createElement("span");
|
|
2404
|
-
sw.className = "c-donut__swatch";
|
|
2405
|
-
sw.style.background = layerColor || (typeof it === "object" && it.color ? it.color : "var(--chart-" + ((i % 8) + 1) + ")");
|
|
2406
|
-
if (sw.style.background) sw.dataset.color = layerColor || (typeof it === "object" && it.color ? it.color : sw.style.background);
|
|
2407
|
-
row.appendChild(sw);
|
|
2408
|
-
const lbl = document.createElement("span");
|
|
2409
|
-
lbl.textContent = (typeof it === "object" ? (it.label || "") : String(it)) + " — " + values[i];
|
|
2410
|
-
row.appendChild(lbl);
|
|
2411
|
-
list.appendChild(row);
|
|
2412
|
-
});
|
|
2413
|
-
this.appendChild(list);
|
|
2414
|
-
if (!items.length) renderEmpty(this, "donut");
|
|
2415
|
-
const note = this.getAttribute("note");
|
|
2416
|
-
let noteEl = this.querySelector(".c-donut__note");
|
|
2417
|
-
if (note) {
|
|
2418
|
-
if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-donut__note"; this.appendChild(noteEl); }
|
|
2419
|
-
noteEl.textContent = note;
|
|
2420
|
-
} else if (noteEl) {
|
|
2421
|
-
noteEl.remove();
|
|
2422
|
-
}
|
|
2423
|
-
}
|
|
2424
|
-
enhance() {}
|
|
2425
|
-
}
|
|
2426
|
-
define("contour-donut", ContourDonut);
|
|
2427
|
-
/**
|
|
2428
|
-
* Time Series: web component wrapper.
|
|
2429
|
-
* Attributes: `values`, `points`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `annotations`.
|
|
2430
|
-
*/
|
|
2431
|
-
class ContourTimeSeries extends ContourBase {
|
|
2432
|
-
static get observed() { return ["values", "points", "series", "style", "title", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "annotations", "note"]; }
|
|
2433
|
-
static get properties() { return { values: { attribute: "values" }, points: { attribute: "points" }, series: { attribute: "series" }, style: { attribute: "style" }, src: { attribute: "src" }, annotations: { attribute: "annotations" }, note: { attribute: "note" } }; }
|
|
2434
|
-
render() {
|
|
2435
|
-
this.classList.add("c-time-series");
|
|
2436
|
-
// Points and bars are focusable marks (roving tabindex below); role=img
|
|
2437
|
-
// hides them. A named group keeps the name and exposes the marks.
|
|
2438
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
2439
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Time series");
|
|
2440
|
-
wireStates(this);
|
|
2441
|
-
loadRemote(this, ["values", "points", "series"]);
|
|
2442
|
-
if (renderStates(this, "time-series")) return;
|
|
2443
|
-
Array.from(this.querySelectorAll(".c-time-series__plot, .c-time-series__axis")).forEach((n) => n.remove());
|
|
2444
|
-
// Series management (R16-21): support multiple series via `series` JSON
|
|
2445
|
-
// attribute, with per-series style (line|bar), color binding, and
|
|
2446
|
-
// interval control. Falls back to single `values` attribute for
|
|
2447
|
-
// backward compatibility.
|
|
2448
|
-
let series = [];
|
|
2449
|
-
const sAttr = this.getAttribute("series");
|
|
2450
|
-
if (sAttr) { try { series = JSON.parse(sAttr); } catch (e) { series = []; } }
|
|
2451
|
-
const remote = remoteData(this, "series");
|
|
2452
|
-
if (Array.isArray(remote)) series = remote;
|
|
2453
|
-
// Backward compat: single `values` attribute becomes one series.
|
|
2454
|
-
if (!series.length) {
|
|
2455
|
-
let values = [];
|
|
2456
|
-
const vAttr = this.getAttribute("values");
|
|
2457
|
-
if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map(Number); } }
|
|
2458
|
-
if (values.length) {
|
|
2459
|
-
series = [{ label: "Series 1", values, style: this.getAttribute("style") || "bar", color: "var(--chart-1)" }];
|
|
2460
|
-
}
|
|
2461
|
-
}
|
|
2462
|
-
const max = series.reduce((m, s) => { const v = Array.isArray(s.values) ? Math.max(...s.values, 0) : 0; return Math.max(m, v); }, 1);
|
|
2463
|
-
const min = series.reduce((m, s) => { const v = Array.isArray(s.values) ? Math.min(...s.values, 0) : 0; return Math.min(m, v); }, 0);
|
|
2464
|
-
const plot = document.createElement("div");
|
|
2465
|
-
plot.className = "c-time-series__plot";
|
|
2466
|
-
plot.setAttribute("part", "plot");
|
|
2467
|
-
series.forEach((s, si) => {
|
|
2468
|
-
const values = Array.isArray(s.values) ? s.values : [];
|
|
2469
|
-
const style = s.style || "bar";
|
|
2470
|
-
const color = s.color || `var(--chart-${((si % 8) + 1)})`;
|
|
2471
|
-
const label = s.label || `Series ${si + 1}`;
|
|
2472
|
-
if (style === "line") {
|
|
2473
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
2474
|
-
svg.setAttribute("viewBox", "0 0 300 120");
|
|
2475
|
-
svg.setAttribute("preserveAspectRatio", "none");
|
|
2476
|
-
svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
|
|
2477
|
-
const range = (max - min) || 1;
|
|
2478
|
-
const n = values.length || 1;
|
|
2479
|
-
const pts = values.map((v, i) => {
|
|
2480
|
-
const x = (i / Math.max(1, n - 1)) * 300;
|
|
2481
|
-
const y = 120 - ((v - min) / range) * 120;
|
|
2482
|
-
return x.toFixed(2) + "," + y.toFixed(2);
|
|
2483
|
-
}).join(" ");
|
|
2484
|
-
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
2485
|
-
path.setAttribute("class", "c-time-series__line");
|
|
2486
|
-
path.setAttribute("data-series", String(si));
|
|
2487
|
-
path.setAttribute("d", "M " + pts.replace(/ /g, " L "));
|
|
2488
|
-
path.style.stroke = color;
|
|
2489
|
-
path.style.fill = "none";
|
|
2490
|
-
path.style.strokeWidth = "2";
|
|
2491
|
-
svg.appendChild(path);
|
|
2492
|
-
// point markers
|
|
2493
|
-
values.forEach((v, i) => {
|
|
2494
|
-
const x = (i / Math.max(1, n - 1)) * 300;
|
|
2495
|
-
const y = 120 - ((v - min) / range) * 120;
|
|
2496
|
-
const c = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
2497
|
-
c.setAttribute("class", "c-time-series__point");
|
|
2498
|
-
c.setAttribute("data-series", String(si));
|
|
2499
|
-
c.setAttribute("data-index", String(i));
|
|
2500
|
-
c.setAttribute("cx", x.toFixed(2));
|
|
2501
|
-
c.setAttribute("cy", y.toFixed(2));
|
|
2502
|
-
c.setAttribute("r", "3");
|
|
2503
|
-
c.setAttribute("tabindex", i === 0 && si === 0 ? "0" : "-1");
|
|
2504
|
-
c.setAttribute("role", "button");
|
|
2505
|
-
c.setAttribute("title", String(v));
|
|
2506
|
-
c.setAttribute("aria-label", label + ": " + String(v));
|
|
2507
|
-
svg.appendChild(c);
|
|
2508
|
-
});
|
|
2509
|
-
plot.appendChild(svg);
|
|
2510
|
-
} else {
|
|
2511
|
-
values.forEach((v, i) => {
|
|
2512
|
-
const bar = document.createElement("div");
|
|
2513
|
-
bar.className = "c-time-series__bar";
|
|
2514
|
-
bar.setAttribute("data-series", String(si));
|
|
2515
|
-
bar.setAttribute("data-index", String(i));
|
|
2516
|
-
bar.style.blockSize = ((v / max) * 100) + "%";
|
|
2517
|
-
bar.style.background = color;
|
|
2518
|
-
bar.setAttribute("title", String(v));
|
|
2519
|
-
// A clickable, focusable mark is a button, not an image; the point
|
|
2520
|
-
// marks above already carry this role.
|
|
2521
|
-
bar.setAttribute("role", "button");
|
|
2522
|
-
bar.setAttribute("aria-label", label + ": " + String(v));
|
|
2523
|
-
bar.setAttribute("tabindex", i === 0 && si === 0 ? "0" : "-1");
|
|
2524
|
-
plot.appendChild(bar);
|
|
2525
|
-
});
|
|
2526
|
-
}
|
|
2527
|
-
});
|
|
2528
|
-
this.appendChild(plot);
|
|
2529
|
-
if (!series.length || !series.some((s) => Array.isArray(s.values) && s.values.length)) renderEmpty(this, "time-series");
|
|
2530
|
-
const note = this.getAttribute("note");
|
|
2531
|
-
let noteEl = this.querySelector(".c-time-series__note");
|
|
2532
|
-
if (note) {
|
|
2533
|
-
if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-time-series__note"; this.appendChild(noteEl); }
|
|
2534
|
-
noteEl.textContent = note;
|
|
2535
|
-
} else if (noteEl) {
|
|
2536
|
-
noteEl.remove();
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2539
|
-
enhance() {
|
|
2540
|
-
if (this._wiredTimeSeries) return;
|
|
2541
|
-
this._wiredTimeSeries = true;
|
|
2542
|
-
const bars = () => Array.from(this.querySelectorAll(".c-time-series__bar"));
|
|
2543
|
-
const points = () => Array.from(this.querySelectorAll(".c-time-series__point"));
|
|
2544
|
-
this.addEventListener("click", (e) => {
|
|
2545
|
-
const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
|
|
2546
|
-
if (!bar || !this.contains(bar)) return;
|
|
2547
|
-
const seriesIdx = Number(bar.dataset.series || "0");
|
|
2548
|
-
const idx = Number(bar.dataset.index || "0");
|
|
2549
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: seriesIdx, index: idx, value: bar.getAttribute("title") } }));
|
|
2550
|
-
return;
|
|
2551
|
-
});
|
|
2552
|
-
const pointClick = (e) => {
|
|
2553
|
-
const point = e.target && e.target.closest ? e.target.closest(".c-time-series__point") : null;
|
|
2554
|
-
if (!point || !this.contains(point)) return;
|
|
2555
|
-
const seriesIdx = Number(point.dataset.series || "0");
|
|
2556
|
-
const idx = Number(point.dataset.index || "0");
|
|
2557
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: seriesIdx, index: idx, value: point.getAttribute("title") } }));
|
|
2558
|
-
};
|
|
2559
|
-
this.addEventListener("click", pointClick);
|
|
2560
|
-
this.addEventListener("keydown", (e) => {
|
|
2561
|
-
const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
|
|
2562
|
-
if (!bar || !this.contains(bar)) return;
|
|
2563
|
-
const all = bars();
|
|
2564
|
-
const idx = all.indexOf(bar);
|
|
2565
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
2566
|
-
e.preventDefault();
|
|
2567
|
-
const seriesIdx = Number(bar.dataset.series || "0");
|
|
2568
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: seriesIdx, index: idx, value: bar.getAttribute("title") } }));
|
|
2569
|
-
return;
|
|
2570
|
-
}
|
|
2571
|
-
navKey(e, all, {
|
|
2572
|
-
wrap: false,
|
|
2573
|
-
homeEnd: true,
|
|
2574
|
-
rtl: isRtl(this),
|
|
2575
|
-
onNavigate: (i) => all.forEach((b, j) => b.setAttribute("tabindex", j === i ? "0" : "-1")),
|
|
2576
|
-
onKey: () => {}
|
|
2577
|
-
});
|
|
2578
|
-
});
|
|
2579
|
-
// focus tooltip
|
|
2580
|
-
this.addEventListener("focusin", (e) => {
|
|
2581
|
-
const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
|
|
2582
|
-
if (bar && this.contains(bar)) {
|
|
2583
|
-
const tip = this.querySelector(".c-time-series__tooltip");
|
|
2584
|
-
if (tip) { tip.textContent = bar.getAttribute("title"); tip.removeAttribute("hidden"); }
|
|
2585
|
-
}
|
|
2586
|
-
const point = e.target && e.target.closest ? e.target.closest(".c-time-series__point") : null;
|
|
2587
|
-
if (point && this.contains(point)) {
|
|
2588
|
-
const tip = this.querySelector(".c-time-series__tooltip");
|
|
2589
|
-
if (tip) { tip.textContent = point.getAttribute("title"); tip.removeAttribute("hidden"); }
|
|
2590
|
-
}
|
|
2591
|
-
});
|
|
2592
|
-
this.addEventListener("focusout", (e) => {
|
|
2593
|
-
const tip = this.querySelector(".c-time-series__tooltip");
|
|
2594
|
-
if (tip && !this.contains(e.relatedTarget)) tip.setAttribute("hidden", "");
|
|
2595
|
-
});
|
|
2596
|
-
}
|
|
2597
|
-
}
|
|
2598
|
-
define("contour-time-series", ContourTimeSeries);
|
|
2599
|
-
/**
|
|
2600
|
-
* Pivot: web component wrapper.
|
|
2601
|
-
* Attributes: `rows`, `columns`, `values`, `data`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
2602
|
-
*/
|
|
2603
|
-
class ContourPivot extends ContourBase {
|
|
2604
|
-
static get observed() { return ["rows", "columns", "values", "data", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2605
|
-
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" } }; }
|
|
2606
|
-
_aggregateFn(name) {
|
|
2607
|
-
const n = (name || "sum").toLowerCase();
|
|
2608
|
-
if (n === "avg" || n === "average" || n === "mean") return (vals) => vals.length ? vals.reduce((a,b)=>a+b,0)/vals.length : 0;
|
|
2609
|
-
if (n === "count") return (vals) => vals.length;
|
|
2610
|
-
if (n === "min") return (vals) => vals.length ? Math.min(...vals) : 0;
|
|
2611
|
-
if (n === "max") return (vals) => vals.length ? Math.max(...vals) : 0;
|
|
2612
|
-
return (vals) => vals.reduce((a,b)=>a+b,0);
|
|
2613
|
-
}
|
|
2614
|
-
render() {
|
|
2615
|
-
this.classList.add("c-pivot");
|
|
2616
|
-
wireStates(this);
|
|
2617
|
-
loadRemote(this, ["data"]);
|
|
2618
|
-
if (renderStates(this, "pivot")) return;
|
|
2619
|
-
Array.from(this.querySelectorAll("table, .c-pivot__toolbar")).forEach((n) => n.remove());
|
|
2620
|
-
let data = [];
|
|
2621
|
-
const dAttr = this.getAttribute("data");
|
|
2622
|
-
if (dAttr) { try { data = JSON.parse(dAttr); } catch (e) { data = []; } }
|
|
2623
|
-
const rows = this.getAttribute("rows") ? this.getAttribute("rows").split(",").map((s)=>s.trim()).filter(Boolean) : [];
|
|
2624
|
-
const cols = this.getAttribute("columns") ? this.getAttribute("columns").split(",").map((s)=>s.trim()).filter(Boolean) : [];
|
|
2625
|
-
const aggName = this.getAttribute("aggregate") || "sum";
|
|
2626
|
-
const aggFn = this._aggregateFn(aggName);
|
|
2627
|
-
const filterQ = (this.getAttribute("filter") || "").toLowerCase().trim();
|
|
2628
|
-
// Toolbar: filter input + aggregate selector.
|
|
2629
|
-
const toolbar = document.createElement("div");
|
|
2630
|
-
toolbar.className = "c-pivot__toolbar";
|
|
2631
|
-
toolbar.style.display = "flex";
|
|
2632
|
-
const filterInput = document.createElement("input");
|
|
2633
|
-
filterInput.type = "search";
|
|
2634
|
-
filterInput.className = "c-input c-pivot__filter";
|
|
2635
|
-
filterInput.placeholder = "Filter…";
|
|
2636
|
-
filterInput.value = this.getAttribute("filter") || "";
|
|
2637
|
-
filterInput.setAttribute("aria-label", "Filter pivot");
|
|
2638
|
-
const aggSelect = document.createElement("select");
|
|
2639
|
-
aggSelect.className = "c-select c-pivot__aggregate";
|
|
2640
|
-
aggSelect.setAttribute("aria-label", "Aggregation");
|
|
2641
|
-
["sum","avg","count","min","max"].forEach((a) => {
|
|
2642
|
-
const opt = document.createElement("option");
|
|
2643
|
-
opt.value = a; opt.textContent = a;
|
|
2644
|
-
if (a === aggName) opt.selected = true;
|
|
2645
|
-
aggSelect.appendChild(opt);
|
|
2646
|
-
});
|
|
2647
|
-
toolbar.appendChild(filterInput);
|
|
2648
|
-
toolbar.appendChild(aggSelect);
|
|
2649
|
-
this.appendChild(toolbar);
|
|
2650
|
-
// Filter rows/cols.
|
|
2651
|
-
let visibleRows = rows;
|
|
2652
|
-
let visibleCols = cols;
|
|
2653
|
-
if (filterQ) {
|
|
2654
|
-
visibleRows = rows.filter((r) => r.toLowerCase().includes(filterQ) || data.some((d) => d.row === r && String(d.value).toLowerCase().includes(filterQ)));
|
|
2655
|
-
visibleCols = cols.filter((c) => c.toLowerCase().includes(filterQ) || data.some((d) => d.col === c && String(d.value).toLowerCase().includes(filterQ)));
|
|
2656
|
-
if (!visibleRows.length) visibleRows = rows;
|
|
2657
|
-
if (!visibleCols.length) visibleCols = cols;
|
|
2658
|
-
}
|
|
2659
|
-
const table = document.createElement("table");
|
|
2660
|
-
table.setAttribute("role", "grid");
|
|
2661
|
-
table.setAttribute("aria-rowcount", String(visibleRows.length + 1));
|
|
2662
|
-
table.setAttribute("aria-colcount", String(visibleCols.length + 1));
|
|
2663
|
-
const thead = document.createElement("thead");
|
|
2664
|
-
const hr = document.createElement("tr");
|
|
2665
|
-
const corner = document.createElement("th");
|
|
2666
|
-
corner.textContent = "";
|
|
2667
|
-
corner.setAttribute("role", "columnheader");
|
|
2668
|
-
corner.setAttribute("aria-label", "Row");
|
|
2669
|
-
hr.appendChild(corner);
|
|
2670
|
-
visibleCols.forEach((c) => { const th = document.createElement("th"); th.textContent = c; th.setAttribute("role", "columnheader"); th.setAttribute("tabindex", "0"); hr.appendChild(th); });
|
|
2671
|
-
thead.appendChild(hr);
|
|
2672
|
-
table.appendChild(thead);
|
|
2673
|
-
const tbody = document.createElement("tbody");
|
|
2674
|
-
visibleRows.forEach((r) => {
|
|
2675
|
-
const tr = document.createElement("tr");
|
|
2676
|
-
tr.setAttribute("role", "row");
|
|
2677
|
-
const th = document.createElement("th");
|
|
2678
|
-
th.textContent = r;
|
|
2679
|
-
th.setAttribute("role", "rowheader");
|
|
2680
|
-
th.setAttribute("tabindex", "0");
|
|
2681
|
-
tr.appendChild(th);
|
|
2682
|
-
visibleCols.forEach((c) => {
|
|
2683
|
-
const td = document.createElement("td");
|
|
2684
|
-
td.setAttribute("role", "gridcell");
|
|
2685
|
-
td.setAttribute("tabindex", "0");
|
|
2686
|
-
const cellData = data.filter((d) => d.row === r && d.col === c);
|
|
2687
|
-
const vals = cellData.map((d) => Number(d.value)).filter((n) => Number.isFinite(n));
|
|
2688
|
-
if (cellData.length && vals.length === cellData.length && vals.length) {
|
|
2689
|
-
const v = aggFn(vals);
|
|
2690
|
-
td.textContent = Number.isInteger(v) ? String(v) : v.toFixed(2);
|
|
2691
|
-
} else if (cellData.length) {
|
|
2692
|
-
td.textContent = cellData.map((d) => d.value).join(", ");
|
|
2693
|
-
} else {
|
|
2694
|
-
td.textContent = "";
|
|
2695
|
-
}
|
|
2696
|
-
if (!td.textContent.trim()) td.setAttribute("aria-label", "Empty");
|
|
2697
|
-
tr.appendChild(td);
|
|
2698
|
-
});
|
|
2699
|
-
tbody.appendChild(tr);
|
|
2700
|
-
});
|
|
2701
|
-
table.appendChild(tbody);
|
|
2702
|
-
this.appendChild(table);
|
|
2703
|
-
if (!data.length && !rows.length && !cols.length) renderEmpty(this, "pivot");
|
|
2704
|
-
}
|
|
2705
|
-
enhance() {
|
|
2706
|
-
if (this._wiredPivot) return;
|
|
2707
|
-
this._wiredPivot = true;
|
|
2708
|
-
this.addEventListener("click", (e) => {
|
|
2709
|
-
const th = e.target && e.target.closest ? e.target.closest("th") : null;
|
|
2710
|
-
const td = e.target && e.target.closest ? e.target.closest("td") : null;
|
|
2711
|
-
const filterInput = e.target && e.target.closest ? e.target.closest(".c-pivot__filter") : null;
|
|
2712
|
-
const aggSelect = e.target && e.target.closest ? e.target.closest(".c-pivot__aggregate") : null;
|
|
2713
|
-
if (filterInput) return;
|
|
2714
|
-
if (aggSelect) return;
|
|
2715
|
-
if (th && this.contains(th) && th.parentElement && th.parentElement.parentElement && th.parentElement.parentElement.tagName === "THEAD") {
|
|
2716
|
-
this.dispatchEvent(new CustomEvent("contour:sort", { bubbles: true, composed: true, detail: { column: th.textContent.trim() } }));
|
|
2717
|
-
return;
|
|
2718
|
-
}
|
|
2719
|
-
if (td && this.contains(td)) {
|
|
2720
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { value: td.textContent } }));
|
|
2721
|
-
}
|
|
2722
|
-
});
|
|
2723
|
-
this.addEventListener("input", (e) => {
|
|
2724
|
-
const fi = e.target && e.target.closest ? e.target.closest(".c-pivot__filter") : null;
|
|
2725
|
-
if (fi && this.contains(fi)) {
|
|
2726
|
-
this.setAttribute("filter", fi.value);
|
|
2727
|
-
this.render();
|
|
2728
|
-
this.dispatchEvent(new CustomEvent("contour:filter", { bubbles: true, composed: true, detail: { query: fi.value } }));
|
|
2729
|
-
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "pivot", filter: { filter: fi.value } } }));
|
|
2730
|
-
}
|
|
2731
|
-
});
|
|
2732
|
-
this.addEventListener("change", (e) => {
|
|
2733
|
-
const as = e.target && e.target.closest ? e.target.closest(".c-pivot__aggregate") : null;
|
|
2734
|
-
if (as && this.contains(as)) {
|
|
2735
|
-
this.setAttribute("aggregate", as.value);
|
|
2736
|
-
this.render();
|
|
2737
|
-
this.dispatchEvent(new CustomEvent("contour:aggregate", { bubbles: true, composed: true, detail: { aggregate: as.value } }));
|
|
2738
|
-
}
|
|
2739
|
-
});
|
|
2740
|
-
this.addEventListener("keydown", (e) => {
|
|
2741
|
-
const cell = e.target && e.target.closest ? e.target.closest("th, td") : null;
|
|
2742
|
-
if (!cell || !this.contains(cell)) return;
|
|
2743
|
-
const table = this.querySelector("table");
|
|
2744
|
-
if (!table) return;
|
|
2745
|
-
const rows = Array.from(table.querySelectorAll("tr"));
|
|
2746
|
-
const ri = rows.indexOf(cell.parentElement);
|
|
2747
|
-
const ci = Array.from(cell.parentElement.children).indexOf(cell);
|
|
2748
|
-
let target = null;
|
|
2749
|
-
if (e.key === "ArrowRight") target = cell.parentElement.children[ci + 1];
|
|
2750
|
-
else if (e.key === "ArrowLeft") target = cell.parentElement.children[ci - 1];
|
|
2751
|
-
else if (e.key === "ArrowDown") target = rows[ri + 1] && rows[ri + 1].children[ci];
|
|
2752
|
-
else if (e.key === "ArrowUp") target = rows[ri - 1] && rows[ri - 1].children[ci];
|
|
2753
|
-
else if (e.key === "Home") target = cell.parentElement.children[0];
|
|
2754
|
-
else if (e.key === "End") target = cell.parentElement.children[cell.parentElement.children.length - 1];
|
|
2755
|
-
if (target) { e.preventDefault(); try { target.focus(); } catch (err) {} }
|
|
2756
|
-
});
|
|
2757
|
-
// Cross-filter contract (R16-16): clear-all resets pivot filter.
|
|
2758
|
-
this.addEventListener("contour:clear-all", () => {
|
|
2759
|
-
if (this.hasAttribute("filter")) {
|
|
2760
|
-
this.removeAttribute("filter");
|
|
2761
|
-
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "pivot", filter: { filter: null } } }));
|
|
2762
|
-
}
|
|
2763
|
-
});
|
|
2764
|
-
}
|
|
2765
|
-
}
|
|
2766
|
-
define("contour-pivot", ContourPivot);
|
|
2767
|
-
/**
|
|
2768
|
-
* Widget State: web component wrapper.
|
|
2769
|
-
* Attributes: `loading`, `error`, `empty`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
2770
|
-
*/
|
|
2771
|
-
class ContourWidgetState extends ContourBase {
|
|
2772
|
-
static get observed() { return ["loading", "error", "empty", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2773
|
-
static get properties() { return { loading: { attribute: "loading" }, error: { attribute: "error" }, empty: { attribute: "empty" }, retry: { attribute: "retry" }, src: { attribute: "src" } }; }
|
|
2774
|
-
render() {
|
|
2775
|
-
this.classList.add("c-widget-state");
|
|
2776
|
-
wireStates(this);
|
|
2777
|
-
loadRemote(this, []);
|
|
2778
|
-
if (renderStates(this, "widget-state")) return;
|
|
2779
|
-
// if no state, render slotted content (already in DOM)
|
|
2780
|
-
}
|
|
2781
|
-
enhance() {}
|
|
2782
|
-
}
|
|
2783
|
-
define("contour-widget-state", ContourWidgetState);
|
|
2784
|
-
/**
|
|
2785
|
-
* Brownout: web component wrapper.
|
|
2786
|
-
* Attributes: `level`.
|
|
2787
|
-
*/
|
|
2788
|
-
class ContourBrownout extends ContourBase {
|
|
2789
|
-
static get observed() { return ["level"]; }
|
|
2790
|
-
static get properties() { return { level: { attribute: "level" } }; }
|
|
2791
|
-
render() {
|
|
2792
|
-
this.classList.add("c-brownout");
|
|
2793
|
-
const level = this.getAttribute("level") || "0";
|
|
2794
|
-
this.dataset.level = level;
|
|
2795
|
-
this.setAttribute("data-level", level);
|
|
2796
|
-
// Decorative bar (visual indicator of the brownout level).
|
|
2797
|
-
let deco = this.querySelector(".c-brownout__decorative");
|
|
2798
|
-
if (!deco) { deco = document.createElement("span"); deco.className = "c-brownout__decorative"; deco.setAttribute("aria-hidden", "true"); this.appendChild(deco); }
|
|
2799
|
-
// Label (text description of the level).
|
|
2800
|
-
let lbl = this.querySelector(".c-brownout__label");
|
|
2801
|
-
if (!lbl) { lbl = document.createElement("span"); lbl.className = "c-brownout__label"; this.appendChild(lbl); }
|
|
2802
|
-
lbl.textContent = "Level " + level;
|
|
2803
|
-
}
|
|
2804
|
-
enhance() {}
|
|
2805
|
-
}
|
|
2806
|
-
define("contour-brownout", ContourBrownout);
|
|
2807
|
-
/**
|
|
2808
|
-
* Instrument: web component wrapper.
|
|
2809
|
-
* Attributes: `rows`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
2810
|
-
*/
|
|
2811
|
-
class ContourInstrument extends ContourBase {
|
|
2812
|
-
static get observed() { return ["rows", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2813
|
-
static get properties() { return { rows: { attribute: "rows" }, src: { attribute: "src" } }; }
|
|
2814
|
-
render() {
|
|
2815
|
-
this.classList.add("c-instrument");
|
|
2816
|
-
wireStates(this);
|
|
2817
|
-
loadRemote(this, "rows");
|
|
2818
|
-
if (renderStates(this, "instrument")) return;
|
|
2819
|
-
const rows = remoteData(this, "rows");
|
|
2820
|
-
// The block's two parts are `__item` and `__value`: the label is the text
|
|
2821
|
-
// the item opens with, and the value is the span inside it. There is no
|
|
2822
|
-
// `__row` and no `__key` — the separators between items are CSS `::before`.
|
|
2823
|
-
Array.from(this.querySelectorAll(".c-instrument__item")).forEach((n) => n.remove());
|
|
2824
|
-
if (rows) {
|
|
2825
|
-
try {
|
|
2826
|
-
const parsed = JSON.parse(rows);
|
|
2827
|
-
parsed.forEach((r) => {
|
|
2828
|
-
const item = document.createElement("span");
|
|
2829
|
-
item.className = "c-instrument__item";
|
|
2830
|
-
item.appendChild(document.createTextNode(String(r.key || r[0] || "")));
|
|
2831
|
-
const val = document.createElement("span");
|
|
2832
|
-
val.className = "c-instrument__value";
|
|
2833
|
-
val.textContent = r.value || r[1] || "";
|
|
2834
|
-
item.appendChild(val);
|
|
2835
|
-
this.appendChild(item);
|
|
2836
|
-
});
|
|
2837
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
2838
|
-
} else {
|
|
2839
|
-
renderEmpty(this, "instrument");
|
|
2840
|
-
}
|
|
2841
|
-
}
|
|
2842
|
-
}
|
|
2843
|
-
define("contour-instrument", ContourInstrument);
|
|
2844
|
-
/**
|
|
2845
|
-
* Bivariate: web component wrapper.
|
|
2846
|
-
* Attributes: `size`, `axis-x`, `axis-y`, `colors`, `selected`.
|
|
2847
|
-
*/
|
|
2848
|
-
class ContourBivariate extends ContourBase {
|
|
2849
|
-
static get observed() { return ["size", "axis-x", "axis-y", "colors", "selected"]; }
|
|
2850
|
-
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" }, selected: { attribute: "selected" } }; }
|
|
2851
|
-
render() {
|
|
2852
|
-
this.classList.add("c-bivariate");
|
|
2853
|
-
this.setAttribute("role", "group");
|
|
2854
|
-
this.setAttribute("aria-label", "Bivariate legend");
|
|
2855
|
-
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
2856
|
-
const matrix = this.ensure(".c-bivariate__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate__matrix"; return el; });
|
|
2857
|
-
matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
|
|
2858
|
-
matrix.style.gridTemplateRows = `repeat(${size}, 1fr)`;
|
|
2859
|
-
// Slot composition: authored cells win over the generated grid.
|
|
2860
|
-
const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains("c-bivariate__cell"));
|
|
2861
|
-
if (!authored.length) {
|
|
2862
|
-
matrix.innerHTML = "";
|
|
2863
|
-
let colors = [];
|
|
2864
|
-
const cAttr = this.getAttribute("colors");
|
|
2865
|
-
if (cAttr) { try { colors = JSON.parse(cAttr); } catch (e) { colors = []; } }
|
|
2866
|
-
for (let r = 0; r < size; r++) {
|
|
2867
|
-
for (let c = 0; c < size; c++) {
|
|
2868
|
-
const cell = document.createElement("div");
|
|
2869
|
-
cell.className = "c-bivariate__cell";
|
|
2870
|
-
cell.setAttribute("role", "button");
|
|
2871
|
-
cell.setAttribute("tabindex", "0");
|
|
2872
|
-
cell.setAttribute("aria-label", "Cell " + c + "," + r);
|
|
2873
|
-
// Palette runs from bottom-left (low/low) to top-right (high/high):
|
|
2874
|
-
// reverse the row order so the first palette row sits at the bottom.
|
|
2875
|
-
const srcIndex = (size - 1 - r) * size + c;
|
|
2876
|
-
if (colors[srcIndex]) { cell.style.background = colors[srcIndex]; cell.dataset.color = colors[srcIndex]; }
|
|
2877
|
-
matrix.appendChild(cell);
|
|
2878
|
-
}
|
|
2879
|
-
}
|
|
2880
|
-
// selected highlight
|
|
2881
|
-
const sel = this.getAttribute("selected");
|
|
2882
|
-
if (sel) {
|
|
2883
|
-
const parts = sel.split(",");
|
|
2884
|
-
const sr = parseInt(parts[0], 10);
|
|
2885
|
-
const sc = parseInt(parts[1], 10);
|
|
2886
|
-
const cells = Array.from(matrix.querySelectorAll(".c-bivariate__cell"));
|
|
2887
|
-
cells.forEach((cell, i) => {
|
|
2888
|
-
const rr = Math.floor(i / size);
|
|
2889
|
-
const cc = i % size;
|
|
2890
|
-
// matrix is row-major in DOM? cells appended row by row r then c, so index = r*size+c
|
|
2891
|
-
if (rr === sr && cc === sc) cell.setAttribute("data-selected", "");
|
|
2892
|
-
else cell.removeAttribute("data-selected");
|
|
2893
|
-
});
|
|
2894
|
-
}
|
|
2895
|
-
// aria-live region
|
|
2896
|
-
let live = this.querySelector(".c-bivariate__live");
|
|
2897
|
-
if (!live) { live = document.createElement("div"); live.className = "c-bivariate__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); }
|
|
2898
|
-
}
|
|
2899
|
-
const axisX = this.getAttribute("axis-x");
|
|
2900
|
-
if (axisX) {
|
|
2901
|
-
const ax = this.ensure(".c-bivariate__axis--x", () => { const el = document.createElement("div"); el.className = "c-bivariate__axis c-bivariate__axis--x"; return el; });
|
|
2902
|
-
ax.textContent = axisX;
|
|
2903
|
-
} else {
|
|
2904
|
-
const ax = this.querySelector(".c-bivariate__axis--x");
|
|
2905
|
-
if (ax) ax.remove();
|
|
2906
|
-
}
|
|
2907
|
-
const axisY = this.getAttribute("axis-y");
|
|
2908
|
-
if (axisY) {
|
|
2909
|
-
const ay = this.ensure(".c-bivariate__axis--y", () => { const el = document.createElement("div"); el.className = "c-bivariate__axis c-bivariate__axis--y"; return el; });
|
|
2910
|
-
ay.textContent = axisY;
|
|
2911
|
-
} else {
|
|
2912
|
-
const ay = this.querySelector(".c-bivariate__axis--y");
|
|
2913
|
-
if (ay) ay.remove();
|
|
2914
|
-
}
|
|
2915
|
-
}
|
|
2916
|
-
enhance() {
|
|
2917
|
-
if (this._wiredBivariate) return;
|
|
2918
|
-
this._wiredBivariate = true;
|
|
2919
|
-
const selectCell = (cell) => {
|
|
2920
|
-
const matrix = this.querySelector(".c-bivariate__matrix");
|
|
2921
|
-
const cells = Array.from(matrix ? matrix.querySelectorAll(".c-bivariate__cell") : []);
|
|
2922
|
-
const idx = cells.indexOf(cell);
|
|
2923
|
-
if (idx < 0) return;
|
|
2924
|
-
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
2925
|
-
const row = Math.floor(idx / size);
|
|
2926
|
-
const col = idx % size;
|
|
2927
|
-
cells.forEach((cell, i) => {
|
|
2928
|
-
const rr = Math.floor(i / size);
|
|
2929
|
-
const cc = i % size;
|
|
2930
|
-
if (rr === row && cc === col) cell.setAttribute("data-selected", "");
|
|
2931
|
-
else cell.removeAttribute("data-selected");
|
|
2932
|
-
});
|
|
2933
|
-
this.dispatchEvent(new CustomEvent("contour:select", { detail: { row, col }, bubbles: true, composed: true }));
|
|
2934
|
-
};
|
|
2935
|
-
this.addEventListener("click", (e) => {
|
|
2936
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate__cell") : null;
|
|
2937
|
-
if (cell && this.contains(cell)) selectCell(cell);
|
|
2938
|
-
});
|
|
2939
|
-
this.addEventListener("keydown", (e) => {
|
|
2940
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate__cell") : null;
|
|
2941
|
-
if (!cell || !this.contains(cell)) return;
|
|
2942
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
2943
|
-
e.preventDefault();
|
|
2944
|
-
selectCell(cell);
|
|
2945
|
-
}
|
|
2946
|
-
});
|
|
2947
|
-
}
|
|
2948
|
-
clear() {
|
|
2949
|
-
this.removeAttribute("selected");
|
|
2950
|
-
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true }));
|
|
2951
|
-
}
|
|
2952
|
-
}
|
|
2953
|
-
define("contour-bivariate", ContourBivariate);
|
|
2954
|
-
class ContourBivariateLegend extends ContourBivariate {
|
|
2955
|
-
static get observed() { return ["size", "axis-x", "axis-y", "colors", "selected"]; }
|
|
2956
|
-
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" }, selected: { attribute: "selected" } }; }
|
|
2957
|
-
render() {
|
|
2958
|
-
this.classList.add("c-bivariate-legend");
|
|
2959
|
-
this.setAttribute("role", "group");
|
|
2960
|
-
this.setAttribute("aria-label", "Bivariate legend");
|
|
2961
|
-
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
2962
|
-
const matrix = this.ensure(".c-bivariate-legend__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate-legend__matrix"; return el; });
|
|
2963
|
-
matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
|
|
2964
|
-
matrix.style.gridTemplateRows = `repeat(${size}, 1fr)`;
|
|
2965
|
-
// Slot composition: authored cells win over the generated grid.
|
|
2966
|
-
const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains("c-bivariate-legend__cell"));
|
|
2967
|
-
if (!authored.length) {
|
|
2968
|
-
matrix.innerHTML = "";
|
|
2969
|
-
let colors = [];
|
|
2970
|
-
const cAttr = this.getAttribute("colors");
|
|
2971
|
-
if (cAttr) { try { colors = JSON.parse(cAttr); } catch (e) { colors = []; } }
|
|
2972
|
-
for (let r = 0; r < size; r++) {
|
|
2973
|
-
for (let c = 0; c < size; c++) {
|
|
2974
|
-
const cell = document.createElement("div");
|
|
2975
|
-
cell.className = "c-bivariate-legend__cell";
|
|
2976
|
-
cell.setAttribute("role", "button");
|
|
2977
|
-
cell.setAttribute("tabindex", "0");
|
|
2978
|
-
cell.setAttribute("aria-label", "Cell " + c + "," + r);
|
|
2979
|
-
// Palette runs from bottom-left (low/low) to top-right (high/high):
|
|
2980
|
-
// reverse the row order so the first palette row sits at the bottom.
|
|
2981
|
-
const srcIndex = (size - 1 - r) * size + c;
|
|
2982
|
-
if (colors[srcIndex]) { cell.style.background = colors[srcIndex]; cell.dataset.color = colors[srcIndex]; }
|
|
2983
|
-
matrix.appendChild(cell);
|
|
2984
|
-
}
|
|
2985
|
-
}
|
|
2986
|
-
// selected highlight
|
|
2987
|
-
const sel = this.getAttribute("selected");
|
|
2988
|
-
if (sel) {
|
|
2989
|
-
const parts = sel.split(",");
|
|
2990
|
-
const sr = parseInt(parts[0], 10);
|
|
2991
|
-
const sc = parseInt(parts[1], 10);
|
|
2992
|
-
const cells = Array.from(matrix.querySelectorAll(".c-bivariate-legend__cell"));
|
|
2993
|
-
cells.forEach((cell, i) => {
|
|
2994
|
-
const rr = Math.floor(i / size);
|
|
2995
|
-
const cc = i % size;
|
|
2996
|
-
if (rr === sr && cc === sc) cell.setAttribute("data-selected", "");
|
|
2997
|
-
else cell.removeAttribute("data-selected");
|
|
2998
|
-
});
|
|
2999
|
-
}
|
|
3000
|
-
// aria-live region
|
|
3001
|
-
let live = this.querySelector(".c-bivariate-legend__live");
|
|
3002
|
-
if (!live) { live = document.createElement("div"); live.className = "c-bivariate-legend__live"; live.setAttribute("aria-live", "polite"); live.style.position = "absolute"; live.style.width = "1px"; live.style.height = "1px"; live.style.overflow = "hidden"; live.style.clip = "rect(0,0,0,0)"; this.appendChild(live); }
|
|
3003
|
-
}
|
|
3004
|
-
const axisX = this.getAttribute("axis-x");
|
|
3005
|
-
if (axisX) {
|
|
3006
|
-
const ax = this.ensure(".c-bivariate-legend__axis--x", () => { const el = document.createElement("div"); el.className = "c-bivariate-legend__axis c-bivariate-legend__axis--x"; return el; });
|
|
3007
|
-
ax.textContent = axisX;
|
|
3008
|
-
} else {
|
|
3009
|
-
const ax = this.querySelector(".c-bivariate-legend__axis--x");
|
|
3010
|
-
if (ax) ax.remove();
|
|
3011
|
-
}
|
|
3012
|
-
const axisY = this.getAttribute("axis-y");
|
|
3013
|
-
if (axisY) {
|
|
3014
|
-
const ay = this.ensure(".c-bivariate-legend__axis--y", () => { const el = document.createElement("div"); el.className = "c-bivariate-legend__axis c-bivariate-legend__axis--y"; return el; });
|
|
3015
|
-
ay.textContent = axisY;
|
|
3016
|
-
} else {
|
|
3017
|
-
const ay = this.querySelector(".c-bivariate-legend__axis--y");
|
|
3018
|
-
if (ay) ay.remove();
|
|
3019
|
-
}
|
|
3020
|
-
}
|
|
3021
|
-
enhance() {
|
|
3022
|
-
if (this._wiredBivLegend) return;
|
|
3023
|
-
this._wiredBivLegend = true;
|
|
3024
|
-
const selectCell = (cell) => {
|
|
3025
|
-
const matrix = this.querySelector(".c-bivariate-legend__matrix");
|
|
3026
|
-
const cells = Array.from(matrix ? matrix.querySelectorAll(".c-bivariate-legend__cell") : []);
|
|
3027
|
-
const idx = cells.indexOf(cell);
|
|
3028
|
-
if (idx < 0) return;
|
|
3029
|
-
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
3030
|
-
const row = Math.floor(idx / size);
|
|
3031
|
-
const col = idx % size;
|
|
3032
|
-
cells.forEach((cell, i) => {
|
|
3033
|
-
const rr = Math.floor(i / size);
|
|
3034
|
-
const cc = i % size;
|
|
3035
|
-
if (rr === row && cc === col) cell.setAttribute("data-selected", "");
|
|
3036
|
-
else cell.removeAttribute("data-selected");
|
|
3037
|
-
});
|
|
3038
|
-
this.dispatchEvent(new CustomEvent("contour:select", { detail: { row, col }, bubbles: true, composed: true }));
|
|
3039
|
-
};
|
|
3040
|
-
this.addEventListener("click", (e) => {
|
|
3041
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate-legend__cell") : null;
|
|
3042
|
-
if (cell && this.contains(cell)) selectCell(cell);
|
|
3043
|
-
});
|
|
3044
|
-
this.addEventListener("keydown", (e) => {
|
|
3045
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate-legend__cell") : null;
|
|
3046
|
-
if (!cell || !this.contains(cell)) return;
|
|
3047
|
-
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); selectCell(cell); }
|
|
3048
|
-
});
|
|
3049
|
-
}
|
|
3050
|
-
clear() {
|
|
3051
|
-
this.removeAttribute("selected");
|
|
3052
|
-
const cells = Array.from(this.querySelectorAll(".c-bivariate-legend__cell"));
|
|
3053
|
-
cells.forEach((c) => c.removeAttribute("data-selected"));
|
|
3054
|
-
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true }));
|
|
3055
|
-
}
|
|
3056
|
-
}
|
|
3057
|
-
define("contour-bivariate-legend", ContourBivariateLegend);
|
|
3058
|
-
/**
|
|
3059
|
-
* Survey: web component wrapper.
|
|
3060
|
-
* Attributes: `date`, `instrument`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3061
|
-
*/
|
|
3062
|
-
class ContourSurvey extends ContourBase {
|
|
3063
|
-
static get observed() { return ["date", "instrument", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
3064
|
-
static get properties() { return { date: { attribute: "date" }, instrument: { attribute: "instrument" }, src: { attribute: "src" } }; }
|
|
3065
|
-
render() {
|
|
3066
|
-
this.classList.add("c-survey");
|
|
3067
|
-
wireStates(this);
|
|
3068
|
-
loadRemote(this, "date");
|
|
3069
|
-
if (renderStates(this, "survey")) return;
|
|
3070
|
-
const date = remoteData(this, "date");
|
|
3071
|
-
Array.from(this.childNodes).forEach((n) => {
|
|
3072
|
-
if (n.nodeType === Node.TEXT_NODE) { if (n.textContent.trim() === "Surveyed" || n.textContent.trim() === "·") n.remove(); }
|
|
3073
|
-
else if (n.classList && (n.classList.contains("c-survey__value") || n.classList.contains("c-survey__sep"))) n.remove();
|
|
3074
|
-
});
|
|
3075
|
-
const rDate = date || (this._remoteData && this._remoteData.date);
|
|
3076
|
-
const instrument = this.getAttribute("instrument") || (this._remoteData && this._remoteData.instrument);
|
|
3077
|
-
if (!rDate) {
|
|
3078
|
-
renderEmpty(this, "survey");
|
|
3079
|
-
return;
|
|
3080
|
-
}
|
|
3081
|
-
const v = document.createElement("span");
|
|
3082
|
-
v.className = "c-survey__value";
|
|
3083
|
-
v.textContent = rDate;
|
|
3084
|
-
this.appendChild(document.createTextNode("Surveyed "));
|
|
3085
|
-
this.appendChild(v);
|
|
3086
|
-
if (instrument) {
|
|
3087
|
-
const sep = document.createElement("span");
|
|
3088
|
-
sep.className = "c-survey__sep";
|
|
3089
|
-
sep.textContent = "·";
|
|
3090
|
-
this.appendChild(sep);
|
|
3091
|
-
const v2 = document.createElement("span");
|
|
3092
|
-
v2.className = "c-survey__value";
|
|
3093
|
-
v2.textContent = instrument;
|
|
3094
|
-
this.appendChild(v2);
|
|
3095
|
-
}
|
|
3096
|
-
}
|
|
3097
|
-
}
|
|
3098
|
-
define("contour-survey", ContourSurvey);
|
|
3099
|
-
/**
|
|
3100
|
-
* Threshold: web component wrapper.
|
|
3101
|
-
* Attributes: `label`, `norm`, `state`, `value`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3102
|
-
*/
|
|
3103
|
-
class ContourThreshold extends ContourBase {
|
|
3104
|
-
static get observed() { return ["label", "norm", "state", "value", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
3105
|
-
static get properties() { return { label: { attribute: "label" }, norm: { attribute: "norm" }, state: { attribute: "state" }, value: { attribute: "value" }, src: { attribute: "src" } }; }
|
|
3106
|
-
render() {
|
|
3107
|
-
this.classList.add("c-threshold");
|
|
3108
|
-
wireStates(this);
|
|
3109
|
-
loadRemote(this, "value");
|
|
3110
|
-
if (renderStates(this, "threshold")) return;
|
|
3111
|
-
const pct = (v) => { const n = Number(v); if (!Number.isFinite(n)) return String(v); return (n <= 1 ? n * 100 : n) + "%"; };
|
|
3112
|
-
const rValue = remoteData(this, "value") || (this._remoteData && this._remoteData.value);
|
|
3113
|
-
const target = this.getAttribute("norm") || (this._remoteData && this._remoteData.norm);
|
|
3114
|
-
const state = this.getAttribute("state") || (this._remoteData && this._remoteData.state);
|
|
3115
|
-
const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
|
|
3116
|
-
if (!rValue && !target && !label) {
|
|
3117
|
-
renderEmpty(this, "threshold");
|
|
3118
|
-
return;
|
|
3119
|
-
}
|
|
3120
|
-
if (rValue) {
|
|
3121
|
-
const v = this.ensure(".c-threshold__fill", () => { const el = document.createElement("span"); el.className = "c-threshold__fill"; return el; });
|
|
3122
|
-
v.style.setProperty("--value", pct(rValue));
|
|
3123
|
-
} else {
|
|
3124
|
-
const v = this.querySelector(".c-threshold__fill");
|
|
3125
|
-
if (v) v.remove();
|
|
3126
|
-
}
|
|
3127
|
-
if (target) {
|
|
3128
|
-
const t = this.ensure(".c-threshold__target", () => { const el = document.createElement("span"); el.className = "c-threshold__target"; return el; });
|
|
3129
|
-
t.style.setProperty("--target", pct(target));
|
|
3130
|
-
} else {
|
|
3131
|
-
const t = this.querySelector(".c-threshold__target");
|
|
3132
|
-
if (t) t.remove();
|
|
3133
|
-
}
|
|
3134
|
-
if (state) this.setAttribute("data-state", state);
|
|
3135
|
-
else this.removeAttribute("data-state");
|
|
3136
|
-
if (label) this.setAttribute("aria-label", label);
|
|
3137
|
-
}
|
|
3138
|
-
enhance() {
|
|
3139
|
-
if (this._wiredThreshold) return;
|
|
3140
|
-
this._wiredThreshold = true;
|
|
3141
|
-
// Cross-filter contract (R16-16): clear-all resets threshold norm/target.
|
|
3142
|
-
this.addEventListener("contour:clear-all", () => {
|
|
3143
|
-
if (this.hasAttribute("norm") || this.hasAttribute("value")) {
|
|
3144
|
-
this.removeAttribute("norm");
|
|
3145
|
-
this.removeAttribute("value");
|
|
3146
|
-
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "threshold", filter: { norm: null, value: null } } }));
|
|
3147
|
-
this.requestRender();
|
|
3148
|
-
}
|
|
3149
|
-
});
|
|
3150
|
-
}
|
|
3151
|
-
}
|
|
3152
|
-
define("contour-threshold", ContourThreshold);
|
|
3153
|
-
/**
|
|
3154
|
-
* Metrics Full: web component wrapper.
|
|
3155
|
-
* Attributes: `items`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3156
|
-
*/
|
|
3157
|
-
class ContourMetricsFull extends ContourBase {
|
|
3158
|
-
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
3159
|
-
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
3160
|
-
render() {
|
|
3161
|
-
this.classList.add("c-metrics");
|
|
3162
|
-
this.setAttribute("role", "list");
|
|
3163
|
-
wireStates(this);
|
|
3164
|
-
loadRemote(this, "items");
|
|
3165
|
-
if (renderStates(this, "metrics")) return;
|
|
3166
|
-
const items = remoteData(this, "items");
|
|
3167
|
-
// Drop previously generated items so re-render doesn't stack.
|
|
3168
|
-
Array.from(this.querySelectorAll(".c-metrics__item")).forEach((n) => n.remove());
|
|
3169
|
-
let parsed = null;
|
|
3170
|
-
if (items) { try { parsed = JSON.parse(items); } catch (e) { parsed = null; } }
|
|
3171
|
-
if (Array.isArray(parsed) && parsed.length) {
|
|
3172
|
-
parsed.forEach((it) => {
|
|
3173
|
-
const item = document.createElement("div");
|
|
3174
|
-
item.className = "c-metrics__item";
|
|
3175
|
-
item.setAttribute("role", "listitem");
|
|
3176
|
-
const v = document.createElement("div");
|
|
3177
|
-
v.className = "c-metrics__value";
|
|
3178
|
-
v.textContent = (typeof it === "object" && it !== null) ? (it.value ?? it.v ?? "") : String(it);
|
|
3179
|
-
const l = document.createElement("div");
|
|
3180
|
-
l.className = "c-metrics__label";
|
|
3181
|
-
l.textContent = (typeof it === "object" && it !== null) ? (it.label ?? it.l ?? "") : "";
|
|
3182
|
-
item.appendChild(v);
|
|
3183
|
-
item.appendChild(l);
|
|
3184
|
-
this.appendChild(item);
|
|
3185
|
-
});
|
|
3186
|
-
} else if (!items) {
|
|
3187
|
-
renderEmpty(this, "metrics");
|
|
3188
|
-
}
|
|
3189
|
-
}
|
|
3190
|
-
enhance() { wireStates(this); }
|
|
3191
|
-
}
|
|
3192
|
-
define("contour-metrics", ContourMetricsFull);
|
|
3193
|
-
/**
|
|
3194
|
-
* Legend: web component wrapper.
|
|
3195
|
-
* Attributes: `title`, `ramp`, `scale`, `items`, `method`, `norm`, `selectable`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `glyphs`, `thresholds`, `breaks`, `no-data-color`, `size`, `table`, `classification`, `audit`, `continuous`, `ends`, `caption`.
|
|
3196
|
-
*/
|
|
3197
|
-
class ContourLegend extends ContourBase {
|
|
3198
|
-
static get observed() { return ["title", "ramp", "scale", "items", "method", "norm", "selectable", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "glyphs", "thresholds", "breaks", "no-data-color", "no-data-label", "size", "table", "classification", "audit", "continuous", "ends", "caption", "graduated"]; }
|
|
3199
|
-
static get properties() { return { title: { attribute: "title" }, ramp: { attribute: "ramp" }, scale: { attribute: "scale" }, items: { attribute: "items" }, method: { attribute: "method" }, norm: { attribute: "norm" }, selectable: { attribute: "selectable", type: Boolean }, src: { attribute: "src" }, graduated: { attribute: "graduated", type: Boolean } }; }
|
|
3200
|
-
render() {
|
|
3201
|
-
this.classList.add("c-legend");
|
|
3202
|
-
const graduated = this.hasAttribute("graduated");
|
|
3203
|
-
if (graduated) this.classList.add("c-legend--graduated");
|
|
3204
|
-
const continuous = this.hasAttribute("continuous");
|
|
3205
|
-
if (continuous || this.hasAttribute("selectable")) {
|
|
3206
|
-
this.setAttribute("role", "group");
|
|
3207
|
-
} else {
|
|
3208
|
-
this.setAttribute("role", "list");
|
|
3209
|
-
}
|
|
3210
|
-
wireStates(this);
|
|
3211
|
-
loadRemote(this, "items");
|
|
3212
|
-
if (renderStates(this, "legend")) return;
|
|
3213
|
-
// Selectable legends (BY-41): items become toggle buttons with
|
|
3214
|
-
// aria-pressed, and the sheet's existing `.c-legend--interactive` rules
|
|
3215
|
-
// (hover, dim when pressed=false) apply.
|
|
3216
|
-
const selectable = this.hasAttribute("selectable");
|
|
3217
|
-
// Slotted content support: authored .c-legend__item children take
|
|
3218
|
-
// precedence over the JSON `items` attribute.
|
|
3219
|
-
const authoredLegendItems = Array.from(this.querySelectorAll(":scope > .c-legend__item"));
|
|
3220
|
-
let items = remoteData(this, "items");
|
|
3221
|
-
if (authoredLegendItems.length) {
|
|
3222
|
-
items = JSON.stringify(authoredLegendItems.map((el) => {
|
|
3223
|
-
const sw = el.querySelector(".c-legend__swatch");
|
|
3224
|
-
const lbl = el.querySelector(".c-legend__label") || el;
|
|
3225
|
-
return { label: lbl ? lbl.textContent.trim() : el.textContent.trim(), color: sw ? (sw.dataset && sw.dataset.color) || sw.style.background || undefined : undefined };
|
|
3226
|
-
}));
|
|
3227
|
-
authoredLegendItems.forEach((el) => el.remove());
|
|
3228
|
-
}
|
|
3229
|
-
const title = this.getAttribute("title");
|
|
3230
|
-
if (title) {
|
|
3231
|
-
const t = this.ensure(".c-legend__title", () => { const el = document.createElement("div"); el.className = "c-legend__title"; return el; });
|
|
3232
|
-
t.textContent = title;
|
|
3233
|
-
} else {
|
|
3234
|
-
const t = this.querySelector(".c-legend__title");
|
|
3235
|
-
if (t) t.remove();
|
|
3236
|
-
}
|
|
3237
|
-
if (items) {
|
|
3238
|
-
try {
|
|
3239
|
-
const parsed = JSON.parse(items);
|
|
3240
|
-
const list = this.ensure(".c-legend__items", () => { const el = document.createElement("div"); el.className = "c-legend__items"; return el; });
|
|
3241
|
-
if (this.hasAttribute("selectable")) {
|
|
3242
|
-
list.setAttribute("role", "group");
|
|
3243
|
-
} else {
|
|
3244
|
-
// Host already has role="list"; inner container should be generic
|
|
3245
|
-
list.removeAttribute("role");
|
|
3246
|
-
}
|
|
3247
|
-
if (title) list.setAttribute("aria-label", title);
|
|
3248
|
-
list.innerHTML = "";
|
|
3249
|
-
parsed.forEach((it) => {
|
|
3250
|
-
const label = typeof it === "string" ? it : (it.label || String(it));
|
|
3251
|
-
const key = typeof it === "string" ? it : (it.key || it.label || String(it));
|
|
3252
|
-
const item = document.createElement("div");
|
|
3253
|
-
item.className = "c-legend__item";
|
|
3254
|
-
item.setAttribute("tabindex", "-1");
|
|
3255
|
-
if (selectable) {
|
|
3256
|
-
item.setAttribute("role", "button");
|
|
3257
|
-
item.setAttribute("aria-pressed", "true");
|
|
3258
|
-
item.dataset.key = key;
|
|
3259
|
-
} else {
|
|
3260
|
-
item.setAttribute("role", "listitem");
|
|
3261
|
-
// aria-selected is not valid on role="listitem"; omit for non-selectable legends
|
|
3262
|
-
}
|
|
3263
|
-
const sw = document.createElement("span");
|
|
3264
|
-
if (graduated) {
|
|
3265
|
-
sw.className = "c-legend__swatch c-legend__swatch--graduated";
|
|
3266
|
-
const gSize = it && it.size != null ? it.size : (it && it.value != null ? it.value : 1);
|
|
3267
|
-
const sizePx = Math.max(6, Math.min(24, parseFloat(gSize) * 4));
|
|
3268
|
-
sw.style.inlineSize = sizePx + "px";
|
|
3269
|
-
sw.style.blockSize = sizePx + "px";
|
|
3270
|
-
} else {
|
|
3271
|
-
sw.className = "c-legend__swatch";
|
|
3272
|
-
}
|
|
3273
|
-
if (it && it.color) { sw.style.background = it.color; sw.dataset.color = it.color; }
|
|
3274
|
-
item.appendChild(sw);
|
|
3275
|
-
// graduated break label
|
|
3276
|
-
if (graduated && (it && it.break != null)) {
|
|
3277
|
-
const bl = document.createElement("span");
|
|
3278
|
-
bl.className = "c-legend__break-label";
|
|
3279
|
-
bl.textContent = String(it.break);
|
|
3280
|
-
item.appendChild(bl);
|
|
3281
|
-
}
|
|
3282
|
-
// geometry glyph
|
|
3283
|
-
const glyphShape = (it && (it.shape || it.marker || it.glyph)) || this.getAttribute("glyphs");
|
|
3284
|
-
if (glyphShape) {
|
|
3285
|
-
const g = document.createElement("span");
|
|
3286
|
-
g.className = "c-legend__glyph";
|
|
3287
|
-
g.setAttribute("part", "glyph");
|
|
3288
|
-
g.textContent = glyphShape === "circle" ? "●" : glyphShape === "square" ? "■" : glyphShape === "triangle" ? "▲" : glyphShape === "diamond" ? "◆" : glyphShape === "star" ? "★" : String(glyphShape);
|
|
3289
|
-
if (it && it.size != null) g.style.fontSize = (typeof it.size === "number" ? it.size + "px" : String(it.size));
|
|
3290
|
-
item.appendChild(g);
|
|
3291
|
-
}
|
|
3292
|
-
// threshold break marker
|
|
3293
|
-
if (it && it.break != null) {
|
|
3294
|
-
const b = document.createElement("span");
|
|
3295
|
-
b.className = "c-legend__break";
|
|
3296
|
-
b.textContent = String(it.break);
|
|
3297
|
-
item.appendChild(b);
|
|
3298
|
-
}
|
|
3299
|
-
const lbl = document.createElement("span");
|
|
3300
|
-
lbl.textContent = label;
|
|
3301
|
-
item.appendChild(lbl);
|
|
3302
|
-
// caption (source-and-method line)
|
|
3303
|
-
const caption = (typeof it === "object" && it) ? (it.caption || it.note || "") : "";
|
|
3304
|
-
if (caption) {
|
|
3305
|
-
const cap = document.createElement("span");
|
|
3306
|
-
cap.className = "c-legend__caption";
|
|
3307
|
-
cap.textContent = caption;
|
|
3308
|
-
item.appendChild(cap);
|
|
3309
|
-
}
|
|
3310
|
-
// threshold mark: outline on swatches that begin at a threshold
|
|
3311
|
-
if (it && (it.threshold || it.break != null)) {
|
|
3312
|
-
sw.style.outline = "2px solid var(--color-border-strong)";
|
|
3313
|
-
}
|
|
3314
|
-
list.appendChild(item);
|
|
3315
|
-
});
|
|
3316
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
3317
|
-
} else {
|
|
3318
|
-
const list = this.querySelector(".c-legend__items");
|
|
3319
|
-
if (list) list.remove();
|
|
3320
|
-
const hasOther = this.getAttribute("title") || this.getAttribute("ramp") || this.getAttribute("scale") || this.getAttribute("method") || this.getAttribute("norm");
|
|
3321
|
-
if (!hasOther) {
|
|
3322
|
-
renderEmpty(this, "legend");
|
|
3323
|
-
}
|
|
3324
|
-
}
|
|
3325
|
-
// caption as option description (aria-describedby), not part of name
|
|
3326
|
-
const caption = this.getAttribute("caption");
|
|
3327
|
-
let captionEl = this.querySelector(".c-legend__caption");
|
|
3328
|
-
if (caption) {
|
|
3329
|
-
if (!captionEl) { captionEl = document.createElement("span"); captionEl.className = "c-legend__caption"; this.appendChild(captionEl); }
|
|
3330
|
-
captionEl.id = captionEl.id || ("legend-caption-" + Math.random().toString(36).slice(2));
|
|
3331
|
-
captionEl.textContent = caption;
|
|
3332
|
-
captionEl.style.position = "absolute"; captionEl.style.width = "1px"; captionEl.style.height = "1px"; captionEl.style.overflow = "hidden"; captionEl.style.clip = "rect(0,0,0,0)";
|
|
3333
|
-
} else if (captionEl) {
|
|
3334
|
-
captionEl.remove();
|
|
3335
|
-
}
|
|
3336
|
-
// single tab stop: first option
|
|
3337
|
-
const _items = this.querySelector(".c-legend__items");
|
|
3338
|
-
if (_items) {
|
|
3339
|
-
const opts = Array.from(_items.querySelectorAll(".c-legend__item"));
|
|
3340
|
-
opts.forEach((o, i) => o.setAttribute("tabindex", i === 0 ? "0" : "-1"));
|
|
3341
|
-
if (captionEl) opts.forEach((o) => o.setAttribute("aria-describedby", captionEl.id));
|
|
3342
|
-
}
|
|
3343
|
-
// no-data entry from palette / no-data-color
|
|
3344
|
-
const ndColor = this.getAttribute("no-data-color");
|
|
3345
|
-
const ndLabel = this.getAttribute("no-data-label") || "No data";
|
|
3346
|
-
if (ndColor) {
|
|
3347
|
-
let nd = this.querySelector(".c-legend__no-data");
|
|
3348
|
-
if (!nd) { nd = document.createElement("div"); nd.className = "c-legend__no-data"; this.appendChild(nd); }
|
|
3349
|
-
nd.setAttribute("part", "no-data");
|
|
3350
|
-
nd.setAttribute("aria-label", ndLabel);
|
|
3351
|
-
nd.textContent = ndLabel;
|
|
3352
|
-
const glyph = document.createElement("span");
|
|
3353
|
-
glyph.className = "glyph";
|
|
3354
|
-
glyph.style.background = ndColor;
|
|
3355
|
-
glyph.dataset.color = ndColor;
|
|
3356
|
-
nd.prepend(glyph);
|
|
3357
|
-
} else {
|
|
3358
|
-
const nd = this.querySelector(".c-legend__no-data");
|
|
3359
|
-
if (nd) nd.remove();
|
|
3360
|
-
}
|
|
3361
|
-
// audit notice
|
|
3362
|
-
const audit = this.getAttribute("audit");
|
|
3363
|
-
if (audit) {
|
|
3364
|
-
const a = this.ensure(".c-legend__audit", () => { const el = document.createElement("div"); el.className = "c-legend__audit"; return el; });
|
|
3365
|
-
a.textContent = audit;
|
|
3366
|
-
} else {
|
|
3367
|
-
const a = this.querySelector(".c-legend__audit");
|
|
3368
|
-
if (a) a.remove();
|
|
3369
|
-
}
|
|
3370
|
-
// continuous variant: ramp with two ends labelled
|
|
3371
|
-
if (this.hasAttribute("continuous")) {
|
|
3372
|
-
const ends = this.getAttribute("ends");
|
|
3373
|
-
let parsedEnds = null;
|
|
3374
|
-
if (ends) { try { parsedEnds = JSON.parse(ends); } catch (e) { parsedEnds = ends.split(","); } }
|
|
3375
|
-
if (Array.isArray(parsedEnds) && parsedEnds.length >= 2) {
|
|
3376
|
-
const r = this.ensure(".c-legend__ramp", () => { const el = document.createElement("div"); el.className = "c-legend__ramp"; return el; });
|
|
3377
|
-
// labels
|
|
3378
|
-
let left = this.querySelector(".c-legend__ramp-label--start");
|
|
3379
|
-
if (!left) { left = document.createElement("span"); left.className = "c-legend__ramp-label c-legend__ramp-label--start"; r.appendChild(left); }
|
|
3380
|
-
left.textContent = parsedEnds[0];
|
|
3381
|
-
let right = this.querySelector(".c-legend__ramp-label--end");
|
|
3382
|
-
if (!right) { right = document.createElement("span"); right.className = "c-legend__ramp-label c-legend__ramp-label--end"; r.appendChild(right); }
|
|
3383
|
-
right.textContent = parsedEnds[parsedEnds.length - 1];
|
|
3384
|
-
}
|
|
3385
|
-
}
|
|
3386
|
-
// size variant: differently-sized glyphs
|
|
3387
|
-
const sizeAttr = this.getAttribute("size");
|
|
3388
|
-
if (sizeAttr) {
|
|
3389
|
-
const sc = this.ensure(".c-legend__size", () => { const el = document.createElement("div"); el.className = "c-legend__size"; return el; });
|
|
3390
|
-
sc.textContent = sizeAttr;
|
|
3391
|
-
} else {
|
|
3392
|
-
const sc = this.querySelector(".c-legend__size");
|
|
3393
|
-
if (sc) sc.remove();
|
|
3394
|
-
}
|
|
3395
|
-
// classification line
|
|
3396
|
-
const classification = this.getAttribute("classification");
|
|
3397
|
-
if (classification) {
|
|
3398
|
-
const c = this.ensure(".c-legend__classification", () => { const el = document.createElement("div"); el.className = "c-legend__classification"; return el; });
|
|
3399
|
-
c.textContent = classification;
|
|
3400
|
-
} else {
|
|
3401
|
-
const c = this.querySelector(".c-legend__classification");
|
|
3402
|
-
if (c) c.remove();
|
|
3403
|
-
}
|
|
3404
|
-
// data table (collapsible)
|
|
3405
|
-
const tableAttr = this.getAttribute("table");
|
|
3406
|
-
if (tableAttr) {
|
|
3407
|
-
let parsed = null;
|
|
3408
|
-
try { parsed = JSON.parse(tableAttr); } catch (e) { parsed = null; }
|
|
3409
|
-
if (Array.isArray(parsed)) {
|
|
3410
|
-
let det = this.querySelector(".c-legend__table-wrap");
|
|
3411
|
-
if (!det) { det = document.createElement("details"); det.className = "c-legend__table-wrap"; this.appendChild(det); }
|
|
3412
|
-
det.innerHTML = "";
|
|
3413
|
-
const sum = document.createElement("summary"); sum.textContent = labelText(this, "data-table", "Data table"); det.appendChild(sum);
|
|
3414
|
-
const tbl = document.createElement("table"); tbl.className = "c-legend__table";
|
|
3415
|
-
const tbody = document.createElement("tbody");
|
|
3416
|
-
parsed.forEach((row) => {
|
|
3417
|
-
const tr = document.createElement("tr");
|
|
3418
|
-
const cells = Array.isArray(row) ? row : [row.label ?? row.key ?? "", row.value ?? ""];
|
|
3419
|
-
cells.forEach((cell) => { const td = document.createElement("td"); td.textContent = cell; tr.appendChild(td); });
|
|
3420
|
-
tbody.appendChild(tr);
|
|
3421
|
-
});
|
|
3422
|
-
tbl.appendChild(tbody);
|
|
3423
|
-
det.appendChild(tbl);
|
|
3424
|
-
}
|
|
3425
|
-
} else {
|
|
3426
|
-
const det = this.querySelector(".c-legend__table-wrap");
|
|
3427
|
-
if (det) det.remove();
|
|
3428
|
-
}
|
|
3429
|
-
// size variant on glyphs
|
|
3430
|
-
if (items) {
|
|
3431
|
-
// apply size to glyphs already rendered? handled below via re-render not needed
|
|
3432
|
-
}
|
|
3433
|
-
const method = this.getAttribute("method");
|
|
3434
|
-
if (method) {
|
|
3435
|
-
const m = this.ensure(".c-legend__method", () => { const el = document.createElement("div"); el.className = "c-legend__method"; return el; });
|
|
3436
|
-
m.textContent = method;
|
|
3437
|
-
} else {
|
|
3438
|
-
const m = this.querySelector(".c-legend__method");
|
|
3439
|
-
if (m) m.remove();
|
|
3440
|
-
}
|
|
3441
|
-
const norm = this.getAttribute("norm");
|
|
3442
|
-
if (norm) {
|
|
3443
|
-
const n = this.ensure(".c-legend__norm", () => { const el = document.createElement("span"); el.className = "c-legend__norm"; return el; });
|
|
3444
|
-
n.textContent = norm;
|
|
3445
|
-
} else {
|
|
3446
|
-
const n = this.querySelector(".c-legend__norm");
|
|
3447
|
-
if (n) n.remove();
|
|
3448
|
-
}
|
|
3449
|
-
const ramp = this.getAttribute("ramp");
|
|
3450
|
-
if (ramp) {
|
|
3451
|
-
const r = this.ensure(".c-legend__ramp", () => { const el = document.createElement("div"); el.className = "c-legend__ramp"; return el; });
|
|
3452
|
-
r.style.background = ramp;
|
|
3453
|
-
// ramp routing: equal-width segments with break labels
|
|
3454
|
-
const breaksAttr = this.getAttribute("breaks");
|
|
3455
|
-
if (breaksAttr) {
|
|
3456
|
-
let breaks = null;
|
|
3457
|
-
try { breaks = JSON.parse(breaksAttr); } catch (e) { breaks = breaksAttr.split(",").map((s) => s.trim()); }
|
|
3458
|
-
if (Array.isArray(breaks)) {
|
|
3459
|
-
// remove old segments
|
|
3460
|
-
Array.from(r.querySelectorAll(".c-legend__ramp-segment")).forEach((n) => n.remove());
|
|
3461
|
-
breaks.forEach((b, i) => {
|
|
3462
|
-
const seg = document.createElement("span");
|
|
3463
|
-
seg.className = "c-legend__ramp-segment";
|
|
3464
|
-
seg.style.flex = "1";
|
|
3465
|
-
const lbl = document.createElement("span");
|
|
3466
|
-
lbl.className = "c-legend__ramp-break";
|
|
3467
|
-
lbl.textContent = String(b);
|
|
3468
|
-
seg.appendChild(lbl);
|
|
3469
|
-
r.appendChild(seg);
|
|
3470
|
-
});
|
|
3471
|
-
}
|
|
3472
|
-
}
|
|
3473
|
-
} else {
|
|
3474
|
-
const r = this.querySelector(".c-legend__ramp");
|
|
3475
|
-
if (r) r.remove();
|
|
3476
|
-
}
|
|
3477
|
-
const scale = this.getAttribute("scale");
|
|
3478
|
-
if (scale) {
|
|
3479
|
-
const sc = this.ensure(".c-legend__scale", () => { const el = document.createElement("div"); el.className = "c-legend__scale"; return el; });
|
|
3480
|
-
sc.textContent = scale;
|
|
3481
|
-
} else {
|
|
3482
|
-
const sc = this.querySelector(".c-legend__scale");
|
|
3483
|
-
if (sc) sc.remove();
|
|
3484
|
-
}
|
|
3485
|
-
}
|
|
3486
|
-
enhance() {
|
|
3487
|
-
if (this._wiredLegend) return;
|
|
3488
|
-
this._wiredLegend = true;
|
|
3489
|
-
const selectable = this.hasAttribute("selectable");
|
|
3490
|
-
this.addEventListener("click", (e) => {
|
|
3491
|
-
if (!selectable) return;
|
|
3492
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-legend__item") : null;
|
|
3493
|
-
if (!btn || !this.contains(btn)) return;
|
|
3494
|
-
const pressed = btn.getAttribute("aria-pressed") !== "true";
|
|
3495
|
-
btn.setAttribute("aria-pressed", String(pressed));
|
|
3496
|
-
const items = Array.from(this.querySelectorAll(".c-legend__item"));
|
|
3497
|
-
const index = items.indexOf(btn);
|
|
3498
|
-
this.dispatchEvent(new CustomEvent("contour:legend-toggle", {
|
|
3499
|
-
detail: { label: btn.textContent.trim(), key: btn.dataset.key || btn.textContent.trim(), pressed, index },
|
|
3500
|
-
bubbles: true,
|
|
3501
|
-
composed: true,
|
|
3502
|
-
}));
|
|
3503
|
-
this.dispatchEvent(new CustomEvent("contour:select", {
|
|
3504
|
-
detail: { label: btn.textContent.trim(), key: btn.dataset.key || btn.textContent.trim(), value: btn.dataset.key || btn.textContent.trim() },
|
|
3505
|
-
bubbles: true,
|
|
3506
|
-
composed: true,
|
|
3507
|
-
}));
|
|
3508
|
-
});
|
|
3509
|
-
// emit style-resolved once on enhance
|
|
3510
|
-
try {
|
|
3511
|
-
let parsed = null;
|
|
3512
|
-
try { parsed = JSON.parse(this.getAttribute("items") || "null"); } catch (e) { parsed = this.getAttribute("items"); }
|
|
3513
|
-
this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: this.getAttribute("items"), items: parsed }, bubbles: true, composed: true }));
|
|
3514
|
-
} catch (e) {}
|
|
3515
|
-
// break-change delegated
|
|
3516
|
-
this.addEventListener("change", (e) => {
|
|
3517
|
-
const t = e.target;
|
|
3518
|
-
if (t && t.classList && t.classList.contains("c-legend__break-input")) {
|
|
3519
|
-
this.dispatchEvent(new CustomEvent("contour:break-change", { detail: { value: t.value }, bubbles: true, composed: true }));
|
|
3520
|
-
}
|
|
3521
|
-
});
|
|
3522
|
-
// keyboard nav (listbox) - only for selectable legends
|
|
3523
|
-
if (selectable) {
|
|
3524
|
-
this.addEventListener("keydown", (e) => {
|
|
3525
|
-
const items = Array.from(this.querySelectorAll(".c-legend__item"));
|
|
3526
|
-
if (!items.length) return;
|
|
3527
|
-
const active = document.activeElement;
|
|
3528
|
-
const idx = items.indexOf(active);
|
|
3529
|
-
if (e.key === "Escape") {
|
|
3530
|
-
// clear selection
|
|
3531
|
-
items.forEach((o) => o.setAttribute("aria-pressed", "false"));
|
|
3532
|
-
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true }));
|
|
3533
|
-
return;
|
|
3534
|
-
}
|
|
3535
|
-
if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
3536
|
-
// type-ahead
|
|
3537
|
-
if (items.length > 7) {
|
|
3538
|
-
const start = idx >= 0 ? idx + 1 : 0;
|
|
3539
|
-
for (let i = 0; i < items.length; i++) {
|
|
3540
|
-
const ii = (start + i) % items.length;
|
|
3541
|
-
const txt = (items[ii].textContent || "").trim().toLowerCase();
|
|
3542
|
-
if (txt.startsWith(e.key.toLowerCase())) {
|
|
3543
|
-
e.preventDefault();
|
|
3544
|
-
items[ii].focus();
|
|
3545
|
-
items.forEach((o,j)=>o.setAttribute("tabindex", j===ii?"0":"-1"));
|
|
3546
|
-
break;
|
|
3547
|
-
}
|
|
3548
|
-
}
|
|
3549
|
-
}
|
|
3550
|
-
return;
|
|
3551
|
-
}
|
|
3552
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
3553
|
-
e.preventDefault();
|
|
3554
|
-
if (active && active.classList.contains("c-legend__item")) {
|
|
3555
|
-
active.click();
|
|
3556
|
-
}
|
|
3557
|
-
return;
|
|
3558
|
-
}
|
|
3559
|
-
navKey(e, items, {
|
|
3560
|
-
wrap: true,
|
|
3561
|
-
homeEnd: true,
|
|
3562
|
-
rtl: isRtl(this),
|
|
3563
|
-
onNavigate: (i) => items.forEach((o, j) => o.setAttribute("tabindex", j === i ? "0" : "-1")),
|
|
3564
|
-
onKey: () => {}
|
|
3565
|
-
});
|
|
3566
|
-
});
|
|
3567
|
-
}
|
|
3568
|
-
// Cross-filter contract (R16-16): clear-all resets legend selection.
|
|
3569
|
-
this.addEventListener("contour:clear-all", () => {
|
|
3570
|
-
const items = Array.from(this.querySelectorAll(".c-legend__item"));
|
|
3571
|
-
let changed = false;
|
|
3572
|
-
items.forEach((o) => {
|
|
3573
|
-
if (o.getAttribute("role") === "button" && o.getAttribute("aria-pressed") === "true") {
|
|
3574
|
-
o.setAttribute("aria-pressed", "false");
|
|
3575
|
-
changed = true;
|
|
3576
|
-
}
|
|
3577
|
-
});
|
|
3578
|
-
if (changed) {
|
|
3579
|
-
this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "legend", filter: { selection: null } } }));
|
|
3580
|
-
}
|
|
3581
|
-
});
|
|
3582
|
-
}
|
|
3583
|
-
}
|
|
3584
|
-
define("contour-legend", ContourLegend);
|
|
3585
|
-
/**
|
|
3586
|
-
* Measure: web component wrapper.
|
|
3587
|
-
* Attributes: `label`, `value`, `point`, `line`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3588
|
-
*/
|
|
3589
|
-
class ContourMeasure extends ContourBase {
|
|
3590
|
-
static get observed() { return ["label", "value", "point", "line", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
3591
|
-
static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, point: { attribute: "point" }, line: { attribute: "line" }, src: { attribute: "src" } }; }
|
|
3592
|
-
render() {
|
|
3593
|
-
this.classList.add("c-measure");
|
|
3594
|
-
this.setAttribute("role", "group");
|
|
3595
|
-
this.setAttribute("aria-label", "Measure");
|
|
3596
|
-
wireStates(this);
|
|
3597
|
-
loadRemote(this, ["label", "value", "point", "line"]);
|
|
3598
|
-
if (renderStates(this, "measure")) return;
|
|
3599
|
-
const rLabel = remoteData(this, "label");
|
|
3600
|
-
const rValue = remoteData(this, "value");
|
|
3601
|
-
const rPoint = remoteData(this, "point");
|
|
3602
|
-
const rLine = remoteData(this, "line");
|
|
3603
|
-
if (!rLabel && !rValue && !rPoint && !rLine) {
|
|
3604
|
-
renderEmpty(this, "measure");
|
|
3605
|
-
return;
|
|
3606
|
-
}
|
|
3607
|
-
if (rLabel) {
|
|
3608
|
-
const l = this.ensure(".c-measure__label", () => { const el = document.createElement("span"); el.className = "c-measure__label"; return el; });
|
|
3609
|
-
l.textContent = rLabel;
|
|
3610
|
-
} else {
|
|
3611
|
-
const l = this.querySelector(".c-measure__label");
|
|
3612
|
-
if (l) l.remove();
|
|
3613
|
-
}
|
|
3614
|
-
if (rValue) {
|
|
3615
|
-
const r = this.ensure(".c-measure__readout", () => { const el = document.createElement("span"); el.className = "c-measure__readout"; return el; });
|
|
3616
|
-
r.textContent = rValue;
|
|
3617
|
-
} else {
|
|
3618
|
-
const r = this.querySelector(".c-measure__readout");
|
|
3619
|
-
if (r) r.remove();
|
|
3620
|
-
}
|
|
3621
|
-
// unit selector
|
|
3622
|
-
let sel = this.querySelector(".c-measure__unit-select");
|
|
3623
|
-
if (!sel) { sel = document.createElement("select"); sel.className = "c-measure__unit-select"; this.appendChild(sel); }
|
|
3624
|
-
["m","km","mi","ft"].forEach((u) => {
|
|
3625
|
-
if (!sel.querySelector('option[value="' + u + '"]')) { const o = document.createElement("option"); o.value = u; o.textContent = u; sel.appendChild(o); }
|
|
3626
|
-
});
|
|
3627
|
-
if (rPoint) {
|
|
3628
|
-
const p = this.ensure(".c-measure__point", () => { const el = document.createElement("span"); el.className = "c-measure__point"; return el; });
|
|
3629
|
-
p.textContent = rPoint;
|
|
3630
|
-
} else {
|
|
3631
|
-
const p = this.querySelector(".c-measure__point");
|
|
3632
|
-
if (p) p.remove();
|
|
3633
|
-
}
|
|
3634
|
-
if (!rLine) {
|
|
3635
|
-
const svg = this.querySelector("svg");
|
|
3636
|
-
if (svg) svg.remove();
|
|
3637
|
-
return;
|
|
3638
|
-
}
|
|
3639
|
-
if (rLine) {
|
|
3640
|
-
const ln = this.ensure(".c-measure__line", () => { const el = document.createElement("span"); el.className = "c-measure__line"; return el; });
|
|
3641
|
-
ln.style.inlineSize = rLine;
|
|
3642
|
-
} else {
|
|
3643
|
-
const ln = this.querySelector(".c-measure__line");
|
|
3644
|
-
if (ln) ln.remove();
|
|
3645
|
-
}
|
|
3646
|
-
}
|
|
3647
|
-
enhance() {
|
|
3648
|
-
if (this._wiredMeasure) return;
|
|
3649
|
-
this._wiredMeasure = true;
|
|
3650
|
-
this.addEventListener("change", (e) => {
|
|
3651
|
-
const sel = e.target && e.target.closest ? e.target.closest(".c-measure__unit-select") : null;
|
|
3652
|
-
if (sel && this.contains(sel)) {
|
|
3653
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { unit: sel.value } }));
|
|
3654
|
-
}
|
|
3655
|
-
});
|
|
3656
|
-
}
|
|
3657
|
-
}
|
|
3658
|
-
define("contour-measure", ContourMeasure);
|
|
3659
|
-
/**
|
|
3660
|
-
* Timeline: web component wrapper.
|
|
3661
|
-
* Attributes: `items`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3662
|
-
*/
|
|
3663
|
-
class ContourTimeline extends ContourBase {
|
|
3664
|
-
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
3665
|
-
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
3666
|
-
render() {
|
|
3667
|
-
this.classList.add("c-timeline");
|
|
3668
|
-
// Native list semantics: an <ol> with <li> items, not a role="list" on a
|
|
3669
|
-
// <div> recreating the platform's list numbering and association.
|
|
3670
|
-
let list = this.querySelector(".c-timeline__list");
|
|
3671
|
-
if (!list) { list = document.createElement("ol"); list.className = "c-timeline__list"; list.setAttribute("aria-label", this.getAttribute("aria-label") || "Timeline"); this.appendChild(list); }
|
|
3672
|
-
wireStates(this);
|
|
3673
|
-
loadRemote(this, "items");
|
|
3674
|
-
if (renderStates(this, "timeline")) return;
|
|
3675
|
-
const authored = Array.from(this.children).filter((n) => n.classList && n.classList.contains("c-timeline__item"));
|
|
3676
|
-
const items = remoteData(this, "items");
|
|
3677
|
-
if (items && !authored.length) {
|
|
3678
|
-
Array.from(list.querySelectorAll(".c-timeline__item")).forEach((n) => n.remove());
|
|
3679
|
-
try {
|
|
3680
|
-
const parsed = JSON.parse(items);
|
|
3681
|
-
parsed.forEach((it) => {
|
|
3682
|
-
const item = document.createElement("li");
|
|
3683
|
-
item.className = "c-timeline__item";
|
|
3684
|
-
item.setAttribute("tabindex", "-1");
|
|
3685
|
-
if (it.time) {
|
|
3686
|
-
const t = document.createElement("time");
|
|
3687
|
-
t.className = "c-timeline__time";
|
|
3688
|
-
t.setAttribute("datetime", String(it.time));
|
|
3689
|
-
t.textContent = it.time;
|
|
3690
|
-
item.appendChild(t);
|
|
3691
|
-
}
|
|
3692
|
-
if (it.title) {
|
|
3693
|
-
const ti = document.createElement("div");
|
|
3694
|
-
ti.className = "c-timeline__title";
|
|
3695
|
-
ti.textContent = it.title;
|
|
3696
|
-
item.appendChild(ti);
|
|
3697
|
-
}
|
|
3698
|
-
if (it.text) {
|
|
3699
|
-
const tx = document.createElement("div");
|
|
3700
|
-
tx.className = "c-timeline__text";
|
|
3701
|
-
tx.textContent = it.text;
|
|
3702
|
-
item.appendChild(tx);
|
|
3703
|
-
}
|
|
3704
|
-
list.appendChild(item);
|
|
3705
|
-
});
|
|
3706
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
3707
|
-
} else if (!authored.length) {
|
|
3708
|
-
renderEmpty(this, "timeline");
|
|
3709
|
-
}
|
|
3710
|
-
}
|
|
3711
|
-
enhance() {
|
|
3712
|
-
if (this._wiredTimeline) return;
|
|
3713
|
-
this._wiredTimeline = true;
|
|
3714
|
-
const items = Array.from(this.querySelectorAll(".c-timeline__item"));
|
|
3715
|
-
items.forEach((it, i) => it.setAttribute("tabindex", i === 0 ? "0" : "-1"));
|
|
3716
|
-
this.addEventListener("click", (e) => {
|
|
3717
|
-
const item = e.target && e.target.closest ? e.target.closest(".c-timeline__item") : null;
|
|
3718
|
-
if (!item || !this.contains(item)) return;
|
|
3719
|
-
const items = Array.from(this.querySelectorAll(".c-timeline__item"));
|
|
3720
|
-
const idx = items.indexOf(item);
|
|
3721
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx } }));
|
|
3722
|
-
});
|
|
3723
|
-
this.addEventListener("keydown", (e) => {
|
|
3724
|
-
const items = Array.from(this.querySelectorAll(".c-timeline__item"));
|
|
3725
|
-
if (!items.length) return;
|
|
3726
|
-
navKey(e, items, { wrap: false, homeEnd: true, onNavigate: (i) => items.forEach((it, j) => it.setAttribute("tabindex", j === i ? "0" : "-1")), onKey: () => { if (e.key === "Enter" || e.key === " ") this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: items.indexOf(document.activeElement) } })); } });
|
|
3727
|
-
});
|
|
3728
|
-
}
|
|
3729
|
-
}
|
|
3730
|
-
define("contour-timeline", ContourTimeline);
|
|
3731
|
-
/**
|
|
3732
|
-
* Heatmap: web component wrapper.
|
|
3733
|
-
* Attributes: `cells`, `count`, `legend`, `empty`, `loading`, `values`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3734
|
-
*/
|
|
3735
|
-
class ContourHeatmap extends ContourBase {
|
|
3736
|
-
static get observed() { return ["cells", "count", "legend", "empty", "loading", "values", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
3737
|
-
static get properties() { return { cells: { attribute: "cells" }, count: { attribute: "count" }, legend: { attribute: "legend" }, src: { attribute: "src" } }; }
|
|
3738
|
-
render() {
|
|
3739
|
-
this.classList.add("c-heatmap");
|
|
3740
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "grid");
|
|
3741
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Heatmap");
|
|
3742
|
-
wireStates(this);
|
|
3743
|
-
loadRemote(this, "cells");
|
|
3744
|
-
if (renderStates(this, "heatmap")) return;
|
|
3745
|
-
// Slotted content support: authored .c-heatmap__cell children take
|
|
3746
|
-
// precedence over the generated grid.
|
|
3747
|
-
const authoredCells = Array.from(this.querySelectorAll(":scope > .c-heatmap__cell"));
|
|
3748
|
-
if (authoredCells.length) {
|
|
3749
|
-
const cols = Math.ceil(Math.sqrt(authoredCells.length));
|
|
3750
|
-
this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
|
|
3751
|
-
this.style.inlineSize = "16rem";
|
|
3752
|
-
// Wrap authored cells in rows so gridcells have a required row parent
|
|
3753
|
-
let row = null;
|
|
3754
|
-
let col = 0;
|
|
3755
|
-
const newRow = () => { row = document.createElement("div"); row.setAttribute("role", "row"); this.appendChild(row); col = 0; };
|
|
3756
|
-
newRow();
|
|
3757
|
-
authoredCells.forEach((cell) => {
|
|
3758
|
-
cell.setAttribute("role", "gridcell");
|
|
3759
|
-
row.appendChild(cell);
|
|
3760
|
-
col++;
|
|
3761
|
-
if (col === cols) newRow();
|
|
3762
|
-
});
|
|
3763
|
-
} else {
|
|
3764
|
-
Array.from(this.querySelectorAll(".c-heatmap__cell")).forEach((n) => n.remove());
|
|
3765
|
-
const count = Math.min(200, Math.max(0, parseInt(this.getAttribute("cells") || this.getAttribute("count") || "0", 10) || 0));
|
|
3766
|
-
const cols = count > 0 ? Math.ceil(Math.sqrt(count)) : 1;
|
|
3767
|
-
this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
|
|
3768
|
-
this.style.inlineSize = "16rem";
|
|
3769
|
-
if (count > 0) {
|
|
3770
|
-
let values = [];
|
|
3771
|
-
try { values = JSON.parse(this.getAttribute("values") || "[]"); } catch (e) { values = []; }
|
|
3772
|
-
let row = null;
|
|
3773
|
-
let col = 0;
|
|
3774
|
-
const newRow = () => { row = document.createElement("div"); row.setAttribute("role", "row"); this.appendChild(row); col = 0; };
|
|
3775
|
-
newRow();
|
|
3776
|
-
for (let i = 0; i < count; i++) {
|
|
3777
|
-
const cell = document.createElement("div");
|
|
3778
|
-
cell.className = "c-heatmap__cell";
|
|
3779
|
-
cell.setAttribute("role", "gridcell");
|
|
3780
|
-
cell.setAttribute("tabindex", i === 0 ? "0" : "-1");
|
|
3781
|
-
cell.dataset.index = String(i);
|
|
3782
|
-
if (values[i] !== undefined) cell.setAttribute("title", String(values[i]));
|
|
3783
|
-
row.appendChild(cell);
|
|
3784
|
-
col++;
|
|
3785
|
-
if (col === cols && i < count - 1) newRow();
|
|
3786
|
-
}
|
|
3787
|
-
const tip = this.ensure(".c-heatmap__tooltip", () => { const el = document.createElement("div"); el.className = "c-heatmap__tooltip"; el.setAttribute("role", "tooltip"); el.setAttribute("hidden", ""); return el; });
|
|
3788
|
-
tip.setAttribute("hidden", "");
|
|
3789
|
-
} else if (!authoredCells.length) {
|
|
3790
|
-
renderEmpty(this, "heatmap");
|
|
3791
|
-
}
|
|
3792
|
-
}
|
|
3793
|
-
if (this.hasAttribute("legend")) {
|
|
3794
|
-
const leg = this.ensure(".c-heatmap__legend", () => {
|
|
3795
|
-
const el = document.createElement("div");
|
|
3796
|
-
el.className = "c-heatmap__legend";
|
|
3797
|
-
const bar = document.createElement("div");
|
|
3798
|
-
bar.className = "c-heatmap__legend-bar";
|
|
3799
|
-
el.appendChild(bar);
|
|
3800
|
-
return el;
|
|
3801
|
-
});
|
|
3802
|
-
} else {
|
|
3803
|
-
const leg = this.querySelector(".c-heatmap__legend");
|
|
3804
|
-
if (leg) leg.remove();
|
|
3805
|
-
}
|
|
3806
|
-
}
|
|
3807
|
-
enhance() {
|
|
3808
|
-
if (this._wiredHeatmap) return;
|
|
3809
|
-
this._wiredHeatmap = true;
|
|
3810
|
-
const cells = () => Array.from(this.querySelectorAll(".c-heatmap__cell"));
|
|
3811
|
-
// The tip is rebuilt on every render (the base wipes generated children),
|
|
3812
|
-
// so handlers re-query it per event (rule 12) — a captured node would be
|
|
3813
|
-
// detached after the first re-render and the tooltip would silently die.
|
|
3814
|
-
const showTip = (e) => {
|
|
3815
|
-
const tip = this.querySelector(".c-heatmap__tooltip");
|
|
3816
|
-
if (!tip) return;
|
|
3817
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-heatmap__cell") : null;
|
|
3818
|
-
if (!cell || !this.contains(cell)) { tip.setAttribute("hidden", ""); return; }
|
|
3819
|
-
const title = cell.getAttribute("title");
|
|
3820
|
-
if (title) tip.textContent = title;
|
|
3821
|
-
else tip.textContent = labelText(this, "cell", "Cell") + " " + (cell.dataset.index || "");
|
|
3822
|
-
const rect = this.getBoundingClientRect();
|
|
3823
|
-
const cr = cell.getBoundingClientRect();
|
|
3824
|
-
this.style.position = this.style.position || "relative";
|
|
3825
|
-
// Logical positioning (BY-48): the CSS positions the tip through the
|
|
3826
|
-
// --chart-tip-* tokens, the same contract the chart tooltip uses, so
|
|
3827
|
-
// the block flips with dir="rtl" instead of staying pinned to the
|
|
3828
|
-
// physical left edge of an RTL host.
|
|
3829
|
-
tip.style.setProperty("--chart-tip-inline-start", (cr.left - rect.left + cr.width / 2) + "px");
|
|
3830
|
-
tip.style.setProperty("--chart-tip-block-start", (cr.top - rect.top) + "px");
|
|
3831
|
-
tip.removeAttribute("hidden");
|
|
3832
|
-
};
|
|
3833
|
-
const hideTip = () => {
|
|
3834
|
-
const tip = this.querySelector(".c-heatmap__tooltip");
|
|
3835
|
-
if (tip) tip.setAttribute("hidden", "");
|
|
3836
|
-
};
|
|
3837
|
-
this.addEventListener("mouseover", showTip);
|
|
3838
|
-
this.addEventListener("mouseout", (e) => {
|
|
3839
|
-
if (!e.relatedTarget || !this.contains(e.relatedTarget)) hideTip();
|
|
3840
|
-
});
|
|
3841
|
-
this.addEventListener("focusin", (e) => {
|
|
3842
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-heatmap__cell") : null;
|
|
3843
|
-
if (cell && this.contains(cell)) showTip({ target: cell });
|
|
3844
|
-
});
|
|
3845
|
-
this.addEventListener("focusout", (e) => {
|
|
3846
|
-
if (!this.contains(e.relatedTarget)) hideTip();
|
|
3847
|
-
});
|
|
3848
|
-
this.addEventListener("keydown", (e) => {
|
|
3849
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-heatmap__cell") : null;
|
|
3850
|
-
if (!cell || !this.contains(cell)) return;
|
|
3851
|
-
const list = cells();
|
|
3852
|
-
const idx = list.indexOf(cell);
|
|
3853
|
-
let next = -1;
|
|
3854
|
-
const rtl = (this.getAttribute("dir") || document.documentElement.getAttribute("dir") || "").toLowerCase() === "rtl";
|
|
3855
|
-
if (e.key === "ArrowRight") next = rtl ? Math.max(idx - 1, 0) : Math.min(idx + 1, list.length - 1);
|
|
3856
|
-
else if (e.key === "ArrowLeft") next = rtl ? Math.min(idx + 1, list.length - 1) : Math.max(idx - 1, 0);
|
|
3857
|
-
else if (e.key === "ArrowDown") next = Math.min(idx + Math.ceil(Math.sqrt(list.length)), list.length - 1);
|
|
3858
|
-
else if (e.key === "ArrowUp") next = Math.max(idx - Math.ceil(Math.sqrt(list.length)), 0);
|
|
3859
|
-
else if (e.key === "Home") next = 0;
|
|
3860
|
-
else if (e.key === "End") next = list.length - 1;
|
|
3861
|
-
else if (e.key === "Enter" || e.key === " ") {
|
|
3862
|
-
e.preventDefault();
|
|
3863
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: 1, index: idx } }));
|
|
3864
|
-
return;
|
|
3865
|
-
}
|
|
3866
|
-
if (next >= 0 && next !== idx) {
|
|
3867
|
-
e.preventDefault();
|
|
3868
|
-
list.forEach((c, i) => c.setAttribute("tabindex", i === next ? "0" : "-1"));
|
|
3869
|
-
try { list[next].focus(); } catch (e) {}
|
|
3870
|
-
}
|
|
3871
|
-
});
|
|
3872
|
-
this.addEventListener("click", (e) => {
|
|
3873
|
-
const cell = e.target && e.target.closest ? e.target.closest(".c-heatmap__cell") : null;
|
|
3874
|
-
if (!cell || !this.contains(cell)) return;
|
|
3875
|
-
const idx = cells().indexOf(cell);
|
|
3876
|
-
if (idx >= 0) this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: 1, index: idx } }));
|
|
3877
|
-
});
|
|
3878
|
-
}
|
|
3879
|
-
}
|
|
3880
|
-
define("contour-heatmap", ContourHeatmap);
|
|
3881
|
-
/**
|
|
3882
|
-
* Compare: web component wrapper.
|
|
3883
|
-
* Attributes: `no`, `text`, `yes`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3884
|
-
*/
|
|
3885
|
-
class ContourCompare extends ContourBase {
|
|
3886
|
-
static get observed() { return ["no", "text", "yes", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
3887
|
-
static get properties() { return { no: { attribute: "no" }, text: { attribute: "text" }, yes: { attribute: "yes" }, src: { attribute: "src" } }; }
|
|
3888
|
-
render() {
|
|
3889
|
-
this.classList.add("c-compare");
|
|
3890
|
-
this.setAttribute("role", "group");
|
|
3891
|
-
this.setAttribute("aria-label", "Comparison");
|
|
3892
|
-
|
|
3893
|
-
wireStates(this);
|
|
3894
|
-
loadRemote(this, ["no", "text", "yes"]);
|
|
3895
|
-
if (renderStates(this, "compare")) return;
|
|
3896
|
-
const rYes = remoteData(this, "yes") || (this._remoteData && this._remoteData.yes);
|
|
3897
|
-
const rNo = remoteData(this, "no") || (this._remoteData && this._remoteData.no);
|
|
3898
|
-
const rText = remoteData(this, "text") || (this._remoteData && this._remoteData.text);
|
|
3899
|
-
Array.from(this.querySelectorAll(".c-compare__yes, .c-compare__no, .c-compare__text")).forEach((n) => n.remove());
|
|
3900
|
-
if (rYes) {
|
|
3901
|
-
const y = document.createElement("span");
|
|
3902
|
-
y.className = "c-compare__yes";
|
|
3903
|
-
y.innerHTML = '<svg aria-hidden="true"><use href="#i-check" /></svg>';
|
|
3904
|
-
this.appendChild(y);
|
|
3905
|
-
}
|
|
3906
|
-
if (rNo) {
|
|
3907
|
-
const n = document.createElement("div");
|
|
3908
|
-
n.className = "c-compare__no";
|
|
3909
|
-
n.textContent = rNo;
|
|
3910
|
-
this.appendChild(n);
|
|
3911
|
-
}
|
|
3912
|
-
if (rText) {
|
|
3913
|
-
const t = document.createElement("p");
|
|
3914
|
-
t.className = "c-compare__text";
|
|
3915
|
-
t.textContent = rText;
|
|
3916
|
-
this.appendChild(t);
|
|
3917
|
-
}
|
|
3918
|
-
if (!rYes && !rNo && !rText) {
|
|
3919
|
-
renderEmpty(this, "compare");
|
|
3920
|
-
}
|
|
3921
|
-
}
|
|
3922
|
-
}
|
|
3923
|
-
define("contour-compare", ContourCompare);
|
|
3924
|
-
/**
|
|
3925
|
-
* Sparkline: web component wrapper.
|
|
3926
|
-
* Attributes: `points`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
3927
|
-
*/
|
|
3928
|
-
class ContourSparkline extends ContourBase {
|
|
3929
|
-
static get observed() { return ["points", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
3930
|
-
static get properties() { return { points: { attribute: "points" }, src: { attribute: "src" } }; }
|
|
3931
|
-
render() {
|
|
3932
|
-
this.classList.add("c-sparkline");
|
|
3933
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
3934
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Sparkline");
|
|
3935
|
-
wireStates(this);
|
|
3936
|
-
loadRemote(this, "points");
|
|
3937
|
-
if (renderStates(this, "sparkline")) return;
|
|
3938
|
-
const points = remoteData(this, "points");
|
|
3939
|
-
if (points) {
|
|
3940
|
-
try {
|
|
3941
|
-
const parsed = JSON.parse(points);
|
|
3942
|
-
if (!Array.isArray(parsed) || parsed.length === 0) throw new Error("empty");
|
|
3943
|
-
Array.from(this.querySelectorAll(".c-sparkline__dot, .c-sparkline__line, .c-sparkline__area")).forEach((n) => n.remove());
|
|
3944
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
3945
|
-
svg.setAttribute("class", "c-sparkline__line");
|
|
3946
|
-
svg.setAttribute("viewBox", "0 0 100 30");
|
|
3947
|
-
svg.setAttribute("preserveAspectRatio", "none");
|
|
3948
|
-
svg.style.inlineSize = "100%";
|
|
3949
|
-
svg.style.blockSize = "100%";
|
|
3950
|
-
svg.setAttribute("width", "100%");
|
|
3951
|
-
svg.setAttribute("height", "100%");
|
|
3952
|
-
svg.setAttribute("title", this.getAttribute("aria-label") || "Sparkline");
|
|
3953
|
-
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
3954
|
-
path.setAttribute("d", parsed.map((p, i) => (i === 0 ? "M" : "L") + " " + (i * 100 / (parsed.length - 1)) + " " + (30 - p * 30)).join(" "));
|
|
3955
|
-
svg.appendChild(path);
|
|
3956
|
-
const dot = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
3957
|
-
dot.setAttribute("class", "c-sparkline__dot");
|
|
3958
|
-
dot.setAttribute("r", "2");
|
|
3959
|
-
dot.setAttribute("cx", "0");
|
|
3960
|
-
dot.setAttribute("cy", "15");
|
|
3961
|
-
dot.setAttribute("hidden", "");
|
|
3962
|
-
svg.appendChild(dot);
|
|
3963
|
-
this.appendChild(svg);
|
|
3964
|
-
this._sparkPoints = parsed;
|
|
3965
|
-
const tip = this.ensure(".c-sparkline__tooltip", () => { const el = document.createElement("div"); el.className = "c-sparkline__tooltip"; el.setAttribute("role", "tooltip"); el.setAttribute("hidden", ""); return el; });
|
|
3966
|
-
tip.setAttribute("hidden", "");
|
|
3967
|
-
} catch (e) {
|
|
3968
|
-
Array.from(this.querySelectorAll("svg")).forEach((n) => n.remove());
|
|
3969
|
-
renderEmpty(this, "sparkline");
|
|
3970
|
-
}
|
|
3971
|
-
} else {
|
|
3972
|
-
renderEmpty(this, "sparkline");
|
|
3973
|
-
}
|
|
3974
|
-
}
|
|
3975
|
-
enhance() {
|
|
3976
|
-
if (this._wiredSparkline) return;
|
|
3977
|
-
this._wiredSparkline = true;
|
|
3978
|
-
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
3979
|
-
// The svg, dot and tip are rebuilt on every render (the base wipes
|
|
3980
|
-
// generated children), so the handlers re-query them per event (rule 12);
|
|
3981
|
-
// a capture made at wiring time is a detached node the moment the first
|
|
3982
|
-
// attribute changes, and every tooltip after that writes into limbo.
|
|
3983
|
-
const showTip = (e) => {
|
|
3984
|
-
const svg = this.querySelector("svg");
|
|
3985
|
-
const tip = this.querySelector(".c-sparkline__tooltip");
|
|
3986
|
-
const dot = this.querySelector(".c-sparkline__dot");
|
|
3987
|
-
if (!tip || !svg) return;
|
|
3988
|
-
const rect = svg.getBoundingClientRect();
|
|
3989
|
-
const x = e.clientX - rect.left;
|
|
3990
|
-
const pct = Math.max(0, Math.min(1, x / rect.width));
|
|
3991
|
-
const pts = this._sparkPoints || [];
|
|
3992
|
-
if (pts.length === 0) return;
|
|
3993
|
-
const idx = Math.round(pct * (pts.length - 1));
|
|
3994
|
-
const val = pts[idx];
|
|
3995
|
-
const cx = (idx * 100 / (pts.length - 1));
|
|
3996
|
-
const cy = 30 - val * 30;
|
|
3997
|
-
if (dot) {
|
|
3998
|
-
dot.setAttribute("cx", String(cx));
|
|
3999
|
-
dot.setAttribute("cy", String(cy));
|
|
4000
|
-
dot.removeAttribute("hidden");
|
|
4001
|
-
}
|
|
4002
|
-
tip.textContent = String(val);
|
|
4003
|
-
const tipX = (cx / 100) * rect.width;
|
|
4004
|
-
// Logical positioning (BY-48): same token contract as the heatmap and
|
|
4005
|
-
// the chart tooltip, so the pointer-tracking tip stays inside the
|
|
4006
|
-
// block in an RTL layout rather than being measured from the left.
|
|
4007
|
-
tip.style.setProperty("--chart-tip-inline-start", tipX + "px");
|
|
4008
|
-
tip.style.setProperty("--chart-tip-block-start", "0px");
|
|
4009
|
-
tip.removeAttribute("hidden");
|
|
4010
|
-
};
|
|
4011
|
-
const hideTip = () => {
|
|
4012
|
-
const tip = this.querySelector(".c-sparkline__tooltip");
|
|
4013
|
-
const dot = this.querySelector(".c-sparkline__dot");
|
|
4014
|
-
if (tip) tip.setAttribute("hidden", "");
|
|
4015
|
-
if (dot) dot.setAttribute("hidden", "");
|
|
4016
|
-
};
|
|
4017
|
-
this.addEventListener("mousemove", showTip);
|
|
4018
|
-
this.addEventListener("mouseleave", hideTip);
|
|
4019
|
-
// Keyboard path (BY-39): the host carries tabindex; a focused sparkline
|
|
4020
|
-
// shows its last value, which is the point a keyboard reader can reach.
|
|
4021
|
-
this.addEventListener("focusin", () => {
|
|
4022
|
-
const pts = this._sparkPoints || [];
|
|
4023
|
-
if (!pts.length) return;
|
|
4024
|
-
const svg = this.querySelector("svg");
|
|
4025
|
-
if (!svg) return;
|
|
4026
|
-
const r = svg.getBoundingClientRect();
|
|
4027
|
-
showTip({ clientX: r.left + r.width - 1 });
|
|
4028
|
-
});
|
|
4029
|
-
this.addEventListener("focusout", hideTip);
|
|
4030
|
-
this.addEventListener("keydown", (e) => {
|
|
4031
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
4032
|
-
e.preventDefault();
|
|
4033
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series: 1 } }));
|
|
4034
|
-
}
|
|
4035
|
-
});
|
|
4036
|
-
}
|
|
4037
|
-
}
|
|
4038
|
-
define("contour-sparkline", ContourSparkline);
|
|
4039
|
-
/**
|
|
4040
|
-
* Chart Grid: web component wrapper.
|
|
4041
|
-
* Attributes: `title`, `series`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
4042
|
-
*/
|
|
4043
|
-
class ContourChartGrid extends ContourBase {
|
|
4044
|
-
static get updateMode() { return "keyed"; }
|
|
4045
|
-
static get observed() { return ["title", "series", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
4046
|
-
static get properties() { return { title: { attribute: "title" }, series: { attribute: "series" }, src: { attribute: "src" } }; }
|
|
4047
|
-
render() {
|
|
4048
|
-
this.classList.add("c-chart-grid");
|
|
4049
|
-
this.setAttribute("role", "group");
|
|
4050
|
-
this.setAttribute("aria-label", "Chart grid");
|
|
4051
|
-
wireStates(this);
|
|
4052
|
-
loadRemote(this, "series");
|
|
4053
|
-
if (renderStates(this, "chart-grid")) return;
|
|
4054
|
-
const title = this.getAttribute("title");
|
|
4055
|
-
if (title) {
|
|
4056
|
-
const t = this.ensure(".c-chart-grid__title", () => { const el = document.createElement("div"); el.className = "c-chart-grid__title"; return el; });
|
|
4057
|
-
t.textContent = title;
|
|
4058
|
-
}
|
|
4059
|
-
const series = remoteData(this, "series");
|
|
4060
|
-
if (!series && !title) renderEmpty(this, "chart-grid");
|
|
4061
|
-
}
|
|
4062
|
-
}
|
|
4063
|
-
define("contour-chart-grid", ContourChartGrid);
|
|
4064
|
-
/**
|
|
4065
|
-
* Contour Plot: web component wrapper.
|
|
4066
|
-
* Attributes: `values` (row-major 2D field), `levels`, `label`.
|
|
4067
|
-
*/
|
|
4068
|
-
class ContourContourPlot extends ContourBase {
|
|
4069
|
-
static get observed() { return ["values", "levels", "label"]; }
|
|
4070
|
-
static get properties() { return { values: { attribute: "values" }, levels: { attribute: "levels" }, label: { attribute: "label" } }; }
|
|
4071
|
-
render() {
|
|
4072
|
-
this.classList.add("c-contour-plot");
|
|
4073
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
4074
|
-
const label = this.getAttribute("label");
|
|
4075
|
-
if (label || !this.hasAttribute("aria-label")) this.setAttribute("aria-label", label || "Contour plot");
|
|
4076
|
-
const valuesAttr = this.getAttribute("values");
|
|
4077
|
-
const levelsAttr = this.getAttribute("levels");
|
|
4078
|
-
let grid = null;
|
|
4079
|
-
if (valuesAttr) { try { grid = JSON.parse(valuesAttr); } catch (e) { grid = null; } }
|
|
4080
|
-
let levels = [0.3, 0.5, 0.7];
|
|
4081
|
-
if (levelsAttr) { try { const l = JSON.parse(levelsAttr); if (Array.isArray(l) && l.length) levels = l; } catch (e) { /* keep defaults */ } }
|
|
4082
|
-
|
|
4083
|
-
let svg = this.querySelector("svg");
|
|
4084
|
-
if (!svg) {
|
|
4085
|
-
svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
4086
|
-
svg.setAttribute("class", "c-contour-plot__svg");
|
|
4087
|
-
svg.setAttribute("aria-hidden", "true");
|
|
4088
|
-
this.appendChild(svg);
|
|
4089
|
-
}
|
|
4090
|
-
// Clear previous contours so a re-render cannot stack a second set.
|
|
4091
|
-
Array.from(svg.querySelectorAll(".c-contour-plot__contour")).forEach((n) => n.remove());
|
|
4092
|
-
|
|
4093
|
-
if (Array.isArray(grid) && grid.length > 1 && Array.isArray(grid[0]) && grid[0].length > 1) {
|
|
4094
|
-
const draw = () => {
|
|
4095
|
-
const w = this.clientWidth || 300;
|
|
4096
|
-
const h = this.clientHeight || 300;
|
|
4097
|
-
svg.setAttribute("viewBox", `0 0 ${w} ${h}`);
|
|
4098
|
-
svg.querySelectorAll(".c-contour-plot__contour").forEach((n) => n.remove());
|
|
4099
|
-
contourPaths(grid, levels, w, h).forEach((line, li) => {
|
|
4100
|
-
if (!line.d) return;
|
|
4101
|
-
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
4102
|
-
path.setAttribute("d", line.d);
|
|
4103
|
-
path.setAttribute("class", "c-contour-plot__contour" + (li > 0 ? " c-contour-plot__contour--level-" + (li + 1) : ""));
|
|
4104
|
-
svg.appendChild(path);
|
|
4105
|
-
});
|
|
4106
|
-
};
|
|
4107
|
-
draw();
|
|
4108
|
-
// Re-render on resize so pixel-space paths track the container.
|
|
4109
|
-
if (typeof ResizeObserver !== "undefined" && !this._contourResize) {
|
|
4110
|
-
this._contourResize = new ResizeObserver(() => draw());
|
|
4111
|
-
this._contourResize.observe(this);
|
|
4112
|
-
onDispose(this, () => { this._contourResize.disconnect(); this._contourResize = null; });
|
|
4113
|
-
}
|
|
4114
|
-
} else if (!Array.isArray(grid)) {
|
|
4115
|
-
const empty = document.createElement("div");
|
|
4116
|
-
empty.className = "c-contour-plot__empty";
|
|
4117
|
-
empty.textContent = this.getAttribute("empty") || "No field";
|
|
4118
|
-
this.appendChild(empty);
|
|
4119
|
-
}
|
|
4120
|
-
}
|
|
4121
|
-
}
|
|
4122
|
-
define("contour-contour-plot", ContourContourPlot);
|
|
4123
|
-
/**
|
|
4124
|
-
* Error Boundary: web component wrapper.
|
|
4125
|
-
* Attributes: `fallback`, `error`.
|
|
4126
|
-
*/
|
|
4127
|
-
class ContourErrorBoundary extends ContourBase {
|
|
4128
|
-
static get observed() { return ["fallback", "error"]; }
|
|
4129
|
-
static get properties() { return { fallback: { attribute: "fallback" }, error: { attribute: "error" } }; }
|
|
4130
|
-
render() {
|
|
4131
|
-
this.classList.add("c-error-boundary");
|
|
4132
|
-
this.setAttribute("role", "region");
|
|
4133
|
-
this.setAttribute("aria-live", "polite");
|
|
4134
|
-
const err = this.getAttribute("error");
|
|
4135
|
-
if (err) {
|
|
4136
|
-
this.dataset.state = "error";
|
|
4137
|
-
// Hide authored children, show fallback.
|
|
4138
|
-
Array.from(this.children).forEach((c) => { if (!c.hasAttribute("data-fallback")) c.style.display = "none"; });
|
|
4139
|
-
let fb = this.querySelector("[data-fallback]");
|
|
4140
|
-
if (!fb) {
|
|
4141
|
-
fb = document.createElement("div");
|
|
4142
|
-
fb.className = "c-error-boundary__fallback";
|
|
4143
|
-
fb.dataset.fallback = "";
|
|
4144
|
-
fb.textContent = this.getAttribute("fallback") || "Something went wrong.";
|
|
4145
|
-
this.appendChild(fb);
|
|
4146
|
-
} else {
|
|
4147
|
-
fb.textContent = this.getAttribute("fallback") || fb.textContent || "Something went wrong.";
|
|
4148
|
-
}
|
|
4149
|
-
} else {
|
|
4150
|
-
this.dataset.state = "ready";
|
|
4151
|
-
Array.from(this.children).forEach((c) => { c.style.display = ""; });
|
|
4152
|
-
const fb = this.querySelector("[data-fallback]");
|
|
4153
|
-
if (fb) fb.remove();
|
|
4154
|
-
}
|
|
4155
|
-
}
|
|
4156
|
-
enhance() {
|
|
4157
|
-
if (this._wiredErrorBoundary) return;
|
|
4158
|
-
this._wiredErrorBoundary = true;
|
|
4159
|
-
// Catch errors thrown by descendants during render/event handling.
|
|
4160
|
-
this.addEventListener("error", (e) => {
|
|
4161
|
-
e.stopPropagation();
|
|
4162
|
-
const msg = (e && e.error && e.error.message) ? e.error.message : (e && e.message) ? e.message : "Unknown error";
|
|
4163
|
-
this.setAttribute("error", msg);
|
|
4164
|
-
this.dispatchEvent(new CustomEvent("contour:error", { bubbles: true, composed: true, detail: { message: msg } }));
|
|
4165
|
-
}, true);
|
|
4166
|
-
}
|
|
4167
|
-
}
|
|
4168
|
-
define("contour-error-boundary", ContourErrorBoundary);
|
|
4169
|
-
|
|
4170
|
-
class ContourDataExport extends ContourBase {
|
|
4171
|
-
static get observed() { return ["data", "format", "filename", "label"]; }
|
|
4172
|
-
static get properties() { return { data: { attribute: "data" }, format: { attribute: "format" }, filename: { attribute: "filename" }, label: { attribute: "label" } }; }
|
|
4173
|
-
render() {
|
|
4174
|
-
this.classList.add("c-data-export");
|
|
4175
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
4176
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Data export");
|
|
4177
|
-
const fmt = (this.getAttribute("format") || "json").toLowerCase();
|
|
4178
|
-
const btn = this.ensure(".c-data-export__btn", () => {
|
|
4179
|
-
const b = document.createElement("button");
|
|
4180
|
-
b.className = "c-data-export__btn";
|
|
4181
|
-
b.type = "button";
|
|
4182
|
-
return b;
|
|
4183
|
-
});
|
|
4184
|
-
btn.textContent = this.getAttribute("label") || ("Export " + fmt.toUpperCase());
|
|
4185
|
-
if (btn.parentNode !== this) this.appendChild(btn);
|
|
4186
|
-
}
|
|
4187
|
-
enhance() {
|
|
4188
|
-
if (this._wiredDataExport) return;
|
|
4189
|
-
this._wiredDataExport = true;
|
|
4190
|
-
this.addEventListener("click", (e) => {
|
|
4191
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-data-export__btn") : null;
|
|
4192
|
-
if (!btn || !this.contains(btn)) return;
|
|
4193
|
-
const fmt = (this.getAttribute("format") || "json").toLowerCase();
|
|
4194
|
-
const raw = this.getAttribute("data") || "[]";
|
|
4195
|
-
let text = raw;
|
|
4196
|
-
if (fmt === "csv") {
|
|
4197
|
-
try {
|
|
4198
|
-
const arr = JSON.parse(raw);
|
|
4199
|
-
if (Array.isArray(arr) && arr.length) {
|
|
4200
|
-
const keys = Object.keys(arr[0]);
|
|
4201
|
-
text = [keys.join(",")].concat(arr.map((r) => keys.map((k) => JSON.stringify(r[k] ?? "")).join(","))).join("\n");
|
|
4202
|
-
}
|
|
4203
|
-
} catch (e) {}
|
|
4204
|
-
}
|
|
4205
|
-
const blob = new Blob([text], { type: fmt === "csv" ? "text/csv" : "application/json" });
|
|
4206
|
-
const url = URL.createObjectURL(blob);
|
|
4207
|
-
const a = document.createElement("a");
|
|
4208
|
-
a.href = url;
|
|
4209
|
-
a.download = this.getAttribute("filename") || ("export." + fmt);
|
|
4210
|
-
document.body.appendChild(a);
|
|
4211
|
-
a.click();
|
|
4212
|
-
a.remove();
|
|
4213
|
-
URL.revokeObjectURL(url);
|
|
4214
|
-
this.dispatchEvent(new CustomEvent("contour:export", { bubbles: true, composed: true, detail: { format: fmt } }));
|
|
4215
|
-
});
|
|
4216
|
-
}
|
|
4217
|
-
}
|
|
4218
|
-
define("contour-data-export", ContourDataExport);
|
|
4219
|
-
|
|
4220
|
-
// Query builder: a list of field/operator/value rows with AND/OR connectors,
|
|
4221
|
-
// a remove button per row, and an Add rule button. The component renders the
|
|
4222
|
-
// rows from a `query` JSON attribute and emits contour:change with the
|
|
4223
|
-
// serialised query.
|
|
4224
|
-
class ContourQueryBuilder extends ContourBase {
|
|
4225
|
-
static get observed() { return ["query", "fields"]; }
|
|
4226
|
-
static get properties() { return { query: { attribute: "query" }, fields: { attribute: "fields" } }; }
|
|
4227
|
-
render() {
|
|
4228
|
-
this.classList.add("c-query-builder");
|
|
4229
|
-
const fields = this.getAttribute("fields");
|
|
4230
|
-
let fieldList = [];
|
|
4231
|
-
if (fields) { try { fieldList = JSON.parse(fields); } catch (e) { fieldList = []; } }
|
|
4232
|
-
const query = this.getAttribute("query");
|
|
4233
|
-
let rules = [];
|
|
4234
|
-
if (query) { try { rules = JSON.parse(query); } catch (e) { rules = []; } }
|
|
4235
|
-
const list = this.ensure(".c-query-builder__list", () => { const el = document.createElement("div"); el.className = "c-query-builder__list"; return el; });
|
|
4236
|
-
Array.from(list.querySelectorAll(".c-query-builder__row, .c-query-builder__connector")).forEach((n) => n.remove());
|
|
4237
|
-
rules.forEach((rule, i) => {
|
|
4238
|
-
// Connector between rows (AND/OR).
|
|
4239
|
-
if (i > 0) {
|
|
4240
|
-
const conn = document.createElement("div");
|
|
4241
|
-
conn.className = "c-query-builder__connector";
|
|
4242
|
-
const sel = document.createElement("select");
|
|
4243
|
-
sel.className = "c-query-builder__op";
|
|
4244
|
-
sel.setAttribute("aria-label", "Connector " + i);
|
|
4245
|
-
["AND", "OR"].forEach((c) => {
|
|
4246
|
-
const opt = document.createElement("option");
|
|
4247
|
-
opt.value = c; opt.textContent = c;
|
|
4248
|
-
if (c === (rule.connector || "AND")) opt.selected = true;
|
|
4249
|
-
sel.appendChild(opt);
|
|
4250
|
-
});
|
|
4251
|
-
conn.appendChild(sel);
|
|
4252
|
-
list.appendChild(conn);
|
|
4253
|
-
}
|
|
4254
|
-
const row = document.createElement("div");
|
|
4255
|
-
row.className = "c-query-builder__row";
|
|
4256
|
-
const field = document.createElement("select");
|
|
4257
|
-
field.className = "c-query-builder__field";
|
|
4258
|
-
field.setAttribute("aria-label", "Field " + (i + 1));
|
|
4259
|
-
fieldList.forEach((f) => {
|
|
4260
|
-
const opt = document.createElement("option");
|
|
4261
|
-
opt.value = typeof f === "string" ? f : (f.value || f.label || "");
|
|
4262
|
-
opt.textContent = typeof f === "string" ? f : (f.label || f.value || "");
|
|
4263
|
-
if (opt.value === rule.field) opt.selected = true;
|
|
4264
|
-
field.appendChild(opt);
|
|
4265
|
-
});
|
|
4266
|
-
const op = document.createElement("select");
|
|
4267
|
-
op.className = "c-query-builder__op";
|
|
4268
|
-
op.setAttribute("aria-label", "Operator " + (i + 1));
|
|
4269
|
-
["=", "!=", ">", "<", "contains"].forEach((o) => {
|
|
4270
|
-
const opt = document.createElement("option");
|
|
4271
|
-
opt.value = o; opt.textContent = o;
|
|
4272
|
-
if (o === rule.op) opt.selected = true;
|
|
4273
|
-
op.appendChild(opt);
|
|
4274
|
-
});
|
|
4275
|
-
const val = document.createElement("input");
|
|
4276
|
-
val.className = "c-query-builder__value";
|
|
4277
|
-
val.type = "text";
|
|
4278
|
-
val.value = rule.value || "";
|
|
4279
|
-
val.setAttribute("aria-label", "Value " + (i + 1));
|
|
4280
|
-
const remove = document.createElement("button");
|
|
4281
|
-
remove.type = "button";
|
|
4282
|
-
remove.className = "c-btn c-btn--sm c-btn--ghost c-query-builder__remove";
|
|
4283
|
-
remove.setAttribute("aria-label", "Remove rule " + (i + 1));
|
|
4284
|
-
remove.textContent = "×";
|
|
4285
|
-
row.appendChild(field); row.appendChild(op); row.appendChild(val); row.appendChild(remove);
|
|
4286
|
-
list.appendChild(row);
|
|
4287
|
-
});
|
|
4288
|
-
const add = this.ensure(".c-query-builder__add", () => { const b = document.createElement("button"); b.type = "button"; b.className = "c-btn c-btn--sm c-query-builder__add"; return b; });
|
|
4289
|
-
add.textContent = labelText(this, "add-rule", "Add rule");
|
|
4290
|
-
if (add.parentNode !== this) this.appendChild(add);
|
|
4291
|
-
}
|
|
4292
|
-
enhance() {
|
|
4293
|
-
if (this._wiredQueryBuilder) return;
|
|
4294
|
-
this._wiredQueryBuilder = true;
|
|
4295
|
-
this.addEventListener("click", (e) => {
|
|
4296
|
-
const t = e.target;
|
|
4297
|
-
if (t && t.closest && t.closest(".c-query-builder__add")) {
|
|
4298
|
-
const rows = Array.from(this.querySelectorAll(".c-query-builder__row")).map((r) => ({
|
|
4299
|
-
field: r.querySelector(".c-query-builder__field")?.value || "",
|
|
4300
|
-
op: r.querySelector(".c-query-builder__op")?.value || "=",
|
|
4301
|
-
value: r.querySelector(".c-query-builder__value")?.value || "",
|
|
4302
|
-
}));
|
|
4303
|
-
rows.push({ field: "", op: "=", value: "" });
|
|
4304
|
-
this.setAttribute("query", JSON.stringify(rows));
|
|
4305
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { query: rows } }));
|
|
4306
|
-
}
|
|
4307
|
-
if (t && t.closest && t.closest(".c-query-builder__remove")) {
|
|
4308
|
-
const row = t.closest(".c-query-builder__row");
|
|
4309
|
-
if (!row) return;
|
|
4310
|
-
const rows = Array.from(this.querySelectorAll(".c-query-builder__row")).map((r) => ({
|
|
4311
|
-
field: r.querySelector(".c-query-builder__field")?.value || "",
|
|
4312
|
-
op: r.querySelector(".c-query-builder__op")?.value || "=",
|
|
4313
|
-
value: r.querySelector(".c-query-builder__value")?.value || "",
|
|
4314
|
-
}));
|
|
4315
|
-
const idx = Array.from(this.querySelectorAll(".c-query-builder__row")).indexOf(row);
|
|
4316
|
-
if (idx >= 0) rows.splice(idx, 1);
|
|
4317
|
-
this.setAttribute("query", JSON.stringify(rows));
|
|
4318
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { query: rows } }));
|
|
4319
|
-
}
|
|
4320
|
-
});
|
|
4321
|
-
}
|
|
4322
|
-
}
|
|
4323
|
-
define("contour-query-builder", ContourQueryBuilder);
|
|
2
|
+
* Data family barrel — the data-surface web components, split into semantic
|
|
3
|
+
* fragments. Importing this module registers every data component (the
|
|
4
|
+
* fragments are side-effectful: each defines its own custom elements). The
|
|
5
|
+
* build concatenates the fragments for the IIFE/ESM bundles; this barrel keeps
|
|
6
|
+
* `contour-ds/wc/data.mjs` working for consumers who import the family by name.
|
|
7
|
+
*/
|
|
8
|
+
import "./data-readout.mjs";
|
|
9
|
+
import "./data-table.mjs";
|
|
10
|
+
import "./data-chart.mjs";
|
|
11
|
+
import "./data-gauge.mjs";
|
|
12
|
+
import "./data-series.mjs";
|
|
13
|
+
import "./data-legend.mjs";
|
|
14
|
+
import "./data-geo.mjs";
|
|
15
|
+
import "./data-export.mjs";
|
|
16
|
+
import "./data-glyphs.mjs";
|