Canvas resizes on window size change, fixes #54

This commit is contained in:
ziajka 2018-01-22 11:58:18 +01:00
parent e563dd6381
commit 6afdeb51a8
2 changed files with 14 additions and 13 deletions

View File

@ -1,5 +1,5 @@
import {
Component, ElementRef, Input, OnChanges, OnDestroy, OnInit, SimpleChange
Component, ElementRef, HostListener, Input, OnChanges, OnDestroy, OnInit, SimpleChange
} from '@angular/core';
import { D3, D3Service } from 'd3-ng2-service';
import {select, Selection} from 'd3-selection';
@ -106,7 +106,6 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
});
this.graphLayout.draw(this.svg, this.graphContext);
}
}
@ -117,13 +116,6 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
}
private changeLayout() {
if (this.graphContext != null) {
this.svg
.attr('width', this.graphContext.getSize().width)
.attr('height', this.graphContext.getSize().height);
}
if (this.windowFullSize) {
if (this.parentNativeElement != null) {
this.graphContext.setSize(this.getSize());
@ -133,6 +125,14 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
}
if (this.graphContext != null) {
this.svg
.attr('width', this.graphContext.getSize().width)
.attr('height', this.graphContext.getSize().height);
}
this.graphLayout.setNodes(this.nodes);
this.graphLayout.setLinks(this.links);
this.graphLayout.setDrawings(this.drawings);
@ -174,4 +174,9 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
this.onLinksChange(null);
this.redraw();
}
@HostListener('window:resize', ['$event'])
onResize(event) {
this.changeLayout();
}
}

View File

@ -16,8 +16,4 @@ export class Context {
public setSize(size: Size): void {
this.size = size;
}
public getRoot() {
return this.root;
}
}