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