Steven Burrows | ad74af8 | 2017-04-28 15:27:19 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Steven Burrows | ad74af8 | 2017-04-28 15:27:19 -0400 | [diff] [blame] | 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 | |
| 17 | /* |
| 18 | ONOS GUI -- Topo2LinkLabel |
| 19 | A label positioned at the center point of a link |
| 20 | usage: new LinkLabel({text, icon}, DOM Element, Link); |
| 21 | */ |
| 22 | |
| 23 | (function () { |
| 24 | |
| 25 | angular.module('ovTopo2') |
| 26 | .factory('Topo2LinkLabel', [ |
| 27 | 'Topo2Label', 'Topo2ZoomService', |
| 28 | function (Label, t2zs) { |
| 29 | return Label.extend({ |
| 30 | className: 'topo2-linklabel', |
| 31 | maxHeight: 30, |
| 32 | minHeight: 20, |
Steven Burrows | ca1a39c | 2017-05-08 17:31:08 -0400 | [diff] [blame] | 33 | initialize: function (label, dom, options) { |
| 34 | this.link = options.link; |
| 35 | this.parent = dom; |
| 36 | this.super = this.constructor.__super__; |
| 37 | this.super.initialize.apply(this, arguments); |
| 38 | }, |
| 39 | onChange: function () { |
| 40 | this.link.onChange(); |
| 41 | this.constructor.__super__.onChange.apply(this, arguments); |
| 42 | }, |
| 43 | linkLabelCSSClass: function () { |
| 44 | return this.get('css') || ''; |
| 45 | }, |
Steven Burrows | ad74af8 | 2017-04-28 15:27:19 -0400 | [diff] [blame] | 46 | setPosition: function () { |
Steven Burrows | ca1a39c | 2017-05-08 17:31:08 -0400 | [diff] [blame] | 47 | var link = this.link; |
Steven Burrows | ad74af8 | 2017-04-28 15:27:19 -0400 | [diff] [blame] | 48 | this.set({ |
| 49 | x: (link.source.x + link.target.x) / 2, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame^] | 50 | y: (link.source.y + link.target.y) / 2, |
Steven Burrows | ad74af8 | 2017-04-28 15:27:19 -0400 | [diff] [blame] | 51 | }); |
| 52 | }, |
| 53 | setScale: function () { |
| 54 | this.content.style('transform', |
| 55 | 'scale(' + t2zs.adjustmentScale(20, 30) + ')'); |
Steven Burrows | ca1a39c | 2017-05-08 17:31:08 -0400 | [diff] [blame] | 56 | }, |
| 57 | beforeRender: function () { |
| 58 | this.link.linkLabel = this; |
| 59 | }, |
| 60 | remove: function () { |
| 61 | this.link.linkLabel = null; |
| 62 | this.link.onChange(); |
| 63 | this.constructor.__super__.remove.apply(this, arguments); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame^] | 64 | }, |
Steven Burrows | ad74af8 | 2017-04-28 15:27:19 -0400 | [diff] [blame] | 65 | }); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame^] | 66 | }, |
Steven Burrows | ad74af8 | 2017-04-28 15:27:19 -0400 | [diff] [blame] | 67 | ]); |
| 68 | })(); |