Skip to content

Commit 8045ba7

Browse files
committed
Improvement - VueUiGauge - Add individual segment name offset dataset option
1 parent 04eb58c commit 8045ba7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/components/vue-ui-gauge.vue

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,10 @@ function useAnimation(targetValue) {
335335
336336
const arcSizeSource = computed(() => {
337337
const src = FINAL_CONFIG.value.responsive ? Math.min(svg.value.width, svg.value.height) : svg.value.width;
338+
const arcRatio = 2.5 / FINAL_CONFIG.value.style.chart.layout.radiusRatio;
338339
return {
339-
arcs: src / 2.5,
340-
gradients: src / 2.75,
340+
arcs: src / arcRatio,
341+
gradients: src / (arcRatio * 1.1),
341342
base: FINAL_CONFIG.value.responsive ? svg.value.height / 2 : svg.value.height * 0.7,
342343
ratingBase: FINAL_CONFIG.value.responsive ? svg.value.height / 2 + (svg.value.height / 4) : svg.value.height * 0.9,
343344
pointerSize: FINAL_CONFIG.value.responsive ? Math.min(svg.value.width, svg.value.height) / 3 : svg.value.width / 3.2
@@ -378,7 +379,11 @@ const labelArcs = computed(() => {
378379
return donut;
379380
});
380381
381-
const pathRadius = computed(() => arcSizeSource.value.arcs * FINAL_CONFIG.value.style.chart.layout.segmentNames.offsetRatio);
382+
const pathRadii = computed(() => {
383+
return arcs.value.map((arc) => {
384+
return arcSizeSource.value.arcs * FINAL_CONFIG.value.style.chart.layout.segmentNames.offsetRatio * (arc.nameOffsetRatio || 1);
385+
});
386+
});
382387
383388
function calculateCumulativeHalfCircleOffsets(percentages) {
384389
const totalPercentage = percentages.reduce((sum, val) => sum + val, 0);
@@ -548,8 +553,9 @@ defineExpose({
548553
<template v-if="FINAL_CONFIG.style.chart.layout.segmentNames.show && FINAL_CONFIG.style.chart.layout.segmentNames.curved">
549554
<!-- CIRCLE PATH AS BASE FOR CURVED LABELS -->
550555
<path
551-
:id="`curve_${uid}`"
552-
:d="`M ${pointer.x1},${pointer.y1} m -${pathRadius},0 a ${pathRadius},${pathRadius} 0 1,1 ${2 * pathRadius},0 a ${pathRadius},${pathRadius} 0 1,1 -${2 * pathRadius},0`" fill="transparent"
556+
v-for="(arc, i) in arcs"
557+
:id="`curve_${uid}_${i}`"
558+
:d="`M ${pointer.x1},${pointer.y1} m -${pathRadii[i]},0 a ${pathRadii[i]},${pathRadii[i]} 0 1,1 ${2 * pathRadii[i]},0 a ${pathRadii[i]},${pathRadii[i]} 0 1,1 -${2 * pathRadii[i]},0`" fill="transparent"
553559
/>
554560

555561
<!-- CURVED LABELS -->
@@ -560,7 +566,7 @@ defineExpose({
560566
:font-weight="FINAL_CONFIG.style.chart.layout.segmentNames.bold ? 'bold' : 'normal'"
561567
text-anchor="middle"
562568
>
563-
<textPath :href="`#curve_${uid}`" :startOffset="curveLabelOffsets[i]">
569+
<textPath :href="`#curve_${uid}_${i}`" :startOffset="curveLabelOffsets[i]">
564570
{{ arc.name || '' }}
565571
</textPath>
566572
</text>

0 commit comments

Comments
 (0)