Skip to content

Commit bb97638

Browse files
committed
Improvement - VueUiDonutEvolution - Add config attrs to hide labels under a given percentage value
1 parent 3670e06 commit bb97638

File tree

6 files changed

+33
-6
lines changed

6 files changed

+33
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,4 @@
107107
"vitest": "^3.1.1",
108108
"vue": "^3.5.13"
109109
}
110-
}
110+
}

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const components = ref([ //------|
120120
* Modify the index to display a component
121121
* [0] = VueUiXy
122122
*/
123-
const selectedComponent = ref(components.value[0]);
123+
const selectedComponent = ref(components.value[26]);
124124
125125
/**
126126
* Legacy testing arena where some non chart components can be tested

src/components/vue-ui-donut-evolution.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('<VueUiDonutEvolution />', () => {
5656

5757
cy.log('shows donut hovered state');
5858
cy.get('[data-cy-trap]').eq(0).trigger('mouseenter');
59-
cy.get('[data-cy="donut_hover_0"]').should('have.length', 4);
59+
cy.get('[data-cy="donut_hover_0"]').should('have.length', 3);
6060
cy.get('[data-cy-trap]').eq(0).trigger('mouseleave');
6161
cy.get('[data-cy="donut_hover_0"]').should('not.exist');
6262
});

src/components/vue-ui-donut-evolution.vue

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,13 @@ function toggleAnnotator() {
578578
isAnnotator.value = !isAnnotator.value;
579579
}
580580
581+
function isArcBigEnoughHover(arc) {
582+
return arc.proportion * 100 > FINAL_CONFIG.value.style.chart.donuts.hover.hideLabelsUnderValue;
583+
}
584+
function isArcBigEnoughZoom(arc) {
585+
return arc.proportion * 100 > FINAL_CONFIG.value.style.chart.donuts.zoom.hideLabelsUnderValue;
586+
}
587+
581588
defineExpose({
582589
getData,
583590
generatePdf,
@@ -841,8 +848,9 @@ defineExpose({
841848
<g v-if="hoveredIndex !== null && hoveredIndex === i">
842849
<g v-for="arc in datapoint.donutHover">
843850
<path
851+
v-if="isArcBigEnoughHover(arc)"
844852
:data-cy="`donut_hover_${i}`"
845-
:d="calcNutArrowPath(arc, {x: arc.center.endX, y: arc.center.endY}, 12, 12, { x: datapoint.x, y: datapoint.y}, true, 20)"
853+
:d="calcNutArrowPath(arc, {x: arc.center.endX, y: arc.center.endY}, 12, 12, { x: datapoint.x, y: datapoint.y}, false, 20)"
846854
:stroke="arc.color"
847855
stroke-width="1"
848856
stroke-linecap="round"
@@ -853,11 +861,12 @@ defineExpose({
853861
<!-- DATALABELS (hovered datapoint) -->
854862
<g v-for="(arc, i) in datapoint.donutHover">
855863
<text
864+
v-if="isArcBigEnoughHover(arc)"
856865
:data-cy="`donut-datalabel-value-${i}`"
857866
data-cy-hover-label
858867
:text-anchor="calcMarkerOffsetX(arc, true, 0).anchor"
859-
:x="calcMarkerOffsetX(arc, true, 3).x"
860-
:y="calcMarkerOffsetY(arc)"
868+
:x="calcMarkerOffsetX(arc, true, 9).x"
869+
:y="calcMarkerOffsetY(arc, 14, 10)"
861870
:fill="FINAL_CONFIG.style.chart.layout.grid.yAxis.dataLabels.color"
862871
:font-size="8"
863872
:font-weight="'bold'"
@@ -993,6 +1002,7 @@ defineExpose({
9931002
9941003
<g v-for="arc in fixedDatapoint.donutFocus">
9951004
<path
1005+
v-if="isArcBigEnoughZoom(arc)"
9961006
data-cy-zoom-donut
9971007
:d="calcNutArrowPath(arc, {x: svg.centerX, y: svg.centerY}, 12, 12, false, false, 15)"
9981008
:stroke="arc.color"
@@ -1019,6 +1029,7 @@ defineExpose({
10191029
/>
10201030
<g v-for="(arc, i) in fixedDatapoint.donutFocus" class="vue-ui-donut-evolution-focus">
10211031
<text
1032+
v-if="isArcBigEnoughZoom(arc)"
10221033
:data-cy="`donut-datalabel-value-${i}`"
10231034
:text-anchor="calcMarkerOffsetX(arc, true, 20).anchor"
10241035
:x="calcMarkerOffsetX(arc, true, 10).x"

src/useConfig.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,6 +2787,14 @@ export function useConfig() {
27872787
backgroundColor: COLOR_WHITE,
27882788
color: COLOR_BLACK,
27892789
zoom: ZOOM,
2790+
donuts: {
2791+
hover: {
2792+
hideLabelsUnderValue: 5,
2793+
},
2794+
zoom: {
2795+
hideLabelsUnderValue: 3,
2796+
}
2797+
},
27902798
layout: {
27912799
height: 316,
27922800
width: 512,

types/vue-data-ui.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,14 @@ declare module "vue-data-ui" {
11601160
backgroundColor?: string;
11611161
color?: string;
11621162
zoom?: ChartZoom;
1163+
donuts?: {
1164+
hover?: {
1165+
hideLabelsUnderValue?: number;
1166+
};
1167+
zoom?: {
1168+
hideLabelsUnderValue?: number;
1169+
}
1170+
};
11631171
layout?: {
11641172
height?: number;
11651173
width?: number;

0 commit comments

Comments
 (0)