Moved ZoomDirective to gui2-fw-lib (from gui2-topo-lib)

Change-Id: Idc8bfefea7c84d6611242a9562d84ca6cc53a7b3
diff --git a/web/gui2-topo-lib/projects/gui2-topo-lib/package.json b/web/gui2-topo-lib/projects/gui2-topo-lib/package.json
index 644d88a..90a3ca7 100644
--- a/web/gui2-topo-lib/projects/gui2-topo-lib/package.json
+++ b/web/gui2-topo-lib/projects/gui2-topo-lib/package.json
@@ -1,6 +1,6 @@
 {
   "name": "gui2-topo-lib",
-  "version": "2.1.1",
+  "version": "2.3.3",
   "author": {
     "name": "Sean Condon",
     "email": "sean@opennetworking.org"
@@ -17,6 +17,6 @@
   "peerDependencies": {
     "@angular/common": "^7.0.0",
     "@angular/core": "^7.0.0",
-    "gui2-fw-lib": "^2.1.1"
+    "gui2-fw-lib": "^2.3.3"
   }
 }
diff --git a/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/gui2-topo-lib.module.ts b/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/gui2-topo-lib.module.ts
index a19b73d..e857b64 100644
--- a/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/gui2-topo-lib.module.ts
+++ b/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/gui2-topo-lib.module.ts
@@ -28,7 +28,6 @@
 import { MapSvgComponent } from './layer/mapsvg/mapsvg.component';
 import { TopologyService } from './topology.service';
 import { DraggableDirective } from './layer/forcesvg/draggable/draggable.directive';
-import { ZoomableDirective } from './layer/zoomable.directive';
 import { MapSelectorComponent } from './panel/mapselector/mapselector.component';
 import { DeviceNodeSvgComponent} from './layer/forcesvg/visuals/devicenodesvg/devicenodesvg.component';
 import { HostNodeSvgComponent } from './layer/forcesvg/visuals/hostnodesvg/hostnodesvg.component';
@@ -72,7 +71,6 @@
         SummaryComponent,
         ToolbarComponent,
         TopologyComponent,
-        ZoomableDirective,
         DraggableDirective,
         BadgeSvgComponent,
     ],
@@ -97,7 +95,6 @@
         SummaryComponent,
         ToolbarComponent,
         TopologyComponent,
-        ZoomableDirective,
         DraggableDirective,
         BadgeSvgComponent
     ]
diff --git a/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/layer/zoomable.directive.spec.ts b/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/layer/zoomable.directive.spec.ts
deleted file mode 100644
index 23d75c5..0000000
--- a/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/layer/zoomable.directive.spec.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import { ZoomableDirective } from './zoomable.directive';
-import {inject, TestBed} from '@angular/core/testing';
-import {LogService, ConsoleLoggerService, FnService} from 'gui2-fw-lib';
-import {ElementRef} from '@angular/core';
-import {ActivatedRoute, Params} from '@angular/router';
-import {of} from 'rxjs';
-
-class MockActivatedRoute extends ActivatedRoute {
-    constructor(params: Params) {
-        super();
-        this.queryParams = of(params);
-    }
-}
-
-describe('ZoomableDirective', () => {
-    let fs: FnService;
-    let ar: MockActivatedRoute;
-    let log: LogService;
-    let mockWindow: Window;
-
-    beforeEach(() => {
-        log = new ConsoleLoggerService();
-        ar = new MockActivatedRoute({ 'debug': 'txrx' });
-
-        mockWindow = <any>{
-            navigator: {
-                userAgent: 'HeadlessChrome',
-                vendor: 'Google Inc.'
-            },
-            location: <any>{
-                hostname: 'foo',
-                host: 'foo',
-                port: '80',
-                protocol: 'http',
-                search: { debug: 'true' },
-                href: 'ws://foo:123/onos/ui/websock/path',
-                absUrl: 'ws://foo:123/onos/ui/websock/path'
-            }
-        };
-
-        fs = new FnService(ar, log, mockWindow);
-
-        TestBed.configureTestingModule({
-            providers: [ZoomableDirective,
-                { provide: FnService, useValue: fs },
-                { provide: LogService, useValue: log },
-                { provide: 'Window', useValue: mockWindow },
-                { provide: ElementRef, useValue: mockWindow }
-            ]
-        });
-    });
-
-    it('should create an instance', inject([ZoomableDirective], (directive: ZoomableDirective) => {
-
-        expect(directive).toBeTruthy();
-    }));
-});
diff --git a/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/layer/zoomable.directive.ts b/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/layer/zoomable.directive.ts
deleted file mode 100644
index 9564444..0000000
--- a/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/layer/zoomable.directive.ts
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import {
-    Directive,
-    ElementRef,
-    Input,
-    OnChanges,
-    OnInit,
-    SimpleChanges
-} from '@angular/core';
-import {LogService, PrefsService, TopoZoomPrefs} from 'gui2-fw-lib';
-import * as d3 from 'd3';
-
-const TOPO_ZOOM_PREFS = 'topo_zoom';
-
-const ZOOM_PREFS_DEFAULT: TopoZoomPrefs = <TopoZoomPrefs>{
-    tx: 0, ty: 0, sc: 1.0
-};
-
-/**
- * A directive that takes care of Zooming and Panning the Topology view
- *
- * It wraps the D3 Pan and Zoom functionality
- * See https://github.com/d3/d3-zoom/blob/master/README.md
- */
-@Directive({
-  selector: '[onosZoomableOf]'
-})
-export class ZoomableDirective implements OnChanges, OnInit {
-    @Input() zoomableOf: ElementRef;
-
-    zoom: any; // The d3 zoom behaviour
-    zoomCached: TopoZoomPrefs = <TopoZoomPrefs>{tx: 0, ty: 0, sc: 1.0};
-
-    constructor(
-        private _element: ElementRef,
-        private log: LogService,
-        private ps: PrefsService
-    ) {
-        const container = d3.select(this._element.nativeElement);
-
-        const zoomed = () => {
-            const transform = d3.event.transform;
-            container.attr('transform', 'translate(' + transform.x + ',' + transform.y + ') scale(' + transform.k + ')');
-            this.updateZoomState(<TopoZoomPrefs>{tx: transform.x, ty: transform.y, sc: transform.k});
-        };
-
-        this.zoom = d3.zoom().on('zoom', zoomed);
-    }
-
-    ngOnInit() {
-        this.zoomCached = this.ps.getPrefs(TOPO_ZOOM_PREFS, ZOOM_PREFS_DEFAULT);
-        const svg = d3.select(this.zoomableOf);
-
-        svg.call(this.zoom);
-
-        svg.transition().call(this.zoom.transform,
-            d3.zoomIdentity.translate(this.zoomCached.tx, this.zoomCached.ty).scale(this.zoomCached.sc));
-        this.log.debug('Loaded topo_zoom_prefs',
-            this.zoomCached.tx, this.zoomCached.ty, this.zoomCached.sc);
-
-    }
-
-    /**
-     * Updates the cache of zoom preferences locally and onwards to the PrefsService
-     */
-    updateZoomState(zoomPrefs: TopoZoomPrefs): void {
-        this.zoomCached = zoomPrefs;
-        this.ps.setPrefs(TOPO_ZOOM_PREFS, zoomPrefs);
-    }
-
-    /**
-     * If the input object is changed then re-establish the zoom
-     */
-    ngOnChanges(changes: SimpleChanges): void {
-        if (changes['zoomableOf']) {
-            const svg = d3.select(changes['zoomableOf'].currentValue);
-            svg.call(this.zoom);
-            this.log.debug('Applying zoomable behaviour on', this.zoomableOf, this._element.nativeElement);
-        }
-    }
-
-    /**
-     * Change the zoom level when a map is chosen in Topology view
-     *
-     * Animated to run over 750ms
-     */
-    changeZoomLevel(zoomState: TopoZoomPrefs, fast?: boolean): void {
-        const svg = d3.select(this.zoomableOf);
-        svg.transition().duration(fast ? 0 : 750).call(this.zoom.transform,
-            d3.zoomIdentity.translate(zoomState.tx, zoomState.ty).scale(zoomState.sc));
-        this.updateZoomState(zoomState);
-        this.log.debug('Pan to', zoomState.tx, zoomState.ty, 'and zoom to', zoomState.sc);
-    }
-
-}
diff --git a/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/topology/topology.component.spec.ts b/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/topology/topology.component.spec.ts
index 15c2bd1..bbab25a 100644
--- a/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/topology/topology.component.spec.ts
+++ b/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/topology/topology.component.spec.ts
@@ -36,7 +36,7 @@
     LogService,
     IconService, IconComponent, PrefsService, KeysService, LionService
 } from 'gui2-fw-lib';
-import {ZoomableDirective} from '../layer/zoomable.directive';
+import {ZoomableDirective} from 'gui2-fw-lib';
 import {RouterTestingModule} from '@angular/router/testing';
 import {TrafficService} from '../traffic.service';
 import {ForceSvgComponent} from '../layer/forcesvg/forcesvg.component';
@@ -203,7 +203,6 @@
                 ToolbarComponent,
                 DetailsComponent,
                 FlashComponent,
-                ZoomableDirective,
                 IconComponent,
                 QuickhelpComponent,
                 ForceSvgComponent,
diff --git a/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/topology/topology.component.ts b/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/topology/topology.component.ts
index f48f33a..dfadb9e 100644
--- a/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/topology/topology.component.ts
+++ b/web/gui2-topo-lib/projects/gui2-topo-lib/src/lib/topology/topology.component.ts
@@ -67,7 +67,7 @@
     ALARMS_TOGGLE
 } from '../panel/toolbar/toolbar.component';
 import {TrafficService, TrafficType} from '../traffic.service';
-import {ZoomableDirective} from '../layer/zoomable.directive';
+import {ZoomableDirective} from 'gui2-fw-lib';
 import {MapObject} from '../layer/maputils';
 import {LayoutService, LayoutType} from '../layout.service';
 import {SelectedEvent} from '../layer/forcesvg/visuals/nodevisual';
diff --git a/web/gui2-topo-lib/projects/gui2-topo-lib/src/public_api.ts b/web/gui2-topo-lib/projects/gui2-topo-lib/src/public_api.ts
index 24d46a2..becde57 100644
--- a/web/gui2-topo-lib/projects/gui2-topo-lib/src/public_api.ts
+++ b/web/gui2-topo-lib/projects/gui2-topo-lib/src/public_api.ts
@@ -23,7 +23,6 @@
 export * from './lib/traffic.service';
 export * from './lib/topology-routing.module';
 
-export * from './lib/layer/zoomable.directive';
 export * from './lib/layer/viewcontroller';
 export * from './lib/layer/maputils';