Skip to content

Commit 64d62fe

Browse files
committed
Added @selectDatpoint emit event on all mini charts
1 parent 9c91756 commit 64d62fe

File tree

8 files changed

+80
-6
lines changed

8 files changed

+80
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-data-ui",
33
"private": false,
4-
"version": "2.0.9",
4+
"version": "2.0.10",
55
"type": "module",
66
"description": "A user-empowering data visualization Vue components library",
77
"keywords": [

src/App.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,6 +2453,22 @@ const moleculeConfig = ref({
24532453
}
24542454
})
24552455
2456+
function selectSparklineDatapoint({ datapoint, index }) {
2457+
console.log({datapoint, index })
2458+
}
2459+
2460+
function selectSparkbarDatapoint({ datapoint, index }) {
2461+
console.log({ datapoint, index })
2462+
}
2463+
2464+
function selectStackbarDatapoint({ datapoint, index }) {
2465+
console.log({ datapoint, index })
2466+
}
2467+
2468+
function selectHistoDatapoint({ datapoint, index }) {
2469+
console.log({ datapoint, index })
2470+
}
2471+
24562472
</script>
24572473

24582474
<template>
@@ -2923,8 +2939,10 @@ const moleculeConfig = ref({
29232939
</template>
29242940
<template #dev>
29252941
<SparklineTest
2942+
ref="sparkline"
29262943
:config="sparklineConfig"
29272944
:dataset="sparklineDataset"
2945+
@selectDatapoint="selectSparklineDatapoint"
29282946
>
29292947
<template #svg="{ svg }">
29302948
<circle :cx="svg.width / 2" :cy="svg.height / 2" :r="30" fill="#FF000033"/>
@@ -2935,6 +2953,7 @@ const moleculeConfig = ref({
29352953
<VueUiSparkline
29362954
:config="sparklineConfig"
29372955
:dataset="sparklineDataset"
2956+
@selectDatapoint="selectSparklineDatapoint"
29382957
>
29392958
<template #svg="{ svg }">
29402959
<circle :cx="svg.width / 2" :cy="svg.height / 2" :r="30" fill="#FF000033"/>
@@ -2999,12 +3018,14 @@ const moleculeConfig = ref({
29993018
<HistoTest
30003019
:dataset="histoDataset"
30013020
:config="histoConfig"
3021+
@selectDatapoint="selectHistoDatapoint"
30023022
/>
30033023
</template>
30043024
<template #prod>
30053025
<VueUiSparkHistogram
30063026
:dataset="histoDataset"
30073027
:config="histoConfig"
3028+
@selectDatapoint="selectHistoDatapoint"
30083029
/>
30093030
</template>
30103031
<template #config>
@@ -3316,11 +3337,13 @@ const moleculeConfig = ref({
33163337
<template #dev>
33173338
<StackTest
33183339
:dataset="stackDataset"
3340+
@selectDatapoint="selectStackbarDatapoint"
33193341
/>
33203342
</template>
33213343
<template #prod>
33223344
<VueUiSparkStackbar
33233345
:dataset="stackDataset"
3346+
@selectDatapoint="selectStackbarDatapoint"
33243347
/>
33253348
</template>
33263349
<template #config>
@@ -3641,12 +3664,14 @@ const moleculeConfig = ref({
36413664
<SparkbarTest
36423665
:config="sparkbarConfig"
36433666
:dataset="sparkbarDataset"
3667+
@selectDatapoint="selectSparkbarDatapoint"
36443668
/>
36453669
</template>
36463670
<template #prod>
36473671
<VueUiSparkbar
36483672
:config="sparkbarConfig"
36493673
:dataset="sparkbarDataset"
3674+
@selectDatapoint="selectSparkbarDatapoint"
36503675
/>
36513676
</template>
36523677
<template #config>

src/components/vue-ui-sparkbar.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,18 @@ function ratioTo(val) {
6565
}
6666
}
6767
68+
const emits = defineEmits(['selectDatapoint'])
69+
70+
function selectDatapoint(datapoint, index) {
71+
emits("selectDatapoint", { datapoint, index })
72+
}
73+
6874
</script>
6975

7076
<template>
7177
<div :style="`width:100%; font-family:${sparkbarConfig.style.fontFamily};background:${sparkbarConfig.style.backgroundColor}`">
7278
<template v-for="(bar, i) in drawableDataset">
73-
<div :style="`display:flex !important;${['left', 'right'].includes(sparkbarConfig.style.labels.name.position) ? 'flex-direction:row !important' : 'flex-direction:column !important'};gap:${sparkbarConfig.style.gap}px !important;${sparkbarConfig.style.labels.name.position === 'right' ? 'row-reverse !important' : ''};align-items:center;${dataset.length > 0 && i !== dataset.length - 1 ? 'margin-bottom:6px' : ''}`">
79+
<div :style="`display:flex !important;${['left', 'right'].includes(sparkbarConfig.style.labels.name.position) ? 'flex-direction:row !important' : 'flex-direction:column !important'};gap:${sparkbarConfig.style.gap}px !important;${sparkbarConfig.style.labels.name.position === 'right' ? 'row-reverse !important' : ''};align-items:center;${dataset.length > 0 && i !== dataset.length - 1 ? 'margin-bottom:6px' : ''}`" @click="() => selectDatapoint(bar, i)">
7480
<div :style="`width:${sparkbarConfig.style.labels.name.width};${['right','top'].includes(sparkbarConfig.style.labels.name.position) ? 'text-align:left' : 'text-align:right'};color:${sparkbarConfig.style.labels.name.color};font-size:${sparkbarConfig.style.labels.fontSize}px;font-weight:${sparkbarConfig.style.labels.name.bold ? 'bold' : 'normal'}`">
7581
<span :data-cy="`sparkbar-name-${i}`">{{ bar.name }}</span>
7682
<span :data-cy="`sparkbar-value-${i}`" v-if="sparkbarConfig.style.labels.value.show" :style="`font-weight:${sparkbarConfig.style.labels.value.bold ? 'bold' : 'normal'}`">

src/components/vue-ui-sparkhistogram.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ const computedDataset = computed(() => {
9696
9797
const selectedIndex = ref(null);
9898
99+
const emits = defineEmits(['selectDatapoint'])
100+
101+
function selectDatapoint(datapoint, index) {
102+
emits('selectDatapoint', { datapoint, index })
103+
}
104+
99105
</script>
100106

101107
<template>
@@ -200,6 +206,7 @@ const selectedIndex = ref(null);
200206
:stroke-width="selectedIndex !== null && selectedIndex === i ? histoConfig.style.selector.strokeWidth : 0"
201207
:rx="histoConfig.style.selector.borderRadius"
202208
:stroke-dasharray="histoConfig.style.selector.strokeDasharray"
209+
@click="() => selectDatapoint(rect, i)"
203210
/>
204211
</g>
205212

src/components/vue-ui-sparkline.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const svg = ref({
4848
width: 500,
4949
});
5050
51-
const emits = defineEmits(['hoverIndex'])
51+
const emits = defineEmits(['hoverIndex', 'selectDatapoint'])
5252
5353
const drawingArea = computed(() => {
5454
const topPadding = 12;
@@ -147,6 +147,9 @@ const isBar = computed(() => {
147147
return sparklineConfig.value.type && sparklineConfig.value.type === 'bar';
148148
});
149149
150+
function selectDatapoint(datapoint, index) {
151+
emits('selectDatapoint', { datapoint, index })
152+
}
150153
</script>
151154

152155
<template>
@@ -286,6 +289,7 @@ const isBar = computed(() => {
286289
fill="transparent"
287290
@mouseenter="selectPlot(plot, i)"
288291
@mouseleave="unselectPlot"
292+
@click="() => selectDatapoint(plot, i)"
289293
/>
290294
<slot name="svg" :svg="svg"/>
291295
</svg>

src/components/vue-ui-sparkstackbar.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ const drawableDataset = computed(() => {
6363
return datapoints;
6464
})
6565
66+
const emits = defineEmits(['selectDatapoint'])
67+
68+
function selectDatapoint(datapoint, index) {
69+
emits('selectDatapoint', { datapoint, index })
70+
}
71+
6672
</script>
6773

6874
<template>
@@ -101,6 +107,7 @@ const drawableDataset = computed(() => {
101107
<rect :x="0" :y="0" :height="svg.height" :width="svg.width" :fill="stackConfig.style.bar.gradient.underlayerColor"/>
102108
<rect
103109
v-for="(rect, i) in drawableDataset" :key="`stack_${i}`"
110+
@click="() => selectDatapoint(rect, i)"
104111
:x="rect.start"
105112
:y="0"
106113
:width="rect.width"
@@ -113,7 +120,7 @@ const drawableDataset = computed(() => {
113120
</svg>
114121
<div v-if="stackConfig.style.legend.show" data-cy="sparkstackbar-legend" :style="`background:${stackConfig.style.backgroundColor};display:flex;flex-wrap:wrap;column-gap:12px;width:calc(100% - 12px);margin:0 auto;margin:${stackConfig.style.legend.margin}; padding: 0 6px;justify-content:${stackConfig.style.legend.textAlign === 'left' ? 'flex-start' : stackConfig.style.legend.textAlign === 'right' ? 'flex-end' : 'center'}`">
115122
<div v-for=" (rect, i) in drawableDataset" :style="`font-size:${stackConfig.style.legend.fontSize}px`">
116-
<div style="display:flex;flex-direction:row;align-items:center;gap:4px;justify-content:center">
123+
<div style="display:flex;flex-direction:row;align-items:center;gap:4px;justify-content:center" >
117124
<svg :height="`${stackConfig.style.legend.fontSize}px`" :width="`${stackConfig.style.legend.fontSize}px`" viewBox="0 0 10 10">
118125
<circle :cx="5" :cy="5" :r="5" :fill="rect.color"/>
119126
</svg>

types/vue-data-ui.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,19 @@ declare module 'vue-data-ui' {
850850
valueLabel?: string;
851851
timeLabel?: string;
852852
intensity?: number & { 0: 0; 1: 1 };
853+
gradient?: string;
854+
height?: number;
855+
proportion?: number;
856+
stroke?: string;
857+
textAnchor?: number;
858+
timeLabel?: string;
859+
trapX?: number;
860+
unitWidth?: number;
861+
value?: number;
862+
valueLabel?: string;
863+
width?: number;
864+
x?: number;
865+
y?: number;
853866
}
854867

855868
export const VueUiSparkHistogram: DefineComponent<{
@@ -913,6 +926,11 @@ declare module 'vue-data-ui' {
913926
name: string;
914927
value: number;
915928
color?: string;
929+
proportion?: number;
930+
proportionLabel?: string;
931+
start?: number;
932+
value?: number;
933+
width?: number;
916934
}
917935

918936
export const VueUiSparkstackbar: DefineComponent<{
@@ -3333,6 +3351,13 @@ declare module 'vue-data-ui' {
33333351
export type VueUiSparklineDatasetItem = {
33343352
period: string;
33353353
value: number;
3354+
absoluteValue?: number;
3355+
id?: string;
3356+
plotValue?: number;
3357+
toMax?: number;
3358+
width?: number;
3359+
x?: number;
3360+
y?: number;
33363361
};
33373362

33383363
export type VueUiSparklineConfig = {

0 commit comments

Comments
 (0)