From 6afdeb51a8c160a9a8d1752afce9eccb1310f663 Mon Sep 17 00:00:00 2001 From: ziajka Date: Mon, 22 Jan 2018 11:58:18 +0100 Subject: [PATCH] Canvas resizes on window size change, fixes #54 --- src/app/cartography/map/map.component.ts | 23 ++++++++++++++--------- src/app/map/models/context.ts | 4 ---- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/app/cartography/map/map.component.ts b/src/app/cartography/map/map.component.ts index 8cec0eb8..056c8dab 100644 --- a/src/app/cartography/map/map.component.ts +++ b/src/app/cartography/map/map.component.ts @@ -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(); + } } diff --git a/src/app/map/models/context.ts b/src/app/map/models/context.ts index 00f0f3fb..da853e1f 100644 --- a/src/app/map/models/context.ts +++ b/src/app/map/models/context.ts @@ -16,8 +16,4 @@ export class Context { public setSize(size: Size): void { this.size = size; } - - public getRoot() { - return this.root; - } }