@dataloop-ai/components 0.13.19 → 0.14.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/.nvmrc +1 -0
- package/README.md +3 -1
- package/package.json +19 -17
- package/src/assets/globals.scss +38 -3
- package/src/assets/grid.scss +9 -0
- package/src/components/DlAccordion/DlAccordion.vue +4 -4
- package/src/components/DlAlert.vue +6 -6
- package/src/components/DlChart/BrushThumb.vue +83 -0
- package/src/components/DlChart/DlBarChart.vue +545 -0
- package/src/components/DlChart/DlBrush.vue +475 -0
- package/src/components/DlChart/DlChartLabels.vue +279 -0
- package/src/components/DlChart/DlChartLegend.vue +141 -0
- package/src/components/DlChart/DlColumnChart.vue +555 -0
- package/src/components/DlChart/DlLineChart.vue +644 -0
- package/src/components/DlChart/DlScrollBar.vue +147 -0
- package/src/components/DlChart/Doughnut/DlDoughnutChart.vue +448 -0
- package/src/components/DlChart/Doughnut/DlDoughnutChartLegend.vue +281 -0
- package/src/components/DlChart/Doughnut/DlDoughnutChartWidget.vue +64 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutChartAnimation.ts +4 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutChartData.ts +16 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutChartOptions.ts +11 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutChartProps.ts +8 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutWithOriginalColor.ts +13 -0
- package/src/components/DlChart/chart.ts +122 -0
- package/src/components/DlChart/index.ts +36 -0
- package/src/components/DlChart/props.ts +348 -0
- package/src/components/DlChart/typedCharts.ts +88 -0
- package/src/components/DlChart/types.ts +63 -0
- package/src/components/DlChart/utils.ts +153 -0
- package/src/components/DlChip/DlChip.vue +40 -13
- package/src/components/DlCounters.vue +31 -7
- package/src/components/DlDatePicker/DlCalendar.vue +22 -10
- package/src/components/DlDatePicker/DlDatePicker.vue +8 -5
- package/src/components/DlDateTimeRange/types.ts +2 -2
- package/src/components/DlDialogBox/DlDialogBox.vue +0 -8
- package/src/components/DlDialogBox/DlDialogBoxHeader.vue +6 -22
- package/src/components/DlDropdownButton.vue +16 -4
- package/src/components/DlPagination/RowsSelector.vue +15 -1
- package/src/components/DlRange/DlRange.vue +3 -2
- package/src/components/DlSearch.vue +1 -1
- package/src/components/DlSelect/DlSelect.vue +1 -19
- package/src/components/DlSlider/sliderStyles.scss +4 -0
- package/src/components/DlSlider/useSlider.ts +39 -12
- package/src/components/DlSpinner.vue +259 -0
- package/src/components/DlTable/DlTable.vue +4 -1
- package/src/components/DlTable/hooks/tablePagination.ts +8 -2
- package/src/components/DlTextArea.vue +9 -0
- package/src/components/DlTextInput.vue +6 -42
- package/src/components/DlThemeProvider.vue +22 -13
- package/src/components/DlToastMessage/api/useToast.ts +23 -0
- package/src/components/DlToastMessage/components/ToastComponent.vue +279 -0
- package/src/components/DlToastMessage/index.ts +5 -0
- package/src/components/DlToastMessage/types.ts +4 -0
- package/src/components/DlToastMessage/utils/config.ts +17 -0
- package/src/components/DlToastMessage/utils/render.ts +54 -0
- package/src/components/DlTypography.vue +1 -1
- package/src/components/DlWidget/DlGrid.vue +33 -0
- package/src/components/DlWidget/DlGridRow.vue +32 -0
- package/src/components/DlWidget/DlWidget.vue +202 -11
- package/src/components/DlWidget/index.ts +2 -2
- package/src/components/DlWidget/utils.ts +26 -19
- package/src/components/index.ts +8 -3
- package/src/demo/BarChartDemo.vue +77 -0
- package/src/demo/ColumnChartDemo.vue +230 -0
- package/src/demo/DlButtonDemo.vue +1 -1
- package/src/demo/DlChartDoughnutDemo.vue +229 -0
- package/src/demo/DlChipDemo.vue +42 -18
- package/src/demo/DlDialogBoxDemo.vue +4 -4
- package/src/demo/DlLineChartDemo.vue +375 -0
- package/src/demo/DlSpinnerDemo.vue +20 -0
- package/src/demo/DlTableDemo.vue +13 -94
- package/src/demo/DlToastMessageDemo.vue +143 -0
- package/src/demo/DlWidgetDemo.vue +105 -143
- package/src/demo/index.ts +20 -2
- package/src/hooks/use-theme.ts +19 -0
- package/src/utils/abbreviate-to-string.ts +14 -0
- package/src/utils/colors.ts +47 -0
- package/src/utils/getRootStyles.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/swapNodes.ts +30 -0
- package/src/utils/update-key.ts +90 -0
- package/tsconfig.json +0 -1
- package/vite.config.ts +17 -0
- package/Dockerfile +0 -12
- package/jest.config.js +0 -16
- package/jest.setup.js +0 -59
- package/src/components/DlWidget/DlWidgetGrid.vue +0 -360
- package/storybook.js +0 -8
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import type { PropType } from 'vue-demi'
|
|
2
|
+
import type {
|
|
3
|
+
ChartType,
|
|
4
|
+
ChartData,
|
|
5
|
+
ChartOptions,
|
|
6
|
+
Plugin,
|
|
7
|
+
UpdateMode,
|
|
8
|
+
DatasetChartOptions
|
|
9
|
+
} from 'chart.js'
|
|
10
|
+
import { TDoughnutProps } from './Doughnut/types/TDoughnutChartProps'
|
|
11
|
+
import { TDoughnutChartData } from './Doughnut/types/TDoughnutChartData'
|
|
12
|
+
|
|
13
|
+
export const CommonProps = {
|
|
14
|
+
data: {
|
|
15
|
+
type: Object as PropType<ChartData>,
|
|
16
|
+
required: true
|
|
17
|
+
},
|
|
18
|
+
options: {
|
|
19
|
+
type: Object as PropType<ChartOptions>,
|
|
20
|
+
default: () => ({})
|
|
21
|
+
},
|
|
22
|
+
plugins: {
|
|
23
|
+
type: Array as PropType<Plugin[]>,
|
|
24
|
+
default: () => [] as Plugin[]
|
|
25
|
+
},
|
|
26
|
+
datasetIdKey: {
|
|
27
|
+
type: String,
|
|
28
|
+
default: 'label'
|
|
29
|
+
},
|
|
30
|
+
updateMode: {
|
|
31
|
+
type: String as PropType<UpdateMode>,
|
|
32
|
+
default: undefined as UpdateMode
|
|
33
|
+
}
|
|
34
|
+
} as const
|
|
35
|
+
|
|
36
|
+
export const Props = {
|
|
37
|
+
type: {
|
|
38
|
+
type: String as PropType<ChartType>,
|
|
39
|
+
required: true
|
|
40
|
+
},
|
|
41
|
+
...CommonProps
|
|
42
|
+
} as const
|
|
43
|
+
|
|
44
|
+
export const ColumnChartProps = {
|
|
45
|
+
displayBrush: {
|
|
46
|
+
type: Boolean,
|
|
47
|
+
default: true
|
|
48
|
+
},
|
|
49
|
+
displayLabels: {
|
|
50
|
+
type: Boolean,
|
|
51
|
+
default: true
|
|
52
|
+
},
|
|
53
|
+
displayLegend: {
|
|
54
|
+
type: Boolean,
|
|
55
|
+
default: true
|
|
56
|
+
},
|
|
57
|
+
rootClass: {
|
|
58
|
+
type: String,
|
|
59
|
+
default: ''
|
|
60
|
+
},
|
|
61
|
+
chartClass: {
|
|
62
|
+
type: String,
|
|
63
|
+
default: ''
|
|
64
|
+
},
|
|
65
|
+
chartStyles: {
|
|
66
|
+
type: String,
|
|
67
|
+
default: ''
|
|
68
|
+
},
|
|
69
|
+
brushClass: {
|
|
70
|
+
type: String,
|
|
71
|
+
default: ''
|
|
72
|
+
},
|
|
73
|
+
wrapperHeight: {
|
|
74
|
+
type: String,
|
|
75
|
+
default: '400px'
|
|
76
|
+
},
|
|
77
|
+
brushProps: {
|
|
78
|
+
type: Object,
|
|
79
|
+
default: () => ({
|
|
80
|
+
width: '100%',
|
|
81
|
+
min: 0,
|
|
82
|
+
max: 100,
|
|
83
|
+
thumbSize: '20px',
|
|
84
|
+
trackSize: '18px',
|
|
85
|
+
step: 1,
|
|
86
|
+
dragRange: true
|
|
87
|
+
})
|
|
88
|
+
},
|
|
89
|
+
legendClass: {
|
|
90
|
+
type: String,
|
|
91
|
+
default: ''
|
|
92
|
+
},
|
|
93
|
+
legendProps: {
|
|
94
|
+
type: Object,
|
|
95
|
+
default: () => ({
|
|
96
|
+
datasets: [] as unknown as DatasetChartOptions,
|
|
97
|
+
width: '100%',
|
|
98
|
+
alignItems: 'center'
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const defaultColumnChartProps = {
|
|
104
|
+
brushProps: {
|
|
105
|
+
width: '100%',
|
|
106
|
+
thumbSize: '20px',
|
|
107
|
+
trackSize: '18px',
|
|
108
|
+
step: 1,
|
|
109
|
+
dragRange: true
|
|
110
|
+
},
|
|
111
|
+
legendProps: {
|
|
112
|
+
alignItems: 'center'
|
|
113
|
+
},
|
|
114
|
+
options: {
|
|
115
|
+
responsive: true,
|
|
116
|
+
maintainAspectRatio: false,
|
|
117
|
+
animation: {
|
|
118
|
+
duration: 100,
|
|
119
|
+
easing: 'linear'
|
|
120
|
+
},
|
|
121
|
+
plugins: {
|
|
122
|
+
legend: {
|
|
123
|
+
display: false
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
scales: {
|
|
127
|
+
y: {
|
|
128
|
+
title: {
|
|
129
|
+
color: '--dl-color-medium',
|
|
130
|
+
display: true,
|
|
131
|
+
font: {
|
|
132
|
+
size: 12
|
|
133
|
+
},
|
|
134
|
+
text: 'Axis Y (sec)'
|
|
135
|
+
},
|
|
136
|
+
ticks: {
|
|
137
|
+
font: {
|
|
138
|
+
size: 12
|
|
139
|
+
},
|
|
140
|
+
color: '--dl-color-darker'
|
|
141
|
+
},
|
|
142
|
+
grid: {
|
|
143
|
+
color: '--dl-color-separator'
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
x: {
|
|
147
|
+
title: {
|
|
148
|
+
font: {
|
|
149
|
+
size: 12
|
|
150
|
+
},
|
|
151
|
+
color: '--dl-color-medium',
|
|
152
|
+
display: false,
|
|
153
|
+
text: 'Axis X'
|
|
154
|
+
},
|
|
155
|
+
min: 0,
|
|
156
|
+
ticks: {
|
|
157
|
+
font: {
|
|
158
|
+
size: 12
|
|
159
|
+
},
|
|
160
|
+
display: false,
|
|
161
|
+
color: '--dl-color-darker'
|
|
162
|
+
},
|
|
163
|
+
grid: {
|
|
164
|
+
color: '--dl-color-separator'
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export const defaultBarChartProps = {
|
|
172
|
+
legendProps: {
|
|
173
|
+
alignItems: 'center'
|
|
174
|
+
},
|
|
175
|
+
options: {
|
|
176
|
+
indexAxis: 'y',
|
|
177
|
+
responsive: true,
|
|
178
|
+
maintainAspectRatio: false,
|
|
179
|
+
plugins: {
|
|
180
|
+
legend: {
|
|
181
|
+
display: false
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
scales: {
|
|
185
|
+
y: {
|
|
186
|
+
title: {
|
|
187
|
+
color: '--dl-color-medium',
|
|
188
|
+
display: true,
|
|
189
|
+
text: 'Axis Y (sec)'
|
|
190
|
+
},
|
|
191
|
+
ticks: {
|
|
192
|
+
color: '--dl-color-darker'
|
|
193
|
+
},
|
|
194
|
+
grid: {
|
|
195
|
+
color: '--dl-color-separator'
|
|
196
|
+
},
|
|
197
|
+
min: 0
|
|
198
|
+
},
|
|
199
|
+
x: {
|
|
200
|
+
title: {
|
|
201
|
+
color: '--dl-color-medium',
|
|
202
|
+
display: true,
|
|
203
|
+
text: 'Axis X'
|
|
204
|
+
},
|
|
205
|
+
min: 0,
|
|
206
|
+
ticks: {
|
|
207
|
+
display: true,
|
|
208
|
+
color: '--dl-color-darker'
|
|
209
|
+
},
|
|
210
|
+
grid: {
|
|
211
|
+
color: '--dl-color-separator'
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export const BarChartProps = {
|
|
219
|
+
rootClass: {
|
|
220
|
+
type: String,
|
|
221
|
+
default: ''
|
|
222
|
+
},
|
|
223
|
+
chartClass: {
|
|
224
|
+
type: String,
|
|
225
|
+
default: ''
|
|
226
|
+
},
|
|
227
|
+
chartStyles: {
|
|
228
|
+
type: String,
|
|
229
|
+
default: ''
|
|
230
|
+
},
|
|
231
|
+
wrapperHeight: {
|
|
232
|
+
type: String,
|
|
233
|
+
default: '600px'
|
|
234
|
+
},
|
|
235
|
+
legendClass: {
|
|
236
|
+
type: String,
|
|
237
|
+
default: ''
|
|
238
|
+
},
|
|
239
|
+
legendProps: {
|
|
240
|
+
type: Object,
|
|
241
|
+
default: () => ({
|
|
242
|
+
datasets: [] as unknown as DatasetChartOptions,
|
|
243
|
+
width: '100%',
|
|
244
|
+
alignItems: 'center'
|
|
245
|
+
})
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export const defaultLineChartProps = {
|
|
250
|
+
brushProps: {
|
|
251
|
+
width: '100%',
|
|
252
|
+
thumbSize: '20px',
|
|
253
|
+
trackSize: '18px',
|
|
254
|
+
step: 1,
|
|
255
|
+
dragRange: true
|
|
256
|
+
},
|
|
257
|
+
legendProps: {
|
|
258
|
+
alignItems: 'center'
|
|
259
|
+
},
|
|
260
|
+
options: {
|
|
261
|
+
responsive: true,
|
|
262
|
+
maintainAspectRatio: false,
|
|
263
|
+
animation: {
|
|
264
|
+
duration: 100,
|
|
265
|
+
easing: 'linear'
|
|
266
|
+
},
|
|
267
|
+
plugins: {
|
|
268
|
+
legend: {
|
|
269
|
+
display: false
|
|
270
|
+
},
|
|
271
|
+
tooltip: {
|
|
272
|
+
callbacks: {
|
|
273
|
+
beforeTitle(context: any) {
|
|
274
|
+
const label =
|
|
275
|
+
context[0]?.chart?.data?.labels[
|
|
276
|
+
context[0]?.dataIndex
|
|
277
|
+
] || context[0].label
|
|
278
|
+
if (typeof label === 'string') {
|
|
279
|
+
context[0].label = label
|
|
280
|
+
} else {
|
|
281
|
+
context[0].label = Object.values(label)
|
|
282
|
+
.filter((item) => !!item)
|
|
283
|
+
.join(' | ')
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
scales: {
|
|
290
|
+
y: {
|
|
291
|
+
title: {
|
|
292
|
+
color: '--dl-color-medium',
|
|
293
|
+
display: true,
|
|
294
|
+
font: {
|
|
295
|
+
size: 12
|
|
296
|
+
},
|
|
297
|
+
text: 'Axis Y (sec)'
|
|
298
|
+
},
|
|
299
|
+
ticks: {
|
|
300
|
+
font: {
|
|
301
|
+
size: 12
|
|
302
|
+
},
|
|
303
|
+
color: '--dl-color-darker'
|
|
304
|
+
},
|
|
305
|
+
grid: {
|
|
306
|
+
color: '--dl-color-separator'
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
x: {
|
|
310
|
+
title: {
|
|
311
|
+
font: {
|
|
312
|
+
size: 12
|
|
313
|
+
},
|
|
314
|
+
color: '--dl-color-medium',
|
|
315
|
+
display: false,
|
|
316
|
+
text: 'Axis X'
|
|
317
|
+
},
|
|
318
|
+
min: 0,
|
|
319
|
+
ticks: {
|
|
320
|
+
font: {
|
|
321
|
+
size: 12
|
|
322
|
+
},
|
|
323
|
+
display: false,
|
|
324
|
+
color: '--dl-color-darker'
|
|
325
|
+
},
|
|
326
|
+
grid: {
|
|
327
|
+
display: false,
|
|
328
|
+
color: '--dl-color-separator'
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export const defaultDoughnutChartProps: TDoughnutProps = {
|
|
336
|
+
data: <TDoughnutChartData>{},
|
|
337
|
+
isSmall: false,
|
|
338
|
+
hasSummary: false,
|
|
339
|
+
options: {
|
|
340
|
+
responsive: true,
|
|
341
|
+
cutout: undefined,
|
|
342
|
+
circumference: 360,
|
|
343
|
+
animation: {
|
|
344
|
+
animateRotate: true,
|
|
345
|
+
animateScale: false
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { defineComponent, shallowRef, computed } from 'vue-demi'
|
|
2
|
+
import type { ChartType, ChartComponentLike, DefaultDataPoint } from 'chart.js'
|
|
3
|
+
import {
|
|
4
|
+
Chart as ChartJS,
|
|
5
|
+
BarController,
|
|
6
|
+
BubbleController,
|
|
7
|
+
DoughnutController,
|
|
8
|
+
LineController,
|
|
9
|
+
PieController,
|
|
10
|
+
PolarAreaController,
|
|
11
|
+
RadarController,
|
|
12
|
+
ScatterController
|
|
13
|
+
} from 'chart.js'
|
|
14
|
+
import type { TypedChartComponent, ChartComponentRef } from './types'
|
|
15
|
+
import { CommonProps } from './props'
|
|
16
|
+
import { Chart } from './chart'
|
|
17
|
+
import { compatProps } from './utils'
|
|
18
|
+
|
|
19
|
+
const template = `<Chart v-bind="{...allProps}" />`
|
|
20
|
+
|
|
21
|
+
export function createTypedChart<
|
|
22
|
+
TType extends ChartType = ChartType,
|
|
23
|
+
TData = DefaultDataPoint<TType>,
|
|
24
|
+
TLabel = unknown
|
|
25
|
+
>(
|
|
26
|
+
type: TType,
|
|
27
|
+
registerables: ChartComponentLike
|
|
28
|
+
): TypedChartComponent<TType, TData, TLabel> {
|
|
29
|
+
ChartJS.register(registerables)
|
|
30
|
+
|
|
31
|
+
return defineComponent({
|
|
32
|
+
components: {
|
|
33
|
+
Chart
|
|
34
|
+
},
|
|
35
|
+
props: CommonProps,
|
|
36
|
+
setup(props) {
|
|
37
|
+
const canvasRef = shallowRef<ChartJS | null>(null)
|
|
38
|
+
const reforwardRef = (chartRef: ChartComponentRef) => {
|
|
39
|
+
canvasRef.value = chartRef?.chart
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const allProps = computed(() => {
|
|
43
|
+
return compatProps(
|
|
44
|
+
{
|
|
45
|
+
ref: reforwardRef as any
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
type,
|
|
49
|
+
...props
|
|
50
|
+
}
|
|
51
|
+
)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
allProps
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
template
|
|
59
|
+
}) as any
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const Bar = /* #__PURE__ */ createTypedChart('bar', BarController)
|
|
63
|
+
|
|
64
|
+
export const Doughnut = /* #__PURE__ */ createTypedChart(
|
|
65
|
+
'doughnut',
|
|
66
|
+
DoughnutController
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
export const Line = /* #__PURE__ */ createTypedChart('line', LineController)
|
|
70
|
+
|
|
71
|
+
export const Pie = /* #__PURE__ */ createTypedChart('pie', PieController)
|
|
72
|
+
|
|
73
|
+
export const PolarArea = /* #__PURE__ */ createTypedChart(
|
|
74
|
+
'polarArea',
|
|
75
|
+
PolarAreaController
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
export const Radar = /* #__PURE__ */ createTypedChart('radar', RadarController)
|
|
79
|
+
|
|
80
|
+
export const Bubble = /* #__PURE__ */ createTypedChart(
|
|
81
|
+
'bubble',
|
|
82
|
+
BubbleController
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
export const Scatter = /* #__PURE__ */ createTypedChart(
|
|
86
|
+
'scatter',
|
|
87
|
+
ScatterController
|
|
88
|
+
)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Chart as ChartJS,
|
|
3
|
+
ChartType,
|
|
4
|
+
ChartData,
|
|
5
|
+
ChartOptions,
|
|
6
|
+
DefaultDataPoint,
|
|
7
|
+
Plugin,
|
|
8
|
+
UpdateMode
|
|
9
|
+
} from 'chart.js'
|
|
10
|
+
|
|
11
|
+
export interface ChartProps<
|
|
12
|
+
TType extends ChartType = ChartType,
|
|
13
|
+
TData = DefaultDataPoint<TType>,
|
|
14
|
+
TLabel = unknown
|
|
15
|
+
> {
|
|
16
|
+
/**
|
|
17
|
+
* Chart.js chart type
|
|
18
|
+
*/
|
|
19
|
+
type: TType
|
|
20
|
+
/**
|
|
21
|
+
* The data object that is passed into the Chart.js chart
|
|
22
|
+
* @see https://www.chartjs.org/docs/latest/getting-started/
|
|
23
|
+
*/
|
|
24
|
+
data: ChartData<TType, TData, TLabel>
|
|
25
|
+
/**
|
|
26
|
+
* The options object that is passed into the Chart.js chart
|
|
27
|
+
* @see https://www.chartjs.org/docs/latest/general/options.html
|
|
28
|
+
* @default {}
|
|
29
|
+
*/
|
|
30
|
+
options?: ChartOptions<TType>
|
|
31
|
+
/**
|
|
32
|
+
* The plugins array that is passed into the Chart.js chart
|
|
33
|
+
* @see https://www.chartjs.org/docs/latest/developers/plugins.html
|
|
34
|
+
* @default []
|
|
35
|
+
*/
|
|
36
|
+
plugins?: Plugin<TType>[]
|
|
37
|
+
/**
|
|
38
|
+
* Key name to identificate dataset
|
|
39
|
+
* @default 'label'
|
|
40
|
+
*/
|
|
41
|
+
datasetIdKey?: string
|
|
42
|
+
/**
|
|
43
|
+
* A mode string to indicate transition configuration should be used.
|
|
44
|
+
* @see https://www.chartjs.org/docs/latest/developers/api.html#update-mode
|
|
45
|
+
*/
|
|
46
|
+
updateMode?: UpdateMode
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ChartComponentRef<
|
|
50
|
+
TType extends ChartType = ChartType,
|
|
51
|
+
TData = DefaultDataPoint<TType>,
|
|
52
|
+
TLabel = unknown
|
|
53
|
+
> {
|
|
54
|
+
chart: ChartJS<TType, TData, TLabel> | null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type ChartComponent = any
|
|
58
|
+
|
|
59
|
+
export type TypedChartComponent<
|
|
60
|
+
TType extends ChartType,
|
|
61
|
+
TData = DefaultDataPoint<TType>,
|
|
62
|
+
TLabel = unknown
|
|
63
|
+
> = any
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { toRaw, isVue2 } from 'vue-demi'
|
|
2
|
+
import type {
|
|
3
|
+
Chart,
|
|
4
|
+
ChartType,
|
|
5
|
+
ChartData,
|
|
6
|
+
ChartDataset,
|
|
7
|
+
ChartOptions,
|
|
8
|
+
DefaultDataPoint
|
|
9
|
+
} from 'chart.js'
|
|
10
|
+
|
|
11
|
+
const isProxy = (obj: any) => {
|
|
12
|
+
try {
|
|
13
|
+
postMessage(obj, '*')
|
|
14
|
+
} catch (error: Error | any) {
|
|
15
|
+
if (error?.code === 25) return false
|
|
16
|
+
}
|
|
17
|
+
return true
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const compatProps = isVue2
|
|
21
|
+
? <I extends {}, T extends {}>(internals: I, props: T) =>
|
|
22
|
+
Object.assign(internals, props) as unknown as I & T
|
|
23
|
+
: <I extends {}, T extends {}>(internals: I, props: T) =>
|
|
24
|
+
Object.assign(internals, props)
|
|
25
|
+
|
|
26
|
+
export function toRawIfProxy<T>(obj: T) {
|
|
27
|
+
return isProxy(obj) ? toRaw(obj) : obj
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function cloneProxy<T extends object>(obj: T, src = obj) {
|
|
31
|
+
return isProxy(src) ? new Proxy(obj, {}) : obj
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function setOptions<
|
|
35
|
+
TType extends ChartType = ChartType,
|
|
36
|
+
TData = DefaultDataPoint<TType>,
|
|
37
|
+
TLabel = unknown
|
|
38
|
+
>(chart: Chart<TType, TData, TLabel>, nextOptions: ChartOptions<TType>) {
|
|
39
|
+
const options = chart.options
|
|
40
|
+
|
|
41
|
+
if (options && nextOptions) {
|
|
42
|
+
Object.assign(options, nextOptions)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function setLabels<
|
|
47
|
+
TType extends ChartType = ChartType,
|
|
48
|
+
TData = DefaultDataPoint<TType>,
|
|
49
|
+
TLabel = unknown
|
|
50
|
+
>(
|
|
51
|
+
currentData: ChartData<TType, TData, TLabel>,
|
|
52
|
+
nextLabels: TLabel[] | undefined
|
|
53
|
+
) {
|
|
54
|
+
currentData.labels = nextLabels
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function setDatasets<
|
|
58
|
+
TType extends ChartType = ChartType,
|
|
59
|
+
TData = DefaultDataPoint<TType>,
|
|
60
|
+
TLabel = unknown
|
|
61
|
+
>(
|
|
62
|
+
currentData: ChartData<TType, TData, TLabel>,
|
|
63
|
+
nextDatasets: ChartDataset<TType, TData>[],
|
|
64
|
+
datasetIdKey: string
|
|
65
|
+
) {
|
|
66
|
+
const addedDatasets: ChartDataset<TType, TData>[] = []
|
|
67
|
+
|
|
68
|
+
currentData.datasets = nextDatasets.map(
|
|
69
|
+
(nextDataset: Record<string, unknown>) => {
|
|
70
|
+
// given the new set, find it's current match
|
|
71
|
+
const currentDataset = currentData.datasets.find(
|
|
72
|
+
(dataset: Record<string, unknown>) =>
|
|
73
|
+
dataset[datasetIdKey] === nextDataset[datasetIdKey]
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
// There is no original to update, so simply add new one
|
|
77
|
+
if (
|
|
78
|
+
!currentDataset ||
|
|
79
|
+
!nextDataset.data ||
|
|
80
|
+
addedDatasets.includes(currentDataset)
|
|
81
|
+
) {
|
|
82
|
+
return { ...nextDataset } as ChartDataset<TType, TData>
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
addedDatasets.push(currentDataset)
|
|
86
|
+
|
|
87
|
+
Object.assign(currentDataset, nextDataset)
|
|
88
|
+
|
|
89
|
+
return currentDataset
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function cloneData<
|
|
95
|
+
TType extends ChartType = ChartType,
|
|
96
|
+
TData = DefaultDataPoint<TType>,
|
|
97
|
+
TLabel = unknown
|
|
98
|
+
>(data: ChartData<TType, TData, TLabel>, datasetIdKey: string) {
|
|
99
|
+
const nextData: ChartData<TType, TData, TLabel> = {
|
|
100
|
+
labels: [],
|
|
101
|
+
datasets: []
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
setLabels(nextData, data.labels)
|
|
105
|
+
setDatasets(nextData, data.datasets, datasetIdKey)
|
|
106
|
+
|
|
107
|
+
return nextData
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Get dataset from mouse click event
|
|
112
|
+
* @param chart - Chart.js instance
|
|
113
|
+
* @param event - Mouse click event
|
|
114
|
+
* @returns Dataset
|
|
115
|
+
*/
|
|
116
|
+
export function getDatasetAtEvent(chart: Chart, event: MouseEvent) {
|
|
117
|
+
return chart.getElementsAtEventForMode(
|
|
118
|
+
event,
|
|
119
|
+
'dataset',
|
|
120
|
+
{ intersect: true },
|
|
121
|
+
false
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get single dataset element from mouse click event
|
|
127
|
+
* @param chart - Chart.js instance
|
|
128
|
+
* @param event - Mouse click event
|
|
129
|
+
* @returns Dataset
|
|
130
|
+
*/
|
|
131
|
+
export function getElementAtEvent(chart: Chart, event: MouseEvent) {
|
|
132
|
+
return chart.getElementsAtEventForMode(
|
|
133
|
+
event,
|
|
134
|
+
'nearest',
|
|
135
|
+
{ intersect: true },
|
|
136
|
+
false
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Get all dataset elements from mouse click event
|
|
142
|
+
* @param chart - Chart.js instance
|
|
143
|
+
* @param event - Mouse click event
|
|
144
|
+
* @returns Dataset
|
|
145
|
+
*/
|
|
146
|
+
export function getElementsAtEvent(chart: Chart, event: MouseEvent) {
|
|
147
|
+
return chart.getElementsAtEventForMode(
|
|
148
|
+
event,
|
|
149
|
+
'index',
|
|
150
|
+
{ intersect: true },
|
|
151
|
+
false
|
|
152
|
+
)
|
|
153
|
+
}
|