contour-ds 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/build-manifest.json +55 -55
- package/dist/contour-wc.esm.js +1461 -182
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +1461 -182
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.components.json +435 -22
- package/dist/contour.css +426 -45
- package/dist/contour.d.ts +31 -0
- package/dist/contour.esm.js +12 -0
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.js +12 -0
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/docs/actions.md +1 -1
- package/dist/docs/affordances.md +1 -1
- package/dist/docs/colour.md +1 -1
- package/dist/docs/data.md +1 -1
- package/dist/docs/docs.md +1 -1
- package/dist/docs/feedback.md +1 -1
- package/dist/docs/field.md +1 -1
- package/dist/docs/forms.md +1 -1
- package/dist/docs/index.json +15 -4
- package/dist/docs/install.md +1 -1
- package/dist/docs/landing.md +1 -1
- package/dist/docs/mapengine.md +1 -1
- package/dist/docs/motion.md +1 -1
- package/dist/docs/navigation.md +1 -1
- package/dist/docs/overlays.md +1 -1
- package/dist/docs/overview.md +1 -1
- package/dist/docs/patterns.md +1 -1
- package/dist/docs/playground.md +1 -1
- package/dist/docs/principles.md +1 -1
- package/dist/docs/recipes.md +1 -1
- package/dist/docs/space.md +1 -1
- package/dist/docs/status.md +1 -1
- package/dist/docs/surfaces.md +1 -1
- package/dist/docs/theming.md +1 -1
- package/dist/docs/type.md +1 -1
- package/dist/docs/webcomponents.md +1 -1
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/wc/core.mjs +17 -6
- package/dist/wc/data.mjs +816 -45
- package/dist/wc/forms.mjs +119 -61
- package/dist/wc/index.mjs +1 -1
- package/dist/wc/interaction.mjs +3 -2
- package/dist/wc/map.mjs +280 -49
- package/dist/wc/navigation.mjs +66 -11
- package/dist/wc/shadow.mjs +29 -1
- package/dist/wc/svg.mjs +16 -1
- package/dist/wc/ui.mjs +117 -9
- package/package.json +1 -1
package/dist/wc/data.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContourBase, define, onDispose, formatValue } from './core.mjs';
|
|
1
|
+
import { ContourBase, define, onDispose, formatValue, contourId } from './core.mjs';
|
|
2
2
|
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates, remoteInvalidate, watchViewport } from './states.mjs';
|
|
3
3
|
import { donutSlices, barRects, smoothPath, polylinePoints } from './svg.mjs';
|
|
4
4
|
class ContourReadout extends ContourBase {
|
|
@@ -44,9 +44,9 @@ class ContourReadout extends ContourBase {
|
|
|
44
44
|
}
|
|
45
45
|
define("contour-readout", ContourReadout);
|
|
46
46
|
class ContourKpi extends ContourBase {
|
|
47
|
-
static get observed() { return ["value", "label", "delta", "direction", "note", "variant", "unit", "format", "locale", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
47
|
+
static get observed() { return ["value", "label", "delta", "direction", "note", "variant", "unit", "format", "locale", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "thresholds", "threshold", "sparkline", "polarity"]; }
|
|
48
48
|
static get properties() {
|
|
49
|
-
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" } };
|
|
49
|
+
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" } };
|
|
50
50
|
}
|
|
51
51
|
render() {
|
|
52
52
|
this.classList.add("c-kpi");
|
|
@@ -76,13 +76,18 @@ class ContourKpi extends ContourBase {
|
|
|
76
76
|
const h = this.querySelector(".c-kpi__head");
|
|
77
77
|
if (h) h.remove();
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
if (delta) {
|
|
80
|
+
const f = this.ensure(".c-kpi__foot", () => { const el = document.createElement("div"); el.className = "c-kpi__foot"; return el; });
|
|
81
|
+
const d = f.querySelector(".c-delta") || document.createElement("span");
|
|
82
|
+
if (!d.parentNode) f.insertBefore(d, f.firstChild);
|
|
83
|
+
const dir = this.getAttribute("direction") || "up";
|
|
84
|
+
const polarity = this.getAttribute("polarity") || "neutral";
|
|
85
|
+
let tone = "neutral";
|
|
86
|
+
if (polarity === "good") tone = (dir === "up") ? "good" : "bad";
|
|
87
|
+
else if (polarity === "bad") tone = (dir === "up") ? "bad" : "good";
|
|
88
|
+
d.className = "c-delta c-delta--" + dir + " c-delta--" + tone;
|
|
89
|
+
d.textContent = delta;
|
|
90
|
+
} else {
|
|
86
91
|
const d = this.querySelector(".c-kpi__foot .c-delta");
|
|
87
92
|
if (d) d.remove();
|
|
88
93
|
}
|
|
@@ -107,6 +112,30 @@ class ContourKpi extends ContourBase {
|
|
|
107
112
|
if (u) u.remove();
|
|
108
113
|
}
|
|
109
114
|
}
|
|
115
|
+
// threshold badge
|
|
116
|
+
const threshold = this.getAttribute("threshold") || this.getAttribute("thresholds");
|
|
117
|
+
if (threshold) {
|
|
118
|
+
const f = this.ensure(".c-kpi__foot", () => { const el = document.createElement("div"); el.className = "c-kpi__foot"; return el; });
|
|
119
|
+
let badge = f.querySelector(".c-kpi__threshold-badge");
|
|
120
|
+
if (!badge) { badge = document.createElement("span"); badge.className = "c-kpi__threshold-badge"; f.appendChild(badge); }
|
|
121
|
+
badge.textContent = threshold;
|
|
122
|
+
badge.setAttribute("part", "threshold-badge");
|
|
123
|
+
} else {
|
|
124
|
+
const b = this.querySelector(".c-kpi__threshold-badge");
|
|
125
|
+
if (b) b.remove();
|
|
126
|
+
}
|
|
127
|
+
// remove orphaned foot container when no children remain
|
|
128
|
+
const foot = this.querySelector(".c-kpi__foot");
|
|
129
|
+
if (foot && !foot.querySelector(".c-delta, .c-kpi__note, .c-kpi__threshold-badge")) foot.remove();
|
|
130
|
+
// sparkline canvas
|
|
131
|
+
const spark = this.getAttribute("sparkline");
|
|
132
|
+
if (spark) {
|
|
133
|
+
let canvas = this.querySelector(".c-kpi__sparkline-canvas");
|
|
134
|
+
if (!canvas) { canvas = document.createElement("canvas"); canvas.className = "c-kpi__sparkline-canvas"; canvas.setAttribute("part", "sparkline-canvas"); this.appendChild(canvas); }
|
|
135
|
+
} else {
|
|
136
|
+
const c = this.querySelector(".c-kpi__sparkline-canvas");
|
|
137
|
+
if (c) c.remove();
|
|
138
|
+
}
|
|
110
139
|
if (!value && !label) {
|
|
111
140
|
renderEmpty(this, "kpi");
|
|
112
141
|
}
|
|
@@ -950,24 +979,32 @@ const series = this.getAttribute("series");
|
|
|
950
979
|
}
|
|
951
980
|
define("contour-chart", ContourChart);
|
|
952
981
|
class ContourComparison extends ContourBase {
|
|
953
|
-
static get observed() { return ["divider", "value"]; }
|
|
954
|
-
static get properties() { return { divider: { attribute: "divider" }, value: { attribute: "value" } }; }
|
|
982
|
+
static get observed() { return ["divider", "value", "before", "after"]; }
|
|
983
|
+
static get properties() { return { divider: { attribute: "divider" }, value: { attribute: "value" }, before: { attribute: "before" }, after: { attribute: "after" } }; }
|
|
955
984
|
render() {
|
|
956
985
|
this.classList.add("c-comparison");
|
|
957
|
-
this.style.blockSize = "12rem";
|
|
986
|
+
if (!this.style.blockSize) this.style.blockSize = "12rem";
|
|
958
987
|
this.style.setProperty("--comparison-pos", (this.getAttribute("value") || "50") + "%");
|
|
959
988
|
// Ensure two panes exist.
|
|
989
|
+
const beforeLabel = this.getAttribute("before") || "Before";
|
|
990
|
+
const afterLabel = this.getAttribute("after") || "After";
|
|
960
991
|
if (!this.querySelector(".c-comparison__pane--before")) {
|
|
961
992
|
const p = document.createElement("div");
|
|
962
993
|
p.className = "c-comparison__pane c-comparison__pane--before";
|
|
963
|
-
p.textContent =
|
|
994
|
+
p.textContent = beforeLabel;
|
|
964
995
|
this.appendChild(p);
|
|
996
|
+
} else {
|
|
997
|
+
const p = this.querySelector(".c-comparison__pane--before");
|
|
998
|
+
if (p) p.textContent = beforeLabel;
|
|
965
999
|
}
|
|
966
1000
|
if (!this.querySelector(".c-comparison__pane:not(.c-comparison__pane--before)")) {
|
|
967
1001
|
const p = document.createElement("div");
|
|
968
1002
|
p.className = "c-comparison__pane";
|
|
969
|
-
p.textContent =
|
|
1003
|
+
p.textContent = afterLabel;
|
|
970
1004
|
this.appendChild(p);
|
|
1005
|
+
} else {
|
|
1006
|
+
const p = this.querySelector(".c-comparison__pane:not(.c-comparison__pane--before)");
|
|
1007
|
+
if (p) p.textContent = afterLabel;
|
|
971
1008
|
}
|
|
972
1009
|
const divider = this.getAttribute("divider");
|
|
973
1010
|
if (divider !== null) {
|
|
@@ -1241,6 +1278,517 @@ class ContourStat extends ContourBase {
|
|
|
1241
1278
|
}
|
|
1242
1279
|
}
|
|
1243
1280
|
define("contour-stat", ContourStat);
|
|
1281
|
+
class ContourGauge extends ContourBase {
|
|
1282
|
+
static get observed() { return ["value", "min", "max", "heading", "thresholds", "format", "locale", "unit", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level", "no-data-message", "show-header", "description"]; }
|
|
1283
|
+
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" } }; }
|
|
1284
|
+
render() {
|
|
1285
|
+
this.classList.add("c-gauge");
|
|
1286
|
+
wireStates(this);
|
|
1287
|
+
loadRemote(this, ["value"]);
|
|
1288
|
+
if (renderStates(this, "gauge")) return;
|
|
1289
|
+
const rawValue = this.getAttribute("value");
|
|
1290
|
+
const num = parseFloat(rawValue);
|
|
1291
|
+
const hasValue = rawValue !== null && rawValue !== "" && Number.isFinite(num);
|
|
1292
|
+
const min = parseFloat(this.getAttribute("min") || "0");
|
|
1293
|
+
const max = parseFloat(this.getAttribute("max") || "100");
|
|
1294
|
+
const heading = this.getAttribute("heading");
|
|
1295
|
+
const showHeader = this.getAttribute("show-header") !== "false";
|
|
1296
|
+
const description = this.getAttribute("description");
|
|
1297
|
+
const noDataMessage = this.getAttribute("no-data-message") || "No readings in view";
|
|
1298
|
+
const brownoutLevel = parseInt(this.getAttribute("brownout-level") || this.getAttribute("brownout") || "0", 10) || 0;
|
|
1299
|
+
// empty state
|
|
1300
|
+
if (!hasValue) {
|
|
1301
|
+
if (heading && showHeader) {
|
|
1302
|
+
const t = this.ensure(".c-gauge__title", () => { const el = document.createElement("div"); el.className = "c-gauge__title"; return el; });
|
|
1303
|
+
t.textContent = heading;
|
|
1304
|
+
}
|
|
1305
|
+
const empty = this.ensure(".c-gauge__empty", () => { const el = document.createElement("div"); el.className = "c-gauge__empty"; el.setAttribute("part", "empty"); return el; });
|
|
1306
|
+
empty.textContent = noDataMessage;
|
|
1307
|
+
// remove dial/value/band if present
|
|
1308
|
+
[".c-gauge__dial", ".c-gauge__value", ".c-gauge__band"].forEach((sel) => { const n = this.querySelector(sel); if (n) n.remove(); });
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
// heading
|
|
1312
|
+
if (heading && showHeader) {
|
|
1313
|
+
const t = this.ensure(".c-gauge__title", () => { const el = document.createElement("div"); el.className = "c-gauge__title"; el.setAttribute("part", "title"); return el; });
|
|
1314
|
+
t.textContent = heading;
|
|
1315
|
+
} else {
|
|
1316
|
+
const t = this.querySelector(".c-gauge__title"); if (t) t.remove();
|
|
1317
|
+
}
|
|
1318
|
+
// thresholds
|
|
1319
|
+
let thresholds = [];
|
|
1320
|
+
const tAttr = this.getAttribute("thresholds");
|
|
1321
|
+
if (tAttr) { try { thresholds = JSON.parse(tAttr); } catch (e) { thresholds = []; } }
|
|
1322
|
+
// band determination
|
|
1323
|
+
let band = null;
|
|
1324
|
+
if (thresholds && thresholds.length) {
|
|
1325
|
+
// thresholds sorted ascending by value
|
|
1326
|
+
const sorted = [...thresholds].sort((a, b) => (a.value || 0) - (b.value || 0));
|
|
1327
|
+
for (let i = sorted.length - 1; i >= 0; i--) {
|
|
1328
|
+
if (num >= (sorted[i].value || 0)) { band = sorted[i]; break; }
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
// dial (unless brownout >= 3)
|
|
1332
|
+
const shedDial = brownoutLevel >= 3;
|
|
1333
|
+
let dial = this.querySelector(".c-gauge__dial");
|
|
1334
|
+
if (shedDial) {
|
|
1335
|
+
if (dial) dial.remove();
|
|
1336
|
+
} else {
|
|
1337
|
+
if (!dial) {
|
|
1338
|
+
dial = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1339
|
+
dial.setAttribute("class", "c-gauge__dial");
|
|
1340
|
+
dial.setAttribute("part", "dial");
|
|
1341
|
+
dial.setAttribute("aria-hidden", "true");
|
|
1342
|
+
dial.setAttribute("viewBox", "0 0 100 100");
|
|
1343
|
+
this.appendChild(dial);
|
|
1344
|
+
}
|
|
1345
|
+
// rebuild dial content
|
|
1346
|
+
dial.innerHTML = "";
|
|
1347
|
+
// track arc (semicircle)
|
|
1348
|
+
const track = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1349
|
+
track.setAttribute("class", "c-gauge__track");
|
|
1350
|
+
track.setAttribute("d", "M 10 90 A 40 40 0 0 1 90 90");
|
|
1351
|
+
dial.appendChild(track);
|
|
1352
|
+
// zones: each threshold defines a band from its value to the next
|
|
1353
|
+
// threshold's value (or max), drawn as an arc along the track so the
|
|
1354
|
+
// bands no longer stack on top of one another.
|
|
1355
|
+
if (thresholds && thresholds.length) {
|
|
1356
|
+
const sorted = [...thresholds].sort((a, b) => (a.value || 0) - (b.value || 0));
|
|
1357
|
+
const toPoint = (v) => {
|
|
1358
|
+
const pos = (1 - (v - min) / (max - min || 1)) * Math.PI;
|
|
1359
|
+
return { x: 50 + 40 * Math.cos(pos), y: 90 - 40 * Math.sin(pos) };
|
|
1360
|
+
};
|
|
1361
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
1362
|
+
const v1 = sorted[i].value || 0;
|
|
1363
|
+
const v2 = (i + 1 < sorted.length) ? (sorted[i + 1].value || max) : max;
|
|
1364
|
+
const p1 = toPoint(v1);
|
|
1365
|
+
const p2 = toPoint(v2);
|
|
1366
|
+
const z = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1367
|
+
z.setAttribute("class", "c-gauge__zone");
|
|
1368
|
+
z.setAttribute("stroke", sorted[i].color || "var(--color-primary)");
|
|
1369
|
+
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));
|
|
1370
|
+
dial.appendChild(z);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
// needle
|
|
1374
|
+
const angle = ((num - min) / (max - min || 1)) * 180 - 90;
|
|
1375
|
+
const needle = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
1376
|
+
needle.setAttribute("class", "c-gauge__needle needle");
|
|
1377
|
+
needle.setAttribute("x1", "50"); needle.setAttribute("y1", "50");
|
|
1378
|
+
needle.setAttribute("x2", String(50 + 35 * Math.cos(angle * Math.PI / 180)));
|
|
1379
|
+
needle.setAttribute("y2", String(50 + 35 * Math.sin(angle * Math.PI / 180)));
|
|
1380
|
+
dial.appendChild(needle);
|
|
1381
|
+
const hub = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
1382
|
+
hub.setAttribute("class", "c-gauge__hub hub");
|
|
1383
|
+
hub.setAttribute("cx", "50"); hub.setAttribute("cy", "50"); hub.setAttribute("r", "4");
|
|
1384
|
+
dial.appendChild(hub);
|
|
1385
|
+
}
|
|
1386
|
+
// value element (meter)
|
|
1387
|
+
const valueEl = this.ensure(".c-gauge__value", () => { const el = document.createElement("div"); el.className = "c-gauge__value"; el.setAttribute("part", "value"); return el; });
|
|
1388
|
+
valueEl.textContent = formatValue(String(num), this.getAttribute("format"), this.getAttribute("locale")) + (this.getAttribute("unit") ? " " + this.getAttribute("unit") : "");
|
|
1389
|
+
valueEl.setAttribute("role", "meter");
|
|
1390
|
+
valueEl.setAttribute("aria-valuenow", String(num));
|
|
1391
|
+
valueEl.setAttribute("aria-valuemin", String(min));
|
|
1392
|
+
valueEl.setAttribute("aria-valuemax", String(max));
|
|
1393
|
+
if (heading) {
|
|
1394
|
+
// labelledby
|
|
1395
|
+
if (!valueEl.id) valueEl.id = contourId("gauge-value");
|
|
1396
|
+
}
|
|
1397
|
+
if (band) {
|
|
1398
|
+
valueEl.setAttribute("aria-valuetext", num + ", " + (band.label || (">= " + band.value)));
|
|
1399
|
+
} else {
|
|
1400
|
+
valueEl.setAttribute("aria-valuetext", String(num));
|
|
1401
|
+
}
|
|
1402
|
+
// aria-labelledby / aria-label
|
|
1403
|
+
const titleEl = this.querySelector(".c-gauge__title");
|
|
1404
|
+
if (titleEl) {
|
|
1405
|
+
if (!titleEl.id) titleEl.id = contourId("gauge-title");
|
|
1406
|
+
valueEl.setAttribute("aria-labelledby", titleEl.id);
|
|
1407
|
+
valueEl.removeAttribute("aria-label");
|
|
1408
|
+
} else {
|
|
1409
|
+
valueEl.removeAttribute("aria-labelledby");
|
|
1410
|
+
if (heading) valueEl.setAttribute("aria-label", heading);
|
|
1411
|
+
}
|
|
1412
|
+
// band word
|
|
1413
|
+
const bandEl = this.querySelector(".c-gauge__band");
|
|
1414
|
+
if (band) {
|
|
1415
|
+
const b = this.ensure(".c-gauge__band", () => { const el = document.createElement("div"); el.className = "c-gauge__band"; el.setAttribute("part", "band"); return el; });
|
|
1416
|
+
b.textContent = band.label || (">= " + band.value);
|
|
1417
|
+
} else {
|
|
1418
|
+
if (bandEl) bandEl.remove();
|
|
1419
|
+
}
|
|
1420
|
+
// description
|
|
1421
|
+
if (description) {
|
|
1422
|
+
let d = this.querySelector(".c-gauge__desc");
|
|
1423
|
+
if (!d) { d = document.createElement("div"); d.className = "c-gauge__desc"; this.appendChild(d); }
|
|
1424
|
+
d.textContent = description;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
enhance() {}
|
|
1428
|
+
}
|
|
1429
|
+
define("contour-gauge", ContourGauge);
|
|
1430
|
+
class ContourAxis extends ContourBase {
|
|
1431
|
+
static get observed() { return ["orientation", "values", "ticks", "format", "locale", "padding", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1432
|
+
static get properties() { return { orientation: { attribute: "orientation" }, values: { attribute: "values" }, ticks: { attribute: "ticks" }, format: { attribute: "format" }, locale: { attribute: "locale" }, padding: { attribute: "padding" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
|
|
1433
|
+
render() {
|
|
1434
|
+
this.classList.add("c-axis");
|
|
1435
|
+
const orientation = this.getAttribute("orientation") || "horizontal";
|
|
1436
|
+
this.classList.toggle("c-axis--horizontal", orientation === "horizontal");
|
|
1437
|
+
this.classList.toggle("c-axis--vertical", orientation === "vertical");
|
|
1438
|
+
if (orientation === "horizontal") this.setAttribute("part", "axis-x");
|
|
1439
|
+
else this.setAttribute("part", "axis-y");
|
|
1440
|
+
wireStates(this);
|
|
1441
|
+
loadRemote(this, ["values"]);
|
|
1442
|
+
if (renderStates(this, "axis")) return;
|
|
1443
|
+
// parse values
|
|
1444
|
+
let values = [];
|
|
1445
|
+
const vAttr = this.getAttribute("values");
|
|
1446
|
+
if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map((x) => x.trim()); } }
|
|
1447
|
+
const ticks = parseInt(this.getAttribute("ticks") || "0", 10) || values.length;
|
|
1448
|
+
// Slotted content support: authored .c-axis__tick children take
|
|
1449
|
+
// precedence over the JSON `values` attribute.
|
|
1450
|
+
const authoredTicks = Array.from(this.querySelectorAll(":scope > .c-axis__tick"));
|
|
1451
|
+
if (authoredTicks.length) {
|
|
1452
|
+
// keep authored ticks, just ensure labels are formatted
|
|
1453
|
+
authoredTicks.forEach((tick) => {
|
|
1454
|
+
const label = tick.querySelector(".c-axis__label");
|
|
1455
|
+
if (label && !label.textContent) label.textContent = tick.textContent;
|
|
1456
|
+
});
|
|
1457
|
+
} else {
|
|
1458
|
+
// clear
|
|
1459
|
+
Array.from(this.querySelectorAll(".c-axis__tick")).forEach((n) => n.remove());
|
|
1460
|
+
const list = values.length ? values : Array.from({ length: ticks }, (_, i) => i);
|
|
1461
|
+
list.forEach((v) => {
|
|
1462
|
+
const tick = document.createElement("span");
|
|
1463
|
+
tick.className = "c-axis__tick";
|
|
1464
|
+
const label = document.createElement("span");
|
|
1465
|
+
label.className = "c-axis__label";
|
|
1466
|
+
label.textContent = formatValue(String(v), this.getAttribute("format"), this.getAttribute("locale"));
|
|
1467
|
+
tick.appendChild(label);
|
|
1468
|
+
this.appendChild(tick);
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
enhance() {}
|
|
1473
|
+
}
|
|
1474
|
+
define("contour-axis", ContourAxis);
|
|
1475
|
+
class ContourBrush extends ContourBase {
|
|
1476
|
+
static get observed() { return ["start", "end", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1477
|
+
static get properties() { return { start: { attribute: "start" }, end: { attribute: "end" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
|
|
1478
|
+
render() {
|
|
1479
|
+
this.classList.add("c-brush");
|
|
1480
|
+
wireStates(this);
|
|
1481
|
+
loadRemote(this, []);
|
|
1482
|
+
if (renderStates(this, "brush")) return;
|
|
1483
|
+
let sel = this.querySelector(".c-brush__selection");
|
|
1484
|
+
if (!sel) { sel = document.createElement("div"); sel.className = "c-brush__selection"; this.appendChild(sel); }
|
|
1485
|
+
const start = parseFloat(this.getAttribute("start") || "0");
|
|
1486
|
+
const end = parseFloat(this.getAttribute("end") || "100");
|
|
1487
|
+
const min = parseFloat(this.getAttribute("min") || "0");
|
|
1488
|
+
const max = parseFloat(this.getAttribute("max") || "100");
|
|
1489
|
+
const range = max - min || 1;
|
|
1490
|
+
const left = ((start - min) / range) * 100;
|
|
1491
|
+
const width = ((end - start) / range) * 100;
|
|
1492
|
+
sel.style.insetInlineStart = left + "%";
|
|
1493
|
+
sel.style.inlineSize = width + "%";
|
|
1494
|
+
// handles
|
|
1495
|
+
["start","end"].forEach((h) => {
|
|
1496
|
+
let handle = this.querySelector(".c-brush__handle--" + h);
|
|
1497
|
+
if (!handle) { handle = document.createElement("div"); handle.className = "c-brush__handle c-brush__handle--" + h; this.appendChild(handle); }
|
|
1498
|
+
const val = h === "start" ? start : end;
|
|
1499
|
+
handle.style.insetInlineStart = (((val - min) / range) * 100) + "%";
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
enhance() {
|
|
1503
|
+
if (this._wiredBrush) return;
|
|
1504
|
+
this._wiredBrush = true;
|
|
1505
|
+
this.addEventListener("pointerdown", (e) => {
|
|
1506
|
+
this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: { value: this.getAttribute("start"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
|
|
1507
|
+
});
|
|
1508
|
+
this.addEventListener("pointerup", (e) => {
|
|
1509
|
+
this.dispatchEvent(new CustomEvent("contour:brush-end", { bubbles: true, composed: true, detail: { value: this.getAttribute("end"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
define("contour-brush", ContourBrush);
|
|
1514
|
+
class ContourStackedBar extends ContourBase {
|
|
1515
|
+
static get observed() { return ["segments", "values", "colors", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "normalize"]; }
|
|
1516
|
+
static get properties() { return { segments: { attribute: "segments" }, values: { attribute: "values" }, colors: { attribute: "colors" }, src: { attribute: "src" }, normalize: { attribute: "normalize" } }; }
|
|
1517
|
+
render() {
|
|
1518
|
+
this.classList.add("c-stacked-bar");
|
|
1519
|
+
wireStates(this);
|
|
1520
|
+
loadRemote(this, ["segments", "values"]);
|
|
1521
|
+
if (renderStates(this, "stacked-bar")) return;
|
|
1522
|
+
Array.from(this.querySelectorAll(".c-stacked-bar__segment")).forEach((n) => n.remove());
|
|
1523
|
+
// Slotted content support: authored .c-stacked-bar__segment children take
|
|
1524
|
+
// precedence over the JSON `segments` attribute.
|
|
1525
|
+
const authoredSegments = Array.from(this.querySelectorAll(":scope > .c-stacked-bar__segment"));
|
|
1526
|
+
let segments = [];
|
|
1527
|
+
if (authoredSegments.length) {
|
|
1528
|
+
segments = authoredSegments.map((el) => ({
|
|
1529
|
+
label: el.getAttribute("title") || el.textContent || "",
|
|
1530
|
+
value: parseFloat(el.style.inlineSize) || 0,
|
|
1531
|
+
color: el.style.background || undefined,
|
|
1532
|
+
}));
|
|
1533
|
+
authoredSegments.forEach((el) => el.remove());
|
|
1534
|
+
} else {
|
|
1535
|
+
const sAttr = this.getAttribute("segments");
|
|
1536
|
+
if (sAttr) { try { segments = JSON.parse(sAttr); } catch (e) { segments = []; } }
|
|
1537
|
+
}
|
|
1538
|
+
const values = segments.map((seg) => (typeof seg === "object" ? (seg.value || 0) : Number(seg) || 0));
|
|
1539
|
+
const total = values.reduce((a, b) => a + b, 0) || 1;
|
|
1540
|
+
const normalize = this.hasAttribute("normalize");
|
|
1541
|
+
const denom = normalize ? total : (parseFloat(this.getAttribute("max") || String(total)) || total);
|
|
1542
|
+
segments.forEach((seg, i) => {
|
|
1543
|
+
const v = values[i];
|
|
1544
|
+
const el = document.createElement("div");
|
|
1545
|
+
el.className = "c-stacked-bar__segment";
|
|
1546
|
+
el.style.inlineSize = ((v / denom) * 100) + "%";
|
|
1547
|
+
el.style.background = (typeof seg === "object" && seg.color) ? seg.color : "var(--chart-" + ((i % 8) + 1) + ")";
|
|
1548
|
+
el.setAttribute("title", (typeof seg === "object" ? (seg.label || "") : "") + " " + v);
|
|
1549
|
+
this.appendChild(el);
|
|
1550
|
+
});
|
|
1551
|
+
if (!segments.length) renderEmpty(this, "stacked-bar");
|
|
1552
|
+
}
|
|
1553
|
+
enhance() {}
|
|
1554
|
+
}
|
|
1555
|
+
define("contour-stacked-bar", ContourStackedBar);
|
|
1556
|
+
class ContourCategory extends ContourBase {
|
|
1557
|
+
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "search"]; }
|
|
1558
|
+
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, search: { attribute: "search" } }; }
|
|
1559
|
+
render() {
|
|
1560
|
+
this.classList.add("c-category");
|
|
1561
|
+
this.setAttribute("role", "listbox");
|
|
1562
|
+
wireStates(this);
|
|
1563
|
+
loadRemote(this, ["items"]);
|
|
1564
|
+
if (renderStates(this, "category")) return;
|
|
1565
|
+
Array.from(this.querySelectorAll(".c-category__item")).forEach((n) => n.remove());
|
|
1566
|
+
// Slotted content support: authored .c-category__item children take
|
|
1567
|
+
// precedence over the JSON `items` attribute.
|
|
1568
|
+
const authoredItems = Array.from(this.querySelectorAll(":scope > .c-category__item"));
|
|
1569
|
+
let items = [];
|
|
1570
|
+
if (authoredItems.length) {
|
|
1571
|
+
authoredItems.forEach((el) => {
|
|
1572
|
+
const lbl = el.querySelector(".c-category__label");
|
|
1573
|
+
items.push({ label: lbl ? lbl.textContent : el.textContent, value: 0 });
|
|
1574
|
+
});
|
|
1575
|
+
authoredItems.forEach((el) => el.remove());
|
|
1576
|
+
} else {
|
|
1577
|
+
const iAttr = this.getAttribute("items");
|
|
1578
|
+
if (iAttr) { try { items = JSON.parse(iAttr); } catch (e) { items = []; } }
|
|
1579
|
+
}
|
|
1580
|
+
const max = items.reduce((m, it) => Math.max(m, (typeof it === "object" ? (it.value || 0) : Number(it) || 0)), 0) || 1;
|
|
1581
|
+
items.forEach((it, idx) => {
|
|
1582
|
+
const value = (typeof it === "object") ? (it.value || 0) : (Number(it) || 0);
|
|
1583
|
+
const label = (typeof it === "object") ? (it.label || it.name || "") : String(it);
|
|
1584
|
+
const item = document.createElement("div");
|
|
1585
|
+
item.className = "c-category__item";
|
|
1586
|
+
item.setAttribute("role", "option");
|
|
1587
|
+
item.setAttribute("aria-selected", "false");
|
|
1588
|
+
const lbl = document.createElement("span");
|
|
1589
|
+
lbl.className = "c-category__label";
|
|
1590
|
+
lbl.textContent = label;
|
|
1591
|
+
const barWrap = document.createElement("div");
|
|
1592
|
+
barWrap.style.flex = "1";
|
|
1593
|
+
const bar = document.createElement("div");
|
|
1594
|
+
bar.className = "c-category__bar";
|
|
1595
|
+
bar.style.inlineSize = ((value / max) * 100) + "%";
|
|
1596
|
+
barWrap.appendChild(bar);
|
|
1597
|
+
const val = document.createElement("span");
|
|
1598
|
+
val.className = "c-category__value";
|
|
1599
|
+
val.textContent = String(value);
|
|
1600
|
+
item.appendChild(lbl);
|
|
1601
|
+
item.appendChild(barWrap);
|
|
1602
|
+
item.appendChild(val);
|
|
1603
|
+
this.appendChild(item);
|
|
1604
|
+
});
|
|
1605
|
+
if (!items.length) renderEmpty(this, "category");
|
|
1606
|
+
}
|
|
1607
|
+
enhance() {}
|
|
1608
|
+
}
|
|
1609
|
+
define("contour-category", ContourCategory);
|
|
1610
|
+
class ContourDonut extends ContourBase {
|
|
1611
|
+
static get observed() { return ["value", "values", "items", "label", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level"]; }
|
|
1612
|
+
static get properties() { return { value: { attribute: "value" }, values: { attribute: "values" }, items: { attribute: "items" }, label: { attribute: "label" }, src: { attribute: "src" } }; }
|
|
1613
|
+
render() {
|
|
1614
|
+
this.classList.add("c-donut");
|
|
1615
|
+
wireStates(this);
|
|
1616
|
+
loadRemote(this, ["items", "values"]);
|
|
1617
|
+
if (renderStates(this, "donut")) return;
|
|
1618
|
+
Array.from(this.querySelectorAll(".c-donut__ring, .c-donut__center, .c-donut__list, .c-donut__empty")).forEach((n) => n.remove());
|
|
1619
|
+
// Slotted content support: authored .c-donut__item children take precedence
|
|
1620
|
+
// over the JSON `items` attribute, so consumers can compose legend rows
|
|
1621
|
+
// by hand instead of serialising them into an attribute.
|
|
1622
|
+
const authoredItems = Array.from(this.querySelectorAll(":scope > .c-donut__item"));
|
|
1623
|
+
let items = [];
|
|
1624
|
+
if (authoredItems.length) {
|
|
1625
|
+
authoredItems.forEach((el) => {
|
|
1626
|
+
const sw = el.querySelector(".c-donut__swatch");
|
|
1627
|
+
const lbl = el.querySelector("span:last-child");
|
|
1628
|
+
const text = lbl ? lbl.textContent : el.textContent;
|
|
1629
|
+
const match = text.match(/—\s*(\d+(?:\.\d+)?)$/);
|
|
1630
|
+
items.push({ label: text.replace(/—\s*\d+(?:\.\d+)?$/, "").trim(), value: match ? Number(match[1]) : 0, color: sw ? sw.style.background : undefined });
|
|
1631
|
+
});
|
|
1632
|
+
// remove authored items from DOM (they will be regenerated below)
|
|
1633
|
+
authoredItems.forEach((el) => el.remove());
|
|
1634
|
+
} else {
|
|
1635
|
+
const iAttr = this.getAttribute("items");
|
|
1636
|
+
if (iAttr) { try { items = JSON.parse(iAttr); } catch (e) { items = []; } }
|
|
1637
|
+
}
|
|
1638
|
+
const values = items.map((it) => (typeof it === "object" ? (it.value || 0) : Number(it) || 0));
|
|
1639
|
+
const total = values.reduce((a, b) => a + b, 0) || 1;
|
|
1640
|
+
const brownoutLevel = parseInt(this.getAttribute("brownout-level") || this.getAttribute("brownout") || "0", 10) || 0;
|
|
1641
|
+
const shedRing = brownoutLevel >= 3;
|
|
1642
|
+
if (!shedRing) {
|
|
1643
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1644
|
+
svg.setAttribute("class", "c-donut__ring");
|
|
1645
|
+
svg.setAttribute("viewBox", "0 0 32 32");
|
|
1646
|
+
let offset = 0;
|
|
1647
|
+
items.forEach((it, i) => {
|
|
1648
|
+
const v = values[i];
|
|
1649
|
+
const pct = v / total;
|
|
1650
|
+
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
1651
|
+
circle.setAttribute("cx", "16"); circle.setAttribute("cy", "16"); circle.setAttribute("r", "12");
|
|
1652
|
+
circle.setAttribute("fill", "none");
|
|
1653
|
+
circle.setAttribute("stroke", (typeof it === "object" && it.color) ? it.color : "var(--chart-" + ((i % 8) + 1) + ")");
|
|
1654
|
+
circle.setAttribute("stroke-width", "6");
|
|
1655
|
+
const circ = 2 * Math.PI * 12;
|
|
1656
|
+
circle.setAttribute("stroke-dasharray", (pct * circ) + " " + (circ - pct * circ));
|
|
1657
|
+
circle.setAttribute("stroke-dashoffset", String(-offset * circ));
|
|
1658
|
+
circle.setAttribute("transform", "rotate(-90 16 16)");
|
|
1659
|
+
svg.appendChild(circle);
|
|
1660
|
+
offset += pct;
|
|
1661
|
+
});
|
|
1662
|
+
// center hole
|
|
1663
|
+
const hole = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
1664
|
+
hole.setAttribute("cx", "16"); hole.setAttribute("cy", "16"); hole.setAttribute("r", "9");
|
|
1665
|
+
hole.setAttribute("fill", "var(--color-surface-0)");
|
|
1666
|
+
svg.appendChild(hole);
|
|
1667
|
+
this.appendChild(svg);
|
|
1668
|
+
}
|
|
1669
|
+
const center = document.createElement("div");
|
|
1670
|
+
center.className = "c-donut__center";
|
|
1671
|
+
center.textContent = this.getAttribute("value") || String(total);
|
|
1672
|
+
this.appendChild(center);
|
|
1673
|
+
// text list
|
|
1674
|
+
const list = document.createElement("div");
|
|
1675
|
+
list.className = "c-donut__list";
|
|
1676
|
+
items.forEach((it, i) => {
|
|
1677
|
+
const row = document.createElement("div");
|
|
1678
|
+
row.className = "c-donut__item";
|
|
1679
|
+
const sw = document.createElement("span");
|
|
1680
|
+
sw.className = "c-donut__swatch";
|
|
1681
|
+
sw.style.background = (typeof it === "object" && it.color) ? it.color : "var(--chart-" + ((i % 8) + 1) + ")";
|
|
1682
|
+
row.appendChild(sw);
|
|
1683
|
+
const lbl = document.createElement("span");
|
|
1684
|
+
lbl.textContent = (typeof it === "object" ? (it.label || "") : String(it)) + " — " + values[i];
|
|
1685
|
+
row.appendChild(lbl);
|
|
1686
|
+
list.appendChild(row);
|
|
1687
|
+
});
|
|
1688
|
+
this.appendChild(list);
|
|
1689
|
+
if (!items.length) renderEmpty(this, "donut");
|
|
1690
|
+
}
|
|
1691
|
+
enhance() {}
|
|
1692
|
+
}
|
|
1693
|
+
define("contour-donut", ContourDonut);
|
|
1694
|
+
class ContourTimeSeries extends ContourBase {
|
|
1695
|
+
static get observed() { return ["values", "points", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "annotations"]; }
|
|
1696
|
+
static get properties() { return { values: { attribute: "values" }, points: { attribute: "points" }, src: { attribute: "src" }, annotations: { attribute: "annotations" } }; }
|
|
1697
|
+
render() {
|
|
1698
|
+
this.classList.add("c-time-series");
|
|
1699
|
+
wireStates(this);
|
|
1700
|
+
loadRemote(this, ["values", "points"]);
|
|
1701
|
+
if (renderStates(this, "time-series")) return;
|
|
1702
|
+
Array.from(this.querySelectorAll(".c-time-series__plot, .c-time-series__axis")).forEach((n) => n.remove());
|
|
1703
|
+
let values = [];
|
|
1704
|
+
const vAttr = this.getAttribute("values");
|
|
1705
|
+
if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map(Number); } }
|
|
1706
|
+
const max = Math.max(...values, 1);
|
|
1707
|
+
const plot = document.createElement("div");
|
|
1708
|
+
plot.className = "c-time-series__plot";
|
|
1709
|
+
plot.setAttribute("part", "plot");
|
|
1710
|
+
values.forEach((v) => {
|
|
1711
|
+
const bar = document.createElement("div");
|
|
1712
|
+
bar.className = "c-time-series__bar";
|
|
1713
|
+
bar.style.blockSize = ((v / max) * 100) + "%";
|
|
1714
|
+
bar.setAttribute("title", String(v));
|
|
1715
|
+
plot.appendChild(bar);
|
|
1716
|
+
});
|
|
1717
|
+
this.appendChild(plot);
|
|
1718
|
+
if (!values.length) renderEmpty(this, "time-series");
|
|
1719
|
+
}
|
|
1720
|
+
enhance() {}
|
|
1721
|
+
}
|
|
1722
|
+
define("contour-time-series", ContourTimeSeries);
|
|
1723
|
+
class ContourPivot extends ContourBase {
|
|
1724
|
+
static get observed() { return ["rows", "columns", "values", "data", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1725
|
+
static get properties() { return { rows: { attribute: "rows" }, columns: { attribute: "columns" }, values: { attribute: "values" }, data: { attribute: "data" }, src: { attribute: "src" } }; }
|
|
1726
|
+
render() {
|
|
1727
|
+
this.classList.add("c-pivot");
|
|
1728
|
+
wireStates(this);
|
|
1729
|
+
loadRemote(this, ["data"]);
|
|
1730
|
+
if (renderStates(this, "pivot")) return;
|
|
1731
|
+
Array.from(this.querySelectorAll("table")).forEach((n) => n.remove());
|
|
1732
|
+
let data = [];
|
|
1733
|
+
const dAttr = this.getAttribute("data");
|
|
1734
|
+
if (dAttr) { try { data = JSON.parse(dAttr); } catch (e) { data = []; } }
|
|
1735
|
+
const rows = this.getAttribute("rows") ? this.getAttribute("rows").split(",") : [];
|
|
1736
|
+
const cols = this.getAttribute("columns") ? this.getAttribute("columns").split(",") : [];
|
|
1737
|
+
const table = document.createElement("table");
|
|
1738
|
+
const thead = document.createElement("thead");
|
|
1739
|
+
const hr = document.createElement("tr");
|
|
1740
|
+
const corner = document.createElement("th");
|
|
1741
|
+
corner.textContent = "";
|
|
1742
|
+
hr.appendChild(corner);
|
|
1743
|
+
cols.forEach((c) => { const th = document.createElement("th"); th.textContent = c.trim(); hr.appendChild(th); });
|
|
1744
|
+
thead.appendChild(hr);
|
|
1745
|
+
table.appendChild(thead);
|
|
1746
|
+
const tbody = document.createElement("tbody");
|
|
1747
|
+
rows.forEach((r) => {
|
|
1748
|
+
const tr = document.createElement("tr");
|
|
1749
|
+
const th = document.createElement("th");
|
|
1750
|
+
th.textContent = r.trim();
|
|
1751
|
+
tr.appendChild(th);
|
|
1752
|
+
cols.forEach((c) => {
|
|
1753
|
+
const td = document.createElement("td");
|
|
1754
|
+
const cell = data.find((d) => d.row === r.trim() && d.col === c.trim());
|
|
1755
|
+
td.textContent = cell ? String(cell.value) : "";
|
|
1756
|
+
tr.appendChild(td);
|
|
1757
|
+
});
|
|
1758
|
+
tbody.appendChild(tr);
|
|
1759
|
+
});
|
|
1760
|
+
table.appendChild(tbody);
|
|
1761
|
+
this.appendChild(table);
|
|
1762
|
+
if (!data.length && !rows.length) renderEmpty(this, "pivot");
|
|
1763
|
+
}
|
|
1764
|
+
enhance() {}
|
|
1765
|
+
}
|
|
1766
|
+
define("contour-pivot", ContourPivot);
|
|
1767
|
+
class ContourWidgetState extends ContourBase {
|
|
1768
|
+
static get observed() { return ["loading", "error", "empty", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1769
|
+
static get properties() { return { loading: { attribute: "loading" }, error: { attribute: "error" }, empty: { attribute: "empty" }, retry: { attribute: "retry" }, src: { attribute: "src" } }; }
|
|
1770
|
+
render() {
|
|
1771
|
+
this.classList.add("c-widget-state");
|
|
1772
|
+
wireStates(this);
|
|
1773
|
+
loadRemote(this, []);
|
|
1774
|
+
if (renderStates(this, "widget-state")) return;
|
|
1775
|
+
// if no state, render slotted content (already in DOM)
|
|
1776
|
+
}
|
|
1777
|
+
enhance() {}
|
|
1778
|
+
}
|
|
1779
|
+
define("contour-widget-state", ContourWidgetState);
|
|
1780
|
+
class ContourBrownout extends ContourBase {
|
|
1781
|
+
static get observed() { return ["level"]; }
|
|
1782
|
+
static get properties() { return { level: { attribute: "level" } }; }
|
|
1783
|
+
render() {
|
|
1784
|
+
this.classList.add("c-brownout");
|
|
1785
|
+
const level = this.getAttribute("level") || "0";
|
|
1786
|
+
this.dataset.level = level;
|
|
1787
|
+
this.setAttribute("data-level", level);
|
|
1788
|
+
}
|
|
1789
|
+
enhance() {}
|
|
1790
|
+
}
|
|
1791
|
+
define("contour-brownout", ContourBrownout);
|
|
1244
1792
|
class ContourInstrument extends ContourBase {
|
|
1245
1793
|
static get observed() { return ["rows", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1246
1794
|
static get properties() { return { rows: { attribute: "rows" }, src: { attribute: "src" } }; }
|
|
@@ -1275,21 +1823,31 @@ class ContourInstrument extends ContourBase {
|
|
|
1275
1823
|
}
|
|
1276
1824
|
define("contour-instrument", ContourInstrument);
|
|
1277
1825
|
class ContourBivariate extends ContourBase {
|
|
1278
|
-
static get observed() { return ["size", "axis-x", "axis-y"]; }
|
|
1279
|
-
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" } }; }
|
|
1826
|
+
static get observed() { return ["size", "axis-x", "axis-y", "colors"]; }
|
|
1827
|
+
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" } }; }
|
|
1280
1828
|
render() {
|
|
1281
1829
|
this.classList.add("c-bivariate");
|
|
1282
1830
|
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
1283
1831
|
const matrix = this.ensure(".c-bivariate__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate__matrix"; return el; });
|
|
1284
1832
|
matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
|
|
1833
|
+
matrix.style.gridTemplateRows = `repeat(${size}, 1fr)`;
|
|
1285
1834
|
// Slot composition: authored cells win over the generated grid.
|
|
1286
1835
|
const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains("c-bivariate__cell"));
|
|
1287
1836
|
if (!authored.length) {
|
|
1288
1837
|
matrix.innerHTML = "";
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1838
|
+
let colors = [];
|
|
1839
|
+
const cAttr = this.getAttribute("colors");
|
|
1840
|
+
if (cAttr) { try { colors = JSON.parse(cAttr); } catch (e) { colors = []; } }
|
|
1841
|
+
for (let r = 0; r < size; r++) {
|
|
1842
|
+
for (let c = 0; c < size; c++) {
|
|
1843
|
+
const cell = document.createElement("div");
|
|
1844
|
+
cell.className = "c-bivariate__cell";
|
|
1845
|
+
// Palette runs from bottom-left (low/low) to top-right (high/high):
|
|
1846
|
+
// reverse the row order so the first palette row sits at the bottom.
|
|
1847
|
+
const srcIndex = (size - 1 - r) * size + c;
|
|
1848
|
+
if (colors[srcIndex]) cell.style.background = colors[srcIndex];
|
|
1849
|
+
matrix.appendChild(cell);
|
|
1850
|
+
}
|
|
1293
1851
|
}
|
|
1294
1852
|
}
|
|
1295
1853
|
const axisX = this.getAttribute("axis-x");
|
|
@@ -1311,6 +1869,49 @@ class ContourBivariate extends ContourBase {
|
|
|
1311
1869
|
}
|
|
1312
1870
|
}
|
|
1313
1871
|
define("contour-bivariate", ContourBivariate);
|
|
1872
|
+
class ContourBivariateLegend extends ContourBase {
|
|
1873
|
+
static get observed() { return ["size", "axis-x", "axis-y", "colors"]; }
|
|
1874
|
+
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" } }; }
|
|
1875
|
+
render() {
|
|
1876
|
+
this.classList.add("c-bivariate-legend");
|
|
1877
|
+
const size = Math.min(8, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
1878
|
+
const matrix = this.ensure(".c-bivariate-legend__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate-legend__matrix"; return el; });
|
|
1879
|
+
matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
|
|
1880
|
+
// Slotted content support: authored cells win over the generated grid.
|
|
1881
|
+
const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains("c-bivariate-legend__cell"));
|
|
1882
|
+
if (!authored.length) {
|
|
1883
|
+
matrix.innerHTML = "";
|
|
1884
|
+
let colors = [];
|
|
1885
|
+
const cAttr = this.getAttribute("colors");
|
|
1886
|
+
if (cAttr) { try { colors = JSON.parse(cAttr); } catch (e) { colors = []; } }
|
|
1887
|
+
for (let i = 0; i < size * size; i++) {
|
|
1888
|
+
const cell = document.createElement("div");
|
|
1889
|
+
cell.className = "c-bivariate-legend__cell";
|
|
1890
|
+
if (colors[i]) cell.style.background = colors[i];
|
|
1891
|
+
else cell.style.background = "var(--chart-" + ((i % 8) + 1) + ")";
|
|
1892
|
+
matrix.appendChild(cell);
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
const axisX = this.getAttribute("axis-x");
|
|
1896
|
+
const ax = this.querySelector(".c-bivariate-legend__axis--x");
|
|
1897
|
+
if (axisX) {
|
|
1898
|
+
const el = ax || this.ensure(".c-bivariate-legend__axis--x", () => { const e = document.createElement("div"); e.className = "c-bivariate-legend__axis c-bivariate-legend__axis--x"; return e; });
|
|
1899
|
+
el.textContent = axisX;
|
|
1900
|
+
} else if (ax) {
|
|
1901
|
+
ax.remove();
|
|
1902
|
+
}
|
|
1903
|
+
const axisY = this.getAttribute("axis-y");
|
|
1904
|
+
const ay = this.querySelector(".c-bivariate-legend__axis--y");
|
|
1905
|
+
if (axisY) {
|
|
1906
|
+
const el = ay || this.ensure(".c-bivariate-legend__axis--y", () => { const e = document.createElement("div"); e.className = "c-bivariate-legend__axis c-bivariate-legend__axis--y"; return e; });
|
|
1907
|
+
el.textContent = axisY;
|
|
1908
|
+
} else if (ay) {
|
|
1909
|
+
ay.remove();
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
enhance() {}
|
|
1913
|
+
}
|
|
1914
|
+
define("contour-bivariate-legend", ContourBivariateLegend);
|
|
1314
1915
|
class ContourSurvey extends ContourBase {
|
|
1315
1916
|
static get observed() { return ["date", "instrument", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1316
1917
|
static get properties() { return { date: { attribute: "date" }, instrument: { attribute: "instrument" }, src: { attribute: "src" } }; }
|
|
@@ -1420,7 +2021,7 @@ class ContourMetricsFull extends ContourBase {
|
|
|
1420
2021
|
}
|
|
1421
2022
|
define("contour-metrics", ContourMetricsFull);
|
|
1422
2023
|
class ContourLegend extends ContourBase {
|
|
1423
|
-
static get observed() { return ["title", "ramp", "scale", "items", "method", "norm", "selectable", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
2024
|
+
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"]; }
|
|
1424
2025
|
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" } }; }
|
|
1425
2026
|
render() {
|
|
1426
2027
|
this.classList.add("c-legend");
|
|
@@ -1459,9 +2060,38 @@ class ContourLegend extends ContourBase {
|
|
|
1459
2060
|
sw.className = "c-legend__swatch";
|
|
1460
2061
|
if (it && it.color) sw.style.background = it.color;
|
|
1461
2062
|
item.appendChild(sw);
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
2063
|
+
// geometry glyph
|
|
2064
|
+
const glyphShape = (it && (it.shape || it.marker || it.glyph)) || this.getAttribute("glyphs");
|
|
2065
|
+
if (glyphShape) {
|
|
2066
|
+
const g = document.createElement("span");
|
|
2067
|
+
g.className = "c-legend__glyph";
|
|
2068
|
+
g.setAttribute("part", "glyph");
|
|
2069
|
+
g.textContent = glyphShape === "circle" ? "●" : glyphShape === "square" ? "■" : glyphShape === "triangle" ? "▲" : glyphShape === "diamond" ? "◆" : glyphShape === "star" ? "★" : String(glyphShape);
|
|
2070
|
+
if (it && it.size != null) g.style.fontSize = (typeof it.size === "number" ? it.size + "px" : String(it.size));
|
|
2071
|
+
item.appendChild(g);
|
|
2072
|
+
}
|
|
2073
|
+
// threshold break marker
|
|
2074
|
+
if (it && it.break != null) {
|
|
2075
|
+
const b = document.createElement("span");
|
|
2076
|
+
b.className = "c-legend__break";
|
|
2077
|
+
b.textContent = String(it.break);
|
|
2078
|
+
item.appendChild(b);
|
|
2079
|
+
}
|
|
2080
|
+
const lbl = document.createElement("span");
|
|
2081
|
+
lbl.textContent = label;
|
|
2082
|
+
item.appendChild(lbl);
|
|
2083
|
+
// caption (source-and-method line)
|
|
2084
|
+
const caption = (typeof it === "object" && it) ? (it.caption || it.note || "") : "";
|
|
2085
|
+
if (caption) {
|
|
2086
|
+
const cap = document.createElement("span");
|
|
2087
|
+
cap.className = "c-legend__caption";
|
|
2088
|
+
cap.textContent = caption;
|
|
2089
|
+
item.appendChild(cap);
|
|
2090
|
+
}
|
|
2091
|
+
// threshold mark: outline on swatches that begin at a threshold
|
|
2092
|
+
if (it && (it.threshold || it.break != null)) {
|
|
2093
|
+
sw.style.outline = "2px solid var(--color-border-strong)";
|
|
2094
|
+
}
|
|
1465
2095
|
list.appendChild(item);
|
|
1466
2096
|
});
|
|
1467
2097
|
} catch (e) { /* keep existing */ }
|
|
@@ -1473,7 +2103,79 @@ class ContourLegend extends ContourBase {
|
|
|
1473
2103
|
renderEmpty(this, "legend");
|
|
1474
2104
|
}
|
|
1475
2105
|
}
|
|
1476
|
-
|
|
2106
|
+
// audit notice
|
|
2107
|
+
const audit = this.getAttribute("audit");
|
|
2108
|
+
if (audit) {
|
|
2109
|
+
const a = this.ensure(".c-legend__audit", () => { const el = document.createElement("div"); el.className = "c-legend__audit"; return el; });
|
|
2110
|
+
a.textContent = audit;
|
|
2111
|
+
} else {
|
|
2112
|
+
const a = this.querySelector(".c-legend__audit");
|
|
2113
|
+
if (a) a.remove();
|
|
2114
|
+
}
|
|
2115
|
+
// continuous variant: ramp with two ends labelled
|
|
2116
|
+
if (this.hasAttribute("continuous")) {
|
|
2117
|
+
const ends = this.getAttribute("ends");
|
|
2118
|
+
let parsedEnds = null;
|
|
2119
|
+
if (ends) { try { parsedEnds = JSON.parse(ends); } catch (e) { parsedEnds = ends.split(","); } }
|
|
2120
|
+
if (Array.isArray(parsedEnds) && parsedEnds.length >= 2) {
|
|
2121
|
+
const r = this.ensure(".c-legend__ramp", () => { const el = document.createElement("div"); el.className = "c-legend__ramp"; return el; });
|
|
2122
|
+
// labels
|
|
2123
|
+
let left = this.querySelector(".c-legend__ramp-label--start");
|
|
2124
|
+
if (!left) { left = document.createElement("span"); left.className = "c-legend__ramp-label c-legend__ramp-label--start"; r.appendChild(left); }
|
|
2125
|
+
left.textContent = parsedEnds[0];
|
|
2126
|
+
let right = this.querySelector(".c-legend__ramp-label--end");
|
|
2127
|
+
if (!right) { right = document.createElement("span"); right.className = "c-legend__ramp-label c-legend__ramp-label--end"; r.appendChild(right); }
|
|
2128
|
+
right.textContent = parsedEnds[parsedEnds.length - 1];
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
// size variant: differently-sized glyphs
|
|
2132
|
+
const sizeAttr = this.getAttribute("size");
|
|
2133
|
+
if (sizeAttr) {
|
|
2134
|
+
const sc = this.ensure(".c-legend__size", () => { const el = document.createElement("div"); el.className = "c-legend__size"; return el; });
|
|
2135
|
+
sc.textContent = sizeAttr;
|
|
2136
|
+
} else {
|
|
2137
|
+
const sc = this.querySelector(".c-legend__size");
|
|
2138
|
+
if (sc) sc.remove();
|
|
2139
|
+
}
|
|
2140
|
+
// classification line
|
|
2141
|
+
const classification = this.getAttribute("classification");
|
|
2142
|
+
if (classification) {
|
|
2143
|
+
const c = this.ensure(".c-legend__classification", () => { const el = document.createElement("div"); el.className = "c-legend__classification"; return el; });
|
|
2144
|
+
c.textContent = classification;
|
|
2145
|
+
} else {
|
|
2146
|
+
const c = this.querySelector(".c-legend__classification");
|
|
2147
|
+
if (c) c.remove();
|
|
2148
|
+
}
|
|
2149
|
+
// data table (collapsible)
|
|
2150
|
+
const tableAttr = this.getAttribute("table");
|
|
2151
|
+
if (tableAttr) {
|
|
2152
|
+
let parsed = null;
|
|
2153
|
+
try { parsed = JSON.parse(tableAttr); } catch (e) { parsed = null; }
|
|
2154
|
+
if (Array.isArray(parsed)) {
|
|
2155
|
+
let det = this.querySelector(".c-legend__table-wrap");
|
|
2156
|
+
if (!det) { det = document.createElement("details"); det.className = "c-legend__table-wrap"; this.appendChild(det); }
|
|
2157
|
+
det.innerHTML = "";
|
|
2158
|
+
const sum = document.createElement("summary"); sum.textContent = "Data table"; det.appendChild(sum);
|
|
2159
|
+
const tbl = document.createElement("table"); tbl.className = "c-legend__table";
|
|
2160
|
+
const tbody = document.createElement("tbody");
|
|
2161
|
+
parsed.forEach((row) => {
|
|
2162
|
+
const tr = document.createElement("tr");
|
|
2163
|
+
const cells = Array.isArray(row) ? row : [row.label ?? row.key ?? "", row.value ?? ""];
|
|
2164
|
+
cells.forEach((cell) => { const td = document.createElement("td"); td.textContent = cell; tr.appendChild(td); });
|
|
2165
|
+
tbody.appendChild(tr);
|
|
2166
|
+
});
|
|
2167
|
+
tbl.appendChild(tbody);
|
|
2168
|
+
det.appendChild(tbl);
|
|
2169
|
+
}
|
|
2170
|
+
} else {
|
|
2171
|
+
const det = this.querySelector(".c-legend__table-wrap");
|
|
2172
|
+
if (det) det.remove();
|
|
2173
|
+
}
|
|
2174
|
+
// size variant on glyphs
|
|
2175
|
+
if (items) {
|
|
2176
|
+
// apply size to glyphs already rendered? handled below via re-render not needed
|
|
2177
|
+
}
|
|
2178
|
+
const method = this.getAttribute("method");
|
|
1477
2179
|
if (method) {
|
|
1478
2180
|
const m = this.ensure(".c-legend__method", () => { const el = document.createElement("div"); el.className = "c-legend__method"; return el; });
|
|
1479
2181
|
m.textContent = method;
|
|
@@ -1489,14 +2191,34 @@ class ContourLegend extends ContourBase {
|
|
|
1489
2191
|
const n = this.querySelector(".c-legend__norm");
|
|
1490
2192
|
if (n) n.remove();
|
|
1491
2193
|
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
2194
|
+
const ramp = this.getAttribute("ramp");
|
|
2195
|
+
if (ramp) {
|
|
2196
|
+
const r = this.ensure(".c-legend__ramp", () => { const el = document.createElement("div"); el.className = "c-legend__ramp"; return el; });
|
|
2197
|
+
r.style.background = ramp;
|
|
2198
|
+
// ramp routing: equal-width segments with break labels
|
|
2199
|
+
const breaksAttr = this.getAttribute("breaks");
|
|
2200
|
+
if (breaksAttr) {
|
|
2201
|
+
let breaks = null;
|
|
2202
|
+
try { breaks = JSON.parse(breaksAttr); } catch (e) { breaks = breaksAttr.split(",").map((s) => s.trim()); }
|
|
2203
|
+
if (Array.isArray(breaks)) {
|
|
2204
|
+
// remove old segments
|
|
2205
|
+
Array.from(r.querySelectorAll(".c-legend__ramp-segment")).forEach((n) => n.remove());
|
|
2206
|
+
breaks.forEach((b, i) => {
|
|
2207
|
+
const seg = document.createElement("span");
|
|
2208
|
+
seg.className = "c-legend__ramp-segment";
|
|
2209
|
+
seg.style.flex = "1";
|
|
2210
|
+
const lbl = document.createElement("span");
|
|
2211
|
+
lbl.className = "c-legend__ramp-break";
|
|
2212
|
+
lbl.textContent = String(b);
|
|
2213
|
+
seg.appendChild(lbl);
|
|
2214
|
+
r.appendChild(seg);
|
|
2215
|
+
});
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
} else {
|
|
2219
|
+
const r = this.querySelector(".c-legend__ramp");
|
|
2220
|
+
if (r) r.remove();
|
|
2221
|
+
}
|
|
1500
2222
|
const scale = this.getAttribute("scale");
|
|
1501
2223
|
if (scale) {
|
|
1502
2224
|
const sc = this.ensure(".c-legend__scale", () => { const el = document.createElement("div"); el.className = "c-legend__scale"; return el; });
|
|
@@ -1509,10 +2231,6 @@ class ContourLegend extends ContourBase {
|
|
|
1509
2231
|
enhance() {
|
|
1510
2232
|
if (this._wiredLegend) return;
|
|
1511
2233
|
this._wiredLegend = true;
|
|
1512
|
-
// Host-delegated (rule 12): the item buttons are rebuilt by every
|
|
1513
|
-
// render, so the handler re-queries per click. The gate-visible name is
|
|
1514
|
-
// `contour:legend-toggle` — the plan's `contour:legend:toggle` carries a
|
|
1515
|
-
// colon inside the name, which the check-wc manifest regex cannot see.
|
|
1516
2234
|
this.addEventListener("click", (e) => {
|
|
1517
2235
|
const btn = e.target && e.target.closest ? e.target.closest(".c-legend__item") : null;
|
|
1518
2236
|
if (!btn || !this.contains(btn)) return;
|
|
@@ -1523,6 +2241,44 @@ class ContourLegend extends ContourBase {
|
|
|
1523
2241
|
bubbles: true,
|
|
1524
2242
|
composed: true,
|
|
1525
2243
|
}));
|
|
2244
|
+
this.dispatchEvent(new CustomEvent("contour:select", {
|
|
2245
|
+
detail: { label: btn.textContent.trim(), key: btn.dataset.key || btn.textContent.trim(), value: btn.dataset.key || btn.textContent.trim() },
|
|
2246
|
+
bubbles: true,
|
|
2247
|
+
composed: true,
|
|
2248
|
+
}));
|
|
2249
|
+
});
|
|
2250
|
+
// emit style-resolved once on enhance
|
|
2251
|
+
try {
|
|
2252
|
+
let parsed = null;
|
|
2253
|
+
try { parsed = JSON.parse(this.getAttribute("items") || "null"); } catch (e) { parsed = this.getAttribute("items"); }
|
|
2254
|
+
this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: this.getAttribute("items"), items: parsed }, bubbles: true, composed: true }));
|
|
2255
|
+
} catch (e) {}
|
|
2256
|
+
// break-change delegated
|
|
2257
|
+
this.addEventListener("change", (e) => {
|
|
2258
|
+
const t = e.target;
|
|
2259
|
+
if (t && t.classList && t.classList.contains("c-legend__break-input")) {
|
|
2260
|
+
this.dispatchEvent(new CustomEvent("contour:break-change", { detail: { value: t.value }, bubbles: true, composed: true }));
|
|
2261
|
+
}
|
|
2262
|
+
});
|
|
2263
|
+
// keyboard nav (listbox)
|
|
2264
|
+
this.addEventListener("keydown", (e) => {
|
|
2265
|
+
const items = Array.from(this.querySelectorAll(".c-legend__item"));
|
|
2266
|
+
if (!items.length) return;
|
|
2267
|
+
const idx = items.indexOf(document.activeElement);
|
|
2268
|
+
if (e.key === "ArrowDown" || e.key === "ArrowRight") {
|
|
2269
|
+
e.preventDefault();
|
|
2270
|
+
const next = items[(idx + 1) % items.length];
|
|
2271
|
+
if (next) next.focus();
|
|
2272
|
+
} else if (e.key === "ArrowUp" || e.key === "ArrowLeft") {
|
|
2273
|
+
e.preventDefault();
|
|
2274
|
+
const prev = items[(idx - 1 + items.length) % items.length];
|
|
2275
|
+
if (prev) prev.focus();
|
|
2276
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
2277
|
+
e.preventDefault();
|
|
2278
|
+
if (document.activeElement && document.activeElement.classList.contains("c-legend__item")) {
|
|
2279
|
+
document.activeElement.click();
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
1526
2282
|
});
|
|
1527
2283
|
}
|
|
1528
2284
|
}
|
|
@@ -1557,6 +2313,12 @@ class ContourMeasure extends ContourBase {
|
|
|
1557
2313
|
const r = this.querySelector(".c-measure__readout");
|
|
1558
2314
|
if (r) r.remove();
|
|
1559
2315
|
}
|
|
2316
|
+
// unit selector
|
|
2317
|
+
let sel = this.querySelector(".c-measure__unit-select");
|
|
2318
|
+
if (!sel) { sel = document.createElement("select"); sel.className = "c-measure__unit-select"; this.appendChild(sel); }
|
|
2319
|
+
["m","km","mi","ft"].forEach((u) => {
|
|
2320
|
+
if (!sel.querySelector('option[value="' + u + '"]')) { const o = document.createElement("option"); o.value = u; o.textContent = u; sel.appendChild(o); }
|
|
2321
|
+
});
|
|
1560
2322
|
if (rPoint) {
|
|
1561
2323
|
const p = this.ensure(".c-measure__point", () => { const el = document.createElement("span"); el.className = "c-measure__point"; return el; });
|
|
1562
2324
|
p.textContent = rPoint;
|
|
@@ -1636,12 +2398,20 @@ class ContourHeatmap extends ContourBase {
|
|
|
1636
2398
|
wireStates(this);
|
|
1637
2399
|
loadRemote(this, "cells");
|
|
1638
2400
|
if (renderStates(this, "heatmap")) return;
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
const
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
2401
|
+
// Slotted content support: authored .c-heatmap__cell children take
|
|
2402
|
+
// precedence over the generated grid.
|
|
2403
|
+
const authoredCells = Array.from(this.querySelectorAll(":scope > .c-heatmap__cell"));
|
|
2404
|
+
if (authoredCells.length) {
|
|
2405
|
+
const cols = Math.ceil(Math.sqrt(authoredCells.length));
|
|
2406
|
+
this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
|
|
2407
|
+
this.style.inlineSize = "16rem";
|
|
2408
|
+
} else {
|
|
2409
|
+
Array.from(this.querySelectorAll(".c-heatmap__cell")).forEach((n) => n.remove());
|
|
2410
|
+
const count = Math.min(200, Math.max(0, parseInt(this.getAttribute("cells") || this.getAttribute("count") || "0", 10) || 0));
|
|
2411
|
+
const cols = count > 0 ? Math.ceil(Math.sqrt(count)) : 1;
|
|
2412
|
+
this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
|
|
2413
|
+
this.style.inlineSize = "16rem";
|
|
2414
|
+
if (count > 0) {
|
|
1645
2415
|
let values = [];
|
|
1646
2416
|
try { values = JSON.parse(this.getAttribute("values") || "[]"); } catch (e) { values = []; }
|
|
1647
2417
|
for (let i = 0; i < count; i++) {
|
|
@@ -1655,9 +2425,10 @@ class ContourHeatmap extends ContourBase {
|
|
|
1655
2425
|
}
|
|
1656
2426
|
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; });
|
|
1657
2427
|
tip.setAttribute("hidden", "");
|
|
1658
|
-
} else {
|
|
2428
|
+
} else if (!authoredCells.length) {
|
|
1659
2429
|
renderEmpty(this, "heatmap");
|
|
1660
2430
|
}
|
|
2431
|
+
}
|
|
1661
2432
|
if (this.hasAttribute("legend")) {
|
|
1662
2433
|
const leg = this.ensure(".c-heatmap__legend", () => {
|
|
1663
2434
|
const el = document.createElement("div");
|