@reliability-design/web 1.4.5 → 1.4.7
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/CHANGELOG.md +211 -49
- package/dist/components/rel-accordion/README.md +132 -132
- package/dist/components/rel-alert/README.md +145 -141
- package/dist/components/rel-autocomplete/README.md +156 -61
- package/dist/components/rel-avatar/README.md +116 -130
- package/dist/components/rel-badge/README.md +98 -93
- package/dist/components/rel-breadcrumb/README.md +96 -102
- package/dist/components/rel-button/README.md +160 -130
- package/dist/components/rel-calendar/README.md +109 -109
- package/dist/components/rel-card/README.md +75 -94
- package/dist/components/rel-cardmedia/README.md +100 -127
- package/dist/components/rel-carousel/README.md +184 -166
- package/dist/components/rel-checkbox/README.md +93 -75
- package/dist/components/rel-chip/README.md +132 -121
- package/dist/components/rel-container/README.md +107 -99
- package/dist/components/rel-date-picker/README.md +200 -289
- package/dist/components/rel-divider/README.md +78 -100
- package/dist/components/rel-drawer/README.md +187 -200
- package/dist/components/rel-kbd/README.md +141 -151
- package/dist/components/rel-menu/README.md +178 -151
- package/dist/components/rel-menubar/README.md +218 -329
- package/dist/components/rel-otp/README.md +170 -440
- package/dist/components/rel-pagination/README.md +100 -424
- package/dist/components/rel-popover/README.md +203 -568
- package/dist/components/rel-progress/README.md +88 -110
- package/dist/components/rel-radio/README.md +131 -135
- package/dist/components/rel-range-picker/README.md +162 -0
- package/dist/components/rel-resizable/README.md +199 -140
- package/dist/components/rel-segmented-button/README.md +155 -141
- package/dist/components/rel-select/README.md +154 -93
- package/dist/components/rel-sheet/README.md +168 -224
- package/dist/components/rel-skeleton/README.md +103 -0
- package/dist/components/rel-slider/README.md +130 -135
- package/dist/components/rel-snackbar/README.md +162 -134
- package/dist/components/rel-stepper/README.md +158 -160
- package/dist/components/rel-switch/README.md +108 -102
- package/dist/components/rel-tab/README.md +171 -163
- package/dist/components/rel-textfield/README.md +159 -69
- package/dist/components/rel-time-picker/README.md +122 -157
- package/dist/components/rel-toast/README.md +157 -148
- package/dist/components/rel-tooltip/README.md +108 -103
- package/dist/components/rel-upload/README.md +220 -0
- package/dist/index.d.mts +1387 -350
- package/dist/index.d.ts +1387 -350
- package/dist/index.js +5863 -3600
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5864 -3592
- package/dist/index.mjs.map +1 -1
- package/dist/styles/vars.css +877 -866
- package/dist/{vars-XNMTSRVN.css → vars-JHTUGNRG.css} +877 -866
- package/package.json +4 -3
- package/dist/components/rel-accordion/rel-accordion.ts +0 -336
- package/dist/components/rel-alert/rel-alert.ts +0 -305
- package/dist/components/rel-autocomplete/rel-autocomplete.ts +0 -689
- package/dist/components/rel-avatar/rel-avatar.ts +0 -142
- package/dist/components/rel-badge/rel-badge.ts +0 -170
- package/dist/components/rel-breadcrumb/rel-breadcrumb.ts +0 -106
- package/dist/components/rel-button/rel-button.ts +0 -560
- package/dist/components/rel-calendar/index.ts +0 -1
- package/dist/components/rel-calendar/rel-calendar.ts +0 -519
- package/dist/components/rel-card/rel-card.ts +0 -88
- package/dist/components/rel-cardmedia/rel-cardmedia.ts +0 -88
- package/dist/components/rel-carousel/index.ts +0 -1
- package/dist/components/rel-carousel/rel-carousel.ts +0 -700
- package/dist/components/rel-chart/README.md +0 -286
- package/dist/components/rel-chart/index.ts +0 -1
- package/dist/components/rel-chart/rel-chart.ts +0 -754
- package/dist/components/rel-checkbox/rel-checkbox.ts +0 -382
- package/dist/components/rel-chip/rel-chip.ts +0 -472
- package/dist/components/rel-container/rel-container.ts +0 -95
- package/dist/components/rel-date-picker/date-format.test.ts +0 -43
- package/dist/components/rel-date-picker/date-format.ts +0 -47
- package/dist/components/rel-date-picker/index.ts +0 -1
- package/dist/components/rel-date-picker/rel-date-picker.ts +0 -1237
- package/dist/components/rel-divider/rel-divider.ts +0 -54
- package/dist/components/rel-drawer/index.ts +0 -1
- package/dist/components/rel-drawer/rel-drawer-footer.ts +0 -27
- package/dist/components/rel-drawer/rel-drawer.ts +0 -604
- package/dist/components/rel-kbd/rel-kbd.ts +0 -188
- package/dist/components/rel-layout/rel-layout.ts +0 -49
- package/dist/components/rel-menu/rel-menu.ts +0 -535
- package/dist/components/rel-menubar/index.ts +0 -2
- package/dist/components/rel-menubar/rel-menubar-menu.css +0 -3
- package/dist/components/rel-menubar/rel-menubar-menu.ts +0 -17
- package/dist/components/rel-menubar/rel-menubar.ts +0 -777
- package/dist/components/rel-nav-menu/README.md +0 -289
- package/dist/components/rel-nav-menu/index.ts +0 -3
- package/dist/components/rel-nav-menu/rel-nav-menu-item.ts +0 -243
- package/dist/components/rel-nav-menu/rel-nav-menu-panel.ts +0 -72
- package/dist/components/rel-nav-menu/rel-nav-menu.ts +0 -270
- package/dist/components/rel-navbar/README.md +0 -126
- package/dist/components/rel-navbar/rel-navbar.ts +0 -105
- package/dist/components/rel-otp/index.ts +0 -1
- package/dist/components/rel-otp/rel-otp.ts +0 -517
- package/dist/components/rel-pagination/index.ts +0 -1
- package/dist/components/rel-pagination/rel-pagination.ts +0 -509
- package/dist/components/rel-popover/index.ts +0 -2
- package/dist/components/rel-popover/rel-popover-content.ts +0 -81
- package/dist/components/rel-popover/rel-popover.ts +0 -444
- package/dist/components/rel-progress/rel-progress.ts +0 -225
- package/dist/components/rel-radio/rel-radio.ts +0 -305
- package/dist/components/rel-range-picker/rel-range-picker.ts +0 -1331
- package/dist/components/rel-resizable/index.ts +0 -3
- package/dist/components/rel-resizable/rel-resizable-group.ts +0 -405
- package/dist/components/rel-resizable/rel-resizable-handle.ts +0 -150
- package/dist/components/rel-resizable/rel-resizable-panel.ts +0 -58
- package/dist/components/rel-segmented-button/rel-segmented-button.ts +0 -213
- package/dist/components/rel-select/rel-select.ts +0 -1385
- package/dist/components/rel-sheet/rel-sheet.ts +0 -465
- package/dist/components/rel-sidebar/README.md +0 -209
- package/dist/components/rel-sidebar/rel-sidebar.ts +0 -1185
- package/dist/components/rel-skeleton/rel-skeleton.ts +0 -134
- package/dist/components/rel-slider/rel-slider.ts +0 -670
- package/dist/components/rel-snackbar/rel-snackbar.ts +0 -325
- package/dist/components/rel-stepper/rel-stepper.ts +0 -565
- package/dist/components/rel-switch/rel-switch.ts +0 -197
- package/dist/components/rel-tab/rel-tab.ts +0 -264
- package/dist/components/rel-table/README.md +0 -178
- package/dist/components/rel-table/rel-table-body.ts +0 -22
- package/dist/components/rel-table/rel-table-caption.ts +0 -30
- package/dist/components/rel-table/rel-table-cell.ts +0 -43
- package/dist/components/rel-table/rel-table-footer.ts +0 -24
- package/dist/components/rel-table/rel-table-head.ts +0 -47
- package/dist/components/rel-table/rel-table-header.ts +0 -22
- package/dist/components/rel-table/rel-table-row.ts +0 -37
- package/dist/components/rel-table/rel-table.ts +0 -62
- package/dist/components/rel-textfield/rel-textfield.ts +0 -866
- package/dist/components/rel-time-picker/rel-time-picker.ts +0 -1126
- package/dist/components/rel-toast/rel-toast.ts +0 -204
- package/dist/components/rel-tooltip/rel-tooltip.ts +0 -190
- package/dist/components/rel-topbar/rel-topbar-actions.ts +0 -27
- package/dist/components/rel-topbar/rel-topbar-brand.ts +0 -54
- package/dist/components/rel-topbar/rel-topbar-dropdown-item.ts +0 -69
- package/dist/components/rel-topbar/rel-topbar-dropdown.ts +0 -31
- package/dist/components/rel-topbar/rel-topbar-item.ts +0 -324
- package/dist/components/rel-topbar/rel-topbar-mobile-panel.ts +0 -27
- package/dist/components/rel-topbar/rel-topbar-profile.ts +0 -243
- package/dist/components/rel-topbar/rel-topbar-utilities.ts +0 -27
- package/dist/components/rel-topbar/rel-topbar.ts +0 -446
- package/dist/components/rel-upload/UPLOAD-DESIGN-CHANGES.md +0 -134
- package/dist/components/rel-upload/rel-upload-actions.ts +0 -163
- package/dist/components/rel-upload/rel-upload.ts +0 -943
|
@@ -1,754 +0,0 @@
|
|
|
1
|
-
import { LitElement, html, css, nothing } from "lit";
|
|
2
|
-
import { customElement, property, state, query } from "lit/decorators.js";
|
|
3
|
-
|
|
4
|
-
interface SeriesConfig {
|
|
5
|
-
key: string;
|
|
6
|
-
label?: string;
|
|
7
|
-
colorToken?: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface TooltipData {
|
|
11
|
-
x: string;
|
|
12
|
-
series: { label: string; value: number; color: string }[];
|
|
13
|
-
xPos: number;
|
|
14
|
-
yPos: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @deprecated rel-chart has no Figma design in RelDS 2.0 and is excluded from
|
|
19
|
-
* the parity contract. It remains exported for compatibility but will be
|
|
20
|
-
* removed in a future major version — use a dedicated charting library styled
|
|
21
|
-
* with RelDS tokens instead.
|
|
22
|
-
*/
|
|
23
|
-
@customElement("rel-chart")
|
|
24
|
-
export class RelChart extends LitElement {
|
|
25
|
-
@property({ type: String, reflect: true }) type: "bar" | "line" = "bar";
|
|
26
|
-
@property({ type: Number }) height = 320;
|
|
27
|
-
@property({ type: String, attribute: "x-key" }) xKey = "";
|
|
28
|
-
@property({ type: String, attribute: "series-json" }) seriesJson = "";
|
|
29
|
-
@property({ type: String, attribute: "data-json" }) dataJson = "";
|
|
30
|
-
@property({ type: Boolean, attribute: "show-grid" }) showGrid = true;
|
|
31
|
-
@property({ type: Boolean, attribute: "show-axis" }) showAxis = true;
|
|
32
|
-
@property({ type: Boolean, attribute: "show-legend" }) showLegend = true;
|
|
33
|
-
@property({ type: Boolean }) stacked = false;
|
|
34
|
-
@property({ type: String, attribute: "format-x" }) formatX: "date" | "string" | "number" = "string";
|
|
35
|
-
@property({ type: String }) locale = "en-US";
|
|
36
|
-
@property({ type: Boolean, reflect: true }) disabled = false;
|
|
37
|
-
|
|
38
|
-
// Programmatic properties - using setters to trigger updates
|
|
39
|
-
private _data: Array<Record<string, unknown>> = [];
|
|
40
|
-
private _series: SeriesConfig[] = [];
|
|
41
|
-
|
|
42
|
-
public get data() {
|
|
43
|
-
return this._data;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public set data(value: Array<Record<string, unknown>>) {
|
|
47
|
-
const oldValue = this._data;
|
|
48
|
-
this._data = value;
|
|
49
|
-
this.requestUpdate('data', oldValue);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public get series() {
|
|
53
|
-
return this._series;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public set series(value: SeriesConfig[]) {
|
|
57
|
-
const oldValue = this._series;
|
|
58
|
-
this._series = value;
|
|
59
|
-
this.requestUpdate('series', oldValue);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
@state() private chartWidth = 600; // Default width before measurement
|
|
63
|
-
@state() private tooltip: TooltipData | null = null;
|
|
64
|
-
|
|
65
|
-
@query(".chart-container") private container?: HTMLElement;
|
|
66
|
-
|
|
67
|
-
private resizeObserver?: ResizeObserver;
|
|
68
|
-
private prefersReducedMotion = false;
|
|
69
|
-
private resizeTimeout?: number;
|
|
70
|
-
|
|
71
|
-
// Default color palette using RDS tokens
|
|
72
|
-
private readonly defaultColors = [
|
|
73
|
-
"var(--rel-bg-info)",
|
|
74
|
-
"var(--rel-bg-success)",
|
|
75
|
-
"var(--rel-bg-warning)",
|
|
76
|
-
"var(--rel-bg-danger)",
|
|
77
|
-
"var(--rel-text-warning)",
|
|
78
|
-
"var(--rel-bg-neutral-elevated-3)",
|
|
79
|
-
];
|
|
80
|
-
|
|
81
|
-
static styles = css`
|
|
82
|
-
:host {
|
|
83
|
-
color: var(--rel-text-default);
|
|
84
|
-
display: block;
|
|
85
|
-
font-family: var(--rel-fonts-font-family);
|
|
86
|
-
position: relative;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
:host([disabled]) {
|
|
90
|
-
opacity: 0.6;
|
|
91
|
-
pointer-events: none;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
.chart-container {
|
|
95
|
-
width: 100%;
|
|
96
|
-
position: relative;
|
|
97
|
-
background: var(--rel-bg-surface);
|
|
98
|
-
border: 1px solid var(--rel-border-default);
|
|
99
|
-
border-radius: var(--rel-border-radius-sm, 8px);
|
|
100
|
-
padding: var(--rel-spacing-md, 16px);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
svg {
|
|
104
|
-
display: block;
|
|
105
|
-
width: 100%;
|
|
106
|
-
overflow: visible;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
.grid-line {
|
|
110
|
-
stroke: var(--rel-border-default);
|
|
111
|
-
stroke-width: 1;
|
|
112
|
-
stroke-dasharray: 2 2;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
.axis-line {
|
|
116
|
-
stroke: var(--rel-border-default);
|
|
117
|
-
stroke-width: 1;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
.axis-label {
|
|
121
|
-
fill: var(--rel-text-default);
|
|
122
|
-
font-family: var(--rel-body-xs-regular-font-family);
|
|
123
|
-
font-weight: var(--rel-body-xs-regular-font-weight);
|
|
124
|
-
font-size: var(--rel-body-xs-regular-font-size);
|
|
125
|
-
line-height: var(--rel-body-xs-regular-line-height);
|
|
126
|
-
letter-spacing: var(--rel-body-xs-regular-letter-spacing);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
.bar {
|
|
130
|
-
cursor: pointer;
|
|
131
|
-
transition: opacity 0.15s ease;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
.bar:hover {
|
|
135
|
-
opacity: 0.8;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
.bar:focus-visible {
|
|
139
|
-
outline: 2px solid var(--rel-border-info);
|
|
140
|
-
outline-offset: 2px;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
.line-path {
|
|
144
|
-
fill: none;
|
|
145
|
-
stroke-width: 2;
|
|
146
|
-
transition: stroke-width 0.15s ease;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
.line-path:hover {
|
|
150
|
-
stroke-width: 3;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
.point {
|
|
154
|
-
cursor: pointer;
|
|
155
|
-
transition: r 0.15s ease;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
.point:hover {
|
|
159
|
-
r: 6;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
.point:focus-visible {
|
|
163
|
-
outline: 2px solid var(--rel-border-info);
|
|
164
|
-
outline-offset: 2px;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
.legend {
|
|
168
|
-
display: flex;
|
|
169
|
-
gap: var(--rel-spacing-md);
|
|
170
|
-
margin-top: var(--rel-spacing-md);
|
|
171
|
-
flex-wrap: wrap;
|
|
172
|
-
justify-content: center;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
.legend-item {
|
|
176
|
-
display: flex;
|
|
177
|
-
align-items: center;
|
|
178
|
-
gap: var(--rel-spacing-xs, 8px);
|
|
179
|
-
color: var(--rel-text-default);
|
|
180
|
-
font-family: var(--rel-body-sm-regular-font-family);
|
|
181
|
-
font-weight: var(--rel-body-sm-regular-font-weight);
|
|
182
|
-
font-size: var(--rel-body-sm-regular-font-size);
|
|
183
|
-
line-height: var(--rel-body-sm-regular-line-height);
|
|
184
|
-
letter-spacing: var(--rel-body-sm-regular-letter-spacing);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
.legend-color {
|
|
188
|
-
width: 12px;
|
|
189
|
-
height: 12px;
|
|
190
|
-
border-radius: var(--rel-border-radius-xs);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
.tooltip {
|
|
194
|
-
position: absolute;
|
|
195
|
-
background: var(--rel-bg-surface);
|
|
196
|
-
border: 1px solid var(--rel-border-default);
|
|
197
|
-
border-radius: var(--rel-border-radius-sm, 8px);
|
|
198
|
-
padding: var(--rel-spacing-sm, 12px);
|
|
199
|
-
box-shadow: var(--rel-shadows-shadow-200);
|
|
200
|
-
pointer-events: none;
|
|
201
|
-
z-index: 100;
|
|
202
|
-
min-width: 120px;
|
|
203
|
-
font-family: var(--rel-body-sm-regular-font-family);
|
|
204
|
-
font-weight: var(--rel-body-sm-regular-font-weight);
|
|
205
|
-
font-size: var(--rel-body-sm-regular-font-size);
|
|
206
|
-
line-height: var(--rel-body-sm-regular-line-height);
|
|
207
|
-
letter-spacing: var(--rel-body-sm-regular-letter-spacing);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
.tooltip-title {
|
|
211
|
-
font-weight: var(--rel-fonts-weight-body-semibold, 600);
|
|
212
|
-
color: var(--rel-text-label);
|
|
213
|
-
margin-bottom: var(--rel-spacing-xs, 8px);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
.tooltip-row {
|
|
217
|
-
display: flex;
|
|
218
|
-
justify-content: space-between;
|
|
219
|
-
align-items: center;
|
|
220
|
-
gap: var(--rel-spacing-md);
|
|
221
|
-
margin-bottom: var(--rel-spacing-3xs);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
.tooltip-row:last-child {
|
|
225
|
-
margin-bottom: 0;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
.tooltip-label {
|
|
229
|
-
display: flex;
|
|
230
|
-
align-items: center;
|
|
231
|
-
gap: var(--rel-spacing-xs, 8px);
|
|
232
|
-
color: var(--rel-text-default);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
.tooltip-dot {
|
|
236
|
-
width: 8px;
|
|
237
|
-
height: 8px;
|
|
238
|
-
border-radius: 50%;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
.tooltip-value {
|
|
242
|
-
font-weight: var(--rel-fonts-weight-body-semibold, 600);
|
|
243
|
-
color: var(--rel-text-label);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
@media (prefers-reduced-motion: reduce) {
|
|
247
|
-
.bar,
|
|
248
|
-
.line-path,
|
|
249
|
-
.point {
|
|
250
|
-
transition: none;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
`;
|
|
254
|
-
|
|
255
|
-
connectedCallback() {
|
|
256
|
-
super.connectedCallback();
|
|
257
|
-
this.prefersReducedMotion = window.matchMedia(
|
|
258
|
-
"(prefers-reduced-motion: reduce)"
|
|
259
|
-
).matches;
|
|
260
|
-
|
|
261
|
-
this.resizeObserver = new ResizeObserver(() => {
|
|
262
|
-
if (this.resizeTimeout) {
|
|
263
|
-
clearTimeout(this.resizeTimeout);
|
|
264
|
-
}
|
|
265
|
-
this.resizeTimeout = window.setTimeout(() => {
|
|
266
|
-
this.measureWidth();
|
|
267
|
-
}, 50);
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
disconnectedCallback() {
|
|
272
|
-
super.disconnectedCallback();
|
|
273
|
-
if (this.resizeObserver) {
|
|
274
|
-
this.resizeObserver.disconnect();
|
|
275
|
-
}
|
|
276
|
-
if (this.resizeTimeout) {
|
|
277
|
-
clearTimeout(this.resizeTimeout);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
firstUpdated() {
|
|
282
|
-
if (this.container) {
|
|
283
|
-
this.resizeObserver?.observe(this.container);
|
|
284
|
-
this.measureWidth();
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
updated(changedProperties: Map<string, any>) {
|
|
289
|
-
// Re-measure when data or series changes, but only if we have data to render
|
|
290
|
-
if ((changedProperties.has("data") || changedProperties.has("series")) && this._data.length > 0) {
|
|
291
|
-
// Use requestAnimationFrame to ensure DOM is ready
|
|
292
|
-
requestAnimationFrame(() => {
|
|
293
|
-
this.measureWidth();
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
private measureWidth() {
|
|
299
|
-
if (this.container) {
|
|
300
|
-
const containerWidth = this.container.offsetWidth;
|
|
301
|
-
|
|
302
|
-
if (containerWidth === 0) return;
|
|
303
|
-
|
|
304
|
-
const measuredWidth = containerWidth - 32; // Account for padding
|
|
305
|
-
const newWidth = Math.max(measuredWidth, 100);
|
|
306
|
-
|
|
307
|
-
if (this.chartWidth !== newWidth) {
|
|
308
|
-
this.chartWidth = newWidth;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
private getChartData(): Array<Record<string, unknown>> {
|
|
314
|
-
if (this.data && this.data.length > 0) {
|
|
315
|
-
return this.data;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (this.dataJson) {
|
|
319
|
-
try {
|
|
320
|
-
return JSON.parse(this.dataJson);
|
|
321
|
-
} catch (e) {
|
|
322
|
-
console.error("Failed to parse data-json:", e);
|
|
323
|
-
return [];
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
return [];
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
private getSeriesConfig(): SeriesConfig[] {
|
|
331
|
-
if (this.series && this.series.length > 0) {
|
|
332
|
-
return this.series;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
if (this.seriesJson) {
|
|
336
|
-
try {
|
|
337
|
-
return JSON.parse(this.seriesJson);
|
|
338
|
-
} catch (e) {
|
|
339
|
-
console.error("Failed to parse series-json:", e);
|
|
340
|
-
return [];
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return [];
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
private getSeriesColor(index: number, config?: SeriesConfig): string {
|
|
348
|
-
if (config?.colorToken) {
|
|
349
|
-
return config.colorToken.startsWith("var(")
|
|
350
|
-
? config.colorToken
|
|
351
|
-
: `var(${config.colorToken})`;
|
|
352
|
-
}
|
|
353
|
-
return this.defaultColors[index % this.defaultColors.length];
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
private formatXValue(value: unknown): string {
|
|
357
|
-
if (this.formatX === "date" && value instanceof Date) {
|
|
358
|
-
return new Intl.DateTimeFormat(this.locale, {
|
|
359
|
-
month: "short",
|
|
360
|
-
day: "numeric",
|
|
361
|
-
}).format(value);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
if (this.formatX === "date" && typeof value === "string") {
|
|
365
|
-
try {
|
|
366
|
-
const date = new Date(value);
|
|
367
|
-
return new Intl.DateTimeFormat(this.locale, {
|
|
368
|
-
month: "short",
|
|
369
|
-
day: "numeric",
|
|
370
|
-
}).format(date);
|
|
371
|
-
} catch {
|
|
372
|
-
return String(value);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
return String(value);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
private calculateScales(data: Array<Record<string, unknown>>, seriesConfigs: SeriesConfig[]) {
|
|
380
|
-
const padding = { top: 20, right: 20, bottom: 40, left: 50 };
|
|
381
|
-
const chartHeight = this.height - padding.top - padding.bottom;
|
|
382
|
-
const chartWidth = this.chartWidth - padding.left - padding.right;
|
|
383
|
-
|
|
384
|
-
// Find max value across all series
|
|
385
|
-
let maxValue = 0;
|
|
386
|
-
data.forEach((item) => {
|
|
387
|
-
seriesConfigs.forEach((config) => {
|
|
388
|
-
const value = Number(item[config.key]) || 0;
|
|
389
|
-
maxValue = Math.max(maxValue, value);
|
|
390
|
-
});
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
// Add 10% padding to max
|
|
394
|
-
maxValue = maxValue * 1.1;
|
|
395
|
-
|
|
396
|
-
return {
|
|
397
|
-
padding,
|
|
398
|
-
chartHeight,
|
|
399
|
-
chartWidth,
|
|
400
|
-
maxValue,
|
|
401
|
-
xScale: (index: number) => padding.left + (index * chartWidth) / data.length,
|
|
402
|
-
yScale: (value: number) => padding.top + chartHeight - (value / maxValue) * chartHeight,
|
|
403
|
-
barWidth: chartWidth / data.length * 0.6 / seriesConfigs.length,
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
private handleBarHover(
|
|
408
|
-
event: MouseEvent,
|
|
409
|
-
datum: Record<string, unknown>,
|
|
410
|
-
index: number
|
|
411
|
-
) {
|
|
412
|
-
if (this.disabled) return;
|
|
413
|
-
|
|
414
|
-
const data = this.getChartData();
|
|
415
|
-
const seriesConfigs = this.getSeriesConfig();
|
|
416
|
-
const target = event.currentTarget as SVGElement;
|
|
417
|
-
const rect = target.getBoundingClientRect();
|
|
418
|
-
|
|
419
|
-
const tooltipData: TooltipData = {
|
|
420
|
-
x: this.formatXValue(datum[this.xKey]),
|
|
421
|
-
series: seriesConfigs.map((config, i) => ({
|
|
422
|
-
label: config.label || config.key,
|
|
423
|
-
value: Number(datum[config.key]) || 0,
|
|
424
|
-
color: this.getSeriesColor(i, config),
|
|
425
|
-
})),
|
|
426
|
-
xPos: rect.left + rect.width / 2,
|
|
427
|
-
yPos: rect.top,
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
this.tooltip = tooltipData;
|
|
431
|
-
|
|
432
|
-
this.dispatchEvent(
|
|
433
|
-
new CustomEvent("rel-hover", {
|
|
434
|
-
detail: { index, datum, seriesKey: undefined },
|
|
435
|
-
bubbles: true,
|
|
436
|
-
composed: true,
|
|
437
|
-
})
|
|
438
|
-
);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
private handlePointHover(
|
|
442
|
-
event: MouseEvent,
|
|
443
|
-
datum: Record<string, unknown>,
|
|
444
|
-
index: number,
|
|
445
|
-
seriesKey: string
|
|
446
|
-
) {
|
|
447
|
-
if (this.disabled) return;
|
|
448
|
-
|
|
449
|
-
const seriesConfigs = this.getSeriesConfig();
|
|
450
|
-
const seriesIndex = seriesConfigs.findIndex((s) => s.key === seriesKey);
|
|
451
|
-
const config = seriesConfigs[seriesIndex];
|
|
452
|
-
const target = event.currentTarget as SVGElement;
|
|
453
|
-
const rect = target.getBoundingClientRect();
|
|
454
|
-
|
|
455
|
-
const tooltipData: TooltipData = {
|
|
456
|
-
x: this.formatXValue(datum[this.xKey]),
|
|
457
|
-
series: [{
|
|
458
|
-
label: config.label || config.key,
|
|
459
|
-
value: Number(datum[config.key]) || 0,
|
|
460
|
-
color: this.getSeriesColor(seriesIndex, config),
|
|
461
|
-
}],
|
|
462
|
-
xPos: rect.left + rect.width / 2,
|
|
463
|
-
yPos: rect.top,
|
|
464
|
-
};
|
|
465
|
-
|
|
466
|
-
this.tooltip = tooltipData;
|
|
467
|
-
|
|
468
|
-
this.dispatchEvent(
|
|
469
|
-
new CustomEvent("rel-hover", {
|
|
470
|
-
detail: { index, datum, seriesKey },
|
|
471
|
-
bubbles: true,
|
|
472
|
-
composed: true,
|
|
473
|
-
})
|
|
474
|
-
);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
private handleMouseLeave() {
|
|
478
|
-
this.tooltip = null;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
private renderGrid(scales: ReturnType<typeof this.calculateScales>) {
|
|
482
|
-
if (!this.showGrid) return nothing;
|
|
483
|
-
|
|
484
|
-
const gridLines = [];
|
|
485
|
-
const numLines = 5;
|
|
486
|
-
|
|
487
|
-
for (let i = 0; i <= numLines; i++) {
|
|
488
|
-
const y = scales.padding.top + (i * scales.chartHeight) / numLines;
|
|
489
|
-
gridLines.push(html`
|
|
490
|
-
<line
|
|
491
|
-
class="grid-line"
|
|
492
|
-
x1="${scales.padding.left}"
|
|
493
|
-
y1="${y}"
|
|
494
|
-
x2="${scales.padding.left + scales.chartWidth}"
|
|
495
|
-
y2="${y}"
|
|
496
|
-
part="grid"
|
|
497
|
-
/>
|
|
498
|
-
`);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
return gridLines;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
private renderAxis(
|
|
505
|
-
data: Array<Record<string, unknown>>,
|
|
506
|
-
scales: ReturnType<typeof this.calculateScales>
|
|
507
|
-
) {
|
|
508
|
-
if (!this.showAxis) return nothing;
|
|
509
|
-
|
|
510
|
-
const yAxisLabels = [];
|
|
511
|
-
const numLabels = 5;
|
|
512
|
-
|
|
513
|
-
for (let i = 0; i <= numLabels; i++) {
|
|
514
|
-
const value = (scales.maxValue * (numLabels - i)) / numLabels;
|
|
515
|
-
const y = scales.padding.top + (i * scales.chartHeight) / numLabels;
|
|
516
|
-
|
|
517
|
-
yAxisLabels.push(html`
|
|
518
|
-
<text
|
|
519
|
-
class="axis-label"
|
|
520
|
-
x="${scales.padding.left - 10}"
|
|
521
|
-
y="${y + 4}"
|
|
522
|
-
text-anchor="end"
|
|
523
|
-
part="axis"
|
|
524
|
-
>
|
|
525
|
-
${Math.round(value)}
|
|
526
|
-
</text>
|
|
527
|
-
`);
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
const xAxisLabels = data.map((item, index) => {
|
|
531
|
-
const x = scales.xScale(index) + scales.chartWidth / data.length / 2;
|
|
532
|
-
return html`
|
|
533
|
-
<text
|
|
534
|
-
class="axis-label"
|
|
535
|
-
x="${x}"
|
|
536
|
-
y="${scales.padding.top + scales.chartHeight + 20}"
|
|
537
|
-
text-anchor="middle"
|
|
538
|
-
part="axis"
|
|
539
|
-
>
|
|
540
|
-
${this.formatXValue(item[this.xKey])}
|
|
541
|
-
</text>
|
|
542
|
-
`;
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
return html`
|
|
546
|
-
<line
|
|
547
|
-
class="axis-line"
|
|
548
|
-
x1="${scales.padding.left}"
|
|
549
|
-
y1="${scales.padding.top + scales.chartHeight}"
|
|
550
|
-
x2="${scales.padding.left + scales.chartWidth}"
|
|
551
|
-
y2="${scales.padding.top + scales.chartHeight}"
|
|
552
|
-
part="axis"
|
|
553
|
-
/>
|
|
554
|
-
<line
|
|
555
|
-
class="axis-line"
|
|
556
|
-
x1="${scales.padding.left}"
|
|
557
|
-
y1="${scales.padding.top}"
|
|
558
|
-
x2="${scales.padding.left}"
|
|
559
|
-
y2="${scales.padding.top + scales.chartHeight}"
|
|
560
|
-
part="axis"
|
|
561
|
-
/>
|
|
562
|
-
${yAxisLabels} ${xAxisLabels}
|
|
563
|
-
`;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
private renderBarChart(
|
|
567
|
-
data: Array<Record<string, unknown>>,
|
|
568
|
-
seriesConfigs: SeriesConfig[]
|
|
569
|
-
) {
|
|
570
|
-
const scales = this.calculateScales(data, seriesConfigs);
|
|
571
|
-
|
|
572
|
-
const bars = data.flatMap((item, dataIndex) => {
|
|
573
|
-
return seriesConfigs.map((config, seriesIndex) => {
|
|
574
|
-
const value = Number(item[config.key]) || 0;
|
|
575
|
-
const x =
|
|
576
|
-
scales.xScale(dataIndex) +
|
|
577
|
-
(scales.chartWidth / data.length - scales.barWidth * seriesConfigs.length) / 2 +
|
|
578
|
-
seriesIndex * scales.barWidth;
|
|
579
|
-
const y = scales.yScale(value);
|
|
580
|
-
const height = scales.padding.top + scales.chartHeight - y;
|
|
581
|
-
const color = this.getSeriesColor(seriesIndex, config);
|
|
582
|
-
|
|
583
|
-
return html`
|
|
584
|
-
<rect
|
|
585
|
-
class="bar"
|
|
586
|
-
part="bar"
|
|
587
|
-
x="${x}"
|
|
588
|
-
y="${y}"
|
|
589
|
-
width="${scales.barWidth}"
|
|
590
|
-
height="${height}"
|
|
591
|
-
fill="${color}"
|
|
592
|
-
role="button"
|
|
593
|
-
tabindex="0"
|
|
594
|
-
aria-label="${config.label || config.key}: ${value}"
|
|
595
|
-
@mouseenter="${(e: MouseEvent) => this.handleBarHover(e, item, dataIndex)}"
|
|
596
|
-
@mouseleave="${this.handleMouseLeave}"
|
|
597
|
-
@focus="${(e: FocusEvent) => this.handleBarHover(e as any, item, dataIndex)}"
|
|
598
|
-
@blur="${this.handleMouseLeave}"
|
|
599
|
-
/>
|
|
600
|
-
`;
|
|
601
|
-
});
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
return html`
|
|
605
|
-
<svg
|
|
606
|
-
height="${this.height}"
|
|
607
|
-
part="svg"
|
|
608
|
-
role="img"
|
|
609
|
-
aria-label="Bar chart"
|
|
610
|
-
>
|
|
611
|
-
${this.renderGrid(scales)} ${this.renderAxis(data, scales)} ${bars}
|
|
612
|
-
</svg>
|
|
613
|
-
`;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
private renderLineChart(
|
|
617
|
-
data: Array<Record<string, unknown>>,
|
|
618
|
-
seriesConfigs: SeriesConfig[]
|
|
619
|
-
) {
|
|
620
|
-
const scales = this.calculateScales(data, seriesConfigs);
|
|
621
|
-
|
|
622
|
-
const lines = seriesConfigs.map((config, seriesIndex) => {
|
|
623
|
-
const points = data.map((item, index) => {
|
|
624
|
-
const value = Number(item[config.key]) || 0;
|
|
625
|
-
const x = scales.xScale(index) + scales.chartWidth / data.length / 2;
|
|
626
|
-
const y = scales.yScale(value);
|
|
627
|
-
return { x, y, value, item, index };
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
const pathData = points
|
|
631
|
-
.map((p, i) => `${i === 0 ? "M" : "L"} ${p.x} ${p.y}`)
|
|
632
|
-
.join(" ");
|
|
633
|
-
|
|
634
|
-
return html`
|
|
635
|
-
<path
|
|
636
|
-
class="line-path"
|
|
637
|
-
part="line"
|
|
638
|
-
d="${pathData}"
|
|
639
|
-
stroke="${this.getSeriesColor(seriesIndex, config)}"
|
|
640
|
-
/>
|
|
641
|
-
${points.map(
|
|
642
|
-
(p) => html`
|
|
643
|
-
<circle
|
|
644
|
-
class="point"
|
|
645
|
-
part="point"
|
|
646
|
-
cx="${p.x}"
|
|
647
|
-
cy="${p.y}"
|
|
648
|
-
r="4"
|
|
649
|
-
fill="${this.getSeriesColor(seriesIndex, config)}"
|
|
650
|
-
role="button"
|
|
651
|
-
tabindex="0"
|
|
652
|
-
aria-label="${config.label || config.key}: ${p.value}"
|
|
653
|
-
@mouseenter="${(e: MouseEvent) =>
|
|
654
|
-
this.handlePointHover(e, p.item, p.index, config.key)}"
|
|
655
|
-
@mouseleave="${this.handleMouseLeave}"
|
|
656
|
-
@focus="${(e: FocusEvent) =>
|
|
657
|
-
this.handlePointHover(e as any, p.item, p.index, config.key)}"
|
|
658
|
-
@blur="${this.handleMouseLeave}"
|
|
659
|
-
/>
|
|
660
|
-
`
|
|
661
|
-
)}
|
|
662
|
-
`;
|
|
663
|
-
});
|
|
664
|
-
|
|
665
|
-
return html`
|
|
666
|
-
<svg
|
|
667
|
-
height="${this.height}"
|
|
668
|
-
part="svg"
|
|
669
|
-
role="img"
|
|
670
|
-
aria-label="Line chart"
|
|
671
|
-
>
|
|
672
|
-
${this.renderGrid(scales)} ${this.renderAxis(data, scales)} ${lines}
|
|
673
|
-
</svg>
|
|
674
|
-
`;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
private renderLegend(seriesConfigs: SeriesConfig[]) {
|
|
678
|
-
if (!this.showLegend || seriesConfigs.length === 0) return nothing;
|
|
679
|
-
|
|
680
|
-
return html`
|
|
681
|
-
<div class="legend" part="legend">
|
|
682
|
-
${seriesConfigs.map(
|
|
683
|
-
(config, index) => html`
|
|
684
|
-
<div class="legend-item">
|
|
685
|
-
<div
|
|
686
|
-
class="legend-color"
|
|
687
|
-
style="background: ${this.getSeriesColor(index, config)}"
|
|
688
|
-
></div>
|
|
689
|
-
<span>${config.label || config.key}</span>
|
|
690
|
-
</div>
|
|
691
|
-
`
|
|
692
|
-
)}
|
|
693
|
-
</div>
|
|
694
|
-
`;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
private renderTooltip() {
|
|
698
|
-
if (!this.tooltip) return nothing;
|
|
699
|
-
|
|
700
|
-
const containerRect = this.container?.getBoundingClientRect();
|
|
701
|
-
if (!containerRect) return nothing;
|
|
702
|
-
|
|
703
|
-
const tooltipX = this.tooltip.xPos - containerRect.left;
|
|
704
|
-
const tooltipY = this.tooltip.yPos - containerRect.top - 10;
|
|
705
|
-
|
|
706
|
-
return html`
|
|
707
|
-
<div
|
|
708
|
-
class="tooltip"
|
|
709
|
-
part="tooltip"
|
|
710
|
-
style="left: ${tooltipX}px; top: ${tooltipY}px; transform: translate(-50%, -100%)"
|
|
711
|
-
>
|
|
712
|
-
<div class="tooltip-title">${this.tooltip.x}</div>
|
|
713
|
-
${this.tooltip.series.map(
|
|
714
|
-
(s) => html`
|
|
715
|
-
<div class="tooltip-row">
|
|
716
|
-
<div class="tooltip-label">
|
|
717
|
-
<div
|
|
718
|
-
class="tooltip-dot"
|
|
719
|
-
style="background: ${s.color}"
|
|
720
|
-
></div>
|
|
721
|
-
<span>${s.label}</span>
|
|
722
|
-
</div>
|
|
723
|
-
<span class="tooltip-value">${s.value}</span>
|
|
724
|
-
</div>
|
|
725
|
-
`
|
|
726
|
-
)}
|
|
727
|
-
</div>
|
|
728
|
-
`;
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
render() {
|
|
732
|
-
const data = this.getChartData();
|
|
733
|
-
const seriesConfigs = this.getSeriesConfig();
|
|
734
|
-
|
|
735
|
-
if (!data.length || !seriesConfigs.length || !this.xKey) {
|
|
736
|
-
return html`
|
|
737
|
-
<div class="chart-container" part="container">
|
|
738
|
-
<p style="text-align: center; color: var(--rel-text-placeholder); padding: 40px;">
|
|
739
|
-
No data available
|
|
740
|
-
</p>
|
|
741
|
-
</div>
|
|
742
|
-
`;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
return html`
|
|
746
|
-
<div class="chart-container" part="container">
|
|
747
|
-
${this.type === "bar"
|
|
748
|
-
? this.renderBarChart(data, seriesConfigs)
|
|
749
|
-
: this.renderLineChart(data, seriesConfigs)}
|
|
750
|
-
${this.renderLegend(seriesConfigs)} ${this.renderTooltip()}
|
|
751
|
-
</div>
|
|
752
|
-
`;
|
|
753
|
-
}
|
|
754
|
-
}
|