Skip to content

Commit ef496c9

Browse files
committed
Fix - VueUiVerticalBar - Fix data labels of parent categories
1 parent eb817c1 commit ef496c9

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

src/components/vue-ui-vertical-bar.vue

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -196,45 +196,49 @@ const immutableDataset = computed(() => {
196196
return props.dataset
197197
.map((serie, i) => {
198198
const id = `vertical_parent_${i}_${uid.value}`;
199-
const hasChildren = !!serie.children && serie.children.length > 0;
199+
const hasChildren = serie.children && serie.children.length > 0;
200200
201-
return {
202-
...serie,
203-
id,
204-
shape: 'square',
205-
opacity: segregated.value.includes(id) ? 0.5 : 1,
206-
value: checkNaN(hasChildren ? serie.children.map(c => c.value || 0).reduce((a, b) => a + b, 0) : (Math.abs(serie.value) || 0)),
207-
sign: serie.value >= 0 ? 1 : -1,
208-
hasChildren,
209-
isChild: false,
210-
segregate: () => segregate(id),
211-
isSegregated: segregated.value.includes(id),
212-
color: convertColorToHex(serie.color) || customPalette.value[i] || palette[i] || palette[i % palette.length],
213-
children: !serie.children || !serie.children.length ? [] : serie.children
214-
.toSorted((a, b) => isSortDown.value ? b.value - a.value : a.value - b.value)
215-
.map((c, j) => {
216-
return {
217-
...c,
218-
value: checkNaN(Math.abs(c.value)),
219-
sign: c.value >= 0 ? 1 : -1,
220-
isChild: true,
221-
parentId: id,
222-
parentName: serie.name,
223-
parentValue: checkNaN(serie.value || hasChildren ? serie.children.map(c => c.value || 0).reduce((a, b) => a + b, 0) : 0),
224-
id: `vertical_child_${i}_${j}_${uid.value}`,
225-
childIndex: j,
226-
color: convertColorToHex(c.color) || convertColorToHex(serie.color) || customPalette.value[i] || palette[i] || palette[i % palette.length]
227-
}
228-
})
229-
.map((c,j) => {
230-
return {
231-
...c,
232-
isFirstChild: j === 0,
233-
isLastChild: j === serie.children.length - 1,
234-
}
235-
})
236-
}
237-
}).toSorted((a, b) => isSortDown.value ? b.value - a.value : a.value - b.value)
201+
const parentValue = checkNaN(serie.value ? serie.value : hasChildren ? serie.children.map(c => c.value || 0).reduce((a, b) => a + b, 0) : 0);
202+
const parentSign = parentValue >= 0 ? 1 : -1;
203+
return {
204+
...serie,
205+
id,
206+
shape: 'square',
207+
opacity: segregated.value.includes(id) ? 0.5 : 1,
208+
value: Math.abs(parentValue),
209+
sign: parentSign,
210+
hasChildren,
211+
isChild: false,
212+
segregate: () => segregate(id),
213+
isSegregated: segregated.value.includes(id),
214+
color: convertColorToHex(serie.color) || customPalette.value[i] || palette[i] || palette[i % palette.length],
215+
children: !serie.children || !serie.children.length ? [] : serie.children
216+
.toSorted((a, b) => isSortDown.value ? b.value - a.value : a.value - b.value)
217+
.map((c, j) => {
218+
return {
219+
...c,
220+
value: checkNaN(Math.abs(c.value)),
221+
sign: c.value >= 0 ? 1 : -1,
222+
isChild: true,
223+
parentId: id,
224+
parentName: serie.name,
225+
parentValue,
226+
parentSign,
227+
id: `vertical_child_${i}_${j}_${uid.value}`,
228+
childIndex: j,
229+
color: convertColorToHex(c.color) || convertColorToHex(serie.color) || customPalette.value[i] || palette[i] || palette[i % palette.length]
230+
}
231+
})
232+
.map((c,j) => {
233+
return {
234+
...c,
235+
isFirstChild: j === 0,
236+
isLastChild: j === serie.children.length - 1,
237+
}
238+
})
239+
}
240+
})
241+
.toSorted((a, b) => isSortDown.value ? b.value - a.value : a.value - b.value)
238242
});
239243
240244
const legendConfig = computed(() => {
@@ -777,7 +781,7 @@ defineExpose({
777781
:font-weight="FINAL_CONFIG.style.chart.layout.bars.dataLabels.bold ? 'bold' : 'normal'"
778782
text-anchor="start"
779783
>
780-
{{ makeDataLabel(getParentData(serie, i).value), getParentData(serie, i), i, getParentData(serie, i).sign }}
784+
{{ makeDataLabel(getParentData(serie, i).value), getParentData(serie, i), i, serie.parentSign || serie.sign }}
781785
</text>
782786

783787
<!-- TOOLTIP TRAPS -->

0 commit comments

Comments
 (0)