diff --git a/src/components/side_panel/column_stats/column_stats_panel.ts b/src/components/side_panel/column_stats/column_stats_panel.ts index 39dfd4ad39..460c545a6e 100644 --- a/src/components/side_panel/column_stats/column_stats_panel.ts +++ b/src/components/side_panel/column_stats/column_stats_panel.ts @@ -44,7 +44,7 @@ export class ColumnStatsPanel extends Component { () => { this.updateChart(); }, - () => [this.store.countChartData, this.store.histogramData] + () => [this.store.countChartData, this.store.histogramData, this.state.currentChart] ); } @@ -258,8 +258,6 @@ export class ColumnStatsPanel extends Component { switchChart(chartType: string) { this.state.currentChart = chartType; - this.destroyChart(); - this.createChart(); } switchFrequencyOrder(order: string) { diff --git a/src/components/side_panel/column_stats/column_stats_panel.xml b/src/components/side_panel/column_stats/column_stats_panel.xml index 0704a82ea3..922bbdbf67 100644 --- a/src/components/side_panel/column_stats/column_stats_panel.xml +++ b/src/components/side_panel/column_stats/column_stats_panel.xml @@ -32,7 +32,7 @@ -
+
-
+
-
+
-
+
-
+
diff --git a/tests/column_statistics/column_statistics_side_panel.test.ts b/tests/column_statistics/column_statistics_side_panel.test.ts index f5276f5313..beec922cd6 100644 --- a/tests/column_statistics/column_statistics_side_panel.test.ts +++ b/tests/column_statistics/column_statistics_side_panel.test.ts @@ -1,3 +1,4 @@ +import { ChartConfiguration } from "chart.js"; import { Model } from "../../src"; import { ColumnStatisticsStore } from "../../src/components/side_panel/column_stats/column_stats_store"; import { SidePanels } from "../../src/components/side_panel/side_panels/side_panels"; @@ -126,4 +127,31 @@ describe("column statistics sidePanel component", () => { labels = Array.from(fixture.querySelectorAll(".frequency-label")).map((el) => el.textContent); expect(labels).toEqual(["c", "b", "a"]); }); + + test("Chart is re-created when switching from distribution to count when there are no distribution chart to display", async () => { + setGrid(model, { A1: "Alice", A2: "Alice" }); + env.openSidePanel("ColumnStats"); + const ChartMock = window.Chart; + window.Chart = jest + .fn() + .mockImplementation(function (ctx: CanvasRenderingContext2D, config: ChartConfiguration) { + return new ChartMock(ctx, config); + }) as any; + + await nextTick(); + + expect(".o-column-stats-chart canvas").toHaveCount(1); + expect(".o-column-stats-no-data").toHaveCount(0); + expect(window.Chart).toHaveBeenCalledTimes(1); + + await click(fixture, '.o-button[data-id="histogram"]'); + expect(".o-column-stats-chart canvas").toHaveCount(0); + expect(".o-column-stats-no-data").toHaveText("No numeric values to display."); + expect(window.Chart).toHaveBeenCalledTimes(1); + + await click(fixture, '.o-button[data-id="count"]'); + expect(".o-column-stats-chart canvas").toHaveCount(1); + expect(".o-column-stats-no-data").toHaveCount(0); + expect(window.Chart).toHaveBeenCalledTimes(2); + }); });