When all the values of a partition chart are zero, there is no reason to render the chart because it doesn't mathematically make sense. The legend instead could be useful to render to understand what is going on.
Looking at the current code, the changes that should be applied to allow the rendering of the legend are the one that touches the HierarchyOfArrays structure used to render the legend.
I'm not fully sure thee changes are error-prone, but they have the desired effect at a first glance
diff --git a/packages/charts/src/chart_types/partition_chart/layout/viewmodel/hierarchy_of_arrays.ts b/packages/charts/src/chart_types/partition_chart/layout/viewmodel/hierarchy_of_arrays.ts
index da141fe5b..e916eb2fc 100644
--- a/packages/charts/src/chart_types/partition_chart/layout/viewmodel/hierarchy_of_arrays.ts
+++ b/packages/charts/src/chart_types/partition_chart/layout/viewmodel/hierarchy_of_arrays.ts
@@ -59,8 +59,8 @@ export function getHierarchyOfArrays(
return Number.isFinite(value) && value >= 0;
});
- // don't render anything if the total, the width or height is not positive or zero
- if (facts.reduce((p: number, n) => aggregator.reducer(p, valueAccessor(n)), aggregator.identity()) <= 0) {
+ // don't render anything if the total, the width or height is not positive
+ if (facts.reduce((p: number, n) => aggregator.reducer(p, valueAccessor(n)), aggregator.identity()) < 0) {
return [];
}
diff --git a/packages/charts/src/chart_types/partition_chart/layout/utils/group_by_rollup.ts b/packages/charts/src/chart_types/partition_chart/layout/utils/group_by_rollup.ts
index a73672966..ae649f40e 100644
--- a/packages/charts/src/chart_types/partition_chart/layout/utils/group_by_rollup.ts
+++ b/packages/charts/src/chart_types/partition_chart/layout/utils/group_by_rollup.ts
@@ -242,7 +242,7 @@ export function mapsToArrays(
mapNode[PATH_KEY] = newPath; // in-place mutation, so disabled `no-param-reassign`
mapNode.children.forEach((entry) => buildPaths(entry, newPath));
};
- buildPaths(tree[0], innerGroups);
+ if (tree.length > 0) buildPaths(tree[0], innerGroups);
return tree;
}
When all the values of a partition chart are zero, there is no reason to render the chart because it doesn't mathematically make sense. The legend instead could be useful to render to understand what is going on.
Looking at the current code, the changes that should be applied to allow the rendering of the legend are the one that touches the
HierarchyOfArraysstructure used to render the legend.I'm not fully sure thee changes are error-prone, but they have the desired effect at a first glance