Skip to content

Commit

Permalink
Resize background as well when resizing canvas.
Browse files Browse the repository at this point in the history
Fixes #99

Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
  • Loading branch information
bhufmann committed Jan 18, 2021
1 parent 6e3fcdf commit 45923b0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions timeline-chart/src/time-graph-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -60,7 +62,7 @@ export class TimeGraphContainer {

this.layers = [];

const background = new TimeGraphRectangle({
this.background = new TimeGraphRectangle({
opacity: 1,
position: {
x: 0, y: 0
Expand All @@ -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 {
Expand All @@ -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());
}

Expand Down

0 comments on commit 45923b0

Please sign in to comment.