@triptease/tt-bar-chart 0.2.2 → 0.2.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/dist/src/TtBarChart.d.ts +4 -2
- package/dist/src/TtBarChart.js +74 -59
- package/dist/src/TtBarChart.js.map +1 -1
- package/dist/src/types.d.ts +3 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils.d.ts +3 -0
- package/dist/src/utils.js +56 -0
- package/dist/src/utils.js.map +1 -1
- package/package.json +1 -1
package/dist/src/TtBarChart.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
2
|
import * as echarts from 'echarts';
|
|
3
|
-
import { Dataset } from './types.js';
|
|
3
|
+
import { ChartDirection, Dataset } from './types.js';
|
|
4
4
|
export declare class TtBarChart extends LitElement {
|
|
5
5
|
datasets: Dataset[];
|
|
6
|
-
direction:
|
|
6
|
+
direction: ChartDirection;
|
|
7
7
|
xAxisTitle?: string;
|
|
8
8
|
yAxisTitle?: string;
|
|
9
9
|
showHorizontalGrid: boolean;
|
|
@@ -12,7 +12,9 @@ export declare class TtBarChart extends LitElement {
|
|
|
12
12
|
showDataLabels: boolean;
|
|
13
13
|
showTooltip: boolean;
|
|
14
14
|
stacked: boolean;
|
|
15
|
+
loading: boolean;
|
|
15
16
|
chart: echarts.ECharts | null;
|
|
17
|
+
private loadingPulseTimer;
|
|
16
18
|
private getSeriesColor;
|
|
17
19
|
render(): import("lit-html").TemplateResult<1>;
|
|
18
20
|
protected firstUpdated(): void;
|
package/dist/src/TtBarChart.js
CHANGED
|
@@ -8,7 +8,7 @@ import { html, LitElement } from 'lit';
|
|
|
8
8
|
// @ts-expect-error Known error - https://github.com/apache/echarts/issues/21250
|
|
9
9
|
import * as echarts from 'echarts';
|
|
10
10
|
import { property, state } from 'lit/decorators.js';
|
|
11
|
-
import { axesFormatter, dataLabelsFormatter, jsonConvertor } from './utils.js';
|
|
11
|
+
import { axesFormatter, dataLabelsFormatter, jsonConvertor, loadingAnimation } from './utils.js';
|
|
12
12
|
// @ts-expect-error Known error - https://github.com/apache/echarts/issues/21250
|
|
13
13
|
import { AriaComponent } from 'echarts/components';
|
|
14
14
|
export class TtBarChart extends LitElement {
|
|
@@ -22,6 +22,7 @@ export class TtBarChart extends LitElement {
|
|
|
22
22
|
this.showDataLabels = false;
|
|
23
23
|
this.showTooltip = false;
|
|
24
24
|
this.stacked = false;
|
|
25
|
+
this.loading = false;
|
|
25
26
|
this.chart = null;
|
|
26
27
|
this.getSeriesColor = (dataset) => {
|
|
27
28
|
if (this.datasets && this.datasets.length > 1)
|
|
@@ -45,68 +46,79 @@ export class TtBarChart extends LitElement {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
updated() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
formatter: axesFormatter,
|
|
49
|
+
if (this.loadingPulseTimer) {
|
|
50
|
+
window.clearInterval(this.loadingPulseTimer);
|
|
51
|
+
}
|
|
52
|
+
if (this.loading && this.chart) {
|
|
53
|
+
this.setAttribute('aria-busy', 'true');
|
|
54
|
+
const pulseTimer = loadingAnimation(this.chart, this.direction);
|
|
55
|
+
this.loadingPulseTimer = pulseTimer;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.removeAttribute('aria-busy');
|
|
59
|
+
const labelsRaw = this.datasets.flatMap((dataset) => dataset.data.map((datapoint) => datapoint.label));
|
|
60
|
+
const labels = [...new Set(labelsRaw)];
|
|
61
|
+
const series = this.datasets.map((dataset) => ({
|
|
62
|
+
name: dataset.label,
|
|
63
|
+
type: 'bar',
|
|
64
|
+
data: labels.map((label) => {
|
|
65
|
+
const point = dataset.data.find((dp) => dp.label === label);
|
|
66
|
+
return point?.value ?? null;
|
|
67
|
+
}),
|
|
68
|
+
stack: this.stacked ? 'A' : undefined,
|
|
69
|
+
color: this.getSeriesColor(dataset),
|
|
70
|
+
label: {
|
|
71
|
+
show: this.showDataLabels,
|
|
72
|
+
position: 'right',
|
|
73
|
+
formatter: ({ value }) => dataLabelsFormatter.format(value),
|
|
74
|
+
},
|
|
75
|
+
cursor: 'default',
|
|
76
|
+
}));
|
|
77
|
+
const option = {
|
|
78
|
+
aria: {
|
|
79
|
+
show: true,
|
|
80
80
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
yAxis: {
|
|
84
|
-
name: this.yAxisTitle,
|
|
85
|
-
nameLocation: 'center',
|
|
86
|
-
type: this.direction === 'horizontal' ? 'category' : 'value',
|
|
87
|
-
data: this.direction === 'horizontal' ? labels : undefined,
|
|
88
|
-
axisLabel: {
|
|
89
|
-
formatter: axesFormatter,
|
|
81
|
+
legend: {
|
|
82
|
+
show: this.showLegend,
|
|
90
83
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
},
|
|
99
|
-
...(this.showTooltip && {
|
|
100
|
-
tooltip: {
|
|
101
|
-
trigger: 'axis',
|
|
102
|
-
axisPointer: {
|
|
103
|
-
type: 'shadow',
|
|
84
|
+
xAxis: {
|
|
85
|
+
name: this.xAxisTitle,
|
|
86
|
+
nameLocation: 'center',
|
|
87
|
+
type: this.direction === 'horizontal' ? 'value' : 'category',
|
|
88
|
+
data: this.direction === 'horizontal' ? undefined : labels,
|
|
89
|
+
axisLabel: {
|
|
90
|
+
formatter: axesFormatter,
|
|
104
91
|
},
|
|
92
|
+
splitLine: { show: this.showVerticalGrid },
|
|
105
93
|
},
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
94
|
+
yAxis: {
|
|
95
|
+
name: this.yAxisTitle,
|
|
96
|
+
nameLocation: 'center',
|
|
97
|
+
type: this.direction === 'horizontal' ? 'category' : 'value',
|
|
98
|
+
data: this.direction === 'horizontal' ? labels : undefined,
|
|
99
|
+
axisLabel: {
|
|
100
|
+
formatter: axesFormatter,
|
|
101
|
+
},
|
|
102
|
+
splitLine: { show: this.showHorizontalGrid },
|
|
103
|
+
},
|
|
104
|
+
grid: {
|
|
105
|
+
left: 0,
|
|
106
|
+
right: 0,
|
|
107
|
+
top: 0,
|
|
108
|
+
...(this.showLegend ? {} : { bottom: 0 }),
|
|
109
|
+
},
|
|
110
|
+
...(this.showTooltip && {
|
|
111
|
+
tooltip: {
|
|
112
|
+
trigger: 'axis',
|
|
113
|
+
axisPointer: {
|
|
114
|
+
type: 'shadow',
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
series,
|
|
119
|
+
};
|
|
120
|
+
this.chart.setOption(option);
|
|
121
|
+
}
|
|
110
122
|
}
|
|
111
123
|
}
|
|
112
124
|
__decorate([
|
|
@@ -139,6 +151,9 @@ __decorate([
|
|
|
139
151
|
__decorate([
|
|
140
152
|
property({ type: Boolean, attribute: 'stacked' })
|
|
141
153
|
], TtBarChart.prototype, "stacked", void 0);
|
|
154
|
+
__decorate([
|
|
155
|
+
property({ type: Boolean, attribute: 'loading' })
|
|
156
|
+
], TtBarChart.prototype, "loading", void 0);
|
|
142
157
|
__decorate([
|
|
143
158
|
state()
|
|
144
159
|
], TtBarChart.prototype, "chart", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TtBarChart.js","sourceRoot":"","sources":["../../src/TtBarChart.ts"],"names":[],"mappings":";;;;;;AAAA,OAA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AE,MAAM,EAAE,CAAC;6CACc;AAGzC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;8CAClC;AAGpB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;8CAClC;AAGpB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,CAAC;sDAC3B;AAGpC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,CAAC;oDAC3B;AAGlC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;8CAC1B;AAG5B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;kDAC3B;AAGhC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;+CAC1B;AAG7B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;2CACzB;AAGzB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;2CACzB;AAGzB;IADC,KAAK,EAAE;yCAC6B","sourcesContent":["import { html, LitElement } from 'lit';\n// @ts-expect-error Known error - https://github.com/apache/echarts/issues/21250\nimport * as echarts from 'echarts';\nimport { property, state } from 'lit/decorators.js';\nimport { ChartDirection, Dataset } from './types.js';\nimport { axesFormatter, dataLabelsFormatter, jsonConvertor, loadingAnimation } from './utils.js';\n// @ts-expect-error Known error - https://github.com/apache/echarts/issues/21250\nimport { AriaComponent } from 'echarts/components';\n\nexport class TtBarChart extends LitElement {\n @property({ type: Array, converter: jsonConvertor })\n datasets: Dataset[] = [];\n\n @property({ type: String })\n direction: ChartDirection = 'horizontal';\n\n @property({ type: String, attribute: 'x-axis-title' })\n xAxisTitle?: string;\n\n @property({ type: String, attribute: 'y-axis-title' })\n yAxisTitle?: string;\n\n @property({ type: Boolean, attribute: 'show-horizontal-grid' })\n showHorizontalGrid: boolean = false;\n\n @property({ type: Boolean, attribute: 'show-vertical-grid' })\n showVerticalGrid: boolean = false;\n\n @property({ type: Boolean, attribute: 'show-legend' })\n showLegend: boolean = false;\n\n @property({ type: Boolean, attribute: 'show-data-labels' })\n showDataLabels: boolean = false;\n\n @property({ type: Boolean, attribute: 'show-tooltip' })\n showTooltip: boolean = false;\n\n @property({ type: Boolean, attribute: 'stacked' })\n stacked: boolean = false;\n\n @property({ type: Boolean, attribute: 'loading' })\n loading: boolean = false;\n\n @state()\n chart: echarts.ECharts | null = null;\n\n private loadingPulseTimer: number | undefined;\n\n private getSeriesColor = (dataset: Dataset) => {\n if (this.datasets && this.datasets.length > 1) return undefined;\n if (dataset.color) return dataset.color;\n\n return '#4d35a1';\n };\n\n render() {\n return html` <div id=${this.id} style=\"width: 100%; height:100%;\"></div> `;\n }\n\n protected firstUpdated() {\n if (this.chart === null) {\n echarts.use([AriaComponent]);\n const divElement = this.renderRoot.querySelector(`#${this.id}`) as HTMLDivElement;\n\n if (!divElement) {\n throw new Error('No div element');\n }\n\n this.chart = echarts.init(divElement);\n }\n }\n\n protected updated() {\n if (this.loadingPulseTimer) {\n window.clearInterval(this.loadingPulseTimer);\n }\n\n if (this.loading && this.chart) {\n this.setAttribute('aria-busy', 'true');\n const pulseTimer = loadingAnimation(this.chart, this.direction);\n this.loadingPulseTimer = pulseTimer;\n } else {\n this.removeAttribute('aria-busy');\n\n const labelsRaw = this.datasets.flatMap((dataset) => dataset.data.map((datapoint) => datapoint.label));\n const labels = [...new Set(labelsRaw)];\n\n const series: echarts.SeriesOption[] = this.datasets.map((dataset) => ({\n name: dataset.label,\n type: 'bar',\n data: labels.map((label) => {\n const point = dataset.data.find((dp) => dp.label === label);\n return point?.value ?? null;\n }),\n stack: this.stacked ? 'A' : undefined,\n color: this.getSeriesColor(dataset),\n label: {\n show: this.showDataLabels,\n position: 'right',\n formatter: ({ value }: { value: number }) => dataLabelsFormatter.format(value),\n },\n cursor: 'default',\n }));\n\n const option: echarts.EChartsOption = {\n aria: {\n show: true,\n },\n legend: {\n show: this.showLegend,\n },\n xAxis: {\n name: this.xAxisTitle,\n nameLocation: 'center',\n type: this.direction === 'horizontal' ? 'value' : 'category',\n data: this.direction === 'horizontal' ? undefined : labels,\n axisLabel: {\n formatter: axesFormatter,\n },\n splitLine: { show: this.showVerticalGrid },\n },\n yAxis: {\n name: this.yAxisTitle,\n nameLocation: 'center',\n type: this.direction === 'horizontal' ? 'category' : 'value',\n data: this.direction === 'horizontal' ? labels : undefined,\n axisLabel: {\n formatter: axesFormatter,\n },\n splitLine: { show: this.showHorizontalGrid },\n },\n grid: {\n left: 0,\n right: 0,\n top: 0,\n ...(this.showLegend ? {} : { bottom: 0 }),\n },\n ...(this.showTooltip && {\n tooltip: {\n trigger: 'axis',\n axisPointer: {\n type: 'shadow',\n },\n },\n }),\n series,\n };\n\n this.chart.setOption(option);\n }\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'tt-bar-chart': TtBarChart;\n }\n}\n"]}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -8,12 +8,13 @@ export interface Dataset {
|
|
|
8
8
|
data: DataPoint[];
|
|
9
9
|
color?: string;
|
|
10
10
|
}
|
|
11
|
+
export type ChartDirection = 'horizontal' | 'vertical';
|
|
11
12
|
interface TTBarChartAttributes {
|
|
12
13
|
id?: string;
|
|
13
14
|
style?: React.CSSProperties;
|
|
14
15
|
[key: `data-${string}`]: string | undefined;
|
|
15
16
|
datasets?: string;
|
|
16
|
-
direction?:
|
|
17
|
+
direction?: ChartDirection;
|
|
17
18
|
'x-axis-title'?: string;
|
|
18
19
|
'y-axis-title'?: string;
|
|
19
20
|
color?: string;
|
|
@@ -23,6 +24,7 @@ interface TTBarChartAttributes {
|
|
|
23
24
|
'show-data-labels'?: boolean;
|
|
24
25
|
'show-tooltip'?: boolean;
|
|
25
26
|
stacked?: boolean;
|
|
27
|
+
loading?: boolean;
|
|
26
28
|
}
|
|
27
29
|
declare global {
|
|
28
30
|
namespace JSX {
|
package/dist/src/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import React from 'react';\n\ninterface DataPoint {\n label: string;\n value: number;\n}\n\nexport interface Dataset {\n label: string;\n data: DataPoint[];\n color?: string;\n}\n\ninterface TTBarChartAttributes {\n id?: string;\n style?: React.CSSProperties;\n [key: `data-${string}`]: string | undefined;\n datasets?: string;\n direction?:
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import React from 'react';\n\ninterface DataPoint {\n label: string;\n value: number;\n}\n\nexport interface Dataset {\n label: string;\n data: DataPoint[];\n color?: string;\n}\n\nexport type ChartDirection = 'horizontal' | 'vertical';\n\ninterface TTBarChartAttributes {\n id?: string;\n style?: React.CSSProperties;\n [key: `data-${string}`]: string | undefined;\n datasets?: string;\n direction?: ChartDirection;\n 'x-axis-title'?: string;\n 'y-axis-title'?: string;\n color?: string;\n 'show-horizontal-grid'?: boolean;\n 'show-vertical-grid'?: boolean;\n 'show-legend'?: boolean;\n 'show-data-labels'?: boolean;\n 'show-tooltip'?: boolean;\n stacked?: boolean;\n loading?: boolean;\n}\n\ndeclare global {\n namespace JSX {\n interface IntrinsicElements {\n 'tt-bar-chart': TTBarChartAttributes & { class?: string };\n }\n }\n\n namespace React {\n namespace JSX {\n interface IntrinsicElements {\n 'tt-bar-chart': TTBarChartAttributes & { className?: string; ref?: React.Ref<unknown> };\n }\n }\n }\n}\n"]}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import * as echarts from 'echarts';
|
|
2
|
+
import { ChartDirection } from './types.js';
|
|
1
3
|
export declare const jsonConvertor: (value: string | null) => any;
|
|
2
4
|
export declare const dataLabelsFormatter: Intl.NumberFormat;
|
|
3
5
|
export declare const axesFormatter: (value: number | string) => string;
|
|
6
|
+
export declare const loadingAnimation: (chart: echarts.ECharts, direction: ChartDirection) => number;
|
package/dist/src/utils.js
CHANGED
|
@@ -7,4 +7,60 @@ export const axesFormatter = (value) => {
|
|
|
7
7
|
}
|
|
8
8
|
return value;
|
|
9
9
|
};
|
|
10
|
+
const SKELETON_ITEMS = 4;
|
|
11
|
+
const PULSE_INTERVAL = 1500;
|
|
12
|
+
export const loadingAnimation = (chart, direction) => {
|
|
13
|
+
const isHorizontal = direction === 'horizontal';
|
|
14
|
+
const generateData = () => Array.from({ length: SKELETON_ITEMS }, () => Math.round(30 + Math.random() * 50));
|
|
15
|
+
const baseAxis = {
|
|
16
|
+
axisLabel: { show: false },
|
|
17
|
+
axisTick: { show: false },
|
|
18
|
+
axisLine: { show: false },
|
|
19
|
+
splitLine: { show: false },
|
|
20
|
+
};
|
|
21
|
+
chart.setOption({
|
|
22
|
+
animation: true,
|
|
23
|
+
animationDuration: 800,
|
|
24
|
+
animationEasing: 'cubicInOut',
|
|
25
|
+
grid: {
|
|
26
|
+
left: 0,
|
|
27
|
+
right: 0,
|
|
28
|
+
top: 0,
|
|
29
|
+
bottom: 0,
|
|
30
|
+
containLabel: false,
|
|
31
|
+
},
|
|
32
|
+
xAxis: isHorizontal
|
|
33
|
+
? { ...baseAxis, type: 'value' }
|
|
34
|
+
: {
|
|
35
|
+
...baseAxis,
|
|
36
|
+
type: 'category',
|
|
37
|
+
data: Array.from({ length: SKELETON_ITEMS }, () => ''),
|
|
38
|
+
},
|
|
39
|
+
yAxis: isHorizontal
|
|
40
|
+
? {
|
|
41
|
+
...baseAxis,
|
|
42
|
+
type: 'category',
|
|
43
|
+
data: Array.from({ length: SKELETON_ITEMS }, () => ''),
|
|
44
|
+
}
|
|
45
|
+
: { ...baseAxis, type: 'value' },
|
|
46
|
+
series: [
|
|
47
|
+
{
|
|
48
|
+
type: 'bar',
|
|
49
|
+
data: generateData(),
|
|
50
|
+
silent: true,
|
|
51
|
+
animationDurationUpdate: 800,
|
|
52
|
+
itemStyle: {
|
|
53
|
+
color: '#e5e7eb',
|
|
54
|
+
},
|
|
55
|
+
emphasis: { disabled: true },
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
}, true);
|
|
59
|
+
const pulseTimer = window.setInterval(() => {
|
|
60
|
+
chart.setOption({
|
|
61
|
+
series: [{ data: generateData() }],
|
|
62
|
+
});
|
|
63
|
+
}, PULSE_INTERVAL);
|
|
64
|
+
return pulseTimer;
|
|
65
|
+
};
|
|
10
66
|
//# sourceMappingURL=utils.js.map
|
package/dist/src/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAoB,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAC/F,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;AAEpE,MAAM,sBAAsB,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,qBAAqB,EAAE,CAAC,EAAE,CAAC,CAAC;AACnH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAsB,EAAE,EAAE;IACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAA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AC,EAAE,CAAC;aACvD;QAEL,KAAK,EAAE,YAAY;YACjB,CAAC,CAAC;gBACE,GAAG,QAAQ;gBACX,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;aACvD;YACH,CAAC,CAAC,EAAE,GAAG,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE;QAElC,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,KAAK;gBACX,IAAI,EAAE,YAAY,EAAE;gBACpB,MAAM,EAAE,IAAI;gBACZ,uBAAuB,EAAE,GAAG;gBAC5B,SAAS,EAAE;oBACT,KAAK,EAAE,SAAS;iBACjB;gBACD,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;aAC7B;SACF;KACF,EACD,IAAI,CACL,CAAC;IAEF,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE;QACzC,KAAK,CAAC,SAAS,CAAC;YACd,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC;SACnC,CAAC,CAAC;IACL,CAAC,EAAE,cAAc,CAAC,CAAC;IAEnB,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC","sourcesContent":["// @ts-expect-error Known error - https://github.com/apache/echarts/issues/21250\nimport * as echarts from 'echarts';\nimport { ChartDirection } from './types.js';\n\nexport const jsonConvertor = (value: string | null) => (value ? JSON.parse(value) : undefined);\nexport const dataLabelsFormatter = new Intl.NumberFormat(undefined);\n\nconst numericalAxesFormatter = new Intl.NumberFormat(undefined, { notation: 'compact', maximumFractionDigits: 2 });\nexport const axesFormatter = (value: number | string) => {\n if (typeof value === 'number') {\n return numericalAxesFormatter.format(value);\n }\n\n return value;\n};\n\nconst SKELETON_ITEMS = 4;\nconst PULSE_INTERVAL = 1500;\n\nexport const loadingAnimation = (chart: echarts.ECharts, direction: ChartDirection) => {\n const isHorizontal = direction === 'horizontal';\n\n const generateData = () => Array.from({ length: SKELETON_ITEMS }, () => Math.round(30 + Math.random() * 50));\n\n const baseAxis = {\n axisLabel: { show: false },\n axisTick: { show: false },\n axisLine: { show: false },\n splitLine: { show: false },\n };\n\n chart.setOption(\n {\n animation: true,\n animationDuration: 800,\n animationEasing: 'cubicInOut',\n\n grid: {\n left: 0,\n right: 0,\n top: 0,\n bottom: 0,\n containLabel: false,\n },\n\n xAxis: isHorizontal\n ? { ...baseAxis, type: 'value' }\n : {\n ...baseAxis,\n type: 'category',\n data: Array.from({ length: SKELETON_ITEMS }, () => ''),\n },\n\n yAxis: isHorizontal\n ? {\n ...baseAxis,\n type: 'category',\n data: Array.from({ length: SKELETON_ITEMS }, () => ''),\n }\n : { ...baseAxis, type: 'value' },\n\n series: [\n {\n type: 'bar',\n data: generateData(),\n silent: true,\n animationDurationUpdate: 800,\n itemStyle: {\n color: '#e5e7eb',\n },\n emphasis: { disabled: true },\n },\n ],\n },\n true\n );\n\n const pulseTimer = window.setInterval(() => {\n chart.setOption({\n series: [{ data: generateData() }],\n });\n }, PULSE_INTERVAL);\n\n return pulseTimer;\n};\n"]}
|
package/package.json
CHANGED