@@ -26,6 +26,7 @@ import { useResponsive } from "../useResponsive";
26
26
import { throttle } from " ../canvas-lib" ;
27
27
import PackageVersion from " ../atoms/PackageVersion.vue" ;
28
28
import { useChartAccessibility } from " ../useChartAccessibility" ;
29
+ import SparkTooltip from " ../atoms/SparkTooltip.vue"
29
30
30
31
const { vue_ui_sparkline: DEFAULT_CONFIG } = useConfig ();
31
32
@@ -317,14 +318,19 @@ const area = computed(() => {
317
318
318
319
319
320
const selectedPlot = ref (undefined );
321
+ const previousSelectedPlot = ref (undefined );
320
322
321
323
function selectPlot (plot , index ) {
322
324
selectedPlot .value = plot;
325
+ if (! previousSelectedPlot .value ) {
326
+ previousSelectedPlot .value = plot;
327
+ }
323
328
emits (' hoverIndex' , {index})
324
329
}
325
330
326
331
function unselectPlot () {
327
- selectedPlot .value = undefined
332
+ previousSelectedPlot .value = selectedPlot .value ;
333
+ selectedPlot .value = undefined ;
328
334
emits (' hoverIndex' , {index: undefined })
329
335
}
330
336
@@ -409,6 +415,7 @@ function selectDatapoint(datapoint, index) {
409
415
v-if =" isDataset"
410
416
data-cy =" sparkline-svg"
411
417
:viewBox =" `0 0 ${svg.width} ${svg.height}`" :style =" `background:${FINAL_CONFIG.style.backgroundColor};overflow:visible`"
418
+ @mouseleave =" previousSelectedPlot = undefined"
412
419
>
413
420
<PackageVersion />
414
421
@@ -557,6 +564,39 @@ function selectDatapoint(datapoint, index) {
557
564
<slot name =" svg" :svg =" svg" />
558
565
</svg >
559
566
567
+ <SparkTooltip
568
+ v-if =" selectedPlot && FINAL_CONFIG.style.tooltip.show"
569
+ :x =" selectedPlot.x"
570
+ :y =" selectedPlot.y"
571
+ :prevX =" previousSelectedPlot.x"
572
+ :prevY =" previousSelectedPlot.y"
573
+ :offsetY =" FINAL_CONFIG.style.plot.radius * 3 + FINAL_CONFIG.style.tooltip.offsetY"
574
+ :svgRef =" svgRef"
575
+ :background =" FINAL_CONFIG.style.tooltip.backgroundColor"
576
+ :color =" FINAL_CONFIG.style.tooltip.color"
577
+ :fontSize =" FINAL_CONFIG.style.tooltip.fontSize"
578
+ :borderWidth =" FINAL_CONFIG.style.tooltip.borderWidth"
579
+ :borderColor =" FINAL_CONFIG.style.tooltip.borderColor"
580
+ :borderRadius =" FINAL_CONFIG.style.tooltip.borderRadius"
581
+ :backgroundOpacity =" FINAL_CONFIG.style.tooltip.backgroundOpacity"
582
+ >
583
+ <slot name =" tootlip" v-bind =" { ...selectedPlot }" >
584
+ {{ selectedPlot.period }}: {{
585
+ applyDataLabel(
586
+ FINAL_CONFIG.style.dataLabel.formatter,
587
+ selectedPlot.absoluteValue,
588
+ dl({
589
+ p: FINAL_CONFIG.style.dataLabel.prefix,
590
+ v: selectedPlot.absoluteValue,
591
+ s: FINAL_CONFIG.style.dataLabel.suffix,
592
+ r: FINAL_CONFIG.style.dataLabel.roundingValue
593
+ }),
594
+ { datapoint: selectedPlot }
595
+ )
596
+ }}
597
+ </slot >
598
+ </SparkTooltip >
599
+
560
600
<div v-if =" $slots.source" ref =" source" dir =" auto" >
561
601
<slot name =" source" />
562
602
</div >
0 commit comments