Skip to content

Commit f8011b5

Browse files
committed
VueUiSparkHistogram add selector
1 parent 6c960fa commit f8011b5

File tree

6 files changed

+40
-7
lines changed

6 files changed

+40
-7
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": "1.9.18",
4+
"version": "1.9.19",
55
"type": "module",
66
"description": "A user-empowering data visualization Vue components library",
77
"keywords": [

src/components/vue-ui-donut.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup>
22
import { ref, computed, nextTick } from "vue";
3-
import { makeDonut, palette, convertColorToHex, createUid, opacity, makeXls } from '../lib';
3+
import { makeDonut, palette, convertColorToHex, opacity, makeXls } from '../lib';
44
import pdf from "../pdf";
55
import img from "../img";
66
import mainConfig from "../default_configs.json";

src/components/vue-ui-sparkhistogram.vue

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const computedDataset = computed(() => {
6969
const width = unitWidth - gap;
7070
const y = drawingArea.value.centerY - height / 2;
7171
const x = drawingArea.value.left + (gap / 2 + (i * unitWidth));
72+
const trapX = drawingArea.value.left + (i * unitWidth);
7273
const intensity = typeof dp.intensity === 'undefined' ? 100 : Math.round(dp.intensity * 100);
7374
const color = dp.value >= 0 ? `${histoConfig.value.style.bars.colors.positive}${opacity[intensity]}` : `${histoConfig.value.style.bars.colors.negative}${opacity[intensity]}`;
7475
const stroke = dp.value >= 0 ? histoConfig.value.style.bars.colors.positive : histoConfig.value.style.bars.colors.negative;
@@ -83,28 +84,32 @@ const computedDataset = computed(() => {
8384
proportion,
8485
stroke,
8586
textAnchor,
87+
trapX,
88+
unitWidth,
8689
width,
8790
x,
8891
y
8992
}
9093
});
9194
});
9295
96+
const selectedIndex = ref(null);
97+
9398
</script>
9499

95100
<template>
96-
<div :style="`width:100%;background:${histoConfig.style.backgroundColor};font-family:${histoConfig.style.fontFamily}`">
101+
<div :style="`width:100%;background:${histoConfig.style.backgroundColor};font-family:${histoConfig.style.fontFamily}`" @mouseleave="selectedIndex = null">
97102
<!-- TITLE -->
98103
<div v-if="histoConfig.style.title.text" :style="`width:calc(100% - 12px);background:${histoConfig.style.backgroundColor};margin:0 auto;margin:${histoConfig.style.title.margin};padding: 0 6px;text-align:${histoConfig.style.title.textAlign}`">
99104
<div :style="`font-size:${histoConfig.style.title.fontSize}px;color:${histoConfig.style.title.color};font-weight:${histoConfig.style.title.bold ? 'bold' : 'normal'}`">
100-
{{ histoConfig.style.title.text }}
105+
{{ histoConfig.style.title.text }} <span v-if="selectedIndex !== null">- {{ computedDataset[selectedIndex].timeLabel || '' }} {{ histoConfig.style.labels.value.prefix }}{{ isNaN(computedDataset[selectedIndex].value) ? '' : ': ' + Number(computedDataset[selectedIndex].value.toFixed(histoConfig.style.labels.value.rounding)).toLocaleString() }}{{ histoConfig.style.labels.value.suffix }}</span> <span v-if="![undefined, null].includes(selectedIndex)">({{ computedDataset[selectedIndex].valueLabel || 0 }})</span>
101106
</div>
102107
<div v-if="histoConfig.style.title.subtitle.text" :style="`font-size:${histoConfig.style.title.subtitle.fontSize}px;color:${histoConfig.style.title.subtitle.color};font-weight:${histoConfig.style.title.subtitle.bold ? 'bold' : 'normal'}`">
103108
{{ histoConfig.style.title.subtitle.text }}
104109
</div>
105110
</div>
106111

107-
<svg data-cy="sparkhistogram-svg" :viewBox="`0 0 ${drawingArea.width} ${drawingArea.height}`">
112+
<svg data-cy="sparkhistogram-svg" :viewBox="`0 0 ${drawingArea.width} ${drawingArea.height}`" style="overflow: visible">
108113
<defs>
109114
<radialGradient v-for="(posGrad, i) in computedDataset" :id="`gradient_positive_${i}_${uid}`" cy="50%" cx="50%" r="50%" fx="50%" fy="50%">
110115
<stop offset="0%" :stop-color="`${shiftHue(histoConfig.style.bars.colors.positive, 0.05)}${opacity[posGrad.intensity]}`"/>
@@ -170,6 +175,22 @@ const computedDataset = computed(() => {
170175
</text>
171176
</g>
172177

178+
<!-- TOOLTIP TRAPS -->
179+
<g v-for="(rect, i) in computedDataset">
180+
<rect
181+
:height="drawingArea.height"
182+
:width="rect.unitWidth"
183+
fill="transparent"
184+
:x="rect.trapX"
185+
:y="0" @mouseover="selectedIndex = i"
186+
@mouseleave="selectedIndex = null"
187+
:stroke="selectedIndex !== null && selectedIndex === i ? histoConfig.style.selector.stroke : ''"
188+
:stroke-width="selectedIndex !== null && selectedIndex === i ? histoConfig.style.selector.strokeWidth : 0"
189+
:rx="histoConfig.style.selector.borderRadius"
190+
:stroke-dasharray="histoConfig.style.selector.strokeDasharray"
191+
/>
192+
</g>
193+
173194
</svg>
174195
</div>
175196
</template>

src/default_configs.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,12 @@
24052405
"bold": false
24062406
}
24072407
},
2408+
"selector": {
2409+
"stroke": "#3366cc",
2410+
"strokeWidth": 2,
2411+
"strokeDasharray": 0,
2412+
"borderRadius": 2
2413+
},
24082414
"title": {
24092415
"textAlign": "left",
24102416
"text": "",

types/vue-data-ui.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ declare module 'vue-data-ui' {
5252
bold?: boolean;
5353
};
5454
};
55+
selector?: {
56+
stroke?: string;
57+
strokeDasharray?: number;
58+
strokeWidth?: number;
59+
borderRadius?: number;
60+
};
5561
title?: {
5662
textAlign?: "left" | "right" | "center";
5763
text?: string;

0 commit comments

Comments
 (0)