Fix default map size

This commit is contained in:
ziajka 2018-07-23 17:57:09 +02:00
parent 88f6134092
commit c7d079ed0d
3 changed files with 18 additions and 21 deletions

View File

@ -2,7 +2,7 @@ import {
Component, ElementRef, HostListener, Input, OnChanges, OnDestroy, OnInit, SimpleChange Component, ElementRef, HostListener, Input, OnChanges, OnDestroy, OnInit, SimpleChange
} from '@angular/core'; } from '@angular/core';
import { D3, D3Service } from 'd3-ng2-service'; import { D3, D3Service } from 'd3-ng2-service';
import {select, Selection} from 'd3-selection'; import { select, Selection } from 'd3-selection';
import { Node } from "../../models/node"; import { Node } from "../../models/node";
import { Link } from "../../models/link"; import { Link } from "../../models/link";
@ -10,7 +10,7 @@ import { GraphLayout } from "../../widgets/graph-layout";
import { Context } from "../../models/context"; import { Context } from "../../models/context";
import { Size } from "../../models/size"; import { Size } from "../../models/size";
import { Drawing } from "../../models/drawing"; import { Drawing } from "../../models/drawing";
import {Symbol} from "../../models/symbol"; import { Symbol } from "../../models/symbol";
@Component({ @Component({
@ -30,10 +30,9 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
private d3: D3; private d3: D3;
private parentNativeElement: any; private parentNativeElement: any;
private svg: Selection<SVGSVGElement, any, null, undefined>; private svg: Selection<SVGSVGElement, any, null, undefined>;
public graphLayout: GraphLayout;
private graphContext: Context; private graphContext: Context;
public graphLayout: GraphLayout;
constructor(protected element: ElementRef, constructor(protected element: ElementRef,
protected d3Service: D3Service protected d3Service: D3Service
@ -118,12 +117,6 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
this.graphContext.size = this.getSize(); this.graphContext.size = this.getSize();
} }
if (this.graphContext != null) {
this.svg
.attr('width', this.graphContext.size.width)
.attr('height', this.graphContext.size.height);
}
this.graphLayout.setNodes(this.nodes); this.graphLayout.setNodes(this.nodes);
this.graphLayout.setLinks(this.links); this.graphLayout.setLinks(this.links);
this.graphLayout.setDrawings(this.drawings); this.graphLayout.setDrawings(this.drawings);

View File

@ -82,6 +82,10 @@ export class GraphLayout implements Widget {
} }
draw(view: SVGSelection, context: Context) { draw(view: SVGSelection, context: Context) {
view
.attr('width', context.size.width)
.attr('height', context.size.height);
const canvas = view const canvas = view
.selectAll<SVGGElement, Context>('g.canvas') .selectAll<SVGGElement, Context>('g.canvas')
.data([context]); .data([context]);

View File

@ -4,21 +4,21 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>GNS3 Web UI</title> <title>GNS3 Web UI</title>
<!-- It's important to have base here because of the script below //--> <!-- It's important to have base here because of the script below //-->
<base href="./"> <base href="/">
<script> <script>
var userAgent = navigator.userAgent.toLowerCase(); var userAgent = navigator.userAgent.toLowerCase();
// in case we're running in electron because we need it for resources //in case we're running in electron because we need it for resources
// if (userAgent.indexOf(' electron/') > -1) { if (userAgent.indexOf(' electron/') > -1) {
// var base = document.getElementsByTagName('base'); var base = document.getElementsByTagName('base');
// if(base.length > 0) { if(base.length > 0) {
// base.href = document.location; base.href ='./';
// } }
// else { else {
// document.write('<base href="' + document.location + '" />'); document.write('<base href="./" />');
// } }
// } }
</script> </script>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">