From 7a5d5688abbcb66c57207ff55ccf42694d6b4e5f Mon Sep 17 00:00:00 2001 From: Anton Vorobev Date: Tue, 5 Dec 2023 10:55:42 +0300 Subject: [PATCH] fix: fix background drawer optimization --- src/chart/components/chart/chart.component.ts | 2 +- src/chart/drawers/chart-background.drawer.ts | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/chart/components/chart/chart.component.ts b/src/chart/components/chart/chart.component.ts index 41041ca3..d126da56 100644 --- a/src/chart/components/chart/chart.component.ts +++ b/src/chart/components/chart/chart.component.ts @@ -117,7 +117,7 @@ export class ChartComponent extends ChartBaseElement { //#region data series drawers this.registerDefaultDataSeriesDrawers(); //#endregion - this.backgroundDrawer = new BackgroundDrawer(backgroundCanvasModel, this.config, this.canvasBoundsContainer); + this.backgroundDrawer = new BackgroundDrawer(backgroundCanvasModel, this.config); drawingManager.addDrawer(this.backgroundDrawer, 'MAIN_BACKGROUND'); cursorHandler.setCursorForCanvasEl(CanvasElement.PANE_UUID(CHART_UUID), config.components.chart.cursor); diff --git a/src/chart/drawers/chart-background.drawer.ts b/src/chart/drawers/chart-background.drawer.ts index edc27ff8..1a5d3182 100644 --- a/src/chart/drawers/chart-background.drawer.ts +++ b/src/chart/drawers/chart-background.drawer.ts @@ -9,23 +9,18 @@ import { ChartAreaTheme, FullChartConfig } from '../chart.config'; import { getDPR } from '../utils/device/device-pixel-ratio.utils'; import { deepEqual } from '../utils/object.utils'; import { floor } from '../utils/math.utils'; -import { CanvasBoundsContainer } from '../canvas/canvas-bounds-container'; export class BackgroundDrawer implements Drawer { - constructor( - private canvasModel: CanvasModel, - private config: FullChartConfig, - private canvasBoundsContainer: CanvasBoundsContainer, - ) {} + constructor(private canvasModel: CanvasModel, private config: FullChartConfig) {} // we need to save previous state to avoid unnecessary redraws private prevState: Partial = {}; - private prevCanvasLocation = {}; draw(): void { if ( deepEqual(this.config.colors.chartAreaTheme, this.prevState) && - this.prevCanvasLocation === this.canvasBoundsContainer.canvasOnPageLocation + this.canvasModel.height === this.canvasModel.prevHeight && + this.canvasModel.width === this.canvasModel.prevWidth ) { return; } @@ -40,9 +35,8 @@ export class BackgroundDrawer implements Drawer { ctx.fillStyle = this.config.colors.chartAreaTheme.backgroundColor; } ctx.fillRect(0, 0, this.canvasModel.width, this.canvasModel.height); - // save prev state + // save prev color state this.prevState = { ...this.config.colors.chartAreaTheme }; - this.prevCanvasLocation = this.canvasBoundsContainer.canvasOnPageLocation; } getCanvasIds(): Array {