Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize background as well when resizing canvas. #100

Merged
merged 1 commit into from
Jan 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 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,17 @@ export class TimeGraphContainer {
reInitCanvasSize(newWidth: number, newHeight?: number) {
if (newHeight === undefined) {
newHeight = this.config.height;
} else {
this.config.height = newHeight;
}
this.config.width = newWidth;

this.application.renderer.resize(newWidth, newHeight);
this.stateController.updateDisplayWidth();
this.stateController.updateDisplayHeight();
this.background.displayObject.width = newWidth;
this.background.displayObject.height = newHeight;
bhufmann marked this conversation as resolved.
Show resolved Hide resolved
this.background.update();
this.layers.forEach(l => l.update());
}

Expand Down