Skip to content

Commit 17e65a6

Browse files
authored
fix(chart) :: fallback to default palette on unknown colour
Before unmatched colours reached ApexCharts as undefined and fell back to white (often on a white background). Now unknown colours are dropped and SQLPage falls back to the default palette.
1 parent 8c3ebcf commit 17e65a6

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎frontend/src/apexcharts.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const sqlpage_chart = (() => {
131131
if (data.ymax == null) data.ymax = undefined;
132132

133133
const palette = [
134-
...data.colors.filter((c) => c).map((c) => colorNames[c]),
134+
...data.colors.map(named_color).filter((c) => c !== undefined),
135135
...tblrColors.map(([_, dark, light]) => (isDarkTheme ? dark : light)),
136136
...tblrColors.map(([_, dark, light]) => (isDarkTheme ? light : dark)),
137137
];

‎tests/end-to-end/fixtures/chart/test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,16 @@ test("keeps the color of the series when a row names a color SQLPage does not kn
487487
expect(fills(unknown)).toEqual(fills(plain));
488488
});
489489

490+
test("keeps the default palette when the chart names a color SQLPage does not know", async ({
491+
page,
492+
}) => {
493+
const plain = await renderChart(page, "uncolored-bar");
494+
const unknown = await renderChart(page, "unknown-chart-color");
495+
496+
expect(unknown.failures).toEqual([]);
497+
expect(fills(unknown)).toEqual(fills(plain));
498+
});
499+
490500
test("renders series named after built-in JavaScript properties", async ({
491501
page,
492502
}) => {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SELECT 'chart' AS component, 'test-chart' AS id, 'Chart test fixture' AS title, 'bar' AS type, 'chartreuse' AS color, 4 AS marker;
2+
WITH points(series, x, y) AS (VALUES ('A', 'Q1', 1), ('A', 'Q2', 2)) SELECT * FROM points;

0 commit comments

Comments
 (0)