Skip to content

Commit bd4cea9

Browse files
authored
Merge pull request #220 from graphieros/trunk
Improvement - VueUiDonut & VueUiNestedDonuts - Gracefully manage empt…
2 parents 6eb82ba + 085bf89 commit bd4cea9

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

src/components/vue-ui-donut.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
calcMarkerOffsetX,
66
calcMarkerOffsetY,
77
calcNutArrowPath,
8+
checkNaN,
89
convertColorToHex,
910
convertCustomPalette,
1011
createCsvContent,
@@ -310,7 +311,7 @@ const immutableSet = computed(() => {
310311
return {
311312
name: serie.name,
312313
color: convertColorToHex(serie.color) || customPalette.value[i] || palette[i] || palette[i % palette.length],
313-
value: serie.values.reduce((a, b) => a + b, 0),
314+
value: checkNaN(serie.values.reduce((a, b) => a + b, 0)),
314315
absoluteValues: serie.values,
315316
comment: serie.comment || '',
316317
patternIndex: i,
@@ -913,7 +914,6 @@ defineExpose({
913914
</radialGradient>
914915
</defs>
915916

916-
917917
<!-- LABEL CONNECTOR -->
918918
<defs>
919919
<filter :id="`blur_${uid}`" x="-50%" y="-50%" width="200%" height="200%">

src/components/vue-ui-nested-donuts.vue

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
setOpacity,
3232
themePalettes,
3333
XMLNS,
34+
checkNaN,
3435
} from "../lib";
3536
import { throttle } from "../canvas-lib";
3637
import { useNestedProp } from "../useNestedProp";
@@ -183,17 +184,19 @@ function animateWithGhost(finalValues, duration = 1000, stagger = 50) {
183184
const ghostByGroup = [];
184185
let cursor = 0;
185186
props.dataset.forEach((ds, groupIndex) => {
186-
const realTotal = ds.series.reduce(
187+
const realTotal = checkNaN(ds.series.reduce(
187188
(sum, s) =>
188-
sum + sanitizeArray(s.values).reduce((a, b) => a + b, 0),
189+
sum + checkNaN(sanitizeArray(s.values).reduce((a, b) => a + b, 0)),
189190
0
190-
);
191-
const animatedTotal = animatedValues.value
191+
));
192+
193+
const animatedTotal = checkNaN(animatedValues.value
192194
.slice(cursor, cursor + ds.series.length)
193-
.reduce((a, b) => a + b, 0);
195+
.reduce((a, b) => a + b, 0));
196+
194197
const ghostValue = realTotal - animatedTotal;
195198
196-
if (ghostValue > 0.001) {
199+
if (ghostValue > Number.MIN_VALUE) {
197200
ghostByGroup.push({
198201
name: "__ghost__",
199202
arcOf: ds.name,
@@ -629,18 +632,19 @@ const radii = computed(() => {
629632
630633
const donuts = computed(() => {
631634
return mutableDataset.value.map((ds, i) => {
632-
const radius =
633-
donutSize.value - (i * donutSize.value) / mutableDataset.value.length;
635+
const hasData = Math.abs(ds.series.map(s => s.value).reduce((a, b) => a + b, 0)) > 0;
636+
const radius = donutSize.value - (i * donutSize.value) / mutableDataset.value.length;
634637
const ghost = isFirstLoad.value
635638
? ghostSlices.value.find((g) => g.datasetIndex === i)
636639
: null;
637-
const series = [...ds.series, ...(ghost ? [ghost] : [])].map((s) => ({
638-
...s,
639-
value: s.value < 0.001 ? 0.001 : s.value,
640-
}));
641-
640+
const series = [...ds.series, ...(ghost ? [ghost] : [])].map((s) => ({
641+
...s,
642+
value: s.value < 0.00000000001 ? Number.MIN_VALUE : s.value,
643+
}));
644+
642645
return {
643646
...ds,
647+
hasData,
644648
radius,
645649
donut: makeDonut(
646650
{ series },
@@ -1181,12 +1185,14 @@ defineExpose({
11811185
11821186
<!-- NESTED DONUTS -->
11831187
<g v-for="(item, i) in donuts">
1184-
<g v-for="(arc, j) in item.donut.filter((el) => !el.ghost)">
1185-
<path data-cy="datapoint-arc" class="vue-ui-donut-arc-path" :d="arc.arcSlice"
1186-
:fill="setOpacity(arc.color, 80)" :stroke="FINAL_CONFIG.style.chart.backgroundColor"
1187-
:stroke-width="FINAL_CONFIG.style.chart.layout.donut.borderWidth"
1188-
:filter="getBlurFilter(arc, j)" />
1189-
</g>
1188+
<template v-if="item.hasData">
1189+
<g v-for="(arc, j) in item.donut.filter((el) => !el.ghost)">
1190+
<path data-cy="datapoint-arc" class="vue-ui-donut-arc-path" :d="arc.arcSlice"
1191+
:fill="setOpacity(arc.color, 80)" :stroke="FINAL_CONFIG.style.chart.backgroundColor"
1192+
:stroke-width="FINAL_CONFIG.style.chart.layout.donut.borderWidth"
1193+
:filter="getBlurFilter(arc, j)" />
1194+
</g>
1195+
</template>
11901196
</g>
11911197
11921198
<g v-if="FINAL_CONFIG.style.chart.useGradient">

0 commit comments

Comments
 (0)