Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | import { |
| 17 | ChangeDetectorRef, |
| 18 | Component, |
| 19 | ElementRef, EventEmitter, |
| 20 | Input, |
| 21 | OnChanges, Output, |
| 22 | SimpleChanges, |
| 23 | ViewChild |
| 24 | } from '@angular/core'; |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 25 | import {Node, Device, LabelToggle} from '../../models'; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 26 | import {LogService} from 'gui2-fw-lib'; |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 27 | import {NodeVisual} from '../nodevisual'; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 28 | |
| 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 Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 54 | export class DeviceNodeSvgComponent extends NodeVisual implements OnChanges { |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 55 | @Input() device: Device; |
| 56 | @Input() scale: number = 1.0; |
| 57 | @Input() labelToggle: LabelToggle = LabelToggle.NONE; |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 58 | @Output() selectedEvent = new EventEmitter<Node>(); |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 59 | textWidth: number = 36; |
| 60 | @ViewChild('idTxt') idTxt: ElementRef; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 61 | constructor( |
| 62 | protected log: LogService, |
| 63 | private ref: ChangeDetectorRef |
| 64 | ) { |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 65 | super(); |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 66 | } |
| 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 Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 87 | } |