@aceshooting/lyra-ui 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -6
- package/custom-elements.json +12015 -0
- package/dist/components/chart/bar-chart.d.ts +14 -0
- package/dist/components/chart/bar-chart.js +14 -0
- package/dist/components/chart/box-plot.d.ts +46 -0
- package/dist/components/chart/box-plot.js +145 -0
- package/dist/components/chart/box-plot.styles.d.ts +1 -0
- package/dist/components/chart/box-plot.styles.js +22 -0
- package/dist/components/chart/bubble-chart.d.ts +19 -0
- package/dist/components/chart/bubble-chart.js +18 -0
- package/dist/components/chart/chart-loader.d.ts +8 -0
- package/dist/components/chart/chart-loader.js +26 -0
- package/dist/components/chart/chart.d.ts +91 -0
- package/dist/components/chart/chart.js +275 -0
- package/dist/components/chart/chart.styles.d.ts +1 -0
- package/dist/components/chart/chart.styles.js +33 -0
- package/dist/components/chart/doughnut-chart.d.ts +15 -0
- package/dist/components/chart/doughnut-chart.js +14 -0
- package/dist/components/chart/histogram-bin.d.ts +6 -0
- package/dist/components/chart/histogram-bin.js +19 -0
- package/dist/components/chart/histogram.d.ts +20 -0
- package/dist/components/chart/histogram.js +70 -0
- package/dist/components/chart/histogram.styles.d.ts +1 -0
- package/dist/components/chart/histogram.styles.js +1 -0
- package/dist/components/chart/line-chart.d.ts +14 -0
- package/dist/components/chart/line-chart.js +14 -0
- package/dist/components/chart/pie-chart.d.ts +16 -0
- package/dist/components/chart/pie-chart.js +15 -0
- package/dist/components/chart/polar-area-chart.d.ts +15 -0
- package/dist/components/chart/polar-area-chart.js +14 -0
- package/dist/components/chart/radar-chart.d.ts +15 -0
- package/dist/components/chart/radar-chart.js +14 -0
- package/dist/components/chart/scatter-chart.d.ts +15 -0
- package/dist/components/chart/scatter-chart.js +15 -0
- package/dist/components/combobox/combobox.d.ts +16 -0
- package/dist/components/combobox/combobox.js +113 -6
- package/dist/components/combobox/combobox.styles.js +68 -7
- package/dist/components/combobox/option.d.ts +2 -2
- package/dist/components/combobox/option.js +11 -7
- package/dist/components/date-picker/date-input.d.ts +12 -1
- package/dist/components/date-picker/date-input.js +68 -6
- package/dist/components/date-picker/date-input.styles.js +58 -6
- package/dist/components/date-picker/date-picker.js +5 -2
- package/dist/components/date-picker/date-picker.styles.js +9 -2
- package/dist/components/empty/empty.d.ts +1 -0
- package/dist/components/empty/empty.js +14 -2
- package/dist/components/export-button/csv.d.ts +10 -0
- package/dist/components/export-button/csv.js +28 -0
- package/dist/components/export-button/export-button.d.ts +41 -0
- package/dist/components/export-button/export-button.js +151 -0
- package/dist/components/export-button/export-button.styles.d.ts +1 -0
- package/dist/components/export-button/export-button.styles.js +79 -0
- package/dist/components/file-input/accept.d.ts +14 -0
- package/dist/components/file-input/accept.js +30 -0
- package/dist/components/file-input/file-input.d.ts +47 -0
- package/dist/components/file-input/file-input.js +182 -0
- package/dist/components/file-input/file-input.styles.d.ts +1 -0
- package/dist/components/file-input/file-input.styles.js +44 -0
- package/dist/components/flag/flag.d.ts +4 -0
- package/dist/components/flag/flag.js +24 -1
- package/dist/components/flag/flag.styles.js +1 -1
- package/dist/components/gauge/gauge.d.ts +29 -0
- package/dist/components/gauge/gauge.js +133 -0
- package/dist/components/gauge/gauge.styles.d.ts +1 -0
- package/dist/components/gauge/gauge.styles.js +60 -0
- package/dist/components/graph/graph.d.ts +68 -0
- package/dist/components/graph/graph.js +276 -0
- package/dist/components/graph/graph.styles.d.ts +1 -0
- package/dist/components/graph/graph.styles.js +34 -0
- package/dist/components/heatmap/heatmap-scale.d.ts +8 -0
- package/dist/components/heatmap/heatmap-scale.js +17 -0
- package/dist/components/heatmap/heatmap.d.ts +66 -0
- package/dist/components/heatmap/heatmap.js +252 -0
- package/dist/components/heatmap/heatmap.styles.d.ts +1 -0
- package/dist/components/heatmap/heatmap.styles.js +39 -0
- package/dist/components/map/map-loader.d.ts +8 -0
- package/dist/components/map/map-loader.js +17 -0
- package/dist/components/map/map.d.ts +49 -0
- package/dist/components/map/map.js +189 -0
- package/dist/components/map/map.styles.d.ts +1 -0
- package/dist/components/map/map.styles.js +48 -0
- package/dist/components/playback/playback.d.ts +51 -0
- package/dist/components/playback/playback.js +146 -0
- package/dist/components/playback/playback.styles.d.ts +1 -0
- package/dist/components/playback/playback.styles.js +40 -0
- package/dist/components/split/split.d.ts +41 -0
- package/dist/components/split/split.js +171 -0
- package/dist/components/split/split.styles.d.ts +1 -0
- package/dist/components/split/split.styles.js +51 -0
- package/dist/components/stat/stat.d.ts +9 -0
- package/dist/components/stat/stat.js +52 -7
- package/dist/components/stat/stat.styles.js +15 -5
- package/dist/components/table/table.d.ts +18 -6
- package/dist/components/table/table.js +76 -24
- package/dist/components/table/table.styles.js +32 -0
- package/dist/components/time-range/time-range.d.ts +40 -0
- package/dist/components/time-range/time-range.js +219 -0
- package/dist/components/time-range/time-range.styles.d.ts +1 -0
- package/dist/components/time-range/time-range.styles.js +78 -0
- package/dist/components/toast/toast-item.js +10 -2
- package/dist/components/toast/toast-item.styles.js +13 -4
- package/dist/components/toast/toast.styles.js +0 -1
- package/dist/components/tree/tree-node.d.ts +50 -0
- package/dist/components/tree/tree-node.js +196 -0
- package/dist/components/tree/tree.d.ts +65 -0
- package/dist/components/tree/tree.js +227 -0
- package/dist/components/tree/tree.styles.d.ts +1 -0
- package/dist/components/tree/tree.styles.js +13 -0
- package/dist/internal/form-associated.js +49 -1
- package/dist/internal/icons.d.ts +11 -0
- package/dist/internal/icons.js +64 -0
- package/dist/internal/tokens.styles.js +41 -1
- package/dist/lyra.d.ts +67 -0
- package/dist/lyra.js +55 -0
- package/llms-full.txt +1425 -0
- package/llms.txt +47 -0
- package/package.json +53 -4
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LyraChart } from './chart.js';
|
|
2
|
+
/**
|
|
3
|
+
* `<lyra-bar-chart>` — `<lyra-chart>` with `type` locked to `"bar"`.
|
|
4
|
+
*
|
|
5
|
+
* @customElement lyra-bar-chart
|
|
6
|
+
*/
|
|
7
|
+
export declare class LyraBarChart extends LyraChart {
|
|
8
|
+
type: 'bar';
|
|
9
|
+
}
|
|
10
|
+
declare global {
|
|
11
|
+
interface HTMLElementTagNameMap {
|
|
12
|
+
'lyra-bar-chart': LyraBarChart;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LyraChart } from './chart.js';
|
|
2
|
+
import { defineElement } from '../../internal/prefix.js';
|
|
3
|
+
/**
|
|
4
|
+
* `<lyra-bar-chart>` — `<lyra-chart>` with `type` locked to `"bar"`.
|
|
5
|
+
*
|
|
6
|
+
* @customElement lyra-bar-chart
|
|
7
|
+
*/
|
|
8
|
+
export class LyraBarChart extends LyraChart {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.type = 'bar';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
defineElement('bar-chart', LyraBarChart);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type TemplateResult, type PropertyValues } from 'lit';
|
|
2
|
+
import { LyraElement } from '../../internal/lyra-element.js';
|
|
3
|
+
export interface BoxPlotPoint {
|
|
4
|
+
min: number;
|
|
5
|
+
q1: number;
|
|
6
|
+
median: number;
|
|
7
|
+
q3: number;
|
|
8
|
+
max: number;
|
|
9
|
+
}
|
|
10
|
+
export interface BoxPlotSeries {
|
|
11
|
+
label: string;
|
|
12
|
+
data: BoxPlotPoint[];
|
|
13
|
+
color?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `<lyra-box-plot>` — a box-and-whisker chart from precomputed five-number
|
|
17
|
+
* summaries (no raw sample data is shipped to the browser). Beyond Web
|
|
18
|
+
* Awesome's chart set — heavily used across ML/clustering dashboards.
|
|
19
|
+
*
|
|
20
|
+
* @customElement lyra-box-plot
|
|
21
|
+
* @csspart base, canvas
|
|
22
|
+
*/
|
|
23
|
+
export declare class LyraBoxPlot extends LyraElement {
|
|
24
|
+
static styles: import("lit").CSSResultGroup[];
|
|
25
|
+
labels: string[];
|
|
26
|
+
boxes: BoxPlotSeries[];
|
|
27
|
+
legend: boolean;
|
|
28
|
+
height: string;
|
|
29
|
+
yLabel: string;
|
|
30
|
+
beginAtZero: boolean;
|
|
31
|
+
private canvasEl?;
|
|
32
|
+
private chart?;
|
|
33
|
+
private chartJsModule?;
|
|
34
|
+
connectedCallback(): void;
|
|
35
|
+
private onBoxPlotPluginLoaded;
|
|
36
|
+
disconnectedCallback(): void;
|
|
37
|
+
protected updated(changed: PropertyValues): void;
|
|
38
|
+
private buildConfig;
|
|
39
|
+
private draw;
|
|
40
|
+
render(): TemplateResult;
|
|
41
|
+
}
|
|
42
|
+
declare global {
|
|
43
|
+
interface HTMLElementTagNameMap {
|
|
44
|
+
'lyra-box-plot': LyraBoxPlot;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html } from 'lit';
|
|
8
|
+
import { property, query } from 'lit/decorators.js';
|
|
9
|
+
import { LyraElement } from '../../internal/lyra-element.js';
|
|
10
|
+
import { defineElement } from '../../internal/prefix.js';
|
|
11
|
+
import { loadChartJs } from './chart-loader.js';
|
|
12
|
+
import { styles } from './box-plot.styles.js';
|
|
13
|
+
let boxPlotPlugin;
|
|
14
|
+
/**
|
|
15
|
+
* Lazily loads `@sgratzl/chartjs-chart-boxplot` and registers its controller
|
|
16
|
+
* only when a `<lyra-box-plot>` connects — kept separate from the base
|
|
17
|
+
* `chart-loader.ts` so importing `lyra-chart.js` alone never pulls this in.
|
|
18
|
+
*/
|
|
19
|
+
function loadBoxPlotPlugin() {
|
|
20
|
+
if (!boxPlotPlugin) {
|
|
21
|
+
boxPlotPlugin = Promise.all([loadChartJs(), import('@sgratzl/chartjs-chart-boxplot')])
|
|
22
|
+
.then(([chartMod, boxMod]) => {
|
|
23
|
+
if (!chartMod)
|
|
24
|
+
return null;
|
|
25
|
+
chartMod.Chart.register(boxMod.BoxPlotController, boxMod.BoxAndWiskers);
|
|
26
|
+
return boxMod;
|
|
27
|
+
})
|
|
28
|
+
.catch(() => {
|
|
29
|
+
console.warn('<lyra-box-plot> needs the optional peer dependency `@sgratzl/chartjs-chart-boxplot` ' +
|
|
30
|
+
'— install it with `pnpm add @sgratzl/chartjs-chart-boxplot`.');
|
|
31
|
+
return null;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return boxPlotPlugin;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* `<lyra-box-plot>` — a box-and-whisker chart from precomputed five-number
|
|
38
|
+
* summaries (no raw sample data is shipped to the browser). Beyond Web
|
|
39
|
+
* Awesome's chart set — heavily used across ML/clustering dashboards.
|
|
40
|
+
*
|
|
41
|
+
* @customElement lyra-box-plot
|
|
42
|
+
* @csspart base, canvas
|
|
43
|
+
*/
|
|
44
|
+
export class LyraBoxPlot extends LyraElement {
|
|
45
|
+
constructor() {
|
|
46
|
+
super(...arguments);
|
|
47
|
+
this.labels = [];
|
|
48
|
+
this.boxes = [];
|
|
49
|
+
this.legend = false;
|
|
50
|
+
this.height = '280px';
|
|
51
|
+
this.yLabel = '';
|
|
52
|
+
this.beginAtZero = true;
|
|
53
|
+
}
|
|
54
|
+
static { this.styles = [LyraElement.styles, styles]; }
|
|
55
|
+
connectedCallback() {
|
|
56
|
+
super.connectedCallback();
|
|
57
|
+
void loadBoxPlotPlugin().then((boxMod) => this.onBoxPlotPluginLoaded(boxMod));
|
|
58
|
+
}
|
|
59
|
+
// Split out from `connectedCallback()` so the partial-peer-dependency-
|
|
60
|
+
// failure path (chart.js loads fine, `@sgratzl/chartjs-chart-boxplot`
|
|
61
|
+
// doesn't) is directly testable: `loadBoxPlotPlugin()` resolves to `null`
|
|
62
|
+
// without ever registering `BoxPlotController`/`BoxAndWiskers` in that
|
|
63
|
+
// case, so this must gate on its resolved value — mirroring the correct,
|
|
64
|
+
// established pattern in `LyraChart.connectedCallback()` — instead of
|
|
65
|
+
// unconditionally re-awaiting the already-cached `loadChartJs()` promise.
|
|
66
|
+
async onBoxPlotPluginLoaded(boxMod) {
|
|
67
|
+
if (!boxMod)
|
|
68
|
+
return;
|
|
69
|
+
this.chartJsModule = (await loadChartJs()) ?? undefined;
|
|
70
|
+
this.draw();
|
|
71
|
+
}
|
|
72
|
+
disconnectedCallback() {
|
|
73
|
+
super.disconnectedCallback();
|
|
74
|
+
this.chart?.destroy();
|
|
75
|
+
this.chart = undefined;
|
|
76
|
+
}
|
|
77
|
+
updated(changed) {
|
|
78
|
+
// `--lyra-chart-height` is read by `:host`'s `block-size` in
|
|
79
|
+
// `chart.styles.ts` (shared with `lyra-chart`). Custom properties only
|
|
80
|
+
// cascade downward (host -> shadow tree), so this must be set on the
|
|
81
|
+
// host element itself, not on the `[part="base"]` div inside the shadow
|
|
82
|
+
// root.
|
|
83
|
+
if (changed.has('height')) {
|
|
84
|
+
this.style.setProperty('--lyra-chart-height', this.height);
|
|
85
|
+
}
|
|
86
|
+
this.draw();
|
|
87
|
+
}
|
|
88
|
+
buildConfig() {
|
|
89
|
+
return {
|
|
90
|
+
// boxplot isn't in chart.js's static ChartType union — same cast the seed uses.
|
|
91
|
+
type: 'boxplot',
|
|
92
|
+
data: {
|
|
93
|
+
labels: this.labels,
|
|
94
|
+
datasets: this.boxes.map((s) => ({
|
|
95
|
+
label: s.label,
|
|
96
|
+
data: s.data,
|
|
97
|
+
backgroundColor: s.color,
|
|
98
|
+
borderColor: s.color,
|
|
99
|
+
})),
|
|
100
|
+
},
|
|
101
|
+
options: {
|
|
102
|
+
responsive: true,
|
|
103
|
+
maintainAspectRatio: false,
|
|
104
|
+
plugins: { legend: { display: this.legend } },
|
|
105
|
+
scales: { y: { beginAtZero: this.beginAtZero, title: { display: !!this.yLabel, text: this.yLabel } } },
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
draw() {
|
|
110
|
+
if (!this.chartJsModule || !this.canvasEl)
|
|
111
|
+
return;
|
|
112
|
+
this.chart?.destroy();
|
|
113
|
+
this.chart = new this.chartJsModule.Chart(this.canvasEl, this.buildConfig());
|
|
114
|
+
}
|
|
115
|
+
render() {
|
|
116
|
+
const label = this.boxes.map((b) => b.label).join(', ') || 'Box plot';
|
|
117
|
+
return html `
|
|
118
|
+
<div part="base">
|
|
119
|
+
<canvas part="canvas" role="img" aria-label=${label}></canvas>
|
|
120
|
+
</div>
|
|
121
|
+
`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
__decorate([
|
|
125
|
+
property({ attribute: false })
|
|
126
|
+
], LyraBoxPlot.prototype, "labels", void 0);
|
|
127
|
+
__decorate([
|
|
128
|
+
property({ attribute: false })
|
|
129
|
+
], LyraBoxPlot.prototype, "boxes", void 0);
|
|
130
|
+
__decorate([
|
|
131
|
+
property({ type: Boolean })
|
|
132
|
+
], LyraBoxPlot.prototype, "legend", void 0);
|
|
133
|
+
__decorate([
|
|
134
|
+
property()
|
|
135
|
+
], LyraBoxPlot.prototype, "height", void 0);
|
|
136
|
+
__decorate([
|
|
137
|
+
property({ attribute: 'y-label' })
|
|
138
|
+
], LyraBoxPlot.prototype, "yLabel", void 0);
|
|
139
|
+
__decorate([
|
|
140
|
+
property({ type: Boolean, attribute: 'begin-at-zero' })
|
|
141
|
+
], LyraBoxPlot.prototype, "beginAtZero", void 0);
|
|
142
|
+
__decorate([
|
|
143
|
+
query('canvas')
|
|
144
|
+
], LyraBoxPlot.prototype, "canvasEl", void 0);
|
|
145
|
+
defineElement('box-plot', LyraBoxPlot);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const styles: import("lit").CSSResult;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
// Deliberately its own sheet rather than a wholesale re-export of
|
|
3
|
+
// `chart.styles.ts`: unlike `lyra-histogram`, `LyraBoxPlot` doesn't extend
|
|
4
|
+
// `LyraChart`, has no `zoom` property, and its `render()` never emits a
|
|
5
|
+
// `part="reset-zoom-button"` element — so that rule (and any other
|
|
6
|
+
// `lyra-chart`-only chrome) has no home here.
|
|
7
|
+
export const styles = css `
|
|
8
|
+
:host {
|
|
9
|
+
display: block;
|
|
10
|
+
position: relative;
|
|
11
|
+
block-size: var(--lyra-chart-height, 280px);
|
|
12
|
+
}
|
|
13
|
+
[part='base'] {
|
|
14
|
+
position: relative;
|
|
15
|
+
inline-size: 100%;
|
|
16
|
+
block-size: 100%;
|
|
17
|
+
}
|
|
18
|
+
canvas {
|
|
19
|
+
inline-size: 100% !important;
|
|
20
|
+
block-size: 100% !important;
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LyraChart } from './chart.js';
|
|
2
|
+
import type { LyraChartType } from './chart.js';
|
|
3
|
+
/**
|
|
4
|
+
* `<lyra-bubble-chart>` — `<lyra-chart>` with `type` locked to `"bubble"`. Feed
|
|
5
|
+
* points via `Series.points`, each needing an `x`/`y`/`r` (radius) triple —
|
|
6
|
+
* cast the array through `as unknown as Series['points']` (or a local
|
|
7
|
+
* `BubblePoint` type) when constructing it, since `Series.points` itself is
|
|
8
|
+
* typed as `{ x; y; label? }[]` with no `r` field.
|
|
9
|
+
*
|
|
10
|
+
* @customElement lyra-bubble-chart
|
|
11
|
+
*/
|
|
12
|
+
export declare class LyraBubbleChart extends LyraChart {
|
|
13
|
+
type: LyraChartType;
|
|
14
|
+
}
|
|
15
|
+
declare global {
|
|
16
|
+
interface HTMLElementTagNameMap {
|
|
17
|
+
'lyra-bubble-chart': LyraBubbleChart;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LyraChart } from './chart.js';
|
|
2
|
+
import { defineElement } from '../../internal/prefix.js';
|
|
3
|
+
/**
|
|
4
|
+
* `<lyra-bubble-chart>` — `<lyra-chart>` with `type` locked to `"bubble"`. Feed
|
|
5
|
+
* points via `Series.points`, each needing an `x`/`y`/`r` (radius) triple —
|
|
6
|
+
* cast the array through `as unknown as Series['points']` (or a local
|
|
7
|
+
* `BubblePoint` type) when constructing it, since `Series.points` itself is
|
|
8
|
+
* typed as `{ x; y; label? }[]` with no `r` field.
|
|
9
|
+
*
|
|
10
|
+
* @customElement lyra-bubble-chart
|
|
11
|
+
*/
|
|
12
|
+
export class LyraBubbleChart extends LyraChart {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.type = 'bubble';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
defineElement('bubble-chart', LyraBubbleChart);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type * as ChartJsModule from 'chart.js';
|
|
2
|
+
/**
|
|
3
|
+
* Lazily loads the optional peer dependency `chart.js` (+ `chartjs-plugin-zoom`)
|
|
4
|
+
* once per page, registering only the tree-shaken subset this library uses.
|
|
5
|
+
* Resolves to `null` (with a one-time warning) if chart.js isn't installed —
|
|
6
|
+
* mirrors `<lyra-flag>`'s peer-dependency pattern.
|
|
7
|
+
*/
|
|
8
|
+
export declare function loadChartJs(): Promise<typeof ChartJsModule | null>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
let chartJs;
|
|
2
|
+
let registered = false;
|
|
3
|
+
/**
|
|
4
|
+
* Lazily loads the optional peer dependency `chart.js` (+ `chartjs-plugin-zoom`)
|
|
5
|
+
* once per page, registering only the tree-shaken subset this library uses.
|
|
6
|
+
* Resolves to `null` (with a one-time warning) if chart.js isn't installed —
|
|
7
|
+
* mirrors `<lyra-flag>`'s peer-dependency pattern.
|
|
8
|
+
*/
|
|
9
|
+
export function loadChartJs() {
|
|
10
|
+
if (!chartJs) {
|
|
11
|
+
chartJs = Promise.all([import('chart.js'), import('chartjs-plugin-zoom')])
|
|
12
|
+
.then(([mod, zoomMod]) => {
|
|
13
|
+
if (!registered) {
|
|
14
|
+
mod.Chart.register(mod.LineController, mod.BarController, mod.ScatterController, mod.DoughnutController, mod.PieController, mod.RadarController, mod.PolarAreaController, mod.BubbleController, mod.LineElement, mod.PointElement, mod.BarElement, mod.ArcElement, mod.LinearScale, mod.CategoryScale, mod.RadialLinearScale, mod.Filler, mod.Tooltip, mod.Legend, zoomMod.default);
|
|
15
|
+
registered = true;
|
|
16
|
+
}
|
|
17
|
+
return mod;
|
|
18
|
+
})
|
|
19
|
+
.catch(() => {
|
|
20
|
+
console.warn('<lyra-chart> needs the optional peer dependencies `chart.js` and ' +
|
|
21
|
+
'`chartjs-plugin-zoom` — install them with `pnpm add chart.js chartjs-plugin-zoom`.');
|
|
22
|
+
return null;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return chartJs;
|
|
26
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type TemplateResult, type PropertyValues } from 'lit';
|
|
2
|
+
import type { ChartConfiguration } from 'chart.js';
|
|
3
|
+
import { LyraElement } from '../../internal/lyra-element.js';
|
|
4
|
+
import '../skeleton/skeleton.js';
|
|
5
|
+
export interface Series {
|
|
6
|
+
label: string;
|
|
7
|
+
data?: (number | null)[];
|
|
8
|
+
points?: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
label?: string;
|
|
12
|
+
}[];
|
|
13
|
+
color?: string | string[];
|
|
14
|
+
fill?: boolean;
|
|
15
|
+
width?: number;
|
|
16
|
+
dash?: boolean;
|
|
17
|
+
noTooltip?: boolean;
|
|
18
|
+
axis?: 'y' | 'y2';
|
|
19
|
+
pointColors?: string[];
|
|
20
|
+
pointRadius?: number;
|
|
21
|
+
type?: 'line' | 'bar';
|
|
22
|
+
}
|
|
23
|
+
export type LyraChartType = 'line' | 'bar' | 'scatter';
|
|
24
|
+
/**
|
|
25
|
+
* `<lyra-chart>` — the core Chart.js wrapper every other `lyra-*-chart` tag
|
|
26
|
+
* subclasses. Requires the optional peer deps `chart.js` + `chartjs-plugin-zoom`.
|
|
27
|
+
*
|
|
28
|
+
* **API mirror note (Task 0):** the real `wa-chart` docs page
|
|
29
|
+
* (https://webawesome.com/docs/components/chart/) documents a `config:
|
|
30
|
+
* ChartJS['config']` property alongside its simplified attributes — "a
|
|
31
|
+
* flexible wrapper around Chart.js" supporting *both* simplified attributes
|
|
32
|
+
* and full Chart.js configuration passthrough, not a `data`/`options` prop
|
|
33
|
+
* pair. `lyra-chart` mirrors that dual surface: the `Series`-based
|
|
34
|
+
* `datasets`/`labels`/`type`/`legend`/`xLabel`/`yLabel`/`zoom` attributes
|
|
35
|
+
* below are the simplified surface (compatible with WA's `type`, `xLabel`,
|
|
36
|
+
* `yLabel`, `withoutLegend`-equivalent `legend`, etc.), and the additional
|
|
37
|
+
* `config` property is the raw-passthrough escape hatch — a
|
|
38
|
+
* `Partial<ChartConfiguration>` deep-merged over the generated config in
|
|
39
|
+
* `buildConfig()`, mirroring WA's `config` property without discarding the
|
|
40
|
+
* `Series` shape the rest of this component family (subclasses, box-plot,
|
|
41
|
+
* histogram) is built on.
|
|
42
|
+
*
|
|
43
|
+
* @customElement lyra-chart
|
|
44
|
+
* @event lyra-zoom - `detail: { zoomed }`.
|
|
45
|
+
* @csspart base, canvas, reset-zoom-button
|
|
46
|
+
*/
|
|
47
|
+
export declare class LyraChart extends LyraElement {
|
|
48
|
+
static styles: import("lit").CSSResultGroup[];
|
|
49
|
+
type: LyraChartType;
|
|
50
|
+
labels: string[];
|
|
51
|
+
datasets: Series[];
|
|
52
|
+
legend: boolean;
|
|
53
|
+
area: boolean;
|
|
54
|
+
zoom: boolean;
|
|
55
|
+
height: string;
|
|
56
|
+
xLabel: string;
|
|
57
|
+
yLabel: string;
|
|
58
|
+
y2Label: string;
|
|
59
|
+
beginAtZero: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Raw Chart.js configuration passthrough — mirrors `wa-chart`'s `config`
|
|
62
|
+
* property. Recursively deep-merged over the `Series`-derived config in
|
|
63
|
+
* `buildConfig()` (any key at any nesting depth — e.g.
|
|
64
|
+
* `config.options.scales.y.min` — wins over the generated equivalent
|
|
65
|
+
* without discarding sibling keys the generated config set), for consumers
|
|
66
|
+
* who need full Chart.js control beyond the simplified `Series` shape.
|
|
67
|
+
*/
|
|
68
|
+
config?: Partial<ChartConfiguration>;
|
|
69
|
+
/** True until the lazy-loaded `chart.js` peer dependency has settled (success or failure). */
|
|
70
|
+
private loading;
|
|
71
|
+
private zoomed;
|
|
72
|
+
private canvasEl?;
|
|
73
|
+
private chart?;
|
|
74
|
+
private chartJsModule?;
|
|
75
|
+
private builtType?;
|
|
76
|
+
private onThemeChange;
|
|
77
|
+
connectedCallback(): void;
|
|
78
|
+
disconnectedCallback(): void;
|
|
79
|
+
protected updated(changed: PropertyValues): void;
|
|
80
|
+
private seriesToDataset;
|
|
81
|
+
private buildConfig;
|
|
82
|
+
private draw;
|
|
83
|
+
/** Reset any active zoom/pan back to the original view. */
|
|
84
|
+
resetZoom(): void;
|
|
85
|
+
render(): TemplateResult;
|
|
86
|
+
}
|
|
87
|
+
declare global {
|
|
88
|
+
interface HTMLElementTagNameMap {
|
|
89
|
+
'lyra-chart': LyraChart;
|
|
90
|
+
}
|
|
91
|
+
}
|