From 45923b021c5fae6a2034f1c18da7b779fdeab95a Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Mon, 18 Jan 2021 10:30:30 -0500 Subject: [PATCH] Resize background as well when resizing canvas. Fixes #99 Signed-off-by: Bernd Hufmann --- timeline-chart/src/time-graph-container.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/timeline-chart/src/time-graph-container.ts b/timeline-chart/src/time-graph-container.ts index caf828a..3555334 100644 --- a/timeline-chart/src/time-graph-container.ts +++ b/timeline-chart/src/time-graph-container.ts @@ -25,6 +25,8 @@ export class TimeGraphContainer { private application: PIXI.Application; + private background: TimeGraphRectangle; + constructor(protected config: TimeGraphContainerOptions, protected unitController: TimeGraphUnitController, protected extCanvas?: HTMLCanvasElement) { let canvas: HTMLCanvasElement if (!extCanvas) { @@ -60,7 +62,7 @@ export class TimeGraphContainer { this.layers = []; - const background = new TimeGraphRectangle({ + this.background = new TimeGraphRectangle({ opacity: 1, position: { x: 0, y: 0 @@ -69,8 +71,8 @@ export class TimeGraphContainer { width: this.canvas.width, color: config.backgroundColor, }); - background.render(); - this.stage.addChild(background.displayObject); + this.background.render(); + this.stage.addChild(this.background.displayObject); } get canvas(): HTMLCanvasElement { @@ -81,10 +83,15 @@ export class TimeGraphContainer { reInitCanvasSize(newWidth: number, newHeight?: number) { if (newHeight === undefined) { newHeight = this.config.height; + } else { + this.config.height = newHeight; } + this.application.renderer.resize(newWidth, newHeight); this.stateController.updateDisplayWidth(); this.stateController.updateDisplayHeight(); + this.background.displayObject.height = newHeight; + this.background.update(); this.layers.forEach(l => l.update()); }