blob: 036fc085b3c5401e1651d1b21d91dec0d5efb925 [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 {
17 ChangeDetectorRef,
18 Component,
19 ElementRef, EventEmitter,
20 Input,
21 OnChanges, Output,
22 SimpleChanges,
23 ViewChild
24} from '@angular/core';
Sean Condon021f0fa2018-12-06 23:31:11 -080025import {Node, Device, LabelToggle} from '../../models';
Sean Condon0c577f62018-11-18 22:40:05 +000026import {LogService} from 'gui2-fw-lib';
Sean Condon021f0fa2018-12-06 23:31:11 -080027import {NodeVisual} from '../nodevisual';
Sean Condon0c577f62018-11-18 22:40:05 +000028
29/**
30 * The Device node in the force graph
31 *
32 * Note: here the selector is given square brackets [] so that it can be
33 * inserted in SVG element like a directive
34 */
35@Component({
36 selector: '[onos-devicenodesvg]',
37 templateUrl: './devicenodesvg.component.html',
38 styleUrls: ['./devicenodesvg.component.css'],
39 // changeDetection: ChangeDetectionStrategy.Default,
40 // animations: [
41 // trigger('deviceLabelToggle', [
42 // state('0', style({ // none
43 // width: '36px',
44 // })),
45 // state('1, 2', // id
46 // style({ width: '{{ txtWidth }}'}),
47 // { params: {'txtWidth': '36px'}}
48 // ), // default
49 // transition('0 => *', animate('1000ms ease-in')),
50 // transition('* => 0', animate('1000ms ease-out'))
51 // ])
52 // ]
53})
Sean Condon021f0fa2018-12-06 23:31:11 -080054export class DeviceNodeSvgComponent extends NodeVisual implements OnChanges {
Sean Condon0c577f62018-11-18 22:40:05 +000055 @Input() device: Device;
56 @Input() scale: number = 1.0;
57 @Input() labelToggle: LabelToggle = LabelToggle.NONE;
Sean Condon021f0fa2018-12-06 23:31:11 -080058 @Output() selectedEvent = new EventEmitter<Node>();
Sean Condon0c577f62018-11-18 22:40:05 +000059 textWidth: number = 36;
60 @ViewChild('idTxt') idTxt: ElementRef;
Sean Condon0c577f62018-11-18 22:40:05 +000061 constructor(
62 protected log: LogService,
63 private ref: ChangeDetectorRef
64 ) {
Sean Condon021f0fa2018-12-06 23:31:11 -080065 super();
Sean Condon0c577f62018-11-18 22:40:05 +000066 }
67
68 /**
69 * Called by parent (forcesvg) when a change happens
70 *
71 * There is a difficulty in passing the SVG text object to the animation
72 * directly, to get its width, so we capture it here and update textWidth
73 * local variable here and use it in the animation
74 */
75 ngOnChanges(changes: SimpleChanges) {
76 if (changes['device']) {
77 if (!this.device.x) {
78 this.device.x = 0;
79 this.device.y = 0;
80 }
81 }
82 if (changes['labelToggle']) {
83 this.labelToggle = changes['labelToggle'].currentValue;
84 }
85 this.ref.markForCheck();
86 }
Sean Condon0c577f62018-11-18 22:40:05 +000087}