contour-ds 1.1.0 → 1.1.2
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 +43 -43
- package/dist/contour-wc.esm.js +794 -184
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +794 -184
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.components.json +67 -21
- package/dist/contour.css +113 -36
- package/dist/contour.d.ts +1 -0
- package/dist/contour.min.css +1 -1
- package/dist/contour.themes.json +4 -1
- package/dist/contour.tokens.json +3 -0
- 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 +3 -3
- 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 +13 -3
- package/dist/wc/data.mjs +302 -36
- package/dist/wc/forms.mjs +119 -61
- package/dist/wc/map.mjs +190 -69
- package/dist/wc/navigation.mjs +66 -11
- package/dist/wc/ui.mjs +104 -4
- package/package.json +1 -1
package/dist/wc/core.mjs
CHANGED
|
@@ -86,6 +86,7 @@
|
|
|
86
86
|
"contour:brush-start": { payload: ["value"], composed: true },
|
|
87
87
|
"contour:brush-end": { payload: ["value"], composed: true },
|
|
88
88
|
"contour:change": { payload: ["name", "value", "checked"], composed: true },
|
|
89
|
+
"contour:clear": { payload: [], composed: true },
|
|
89
90
|
"contour:close": { payload: [], composed: true },
|
|
90
91
|
"contour:copy": { payload: ["text"], composed: true },
|
|
91
92
|
"contour:dash-action": { payload: ["label"], composed: true },
|
|
@@ -105,6 +106,8 @@
|
|
|
105
106
|
"contour:layer-duplicate": { payload: ["name"], composed: true },
|
|
106
107
|
"contour:layer-zoom": { payload: ["name"], composed: true },
|
|
107
108
|
"contour:layer-projection": { payload: ["name", "projection"], composed: true },
|
|
109
|
+
"contour:layer-remove": { payload: ["name"], composed: true },
|
|
110
|
+
"contour:layer-reorder": { payload: ["layerIds"], composed: true },
|
|
108
111
|
"contour:layer-toggle": { payload: ["name"], composed: true },
|
|
109
112
|
"contour:layer-visibility": { payload: ["name", "visible"], composed: true },
|
|
110
113
|
"contour:legend-toggle": { payload: ["label", "key", "layers", "pressed"], composed: true },
|
|
@@ -112,6 +115,7 @@
|
|
|
112
115
|
"contour:map-control": { payload: ["control"], composed: true },
|
|
113
116
|
"contour:map-attach": { payload: [], composed: true },
|
|
114
117
|
"contour:map-detach": { payload: [], composed: true },
|
|
118
|
+
"contour:mode-change": { payload: ["mode"], composed: true },
|
|
115
119
|
"contour:move": { payload: ["direction"], composed: true },
|
|
116
120
|
"contour:open": { payload: [], composed: true },
|
|
117
121
|
"contour:page": { payload: ["page"], composed: true },
|
|
@@ -119,7 +123,12 @@
|
|
|
119
123
|
"contour:remove": { payload: ["label", "key", "layers", "value"], composed: true },
|
|
120
124
|
"contour:range-change": { payload: ["value"], composed: true },
|
|
121
125
|
"contour:retry": { payload: ["src"], composed: true },
|
|
126
|
+
"contour:loop-change": { payload: ["loop"], composed: true },
|
|
127
|
+
"contour:pause": { payload: [], composed: true },
|
|
128
|
+
"contour:play": { payload: [], composed: true },
|
|
129
|
+
"contour:seek": { payload: ["progress", "value"], composed: true },
|
|
122
130
|
"contour:select": { payload: ["series", "index", "label", "value"], composed: true },
|
|
131
|
+
"contour:speed-change": { payload: ["speed"], composed: true },
|
|
123
132
|
"contour:showcase-activate": { payload: ["title"], composed: true },
|
|
124
133
|
"contour:step-activate": { payload: ["index", "title"], composed: true },
|
|
125
134
|
"contour:step-change": { payload: ["index", "title"], composed: true },
|
|
@@ -174,14 +183,15 @@
|
|
|
174
183
|
// role, open, aria-label, aria-valuenow, aria-valuemin, aria-valuemax, tabindex
|
|
175
184
|
// Adding one of those back to this list makes that component recurse.
|
|
176
185
|
export const OBSERVED = [
|
|
177
|
-
"accept", "action", "actions", "after", "anchor", "answer", "area", "article", "attribution", "attribution-mark", "autoplay", "axis", "axis-x", "axis-y", "brownout", "brownout-level", "before", "body", "brand", "breakpoint", "cache-key", "canvas", "center", "clearable", "cols", "columns", "color", "command",
|
|
178
|
-
"cells", "checked", "chrome", "closable", "colors", "content", "controls", "copyable", "count", "current", "data", "date", "delta", "description", "glyphs", "demo", "density", "desc", "dir", "direction", "disabled", "dismissible", "divider", "do", "dont", "dot",
|
|
186
|
+
"accept", "action", "actions", "after", "allow-duplicate", "allow-remove", "allow-rename", "allow-zoom", "anchor", "answer", "area", "article", "attribution", "attribution-mark", "audit", "autoplay", "axis", "axis-x", "axis-y", "brownout", "brownout-level", "before", "body", "brand", "breakpoint", "breaks", "cache-key", "canvas", "center", "clearable", "cols", "columns", "color", "command",
|
|
187
|
+
"cells", "checked", "chrome", "closable", "classification", "colors", "continuous", "content", "controls", "copyable", "count", "current", "data", "date", "delta", "description", "glyphs", "demo", "density", "desc", "dir", "direction", "disabled", "dismissible", "divider", "do", "dont", "dot", "ends", "high", "input", "layer", "low", "mode", "modes", "n", "opacity", "palette", "polarity", "range", "single",
|
|
179
188
|
"empty", "error", "exclusive", "format", "heading", "hint", "href", "icon", "illustration", "index", "instrument", "interval", "items", "key", "layers", "level",
|
|
180
189
|
"label", "lazy", "lede", "legend", "line", "link", "links", "live", "loading", "locale", "loop", "max", "media", "message", "method", "month", "menu", "min", "multiple", "name", "needle", "next", "no", "no-cache", "no-data-message", "nodes", "note", "norm", "normalize",
|
|
181
190
|
"options", "orientation", "page-size", "pages", "pause", "paused", "pausable", "persist", "placeholder", "playing", "point", "points", "prev", "progress", "prompt", "question", "recent", "required",
|
|
182
191
|
"quote", "ramp", "refresh", "removable", "reverse", "rings", "retry", "rows", "scale", "selectable", "segments", "show-header", "sparkline", "start", "end", "threshold", "thresholds", "selected", "separator", "series", "shortcut", "side", "size", "skeleton", "sort", "sort-dir", "speed", "status", "step", "submit", "timeout", "trigger", "virtual",
|
|
183
|
-
"state", "steps", "subtitle", "summary", "src", "tabs", "tag", "text", "ticks", "title", "type", "unit",
|
|
192
|
+
"state", "steps", "subtitle", "summary", "src", "table", "tabs", "tag", "text", "ticks", "title", "type", "unit",
|
|
184
193
|
"variant", "values", "viewport", "yes", "zoomable", "x", "y",
|
|
194
|
+
"caption", "current-time", "is-playing", "loop-label", "no-data-color", "property", "show-loop", "show-thumb", "show-thumb-caption", "speeds",
|
|
185
195
|
];
|
|
186
196
|
|
|
187
197
|
export function headingTag(host, fallback = "h3") {
|
package/dist/wc/data.mjs
CHANGED
|
@@ -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
|
}
|
|
@@ -1818,8 +1823,8 @@ class ContourInstrument extends ContourBase {
|
|
|
1818
1823
|
}
|
|
1819
1824
|
define("contour-instrument", ContourInstrument);
|
|
1820
1825
|
class ContourBivariate extends ContourBase {
|
|
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" } }; }
|
|
1826
|
+
static get observed() { return ["size", "axis-x", "axis-y", "colors", "selected"]; }
|
|
1827
|
+
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" }, selected: { attribute: "selected" } }; }
|
|
1823
1828
|
render() {
|
|
1824
1829
|
this.classList.add("c-bivariate");
|
|
1825
1830
|
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
@@ -1837,6 +1842,9 @@ class ContourBivariate extends ContourBase {
|
|
|
1837
1842
|
for (let c = 0; c < size; c++) {
|
|
1838
1843
|
const cell = document.createElement("div");
|
|
1839
1844
|
cell.className = "c-bivariate__cell";
|
|
1845
|
+
cell.setAttribute("role", "button");
|
|
1846
|
+
cell.setAttribute("tabindex", "0");
|
|
1847
|
+
cell.setAttribute("aria-label", "Cell " + c + "," + r);
|
|
1840
1848
|
// Palette runs from bottom-left (low/low) to top-right (high/high):
|
|
1841
1849
|
// reverse the row order so the first palette row sits at the bottom.
|
|
1842
1850
|
const srcIndex = (size - 1 - r) * size + c;
|
|
@@ -1844,6 +1852,24 @@ class ContourBivariate extends ContourBase {
|
|
|
1844
1852
|
matrix.appendChild(cell);
|
|
1845
1853
|
}
|
|
1846
1854
|
}
|
|
1855
|
+
// selected highlight
|
|
1856
|
+
const sel = this.getAttribute("selected");
|
|
1857
|
+
if (sel) {
|
|
1858
|
+
const parts = sel.split(",");
|
|
1859
|
+
const sr = parseInt(parts[0], 10);
|
|
1860
|
+
const sc = parseInt(parts[1], 10);
|
|
1861
|
+
const cells = Array.from(matrix.querySelectorAll(".c-bivariate__cell"));
|
|
1862
|
+
cells.forEach((cell, i) => {
|
|
1863
|
+
const rr = Math.floor(i / size);
|
|
1864
|
+
const cc = i % size;
|
|
1865
|
+
// matrix is row-major in DOM? cells appended row by row r then c, so index = r*size+c
|
|
1866
|
+
if (rr === sr && cc === sc) cell.setAttribute("data-selected", "");
|
|
1867
|
+
else cell.removeAttribute("data-selected");
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
// aria-live region
|
|
1871
|
+
let live = this.querySelector(".c-bivariate__live");
|
|
1872
|
+
if (!live) { live = document.createElement("div"); live.className = "c-bivariate__live"; live.setAttribute("aria-live", "polite"); live.style.position = "absolute"; live.style.width = "1px"; live.style.height = "1px"; live.style.overflow = "hidden"; live.style.clip = "rect(0,0,0,0)"; this.appendChild(live); }
|
|
1847
1873
|
}
|
|
1848
1874
|
const axisX = this.getAttribute("axis-x");
|
|
1849
1875
|
if (axisX) {
|
|
@@ -1862,11 +1888,47 @@ class ContourBivariate extends ContourBase {
|
|
|
1862
1888
|
if (ay) ay.remove();
|
|
1863
1889
|
}
|
|
1864
1890
|
}
|
|
1891
|
+
enhance() {
|
|
1892
|
+
if (this._wiredBivariate) return;
|
|
1893
|
+
this._wiredBivariate = true;
|
|
1894
|
+
const selectCell = (cell) => {
|
|
1895
|
+
const matrix = this.querySelector(".c-bivariate__matrix");
|
|
1896
|
+
const cells = Array.from(matrix ? matrix.querySelectorAll(".c-bivariate__cell") : []);
|
|
1897
|
+
const idx = cells.indexOf(cell);
|
|
1898
|
+
if (idx < 0) return;
|
|
1899
|
+
const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
1900
|
+
const row = Math.floor(idx / size);
|
|
1901
|
+
const col = idx % size;
|
|
1902
|
+
cells.forEach((cell, i) => {
|
|
1903
|
+
const rr = Math.floor(i / size);
|
|
1904
|
+
const cc = i % size;
|
|
1905
|
+
if (rr === row && cc === col) cell.setAttribute("data-selected", "");
|
|
1906
|
+
else cell.removeAttribute("data-selected");
|
|
1907
|
+
});
|
|
1908
|
+
this.dispatchEvent(new CustomEvent("contour:select", { detail: { row, col }, bubbles: true, composed: true }));
|
|
1909
|
+
};
|
|
1910
|
+
this.addEventListener("click", (e) => {
|
|
1911
|
+
const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate__cell") : null;
|
|
1912
|
+
if (cell && this.contains(cell)) selectCell(cell);
|
|
1913
|
+
});
|
|
1914
|
+
this.addEventListener("keydown", (e) => {
|
|
1915
|
+
const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate__cell") : null;
|
|
1916
|
+
if (!cell || !this.contains(cell)) return;
|
|
1917
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
1918
|
+
e.preventDefault();
|
|
1919
|
+
selectCell(cell);
|
|
1920
|
+
}
|
|
1921
|
+
});
|
|
1922
|
+
}
|
|
1923
|
+
clear() {
|
|
1924
|
+
this.removeAttribute("selected");
|
|
1925
|
+
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true }));
|
|
1926
|
+
}
|
|
1865
1927
|
}
|
|
1866
1928
|
define("contour-bivariate", ContourBivariate);
|
|
1867
1929
|
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" } }; }
|
|
1930
|
+
static get observed() { return ["size", "axis-x", "axis-y", "colors", "selected"]; }
|
|
1931
|
+
static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" }, selected: { attribute: "selected" } }; }
|
|
1870
1932
|
render() {
|
|
1871
1933
|
this.classList.add("c-bivariate-legend");
|
|
1872
1934
|
const size = Math.min(8, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
@@ -1882,10 +1944,18 @@ class ContourBivariateLegend extends ContourBase {
|
|
|
1882
1944
|
for (let i = 0; i < size * size; i++) {
|
|
1883
1945
|
const cell = document.createElement("div");
|
|
1884
1946
|
cell.className = "c-bivariate-legend__cell";
|
|
1947
|
+
cell.setAttribute("role", "button");
|
|
1948
|
+
cell.setAttribute("tabindex", "0");
|
|
1949
|
+
const x = i % size;
|
|
1950
|
+
const y = Math.floor(i / size);
|
|
1951
|
+
cell.setAttribute("aria-label", "Cell " + x + "," + y);
|
|
1885
1952
|
if (colors[i]) cell.style.background = colors[i];
|
|
1886
1953
|
else cell.style.background = "var(--chart-" + ((i % 8) + 1) + ")";
|
|
1887
1954
|
matrix.appendChild(cell);
|
|
1888
1955
|
}
|
|
1956
|
+
// aria-live
|
|
1957
|
+
let live = this.querySelector(".c-bivariate-legend__live");
|
|
1958
|
+
if (!live) { live = document.createElement("div"); live.className = "c-bivariate-legend__live"; live.setAttribute("aria-live", "polite"); live.style.position = "absolute"; live.style.width = "1px"; live.style.height = "1px"; live.style.overflow = "hidden"; live.style.clip = "rect(0,0,0,0)"; this.appendChild(live); }
|
|
1889
1959
|
}
|
|
1890
1960
|
const axisX = this.getAttribute("axis-x");
|
|
1891
1961
|
const ax = this.querySelector(".c-bivariate-legend__axis--x");
|
|
@@ -1904,7 +1974,36 @@ class ContourBivariateLegend extends ContourBase {
|
|
|
1904
1974
|
ay.remove();
|
|
1905
1975
|
}
|
|
1906
1976
|
}
|
|
1907
|
-
enhance() {
|
|
1977
|
+
enhance() {
|
|
1978
|
+
if (this._wiredBivLegend) return;
|
|
1979
|
+
this._wiredBivLegend = true;
|
|
1980
|
+
const selectCell = (cell) => {
|
|
1981
|
+
const matrix = this.querySelector(".c-bivariate-legend__matrix");
|
|
1982
|
+
const cells = Array.from(matrix ? matrix.querySelectorAll(".c-bivariate-legend__cell") : []);
|
|
1983
|
+
const idx = cells.indexOf(cell);
|
|
1984
|
+
if (idx < 0) return;
|
|
1985
|
+
const size = Math.min(8, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
|
|
1986
|
+
const row = Math.floor(idx / size);
|
|
1987
|
+
const col = idx % size;
|
|
1988
|
+
cells.forEach((cell, i) => {
|
|
1989
|
+
const rr = Math.floor(i / size);
|
|
1990
|
+
const cc = i % size;
|
|
1991
|
+
if (rr === row && cc === col) cell.setAttribute("data-selected", "");
|
|
1992
|
+
else cell.removeAttribute("data-selected");
|
|
1993
|
+
});
|
|
1994
|
+
this.dispatchEvent(new CustomEvent("contour:select", { detail: { row, col }, bubbles: true, composed: true }));
|
|
1995
|
+
};
|
|
1996
|
+
this.addEventListener("click", (e) => {
|
|
1997
|
+
const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate-legend__cell") : null;
|
|
1998
|
+
if (cell && this.contains(cell)) selectCell(cell);
|
|
1999
|
+
});
|
|
2000
|
+
this.addEventListener("keydown", (e) => {
|
|
2001
|
+
const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate-legend__cell") : null;
|
|
2002
|
+
if (!cell || !this.contains(cell)) return;
|
|
2003
|
+
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); selectCell(cell); }
|
|
2004
|
+
});
|
|
2005
|
+
}
|
|
2006
|
+
clear() { this.removeAttribute("selected"); this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true })); }
|
|
1908
2007
|
}
|
|
1909
2008
|
define("contour-bivariate-legend", ContourBivariateLegend);
|
|
1910
2009
|
class ContourSurvey extends ContourBase {
|
|
@@ -2016,7 +2115,7 @@ class ContourMetricsFull extends ContourBase {
|
|
|
2016
2115
|
}
|
|
2017
2116
|
define("contour-metrics", ContourMetricsFull);
|
|
2018
2117
|
class ContourLegend extends ContourBase {
|
|
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"]; }
|
|
2118
|
+
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"]; }
|
|
2020
2119
|
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" } }; }
|
|
2021
2120
|
render() {
|
|
2022
2121
|
this.classList.add("c-legend");
|
|
@@ -2039,13 +2138,18 @@ class ContourLegend extends ContourBase {
|
|
|
2039
2138
|
if (items) {
|
|
2040
2139
|
try {
|
|
2041
2140
|
const parsed = JSON.parse(items);
|
|
2042
|
-
const list = this.ensure(".c-legend__items", () => { const el = document.createElement("div"); el.className = "c-legend__items"; return el; });
|
|
2141
|
+
const list = this.ensure(".c-legend__items", () => { const el = document.createElement("div"); el.className = "c-legend__items"; el.setAttribute("role", "listbox"); return el; });
|
|
2142
|
+
list.setAttribute("role", "listbox");
|
|
2143
|
+
if (title) list.setAttribute("aria-label", title);
|
|
2043
2144
|
list.innerHTML = "";
|
|
2044
2145
|
parsed.forEach((it) => {
|
|
2045
2146
|
const label = typeof it === "string" ? it : (it.label || String(it));
|
|
2046
2147
|
const key = typeof it === "string" ? it : (it.key || it.label || String(it));
|
|
2047
2148
|
const item = document.createElement(selectable ? "button" : "div");
|
|
2048
2149
|
item.className = "c-legend__item";
|
|
2150
|
+
item.setAttribute("role", "option");
|
|
2151
|
+
item.setAttribute("aria-selected", "false");
|
|
2152
|
+
item.setAttribute("tabindex", "-1");
|
|
2049
2153
|
if (selectable) {
|
|
2050
2154
|
item.type = "button";
|
|
2051
2155
|
item.setAttribute("aria-pressed", "true");
|
|
@@ -2056,14 +2160,15 @@ class ContourLegend extends ContourBase {
|
|
|
2056
2160
|
if (it && it.color) sw.style.background = it.color;
|
|
2057
2161
|
item.appendChild(sw);
|
|
2058
2162
|
// geometry glyph
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2163
|
+
const glyphShape = (it && (it.shape || it.marker || it.glyph)) || this.getAttribute("glyphs");
|
|
2164
|
+
if (glyphShape) {
|
|
2165
|
+
const g = document.createElement("span");
|
|
2166
|
+
g.className = "c-legend__glyph";
|
|
2167
|
+
g.setAttribute("part", "glyph");
|
|
2168
|
+
g.textContent = glyphShape === "circle" ? "●" : glyphShape === "square" ? "■" : glyphShape === "triangle" ? "▲" : glyphShape === "diamond" ? "◆" : glyphShape === "star" ? "★" : String(glyphShape);
|
|
2169
|
+
if (it && it.size != null) g.style.fontSize = (typeof it.size === "number" ? it.size + "px" : String(it.size));
|
|
2170
|
+
item.appendChild(g);
|
|
2171
|
+
}
|
|
2067
2172
|
// threshold break marker
|
|
2068
2173
|
if (it && it.break != null) {
|
|
2069
2174
|
const b = document.createElement("span");
|
|
@@ -2071,9 +2176,21 @@ class ContourLegend extends ContourBase {
|
|
|
2071
2176
|
b.textContent = String(it.break);
|
|
2072
2177
|
item.appendChild(b);
|
|
2073
2178
|
}
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2179
|
+
const lbl = document.createElement("span");
|
|
2180
|
+
lbl.textContent = label;
|
|
2181
|
+
item.appendChild(lbl);
|
|
2182
|
+
// caption (source-and-method line)
|
|
2183
|
+
const caption = (typeof it === "object" && it) ? (it.caption || it.note || "") : "";
|
|
2184
|
+
if (caption) {
|
|
2185
|
+
const cap = document.createElement("span");
|
|
2186
|
+
cap.className = "c-legend__caption";
|
|
2187
|
+
cap.textContent = caption;
|
|
2188
|
+
item.appendChild(cap);
|
|
2189
|
+
}
|
|
2190
|
+
// threshold mark: outline on swatches that begin at a threshold
|
|
2191
|
+
if (it && (it.threshold || it.break != null)) {
|
|
2192
|
+
sw.style.outline = "2px solid var(--color-border-strong)";
|
|
2193
|
+
}
|
|
2077
2194
|
list.appendChild(item);
|
|
2078
2195
|
});
|
|
2079
2196
|
} catch (e) { /* keep existing */ }
|
|
@@ -2085,7 +2202,112 @@ class ContourLegend extends ContourBase {
|
|
|
2085
2202
|
renderEmpty(this, "legend");
|
|
2086
2203
|
}
|
|
2087
2204
|
}
|
|
2088
|
-
|
|
2205
|
+
// caption as option description (aria-describedby), not part of name
|
|
2206
|
+
const caption = this.getAttribute("caption");
|
|
2207
|
+
let captionEl = this.querySelector(".c-legend__caption");
|
|
2208
|
+
if (caption) {
|
|
2209
|
+
if (!captionEl) { captionEl = document.createElement("span"); captionEl.className = "c-legend__caption"; this.appendChild(captionEl); }
|
|
2210
|
+
captionEl.id = captionEl.id || ("legend-caption-" + Math.random().toString(36).slice(2));
|
|
2211
|
+
captionEl.textContent = caption;
|
|
2212
|
+
captionEl.style.position = "absolute"; captionEl.style.width = "1px"; captionEl.style.height = "1px"; captionEl.style.overflow = "hidden"; captionEl.style.clip = "rect(0,0,0,0)";
|
|
2213
|
+
} else if (captionEl) {
|
|
2214
|
+
captionEl.remove();
|
|
2215
|
+
}
|
|
2216
|
+
// single tab stop: first option
|
|
2217
|
+
const _items = this.querySelector(".c-legend__items");
|
|
2218
|
+
if (_items) {
|
|
2219
|
+
const opts = Array.from(_items.querySelectorAll(".c-legend__item"));
|
|
2220
|
+
opts.forEach((o, i) => o.setAttribute("tabindex", i === 0 ? "0" : "-1"));
|
|
2221
|
+
if (captionEl) opts.forEach((o) => o.setAttribute("aria-describedby", captionEl.id));
|
|
2222
|
+
}
|
|
2223
|
+
// no-data entry from palette / no-data-color
|
|
2224
|
+
const ndColor = this.getAttribute("no-data-color");
|
|
2225
|
+
if (ndColor) {
|
|
2226
|
+
let nd = this.querySelector(".c-legend__no-data");
|
|
2227
|
+
if (!nd) { nd = document.createElement("div"); nd.className = "c-legend__no-data"; this.appendChild(nd); }
|
|
2228
|
+
nd.setAttribute("part", "no-data");
|
|
2229
|
+
nd.textContent = "No data";
|
|
2230
|
+
const glyph = document.createElement("span");
|
|
2231
|
+
glyph.className = "glyph";
|
|
2232
|
+
glyph.style.background = ndColor;
|
|
2233
|
+
nd.prepend(glyph);
|
|
2234
|
+
} else {
|
|
2235
|
+
const nd = this.querySelector(".c-legend__no-data");
|
|
2236
|
+
if (nd) nd.remove();
|
|
2237
|
+
}
|
|
2238
|
+
// audit notice
|
|
2239
|
+
const audit = this.getAttribute("audit");
|
|
2240
|
+
if (audit) {
|
|
2241
|
+
const a = this.ensure(".c-legend__audit", () => { const el = document.createElement("div"); el.className = "c-legend__audit"; return el; });
|
|
2242
|
+
a.textContent = audit;
|
|
2243
|
+
} else {
|
|
2244
|
+
const a = this.querySelector(".c-legend__audit");
|
|
2245
|
+
if (a) a.remove();
|
|
2246
|
+
}
|
|
2247
|
+
// continuous variant: ramp with two ends labelled
|
|
2248
|
+
if (this.hasAttribute("continuous")) {
|
|
2249
|
+
const ends = this.getAttribute("ends");
|
|
2250
|
+
let parsedEnds = null;
|
|
2251
|
+
if (ends) { try { parsedEnds = JSON.parse(ends); } catch (e) { parsedEnds = ends.split(","); } }
|
|
2252
|
+
if (Array.isArray(parsedEnds) && parsedEnds.length >= 2) {
|
|
2253
|
+
const r = this.ensure(".c-legend__ramp", () => { const el = document.createElement("div"); el.className = "c-legend__ramp"; return el; });
|
|
2254
|
+
// labels
|
|
2255
|
+
let left = this.querySelector(".c-legend__ramp-label--start");
|
|
2256
|
+
if (!left) { left = document.createElement("span"); left.className = "c-legend__ramp-label c-legend__ramp-label--start"; r.appendChild(left); }
|
|
2257
|
+
left.textContent = parsedEnds[0];
|
|
2258
|
+
let right = this.querySelector(".c-legend__ramp-label--end");
|
|
2259
|
+
if (!right) { right = document.createElement("span"); right.className = "c-legend__ramp-label c-legend__ramp-label--end"; r.appendChild(right); }
|
|
2260
|
+
right.textContent = parsedEnds[parsedEnds.length - 1];
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
// size variant: differently-sized glyphs
|
|
2264
|
+
const sizeAttr = this.getAttribute("size");
|
|
2265
|
+
if (sizeAttr) {
|
|
2266
|
+
const sc = this.ensure(".c-legend__size", () => { const el = document.createElement("div"); el.className = "c-legend__size"; return el; });
|
|
2267
|
+
sc.textContent = sizeAttr;
|
|
2268
|
+
} else {
|
|
2269
|
+
const sc = this.querySelector(".c-legend__size");
|
|
2270
|
+
if (sc) sc.remove();
|
|
2271
|
+
}
|
|
2272
|
+
// classification line
|
|
2273
|
+
const classification = this.getAttribute("classification");
|
|
2274
|
+
if (classification) {
|
|
2275
|
+
const c = this.ensure(".c-legend__classification", () => { const el = document.createElement("div"); el.className = "c-legend__classification"; return el; });
|
|
2276
|
+
c.textContent = classification;
|
|
2277
|
+
} else {
|
|
2278
|
+
const c = this.querySelector(".c-legend__classification");
|
|
2279
|
+
if (c) c.remove();
|
|
2280
|
+
}
|
|
2281
|
+
// data table (collapsible)
|
|
2282
|
+
const tableAttr = this.getAttribute("table");
|
|
2283
|
+
if (tableAttr) {
|
|
2284
|
+
let parsed = null;
|
|
2285
|
+
try { parsed = JSON.parse(tableAttr); } catch (e) { parsed = null; }
|
|
2286
|
+
if (Array.isArray(parsed)) {
|
|
2287
|
+
let det = this.querySelector(".c-legend__table-wrap");
|
|
2288
|
+
if (!det) { det = document.createElement("details"); det.className = "c-legend__table-wrap"; this.appendChild(det); }
|
|
2289
|
+
det.innerHTML = "";
|
|
2290
|
+
const sum = document.createElement("summary"); sum.textContent = "Data table"; det.appendChild(sum);
|
|
2291
|
+
const tbl = document.createElement("table"); tbl.className = "c-legend__table";
|
|
2292
|
+
const tbody = document.createElement("tbody");
|
|
2293
|
+
parsed.forEach((row) => {
|
|
2294
|
+
const tr = document.createElement("tr");
|
|
2295
|
+
const cells = Array.isArray(row) ? row : [row.label ?? row.key ?? "", row.value ?? ""];
|
|
2296
|
+
cells.forEach((cell) => { const td = document.createElement("td"); td.textContent = cell; tr.appendChild(td); });
|
|
2297
|
+
tbody.appendChild(tr);
|
|
2298
|
+
});
|
|
2299
|
+
tbl.appendChild(tbody);
|
|
2300
|
+
det.appendChild(tbl);
|
|
2301
|
+
}
|
|
2302
|
+
} else {
|
|
2303
|
+
const det = this.querySelector(".c-legend__table-wrap");
|
|
2304
|
+
if (det) det.remove();
|
|
2305
|
+
}
|
|
2306
|
+
// size variant on glyphs
|
|
2307
|
+
if (items) {
|
|
2308
|
+
// apply size to glyphs already rendered? handled below via re-render not needed
|
|
2309
|
+
}
|
|
2310
|
+
const method = this.getAttribute("method");
|
|
2089
2311
|
if (method) {
|
|
2090
2312
|
const m = this.ensure(".c-legend__method", () => { const el = document.createElement("div"); el.className = "c-legend__method"; return el; });
|
|
2091
2313
|
m.textContent = method;
|
|
@@ -2101,14 +2323,34 @@ class ContourLegend extends ContourBase {
|
|
|
2101
2323
|
const n = this.querySelector(".c-legend__norm");
|
|
2102
2324
|
if (n) n.remove();
|
|
2103
2325
|
}
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2326
|
+
const ramp = this.getAttribute("ramp");
|
|
2327
|
+
if (ramp) {
|
|
2328
|
+
const r = this.ensure(".c-legend__ramp", () => { const el = document.createElement("div"); el.className = "c-legend__ramp"; return el; });
|
|
2329
|
+
r.style.background = ramp;
|
|
2330
|
+
// ramp routing: equal-width segments with break labels
|
|
2331
|
+
const breaksAttr = this.getAttribute("breaks");
|
|
2332
|
+
if (breaksAttr) {
|
|
2333
|
+
let breaks = null;
|
|
2334
|
+
try { breaks = JSON.parse(breaksAttr); } catch (e) { breaks = breaksAttr.split(",").map((s) => s.trim()); }
|
|
2335
|
+
if (Array.isArray(breaks)) {
|
|
2336
|
+
// remove old segments
|
|
2337
|
+
Array.from(r.querySelectorAll(".c-legend__ramp-segment")).forEach((n) => n.remove());
|
|
2338
|
+
breaks.forEach((b, i) => {
|
|
2339
|
+
const seg = document.createElement("span");
|
|
2340
|
+
seg.className = "c-legend__ramp-segment";
|
|
2341
|
+
seg.style.flex = "1";
|
|
2342
|
+
const lbl = document.createElement("span");
|
|
2343
|
+
lbl.className = "c-legend__ramp-break";
|
|
2344
|
+
lbl.textContent = String(b);
|
|
2345
|
+
seg.appendChild(lbl);
|
|
2346
|
+
r.appendChild(seg);
|
|
2347
|
+
});
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
} else {
|
|
2351
|
+
const r = this.querySelector(".c-legend__ramp");
|
|
2352
|
+
if (r) r.remove();
|
|
2353
|
+
}
|
|
2112
2354
|
const scale = this.getAttribute("scale");
|
|
2113
2355
|
if (scale) {
|
|
2114
2356
|
const sc = this.ensure(".c-legend__scale", () => { const el = document.createElement("div"); el.className = "c-legend__scale"; return el; });
|
|
@@ -2126,6 +2368,7 @@ class ContourLegend extends ContourBase {
|
|
|
2126
2368
|
if (!btn || !this.contains(btn)) return;
|
|
2127
2369
|
const pressed = btn.getAttribute("aria-pressed") !== "true";
|
|
2128
2370
|
btn.setAttribute("aria-pressed", String(pressed));
|
|
2371
|
+
btn.setAttribute("aria-selected", String(pressed));
|
|
2129
2372
|
this.dispatchEvent(new CustomEvent("contour:legend-toggle", {
|
|
2130
2373
|
detail: { label: btn.textContent.trim(), key: btn.dataset.key || btn.textContent.trim(), pressed },
|
|
2131
2374
|
bubbles: true,
|
|
@@ -2158,11 +2401,34 @@ class ContourLegend extends ContourBase {
|
|
|
2158
2401
|
if (e.key === "ArrowDown" || e.key === "ArrowRight") {
|
|
2159
2402
|
e.preventDefault();
|
|
2160
2403
|
const next = items[(idx + 1) % items.length];
|
|
2161
|
-
if (next) next.focus();
|
|
2404
|
+
if (next) { next.focus(); items.forEach((o,i)=>o.setAttribute("tabindex", o===next?"0":"-1")); }
|
|
2162
2405
|
} else if (e.key === "ArrowUp" || e.key === "ArrowLeft") {
|
|
2163
2406
|
e.preventDefault();
|
|
2164
2407
|
const prev = items[(idx - 1 + items.length) % items.length];
|
|
2165
|
-
if (prev) prev.focus();
|
|
2408
|
+
if (prev) { prev.focus(); items.forEach((o)=>o.setAttribute("tabindex", o===prev?"0":"-1")); }
|
|
2409
|
+
} else if (e.key === "Home") {
|
|
2410
|
+
if (items.length > 4) { e.preventDefault(); items[0].focus(); items.forEach((o,i)=>o.setAttribute("tabindex", i===0?"0":"-1")); }
|
|
2411
|
+
} else if (e.key === "End") {
|
|
2412
|
+
if (items.length > 4) { e.preventDefault(); const last = items[items.length-1]; last.focus(); items.forEach((o)=>o.setAttribute("tabindex", o===last?"0":"-1")); }
|
|
2413
|
+
} else if (e.key === "Escape") {
|
|
2414
|
+
// clear selection
|
|
2415
|
+
items.forEach((o) => o.setAttribute("aria-selected", "false"));
|
|
2416
|
+
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true }));
|
|
2417
|
+
} else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
2418
|
+
// type-ahead
|
|
2419
|
+
if (items.length > 7) {
|
|
2420
|
+
const start = idx >= 0 ? idx + 1 : 0;
|
|
2421
|
+
for (let i = 0; i < items.length; i++) {
|
|
2422
|
+
const ii = (start + i) % items.length;
|
|
2423
|
+
const txt = (items[ii].textContent || "").trim().toLowerCase();
|
|
2424
|
+
if (txt.startsWith(e.key.toLowerCase())) {
|
|
2425
|
+
e.preventDefault();
|
|
2426
|
+
items[ii].focus();
|
|
2427
|
+
items.forEach((o,j)=>o.setAttribute("tabindex", j===ii?"0":"-1"));
|
|
2428
|
+
break;
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2166
2432
|
} else if (e.key === "Enter" || e.key === " ") {
|
|
2167
2433
|
e.preventDefault();
|
|
2168
2434
|
if (document.activeElement && document.activeElement.classList.contains("c-legend__item")) {
|