blob: c956627f977993eb930ab51b490979642b444501 [file] [log] [blame]
Sean Condon0c577f62018-11-18 22:40:05 +00001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import {Directive, ElementRef, Input, OnChanges} from '@angular/core';
17import {LogService} from 'gui2-fw-lib';
18import * as d3 from 'd3';
19
20@Directive({
21 selector: '[onosZoomableOf]'
22})
23export class ZoomableDirective implements OnChanges {
24 @Input() zoomableOf: ElementRef;
25
26 constructor(
27 private _element: ElementRef,
28 private log: LogService,
29 ) {}
30
31 ngOnChanges() {
32 let zoomed, zoom;
33
34 const svg = d3.select(this.zoomableOf);
35 const container = d3.select(this._element.nativeElement);
36
37 zoomed = () => {
38 const transform = d3.event.transform;
39 container.attr('transform', 'translate(' + transform.x + ',' + transform.y + ') scale(' + transform.k + ')');
40 };
41
42 zoom = d3.zoom().on('zoom', zoomed);
43 svg.call(zoom);
44 this.log.debug('Applying zoomable behaviour on', this.zoomableOf, this._element.nativeElement);
45 }
46
47}