@mintplayer/web-components 2.10.0 → 2.12.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/accordion/index.mjs +4 -4
- package/charts/core/index.d.ts +1 -0
- package/charts/core/index.mjs +19 -0
- package/charts/core/src/arc.d.ts +28 -0
- package/charts/core/src/color.d.ts +11 -0
- package/charts/core/src/hierarchy-layout.d.ts +68 -0
- package/charts/core/src/index.d.ts +5 -0
- package/charts/core/src/scale.d.ts +21 -0
- package/charts/core/src/types.d.ts +52 -0
- package/charts/hierarchy/index.d.ts +1 -0
- package/charts/hierarchy/index.mjs +816 -0
- package/charts/hierarchy/src/components/index.d.ts +1 -0
- package/charts/hierarchy/src/components/mp-hierarchy-chart.d.ts +188 -0
- package/charts/hierarchy/src/index.d.ts +2 -0
- package/charts/hierarchy/src/styles/hierarchy-chart.styles.d.ts +2 -0
- package/charts/hierarchy/src/styles/index.d.ts +1 -0
- package/charts/sparkline/index.d.ts +1 -0
- package/charts/sparkline/index.mjs +162 -0
- package/charts/sparkline/src/components/index.d.ts +1 -0
- package/charts/sparkline/src/components/mp-sparkline.d.ts +51 -0
- package/charts/sparkline/src/index.d.ts +1 -0
- package/charts/sparkline/src/styles/index.d.ts +1 -0
- package/charts/sparkline/src/styles/sparkline.styles.d.ts +2 -0
- package/charts/trend/index.d.ts +1 -0
- package/charts/trend/index.mjs +432 -0
- package/charts/trend/src/components/index.d.ts +1 -0
- package/charts/trend/src/components/mp-trend-chart.d.ts +104 -0
- package/charts/trend/src/index.d.ts +2 -0
- package/charts/trend/src/styles/index.d.ts +1 -0
- package/charts/trend/src/styles/trend-chart.styles.d.ts +2 -0
- package/checkbox/index.mjs +1 -1
- package/chunks/color-5yPBn70k.mjs +179 -0
- package/chunks/{form-check.styles-jBlHetYX.mjs → form-check.styles-B0pxJ6YC.mjs} +2 -2
- package/chunks/{form-control.styles-BOTBdmvg.mjs → form-control.styles-C3j87Sn3.mjs} +1 -1
- package/chunks/{mp-checkbox-6EJwdUIn.mjs → mp-checkbox-CzwS7Y_t.mjs} +2 -2
- package/chunks/{mp-datatable-25O1GtvU.mjs → mp-datatable-GmKqaN8y.mjs} +1 -1
- package/chunks/{mp-radio-DvKgrTFL.mjs → mp-radio-cL46sUA0.mjs} +2 -2
- package/chunks/{mp-select-lHP00OBH.mjs → mp-select-BNrbPwN4.mjs} +1 -1
- package/chunks/{mp-toggle-button-C4Loq_p4.mjs → mp-toggle-button-eo_aTQtu.mjs} +32 -32
- package/chunks/scale-B0bRUdc7.mjs +91 -0
- package/code-snippet/index.mjs +788 -176
- package/code-snippet/src/core/highlighter.d.ts +39 -0
- package/code-snippet/src/core/split-lines.d.ts +44 -0
- package/code-snippet/src/hljs-loaders.generated.d.ts +14 -0
- package/code-snippet/src/index.d.ts +2 -0
- package/code-snippet/src/mp-code-snippet.element.d.ts +172 -2
- package/code-snippet/src/styles/code-snippet.styles.d.ts +2 -0
- package/code-snippet/src/styles/index.d.ts +1 -0
- package/code-snippet/src/types/code-line-annotation.d.ts +29 -0
- package/code-snippet/src/types/index.d.ts +1 -0
- package/datatable/index.mjs +1 -1
- package/file-manager/index.mjs +1 -1
- package/package.json +17 -1
- package/phone-input/index.mjs +26 -12
- package/phone-input/src/components/mp-phone-input.d.ts +9 -0
- package/query-builder/index.mjs +101 -101
- package/radio/index.mjs +1 -1
- package/radio-group/index.mjs +1 -1
- package/scheduler/index.mjs +3 -3
- package/select/index.mjs +1 -1
- package/toggle-button/index.mjs +1 -1
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import { unsafeCSS as A, LitElement as F, nothing as b, svg as y, html as I } from "lit";
|
|
2
|
+
import { repeat as k } from "lit/directives/repeat.js";
|
|
3
|
+
import { l as $, a as q, t as O, n as K } from "../../chunks/scale-B0bRUdc7.mjs";
|
|
4
|
+
const U = A(`:host {
|
|
5
|
+
display: block;
|
|
6
|
+
width: 100%;
|
|
7
|
+
aspect-ratio: 16/9;
|
|
8
|
+
--mp-trend-chart-grid-color: var(--bs-border-color, #dee2e6);
|
|
9
|
+
--mp-trend-chart-axis-color: var(--bs-secondary-color, #6c757d);
|
|
10
|
+
--mp-trend-chart-goal-color: var(--bs-warning, #ffc107);
|
|
11
|
+
--mp-trend-chart-tooltip-bg: var(--bs-dark, #212529);
|
|
12
|
+
--mp-trend-chart-tooltip-color: var(--bs-light, #f8f9fa);
|
|
13
|
+
--mp-trend-chart-focus-ring-color: var(--bs-primary, #0d6efd);
|
|
14
|
+
--mp-trend-chart-crosshair-color: var(--bs-secondary-color, #6c757d);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
* {
|
|
18
|
+
box-sizing: border-box;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.chart {
|
|
22
|
+
position: relative;
|
|
23
|
+
width: 100%;
|
|
24
|
+
height: 100%;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
svg {
|
|
28
|
+
display: block;
|
|
29
|
+
width: 100%;
|
|
30
|
+
height: 100%;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.grid line {
|
|
34
|
+
stroke: var(--mp-trend-chart-grid-color);
|
|
35
|
+
stroke-width: 1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.axis text {
|
|
39
|
+
fill: var(--mp-trend-chart-axis-color);
|
|
40
|
+
font-size: 22px; /* logical viewBox units */
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.axis .y-label {
|
|
44
|
+
text-anchor: end;
|
|
45
|
+
dominant-baseline: middle;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.axis .x-label {
|
|
49
|
+
text-anchor: middle;
|
|
50
|
+
dominant-baseline: hanging;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.series-line {
|
|
54
|
+
fill: none;
|
|
55
|
+
stroke-width: 4;
|
|
56
|
+
stroke-linejoin: round;
|
|
57
|
+
stroke-linecap: round;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.series-area {
|
|
61
|
+
opacity: 0.25;
|
|
62
|
+
stroke: none;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.goal-line {
|
|
66
|
+
stroke: var(--mp-trend-chart-goal-color);
|
|
67
|
+
stroke-width: 3;
|
|
68
|
+
stroke-dasharray: 10 8;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.goal-label {
|
|
72
|
+
fill: var(--mp-trend-chart-goal-color);
|
|
73
|
+
font-size: 22px;
|
|
74
|
+
text-anchor: end;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.crosshair {
|
|
78
|
+
stroke: var(--mp-trend-chart-crosshair-color);
|
|
79
|
+
stroke-width: 1;
|
|
80
|
+
stroke-dasharray: 4 4;
|
|
81
|
+
pointer-events: none;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.point {
|
|
85
|
+
fill: transparent;
|
|
86
|
+
stroke: none;
|
|
87
|
+
cursor: pointer;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.point:focus {
|
|
91
|
+
outline: none;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* Drawn focus/hover marker: the point becomes a visible dot. */
|
|
95
|
+
.point:focus-visible,
|
|
96
|
+
.point[data-hovered] {
|
|
97
|
+
fill: currentColor;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.point:focus-visible {
|
|
101
|
+
stroke: var(--mp-trend-chart-focus-ring-color);
|
|
102
|
+
stroke-width: 4;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.chart-tooltip {
|
|
106
|
+
position: absolute;
|
|
107
|
+
display: none;
|
|
108
|
+
max-width: 60%;
|
|
109
|
+
padding: 0.25rem 0.5rem;
|
|
110
|
+
background: var(--mp-trend-chart-tooltip-bg);
|
|
111
|
+
color: var(--mp-trend-chart-tooltip-color);
|
|
112
|
+
border-radius: 0.25rem;
|
|
113
|
+
font-size: 0.8125rem;
|
|
114
|
+
pointer-events: none;
|
|
115
|
+
z-index: 1;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.chart-tooltip[data-visible] {
|
|
119
|
+
display: block;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.visually-hidden {
|
|
123
|
+
position: absolute;
|
|
124
|
+
width: 1px;
|
|
125
|
+
height: 1px;
|
|
126
|
+
overflow: hidden;
|
|
127
|
+
clip-path: inset(50%);
|
|
128
|
+
white-space: nowrap;
|
|
129
|
+
}`), M = ["#0d6efd", "#21b577", "#fd7e14", "#6f42c1", "#d63384", "#20c997", "#dc3545", "#6c757d"], g = 1e3, x = 562, l = { top: 20, right: 20, bottom: 48, left: 72 };
|
|
130
|
+
class _ extends F {
|
|
131
|
+
constructor() {
|
|
132
|
+
super(...arguments), this._series = [], this._area = !0, this._stacked = !1, this._inputLabel = null, this._placed = [], this._focusedKey = null, this._restoreFocus = !1, this._hoveredKey = null;
|
|
133
|
+
}
|
|
134
|
+
static {
|
|
135
|
+
this.styles = [U];
|
|
136
|
+
}
|
|
137
|
+
static get observedAttributes() {
|
|
138
|
+
return [
|
|
139
|
+
...super.observedAttributes ?? [],
|
|
140
|
+
"area",
|
|
141
|
+
"stacked",
|
|
142
|
+
"y-min",
|
|
143
|
+
"y-max",
|
|
144
|
+
"goal",
|
|
145
|
+
"goal-label",
|
|
146
|
+
"locale",
|
|
147
|
+
"summary",
|
|
148
|
+
"aria-label",
|
|
149
|
+
"input-label"
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
get series() {
|
|
153
|
+
return this._series;
|
|
154
|
+
}
|
|
155
|
+
set series(t) {
|
|
156
|
+
this._series = Array.isArray(t) ? t : [], this.requestUpdate();
|
|
157
|
+
}
|
|
158
|
+
get area() {
|
|
159
|
+
return this._area;
|
|
160
|
+
}
|
|
161
|
+
set area(t) {
|
|
162
|
+
this._area = !!t, this.requestUpdate();
|
|
163
|
+
}
|
|
164
|
+
get stacked() {
|
|
165
|
+
return this._stacked;
|
|
166
|
+
}
|
|
167
|
+
set stacked(t) {
|
|
168
|
+
this._stacked = !!t, this.requestUpdate();
|
|
169
|
+
}
|
|
170
|
+
get yMin() {
|
|
171
|
+
return this._yMin;
|
|
172
|
+
}
|
|
173
|
+
set yMin(t) {
|
|
174
|
+
this._yMin = t == null ? void 0 : Number(t), this.requestUpdate();
|
|
175
|
+
}
|
|
176
|
+
get yMax() {
|
|
177
|
+
return this._yMax;
|
|
178
|
+
}
|
|
179
|
+
set yMax(t) {
|
|
180
|
+
this._yMax = t == null ? void 0 : Number(t), this.requestUpdate();
|
|
181
|
+
}
|
|
182
|
+
get goal() {
|
|
183
|
+
return this._goal;
|
|
184
|
+
}
|
|
185
|
+
set goal(t) {
|
|
186
|
+
this._goal = t == null ? void 0 : Number(t), this.requestUpdate();
|
|
187
|
+
}
|
|
188
|
+
get goalLabel() {
|
|
189
|
+
return this._goalLabel;
|
|
190
|
+
}
|
|
191
|
+
set goalLabel(t) {
|
|
192
|
+
this._goalLabel = t || void 0, this.requestUpdate();
|
|
193
|
+
}
|
|
194
|
+
get locale() {
|
|
195
|
+
return this._locale;
|
|
196
|
+
}
|
|
197
|
+
set locale(t) {
|
|
198
|
+
this._locale = t || void 0, this.requestUpdate();
|
|
199
|
+
}
|
|
200
|
+
get summary() {
|
|
201
|
+
return this._summary;
|
|
202
|
+
}
|
|
203
|
+
set summary(t) {
|
|
204
|
+
this._summary = t || void 0, this.requestUpdate();
|
|
205
|
+
}
|
|
206
|
+
get inputLabel() {
|
|
207
|
+
return this._inputLabel;
|
|
208
|
+
}
|
|
209
|
+
set inputLabel(t) {
|
|
210
|
+
this._inputLabel = t ?? null, this.requestUpdate();
|
|
211
|
+
}
|
|
212
|
+
get summaryFormatter() {
|
|
213
|
+
return this._summaryFormatter;
|
|
214
|
+
}
|
|
215
|
+
set summaryFormatter(t) {
|
|
216
|
+
this._summaryFormatter = t, this.requestUpdate();
|
|
217
|
+
}
|
|
218
|
+
get tooltipFormatter() {
|
|
219
|
+
return this._tooltipFormatter;
|
|
220
|
+
}
|
|
221
|
+
set tooltipFormatter(t) {
|
|
222
|
+
this._tooltipFormatter = t;
|
|
223
|
+
}
|
|
224
|
+
attributeChangedCallback(t, i, e) {
|
|
225
|
+
switch (super.attributeChangedCallback(t, i, e), t) {
|
|
226
|
+
case "area":
|
|
227
|
+
this.area = e !== "false" && e !== null;
|
|
228
|
+
break;
|
|
229
|
+
case "stacked":
|
|
230
|
+
this.stacked = e !== null && e !== "false";
|
|
231
|
+
break;
|
|
232
|
+
case "y-min":
|
|
233
|
+
this.yMin = e === null ? void 0 : Number(e);
|
|
234
|
+
break;
|
|
235
|
+
case "y-max":
|
|
236
|
+
this.yMax = e === null ? void 0 : Number(e);
|
|
237
|
+
break;
|
|
238
|
+
case "goal":
|
|
239
|
+
this.goal = e === null ? void 0 : Number(e);
|
|
240
|
+
break;
|
|
241
|
+
case "goal-label":
|
|
242
|
+
this.goalLabel = e ?? void 0;
|
|
243
|
+
break;
|
|
244
|
+
case "locale":
|
|
245
|
+
this.locale = e ?? void 0;
|
|
246
|
+
break;
|
|
247
|
+
case "summary":
|
|
248
|
+
this.summary = e ?? void 0;
|
|
249
|
+
break;
|
|
250
|
+
case "aria-label":
|
|
251
|
+
this.requestUpdate();
|
|
252
|
+
break;
|
|
253
|
+
case "input-label":
|
|
254
|
+
this._inputLabel = e, this.requestUpdate();
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/* ---------- layout ---------- */
|
|
259
|
+
static toMs(t) {
|
|
260
|
+
return t instanceof Date ? t.getTime() : Number(t);
|
|
261
|
+
}
|
|
262
|
+
numberFormat() {
|
|
263
|
+
return new Intl.NumberFormat(this._locale || this.closest("[lang]")?.getAttribute("lang") || void 0);
|
|
264
|
+
}
|
|
265
|
+
dateFormat() {
|
|
266
|
+
return new Intl.DateTimeFormat(this._locale || this.closest("[lang]")?.getAttribute("lang") || void 0, {
|
|
267
|
+
dateStyle: "medium"
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
/** Plot every non-gap point; stacked series plot the running sum per x. */
|
|
271
|
+
place() {
|
|
272
|
+
const t = /* @__PURE__ */ new Map(), i = this._series.flatMap(
|
|
273
|
+
(n, v) => n.points.map((p, s) => ({ point: p, pi: s })).filter((p) => p.point.y !== null).map((p) => {
|
|
274
|
+
const s = _.toMs(p.point.x), f = (this._stacked ? t.get(s) ?? 0 : 0) + p.point.y;
|
|
275
|
+
return this._stacked && t.set(s, f), {
|
|
276
|
+
seriesId: n.id,
|
|
277
|
+
seriesLabel: n.label,
|
|
278
|
+
color: n.color ?? M[v % M.length],
|
|
279
|
+
point: p.point,
|
|
280
|
+
xMs: s,
|
|
281
|
+
yPlot: f,
|
|
282
|
+
px: 0,
|
|
283
|
+
py: 0,
|
|
284
|
+
seriesIndex: v,
|
|
285
|
+
pointIndex: p.pi
|
|
286
|
+
};
|
|
287
|
+
})
|
|
288
|
+
), e = i.map((n) => n.xMs), r = i.map((n) => n.yPlot), h = e.length ? [Math.min(...e), Math.max(...e)] : [0, 1], u = Math.min(...r.length ? r : [0], this._goal ?? 1 / 0, this._stacked ? 0 : 1 / 0), m = Math.max(...r.length ? r : [1], this._goal ?? -1 / 0), c = K(Math.min(u, m), Math.max(u, m)), o = [this._yMin ?? c[0], this._yMax ?? c[1]], a = $(h, [l.left, g - l.right]), d = $(o, [x - l.bottom, l.top]);
|
|
289
|
+
return i.map((n) => (n.px = a(n.xMs), n.py = d(n.yPlot), n)), { placed: i, xd: h, yd: o };
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Null points are dropped before placement, so a gap shows up as a jump in
|
|
293
|
+
* pointIndex between neighbours — each contiguous stretch is its own run.
|
|
294
|
+
*/
|
|
295
|
+
static runsOf(t) {
|
|
296
|
+
return t.reduce((i, e) => {
|
|
297
|
+
const r = i[i.length - 1];
|
|
298
|
+
return r?.length && e.pointIndex === r[r.length - 1].pointIndex + 1 ? [...i.slice(0, -1), [...r, e]] : [...i, [e]];
|
|
299
|
+
}, []);
|
|
300
|
+
}
|
|
301
|
+
linePath(t) {
|
|
302
|
+
return _.runsOf(t).map((i) => i.map((e, r) => `${r === 0 ? "M" : "L"} ${e.px} ${e.py}`).join(" ")).join(" ");
|
|
303
|
+
}
|
|
304
|
+
areaPath(t, i) {
|
|
305
|
+
return _.runsOf(t).filter((e) => e.length > 1).map((e) => `M ${e[0].px} ${i} ` + e.map((r) => `L ${r.px} ${r.py}`).join(" ") + ` L ${e[e.length - 1].px} ${i} Z`).join(" ");
|
|
306
|
+
}
|
|
307
|
+
/* ---------- interaction ---------- */
|
|
308
|
+
keyOf(t) {
|
|
309
|
+
return `${t.seriesId}\0${t.pointIndex}`;
|
|
310
|
+
}
|
|
311
|
+
pointName(t) {
|
|
312
|
+
const i = this.numberFormat(), e = typeof t.point.x == "number" && t.point.x < 1e7 ? i.format(t.point.x) : this.dateFormat().format(new Date(t.xMs));
|
|
313
|
+
return `${t.seriesLabel}, ${e}, ${t.point.y === null ? "—" : i.format(t.point.y)}`;
|
|
314
|
+
}
|
|
315
|
+
onPointerMove(t) {
|
|
316
|
+
if (!this._placed.length) return;
|
|
317
|
+
const e = this.shadowRoot?.querySelector(".chart")?.getBoundingClientRect();
|
|
318
|
+
if (!e || e.width === 0) return;
|
|
319
|
+
const r = (t.clientX - e.left) / e.width * g, h = (t.clientY - e.top) / e.height * x, u = this._placed.reduce((a, d) => Math.abs(d.px - r) < Math.abs(a.px - r) ? d : a), m = this._placed.filter((a) => a.xMs === u.xMs), c = m.reduce((a, d) => Math.abs(d.py - h) < Math.abs(a.py - h) ? d : a), o = this.shadowRoot?.querySelector(".chart-tooltip");
|
|
320
|
+
o && (o.textContent = this._tooltipFormatter?.(m) ?? m.map((a) => this.pointName(a)).join(" · "), o.style.left = `${t.clientX - e.left + 12}px`, o.style.top = `${t.clientY - e.top + 12}px`, o.setAttribute("data-visible", "")), this._hoveredKey !== this.keyOf(c) && (this._hoveredKey = this.keyOf(c), this.requestUpdate(), this.emit("trend-point-hover", { seriesId: c.seriesId, point: c.point }));
|
|
321
|
+
}
|
|
322
|
+
clearHover() {
|
|
323
|
+
this.shadowRoot?.querySelector(".chart-tooltip")?.removeAttribute("data-visible"), this._hoveredKey !== null && (this._hoveredKey = null, this.requestUpdate(), this.emit("trend-point-hover", { seriesId: null, point: null }));
|
|
324
|
+
}
|
|
325
|
+
onClick(t) {
|
|
326
|
+
const i = t.composedPath()[0]?.closest?.("[data-key]")?.getAttribute("data-key"), e = this._placed.find((r) => this.keyOf(r) === i);
|
|
327
|
+
e && this.emit("trend-point-select", { seriesId: e.seriesId, point: e.point });
|
|
328
|
+
}
|
|
329
|
+
onKeyDown(t) {
|
|
330
|
+
const i = t.composedPath()[0]?.closest?.("[data-key]")?.getAttribute("data-key"), e = this._placed.find((o) => this.keyOf(o) === i);
|
|
331
|
+
if (!e) return;
|
|
332
|
+
const r = this._placed.filter((o) => o.seriesId === e.seriesId).sort((o, a) => o.xMs - a.xMs), h = r.findIndex((o) => this.keyOf(o) === i), u = [...new Set(this._placed.map((o) => o.seriesId))], m = u.indexOf(e.seriesId), c = (o) => {
|
|
333
|
+
o && (this._focusedKey = this.keyOf(o), this._restoreFocus = !0, this.requestUpdate());
|
|
334
|
+
};
|
|
335
|
+
switch (t.key) {
|
|
336
|
+
case "ArrowRight":
|
|
337
|
+
c(r[h + 1]);
|
|
338
|
+
break;
|
|
339
|
+
case "ArrowLeft":
|
|
340
|
+
c(r[h - 1]);
|
|
341
|
+
break;
|
|
342
|
+
case "Home":
|
|
343
|
+
c(r[0]);
|
|
344
|
+
break;
|
|
345
|
+
case "End":
|
|
346
|
+
c(r[r.length - 1]);
|
|
347
|
+
break;
|
|
348
|
+
case "ArrowUp":
|
|
349
|
+
case "ArrowDown": {
|
|
350
|
+
const o = u[(m + (t.key === "ArrowDown" ? 1 : u.length - 1)) % u.length], a = this._placed.filter((d) => d.seriesId === o);
|
|
351
|
+
if (!a.length) return;
|
|
352
|
+
c(a.reduce((d, n) => Math.abs(n.xMs - e.xMs) < Math.abs(d.xMs - e.xMs) ? n : d));
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
case "Enter":
|
|
356
|
+
case " ":
|
|
357
|
+
this.emit("trend-point-select", { seriesId: e.seriesId, point: e.point });
|
|
358
|
+
break;
|
|
359
|
+
default:
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
t.preventDefault(), t.stopPropagation();
|
|
363
|
+
}
|
|
364
|
+
emit(t, i) {
|
|
365
|
+
this.dispatchEvent(new CustomEvent(t, { detail: i, bubbles: !0, composed: !0 }));
|
|
366
|
+
}
|
|
367
|
+
updated(t) {
|
|
368
|
+
super.updated(t), this._restoreFocus && this._focusedKey && (this._restoreFocus = !1, Array.from(this.shadowRoot?.querySelectorAll(".point") ?? []).find((e) => e.dataset.key === this._focusedKey)?.focus({ preventScroll: !0 }));
|
|
369
|
+
}
|
|
370
|
+
/* ---------- render ---------- */
|
|
371
|
+
groupLabel() {
|
|
372
|
+
return this.getAttribute("aria-label") ?? this._inputLabel;
|
|
373
|
+
}
|
|
374
|
+
render() {
|
|
375
|
+
const { placed: t, xd: i, yd: e } = this.place();
|
|
376
|
+
this._placed = t, this._focusedKey && t.some((s) => this.keyOf(s) === this._focusedKey) || (this._focusedKey = t.length ? this.keyOf(t[0]) : null);
|
|
377
|
+
const h = $(e, [x - l.bottom, l.top]), u = $(i, [l.left, g - l.right]), m = this.numberFormat(), c = q(e[0], e[1]).filter((s) => s >= e[0] && s <= e[1]), o = O(i[0], i[1], 6, this._locale), a = this._summaryFormatter?.(this._series) ?? this._summary, d = this.groupLabel(), n = h(Math.max(e[0], Math.min(e[1], this._stacked ? 0 : e[0]))), v = this._series.map((s, w) => ({
|
|
378
|
+
series: s,
|
|
379
|
+
color: s.color ?? M[w % M.length],
|
|
380
|
+
points: t.filter((f) => f.seriesId === s.id).sort((f, L) => f.xMs - L.xMs)
|
|
381
|
+
})), p = t.find((s) => this.keyOf(s) === this._hoveredKey);
|
|
382
|
+
return I`<div
|
|
383
|
+
class="chart"
|
|
384
|
+
@click=${this.onClick}
|
|
385
|
+
@keydown=${this.onKeyDown}
|
|
386
|
+
@pointermove=${this.onPointerMove}
|
|
387
|
+
@pointerleave=${this.clearHover}
|
|
388
|
+
>
|
|
389
|
+
<svg
|
|
390
|
+
viewBox="0 0 ${g} ${x}"
|
|
391
|
+
role="group"
|
|
392
|
+
aria-label=${d ?? b}
|
|
393
|
+
aria-describedby=${a ? "trend-summary" : b}
|
|
394
|
+
>
|
|
395
|
+
<g class="grid" aria-hidden="true">
|
|
396
|
+
${k(c, (s) => `y-${s}`, (s) => y`<line x1=${l.left} x2=${g - l.right} y1=${h(s)} y2=${h(s)}></line>`)}
|
|
397
|
+
</g>
|
|
398
|
+
<g class="axis" aria-hidden="true">
|
|
399
|
+
${k(c, (s) => `yl-${s}`, (s) => y`<text class="y-label" x=${l.left - 10} y=${h(s)}>${m.format(s)}</text>`)}
|
|
400
|
+
${k(o, (s) => `xl-${s.time}`, (s) => y`<text class="x-label" x=${u(s.time)} y=${x - l.bottom + 12}>${s.label}</text>`)}
|
|
401
|
+
</g>
|
|
402
|
+
${this._goal !== void 0 ? y`<g aria-hidden="true">
|
|
403
|
+
<line class="goal-line" x1=${l.left} x2=${g - l.right} y1=${h(this._goal)} y2=${h(this._goal)}></line>
|
|
404
|
+
${this._goalLabel ? y`<text class="goal-label" x=${g - l.right} y=${h(this._goal) - 8}>${this._goalLabel}</text>` : b}
|
|
405
|
+
</g>` : b}
|
|
406
|
+
${p ? y`<line class="crosshair" x1=${p.px} x2=${p.px} y1=${l.top} y2=${x - l.bottom}></line>` : b}
|
|
407
|
+
${k(v, (s) => s.series.id, (s) => y`<g aria-hidden="true">
|
|
408
|
+
${this._area ? y`<path class="series-area" fill=${s.color} d=${this.areaPath(s.points, n)}></path>` : b}
|
|
409
|
+
<path class="series-line" stroke=${s.color} d=${this.linePath(s.points)}></path>
|
|
410
|
+
</g>`)}
|
|
411
|
+
${k(t, (s) => this.keyOf(s), (s) => y`<circle
|
|
412
|
+
class="point"
|
|
413
|
+
data-key=${this.keyOf(s)}
|
|
414
|
+
?data-hovered=${this.keyOf(s) === this._hoveredKey}
|
|
415
|
+
cx=${s.px}
|
|
416
|
+
cy=${s.py}
|
|
417
|
+
r="9"
|
|
418
|
+
color=${s.color}
|
|
419
|
+
role="button"
|
|
420
|
+
tabindex=${this.keyOf(s) === this._focusedKey ? "0" : "-1"}
|
|
421
|
+
aria-label=${this.pointName(s)}
|
|
422
|
+
></circle>`)}
|
|
423
|
+
</svg>
|
|
424
|
+
${a ? I`<div id="trend-summary" class="visually-hidden">${a}</div>` : b}
|
|
425
|
+
<div class="chart-tooltip" aria-hidden="true"></div>
|
|
426
|
+
</div>`;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
typeof customElements < "u" && !customElements.get("mp-trend-chart") && customElements.define("mp-trend-chart", _);
|
|
430
|
+
export {
|
|
431
|
+
_ as MpTrendChart
|
|
432
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mp-trend-chart';
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { LitElement, PropertyValues, TemplateResult } from 'lit';
|
|
2
|
+
import { TrendPoint, TrendSeries } from '@mintplayer/web-components/charts/core';
|
|
3
|
+
interface PlacedPoint {
|
|
4
|
+
seriesId: string;
|
|
5
|
+
seriesLabel: string;
|
|
6
|
+
color: string;
|
|
7
|
+
point: TrendPoint;
|
|
8
|
+
xMs: number;
|
|
9
|
+
/** Plotted y (stacked charts plot the running sum). */
|
|
10
|
+
yPlot: number;
|
|
11
|
+
px: number;
|
|
12
|
+
py: number;
|
|
13
|
+
seriesIndex: number;
|
|
14
|
+
pointIndex: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `<mp-trend-chart>` — metric-over-time line/area chart (the codecov/Codacy
|
|
18
|
+
* coverage trend shape): multi-series, optional stacking (assumes aligned x
|
|
19
|
+
* samples), optional goal line, locale-aware calendar ticks.
|
|
20
|
+
*
|
|
21
|
+
* `y: null` renders a gap — forward-filling is the consumer's choice.
|
|
22
|
+
* No-JS tier: none; the demo registers in axe.spec.ts only.
|
|
23
|
+
*
|
|
24
|
+
* A11y: the svg is a named `role="group"`; every data point is a focusable
|
|
25
|
+
* `role="button"` circle ("series, date, value") behind ONE tab stop (roving);
|
|
26
|
+
* Left/Right walk points, Up/Down switch series, Home/End jump. The optional
|
|
27
|
+
* `summary` attribute (or `summaryFormatter`) is exposed via aria-describedby
|
|
28
|
+
* inside the same shadow tree (IDREFs never cross a root here).
|
|
29
|
+
*
|
|
30
|
+
* Events: `trend-point-hover`, `trend-point-select` (bubbling + composed).
|
|
31
|
+
*/
|
|
32
|
+
export declare class MpTrendChart extends LitElement {
|
|
33
|
+
static styles: import('lit').CSSResult[];
|
|
34
|
+
static get observedAttributes(): string[];
|
|
35
|
+
private _series;
|
|
36
|
+
private _area;
|
|
37
|
+
private _stacked;
|
|
38
|
+
private _yMin;
|
|
39
|
+
private _yMax;
|
|
40
|
+
private _goal;
|
|
41
|
+
private _goalLabel;
|
|
42
|
+
private _locale;
|
|
43
|
+
private _summary;
|
|
44
|
+
private _inputLabel;
|
|
45
|
+
private _summaryFormatter;
|
|
46
|
+
private _tooltipFormatter;
|
|
47
|
+
private _placed;
|
|
48
|
+
private _focusedKey;
|
|
49
|
+
private _restoreFocus;
|
|
50
|
+
private _hoveredKey;
|
|
51
|
+
get series(): TrendSeries[];
|
|
52
|
+
set series(value: TrendSeries[]);
|
|
53
|
+
get area(): boolean;
|
|
54
|
+
set area(value: boolean);
|
|
55
|
+
get stacked(): boolean;
|
|
56
|
+
set stacked(value: boolean);
|
|
57
|
+
get yMin(): number | undefined;
|
|
58
|
+
set yMin(value: number | undefined);
|
|
59
|
+
get yMax(): number | undefined;
|
|
60
|
+
set yMax(value: number | undefined);
|
|
61
|
+
get goal(): number | undefined;
|
|
62
|
+
set goal(value: number | undefined);
|
|
63
|
+
get goalLabel(): string | undefined;
|
|
64
|
+
set goalLabel(value: string | undefined);
|
|
65
|
+
get locale(): string | undefined;
|
|
66
|
+
set locale(value: string | undefined);
|
|
67
|
+
get summary(): string | undefined;
|
|
68
|
+
set summary(value: string | undefined);
|
|
69
|
+
get inputLabel(): string | null;
|
|
70
|
+
set inputLabel(value: string | null);
|
|
71
|
+
get summaryFormatter(): ((series: TrendSeries[]) => string | undefined) | undefined;
|
|
72
|
+
set summaryFormatter(value: ((series: TrendSeries[]) => string | undefined) | undefined);
|
|
73
|
+
get tooltipFormatter(): ((points: PlacedPoint[]) => string | undefined) | undefined;
|
|
74
|
+
set tooltipFormatter(value: ((points: PlacedPoint[]) => string | undefined) | undefined);
|
|
75
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
76
|
+
private static toMs;
|
|
77
|
+
private numberFormat;
|
|
78
|
+
private dateFormat;
|
|
79
|
+
/** Plot every non-gap point; stacked series plot the running sum per x. */
|
|
80
|
+
private place;
|
|
81
|
+
/**
|
|
82
|
+
* Null points are dropped before placement, so a gap shows up as a jump in
|
|
83
|
+
* pointIndex between neighbours — each contiguous stretch is its own run.
|
|
84
|
+
*/
|
|
85
|
+
private static runsOf;
|
|
86
|
+
private linePath;
|
|
87
|
+
private areaPath;
|
|
88
|
+
private keyOf;
|
|
89
|
+
private pointName;
|
|
90
|
+
private onPointerMove;
|
|
91
|
+
private clearHover;
|
|
92
|
+
private onClick;
|
|
93
|
+
private onKeyDown;
|
|
94
|
+
private emit;
|
|
95
|
+
protected updated(changed: PropertyValues): void;
|
|
96
|
+
private groupLabel;
|
|
97
|
+
render(): TemplateResult;
|
|
98
|
+
}
|
|
99
|
+
declare global {
|
|
100
|
+
interface HTMLElementTagNameMap {
|
|
101
|
+
'mp-trend-chart': MpTrendChart;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { trendChartStyles } from './trend-chart.styles';
|
package/checkbox/index.mjs
CHANGED