@dataloop-ai/components 0.19.219 → 0.19.221

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataloop-ai/components",
3
- "version": "0.19.219",
3
+ "version": "0.19.221",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -98,6 +98,11 @@ import { TDoughnutWithOriginalColor } from './types/TDoughnutWithOriginalColor'
98
98
  import DlEmptyState from '../../../../basic/DlEmptyState/DlEmptyState.vue'
99
99
  import { DlEmptyStateProps } from '../../../../basic/DlEmptyState/types'
100
100
 
101
+ type SetupParams = {
102
+ attrs: { onItemClick?: (index: number) => void }
103
+ listeners?: { itemClick?: (index: number) => void }
104
+ }
105
+
101
106
  export default defineComponent({
102
107
  name: 'DlDoughnutChart',
103
108
  components: {
@@ -132,7 +137,7 @@ export default defineComponent({
132
137
  default: () => doughnutChartEmptyStateProps
133
138
  }
134
139
  },
135
- setup(props) {
140
+ setup(props, params: SetupParams) {
136
141
  /** Data */
137
142
  const doughnutChartRef = ref(null)
138
143
  const dlDoughnutChartWidgetRef = ref(null)
@@ -304,6 +309,23 @@ export default defineComponent({
304
309
  }
305
310
  }
306
311
  }
312
+ },
313
+ onClick: (e: Event & { chart: ChartJS }) => {
314
+ const itemClick =
315
+ params.attrs.onItemClick ??
316
+ params.listeners?.itemClick
317
+ if (itemClick) {
318
+ const intersects =
319
+ e.chart.getElementsAtEventForMode(
320
+ e,
321
+ 'nearest',
322
+ { intersect: true },
323
+ false
324
+ )
325
+ if (intersects.length > 0) {
326
+ itemClick(intersects[0].index)
327
+ }
328
+ }
307
329
  }
308
330
  },
309
331
  defaultOptions
@@ -5,6 +5,7 @@
5
5
  <DlDoughnutChart
6
6
  :data="doughnutLessData"
7
7
  :animation="doughnutAnimation"
8
+ @itemClick="handleItemClick"
8
9
  >
9
10
  <template #default="{ item, index }">
10
11
  <span style="color: tomato">
@@ -230,7 +231,12 @@ export default defineComponent({
230
231
  return {
231
232
  doughnutData,
232
233
  doughnutLessData,
233
- doughnutAnimation
234
+ doughnutAnimation,
235
+ handleItemClick: (index: number) => {
236
+ alert(
237
+ `You clicked ${doughnutLessData.datasets[0].data[index]} 🍅`
238
+ )
239
+ }
234
240
  }
235
241
  }
236
242
  })