Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/helpers/figures/charts/runtime/chartjs_dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@ function getTreeMapGroupColors(
}

function getTreeMapColorScale(tree: SunburstTreeNode[], coloringOption: TreeMapColorScaleOptions) {
if (tree.length === 0) {
return undefined;
}
const treeNodesByLevel = pyramidizeTree(tree);
const nodes = treeNodesByLevel[treeNodesByLevel.length - 1];
const minValue = Math.min(...nodes.map((node) => node.value));
Expand Down
23 changes: 23 additions & 0 deletions tests/figures/chart/treemap/treemap_chart_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TreeMapChartRuntime } from "../../../../src/types/chart/tree_map_chart"
import {
createSunburstChart,
createTreeMapChart,
hideColumns,
setCellContent,
setFormat,
updateChart,
Expand Down Expand Up @@ -431,6 +432,28 @@ describe("TreeMap chart", () => {
);
});

test("TreeMap color scale with no visible data", () => {
const grid = {
A1: "Year",
B1: "2025",
};
setGrid(model, grid);
const chartId = createTreeMapChart(model, {
dataSets: [{ dataRange: "A1" }],
labelRange: "B1",
dataSetsHaveTitle: false,
coloringOptions: {
type: "colorScale",
minColor: "#112233",
midColor: "#445566",
maxColor: "#778899",
},
});
expect(getTreeMapDatasetConfig(chartId).tree).toHaveLength(1);
hideColumns(model, ["B"]);
expect(getTreeMapDatasetConfig(chartId).tree).toHaveLength(0);
});

test("TreeMap category colors with single level", () => {
// prettier-ignore
const grid = {
Expand Down