@@ -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 >
0 commit comments