@dataloop-ai/components 0.13.19 → 0.14.4
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/DlDropdownButton.vue +5 -3
- package/src/components/DlMenu/DlMenu.vue +4 -2
- package/src/components/DlPagination/RowsSelector.vue +15 -2
- package/src/components/DlPopup/DlPopup.vue +0 -1
- package/src/components/DlRange/DlRange.vue +3 -2
- package/src/components/DlSearch.vue +1 -1
- package/src/components/DlSelect/DlSelect.vue +3 -2
- package/src/components/DlSlider/sliderStyles.scss +4 -0
- package/src/components/DlSlider/useSlider.ts +39 -12
- package/src/components/DlSmartSearch/DlSuggestionsDropdown.vue +1 -1
- 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 +4 -2
- 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 +56 -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/DlDropdownButtonDemo.vue +1 -1
- package/src/demo/DlLineChartDemo.vue +375 -0
- package/src/demo/DlMenuDemo.vue +1 -1
- package/src/demo/DlOptionGroupDemo.vue +1 -1
- package/src/demo/DlSelectDemo.vue +1 -1
- 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/position-engine.ts +11 -2
- 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,281 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
ref="dlDoughnutChartLegendMainRef"
|
|
4
|
+
:class="legendMainClass"
|
|
5
|
+
>
|
|
6
|
+
<div
|
|
7
|
+
v-if="itemsCount"
|
|
8
|
+
class="wrapper__legend"
|
|
9
|
+
>
|
|
10
|
+
<div
|
|
11
|
+
v-for="(item, index) in data.datasets[0].data"
|
|
12
|
+
:key="index"
|
|
13
|
+
class="wrapper__legend__item"
|
|
14
|
+
@click="hideData({ index })"
|
|
15
|
+
@mouseenter="emitMouseOverLegend(index)"
|
|
16
|
+
@mouseleave="emitMouseLeaveLegend(index)"
|
|
17
|
+
>
|
|
18
|
+
<dl-tooltip
|
|
19
|
+
self="top middle"
|
|
20
|
+
anchor="top middle"
|
|
21
|
+
>
|
|
22
|
+
{{ data.labels[index] }}
|
|
23
|
+
</dl-tooltip>
|
|
24
|
+
<div class="wrapper__legend__item__label">
|
|
25
|
+
<div>
|
|
26
|
+
<div
|
|
27
|
+
class="wrapper__legend__item__label__circle"
|
|
28
|
+
:style="{ backgroundColor: getColor(index, badge) }"
|
|
29
|
+
/>
|
|
30
|
+
</div>
|
|
31
|
+
<dl-typography>
|
|
32
|
+
<div
|
|
33
|
+
:class="legendLabelClass"
|
|
34
|
+
:style="{ color: getColor(index, text) }"
|
|
35
|
+
>
|
|
36
|
+
{{ data.labels[index] }}
|
|
37
|
+
</div>
|
|
38
|
+
</dl-typography>
|
|
39
|
+
</div>
|
|
40
|
+
<div
|
|
41
|
+
class="wrapper__legend__item__counter truncate"
|
|
42
|
+
:style="{ color: getColor(index, text) }"
|
|
43
|
+
>
|
|
44
|
+
{{ data.datasets[0].data[index] }}
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
</template>
|
|
50
|
+
|
|
51
|
+
<script lang="ts">
|
|
52
|
+
import { defineComponent, PropType } from 'vue-demi'
|
|
53
|
+
import type { LegendItem } from 'chart.js'
|
|
54
|
+
import DlTypography from '../../DlTypography.vue'
|
|
55
|
+
import { TDoughnutChartData } from './types/TDoughnutChartData'
|
|
56
|
+
import DlTooltip from '../../DlTooltip.vue'
|
|
57
|
+
|
|
58
|
+
enum EBadgeText {
|
|
59
|
+
badge = 'badge',
|
|
60
|
+
text = 'text'
|
|
61
|
+
}
|
|
62
|
+
type TBadgeText = EBadgeText.badge | EBadgeText.text
|
|
63
|
+
|
|
64
|
+
export default defineComponent({
|
|
65
|
+
name: 'DlDoughnutChartLegend',
|
|
66
|
+
components: {
|
|
67
|
+
DlTypography,
|
|
68
|
+
DlTooltip
|
|
69
|
+
},
|
|
70
|
+
props: {
|
|
71
|
+
data: {
|
|
72
|
+
type: Object,
|
|
73
|
+
default: () => Object as PropType<TDoughnutChartData>
|
|
74
|
+
},
|
|
75
|
+
isSmall: {
|
|
76
|
+
type: Boolean,
|
|
77
|
+
default: false
|
|
78
|
+
},
|
|
79
|
+
hiddenIndexes: {
|
|
80
|
+
type: Array,
|
|
81
|
+
default: () => [] as number[]
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
emits: ['hide', 'mouseOverLegend', 'mouseLeaveLegend'],
|
|
85
|
+
data() {
|
|
86
|
+
return {
|
|
87
|
+
grayColor: 'var(--dl-color-disabled)',
|
|
88
|
+
hoveredIndex: [],
|
|
89
|
+
paddingBody: '',
|
|
90
|
+
badge: EBadgeText.badge,
|
|
91
|
+
text: EBadgeText.text
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
computed: {
|
|
95
|
+
legendMainClass(): string[] {
|
|
96
|
+
return [
|
|
97
|
+
this.isSmall
|
|
98
|
+
? 'wrapper__height__sm wrapper__margin__sm wrapper__width__sm'
|
|
99
|
+
: 'wrapper__height__lg wrapper__height__lg',
|
|
100
|
+
this.paddingBody,
|
|
101
|
+
'wrapper'
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
legendLabelClass(): string[] {
|
|
105
|
+
return [
|
|
106
|
+
this.isSmall
|
|
107
|
+
? 'wrapper__legend__item__label__width__sm'
|
|
108
|
+
: 'wrapper__legend__item__label__width__lg',
|
|
109
|
+
'wrapper__legend__item__label__truncate'
|
|
110
|
+
]
|
|
111
|
+
},
|
|
112
|
+
itemsCount(): number | undefined {
|
|
113
|
+
return this.data?.datasets[0]?.data?.length
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
mounted(): void {
|
|
117
|
+
this.setBodyPadding()
|
|
118
|
+
},
|
|
119
|
+
methods: {
|
|
120
|
+
setBodyPadding() {
|
|
121
|
+
const clientHeight =
|
|
122
|
+
(this.$refs.dlDoughnutChartLegendMainRef as any)
|
|
123
|
+
?.clientHeight || 0
|
|
124
|
+
const scrollHeight =
|
|
125
|
+
(this.$refs.dlDoughnutChartLegendMainRef as any)
|
|
126
|
+
?.scrollHeight || 0
|
|
127
|
+
|
|
128
|
+
const hasScroll = clientHeight < scrollHeight
|
|
129
|
+
/**
|
|
130
|
+
* - if it is small and has scroll then should be have spaces on top and on the side
|
|
131
|
+
* - if it is small and hasn't scroll then should be have spaces only on the side
|
|
132
|
+
*/
|
|
133
|
+
if (this.isSmall) {
|
|
134
|
+
this.paddingBody = hasScroll
|
|
135
|
+
? 'wrapper__margin__scrollbar__with'
|
|
136
|
+
: 'wrapper__margin__scrollbar__without'
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
this.paddingBody = 'wrapper__margin__lg'
|
|
141
|
+
},
|
|
142
|
+
hideData(item: { index: number }) {
|
|
143
|
+
/**
|
|
144
|
+
* this should be check if this item index contains in hiddenIndexes
|
|
145
|
+
* if it is containing then should emit hidden: false
|
|
146
|
+
* overwise it is emitting hidden: true
|
|
147
|
+
* */
|
|
148
|
+
|
|
149
|
+
this.$emit('hide', {
|
|
150
|
+
...item,
|
|
151
|
+
hidden: !this.hiddenIndexes.includes(item.index)
|
|
152
|
+
})
|
|
153
|
+
},
|
|
154
|
+
emitMouseOverLegend(backgroundColorIndex: number) {
|
|
155
|
+
this.hoveredIndex.push(backgroundColorIndex)
|
|
156
|
+
this.$emit('mouseOverLegend', backgroundColorIndex)
|
|
157
|
+
},
|
|
158
|
+
emitMouseLeaveLegend(index: number) {
|
|
159
|
+
this.hoveredIndex.splice(
|
|
160
|
+
this.hoveredIndex.findIndex((element) => element === index),
|
|
161
|
+
1
|
|
162
|
+
)
|
|
163
|
+
this.$emit('mouseLeaveLegend')
|
|
164
|
+
},
|
|
165
|
+
getColor(index: number, element: TBadgeText) {
|
|
166
|
+
const originalColor =
|
|
167
|
+
element === EBadgeText.badge
|
|
168
|
+
? this.data.datasets[0].backgroundColor[index]
|
|
169
|
+
: 'var(--dl-color-darker)'
|
|
170
|
+
/**
|
|
171
|
+
* if it is hidden then should be gray
|
|
172
|
+
* if it is hidden, on hover the color should be default
|
|
173
|
+
* otherwise is default color
|
|
174
|
+
* */
|
|
175
|
+
return this.hiddenIndexes.includes(index) &&
|
|
176
|
+
!this.hoveredIndex.includes(index)
|
|
177
|
+
? this.grayColor
|
|
178
|
+
: originalColor
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
</script>
|
|
183
|
+
|
|
184
|
+
<style scoped lang="scss">
|
|
185
|
+
.wrapper {
|
|
186
|
+
overflow-y: scroll;
|
|
187
|
+
scrollbar-width: auto;
|
|
188
|
+
scrollbar-color: #e4e4e4;
|
|
189
|
+
scroll-padding: 4px;
|
|
190
|
+
|
|
191
|
+
&__height {
|
|
192
|
+
&__lg {
|
|
193
|
+
max-height: 480px;
|
|
194
|
+
}
|
|
195
|
+
&__sm {
|
|
196
|
+
max-height: 265px;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
&__width {
|
|
201
|
+
&__lg {
|
|
202
|
+
max-width: 500px;
|
|
203
|
+
}
|
|
204
|
+
&__sm {
|
|
205
|
+
max-width: 273px;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
&__margin {
|
|
210
|
+
&__sm {
|
|
211
|
+
margin: 0 19px 0 19px;
|
|
212
|
+
}
|
|
213
|
+
&__lg {
|
|
214
|
+
margin-left: 0;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
&__scrollbar {
|
|
218
|
+
&__with {
|
|
219
|
+
margin: 0 19px 0 19px;
|
|
220
|
+
}
|
|
221
|
+
&__without {
|
|
222
|
+
margin: 0 26px 0 26px;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
&__legend {
|
|
228
|
+
display: flex;
|
|
229
|
+
flex-wrap: wrap;
|
|
230
|
+
justify-content: initial;
|
|
231
|
+
gap: 0 5px;
|
|
232
|
+
|
|
233
|
+
&__item {
|
|
234
|
+
font-size: var(--dl-font-size-body);
|
|
235
|
+
display: flex;
|
|
236
|
+
width: 100%;
|
|
237
|
+
gap: 0 5px;
|
|
238
|
+
align-items: center;
|
|
239
|
+
cursor: pointer;
|
|
240
|
+
user-select: none;
|
|
241
|
+
line-height: 14px;
|
|
242
|
+
padding: 7px 8px 7px 8px;
|
|
243
|
+
|
|
244
|
+
&__label {
|
|
245
|
+
display: flex;
|
|
246
|
+
gap: 0 8px;
|
|
247
|
+
align-items: center;
|
|
248
|
+
|
|
249
|
+
&__width {
|
|
250
|
+
&__lg {
|
|
251
|
+
max-width: 242px;
|
|
252
|
+
}
|
|
253
|
+
&__sm {
|
|
254
|
+
max-width: 202px;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
&__truncate {
|
|
259
|
+
white-space: nowrap;
|
|
260
|
+
overflow: hidden;
|
|
261
|
+
text-overflow: ellipsis;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
&__circle {
|
|
265
|
+
height: 8px;
|
|
266
|
+
width: 8px;
|
|
267
|
+
border-radius: 50%;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
&__counter {
|
|
272
|
+
display: flex;
|
|
273
|
+
width: 100%;
|
|
274
|
+
text-align: flex-end;
|
|
275
|
+
justify-content: flex-end;
|
|
276
|
+
color: var(--dl-color-darker);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
</style>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<dl-grid gap="20px">
|
|
4
|
+
<dl-grid-row>
|
|
5
|
+
<dl-widget>
|
|
6
|
+
<template #header>
|
|
7
|
+
<span>{{ title }}</span>
|
|
8
|
+
<span style="font-size: 12px; color: gray">{{
|
|
9
|
+
subTitle
|
|
10
|
+
}}</span>
|
|
11
|
+
</template>
|
|
12
|
+
<template #content>
|
|
13
|
+
<DlDoughnutChart
|
|
14
|
+
:data="data"
|
|
15
|
+
:is-small="isSmall"
|
|
16
|
+
:has-summary="hasSummary"
|
|
17
|
+
/>
|
|
18
|
+
</template>
|
|
19
|
+
</dl-widget>
|
|
20
|
+
</dl-grid-row>
|
|
21
|
+
</dl-grid>
|
|
22
|
+
</div>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script lang="ts">
|
|
26
|
+
import { defineComponent, PropType } from 'vue-demi'
|
|
27
|
+
import DlDoughnutChart from './DlDoughnutChart.vue'
|
|
28
|
+
import { TDoughnutChartData } from './types/TDoughnutChartData'
|
|
29
|
+
import DlGrid from '../../../components/DlWidget/DlGrid.vue'
|
|
30
|
+
import DlGridRow from '../../../components/DlWidget/DlGridRow.vue'
|
|
31
|
+
import DlWidget from '../../../components/DlWidget/DlWidget.vue'
|
|
32
|
+
|
|
33
|
+
export default defineComponent({
|
|
34
|
+
name: 'DlDoughnutChartWidget',
|
|
35
|
+
components: {
|
|
36
|
+
DlDoughnutChart,
|
|
37
|
+
DlGrid,
|
|
38
|
+
DlGridRow,
|
|
39
|
+
DlWidget
|
|
40
|
+
},
|
|
41
|
+
props: {
|
|
42
|
+
data: {
|
|
43
|
+
type: Object as PropType<TDoughnutChartData>,
|
|
44
|
+
required: true
|
|
45
|
+
},
|
|
46
|
+
isSmall: {
|
|
47
|
+
type: Boolean,
|
|
48
|
+
default: false
|
|
49
|
+
},
|
|
50
|
+
hasSummary: {
|
|
51
|
+
type: Boolean,
|
|
52
|
+
default: false
|
|
53
|
+
},
|
|
54
|
+
title: {
|
|
55
|
+
type: String,
|
|
56
|
+
default: ''
|
|
57
|
+
},
|
|
58
|
+
subTitle: {
|
|
59
|
+
type: String,
|
|
60
|
+
default: ''
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
</script>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type TDoughnutChartDataset = {
|
|
2
|
+
label: string
|
|
3
|
+
data: number[]
|
|
4
|
+
backgroundColor: string[]
|
|
5
|
+
hoverBackgroundColor?: string[]
|
|
6
|
+
backgroundColorOrignal?: string[]
|
|
7
|
+
lightColor: string[]
|
|
8
|
+
hoverOffset?: number
|
|
9
|
+
borderWidth: number
|
|
10
|
+
cutout?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type TDoughnutChartData = {
|
|
14
|
+
labels: string[]
|
|
15
|
+
datasets: TDoughnutChartDataset[]
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ChartData } from 'chart.js'
|
|
2
|
+
|
|
3
|
+
export type TDoughnutWithOriginalColor = ChartData<'doughnut'> & {
|
|
4
|
+
datasets: [
|
|
5
|
+
{
|
|
6
|
+
data: any[]
|
|
7
|
+
label?: string
|
|
8
|
+
originalBackgroundColor?: string[]
|
|
9
|
+
backgroundColor?: string[]
|
|
10
|
+
lightColor?: string[]
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
shallowRef,
|
|
4
|
+
ref,
|
|
5
|
+
onMounted,
|
|
6
|
+
onBeforeUnmount,
|
|
7
|
+
toRaw,
|
|
8
|
+
watch,
|
|
9
|
+
getCurrentInstance
|
|
10
|
+
} from 'vue-demi'
|
|
11
|
+
import { Chart as ChartJS } from 'chart.js'
|
|
12
|
+
import type { ChartComponent } from './types'
|
|
13
|
+
import { Props } from './props'
|
|
14
|
+
import {
|
|
15
|
+
cloneData,
|
|
16
|
+
setLabels,
|
|
17
|
+
setDatasets,
|
|
18
|
+
setOptions,
|
|
19
|
+
toRawIfProxy,
|
|
20
|
+
cloneProxy
|
|
21
|
+
} from './utils'
|
|
22
|
+
|
|
23
|
+
export const Chart = defineComponent({
|
|
24
|
+
props: Props,
|
|
25
|
+
setup(props) {
|
|
26
|
+
const canvasRef = ref<HTMLCanvasElement | null>(null)
|
|
27
|
+
const chartRef = shallowRef<ChartJS | null>(null)
|
|
28
|
+
|
|
29
|
+
const vm = getCurrentInstance()
|
|
30
|
+
|
|
31
|
+
Object.assign(vm.parent.proxy, { chart: chartRef })
|
|
32
|
+
|
|
33
|
+
const renderChart = () => {
|
|
34
|
+
if (!canvasRef.value) return
|
|
35
|
+
|
|
36
|
+
const { type, data, options, plugins, datasetIdKey } = props
|
|
37
|
+
const clonedData = cloneData(data, datasetIdKey)
|
|
38
|
+
const proxiedData = cloneProxy(clonedData, data)
|
|
39
|
+
|
|
40
|
+
chartRef.value = new ChartJS(canvasRef.value, {
|
|
41
|
+
type,
|
|
42
|
+
data: proxiedData,
|
|
43
|
+
options: { ...options },
|
|
44
|
+
plugins
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const destroyChart = () => {
|
|
49
|
+
const chart = toRaw(chartRef.value)
|
|
50
|
+
|
|
51
|
+
if (chart) {
|
|
52
|
+
chart.destroy()
|
|
53
|
+
chartRef.value = null
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const update = (chart: ChartJS) => {
|
|
58
|
+
chart.update(props.updateMode)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
onMounted(renderChart)
|
|
62
|
+
|
|
63
|
+
onBeforeUnmount(destroyChart)
|
|
64
|
+
|
|
65
|
+
watch(
|
|
66
|
+
[() => props.options, () => props.data],
|
|
67
|
+
(
|
|
68
|
+
[nextOptionsProxy, nextDataProxy],
|
|
69
|
+
[prevOptionsProxy, prevDataProxy]
|
|
70
|
+
) => {
|
|
71
|
+
const chart = toRaw(chartRef.value)
|
|
72
|
+
|
|
73
|
+
if (!chart) {
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let shouldUpdate = false
|
|
78
|
+
|
|
79
|
+
if (nextOptionsProxy) {
|
|
80
|
+
const nextOptions = toRawIfProxy(nextOptionsProxy)
|
|
81
|
+
const prevOptions = toRawIfProxy(prevOptionsProxy)
|
|
82
|
+
|
|
83
|
+
if (nextOptions && nextOptions !== prevOptions) {
|
|
84
|
+
setOptions(chart, nextOptions)
|
|
85
|
+
shouldUpdate = true
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (nextDataProxy) {
|
|
90
|
+
const nextLabels = toRawIfProxy(nextDataProxy.labels)
|
|
91
|
+
const prevLabels = toRawIfProxy(prevDataProxy.labels)
|
|
92
|
+
const nextDatasets = toRawIfProxy(nextDataProxy.datasets)
|
|
93
|
+
const prevDatasets = toRawIfProxy(prevDataProxy.datasets)
|
|
94
|
+
|
|
95
|
+
if (nextLabels !== prevLabels) {
|
|
96
|
+
setLabels(chart.config.data, nextLabels)
|
|
97
|
+
shouldUpdate = true
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (nextDatasets && nextDatasets !== prevDatasets) {
|
|
101
|
+
setDatasets(
|
|
102
|
+
chart.config.data,
|
|
103
|
+
nextDatasets,
|
|
104
|
+
props.datasetIdKey
|
|
105
|
+
)
|
|
106
|
+
shouldUpdate = true
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (shouldUpdate) {
|
|
111
|
+
update(chart)
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
{ deep: true }
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
canvasRef
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
template: `<canvas ref="canvasRef" />`
|
|
122
|
+
}) as unknown as ChartComponent
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Chart } from './chart'
|
|
2
|
+
import {
|
|
3
|
+
createTypedChart,
|
|
4
|
+
Bar,
|
|
5
|
+
Doughnut,
|
|
6
|
+
Line,
|
|
7
|
+
Pie,
|
|
8
|
+
PolarArea,
|
|
9
|
+
Radar,
|
|
10
|
+
Bubble,
|
|
11
|
+
Scatter
|
|
12
|
+
} from './typedCharts'
|
|
13
|
+
import DlColumnChart from './DlColumnChart.vue'
|
|
14
|
+
import DlLineChart from './DlLineChart.vue'
|
|
15
|
+
|
|
16
|
+
export type { ChartProps, ChartComponentRef } from './types'
|
|
17
|
+
export {
|
|
18
|
+
getDatasetAtEvent,
|
|
19
|
+
getElementAtEvent,
|
|
20
|
+
getElementsAtEvent
|
|
21
|
+
} from './utils'
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
Chart,
|
|
25
|
+
createTypedChart,
|
|
26
|
+
Bar,
|
|
27
|
+
Doughnut,
|
|
28
|
+
Line,
|
|
29
|
+
Pie,
|
|
30
|
+
PolarArea,
|
|
31
|
+
Radar,
|
|
32
|
+
Bubble,
|
|
33
|
+
Scatter,
|
|
34
|
+
DlColumnChart,
|
|
35
|
+
DlLineChart
|
|
36
|
+
}
|