@@ -21,6 +21,10 @@ const props = defineProps({
2121 default () {
2222 return []
2323 }
24+ },
25+ showInfo : {
26+ type: Boolean ,
27+ default: true
2428 }
2529});
2630
@@ -39,15 +43,17 @@ const svg = ref({
3943 width: 500 ,
4044});
4145
46+ const emits = defineEmits ([' hoverIndex' ])
47+
4248const drawingArea = computed (() => {
4349 const topPadding = 12 ;
4450 return {
4551 top: topPadding,
4652 left: 0 ,
4753 right: svg .value .width ,
4854 bottom: svg .value .height - 3 ,
49- start: sparklineConfig .value .style .dataLabel .position === ' left' ? 210 : 0 ,
50- width: 290 ,
55+ start: props . showInfo && sparklineConfig .value .style .dataLabel .position === ' left' ? 210 : 0 ,
56+ width: props . showInfo ? 290 : svg . value . width ,
5157 height: svg .value .height - topPadding
5258 }
5359});
@@ -110,8 +116,14 @@ const area = computed(() => {
110116
111117const selectedPlot = ref (undefined );
112118
113- function selectPlot (plot ) {
119+ function selectPlot (plot , index ) {
114120 selectedPlot .value = plot;
121+ emits (' hoverIndex' , {index})
122+ }
123+
124+ function unselectPlot () {
125+ selectedPlot .value = undefined
126+ emits (' hoverIndex' , {index: undefined })
115127}
116128
117129const dataLabel = computed (() => {
@@ -135,7 +147,7 @@ const isBar = computed(() => {
135147<template >
136148 <div class =" vue-ui-sparkline" :id =" uid" :style =" `width:100%;font-family:${sparklineConfig.style.fontFamily}`" >
137149 <!-- TITLE -->
138- <div v-if =" sparklineConfig.style.title.show" class =" vue-ui-sparkline-title" :style =" `display:flex;align-items:center;width:100%;color:${sparklineConfig.style.title.color};background:${sparklineConfig.style.backgroundColor};justify-content:${sparklineConfig.style.title.textAlign === 'left' ? 'flex-start' : sparklineConfig.style.title.textAlign === 'right' ? 'flex-end' : 'center'};height:${sparklineConfig.style.title.fontSize * 2}px;font-size:${sparklineConfig.style.title.fontSize}px;font-weight:${sparklineConfig.style.title.bold ? 'bold' : 'normal'};`" >
150+ <div v-if =" sparklineConfig.style.title.show && showInfo " class =" vue-ui-sparkline-title" :style =" `display:flex;align-items:center;width:100%;color:${sparklineConfig.style.title.color};background:${sparklineConfig.style.backgroundColor};justify-content:${sparklineConfig.style.title.textAlign === 'left' ? 'flex-start' : sparklineConfig.style.title.textAlign === 'right' ? 'flex-end' : 'center'};height:${sparklineConfig.style.title.fontSize * 2}px;font-size:${sparklineConfig.style.title.fontSize}px;font-weight:${sparklineConfig.style.title.bold ? 'bold' : 'normal'};`" >
139151 <span data-cy =" sparkline-period-label" :style =" `padding:${sparklineConfig.style.title.textAlign === 'left' ? '0 0 0 12px' : sparklineConfig.style.title.textAlign === 'right' ? '0 12px 0 0' : '0'}`" >
140152 {{ selectedPlot ? selectedPlot.period : sparklineConfig.style.title.text }}
141153 </span >
@@ -247,6 +259,7 @@ const isBar = computed(() => {
247259
248260 <!-- DATALABEL -->
249261 <text
262+ v-if =" showInfo"
250263 data-cy =" sparkline-datalabel"
251264 :x =" sparklineConfig.style.dataLabel.position === 'left' ? 12 : drawingArea.width + 12"
252265 :y =" svg.height / 2 + sparklineConfig.style.dataLabel.fontSize / 2.5"
@@ -266,8 +279,8 @@ const isBar = computed(() => {
266279 :height =" drawingArea.height + 6"
267280 :width =" (drawingArea.width / len)"
268281 fill =" transparent"
269- @mouseenter =" selectPlot(plot)"
270- @mouseleave =" selectedPlot = undefined "
282+ @mouseenter =" selectPlot(plot, i )"
283+ @mouseleave =" unselectPlot "
271284 />
272285 <slot name =" svg" :svg =" svg" />
273286 </svg >
0 commit comments