Skip to content

Commit 2e4cadd

Browse files
committed
Improvement - VueUiGauge - Add config attributes to further customize labels
1 parent 2c9d727 commit 2e4cadd

File tree

1 file changed

+51
-25
lines changed

1 file changed

+51
-25
lines changed

src/components/vue-ui-gauge.vue

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -514,32 +514,46 @@ defineExpose({
514514
</template>
515515

516516
<!-- STEP MARKERS -->
517-
<text
518-
v-for="(arc, i) in arcs"
519-
:data-cy="`gauge-step-marker-label-${i}`"
520-
:x="offsetFromCenterPoint({
521-
centerX: svg.width / 2,
522-
centerY: arcSizeSource.base,
523-
initX: arc.center.startX,
524-
initY: arc.center.startY,
525-
offset: svg.markerOffset
526-
}).x"
527-
:y="offsetFromCenterPoint({
528-
centerX: svg.width / 2,
529-
centerY: arcSizeSource.base,
530-
initX: arc.center.startX,
531-
initY: arc.center.startY,
532-
offset: svg.markerOffset
533-
}).y"
534-
:text-anchor="arc.center.startX < (svg.width / 2 - 5) ? 'end' : arc.center.startX > (svg.width / 2 + 5) ? 'start' : 'middle'"
535-
:font-size="svg.labelFontSize * FINAL_CONFIG.style.chart.layout.markers.fontSizeRatio"
536-
:font-weight="`${FINAL_CONFIG.style.chart.layout.markers.bold ? 'bold' : 'normal'}`"
537-
:fill="FINAL_CONFIG.style.chart.layout.markers.color"
538-
>
539-
{{ arc.from.toFixed(FINAL_CONFIG.style.chart.layout.markers.roundingValue) }}
540-
</text>
517+
<g v-if="FINAL_CONFIG.style.chart.layout.markers.show">
518+
<text
519+
v-for="(arc, i) in arcs"
520+
:data-cy="`gauge-step-marker-label-${i}`"
521+
:x="offsetFromCenterPoint({
522+
centerX: svg.width / 2,
523+
centerY: arcSizeSource.base,
524+
initX: arc.center.startX,
525+
initY: arc.center.startY,
526+
offset: svg.markerOffset
527+
}).x"
528+
:y="offsetFromCenterPoint({
529+
centerX: svg.width / 2,
530+
centerY: arcSizeSource.base,
531+
initX: arc.center.startX,
532+
initY: arc.center.startY,
533+
offset: svg.markerOffset
534+
}).y"
535+
:text-anchor="arc.center.startX < (svg.width / 2 - 5) ? 'end' : arc.center.startX > (svg.width / 2 + 5) ? 'start' : 'middle'"
536+
:font-size="svg.labelFontSize * FINAL_CONFIG.style.chart.layout.markers.fontSizeRatio"
537+
:font-weight="`${FINAL_CONFIG.style.chart.layout.markers.bold ? 'bold' : 'normal'}`"
538+
:fill="FINAL_CONFIG.style.chart.layout.markers.color"
539+
>
540+
{{
541+
applyDataLabel(
542+
FINAL_CONFIG.style.chart.layout.markers.formatter,
543+
arc.from,
544+
dataLabel({
545+
p: FINAL_CONFIG.style.chart.layout.markers.prefix,
546+
v: arc.from,
547+
s: FINAL_CONFIG.style.chart.layout.markers.suffix,
548+
r: FINAL_CONFIG.style.chart.layout.markers.roundingValue
549+
})
550+
)
551+
}}
552+
</text>
553+
</g>
541554

542555
<text
556+
v-if="FINAL_CONFIG.style.chart.layout.markers.show"
543557
data-cy="gauge-step-marker-label-last"
544558
:x="offsetFromCenterPoint({
545559
centerX: svg.width / 2,
@@ -560,7 +574,18 @@ defineExpose({
560574
:font-weight="`${FINAL_CONFIG.style.chart.layout.markers.bold ? 'bold' : 'normal'}`"
561575
:fill="FINAL_CONFIG.style.chart.layout.markers.color"
562576
>
563-
{{ max.toFixed(FINAL_CONFIG.style.chart.layout.markers.roundingValue) }}
577+
{{
578+
applyDataLabel(
579+
FINAL_CONFIG.style.chart.layout.markers.formatter,
580+
max,
581+
dataLabel({
582+
p: FINAL_CONFIG.style.chart.layout.markers.prefix,
583+
v: max,
584+
s: FINAL_CONFIG.style.chart.layout.markers.suffix,
585+
r: FINAL_CONFIG.style.chart.layout.markers.roundingValue
586+
})
587+
)
588+
}}
564589
</text>
565590

566591
<!-- GAUGE POINTER -->
@@ -622,6 +647,7 @@ defineExpose({
622647

623648
<!-- GAUGE RATING -->
624649
<text
650+
v-if="FINAL_CONFIG.style.chart.legend.show"
625651
data-cy="gauge-score"
626652
:x="svg.width / 2"
627653
:y="arcSizeSource.ratingBase"

0 commit comments

Comments
 (0)