Merge pull request #552 from GNS3/Option-to-show-the-grid

Option to show the grid
This commit is contained in:
piotrpekala7 2019-10-25 10:48:31 +02:00 committed by GitHub
commit 0dbede58f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 3 deletions

View File

@ -1,5 +1,19 @@
<svg #svg class="map" preserveAspectRatio="none" movingCanvas zoomingCanvas> <svg #svg class="map" preserveAspectRatio="none" movingCanvas zoomingCanvas>
<filter id="grayscale"><feColorMatrix id="feGrayscale" type="saturate" values="0" /></filter> <filter id="grayscale"><feColorMatrix id="feGrayscale" type="saturate" values="0" /></filter>
<defs>
<pattern id="gridDrawing" attr.width="{{project.drawing_grid_size}}" attr.height="{{project.drawing_grid_size}}" patternUnits="userSpaceOnUse">
<path attr.d="M {{project.drawing_grid_size}} 0 L 0 0 0 {{project.drawing_grid_size}}" fill="none" stroke="silver" attr.stroke-width="{{gridVisibility}}"/>
</pattern>
</defs>
<defs>
<pattern id="gridNode" attr.width="{{project.grid_size}}" attr.height="{{project.grid_size}}" patternUnits="userSpaceOnUse">
<path attr.d="M {{project.grid_size}} 0 L 0 0 0 {{project.grid_size}}" fill="none" stroke="DarkSlateGray" attr.stroke-width="{{gridVisibility}}"/>
</pattern>
</defs>
<rect width="100%" height="100%" fill="url(#gridDrawing)" />
<rect width="100%" height="100%" fill="url(#gridNode)" />
</svg> </svg>
<app-drawing-adding [svg]="svg"></app-drawing-adding> <app-drawing-adding [svg]="svg"></app-drawing-adding>

Before

Width:  |  Height:  |  Size: 517 B

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -32,6 +32,7 @@ import { Server } from '../../../models/server';
import { ToolsService } from '../../../services/tools.service'; import { ToolsService } from '../../../services/tools.service';
import { TextEditorComponent } from '../text-editor/text-editor.component'; import { TextEditorComponent } from '../text-editor/text-editor.component';
import { MapScaleService } from '../../../services/mapScale.service'; import { MapScaleService } from '../../../services/mapScale.service';
import { Project } from '../../../models/project';
@Component({ @Component({
selector: 'app-d3-map', selector: 'app-d3-map',
@ -43,6 +44,7 @@ export class D3MapComponent implements OnInit, OnChanges, OnDestroy {
@Input() links: Link[] = []; @Input() links: Link[] = [];
@Input() drawings: Drawing[] = []; @Input() drawings: Drawing[] = [];
@Input() symbols: Symbol[] = []; @Input() symbols: Symbol[] = [];
@Input() project: Project;
@Input() server: Server; @Input() server: Server;
@Input() width = 1500; @Input() width = 1500;
@ -53,15 +55,13 @@ export class D3MapComponent implements OnInit, OnChanges, OnDestroy {
private parentNativeElement: any; private parentNativeElement: any;
private svg: Selection<SVGSVGElement, any, null, undefined>; private svg: Selection<SVGSVGElement, any, null, undefined>;
private onChangesDetected: Subscription; private onChangesDetected: Subscription;
private subscriptions: Subscription[] = []; private subscriptions: Subscription[] = [];
private drawLinkTool: boolean; private drawLinkTool: boolean;
protected settings = { protected settings = {
show_interface_labels: true show_interface_labels: true
}; };
public gridVisibility: number = 0;
constructor( constructor(
private graphDataManager: GraphDataManager, private graphDataManager: GraphDataManager,
@ -143,6 +143,8 @@ export class D3MapComponent implements OnInit, OnChanges, OnDestroy {
this.drawLinkTool = value; this.drawLinkTool = value;
}) })
); );
this.gridVisibility = localStorage.getItem('gridVisibility') === 'true' ? 1 : 0;
} }
ngOnDestroy() { ngOnDestroy() {

View File

@ -2,6 +2,7 @@
<app-d3-map <app-d3-map
*ngIf="!settings.angular_map" *ngIf="!settings.angular_map"
[server]="server" [server]="server"
[project]="project"
[symbols]="symbols" [symbols]="symbols"
[nodes]="nodes" [nodes]="nodes"
[links]="links" [links]="links"
@ -92,6 +93,9 @@
</mat-checkbox> </mat-checkbox>
<mat-checkbox [ngModel]="layersVisibility" (change)="toggleLayers($event.checked)"> <mat-checkbox [ngModel]="layersVisibility" (change)="toggleLayers($event.checked)">
Show layers Show layers
</mat-checkbox><br/>
<mat-checkbox [ngModel]="gridVisibility" (change)="toggleGrid($event.checked)">
Show grid
</mat-checkbox> </mat-checkbox>
</div> </div>
</mat-menu> </mat-menu>

View File

@ -84,6 +84,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
public isInterfaceLabelVisible: boolean = false; public isInterfaceLabelVisible: boolean = false;
public notificationsVisibility: boolean = false; public notificationsVisibility: boolean = false;
public layersVisibility: boolean = false; public layersVisibility: boolean = false;
public gridVisibility: boolean = false;
tools = { tools = {
selection: true, selection: true,
@ -240,6 +241,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
this.notificationsVisibility = localStorage.getItem('notificationsVisibility') === 'true' ? true : false; this.notificationsVisibility = localStorage.getItem('notificationsVisibility') === 'true' ? true : false;
this.layersVisibility = localStorage.getItem('layersVisibility') === 'true' ? true : false; this.layersVisibility = localStorage.getItem('layersVisibility') === 'true' ? true : false;
this.gridVisibility = localStorage.getItem('gridVisibility') === 'true' ? true : false;
this.addKeyboardListeners(); this.addKeyboardListeners();
} }
@ -492,6 +494,16 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
this.mapChild.applyMapSettingsChanges(); this.mapChild.applyMapSettingsChanges();
} }
public toggleGrid(visible: boolean) {
this.gridVisibility = visible;
if (this.gridVisibility) {
localStorage.setItem('gridVisibility', 'true');
} else {
localStorage.removeItem('gridVisibility');
}
this.mapChild.gridVisibility = this.gridVisibility ? 1 : 0;
}
private showMessage(msg) { private showMessage(msg) {
if (this.notificationsVisibility) { if (this.notificationsVisibility) {
if (msg.type === 'error') this.toasterService.error(msg.message); if (msg.type === 'error') this.toasterService.error(msg.message);