Skip to content

Commit ecb26f8

Browse files
committed
[FIX] chart: don't crash treemap without visible data
Steps to reproduce: - in A1: "Year" - in B1: "2025" - create a tree map chart with Hierachy: A1 and Values: B1 - go to the design panel - change it to "Color scale" - hide column B => Crash opw-5166581 closes #7549 Task: 5365419 Signed-off-by: Pierre Rousseau (pro) <[email protected]>
1 parent 645e850 commit ecb26f8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/helpers/figures/charts/runtime/chartjs_dataset.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,9 @@ function getTreeMapGroupColors(
692692
}
693693

694694
function getTreeMapColorScale(tree: SunburstTreeNode[], coloringOption: TreeMapColorScaleOptions) {
695+
if (tree.length === 0) {
696+
return undefined;
697+
}
695698
const treeNodesByLevel = pyramidizeTree(tree);
696699
const nodes = treeNodesByLevel[treeNodesByLevel.length - 1];
697700
const minValue = Math.min(...nodes.map((node) => node.value));

tests/figures/chart/treemap/treemap_chart_plugin.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TreeMapChartRuntime } from "../../../../src/types/chart/tree_map_chart"
55
import {
66
createSunburstChart,
77
createTreeMapChart,
8+
hideColumns,
89
setCellContent,
910
setFormat,
1011
updateChart,
@@ -431,6 +432,28 @@ describe("TreeMap chart", () => {
431432
);
432433
});
433434

435+
test("TreeMap color scale with no visible data", () => {
436+
const grid = {
437+
A1: "Year",
438+
B1: "2025",
439+
};
440+
setGrid(model, grid);
441+
const chartId = createTreeMapChart(model, {
442+
dataSets: [{ dataRange: "A1" }],
443+
labelRange: "B1",
444+
dataSetsHaveTitle: false,
445+
coloringOptions: {
446+
type: "colorScale",
447+
minColor: "#112233",
448+
midColor: "#445566",
449+
maxColor: "#778899",
450+
},
451+
});
452+
expect(getTreeMapDatasetConfig(chartId).tree).toHaveLength(1);
453+
hideColumns(model, ["B"]);
454+
expect(getTreeMapDatasetConfig(chartId).tree).toHaveLength(0);
455+
});
456+
434457
test("TreeMap category colors with single level", () => {
435458
// prettier-ignore
436459
const grid = {

0 commit comments

Comments
 (0)