Skip to content

Commit cadefb5

Browse files
committed
Improvement - VueUiGauge - Add optional segment separators
1 parent c72e972 commit cadefb5

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

src/components/vue-ui-gauge.vue

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,44 @@ const pathRadii = computed(() => {
385385
});
386386
});
387387
388+
const firstSeparator = computed(() => {
389+
const { x: x1, y: y1 } = offsetFromCenterPoint({
390+
initX: arcs.value[0].firstSeparator.x,
391+
initY: arcs.value[0].firstSeparator.y,
392+
centerX: pointer.value.x1,
393+
centerY: pointer.value.y1,
394+
offset: -FINAL_CONFIG.value.style.chart.layout.segmentSeparators.offsetIn
395+
});
396+
const { x: x2, y: y2 } = offsetFromCenterPoint({
397+
initX: arcs.value[0].startX,
398+
initY: arcs.value[0].startY,
399+
centerX: pointer.value.x1,
400+
centerY: pointer.value.y1,
401+
offset: FINAL_CONFIG.value.style.chart.layout.segmentSeparators.offsetOut
402+
});
403+
return { x1, y1, x2, y2 };
404+
})
405+
406+
const segmentSeparators = computed(() => {
407+
return arcs.value.map(arc => {
408+
const { x: x1, y: y1 } = offsetFromCenterPoint({
409+
initX: arc.separator.x,
410+
initY: arc.separator.y,
411+
centerX: pointer.value.x1,
412+
centerY: pointer.value.y1,
413+
offset: -FINAL_CONFIG.value.style.chart.layout.segmentSeparators.offsetIn
414+
});
415+
const { x: x2, y: y2 } = offsetFromCenterPoint({
416+
initX: arc.endX,
417+
initY: arc.endY,
418+
centerX: pointer.value.x1,
419+
centerY: pointer.value.y1,
420+
offset: FINAL_CONFIG.value.style.chart.layout.segmentSeparators.offsetOut
421+
})
422+
return { x1, y1, x2, y2 };
423+
})
424+
})
425+
388426
function calculateCumulativeHalfCircleOffsets(percentages) {
389427
const totalPercentage = percentages.reduce((sum, val) => sum + val, 0);
390428
if (totalPercentage > 100) {
@@ -601,26 +639,55 @@ defineExpose({
601639
/>
602640
</template>
603641

642+
<template v-if="FINAL_CONFIG.style.chart.layout.segmentSeparators.show">
643+
<line
644+
v-bind="firstSeparator"
645+
:stroke="FINAL_CONFIG.style.chart.backgroundColor"
646+
:stroke-width="FINAL_CONFIG.style.chart.layout.segmentSeparators.strokeWidth + 2"
647+
stroke-linecap="round"
648+
/>
649+
<line
650+
v-bind="firstSeparator"
651+
:stroke="FINAL_CONFIG.style.chart.layout.segmentSeparators.stroke"
652+
:stroke-width="FINAL_CONFIG.style.chart.layout.segmentSeparators.strokeWidth"
653+
stroke-linecap="round"
654+
/>
655+
<line
656+
v-for="segmentSeparator in segmentSeparators"
657+
v-bind="segmentSeparator"
658+
:stroke="FINAL_CONFIG.style.chart.backgroundColor"
659+
:stroke-width="FINAL_CONFIG.style.chart.layout.segmentSeparators.strokeWidth + 2"
660+
stroke-linecap="round"
661+
/>
662+
<line
663+
v-for="segmentSeparator in segmentSeparators"
664+
v-bind="segmentSeparator"
665+
:stroke="FINAL_CONFIG.style.chart.layout.segmentSeparators.stroke"
666+
:stroke-width="FINAL_CONFIG.style.chart.layout.segmentSeparators.strokeWidth"
667+
stroke-linecap="round"
668+
/>
669+
</template>
670+
604671
<!-- STEP MARKERS -->
605672
<g v-if="FINAL_CONFIG.style.chart.layout.markers.show">
606673
<text
607674
v-for="(arc, i) in arcs"
608675
:data-cy="`gauge-step-marker-label-${i}`"
609676
:x="offsetFromCenterPoint({
610-
centerX: svg.width / 2,
677+
centerX: pointer.x1,
611678
centerY: arcSizeSource.base,
612679
initX: arc.center.startX,
613680
initY: arc.center.startY,
614681
offset: svg.markerOffset
615682
}).x"
616683
:y="offsetFromCenterPoint({
617-
centerX: svg.width / 2,
684+
centerX: pointer.x1,
618685
centerY: arcSizeSource.base,
619686
initX: arc.center.startX,
620687
initY: arc.center.startY,
621688
offset: svg.markerOffset
622689
}).y"
623-
:text-anchor="arc.center.startX < (svg.width / 2 - 5) ? 'end' : arc.center.startX > (svg.width / 2 + 5) ? 'start' : 'middle'"
690+
:text-anchor="arc.center.startX < (pointer.x1 - 5) ? 'end' : arc.center.startX > (pointer.x1 + 5) ? 'start' : 'middle'"
624691
:font-size="svg.labelFontSize * FINAL_CONFIG.style.chart.layout.markers.fontSizeRatio"
625692
:font-weight="`${FINAL_CONFIG.style.chart.layout.markers.bold ? 'bold' : 'normal'}`"
626693
:fill="FINAL_CONFIG.style.chart.layout.markers.color"

0 commit comments

Comments
 (0)