mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-05-11 13:03:05 +00:00
Canvas size detector
This commit is contained in:
parent
6435a84da2
commit
5da90118c7
@ -15,6 +15,7 @@ import { LayersManager } from './managers/layers-manager';
|
|||||||
import { MapChangeDetectorRef } from './services/map-change-detector-ref';
|
import { MapChangeDetectorRef } from './services/map-change-detector-ref';
|
||||||
import { Context } from './models/context';
|
import { Context } from './models/context';
|
||||||
import { D3_MAP_IMPORTS } from './d3-map.imports';
|
import { D3_MAP_IMPORTS } from './d3-map.imports';
|
||||||
|
import { CanvasSizeDetector } from './helpers/canvas-size-detector';
|
||||||
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
@ -36,6 +37,7 @@ import { D3_MAP_IMPORTS } from './d3-map.imports';
|
|||||||
QtDasharrayFixer,
|
QtDasharrayFixer,
|
||||||
LayersManager,
|
LayersManager,
|
||||||
MapChangeDetectorRef,
|
MapChangeDetectorRef,
|
||||||
|
CanvasSizeDetector,
|
||||||
Context,
|
Context,
|
||||||
...D3_MAP_IMPORTS
|
...D3_MAP_IMPORTS
|
||||||
],
|
],
|
||||||
|
@ -19,6 +19,7 @@ import { LinksWidget } from '../../widgets/links';
|
|||||||
import { MapChangeDetectorRef } from '../../services/map-change-detector-ref';
|
import { MapChangeDetectorRef } from '../../services/map-change-detector-ref';
|
||||||
import { NodeDragging, NodeDragged } from '../../events/nodes';
|
import { NodeDragging, NodeDragged } from '../../events/nodes';
|
||||||
import { LinkCreated } from '../../events/links';
|
import { LinkCreated } from '../../events/links';
|
||||||
|
import { CanvasSizeDetector } from '../../helpers/canvas-size-detector';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -51,6 +52,7 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
constructor(
|
constructor(
|
||||||
private context: Context,
|
private context: Context,
|
||||||
private mapChangeDetectorRef: MapChangeDetectorRef,
|
private mapChangeDetectorRef: MapChangeDetectorRef,
|
||||||
|
private canvasSizeDetector: CanvasSizeDetector,
|
||||||
protected element: ElementRef,
|
protected element: ElementRef,
|
||||||
protected nodesWidget: NodesWidget,
|
protected nodesWidget: NodesWidget,
|
||||||
protected linksWidget: LinksWidget,
|
protected linksWidget: LinksWidget,
|
||||||
@ -121,7 +123,7 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
this.context.size = this.getSize();
|
this.context.size = this.getSize();
|
||||||
|
|
||||||
this.onNodeDraggingSubscription = this.nodesWidget.onNodeDragging.subscribe((eventNode: NodeDragging) => {
|
this.onNodeDraggingSubscription = this.nodesWidget.onNodeDragging.subscribe((eventNode: NodeDragging) => {
|
||||||
const links = this.links.filter((link) => link.target.node_id === eventNode.node.node_id || link.source.node_id === eventNode.node.node_id)
|
const links = this.links.filter((link) => link.target.node_id === eventNode.node.node_id || link.source.node_id === eventNode.node.node_id);
|
||||||
|
|
||||||
links.forEach((link) => {
|
links.forEach((link) => {
|
||||||
this.linksWidget.redrawLink(this.svg, link);
|
this.linksWidget.redrawLink(this.svg, link);
|
||||||
@ -144,15 +146,7 @@ export class MapComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getSize(): Size {
|
public getSize(): Size {
|
||||||
let width = document.documentElement.clientWidth;
|
return this.canvasSizeDetector.getOptimalSize(this.width, this.height);
|
||||||
let height = document.documentElement.clientHeight;
|
|
||||||
if (this.width > width) {
|
|
||||||
width = this.width;
|
|
||||||
}
|
|
||||||
if (this.height > height) {
|
|
||||||
height = this.height;
|
|
||||||
}
|
|
||||||
return new Size(width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected linkCreated(evt) {
|
protected linkCreated(evt) {
|
||||||
|
18
src/app/cartography/helpers/canvas-size-detector.ts
Normal file
18
src/app/cartography/helpers/canvas-size-detector.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { Injectable } from "@angular/core";
|
||||||
|
import { Size } from "../models/size";
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CanvasSizeDetector {
|
||||||
|
public getOptimalSize(minWidth: number, minHeight: number) {
|
||||||
|
let width = document.documentElement.clientWidth;
|
||||||
|
let height = document.documentElement.clientHeight;
|
||||||
|
if (minWidth > width) {
|
||||||
|
width = minWidth;
|
||||||
|
}
|
||||||
|
if (minHeight > height) {
|
||||||
|
height = minHeight;
|
||||||
|
}
|
||||||
|
return new Size(width, height);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user