Code cleaned up

This commit is contained in:
Piotr Pekala 2019-04-03 04:24:26 -07:00
parent 2d3a4798d9
commit 83ac53e0a1
3 changed files with 9 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import { Context } from '../models/context';
import { MovingEventSource } from '../events/moving-event-source';
import { Component } from '@angular/core';
import { ZoomingCanvasDirective } from './zooming-canvas.directive';
import { MapScaleService } from '../../services/mapScale.service';
@Component({
template: `<svg #svg class="map" preserveAspectRatio="none" zoomingCanvas><g class="canvas" transform="translate(0, 0) scale(1)"></g></svg>`
@ -22,7 +23,8 @@ describe('ZoomingCanvasDirective', () => {
imports: [NoopAnimationsModule],
providers: [
{ provide: MovingEventSource, useValue: movingEventSource },
{ provide: Context, useClass: Context }
{ provide: Context, useClass: Context },
{ provide: MapScaleService, useClass: MapScaleService }
],
declarations: [DummyComponent, ZoomingCanvasDirective]
}).compileComponents();

View File

@ -3,6 +3,7 @@ import { Subscription } from 'rxjs';
import { MovingEventSource } from '../events/moving-event-source';
import { Context } from '../models/context';
import { select } from 'd3-selection';
import { MapScaleService } from '../../services/mapScale.service';
@Directive({
selector: '[zoomingCanvas]',
@ -14,7 +15,8 @@ export class ZoomingCanvasDirective implements OnInit, OnDestroy {
constructor(
private element: ElementRef,
private movingEventSource: MovingEventSource,
private context: Context
private context: Context,
private mapsScaleService: MapScaleService
) {}
ngOnInit() {
@ -45,6 +47,7 @@ export class ZoomingCanvasDirective implements OnInit, OnDestroy {
const xTrans = this.context.getZeroZeroTransformationPoint().x + this.context.transformation.x;
const yTrans = this.context.getZeroZeroTransformationPoint().y + this.context.transformation.y;
const kTrans = this.context.transformation.k;
this.mapsScaleService.setScale(kTrans);
return `translate(${xTrans}, ${yTrans}) scale(${kTrans})`;
});

View File

@ -11,7 +11,6 @@ import { MapLink } from '../models/map/map-link';
import { SelectionManager } from '../managers/selection-manager';
import { event } from 'd3-selection';
import { LinkContextMenu } from '../events/event-source';
import { MapScaleService } from '../../services/mapScale.service';
@Injectable()
export class LinkWidget implements Widget {
@ -21,8 +20,7 @@ export class LinkWidget implements Widget {
private multiLinkCalculatorHelper: MultiLinkCalculatorHelper,
private interfaceLabelWidget: InterfaceLabelWidget,
private interfaceStatusWidget: InterfaceStatusWidget,
private selectionManager: SelectionManager,
private mapScaleService: MapScaleService
private selectionManager: SelectionManager
) {}
public draw(view: SVGSelection) {
@ -31,8 +29,7 @@ export class LinkWidget implements Widget {
const link_body_enter = link_body
.enter()
.append<SVGGElement>('g')
.attr('class', 'link_body')
.attr('transform', `scale(${this.mapScaleService.getScale()})`);;
.attr('class', 'link_body');
const link_body_merge = link_body.merge(link_body_enter).attr('transform', link => {
const translation = this.multiLinkCalculatorHelper.linkTranslation(link.distance, link.source, link.target);