contour-ds 1.0.0 → 1.1.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 +1 -1
- package/dist/build-manifest.json +44 -44
- package/dist/contour-wc.esm.js +1012 -67
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +1012 -67
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.components.json +403 -16
- package/dist/contour.css +328 -10
- 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 +1 -1
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +1 -1
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +6 -6
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/wc/core.mjs +13 -5
- package/dist/wc/data.mjs +687 -26
- package/dist/wc/index.mjs +1 -1
- package/dist/wc/interaction.mjs +3 -2
- package/dist/wc/map.mjs +189 -27
- package/dist/wc/shadow.mjs +29 -1
- package/dist/wc/svg.mjs +16 -1
- package/dist/wc/ui.mjs +77 -8
- 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");
|
|
@@ -107,6 +107,30 @@ class ContourKpi extends ContourBase {
|
|
|
107
107
|
if (u) u.remove();
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
+
// threshold badge
|
|
111
|
+
const threshold = this.getAttribute("threshold") || this.getAttribute("thresholds");
|
|
112
|
+
if (threshold) {
|
|
113
|
+
const f = this.ensure(".c-kpi__foot", () => { const el = document.createElement("div"); el.className = "c-kpi__foot"; return el; });
|
|
114
|
+
let badge = f.querySelector(".c-kpi__threshold-badge");
|
|
115
|
+
if (!badge) { badge = document.createElement("span"); badge.className = "c-kpi__threshold-badge"; f.appendChild(badge); }
|
|
116
|
+
badge.textContent = threshold;
|
|
117
|
+
badge.setAttribute("part", "threshold-badge");
|
|
118
|
+
} else {
|
|
119
|
+
const b = this.querySelector(".c-kpi__threshold-badge");
|
|
120
|
+
if (b) b.remove();
|
|
121
|
+
}
|
|
122
|
+
// remove orphaned foot container when no children remain
|
|
123
|
+
const foot = this.querySelector(".c-kpi__foot");
|
|
124
|
+
if (foot && !foot.querySelector(".c-delta, .c-kpi__note, .c-kpi__threshold-badge")) foot.remove();
|
|
125
|
+
// sparkline canvas
|
|
126
|
+
const spark = this.getAttribute("sparkline");
|
|
127
|
+
if (spark) {
|
|
128
|
+
let canvas = this.querySelector(".c-kpi__sparkline-canvas");
|
|
129
|
+
if (!canvas) { canvas = document.createElement("canvas"); canvas.className = "c-kpi__sparkline-canvas"; canvas.setAttribute("part", "sparkline-canvas"); this.appendChild(canvas); }
|
|
130
|
+
} else {
|
|
131
|
+
const c = this.querySelector(".c-kpi__sparkline-canvas");
|
|
132
|
+
if (c) c.remove();
|
|
133
|
+
}
|
|
110
134
|
if (!value && !label) {
|
|
111
135
|
renderEmpty(this, "kpi");
|
|
112
136
|
}
|
|
@@ -950,24 +974,32 @@ const series = this.getAttribute("series");
|
|
|
950
974
|
}
|
|
951
975
|
define("contour-chart", ContourChart);
|
|
952
976
|
class ContourComparison extends ContourBase {
|
|
953
|
-
static get observed() { return ["divider", "value"]; }
|
|
954
|
-
static get properties() { return { divider: { attribute: "divider" }, value: { attribute: "value" } }; }
|
|
977
|
+
static get observed() { return ["divider", "value", "before", "after"]; }
|
|
978
|
+
static get properties() { return { divider: { attribute: "divider" }, value: { attribute: "value" }, before: { attribute: "before" }, after: { attribute: "after" } }; }
|
|
955
979
|
render() {
|
|
956
980
|
this.classList.add("c-comparison");
|
|
957
|
-
this.style.blockSize = "12rem";
|
|
981
|
+
if (!this.style.blockSize) this.style.blockSize = "12rem";
|
|
958
982
|
this.style.setProperty("--comparison-pos", (this.getAttribute("value") || "50") + "%");
|
|
959
983
|
// Ensure two panes exist.
|
|
984
|
+
const beforeLabel = this.getAttribute("before") || "Before";
|
|
985
|
+
const afterLabel = this.getAttribute("after") || "After";
|
|
960
986
|
if (!this.querySelector(".c-comparison__pane--before")) {
|
|
961
987
|
const p = document.createElement("div");
|
|
962
988
|
p.className = "c-comparison__pane c-comparison__pane--before";
|
|
963
|
-
p.textContent =
|
|
989
|
+
p.textContent = beforeLabel;
|
|
964
990
|
this.appendChild(p);
|
|
991
|
+
} else {
|
|
992
|
+
const p = this.querySelector(".c-comparison__pane--before");
|
|
993
|
+
if (p) p.textContent = beforeLabel;
|
|
965
994
|
}
|
|
966
995
|
if (!this.querySelector(".c-comparison__pane:not(.c-comparison__pane--before)")) {
|
|
967
996
|
const p = document.createElement("div");
|
|
968
997
|
p.className = "c-comparison__pane";
|
|
969
|
-
p.textContent =
|
|
998
|
+
p.textContent = afterLabel;
|
|
970
999
|
this.appendChild(p);
|
|
1000
|
+
} else {
|
|
1001
|
+
const p = this.querySelector(".c-comparison__pane:not(.c-comparison__pane--before)");
|
|
1002
|
+
if (p) p.textContent = afterLabel;
|
|
971
1003
|
}
|
|
972
1004
|
const divider = this.getAttribute("divider");
|
|
973
1005
|
if (divider !== null) {
|
|
@@ -1241,6 +1273,517 @@ class ContourStat extends ContourBase {
|
|
|
1241
1273
|
}
|
|
1242
1274
|
}
|
|
1243
1275
|
define("contour-stat", ContourStat);
|
|
1276
|
+
class ContourGauge extends ContourBase {
|
|
1277
|
+
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"]; }
|
|
1278
|
+
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" } }; }
|
|
1279
|
+
render() {
|
|
1280
|
+
this.classList.add("c-gauge");
|
|
1281
|
+
wireStates(this);
|
|
1282
|
+
loadRemote(this, ["value"]);
|
|
1283
|
+
if (renderStates(this, "gauge")) return;
|
|
1284
|
+
const rawValue = this.getAttribute("value");
|
|
1285
|
+
const num = parseFloat(rawValue);
|
|
1286
|
+
const hasValue = rawValue !== null && rawValue !== "" && Number.isFinite(num);
|
|
1287
|
+
const min = parseFloat(this.getAttribute("min") || "0");
|
|
1288
|
+
const max = parseFloat(this.getAttribute("max") || "100");
|
|
1289
|
+
const heading = this.getAttribute("heading");
|
|
1290
|
+
const showHeader = this.getAttribute("show-header") !== "false";
|
|
1291
|
+
const description = this.getAttribute("description");
|
|
1292
|
+
const noDataMessage = this.getAttribute("no-data-message") || "No readings in view";
|
|
1293
|
+
const brownoutLevel = parseInt(this.getAttribute("brownout-level") || this.getAttribute("brownout") || "0", 10) || 0;
|
|
1294
|
+
// empty state
|
|
1295
|
+
if (!hasValue) {
|
|
1296
|
+
if (heading && showHeader) {
|
|
1297
|
+
const t = this.ensure(".c-gauge__title", () => { const el = document.createElement("div"); el.className = "c-gauge__title"; return el; });
|
|
1298
|
+
t.textContent = heading;
|
|
1299
|
+
}
|
|
1300
|
+
const empty = this.ensure(".c-gauge__empty", () => { const el = document.createElement("div"); el.className = "c-gauge__empty"; el.setAttribute("part", "empty"); return el; });
|
|
1301
|
+
empty.textContent = noDataMessage;
|
|
1302
|
+
// remove dial/value/band if present
|
|
1303
|
+
[".c-gauge__dial", ".c-gauge__value", ".c-gauge__band"].forEach((sel) => { const n = this.querySelector(sel); if (n) n.remove(); });
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
// heading
|
|
1307
|
+
if (heading && showHeader) {
|
|
1308
|
+
const t = this.ensure(".c-gauge__title", () => { const el = document.createElement("div"); el.className = "c-gauge__title"; el.setAttribute("part", "title"); return el; });
|
|
1309
|
+
t.textContent = heading;
|
|
1310
|
+
} else {
|
|
1311
|
+
const t = this.querySelector(".c-gauge__title"); if (t) t.remove();
|
|
1312
|
+
}
|
|
1313
|
+
// thresholds
|
|
1314
|
+
let thresholds = [];
|
|
1315
|
+
const tAttr = this.getAttribute("thresholds");
|
|
1316
|
+
if (tAttr) { try { thresholds = JSON.parse(tAttr); } catch (e) { thresholds = []; } }
|
|
1317
|
+
// band determination
|
|
1318
|
+
let band = null;
|
|
1319
|
+
if (thresholds && thresholds.length) {
|
|
1320
|
+
// thresholds sorted ascending by value
|
|
1321
|
+
const sorted = [...thresholds].sort((a, b) => (a.value || 0) - (b.value || 0));
|
|
1322
|
+
for (let i = sorted.length - 1; i >= 0; i--) {
|
|
1323
|
+
if (num >= (sorted[i].value || 0)) { band = sorted[i]; break; }
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
// dial (unless brownout >= 3)
|
|
1327
|
+
const shedDial = brownoutLevel >= 3;
|
|
1328
|
+
let dial = this.querySelector(".c-gauge__dial");
|
|
1329
|
+
if (shedDial) {
|
|
1330
|
+
if (dial) dial.remove();
|
|
1331
|
+
} else {
|
|
1332
|
+
if (!dial) {
|
|
1333
|
+
dial = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1334
|
+
dial.setAttribute("class", "c-gauge__dial");
|
|
1335
|
+
dial.setAttribute("part", "dial");
|
|
1336
|
+
dial.setAttribute("aria-hidden", "true");
|
|
1337
|
+
dial.setAttribute("viewBox", "0 0 100 100");
|
|
1338
|
+
this.appendChild(dial);
|
|
1339
|
+
}
|
|
1340
|
+
// rebuild dial content
|
|
1341
|
+
dial.innerHTML = "";
|
|
1342
|
+
// track arc (semicircle)
|
|
1343
|
+
const track = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1344
|
+
track.setAttribute("class", "c-gauge__track");
|
|
1345
|
+
track.setAttribute("d", "M 10 90 A 40 40 0 0 1 90 90");
|
|
1346
|
+
dial.appendChild(track);
|
|
1347
|
+
// zones: each threshold defines a band from its value to the next
|
|
1348
|
+
// threshold's value (or max), drawn as an arc along the track so the
|
|
1349
|
+
// bands no longer stack on top of one another.
|
|
1350
|
+
if (thresholds && thresholds.length) {
|
|
1351
|
+
const sorted = [...thresholds].sort((a, b) => (a.value || 0) - (b.value || 0));
|
|
1352
|
+
const toPoint = (v) => {
|
|
1353
|
+
const pos = (1 - (v - min) / (max - min || 1)) * Math.PI;
|
|
1354
|
+
return { x: 50 + 40 * Math.cos(pos), y: 90 - 40 * Math.sin(pos) };
|
|
1355
|
+
};
|
|
1356
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
1357
|
+
const v1 = sorted[i].value || 0;
|
|
1358
|
+
const v2 = (i + 1 < sorted.length) ? (sorted[i + 1].value || max) : max;
|
|
1359
|
+
const p1 = toPoint(v1);
|
|
1360
|
+
const p2 = toPoint(v2);
|
|
1361
|
+
const z = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1362
|
+
z.setAttribute("class", "c-gauge__zone");
|
|
1363
|
+
z.setAttribute("stroke", sorted[i].color || "var(--color-primary)");
|
|
1364
|
+
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));
|
|
1365
|
+
dial.appendChild(z);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
// needle
|
|
1369
|
+
const angle = ((num - min) / (max - min || 1)) * 180 - 90;
|
|
1370
|
+
const needle = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
1371
|
+
needle.setAttribute("class", "c-gauge__needle needle");
|
|
1372
|
+
needle.setAttribute("x1", "50"); needle.setAttribute("y1", "50");
|
|
1373
|
+
needle.setAttribute("x2", String(50 + 35 * Math.cos(angle * Math.PI / 180)));
|
|
1374
|
+
needle.setAttribute("y2", String(50 + 35 * Math.sin(angle * Math.PI / 180)));
|
|
1375
|
+
dial.appendChild(needle);
|
|
1376
|
+
const hub = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
1377
|
+
hub.setAttribute("class", "c-gauge__hub hub");
|
|
1378
|
+
hub.setAttribute("cx", "50"); hub.setAttribute("cy", "50"); hub.setAttribute("r", "4");
|
|
1379
|
+
dial.appendChild(hub);
|
|
1380
|
+
}
|
|
1381
|
+
// value element (meter)
|
|
1382
|
+
const valueEl = this.ensure(".c-gauge__value", () => { const el = document.createElement("div"); el.className = "c-gauge__value"; el.setAttribute("part", "value"); return el; });
|
|
1383
|
+
valueEl.textContent = formatValue(String(num), this.getAttribute("format"), this.getAttribute("locale")) + (this.getAttribute("unit") ? " " + this.getAttribute("unit") : "");
|
|
1384
|
+
valueEl.setAttribute("role", "meter");
|
|
1385
|
+
valueEl.setAttribute("aria-valuenow", String(num));
|
|
1386
|
+
valueEl.setAttribute("aria-valuemin", String(min));
|
|
1387
|
+
valueEl.setAttribute("aria-valuemax", String(max));
|
|
1388
|
+
if (heading) {
|
|
1389
|
+
// labelledby
|
|
1390
|
+
if (!valueEl.id) valueEl.id = contourId("gauge-value");
|
|
1391
|
+
}
|
|
1392
|
+
if (band) {
|
|
1393
|
+
valueEl.setAttribute("aria-valuetext", num + ", " + (band.label || (">= " + band.value)));
|
|
1394
|
+
} else {
|
|
1395
|
+
valueEl.setAttribute("aria-valuetext", String(num));
|
|
1396
|
+
}
|
|
1397
|
+
// aria-labelledby / aria-label
|
|
1398
|
+
const titleEl = this.querySelector(".c-gauge__title");
|
|
1399
|
+
if (titleEl) {
|
|
1400
|
+
if (!titleEl.id) titleEl.id = contourId("gauge-title");
|
|
1401
|
+
valueEl.setAttribute("aria-labelledby", titleEl.id);
|
|
1402
|
+
valueEl.removeAttribute("aria-label");
|
|
1403
|
+
} else {
|
|
1404
|
+
valueEl.removeAttribute("aria-labelledby");
|
|
1405
|
+
if (heading) valueEl.setAttribute("aria-label", heading);
|
|
1406
|
+
}
|
|
1407
|
+
// band word
|
|
1408
|
+
const bandEl = this.querySelector(".c-gauge__band");
|
|
1409
|
+
if (band) {
|
|
1410
|
+
const b = this.ensure(".c-gauge__band", () => { const el = document.createElement("div"); el.className = "c-gauge__band"; el.setAttribute("part", "band"); return el; });
|
|
1411
|
+
b.textContent = band.label || (">= " + band.value);
|
|
1412
|
+
} else {
|
|
1413
|
+
if (bandEl) bandEl.remove();
|
|
1414
|
+
}
|
|
1415
|
+
// description
|
|
1416
|
+
if (description) {
|
|
1417
|
+
let d = this.querySelector(".c-gauge__desc");
|
|
1418
|
+
if (!d) { d = document.createElement("div"); d.className = "c-gauge__desc"; this.appendChild(d); }
|
|
1419
|
+
d.textContent = description;
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
enhance() {}
|
|
1423
|
+
}
|
|
1424
|
+
define("contour-gauge", ContourGauge);
|
|
1425
|
+
class ContourAxis extends ContourBase {
|
|
1426
|
+
static get observed() { return ["orientation", "values", "ticks", "format", "locale", "padding", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1427
|
+
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" } }; }
|
|
1428
|
+
render() {
|
|
1429
|
+
this.classList.add("c-axis");
|
|
1430
|
+
const orientation = this.getAttribute("orientation") || "horizontal";
|
|
1431
|
+
this.classList.toggle("c-axis--horizontal", orientation === "horizontal");
|
|
1432
|
+
this.classList.toggle("c-axis--vertical", orientation === "vertical");
|
|
1433
|
+
if (orientation === "horizontal") this.setAttribute("part", "axis-x");
|
|
1434
|
+
else this.setAttribute("part", "axis-y");
|
|
1435
|
+
wireStates(this);
|
|
1436
|
+
loadRemote(this, ["values"]);
|
|
1437
|
+
if (renderStates(this, "axis")) return;
|
|
1438
|
+
// parse values
|
|
1439
|
+
let values = [];
|
|
1440
|
+
const vAttr = this.getAttribute("values");
|
|
1441
|
+
if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map((x) => x.trim()); } }
|
|
1442
|
+
const ticks = parseInt(this.getAttribute("ticks") || "0", 10) || values.length;
|
|
1443
|
+
// Slotted content support: authored .c-axis__tick children take
|
|
1444
|
+
// precedence over the JSON `values` attribute.
|
|
1445
|
+
const authoredTicks = Array.from(this.querySelectorAll(":scope > .c-axis__tick"));
|
|
1446
|
+
if (authoredTicks.length) {
|
|
1447
|
+
// keep authored ticks, just ensure labels are formatted
|
|
1448
|
+
authoredTicks.forEach((tick) => {
|
|
1449
|
+
const label = tick.querySelector(".c-axis__label");
|
|
1450
|
+
if (label && !label.textContent) label.textContent = tick.textContent;
|
|
1451
|
+
});
|
|
1452
|
+
} else {
|
|
1453
|
+
// clear
|
|
1454
|
+
Array.from(this.querySelectorAll(".c-axis__tick")).forEach((n) => n.remove());
|
|
1455
|
+
const list = values.length ? values : Array.from({ length: ticks }, (_, i) => i);
|
|
1456
|
+
list.forEach((v) => {
|
|
1457
|
+
const tick = document.createElement("span");
|
|
1458
|
+
tick.className = "c-axis__tick";
|
|
1459
|
+
const label = document.createElement("span");
|
|
1460
|
+
label.className = "c-axis__label";
|
|
1461
|
+
label.textContent = formatValue(String(v), this.getAttribute("format"), this.getAttribute("locale"));
|
|
1462
|
+
tick.appendChild(label);
|
|
1463
|
+
this.appendChild(tick);
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
enhance() {}
|
|
1468
|
+
}
|
|
1469
|
+
define("contour-axis", ContourAxis);
|
|
1470
|
+
class ContourBrush extends ContourBase {
|
|
1471
|
+
static get observed() { return ["start", "end", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1472
|
+
static get properties() { return { start: { attribute: "start" }, end: { attribute: "end" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
|
|
1473
|
+
render() {
|
|
1474
|
+
this.classList.add("c-brush");
|
|
1475
|
+
wireStates(this);
|
|
1476
|
+
loadRemote(this, []);
|
|
1477
|
+
if (renderStates(this, "brush")) return;
|
|
1478
|
+
let sel = this.querySelector(".c-brush__selection");
|
|
1479
|
+
if (!sel) { sel = document.createElement("div"); sel.className = "c-brush__selection"; this.appendChild(sel); }
|
|
1480
|
+
const start = parseFloat(this.getAttribute("start") || "0");
|
|
1481
|
+
const end = parseFloat(this.getAttribute("end") || "100");
|
|
1482
|
+
const min = parseFloat(this.getAttribute("min") || "0");
|
|
1483
|
+
const max = parseFloat(this.getAttribute("max") || "100");
|
|
1484
|
+
const range = max - min || 1;
|
|
1485
|
+
const left = ((start - min) / range) * 100;
|
|
1486
|
+
const width = ((end - start) / range) * 100;
|
|
1487
|
+
sel.style.insetInlineStart = left + "%";
|
|
1488
|
+
sel.style.inlineSize = width + "%";
|
|
1489
|
+
// handles
|
|
1490
|
+
["start","end"].forEach((h) => {
|
|
1491
|
+
let handle = this.querySelector(".c-brush__handle--" + h);
|
|
1492
|
+
if (!handle) { handle = document.createElement("div"); handle.className = "c-brush__handle c-brush__handle--" + h; this.appendChild(handle); }
|
|
1493
|
+
const val = h === "start" ? start : end;
|
|
1494
|
+
handle.style.insetInlineStart = (((val - min) / range) * 100) + "%";
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
enhance() {
|
|
1498
|
+
if (this._wiredBrush) return;
|
|
1499
|
+
this._wiredBrush = true;
|
|
1500
|
+
this.addEventListener("pointerdown", (e) => {
|
|
1501
|
+
this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: { value: this.getAttribute("start"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
|
|
1502
|
+
});
|
|
1503
|
+
this.addEventListener("pointerup", (e) => {
|
|
1504
|
+
this.dispatchEvent(new CustomEvent("contour:brush-end", { bubbles: true, composed: true, detail: { value: this.getAttribute("end"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
define("contour-brush", ContourBrush);
|
|
1509
|
+
class ContourStackedBar extends ContourBase {
|
|
1510
|
+
static get observed() { return ["segments", "values", "colors", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "normalize"]; }
|
|
1511
|
+
static get properties() { return { segments: { attribute: "segments" }, values: { attribute: "values" }, colors: { attribute: "colors" }, src: { attribute: "src" }, normalize: { attribute: "normalize" } }; }
|
|
1512
|
+
render() {
|
|
1513
|
+
this.classList.add("c-stacked-bar");
|
|
1514
|
+
wireStates(this);
|
|
1515
|
+
loadRemote(this, ["segments", "values"]);
|
|
1516
|
+
if (renderStates(this, "stacked-bar")) return;
|
|
1517
|
+
Array.from(this.querySelectorAll(".c-stacked-bar__segment")).forEach((n) => n.remove());
|
|
1518
|
+
// Slotted content support: authored .c-stacked-bar__segment children take
|
|
1519
|
+
// precedence over the JSON `segments` attribute.
|
|
1520
|
+
const authoredSegments = Array.from(this.querySelectorAll(":scope > .c-stacked-bar__segment"));
|
|
1521
|
+
let segments = [];
|
|
1522
|
+
if (authoredSegments.length) {
|
|
1523
|
+
segments = authoredSegments.map((el) => ({
|
|
1524
|
+
label: el.getAttribute("title") || el.textContent || "",
|
|
1525
|
+
value: parseFloat(el.style.inlineSize) || 0,
|
|
1526
|
+
color: el.style.background || undefined,
|
|
1527
|
+
}));
|
|
1528
|
+
authoredSegments.forEach((el) => el.remove());
|
|
1529
|
+
} else {
|
|
1530
|
+
const sAttr = this.getAttribute("segments");
|
|
1531
|
+
if (sAttr) { try { segments = JSON.parse(sAttr); } catch (e) { segments = []; } }
|
|
1532
|
+
}
|
|
1533
|
+
const values = segments.map((seg) => (typeof seg === "object" ? (seg.value || 0) : Number(seg) || 0));
|
|
1534
|
+
const total = values.reduce((a, b) => a + b, 0) || 1;
|
|
1535
|
+
const normalize = this.hasAttribute("normalize");
|
|
1536
|
+
const denom = normalize ? total : (parseFloat(this.getAttribute("max") || String(total)) || total);
|
|
1537
|
+
segments.forEach((seg, i) => {
|
|
1538
|
+
const v = values[i];
|
|
1539
|
+
const el = document.createElement("div");
|
|
1540
|
+
el.className = "c-stacked-bar__segment";
|
|
1541
|
+
el.style.inlineSize = ((v / denom) * 100) + "%";
|
|
1542
|
+
el.style.background = (typeof seg === "object" && seg.color) ? seg.color : "var(--chart-" + ((i % 8) + 1) + ")";
|
|
1543
|
+
el.setAttribute("title", (typeof seg === "object" ? (seg.label || "") : "") + " " + v);
|
|
1544
|
+
this.appendChild(el);
|
|
1545
|
+
});
|
|
1546
|
+
if (!segments.length) renderEmpty(this, "stacked-bar");
|
|
1547
|
+
}
|
|
1548
|
+
enhance() {}
|
|
1549
|
+
}
|
|
1550
|
+
define("contour-stacked-bar", ContourStackedBar);
|
|
1551
|
+
class ContourCategory extends ContourBase {
|
|
1552
|
+
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "search"]; }
|
|
1553
|
+
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, search: { attribute: "search" } }; }
|
|
1554
|
+
render() {
|
|
1555
|
+
this.classList.add("c-category");
|
|
1556
|
+
this.setAttribute("role", "listbox");
|
|
1557
|
+
wireStates(this);
|
|
1558
|
+
loadRemote(this, ["items"]);
|
|
1559
|
+
if (renderStates(this, "category")) return;
|
|
1560
|
+
Array.from(this.querySelectorAll(".c-category__item")).forEach((n) => n.remove());
|
|
1561
|
+
// Slotted content support: authored .c-category__item children take
|
|
1562
|
+
// precedence over the JSON `items` attribute.
|
|
1563
|
+
const authoredItems = Array.from(this.querySelectorAll(":scope > .c-category__item"));
|
|
1564
|
+
let items = [];
|
|
1565
|
+
if (authoredItems.length) {
|
|
1566
|
+
authoredItems.forEach((el) => {
|
|
1567
|
+
const lbl = el.querySelector(".c-category__label");
|
|
1568
|
+
items.push({ label: lbl ? lbl.textContent : el.textContent, value: 0 });
|
|
1569
|
+
});
|
|
1570
|
+
authoredItems.forEach((el) => el.remove());
|
|
1571
|
+
} else {
|
|
1572
|
+
const iAttr = this.getAttribute("items");
|
|
1573
|
+
if (iAttr) { try { items = JSON.parse(iAttr); } catch (e) { items = []; } }
|
|
1574
|
+
}
|
|
1575
|
+
const max = items.reduce((m, it) => Math.max(m, (typeof it === "object" ? (it.value || 0) : Number(it) || 0)), 0) || 1;
|
|
1576
|
+
items.forEach((it, idx) => {
|
|
1577
|
+
const value = (typeof it === "object") ? (it.value || 0) : (Number(it) || 0);
|
|
1578
|
+
const label = (typeof it === "object") ? (it.label || it.name || "") : String(it);
|
|
1579
|
+
const item = document.createElement("div");
|
|
1580
|
+
item.className = "c-category__item";
|
|
1581
|
+
item.setAttribute("role", "option");
|
|
1582
|
+
item.setAttribute("aria-selected", "false");
|
|
1583
|
+
const lbl = document.createElement("span");
|
|
1584
|
+
lbl.className = "c-category__label";
|
|
1585
|
+
lbl.textContent = label;
|
|
1586
|
+
const barWrap = document.createElement("div");
|
|
1587
|
+
barWrap.style.flex = "1";
|
|
1588
|
+
const bar = document.createElement("div");
|
|
1589
|
+
bar.className = "c-category__bar";
|
|
1590
|
+
bar.style.inlineSize = ((value / max) * 100) + "%";
|
|
1591
|
+
barWrap.appendChild(bar);
|
|
1592
|
+
const val = document.createElement("span");
|
|
1593
|
+
val.className = "c-category__value";
|
|
1594
|
+
val.textContent = String(value);
|
|
1595
|
+
item.appendChild(lbl);
|
|
1596
|
+
item.appendChild(barWrap);
|
|
1597
|
+
item.appendChild(val);
|
|
1598
|
+
this.appendChild(item);
|
|
1599
|
+
});
|
|
1600
|
+
if (!items.length) renderEmpty(this, "category");
|
|
1601
|
+
}
|
|
1602
|
+
enhance() {}
|
|
1603
|
+
}
|
|
1604
|
+
define("contour-category", ContourCategory);
|
|
1605
|
+
class ContourDonut extends ContourBase {
|
|
1606
|
+
static get observed() { return ["value", "values", "items", "label", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level"]; }
|
|
1607
|
+
static get properties() { return { value: { attribute: "value" }, values: { attribute: "values" }, items: { attribute: "items" }, label: { attribute: "label" }, src: { attribute: "src" } }; }
|
|
1608
|
+
render() {
|
|
1609
|
+
this.classList.add("c-donut");
|
|
1610
|
+
wireStates(this);
|
|
1611
|
+
loadRemote(this, ["items", "values"]);
|
|
1612
|
+
if (renderStates(this, "donut")) return;
|
|
1613
|
+
Array.from(this.querySelectorAll(".c-donut__ring, .c-donut__center, .c-donut__list, .c-donut__empty")).forEach((n) => n.remove());
|
|
1614
|
+
// Slotted content support: authored .c-donut__item children take precedence
|
|
1615
|
+
// over the JSON `items` attribute, so consumers can compose legend rows
|
|
1616
|
+
// by hand instead of serialising them into an attribute.
|
|
1617
|
+
const authoredItems = Array.from(this.querySelectorAll(":scope > .c-donut__item"));
|
|
1618
|
+
let items = [];
|
|
1619
|
+
if (authoredItems.length) {
|
|
1620
|
+
authoredItems.forEach((el) => {
|
|
1621
|
+
const sw = el.querySelector(".c-donut__swatch");
|
|
1622
|
+
const lbl = el.querySelector("span:last-child");
|
|
1623
|
+
const text = lbl ? lbl.textContent : el.textContent;
|
|
1624
|
+
const match = text.match(/—\s*(\d+(?:\.\d+)?)$/);
|
|
1625
|
+
items.push({ label: text.replace(/—\s*\d+(?:\.\d+)?$/, "").trim(), value: match ? Number(match[1]) : 0, color: sw ? sw.style.background : undefined });
|
|
1626
|
+
});
|
|
1627
|
+
// remove authored items from DOM (they will be regenerated below)
|
|
1628
|
+
authoredItems.forEach((el) => el.remove());
|
|
1629
|
+
} else {
|
|
1630
|
+
const iAttr = this.getAttribute("items");
|
|
1631
|
+
if (iAttr) { try { items = JSON.parse(iAttr); } catch (e) { items = []; } }
|
|
1632
|
+
}
|
|
1633
|
+
const values = items.map((it) => (typeof it === "object" ? (it.value || 0) : Number(it) || 0));
|
|
1634
|
+
const total = values.reduce((a, b) => a + b, 0) || 1;
|
|
1635
|
+
const brownoutLevel = parseInt(this.getAttribute("brownout-level") || this.getAttribute("brownout") || "0", 10) || 0;
|
|
1636
|
+
const shedRing = brownoutLevel >= 3;
|
|
1637
|
+
if (!shedRing) {
|
|
1638
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1639
|
+
svg.setAttribute("class", "c-donut__ring");
|
|
1640
|
+
svg.setAttribute("viewBox", "0 0 32 32");
|
|
1641
|
+
let offset = 0;
|
|
1642
|
+
items.forEach((it, i) => {
|
|
1643
|
+
const v = values[i];
|
|
1644
|
+
const pct = v / total;
|
|
1645
|
+
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
1646
|
+
circle.setAttribute("cx", "16"); circle.setAttribute("cy", "16"); circle.setAttribute("r", "12");
|
|
1647
|
+
circle.setAttribute("fill", "none");
|
|
1648
|
+
circle.setAttribute("stroke", (typeof it === "object" && it.color) ? it.color : "var(--chart-" + ((i % 8) + 1) + ")");
|
|
1649
|
+
circle.setAttribute("stroke-width", "6");
|
|
1650
|
+
const circ = 2 * Math.PI * 12;
|
|
1651
|
+
circle.setAttribute("stroke-dasharray", (pct * circ) + " " + (circ - pct * circ));
|
|
1652
|
+
circle.setAttribute("stroke-dashoffset", String(-offset * circ));
|
|
1653
|
+
circle.setAttribute("transform", "rotate(-90 16 16)");
|
|
1654
|
+
svg.appendChild(circle);
|
|
1655
|
+
offset += pct;
|
|
1656
|
+
});
|
|
1657
|
+
// center hole
|
|
1658
|
+
const hole = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
1659
|
+
hole.setAttribute("cx", "16"); hole.setAttribute("cy", "16"); hole.setAttribute("r", "9");
|
|
1660
|
+
hole.setAttribute("fill", "var(--color-surface-0)");
|
|
1661
|
+
svg.appendChild(hole);
|
|
1662
|
+
this.appendChild(svg);
|
|
1663
|
+
}
|
|
1664
|
+
const center = document.createElement("div");
|
|
1665
|
+
center.className = "c-donut__center";
|
|
1666
|
+
center.textContent = this.getAttribute("value") || String(total);
|
|
1667
|
+
this.appendChild(center);
|
|
1668
|
+
// text list
|
|
1669
|
+
const list = document.createElement("div");
|
|
1670
|
+
list.className = "c-donut__list";
|
|
1671
|
+
items.forEach((it, i) => {
|
|
1672
|
+
const row = document.createElement("div");
|
|
1673
|
+
row.className = "c-donut__item";
|
|
1674
|
+
const sw = document.createElement("span");
|
|
1675
|
+
sw.className = "c-donut__swatch";
|
|
1676
|
+
sw.style.background = (typeof it === "object" && it.color) ? it.color : "var(--chart-" + ((i % 8) + 1) + ")";
|
|
1677
|
+
row.appendChild(sw);
|
|
1678
|
+
const lbl = document.createElement("span");
|
|
1679
|
+
lbl.textContent = (typeof it === "object" ? (it.label || "") : String(it)) + " — " + values[i];
|
|
1680
|
+
row.appendChild(lbl);
|
|
1681
|
+
list.appendChild(row);
|
|
1682
|
+
});
|
|
1683
|
+
this.appendChild(list);
|
|
1684
|
+
if (!items.length) renderEmpty(this, "donut");
|
|
1685
|
+
}
|
|
1686
|
+
enhance() {}
|
|
1687
|
+
}
|
|
1688
|
+
define("contour-donut", ContourDonut);
|
|
1689
|
+
class ContourTimeSeries extends ContourBase {
|
|
1690
|
+
static get observed() { return ["values", "points", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "annotations"]; }
|
|
1691
|
+
static get properties() { return { values: { attribute: "values" }, points: { attribute: "points" }, src: { attribute: "src" }, annotations: { attribute: "annotations" } }; }
|
|
1692
|
+
render() {
|
|
1693
|
+
this.classList.add("c-time-series");
|
|
1694
|
+
wireStates(this);
|
|
1695
|
+
loadRemote(this, ["values", "points"]);
|
|
1696
|
+
if (renderStates(this, "time-series")) return;
|
|
1697
|
+
Array.from(this.querySelectorAll(".c-time-series__plot, .c-time-series__axis")).forEach((n) => n.remove());
|
|
1698
|
+
let values = [];
|
|
1699
|
+
const vAttr = this.getAttribute("values");
|
|
1700
|
+
if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map(Number); } }
|
|
1701
|
+
const max = Math.max(...values, 1);
|
|
1702
|
+
const plot = document.createElement("div");
|
|
1703
|
+
plot.className = "c-time-series__plot";
|
|
1704
|
+
plot.setAttribute("part", "plot");
|
|
1705
|
+
values.forEach((v) => {
|
|
1706
|
+
const bar = document.createElement("div");
|
|
1707
|
+
bar.className = "c-time-series__bar";
|
|
1708
|
+
bar.style.blockSize = ((v / max) * 100) + "%";
|
|
1709
|
+
bar.setAttribute("title", String(v));
|
|
1710
|
+
plot.appendChild(bar);
|
|
1711
|
+
});
|
|
1712
|
+
this.appendChild(plot);
|
|
1713
|
+
if (!values.length) renderEmpty(this, "time-series");
|
|
1714
|
+
}
|
|
1715
|
+
enhance() {}
|
|
1716
|
+
}
|
|
1717
|
+
define("contour-time-series", ContourTimeSeries);
|
|
1718
|
+
class ContourPivot extends ContourBase {
|
|
1719
|
+
static get observed() { return ["rows", "columns", "values", "data", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1720
|
+
static get properties() { return { rows: { attribute: "rows" }, columns: { attribute: "columns" }, values: { attribute: "values" }, data: { attribute: "data" }, src: { attribute: "src" } }; }
|
|
1721
|
+
render() {
|
|
1722
|
+
this.classList.add("c-pivot");
|
|
1723
|
+
wireStates(this);
|
|
1724
|
+
loadRemote(this, ["data"]);
|
|
1725
|
+
if (renderStates(this, "pivot")) return;
|
|
1726
|
+
Array.from(this.querySelectorAll("table")).forEach((n) => n.remove());
|
|
1727
|
+
let data = [];
|
|
1728
|
+
const dAttr = this.getAttribute("data");
|
|
1729
|
+
if (dAttr) { try { data = JSON.parse(dAttr); } catch (e) { data = []; } }
|
|
1730
|
+
const rows = this.getAttribute("rows") ? this.getAttribute("rows").split(",") : [];
|
|
1731
|
+
const cols = this.getAttribute("columns") ? this.getAttribute("columns").split(",") : [];
|
|
1732
|
+
const table = document.createElement("table");
|
|
1733
|
+
const thead = document.createElement("thead");
|
|
1734
|
+
const hr = document.createElement("tr");
|
|
1735
|
+
const corner = document.createElement("th");
|
|
1736
|
+
corner.textContent = "";
|
|
1737
|
+
hr.appendChild(corner);
|
|
1738
|
+
cols.forEach((c) => { const th = document.createElement("th"); th.textContent = c.trim(); hr.appendChild(th); });
|
|
1739
|
+
thead.appendChild(hr);
|
|
1740
|
+
table.appendChild(thead);
|
|
1741
|
+
const tbody = document.createElement("tbody");
|
|
1742
|
+
rows.forEach((r) => {
|
|
1743
|
+
const tr = document.createElement("tr");
|
|
1744
|
+
const th = document.createElement("th");
|
|
1745
|
+
th.textContent = r.trim();
|
|
1746
|
+
tr.appendChild(th);
|
|
1747
|
+
cols.forEach((c) => {
|
|
1748
|
+
const td = document.createElement("td");
|
|
1749
|
+
const cell = data.find((d) => d.row === r.trim() && d.col === c.trim());
|
|
1750
|
+
td.textContent = cell ? String(cell.value) : "";
|
|
1751
|
+
tr.appendChild(td);
|
|
1752
|
+
});
|
|
1753
|
+
tbody.appendChild(tr);
|
|
1754
|
+
});
|
|
1755
|
+
table.appendChild(tbody);
|
|
1756
|
+
this.appendChild(table);
|
|
1757
|
+
if (!data.length && !rows.length) renderEmpty(this, "pivot");
|
|
1758
|
+
}
|
|
1759
|
+
enhance() {}
|
|
1760
|
+
}
|
|
1761
|
+
define("contour-pivot", ContourPivot);
|
|
1762
|
+
class ContourWidgetState extends ContourBase {
|
|
1763
|
+
static get observed() { return ["loading", "error", "empty", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1764
|
+
static get properties() { return { loading: { attribute: "loading" }, error: { attribute: "error" }, empty: { attribute: "empty" }, retry: { attribute: "retry" }, src: { attribute: "src" } }; }
|
|
1765
|
+
render() {
|
|
1766
|
+
this.classList.add("c-widget-state");
|
|
1767
|
+
wireStates(this);
|
|
1768
|
+
loadRemote(this, []);
|
|
1769
|
+
if (renderStates(this, "widget-state")) return;
|
|
1770
|
+
// if no state, render slotted content (already in DOM)
|
|
1771
|
+
}
|
|
1772
|
+
enhance() {}
|
|
1773
|
+
}
|
|
1774
|
+
define("contour-widget-state", ContourWidgetState);
|
|
1775
|
+
class ContourBrownout extends ContourBase {
|
|
1776
|
+
static get observed() { return ["level"]; }
|
|
1777
|
+
static get properties() { return { level: { attribute: "level" } }; }
|
|
1778
|
+
render() {
|
|
1779
|
+
this.classList.add("c-brownout");
|
|
1780
|
+
const level = this.getAttribute("level") || "0";
|
|
1781
|
+
this.dataset.level = level;
|
|
1782
|
+
this.setAttribute("data-level", level);
|
|
1783
|
+
}
|
|
1784
|
+
enhance() {}
|
|
1785
|
+
}
|
|
1786
|
+
define("contour-brownout", ContourBrownout);
|
|
1244
1787
|
class ContourInstrument extends ContourBase {
|
|
1245
1788
|
static get observed() { return ["rows", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1246
1789
|
static get properties() { return { rows: { attribute: "rows" }, src: { attribute: "src" } }; }
|
|
@@ -1275,21 +1818,31 @@ class ContourInstrument extends ContourBase {
|
|
|
1275
1818
|
}
|
|
1276
1819
|
define("contour-instrument", ContourInstrument);
|
|
1277
1820
|
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" } }; }
|
|
1821
|
+
static get observed() { return ["size", "axis-x", "axis-y", "colors"]; }
|
|
1822
|
+
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" } }; }
|
|
1280
1823
|
render() {
|
|
1281
1824
|
this.classList.add("c-bivariate");
|
|
1282
1825
|
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
1283
1826
|
const matrix = this.ensure(".c-bivariate__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate__matrix"; return el; });
|
|
1284
1827
|
matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
|
|
1828
|
+
matrix.style.gridTemplateRows = `repeat(${size}, 1fr)`;
|
|
1285
1829
|
// Slot composition: authored cells win over the generated grid.
|
|
1286
1830
|
const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains("c-bivariate__cell"));
|
|
1287
1831
|
if (!authored.length) {
|
|
1288
1832
|
matrix.innerHTML = "";
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1833
|
+
let colors = [];
|
|
1834
|
+
const cAttr = this.getAttribute("colors");
|
|
1835
|
+
if (cAttr) { try { colors = JSON.parse(cAttr); } catch (e) { colors = []; } }
|
|
1836
|
+
for (let r = 0; r < size; r++) {
|
|
1837
|
+
for (let c = 0; c < size; c++) {
|
|
1838
|
+
const cell = document.createElement("div");
|
|
1839
|
+
cell.className = "c-bivariate__cell";
|
|
1840
|
+
// Palette runs from bottom-left (low/low) to top-right (high/high):
|
|
1841
|
+
// reverse the row order so the first palette row sits at the bottom.
|
|
1842
|
+
const srcIndex = (size - 1 - r) * size + c;
|
|
1843
|
+
if (colors[srcIndex]) cell.style.background = colors[srcIndex];
|
|
1844
|
+
matrix.appendChild(cell);
|
|
1845
|
+
}
|
|
1293
1846
|
}
|
|
1294
1847
|
}
|
|
1295
1848
|
const axisX = this.getAttribute("axis-x");
|
|
@@ -1311,6 +1864,49 @@ class ContourBivariate extends ContourBase {
|
|
|
1311
1864
|
}
|
|
1312
1865
|
}
|
|
1313
1866
|
define("contour-bivariate", ContourBivariate);
|
|
1867
|
+
class ContourBivariateLegend extends ContourBase {
|
|
1868
|
+
static get observed() { return ["size", "axis-x", "axis-y", "colors"]; }
|
|
1869
|
+
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" } }; }
|
|
1870
|
+
render() {
|
|
1871
|
+
this.classList.add("c-bivariate-legend");
|
|
1872
|
+
const size = Math.min(8, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
1873
|
+
const matrix = this.ensure(".c-bivariate-legend__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate-legend__matrix"; return el; });
|
|
1874
|
+
matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
|
|
1875
|
+
// Slotted content support: authored cells win over the generated grid.
|
|
1876
|
+
const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains("c-bivariate-legend__cell"));
|
|
1877
|
+
if (!authored.length) {
|
|
1878
|
+
matrix.innerHTML = "";
|
|
1879
|
+
let colors = [];
|
|
1880
|
+
const cAttr = this.getAttribute("colors");
|
|
1881
|
+
if (cAttr) { try { colors = JSON.parse(cAttr); } catch (e) { colors = []; } }
|
|
1882
|
+
for (let i = 0; i < size * size; i++) {
|
|
1883
|
+
const cell = document.createElement("div");
|
|
1884
|
+
cell.className = "c-bivariate-legend__cell";
|
|
1885
|
+
if (colors[i]) cell.style.background = colors[i];
|
|
1886
|
+
else cell.style.background = "var(--chart-" + ((i % 8) + 1) + ")";
|
|
1887
|
+
matrix.appendChild(cell);
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
const axisX = this.getAttribute("axis-x");
|
|
1891
|
+
const ax = this.querySelector(".c-bivariate-legend__axis--x");
|
|
1892
|
+
if (axisX) {
|
|
1893
|
+
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; });
|
|
1894
|
+
el.textContent = axisX;
|
|
1895
|
+
} else if (ax) {
|
|
1896
|
+
ax.remove();
|
|
1897
|
+
}
|
|
1898
|
+
const axisY = this.getAttribute("axis-y");
|
|
1899
|
+
const ay = this.querySelector(".c-bivariate-legend__axis--y");
|
|
1900
|
+
if (axisY) {
|
|
1901
|
+
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; });
|
|
1902
|
+
el.textContent = axisY;
|
|
1903
|
+
} else if (ay) {
|
|
1904
|
+
ay.remove();
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
enhance() {}
|
|
1908
|
+
}
|
|
1909
|
+
define("contour-bivariate-legend", ContourBivariateLegend);
|
|
1314
1910
|
class ContourSurvey extends ContourBase {
|
|
1315
1911
|
static get observed() { return ["date", "instrument", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1316
1912
|
static get properties() { return { date: { attribute: "date" }, instrument: { attribute: "instrument" }, src: { attribute: "src" } }; }
|
|
@@ -1420,7 +2016,7 @@ class ContourMetricsFull extends ContourBase {
|
|
|
1420
2016
|
}
|
|
1421
2017
|
define("contour-metrics", ContourMetricsFull);
|
|
1422
2018
|
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"]; }
|
|
2019
|
+
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"]; }
|
|
1424
2020
|
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
2021
|
render() {
|
|
1426
2022
|
this.classList.add("c-legend");
|
|
@@ -1459,6 +2055,22 @@ class ContourLegend extends ContourBase {
|
|
|
1459
2055
|
sw.className = "c-legend__swatch";
|
|
1460
2056
|
if (it && it.color) sw.style.background = it.color;
|
|
1461
2057
|
item.appendChild(sw);
|
|
2058
|
+
// geometry glyph
|
|
2059
|
+
const glyphShape = (it && (it.shape || it.marker || it.glyph)) || this.getAttribute("glyphs");
|
|
2060
|
+
if (glyphShape) {
|
|
2061
|
+
const g = document.createElement("span");
|
|
2062
|
+
g.className = "c-legend__glyph";
|
|
2063
|
+
g.setAttribute("part", "glyph");
|
|
2064
|
+
g.textContent = glyphShape === "circle" ? "●" : glyphShape === "square" ? "■" : glyphShape === "triangle" ? "▲" : glyphShape === "diamond" ? "◆" : glyphShape === "star" ? "★" : String(glyphShape);
|
|
2065
|
+
item.appendChild(g);
|
|
2066
|
+
}
|
|
2067
|
+
// threshold break marker
|
|
2068
|
+
if (it && it.break != null) {
|
|
2069
|
+
const b = document.createElement("span");
|
|
2070
|
+
b.className = "c-legend__break";
|
|
2071
|
+
b.textContent = String(it.break);
|
|
2072
|
+
item.appendChild(b);
|
|
2073
|
+
}
|
|
1462
2074
|
const lbl = document.createElement("span");
|
|
1463
2075
|
lbl.textContent = label;
|
|
1464
2076
|
item.appendChild(lbl);
|
|
@@ -1509,10 +2121,6 @@ class ContourLegend extends ContourBase {
|
|
|
1509
2121
|
enhance() {
|
|
1510
2122
|
if (this._wiredLegend) return;
|
|
1511
2123
|
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
2124
|
this.addEventListener("click", (e) => {
|
|
1517
2125
|
const btn = e.target && e.target.closest ? e.target.closest(".c-legend__item") : null;
|
|
1518
2126
|
if (!btn || !this.contains(btn)) return;
|
|
@@ -1523,6 +2131,44 @@ class ContourLegend extends ContourBase {
|
|
|
1523
2131
|
bubbles: true,
|
|
1524
2132
|
composed: true,
|
|
1525
2133
|
}));
|
|
2134
|
+
this.dispatchEvent(new CustomEvent("contour:select", {
|
|
2135
|
+
detail: { label: btn.textContent.trim(), key: btn.dataset.key || btn.textContent.trim(), value: btn.dataset.key || btn.textContent.trim() },
|
|
2136
|
+
bubbles: true,
|
|
2137
|
+
composed: true,
|
|
2138
|
+
}));
|
|
2139
|
+
});
|
|
2140
|
+
// emit style-resolved once on enhance
|
|
2141
|
+
try {
|
|
2142
|
+
let parsed = null;
|
|
2143
|
+
try { parsed = JSON.parse(this.getAttribute("items") || "null"); } catch (e) { parsed = this.getAttribute("items"); }
|
|
2144
|
+
this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: this.getAttribute("items"), items: parsed }, bubbles: true, composed: true }));
|
|
2145
|
+
} catch (e) {}
|
|
2146
|
+
// break-change delegated
|
|
2147
|
+
this.addEventListener("change", (e) => {
|
|
2148
|
+
const t = e.target;
|
|
2149
|
+
if (t && t.classList && t.classList.contains("c-legend__break-input")) {
|
|
2150
|
+
this.dispatchEvent(new CustomEvent("contour:break-change", { detail: { value: t.value }, bubbles: true, composed: true }));
|
|
2151
|
+
}
|
|
2152
|
+
});
|
|
2153
|
+
// keyboard nav (listbox)
|
|
2154
|
+
this.addEventListener("keydown", (e) => {
|
|
2155
|
+
const items = Array.from(this.querySelectorAll(".c-legend__item"));
|
|
2156
|
+
if (!items.length) return;
|
|
2157
|
+
const idx = items.indexOf(document.activeElement);
|
|
2158
|
+
if (e.key === "ArrowDown" || e.key === "ArrowRight") {
|
|
2159
|
+
e.preventDefault();
|
|
2160
|
+
const next = items[(idx + 1) % items.length];
|
|
2161
|
+
if (next) next.focus();
|
|
2162
|
+
} else if (e.key === "ArrowUp" || e.key === "ArrowLeft") {
|
|
2163
|
+
e.preventDefault();
|
|
2164
|
+
const prev = items[(idx - 1 + items.length) % items.length];
|
|
2165
|
+
if (prev) prev.focus();
|
|
2166
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
2167
|
+
e.preventDefault();
|
|
2168
|
+
if (document.activeElement && document.activeElement.classList.contains("c-legend__item")) {
|
|
2169
|
+
document.activeElement.click();
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
1526
2172
|
});
|
|
1527
2173
|
}
|
|
1528
2174
|
}
|
|
@@ -1557,6 +2203,12 @@ class ContourMeasure extends ContourBase {
|
|
|
1557
2203
|
const r = this.querySelector(".c-measure__readout");
|
|
1558
2204
|
if (r) r.remove();
|
|
1559
2205
|
}
|
|
2206
|
+
// unit selector
|
|
2207
|
+
let sel = this.querySelector(".c-measure__unit-select");
|
|
2208
|
+
if (!sel) { sel = document.createElement("select"); sel.className = "c-measure__unit-select"; this.appendChild(sel); }
|
|
2209
|
+
["m","km","mi","ft"].forEach((u) => {
|
|
2210
|
+
if (!sel.querySelector('option[value="' + u + '"]')) { const o = document.createElement("option"); o.value = u; o.textContent = u; sel.appendChild(o); }
|
|
2211
|
+
});
|
|
1560
2212
|
if (rPoint) {
|
|
1561
2213
|
const p = this.ensure(".c-measure__point", () => { const el = document.createElement("span"); el.className = "c-measure__point"; return el; });
|
|
1562
2214
|
p.textContent = rPoint;
|
|
@@ -1636,12 +2288,20 @@ class ContourHeatmap extends ContourBase {
|
|
|
1636
2288
|
wireStates(this);
|
|
1637
2289
|
loadRemote(this, "cells");
|
|
1638
2290
|
if (renderStates(this, "heatmap")) return;
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
const
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
2291
|
+
// Slotted content support: authored .c-heatmap__cell children take
|
|
2292
|
+
// precedence over the generated grid.
|
|
2293
|
+
const authoredCells = Array.from(this.querySelectorAll(":scope > .c-heatmap__cell"));
|
|
2294
|
+
if (authoredCells.length) {
|
|
2295
|
+
const cols = Math.ceil(Math.sqrt(authoredCells.length));
|
|
2296
|
+
this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
|
|
2297
|
+
this.style.inlineSize = "16rem";
|
|
2298
|
+
} else {
|
|
2299
|
+
Array.from(this.querySelectorAll(".c-heatmap__cell")).forEach((n) => n.remove());
|
|
2300
|
+
const count = Math.min(200, Math.max(0, parseInt(this.getAttribute("cells") || this.getAttribute("count") || "0", 10) || 0));
|
|
2301
|
+
const cols = count > 0 ? Math.ceil(Math.sqrt(count)) : 1;
|
|
2302
|
+
this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
|
|
2303
|
+
this.style.inlineSize = "16rem";
|
|
2304
|
+
if (count > 0) {
|
|
1645
2305
|
let values = [];
|
|
1646
2306
|
try { values = JSON.parse(this.getAttribute("values") || "[]"); } catch (e) { values = []; }
|
|
1647
2307
|
for (let i = 0; i < count; i++) {
|
|
@@ -1655,9 +2315,10 @@ class ContourHeatmap extends ContourBase {
|
|
|
1655
2315
|
}
|
|
1656
2316
|
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
2317
|
tip.setAttribute("hidden", "");
|
|
1658
|
-
} else {
|
|
2318
|
+
} else if (!authoredCells.length) {
|
|
1659
2319
|
renderEmpty(this, "heatmap");
|
|
1660
2320
|
}
|
|
2321
|
+
}
|
|
1661
2322
|
if (this.hasAttribute("legend")) {
|
|
1662
2323
|
const leg = this.ensure(".c-heatmap__legend", () => {
|
|
1663
2324
|
const el = document.createElement("div");
|