@mattilsynet/design 2.2.9 → 2.2.10
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/mtds/chart/chart-axis.d.ts +2 -1
- package/mtds/chart/chart-axis.js +16 -16
- package/mtds/chart/chart-axis.js.map +1 -1
- package/mtds/chart/chart-element.d.ts +2 -0
- package/mtds/chart/chart-element.js +46 -41
- package/mtds/chart/chart-element.js.map +1 -1
- package/mtds/chart/chart-lines.d.ts +1 -1
- package/mtds/chart/chart-lines.js +30 -30
- package/mtds/chart/chart-lines.js.map +1 -1
- package/mtds/chart/chart-pies.d.ts +5 -2
- package/mtds/chart/chart-pies.js +10 -10
- package/mtds/chart/chart-pies.js.map +1 -1
- package/mtds/chart/chart.css.js +104 -38
- package/mtds/chart/chart.css.js.map +1 -1
- package/mtds/chart/chart.d.ts +4 -0
- package/mtds/chart/chart.js +9 -9
- package/mtds/chart/chart.js.map +1 -1
- package/mtds/chart/chart.stories.d.ts +5 -3
- package/mtds/index.iife.js +113 -47
- package/mtds/lawpicker/lawpicker-element.d.ts +18 -0
- package/mtds/lawpicker/lawpicker.stories.d.ts +10 -0
- package/mtds/package.json.js +1 -1
- package/mtds/popover/popover-observer.js +19 -18
- package/mtds/popover/popover-observer.js.map +1 -1
- package/mtds/styles.css +1 -1
- package/package.json +16 -14
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ChartData } from './chart-element';
|
|
2
2
|
type Config = {
|
|
3
3
|
type: string;
|
|
4
|
+
aspect?: string;
|
|
4
5
|
};
|
|
5
|
-
export declare function toAxis(data: ChartData, { type }: Config): {
|
|
6
|
+
export declare function toAxis(data: ChartData, { aspect, type }: Config): {
|
|
6
7
|
total: number;
|
|
7
8
|
groups: HTMLDivElement;
|
|
8
9
|
axis: HTMLDivElement;
|
package/mtds/chart/chart-axis.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { tag as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
);
|
|
10
|
-
const e = r("div", {
|
|
11
|
-
"aria-label": t[0][0].value || null,
|
|
1
|
+
import { tag as n } from "../utils.js";
|
|
2
|
+
const $ = [0.1, 0.2, 0.25, 0.5, 1];
|
|
3
|
+
function y(s, { aspect: i, type: d }) {
|
|
4
|
+
const g = d === "stacked", l = s[0].reduce((t, u, f) => {
|
|
5
|
+
const m = s.map((o) => o[f].number), v = m.reduce((o, S) => o + S, 0);
|
|
6
|
+
return Math.max(t, ...g ? [v] : m);
|
|
7
|
+
}, 0), r = l / 10, p = 10 ** `${Math.round(r)}`.length, h = r / p, e = ($.find((t) => t > h) || 1) * p, a = Math.ceil(l / e) * e, c = n("div", {
|
|
8
|
+
"aria-label": s[0][0].value || null,
|
|
12
9
|
class: "axis",
|
|
13
|
-
role: "figure"
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
role: "figure",
|
|
11
|
+
style: `${i ? `--mtdsc-chart-aspect: ${i};` : ""} --bars: ${s[0]?.length - 1}; --groups: ${s.length - 1}; --total: ${a}`
|
|
12
|
+
}), x = c.appendChild(n("div", { class: "axisSteps" })), k = c.appendChild(n("div", { class: "axisGroups" }));
|
|
13
|
+
return Array.from({ length: a / e + 1 }, (t, u) => b(e * u)).reverse().map(
|
|
14
|
+
(t) => x.append(n("div", { class: "axisStep", "data-label": t }))
|
|
15
|
+
), { total: a, groups: k, axis: c };
|
|
16
16
|
}
|
|
17
|
-
const
|
|
17
|
+
const b = new Intl.NumberFormat().format;
|
|
18
18
|
export {
|
|
19
|
-
|
|
19
|
+
y as toAxis
|
|
20
20
|
};
|
|
21
21
|
//# sourceMappingURL=chart-axis.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-axis.js","sources":["../../designsystem/chart/chart-axis.ts"],"sourcesContent":["import { tag } from \"../utils\";\nimport type { ChartData } from \"./chart-element\";\n\ntype Config = { type: string };\n\nexport function toAxis(data: ChartData, { type }: Config) {\n\tconst isStacked = type === \"stacked\";\n\tconst max = data[0].reduce((acc, _, index) => {\n\t\tconst all = data.map((row) => row[index].number);\n\t\tconst sum = all.reduce((acc, num) => acc + num, 0);\n\t\treturn Math.max(acc, ...(isStacked ? [sum] : all));\n\t}, 0);\n\n\tconst
|
|
1
|
+
{"version":3,"file":"chart-axis.js","sources":["../../designsystem/chart/chart-axis.ts"],"sourcesContent":["import { tag } from \"../utils\";\nimport type { ChartData } from \"./chart-element\";\n\ntype Config = { type: string; aspect?: string };\n\nconst STEPS = [0.1, 0.2, 0.25, 0.5, 1];\n\nexport function toAxis(data: ChartData, { aspect, type }: Config) {\n\tconst totalTicks = 10;\n\tconst isStacked = type === \"stacked\";\n\tconst max = data[0].reduce((acc, _, index) => {\n\t\tconst all = data.map((row) => row[index].number);\n\t\tconst sum = all.reduce((acc, num) => acc + num, 0);\n\t\treturn Math.max(acc, ...(isStacked ? [sum] : all));\n\t}, 0);\n\n\tconst tickRange = max / totalTicks;\n\tconst tickDigits = 10 ** `${Math.round(tickRange)}`.length; // Get amount of digits in total number and use as exponent for 10x\n\tconst tickSize = tickRange / tickDigits; // Get amount of digits in total number and use as exponent for 10\n\tconst step = (STEPS.find((current) => current > tickSize) || 1) * tickDigits; // Find closest step larger than tick\n\tconst total = Math.ceil(max / step) * step;\n\tconst axis = tag(\"div\", {\n\t\t\"aria-label\": data[0][0].value || null,\n\t\tclass: \"axis\",\n\t\trole: \"figure\",\n\t\tstyle: `${aspect ? `--mtdsc-chart-aspect: ${aspect};` : \"\"} --bars: ${data[0]?.length - 1}; --groups: ${data.length - 1}; --total: ${total}`,\n\t});\n\tconst steps = axis.appendChild(tag(\"div\", { class: \"axisSteps\" }));\n\tconst groups = axis.appendChild(tag(\"div\", { class: \"axisGroups\" }));\n\n\tArray.from({ length: total / step + 1 }, (_, i) => getNum(step * i))\n\t\t.reverse()\n\t\t.map((num) =>\n\t\t\tsteps.append(tag(\"div\", { class: \"axisStep\", \"data-label\": num })),\n\t\t);\n\n\treturn { total, groups, axis };\n}\n\nconst getNum = new Intl.NumberFormat().format;\n"],"names":["STEPS","toAxis","data","aspect","type","isStacked","max","acc","_","index","all","row","sum","num","tickRange","tickDigits","tickSize","step","current","total","axis","tag","steps","groups","i","getNum"],"mappings":";AAKA,MAAMA,IAAQ,CAAC,KAAK,KAAK,MAAM,KAAK,CAAC;AAE9B,SAASC,EAAOC,GAAiB,EAAE,QAAAC,GAAQ,MAAAC,KAAgB;AAEjE,QAAMC,IAAYD,MAAS,WACrBE,IAAMJ,EAAK,CAAC,EAAE,OAAO,CAACK,GAAKC,GAAGC,MAAU;AAC7C,UAAMC,IAAMR,EAAK,IAAI,CAACS,MAAQA,EAAIF,CAAK,EAAE,MAAM,GACzCG,IAAMF,EAAI,OAAO,CAACH,GAAKM,MAAQN,IAAMM,GAAK,CAAC;AACjD,WAAO,KAAK,IAAIN,GAAK,GAAIF,IAAY,CAACO,CAAG,IAAIF,CAAI;AAAA,EAClD,GAAG,CAAC,GAEEI,IAAYR,IAAM,IAClBS,IAAa,MAAM,GAAG,KAAK,MAAMD,CAAS,CAAC,GAAG,QAC9CE,IAAWF,IAAYC,GACvBE,KAAQjB,EAAM,KAAK,CAACkB,MAAYA,IAAUF,CAAQ,KAAK,KAAKD,GAC5DI,IAAQ,KAAK,KAAKb,IAAMW,CAAI,IAAIA,GAChCG,IAAOC,EAAI,OAAO;AAAA,IACvB,cAAcnB,EAAK,CAAC,EAAE,CAAC,EAAE,SAAS;AAAA,IAClC,OAAO;AAAA,IACP,MAAM;AAAA,IACN,OAAO,GAAGC,IAAS,yBAAyBA,CAAM,MAAM,EAAE,YAAYD,EAAK,CAAC,GAAG,SAAS,CAAC,eAAeA,EAAK,SAAS,CAAC,cAAciB,CAAK;AAAA,EAAA,CAC1I,GACKG,IAAQF,EAAK,YAAYC,EAAI,OAAO,EAAE,OAAO,YAAA,CAAa,CAAC,GAC3DE,IAASH,EAAK,YAAYC,EAAI,OAAO,EAAE,OAAO,aAAA,CAAc,CAAC;AAEnE,eAAM,KAAK,EAAE,QAAQF,IAAQF,IAAO,KAAK,CAACT,GAAGgB,MAAMC,EAAOR,IAAOO,CAAC,CAAC,EACjE,UACA;AAAA,IAAI,CAACX,MACLS,EAAM,OAAOD,EAAI,OAAO,EAAE,OAAO,YAAY,cAAcR,GAAK,CAAC;AAAA,EAAA,GAG5D,EAAE,OAAAM,GAAO,QAAAI,GAAQ,MAAAH,EAAA;AACzB;AAEA,MAAMK,IAAS,IAAI,KAAK,aAAA,EAAe;"}
|
|
@@ -2,12 +2,14 @@ import { MTDSElement } from '../utils';
|
|
|
2
2
|
export type ChartData = ReturnType<typeof toData>;
|
|
3
3
|
export declare class MTDSChartElement extends MTDSElement {
|
|
4
4
|
_observer?: MutationObserver;
|
|
5
|
+
_resize?: ResizeObserver;
|
|
5
6
|
static get observedAttributes(): string[];
|
|
6
7
|
constructor();
|
|
7
8
|
connectedCallback(): void;
|
|
8
9
|
disconnectedCallback(): void;
|
|
9
10
|
attributeChangedCallback(): void;
|
|
10
11
|
handleEvent(e: Event): void;
|
|
12
|
+
handleResize(): void;
|
|
11
13
|
}
|
|
12
14
|
declare const toData: (table?: HTMLTableElement | null) => {
|
|
13
15
|
number: number;
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { IS_BROWSER as
|
|
3
|
-
import
|
|
4
|
-
import { toAxis as
|
|
5
|
-
import { toBars as
|
|
6
|
-
import { toLines as
|
|
7
|
-
import { toPies as
|
|
8
|
-
const
|
|
9
|
-
class
|
|
1
|
+
import E from "../styles.module.css.js";
|
|
2
|
+
import { IS_BROWSER as v, tag as l, MTDSElement as C, on as w, off as _, attr as d } from "../utils.js";
|
|
3
|
+
import k from "./chart.css.js";
|
|
4
|
+
import { toAxis as S } from "./chart-axis.js";
|
|
5
|
+
import { toBars as T } from "./chart-bars.js";
|
|
6
|
+
import { toLines as O } from "./chart-lines.js";
|
|
7
|
+
import { toPies as R } from "./chart-pies.js";
|
|
8
|
+
const u = "click,keydown,mousemove,mouseout", f = "mtds-chart-tooltip", a = v ? document.getElementById(f) || l("div", { class: E._tooltip, id: f, hidden: "" }) : null;
|
|
9
|
+
class $ extends C {
|
|
10
10
|
_observer;
|
|
11
11
|
// Using underscore instead of # for backwards compatibility
|
|
12
|
+
_resize;
|
|
12
13
|
static get observedAttributes() {
|
|
13
|
-
return ["data-variant"];
|
|
14
|
+
return ["data-variant", "data-aspect"];
|
|
14
15
|
}
|
|
15
16
|
constructor() {
|
|
16
17
|
super(), this.attachShadow({ mode: "open" });
|
|
17
18
|
}
|
|
18
19
|
connectedCallback() {
|
|
19
|
-
this._observer = new MutationObserver(
|
|
20
|
+
this._resize = new ResizeObserver(this.handleResize.bind(this)), this._resize.observe(this), this._observer = new MutationObserver(
|
|
20
21
|
this.attributeChangedCallback.bind(this)
|
|
21
22
|
), this._observer.observe(this, {
|
|
22
23
|
attributeFilter: ["data-tooltip"],
|
|
@@ -24,53 +25,57 @@ class O extends E {
|
|
|
24
25
|
characterData: !0,
|
|
25
26
|
childList: !0,
|
|
26
27
|
subtree: !0
|
|
27
|
-
}), this.attributeChangedCallback(),
|
|
28
|
+
}), this.attributeChangedCallback(), w(this, u, this);
|
|
28
29
|
}
|
|
29
30
|
disconnectedCallback() {
|
|
30
|
-
|
|
31
|
+
a && (a.hidden = !0), _(this, u, this), this._resize?.disconnect(), this._observer?.disconnect(), this._observer = this._resize = void 0;
|
|
31
32
|
}
|
|
32
33
|
attributeChangedCallback() {
|
|
33
|
-
Array.from(this.shadowRoot?.children || []).map((
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
Array.from(this.shadowRoot?.children || []).map((p) => p.remove());
|
|
35
|
+
const [t, e] = (d(this, "data-variant") || "column").split("-"), i = d(this, "data-aspect") || void 0, o = L(this.querySelector("table")), r = l("style", {}, k), n = l("div", { class: "legends" });
|
|
36
|
+
o.slice(1).forEach(([{ value: p, style: g }]) => {
|
|
37
|
+
n.appendChild(l("div", { class: "legend", style: g }, p));
|
|
37
38
|
});
|
|
38
|
-
const { axis:
|
|
39
|
-
(t === "
|
|
39
|
+
const { axis: h, groups: m, total: y } = S(o, { aspect: i, type: e });
|
|
40
|
+
(t === "column" || t === "bar") && m.append(...T(o)), (t === "line" || t === "area") && m.append(O(o, { total: y, variant: t, type: e })), (t === "doughnut" || t === "pie") && this.shadowRoot?.append(R(o, { aspect: i, variant: t })), this.shadowRoot?.append(h, n, r);
|
|
40
41
|
}
|
|
41
|
-
handleEvent(
|
|
42
|
-
|
|
42
|
+
handleEvent(t) {
|
|
43
|
+
t.type === "click" || t.type === "keydown" ? x(t, this) : z(t);
|
|
44
|
+
}
|
|
45
|
+
handleResize() {
|
|
46
|
+
const t = this.shadowRoot?.firstElementChild, e = t?.firstElementChild;
|
|
47
|
+
t?.classList.toggle("axisStepsYHalf", (e?.offsetHeight || 0) < 400), t?.classList.toggle("axisStepsXHalf", (e?.offsetWidth || 0) < 500);
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
|
-
function
|
|
46
|
-
if (
|
|
47
|
-
const
|
|
48
|
-
|
|
50
|
+
function x(s, t) {
|
|
51
|
+
if (s instanceof KeyboardEvent && s.key !== "Enter") return;
|
|
52
|
+
const e = s.composedPath()[0], i = t.querySelector("table"), [o, r] = e instanceof Element && d(e, "data-event")?.split("-").map(Number) || [];
|
|
53
|
+
i?.rows[o]?.cells[r]?.querySelector("a,button")?.click?.();
|
|
49
54
|
}
|
|
50
55
|
let b = "";
|
|
51
|
-
function
|
|
52
|
-
if (!
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
+
function z(s) {
|
|
57
|
+
if (!a) return;
|
|
58
|
+
a?.isConnected || document.body.append(a);
|
|
59
|
+
const t = s.composedPath()[0], e = t instanceof Element && t.getAttribute("aria-label") || "";
|
|
60
|
+
e && (a.style.transform = `translate(${s.pageX}px, ${s.pageY}px)`), e !== b && (e && (a.textContent = e), b = e, a.hidden = !e);
|
|
56
61
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
(
|
|
60
|
-
const
|
|
62
|
+
const c = (s) => s?.textContent?.trim() || "", L = (s) => Array.from(
|
|
63
|
+
s?.rows || [],
|
|
64
|
+
(t, e) => Array.from(t.cells, (i, o) => {
|
|
65
|
+
const r = c(t.cells[0]), n = c(s?.rows[0].cells[o]), h = `${r}: ${c(i)}${n ? ` (${n})` : ""}`;
|
|
61
66
|
return {
|
|
62
|
-
number:
|
|
67
|
+
number: o && e && Number.parseFloat(c(i)) || 0,
|
|
63
68
|
// First row and column is not a number
|
|
64
|
-
event:
|
|
69
|
+
event: i.querySelector("a,button") && `${e}-${o}`,
|
|
65
70
|
// Reference to proxy events
|
|
66
|
-
style: `--color: var(--mtdsc-chart-color-${
|
|
67
|
-
value:
|
|
68
|
-
tooltip:
|
|
71
|
+
style: `--color: var(--mtdsc-chart-color-${e}, var(--mtdsc-chart-color-base))`,
|
|
72
|
+
value: c(i),
|
|
73
|
+
tooltip: d(i, "data-tooltip") || h
|
|
69
74
|
};
|
|
70
75
|
})
|
|
71
76
|
);
|
|
72
|
-
|
|
77
|
+
v && !window.customElements.get("mtds-chart") && window.customElements.define("mtds-chart", $);
|
|
73
78
|
export {
|
|
74
|
-
|
|
79
|
+
$ as MTDSChartElement
|
|
75
80
|
};
|
|
76
81
|
//# sourceMappingURL=chart-element.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-element.js","sources":["../../designsystem/chart/chart-element.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { attr, IS_BROWSER, MTDSElement, off, on, tag } from \"../utils\";\nimport css from \"./chart.css?raw\";\nimport { toAxis } from \"./chart-axis\";\nimport { toBars } from \"./chart-bars\";\nimport { toLines } from \"./chart-lines\";\nimport { toPies } from \"./chart-pies\";\n\nexport type ChartData = ReturnType<typeof toData>;\n\nconst EVENTS = \"click,keydown,mousemove,mouseout\";\nconst TOOLTIP_ID = \"mtds-chart-tooltip\";\nconst TOOLTIP = IS_BROWSER\n\t? document.getElementById(TOOLTIP_ID) ||\n\t\ttag(\"div\", { class: styles._tooltip, id: TOOLTIP_ID, hidden: \"\" })\n\t: null;\n\nexport class MTDSChartElement extends MTDSElement {\n\t_observer?: MutationObserver; // Using underscore instead of # for backwards compatibility\n\n\tstatic get observedAttributes() {\n\t\treturn [\"data-variant\"]; // Using ES2015 syntax for backwards compatibility\n\t}\n\tconstructor() {\n\t\tsuper();\n\t\tthis.attachShadow({ mode: \"open\" });\n\t}\n\tconnectedCallback() {\n\t\tthis._observer = new MutationObserver(\n\t\t\tthis.attributeChangedCallback.bind(this),\n\t\t);\n\t\tthis._observer.observe(this, {\n\t\t\tattributeFilter: [\"data-tooltip\"],\n\t\t\tattributes: true,\n\t\t\tcharacterData: true,\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t});\n\t\tthis.attributeChangedCallback(); // Initial setup\n\t\ton(this, EVENTS, this);\n\t}\n\tdisconnectedCallback() {\n\t\tif (TOOLTIP) TOOLTIP.hidden = true;\n\t\toff(this, EVENTS, this);\n\t\tthis._observer?.disconnect();\n\t\tthis._observer = undefined;\n\t}\n\tattributeChangedCallback() {\n\t\tArray.from(this.shadowRoot?.children || []).map((el) => el.remove()); // Clear shadowRoot\n\n\t\tconst
|
|
1
|
+
{"version":3,"file":"chart-element.js","sources":["../../designsystem/chart/chart-element.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { attr, IS_BROWSER, MTDSElement, off, on, tag } from \"../utils\";\nimport css from \"./chart.css?raw\";\nimport { toAxis } from \"./chart-axis\";\nimport { toBars } from \"./chart-bars\";\nimport { toLines } from \"./chart-lines\";\nimport { toPies } from \"./chart-pies\";\n\nexport type ChartData = ReturnType<typeof toData>;\n\nconst EVENTS = \"click,keydown,mousemove,mouseout\";\nconst TOOLTIP_ID = \"mtds-chart-tooltip\";\nconst TOOLTIP = IS_BROWSER\n\t? document.getElementById(TOOLTIP_ID) ||\n\t\ttag(\"div\", { class: styles._tooltip, id: TOOLTIP_ID, hidden: \"\" })\n\t: null;\n\nexport class MTDSChartElement extends MTDSElement {\n\t_observer?: MutationObserver; // Using underscore instead of # for backwards compatibility\n\t_resize?: ResizeObserver;\n\n\tstatic get observedAttributes() {\n\t\treturn [\"data-variant\", \"data-aspect\"]; // Using ES2015 syntax for backwards compatibility\n\t}\n\tconstructor() {\n\t\tsuper();\n\t\tthis.attachShadow({ mode: \"open\" });\n\t}\n\tconnectedCallback() {\n\t\tthis._resize = new ResizeObserver(this.handleResize.bind(this));\n\t\tthis._resize.observe(this);\n\t\tthis._observer = new MutationObserver(\n\t\t\tthis.attributeChangedCallback.bind(this),\n\t\t);\n\t\tthis._observer.observe(this, {\n\t\t\tattributeFilter: [\"data-tooltip\"],\n\t\t\tattributes: true,\n\t\t\tcharacterData: true,\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t});\n\t\tthis.attributeChangedCallback(); // Initial setup\n\t\ton(this, EVENTS, this);\n\t}\n\tdisconnectedCallback() {\n\t\tif (TOOLTIP) TOOLTIP.hidden = true;\n\t\toff(this, EVENTS, this);\n\t\tthis._resize?.disconnect();\n\t\tthis._observer?.disconnect();\n\t\tthis._observer = this._resize = undefined;\n\t}\n\tattributeChangedCallback() {\n\t\tArray.from(this.shadowRoot?.children || []).map((el) => el.remove()); // Clear shadowRoot\n\n\t\tconst [variant, type] = (attr(this, \"data-variant\") || \"column\").split(\"-\");\n\t\tconst aspect = attr(this, \"data-aspect\") || undefined;\n\t\tconst data = toData(this.querySelector(\"table\"));\n\t\tconst style = tag(\"style\", {}, css);\n\t\tconst legend = tag(\"div\", { class: \"legends\" });\n\t\tdata.slice(1).forEach(([{ value, style }]) => {\n\t\t\tlegend.appendChild(tag(\"div\", { class: \"legend\", style }, value));\n\t\t});\n\n\t\tconst { axis, groups, total } = toAxis(data, { aspect, type });\n\t\tif (variant === \"column\" || variant === \"bar\")\n\t\t\tgroups.append(...toBars(data));\n\t\tif (variant === \"line\" || variant === \"area\")\n\t\t\tgroups.append(toLines(data, { total, variant, type }));\n\t\tif (variant === \"doughnut\" || variant === \"pie\")\n\t\t\tthis.shadowRoot?.append(toPies(data, { aspect, variant }));\n\n\t\tthis.shadowRoot?.append(axis, legend, style); // Axis must be first\n\t}\n\thandleEvent(e: Event) {\n\t\tif (e.type === \"click\" || e.type === \"keydown\") onClick(e, this);\n\t\telse onMoveTooltip(e as MouseEvent);\n\t}\n\thandleResize() {\n\t\tconst axis = this.shadowRoot?.firstElementChild as HTMLElement | null;\n\t\tconst steps = axis?.firstElementChild as HTMLElement | null;\n\t\taxis?.classList.toggle(\"axisStepsYHalf\", (steps?.offsetHeight || 0) < 400);\n\t\taxis?.classList.toggle(\"axisStepsXHalf\", (steps?.offsetWidth || 0) < 500);\n\t}\n}\n\nfunction onClick(event: Event, self: MTDSChartElement) {\n\tif (event instanceof KeyboardEvent && event.key !== \"Enter\") return; // Only handle enter key\n\tconst el = event.composedPath()[0];\n\tconst table = self.querySelector(\"table\");\n\tconst [tr, td] =\n\t\t(el instanceof Element && attr(el, \"data-event\")?.split(\"-\").map(Number)) ||\n\t\t[];\n\n\ttable?.rows[tr]?.cells[td]?.querySelector<HTMLElement>(\"a,button\")?.click?.();\n}\n\nlet TOOLTIP_TEXT = \"\";\nfunction onMoveTooltip(event: MouseEvent) {\n\tif (!TOOLTIP) return;\n\tif (!TOOLTIP?.isConnected) document.body.append(TOOLTIP); // Ensure connected\n\n\tconst el = event.composedPath()[0];\n\tconst tip = (el instanceof Element && el.getAttribute(\"aria-label\")) || \"\";\n\n\tif (tip)\n\t\tTOOLTIP.style.transform = `translate(${event.pageX}px, ${event.pageY}px)`;\n\tif (tip !== TOOLTIP_TEXT) {\n\t\tif (tip) TOOLTIP.textContent = tip;\n\t\tTOOLTIP_TEXT = tip;\n\t\tTOOLTIP.hidden = !tip;\n\t}\n}\n\nconst text = (el?: Element | null) => el?.textContent?.trim() || \"\"; // Helper to get trimmed text\nconst toData = (table?: HTMLTableElement | null) =>\n\tArray.from(table?.rows || [], (row, rowIndex) =>\n\t\tArray.from(row.cells, (cell, cellIndex) => {\n\t\t\tconst rowHeading = text(row.cells[0]);\n\t\t\tconst colHeading = text(table?.rows[0].cells[cellIndex]);\n\t\t\tconst tooltip = `${rowHeading}: ${text(cell)}${colHeading ? ` (${colHeading})` : \"\"}`;\n\n\t\t\treturn {\n\t\t\t\tnumber: (cellIndex && rowIndex && Number.parseFloat(text(cell))) || 0, // First row and column is not a number\n\t\t\t\tevent: cell.querySelector(\"a,button\") && `${rowIndex}-${cellIndex}`, // Reference to proxy events\n\t\t\t\tstyle: `--color: var(--mtdsc-chart-color-${rowIndex}, var(--mtdsc-chart-color-base))`,\n\t\t\t\tvalue: text(cell),\n\t\t\t\ttooltip: attr(cell, \"data-tooltip\") || tooltip,\n\t\t\t};\n\t\t}),\n\t);\n\nif (IS_BROWSER && !window.customElements.get(\"mtds-chart\"))\n\twindow.customElements.define(\"mtds-chart\", MTDSChartElement);\n"],"names":["EVENTS","TOOLTIP_ID","TOOLTIP","IS_BROWSER","tag","styles","MTDSChartElement","MTDSElement","on","off","el","variant","type","attr","aspect","data","toData","style","css","legend","value","axis","groups","total","toAxis","toBars","toLines","toPies","e","onClick","steps","event","self","table","tr","td","TOOLTIP_TEXT","onMoveTooltip","tip","text","row","rowIndex","cell","cellIndex","rowHeading","colHeading","tooltip"],"mappings":";;;;;;;AAUA,MAAMA,IAAS,oCACTC,IAAa,sBACbC,IAAUC,IACb,SAAS,eAAeF,CAAU,KACnCG,EAAI,OAAO,EAAE,OAAOC,EAAO,UAAU,IAAIJ,GAAY,QAAQ,GAAA,CAAI,IAChE;AAEI,MAAMK,UAAyBC,EAAY;AAAA,EACjD;AAAA;AAAA,EACA;AAAA,EAEA,WAAW,qBAAqB;AAC/B,WAAO,CAAC,gBAAgB,aAAa;AAAA,EACtC;AAAA,EACA,cAAc;AACb,UAAA,GACA,KAAK,a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as a } from "../utils.js";
|
|
2
|
+
function E(e, { total: t, type: n, variant: o }) {
|
|
3
|
+
const s = Number.parseFloat(n || "0") || 0, r = m("div", { class: "axisGroup" });
|
|
4
|
+
return e.slice(1).forEach(([, ...l]) => {
|
|
5
|
+
const d = m("div", {
|
|
6
6
|
class: "lineContainer",
|
|
7
7
|
role: "list",
|
|
8
|
-
style:
|
|
9
|
-
}),
|
|
10
|
-
|
|
11
|
-
100 / (
|
|
12
|
-
100 -
|
|
8
|
+
style: l[0].style
|
|
9
|
+
}), h = C(
|
|
10
|
+
l.map(({ number: c }, u, { length: $ }) => [
|
|
11
|
+
100 / ($ - 1) * u,
|
|
12
|
+
100 - c / t * 100
|
|
13
13
|
]),
|
|
14
|
-
|
|
15
|
-
),
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
const
|
|
20
|
-
c
|
|
14
|
+
s / 100
|
|
15
|
+
), p = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
16
|
+
a(p, "aria-hidden", "true"), a(p, "preserveAspectRatio", "none"), a(p, "viewBox", "0 0 100 100");
|
|
17
|
+
const i = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
18
|
+
if (a(i, "class", "line"), a(i, "d", h), a(i, "fill", "none"), a(i, "stroke", "currentColor"), o === "area") {
|
|
19
|
+
const c = i.cloneNode(!0);
|
|
20
|
+
a(c, "d", `M-100,100 L${h.slice(1)}L200,100`), a(c, "class", "lineShade"), p.append(c);
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"aria-label":
|
|
27
|
-
"data-event":
|
|
22
|
+
l.forEach(({ number: c, tooltip: u, event: $ }) => {
|
|
23
|
+
const g = m("div", { role: "listitem" });
|
|
24
|
+
g.appendChild(
|
|
25
|
+
m("div", {
|
|
26
|
+
"aria-label": u,
|
|
27
|
+
"data-event": $,
|
|
28
28
|
tabindex: "0",
|
|
29
29
|
class: "linePoint",
|
|
30
30
|
role: "img",
|
|
31
|
-
style: `--value: ${
|
|
31
|
+
style: `--value: ${c}`
|
|
32
32
|
})
|
|
33
|
-
), d.append(
|
|
34
|
-
}), d.appendChild(
|
|
35
|
-
}),
|
|
33
|
+
), d.append(g);
|
|
34
|
+
}), d.appendChild(p).append(i), r.append(d);
|
|
35
|
+
}), r;
|
|
36
36
|
}
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
return `C ${
|
|
37
|
+
const C = (e, t) => e.map(([n, o], s, r) => s ? b(s, r, t) : `M${n},${o}`).join(" "), v = ([e, t], [n, o]) => [e + n, t + o], w = ([e, t], [n, o]) => [e - n, t - o], f = (e, [t, n]) => [e * t, e * n], b = (e, t, n) => {
|
|
38
|
+
const o = t[e - 1], s = t[e], [r, l] = v(o, f(n, w(s, t[e - 2] || o))), [d, h] = v(s, f(n, w(o, t[e + 1] || s)));
|
|
39
|
+
return `C ${r},${l} ${d},${h} ${s[0]},${s[1]}`;
|
|
40
40
|
};
|
|
41
41
|
export {
|
|
42
42
|
E as toLines
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-lines.js","sources":["../../designsystem/chart/chart-lines.ts"],"sourcesContent":["import { attr, tag } from \"../utils\";\nimport type { ChartData } from \"./chart-element\";\n\ntype Config = {\n\ttotal: number;\n\ttype: string;\n\tvariant: string;\n};\n\nexport function toLines(data: ChartData, { total, variant }: Config) {\n\tconst smoothing =
|
|
1
|
+
{"version":3,"file":"chart-lines.js","sources":["../../designsystem/chart/chart-lines.ts"],"sourcesContent":["import { attr, tag } from \"../utils\";\nimport type { ChartData } from \"./chart-element\";\n\ntype Config = {\n\ttotal: number;\n\ttype: string;\n\tvariant: string;\n};\n\nexport function toLines(data: ChartData, { total, type, variant }: Config) {\n\tconst smoothing = Number.parseFloat(type || \"0\") || 0;\n\tconst group = tag(\"div\", { class: \"axisGroup\" });\n\tdata.slice(1).forEach(([, ...values]) => {\n\t\tconst lineContainer = tag(\"div\", {\n\t\t\tclass: `lineContainer`,\n\t\t\trole: \"list\",\n\t\t\tstyle: values[0].style,\n\t\t});\n\n\t\tconst pathDefintion = toPath(\n\t\t\tvalues.map(({ number }, index, { length }) => [\n\t\t\t\t(100 / (length - 1)) * index,\n\t\t\t\t100 - (number / total) * 100,\n\t\t\t]),\n\t\t\tsmoothing / 100,\n\t\t);\n\n\t\tconst line = document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\");\n\t\tattr(line, \"aria-hidden\", \"true\");\n\t\tattr(line, \"preserveAspectRatio\", \"none\");\n\t\tattr(line, \"viewBox\", \"0 0 100 100\");\n\n\t\tconst path = document.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n\t\tattr(path, \"class\", \"line\");\n\t\tattr(path, \"d\", pathDefintion);\n\t\tattr(path, \"fill\", \"none\");\n\t\tattr(path, \"stroke\", \"currentColor\");\n\n\t\tif (variant === \"area\") {\n\t\t\tconst lineShade = path.cloneNode(true) as SVGPathElement;\n\t\t\tattr(lineShade, \"d\", `M-100,100 L${pathDefintion.slice(1)}L200,100`);\n\t\t\tattr(lineShade, \"class\", \"lineShade\");\n\t\t\tline.append(lineShade);\n\t\t}\n\n\t\tvalues.forEach(({ number, tooltip, event }) => {\n\t\t\tconst col = tag(\"div\", { role: \"listitem\" });\n\t\t\tcol.appendChild(\n\t\t\t\ttag(\"div\", {\n\t\t\t\t\t\"aria-label\": tooltip,\n\t\t\t\t\t\"data-event\": event,\n\t\t\t\t\ttabindex: \"0\",\n\t\t\t\t\tclass: \"linePoint\",\n\t\t\t\t\trole: \"img\",\n\t\t\t\t\tstyle: `--value: ${number}`,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tlineContainer.append(col);\n\t\t});\n\n\t\tlineContainer.appendChild(line).append(path);\n\t\tgroup.append(lineContainer);\n\t});\n\treturn group;\n}\n\n// Based on https://observablehq.com/@ndry/smooth-a-svg-path-with-cubic-bezier-curves\nconst toPath = (points: number[][], s: number) =>\n\tpoints.map(([x, y], i, a) => (i ? smooth(i, a, s) : `M${x},${y}`)).join(\" \");\nconst add = ([ax, ay]: number[], [bx, by]: number[]) => [ax + bx, ay + by];\nconst sub = ([ax, ay]: number[], [bx, by]: number[]) => [ax - bx, ay - by];\nconst scale = (s: number, [x, y]: number[]) => [s * x, s * y];\nconst smooth = (i: number, all: number[][], smooth: number) => {\n\tconst start = all[i - 1];\n\tconst end = all[i];\n\tconst [csX, csY] = add(start, scale(smooth, sub(end, all[i - 2] || start))); // start control point\n\tconst [ceX, ceY] = add(end, scale(smooth, sub(start, all[i + 1] || end))); // end control point\n\treturn `C ${csX},${csY} ${ceX},${ceY} ${end[0]},${end[1]}`;\n};\n"],"names":["toLines","data","total","type","variant","smoothing","group","tag","lineContainer","values","pathDefintion","toPath","number","index","length","line","attr","path","lineShade","tooltip","event","col","points","s","x","y","i","a","smooth","add","ax","ay","bx","by","sub","scale","all","start","end","csX","csY","ceX","ceY"],"mappings":";AASO,SAASA,EAAQC,GAAiB,EAAE,OAAAC,GAAO,MAAAC,GAAM,SAAAC,KAAmB;AAC1E,QAAMC,IAAY,OAAO,WAAWF,KAAQ,GAAG,KAAK,GAC9CG,IAAQC,EAAI,OAAO,EAAE,OAAO,aAAa;AAC/C,SAAAN,EAAK,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAA,MAAY,MAAM;AACxC,UAAMO,IAAgBD,EAAI,OAAO;AAAA,MAChC,OAAO;AAAA,MACP,MAAM;AAAA,MACN,OAAOE,EAAO,CAAC,EAAE;AAAA,IAAA,CACjB,GAEKC,IAAgBC;AAAA,MACrBF,EAAO,IAAI,CAAC,EAAE,QAAAG,KAAUC,GAAO,EAAE,QAAAC,QAAa;AAAA,QAC5C,OAAOA,IAAS,KAAMD;AAAA,QACvB,MAAOD,IAASV,IAAS;AAAA,MAAA,CACzB;AAAA,MACDG,IAAY;AAAA,IAAA,GAGPU,IAAO,SAAS,gBAAgB,8BAA8B,KAAK;AACzE,IAAAC,EAAKD,GAAM,eAAe,MAA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EC,IAAM,CAAC,CAACJ,GAAIC,CAAE,GAAa,CAACC,GAAIC,CAAE,MAAgB,CAACH,IAAKE,GAAID,IAAKE,CAAE,GACnEE,IAAQ,CAACZ,GAAW,CAACC,GAAGC,CAAC,MAAgB,CAACF,IAAIC,GAAGD,IAAIE,CAAC,GACtDG,IAAS,CAACF,GAAWU,GAAiBR,MAAmB;AAC9D,QAAMS,IAAQD,EAAIV,IAAI,CAAC,GACjBY,IAAMF,EAAIV,CAAC,GACX,CAACa,GAAKC,CAAG,IAAIX,EAAIQ,GAAOF,EAAMP,GAAQM,EAAII,GAAKF,EAAIV,IAAI,CAAC,KAAKW,CAAK,CAAC,CAAC,GACpE,CAACI,GAAKC,CAAG,IAAIb,EAAIS,GAAKH,EAAMP,GAAQM,EAAIG,GAAOD,EAAIV,IAAI,CAAC,KAAKY,CAAG,CAAC,CAAC;AACxE,SAAO,KAAKC,CAAG,IAAIC,CAAG,IAAIC,CAAG,IAAIC,CAAG,IAAIJ,EAAI,CAAC,CAAC,IAAIA,EAAI,CAAC,CAAC;AACzD;"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { ChartData } from './chart-element';
|
|
2
|
-
|
|
2
|
+
type Options = {
|
|
3
|
+
aspect?: string;
|
|
3
4
|
variant: string;
|
|
4
|
-
}
|
|
5
|
+
};
|
|
6
|
+
export declare function toPies(data: ChartData, { aspect, variant }: Options): SVGSVGElement;
|
|
7
|
+
export {};
|
package/mtds/chart/chart-pies.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { attr as
|
|
2
|
-
function E(h, { variant:
|
|
3
|
-
const
|
|
4
|
-
|
|
1
|
+
import { attr as s } from "../utils.js";
|
|
2
|
+
function E(h, { aspect: l, variant: v }) {
|
|
3
|
+
const o = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
4
|
+
l && o.style.setProperty("--mtdsc-chart-aspect", l), s(o, "class", "pie"), s(o, "viewBox", "0 0 100 100");
|
|
5
5
|
let a = 0;
|
|
6
|
-
const t = 50, e =
|
|
7
|
-
return h.slice(1).forEach(([, { tooltip: r, number: c, event:
|
|
6
|
+
const t = 50, e = v === "doughnut" ? 25 : 0, d = h.slice(1).reduce((r, [, c]) => r + c.number, 0);
|
|
7
|
+
return h.slice(1).forEach(([, { tooltip: r, number: c, event: x, style: y }]) => {
|
|
8
8
|
if (!c) return;
|
|
9
|
-
const
|
|
9
|
+
const n = document.createElementNS("http://www.w3.org/2000/svg", "path"), p = a / d;
|
|
10
10
|
a += c;
|
|
11
|
-
const
|
|
12
|
-
n
|
|
13
|
-
}),
|
|
11
|
+
const m = Math.min(a / d, 0.99999), u = m - p > 0.5 ? 1 : 0, w = 2 * Math.PI * (p - 0.25), g = 2 * Math.PI * (m - 0.25), i = Math.cos(w), $ = Math.sin(w), M = Math.cos(g), f = Math.sin(g), P = `M ${t + e * i} ${t + e * $} L ${t + t * i} ${t + t * $} A ${t} ${t} 0 ${u} 1 ${t + t * M} ${t + t * f} L ${t + e * M} ${t + e * f} A ${e} ${e} 0 ${u} 0 ${t + e * i} ${t + e * $}`;
|
|
12
|
+
s(n, "aria-label", r), s(n, "data-event", x), s(n, "style", y), s(n, "d", P), s(n, "role", "img"), s(n, "tabindex", "0"), o.appendChild(n);
|
|
13
|
+
}), o;
|
|
14
14
|
}
|
|
15
15
|
export {
|
|
16
16
|
E as toPies
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-pies.js","sources":["../../designsystem/chart/chart-pies.ts"],"sourcesContent":["import { attr } from \"../utils\";\nimport type { ChartData } from \"./chart-element\";\n\nexport function toPies(data: ChartData, { variant }:
|
|
1
|
+
{"version":3,"file":"chart-pies.js","sources":["../../designsystem/chart/chart-pies.ts"],"sourcesContent":["import { attr } from \"../utils\";\nimport type { ChartData } from \"./chart-element\";\n\ntype Options = { aspect?: string; variant: string };\n\nexport function toPies(data: ChartData, { aspect, variant }: Options) {\n\tconst pie = document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\");\n\tif (aspect) pie.style.setProperty(\"--mtdsc-chart-aspect\", aspect);\n\tattr(pie, \"class\", \"pie\");\n\tattr(pie, \"viewBox\", \"0 0 100 100\");\n\n\tlet offset = 0;\n\tconst radius = 50;\n\tconst inner = variant === \"doughnut\" ? 25 : 0;\n\tconst total = data.slice(1).reduce((tot, [, td]) => tot + td.number, 0);\n\n\tdata.slice(1).forEach(([, { tooltip, number, event, style }]) => {\n\t\tif (!number) return; // Skip empty\n\t\tconst path = document.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n\t\tconst start = offset / total;\n\t\toffset += number;\n\t\tconst end = Math.min(offset / total, 0.99999); // Ensure full circle works\n\t\tconst largeArc = end - start > 0.5 ? 1 : 0;\n\t\tconst a0 = 2 * Math.PI * (start - 0.25);\n\t\tconst a1 = 2 * Math.PI * (end - 0.25);\n\t\tconst x0 = Math.cos(a0);\n\t\tconst y0 = Math.sin(a0);\n\t\tconst x1 = Math.cos(a1);\n\t\tconst y1 = Math.sin(a1);\n\t\tconst d = `M ${radius + inner * x0} ${radius + inner * y0} L ${radius + radius * x0} ${radius + radius * y0} A ${radius} ${radius} 0 ${largeArc} 1 ${radius + radius * x1} ${radius + radius * y1} L ${radius + inner * x1} ${radius + inner * y1} A ${inner} ${inner} 0 ${largeArc} 0 ${radius + inner * x0} ${radius + inner * y0}`;\n\n\t\tattr(path, \"aria-label\", tooltip);\n\t\tattr(path, \"data-event\", event);\n\t\tattr(path, \"style\", style);\n\t\tattr(path, \"d\", d);\n\t\tattr(path, \"role\", \"img\");\n\t\tattr(path, \"tabindex\", \"0\");\n\t\tpie.appendChild(path);\n\t});\n\treturn pie;\n}\n"],"names":["toPies","data","aspect","variant","pie","attr","offset","radius","inner","total","tot","td","tooltip","number","event","style","path","start","end","largeArc","a0","a1","x0","y0","x1","y1","d"],"mappings":";AAKO,SAASA,EAAOC,GAAiB,EAAE,QAAAC,GAAQ,SAAAC,KAAoB;AACrE,QAAMC,IAAM,SAAS,g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