diff --git a/packages/chart/src/FigureChartModel.test.ts b/packages/chart/src/FigureChartModel.test.ts index af3df563f..48b929c87 100644 --- a/packages/chart/src/FigureChartModel.test.ts +++ b/packages/chart/src/FigureChartModel.test.ts @@ -140,6 +140,21 @@ it('handles colors on bar charts properly', () => { ]); }); +it('updates the title correctly', () => { + const figure = chartTestUtils.makeFigure(); + const model = new FigureChartModel(dh, figure); + const mockSubscribe = jest.fn(); + model.subscribe(mockSubscribe); + + model.setTitle('New Title'); + expect(mockSubscribe).toHaveBeenCalledTimes(1); + expect(mockSubscribe).toHaveBeenCalledWith( + expect.objectContaining({ + type: FigureChartModel.EVENT_LAYOUT_UPDATED, + }) + ); +}); + describe('axis transform tests', () => { it('handles log x-axis properly', () => { const xAxis = chartTestUtils.makeAxis({ diff --git a/packages/chart/src/FigureChartModel.ts b/packages/chart/src/FigureChartModel.ts index ca583e6e0..2a7cff629 100644 --- a/packages/chart/src/FigureChartModel.ts +++ b/packages/chart/src/FigureChartModel.ts @@ -625,6 +625,8 @@ class FigureChartModel extends ChartModel { ChartUtils.DEFAULT_TITLE_PADDING.t + subtitleCount * ChartUtils.SUBTITLE_LINE_HEIGHT * 0.5; } + + this.fireLayoutUpdated({ title: this.layout.title }); } getPlotWidth(): number {