@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.
Files changed (94) hide show
  1. package/.nvmrc +1 -0
  2. package/README.md +3 -1
  3. package/package.json +19 -17
  4. package/src/assets/globals.scss +38 -3
  5. package/src/assets/grid.scss +9 -0
  6. package/src/components/DlAccordion/DlAccordion.vue +4 -4
  7. package/src/components/DlAlert.vue +6 -6
  8. package/src/components/DlChart/BrushThumb.vue +83 -0
  9. package/src/components/DlChart/DlBarChart.vue +545 -0
  10. package/src/components/DlChart/DlBrush.vue +475 -0
  11. package/src/components/DlChart/DlChartLabels.vue +279 -0
  12. package/src/components/DlChart/DlChartLegend.vue +141 -0
  13. package/src/components/DlChart/DlColumnChart.vue +555 -0
  14. package/src/components/DlChart/DlLineChart.vue +644 -0
  15. package/src/components/DlChart/DlScrollBar.vue +147 -0
  16. package/src/components/DlChart/Doughnut/DlDoughnutChart.vue +448 -0
  17. package/src/components/DlChart/Doughnut/DlDoughnutChartLegend.vue +281 -0
  18. package/src/components/DlChart/Doughnut/DlDoughnutChartWidget.vue +64 -0
  19. package/src/components/DlChart/Doughnut/types/TDoughnutChartAnimation.ts +4 -0
  20. package/src/components/DlChart/Doughnut/types/TDoughnutChartData.ts +16 -0
  21. package/src/components/DlChart/Doughnut/types/TDoughnutChartOptions.ts +11 -0
  22. package/src/components/DlChart/Doughnut/types/TDoughnutChartProps.ts +8 -0
  23. package/src/components/DlChart/Doughnut/types/TDoughnutWithOriginalColor.ts +13 -0
  24. package/src/components/DlChart/chart.ts +122 -0
  25. package/src/components/DlChart/index.ts +36 -0
  26. package/src/components/DlChart/props.ts +348 -0
  27. package/src/components/DlChart/typedCharts.ts +88 -0
  28. package/src/components/DlChart/types.ts +63 -0
  29. package/src/components/DlChart/utils.ts +153 -0
  30. package/src/components/DlChip/DlChip.vue +40 -13
  31. package/src/components/DlCounters.vue +31 -7
  32. package/src/components/DlDatePicker/DlCalendar.vue +22 -10
  33. package/src/components/DlDatePicker/DlDatePicker.vue +8 -5
  34. package/src/components/DlDateTimeRange/types.ts +2 -2
  35. package/src/components/DlDropdownButton.vue +5 -3
  36. package/src/components/DlMenu/DlMenu.vue +4 -2
  37. package/src/components/DlPagination/RowsSelector.vue +15 -2
  38. package/src/components/DlPopup/DlPopup.vue +0 -1
  39. package/src/components/DlRange/DlRange.vue +3 -2
  40. package/src/components/DlSearch.vue +1 -1
  41. package/src/components/DlSelect/DlSelect.vue +3 -2
  42. package/src/components/DlSlider/sliderStyles.scss +4 -0
  43. package/src/components/DlSlider/useSlider.ts +39 -12
  44. package/src/components/DlSmartSearch/DlSuggestionsDropdown.vue +1 -1
  45. package/src/components/DlSpinner.vue +259 -0
  46. package/src/components/DlTable/DlTable.vue +4 -1
  47. package/src/components/DlTable/hooks/tablePagination.ts +8 -2
  48. package/src/components/DlTextArea.vue +9 -0
  49. package/src/components/DlTextInput.vue +4 -2
  50. package/src/components/DlThemeProvider.vue +22 -13
  51. package/src/components/DlToastMessage/api/useToast.ts +23 -0
  52. package/src/components/DlToastMessage/components/ToastComponent.vue +279 -0
  53. package/src/components/DlToastMessage/index.ts +5 -0
  54. package/src/components/DlToastMessage/types.ts +4 -0
  55. package/src/components/DlToastMessage/utils/config.ts +17 -0
  56. package/src/components/DlToastMessage/utils/render.ts +56 -0
  57. package/src/components/DlTypography.vue +1 -1
  58. package/src/components/DlWidget/DlGrid.vue +33 -0
  59. package/src/components/DlWidget/DlGridRow.vue +32 -0
  60. package/src/components/DlWidget/DlWidget.vue +202 -11
  61. package/src/components/DlWidget/index.ts +2 -2
  62. package/src/components/DlWidget/utils.ts +26 -19
  63. package/src/components/index.ts +8 -3
  64. package/src/demo/BarChartDemo.vue +77 -0
  65. package/src/demo/ColumnChartDemo.vue +230 -0
  66. package/src/demo/DlButtonDemo.vue +1 -1
  67. package/src/demo/DlChartDoughnutDemo.vue +229 -0
  68. package/src/demo/DlChipDemo.vue +42 -18
  69. package/src/demo/DlDialogBoxDemo.vue +4 -4
  70. package/src/demo/DlDropdownButtonDemo.vue +1 -1
  71. package/src/demo/DlLineChartDemo.vue +375 -0
  72. package/src/demo/DlMenuDemo.vue +1 -1
  73. package/src/demo/DlOptionGroupDemo.vue +1 -1
  74. package/src/demo/DlSelectDemo.vue +1 -1
  75. package/src/demo/DlSpinnerDemo.vue +20 -0
  76. package/src/demo/DlTableDemo.vue +13 -94
  77. package/src/demo/DlToastMessageDemo.vue +143 -0
  78. package/src/demo/DlWidgetDemo.vue +105 -143
  79. package/src/demo/index.ts +20 -2
  80. package/src/hooks/use-theme.ts +19 -0
  81. package/src/utils/abbreviate-to-string.ts +14 -0
  82. package/src/utils/colors.ts +47 -0
  83. package/src/utils/getRootStyles.ts +1 -1
  84. package/src/utils/index.ts +1 -0
  85. package/src/utils/position-engine.ts +11 -2
  86. package/src/utils/swapNodes.ts +30 -0
  87. package/src/utils/update-key.ts +90 -0
  88. package/tsconfig.json +0 -1
  89. package/vite.config.ts +17 -0
  90. package/Dockerfile +0 -12
  91. package/jest.config.js +0 -16
  92. package/jest.setup.js +0 -59
  93. package/src/components/DlWidget/DlWidgetGrid.vue +0 -360
  94. package/storybook.js +0 -8
@@ -0,0 +1,555 @@
1
+ <template>
2
+ <div :class="chartWrapperClasses">
3
+ <Bar
4
+ :id="id"
5
+ ref="columnChart"
6
+ :class="chartClasses"
7
+ :style="(chartStyles, `max-height: ${wrapperHeight}`)"
8
+ :data="chartData"
9
+ :options="chartOptions"
10
+ @mouseout="onChartLeave"
11
+ />
12
+ <slot
13
+ v-if="displayLabels"
14
+ v-bind="{ ...labelStyles, labels: xLabels, chartWidth }"
15
+ name="axe-x-labels"
16
+ >
17
+ <dl-chart-labels
18
+ :font-size="labelStyles.labelSize"
19
+ :title="labelStyles.title"
20
+ :title-size="labelStyles.titleSize"
21
+ :title-color="labelStyles.titleColor"
22
+ :label-color="labelStyles.labelColor"
23
+ :width="chartWidth"
24
+ :labels="xLabels"
25
+ />
26
+ </slot>
27
+ <slot
28
+ v-if="displayBrush"
29
+ v-bind="{
30
+ chartWidth,
31
+ modelValue: brush.value,
32
+ handleBrushUpdate,
33
+ brushClasses,
34
+ ...brushProperties
35
+ }"
36
+ name="brush"
37
+ >
38
+ <dl-brush
39
+ :model-value="brush.value"
40
+ :width="chartWidth"
41
+ :min="brushProperties.min"
42
+ :max="brushProperties.max"
43
+ :class="brushClasses"
44
+ :thumb-size="brushProperties.thumbSize"
45
+ :track-size="brushProperties.trackSize"
46
+ :step="brushProperties.step"
47
+ :drag-range="brushProperties.dragRange"
48
+ @update:model-value="handleBrushUpdate"
49
+ />
50
+ </slot>
51
+ <slot
52
+ v-if="displayLegend"
53
+ v-bind="{
54
+ data: legendDatasets,
55
+ chartWidth,
56
+ onHide: hideData,
57
+ onHoverLegend,
58
+ onLeaveLegend,
59
+ ...legendProperties
60
+ }"
61
+ name="legend"
62
+ >
63
+ <dl-chart-legend
64
+ :datasets="legendDatasets"
65
+ :width="chartWidth"
66
+ :class="legendClasses"
67
+ :align-items="legendProperties.alignItems"
68
+ @hide="hideData"
69
+ @on-hover="onHoverLegend"
70
+ @on-leave="onLeaveLegend"
71
+ />
72
+ </slot>
73
+ </div>
74
+ </template>
75
+
76
+ <script lang="ts">
77
+ import { Bar } from './'
78
+ import { CommonProps, ColumnChartProps, defaultColumnChartProps } from './props'
79
+ import { defineComponent, reactive, watch, ref, computed } from 'vue-demi'
80
+ import DlBrush from './DlBrush.vue'
81
+ import DlChartLegend from './DlChartLegend.vue'
82
+ import DlChartLabels from './DlChartLabels.vue'
83
+ import { updateKey } from '../../utils/update-key'
84
+ import { rgba2hex, hexToRgbA, revertRGBAOpacity } from '../../utils'
85
+ import {
86
+ Chart as ChartJS,
87
+ Title,
88
+ Tooltip,
89
+ Legend,
90
+ BarElement,
91
+ CategoryScale,
92
+ LinearScale,
93
+ PointElement,
94
+ LineElement,
95
+ BarControllerDatasetOptions
96
+ } from 'chart.js'
97
+ import type {
98
+ Chart,
99
+ ChartMeta,
100
+ ChartDataset,
101
+ ActiveElement,
102
+ ChartType
103
+ } from 'chart.js'
104
+ import { unionBy, orderBy, merge, isEqual } from 'lodash'
105
+ import { useThemeVariables } from '../../hooks/use-theme'
106
+
107
+ ChartJS.register(
108
+ Title,
109
+ Tooltip,
110
+ Legend,
111
+ BarElement,
112
+ CategoryScale,
113
+ LinearScale,
114
+ PointElement,
115
+ LineElement
116
+ )
117
+
118
+ export default defineComponent({
119
+ name: 'DlColumnChart',
120
+ components: {
121
+ DlBrush,
122
+ DlChartLegend,
123
+ Bar,
124
+ DlChartLabels
125
+ },
126
+ props: {
127
+ id: {
128
+ type: String,
129
+ default: null
130
+ },
131
+ ...CommonProps,
132
+ ...ColumnChartProps
133
+ },
134
+ setup(props, { slots }) {
135
+ const { variables } = useThemeVariables()
136
+
137
+ const chartWidth = ref('100%')
138
+
139
+ const chartHoverDataset: { value: null | ChartMeta } = {
140
+ value: null
141
+ }
142
+
143
+ const onResize = (
144
+ chart: Chart,
145
+ size: { height: number; width: number }
146
+ ) => {
147
+ if (chart?.scales?.x?.width) {
148
+ chartWidth.value = `${parseInt(
149
+ chart.scales.x.width as unknown as string
150
+ )}px`
151
+ }
152
+ }
153
+
154
+ const chart = computed(() => {
155
+ return columnChart.value?.chart?.value || {}
156
+ })
157
+
158
+ const replaceColor = (key: keyof typeof variables) =>
159
+ variables[key] || key
160
+
161
+ const columnChart = ref(null)
162
+
163
+ const brush = reactive({
164
+ value: {
165
+ min: 0,
166
+ max: orderBy(props.data.datasets, (o) => o.data.length)[0].data
167
+ .length
168
+ }
169
+ })
170
+
171
+ const chartWrapperClasses = computed(() => {
172
+ const classes = 'dl-column-chart-wrapper'
173
+
174
+ if (props.rootClass) {
175
+ classes.concat(' ', props.rootClass)
176
+ }
177
+
178
+ return classes
179
+ })
180
+
181
+ const chartClasses = computed(() => {
182
+ const classes = 'dl-column-chart'
183
+
184
+ if (props.chartClass) {
185
+ classes.concat(' ', props.chartClass)
186
+ }
187
+
188
+ return classes
189
+ })
190
+
191
+ const brushClasses = computed(() => {
192
+ const classes = 'dl-brush'
193
+
194
+ if (props.brushClass) {
195
+ classes.concat(' ', props.brushClass)
196
+ }
197
+
198
+ return classes
199
+ })
200
+
201
+ const legendClasses = computed(() => {
202
+ const classes = 'dl-legend'
203
+
204
+ if (props.legendClass) {
205
+ classes.concat(' ', props.legendClass)
206
+ }
207
+
208
+ return classes
209
+ })
210
+
211
+ const brushProperties = computed(() => {
212
+ return merge(defaultColumnChartProps.brushProps, props.brushProps)
213
+ })
214
+
215
+ const legendProperties = computed(() => {
216
+ return merge(defaultColumnChartProps.legendProps, props.legendProps)
217
+ })
218
+
219
+ const chartData = ref(
220
+ updateKey(
221
+ updateKey(props.data, 'backgroundColor', replaceColor),
222
+ 'hoverBackgroundColor',
223
+ replaceColor
224
+ )
225
+ )
226
+
227
+ const legendDatasets = ref(
228
+ unionBy(
229
+ props.legendProps?.datasets || [],
230
+ props.data?.datasets || [],
231
+ 'label'
232
+ )
233
+ )
234
+
235
+ const onChartLeave = () => {
236
+ if (chartHoverDataset.value) {
237
+ const filteredItems = chart.value.data.datasets
238
+ .map((d: ChartDataset, i: number) => ({
239
+ ...d,
240
+ index: i
241
+ }))
242
+ .filter(
243
+ (dataset: ChartDataset) =>
244
+ dataset.label !== chartHoverDataset.value.label
245
+ )
246
+
247
+ for (const dataset of filteredItems) {
248
+ chart.value.data.datasets[dataset.index].backgroundColor =
249
+ rgba2hex(revertRGBAOpacity(dataset.backgroundColor))
250
+ }
251
+ chart.value.update()
252
+ chartHoverDataset.value = null
253
+ }
254
+ }
255
+
256
+ const onHover = (
257
+ event: Event,
258
+ items: ActiveElement[],
259
+ chartJS: Chart
260
+ ) => {
261
+ if (event.type !== 'mousemove') {
262
+ return
263
+ }
264
+ if (
265
+ items.length === 0 ||
266
+ chartJS.getElementsAtEventForMode(
267
+ event,
268
+ 'nearest',
269
+ {
270
+ intersect: true
271
+ },
272
+ true
273
+ ).length === 0
274
+ ) {
275
+ if (chartHoverDataset.value) {
276
+ const filteredItems = chartJS.data.datasets
277
+ .map((d: ChartDataset, i: number) => ({
278
+ ...d,
279
+ index: i
280
+ }))
281
+ .filter(
282
+ (dataset: ChartDataset) =>
283
+ dataset.label !== chartHoverDataset.value.label
284
+ )
285
+
286
+ for (const dataset of filteredItems) {
287
+ chartJS.data.datasets[dataset.index].backgroundColor =
288
+ rgba2hex(
289
+ revertRGBAOpacity(
290
+ dataset.backgroundColor as string
291
+ )
292
+ )
293
+ }
294
+ chartJS.update()
295
+
296
+ chartHoverDataset.value = null
297
+ }
298
+ return
299
+ } else {
300
+ const item = items[0]
301
+
302
+ const datasetItem = chartJS.getDatasetMeta(item.datasetIndex)
303
+
304
+ if (!chartHoverDataset.value) {
305
+ const filteredDatasets = chartJS.data.datasets
306
+ .map((d: ChartDataset, i: number) => ({
307
+ ...d,
308
+ index: i
309
+ }))
310
+ .filter(
311
+ (ds: ChartDataset) => ds.label !== datasetItem.label
312
+ )
313
+
314
+ for (const dataset of filteredDatasets) {
315
+ chartJS.data.datasets[dataset.index].backgroundColor =
316
+ hexToRgbA(dataset.backgroundColor as string, 0.2)
317
+ }
318
+
319
+ chartJS.update()
320
+
321
+ chartHoverDataset.value = datasetItem
322
+
323
+ return
324
+ }
325
+
326
+ if (!isEqual(chartHoverDataset.value, datasetItem)) {
327
+ const filteredItems = chartJS.data.datasets
328
+ .map((d: ChartDataset, i: number) => ({
329
+ ...d,
330
+ index: i
331
+ }))
332
+ .filter(
333
+ (dataset: ChartDataset) =>
334
+ dataset.label !== chartHoverDataset.value.label
335
+ )
336
+
337
+ for (const dataset of filteredItems) {
338
+ chartJS.data.datasets[dataset.index].backgroundColor =
339
+ rgba2hex(
340
+ revertRGBAOpacity(
341
+ dataset.backgroundColor as string
342
+ )
343
+ )
344
+ }
345
+
346
+ chartHoverDataset.value = datasetItem
347
+
348
+ const allFilteredItems = chartJS.data.datasets
349
+ .map((d: ChartDataset, i: number) => ({
350
+ ...d,
351
+ index: i
352
+ }))
353
+ .filter(
354
+ (dataset: ChartDataset) =>
355
+ dataset.label !== datasetItem.label
356
+ )
357
+
358
+ for (const dataset of allFilteredItems) {
359
+ chartJS.data.datasets[dataset.index].backgroundColor =
360
+ hexToRgbA(dataset.backgroundColor as string, 0.2)
361
+ }
362
+ chartJS.update()
363
+ }
364
+ }
365
+ }
366
+
367
+ const chartOptions = reactive(
368
+ updateKey(
369
+ merge(
370
+ { onResize, onHover },
371
+ defaultColumnChartProps.options,
372
+ props.options
373
+ ),
374
+ 'color',
375
+ replaceColor
376
+ )
377
+ )
378
+
379
+ watch(
380
+ () => chart.value?.scales?.x?.width,
381
+ (val: string) => {
382
+ if (val) {
383
+ chartWidth.value = `${parseInt(val as unknown as string)}px`
384
+ }
385
+ },
386
+ { deep: true }
387
+ )
388
+
389
+ const handleBrushUpdate = (value: { min: number; max: number }) => {
390
+ brush.value.min = value.min
391
+ brush.value.max = value.max
392
+
393
+ chart.value.options.scales.x.min = value.min
394
+ chart.value.options.scales.x.max = value.max
395
+
396
+ xLabels.value = chart.value.data.labels.slice(
397
+ value.min,
398
+ value.max + brushProperties.value.step
399
+ )
400
+
401
+ chart.value.update()
402
+ }
403
+
404
+ const xLabels = ref(props.data.labels)
405
+
406
+ const onHoverLegend = (
407
+ item: BarControllerDatasetOptions,
408
+ index: number
409
+ ) => {
410
+ const filteredItems = chart.value.data.datasets
411
+ .map((d: ChartDataset, i: number) => ({
412
+ ...d,
413
+ index: i
414
+ }))
415
+ .filter(
416
+ (dataset: ChartDataset & { index: number }) =>
417
+ dataset.index! !== index
418
+ )
419
+
420
+ for (const dataset of filteredItems) {
421
+ chart.value.data.datasets[dataset.index].backgroundColor =
422
+ hexToRgbA(dataset.backgroundColor, 0.2)
423
+ }
424
+ chart.value.update()
425
+ }
426
+
427
+ const onLeaveLegend = (
428
+ item: BarControllerDatasetOptions,
429
+ index: number
430
+ ) => {
431
+ const filteredItems = chart.value.data.datasets
432
+ .map((d: ChartDataset, i: number) => ({
433
+ ...d,
434
+ index: i
435
+ }))
436
+ .filter(
437
+ (dataset: ChartDataset & { index: number }) =>
438
+ dataset.index !== index
439
+ )
440
+
441
+ for (const dataset of filteredItems) {
442
+ chart.value.data.datasets[dataset.index].backgroundColor =
443
+ rgba2hex(revertRGBAOpacity(dataset.backgroundColor))
444
+ }
445
+ chart.value.update()
446
+ }
447
+
448
+ const labelStyles = computed(() => {
449
+ const options = merge(
450
+ {},
451
+ defaultColumnChartProps.options,
452
+ props.options
453
+ )
454
+ return {
455
+ title: options.scales.x.title.text,
456
+ titleSize: `${options.scales.x.title.font.size}px`,
457
+ titleColor: options.scales.x.title.color.replace('--', ''),
458
+ labelColor: options.scales.x.ticks.color.replace('--', ''),
459
+ fontSize: `${options.scales.x.ticks.font.size}px`
460
+ }
461
+ })
462
+
463
+ const hideData = (item: BarControllerDatasetOptions, index: number) => {
464
+ onLeaveLegend(item, index)
465
+
466
+ chart.value.data.datasets[index].hidden = !!item.hidden
467
+
468
+ legendDatasets.value.splice(index, 1, {
469
+ ...legendDatasets.value[index],
470
+ hidden: !!item.hidden
471
+ })
472
+
473
+ chart.value.update()
474
+ }
475
+
476
+ watch(variables, () => {
477
+ merge(
478
+ chart.value.data,
479
+ updateKey(
480
+ updateKey(props.data, 'backgroundColor', replaceColor),
481
+ 'hoverBackgroundColor',
482
+ replaceColor
483
+ )
484
+ )
485
+
486
+ merge(
487
+ chart.value.options,
488
+ updateKey(
489
+ merge(
490
+ { onResize, onHover },
491
+ defaultColumnChartProps.options,
492
+ props.options
493
+ ),
494
+ 'color',
495
+ replaceColor
496
+ )
497
+ )
498
+
499
+ chart.value.options.scales.x.min = brush.value.min
500
+ chart.value.options.scales.x.max = brush.value.max
501
+
502
+ chart.value.update()
503
+ })
504
+
505
+ return {
506
+ variables,
507
+ chartData,
508
+ chartOptions,
509
+ brush,
510
+ xLabels,
511
+ columnChart,
512
+ handleBrushUpdate,
513
+ chartWrapperClasses,
514
+ chartClasses,
515
+ brushClasses,
516
+ legendClasses,
517
+ brushProperties,
518
+ legendDatasets,
519
+ legendProperties,
520
+ hideData,
521
+ chartWidth,
522
+ onHoverLegend,
523
+ onLeaveLegend,
524
+ onChartLeave,
525
+ chart,
526
+ labelStyles
527
+ }
528
+ },
529
+ data() {
530
+ return {}
531
+ }
532
+ })
533
+ </script>
534
+
535
+ <style scoped lang="scss">
536
+ .dl-column-chart-wrapper {
537
+ display: flex;
538
+ flex-direction: column;
539
+ align-self: stretch;
540
+ }
541
+
542
+ .dl-brush {
543
+ margin-top: 10px;
544
+ }
545
+
546
+ .dl-legend {
547
+ margin-top: 16px;
548
+ margin-bottom: 16px;
549
+ }
550
+
551
+ .dl-brush,
552
+ .dl-legend {
553
+ align-self: flex-end;
554
+ }
555
+ </style>