blob: fe748c3c8df14799ca4657ebb2a8ab2812732ab1 [file] [log] [blame]
Steven Burrowsad74af82017-04-28 15:27:19 -04001/*
2 * Copyright 2017-present Open Networking Laboratory
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 Burrowsca1a39c2017-05-08 17:31:08 -040033 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 Burrowsad74af82017-04-28 15:27:19 -040046 setPosition: function () {
Steven Burrowsca1a39c2017-05-08 17:31:08 -040047 var link = this.link;
Steven Burrowsad74af82017-04-28 15:27:19 -040048 this.set({
49 x: (link.source.x + link.target.x) / 2,
50 y: (link.source.y + link.target.y) / 2
51 });
52 },
Steven Burrows1c69c9b2017-05-16 10:23:29 -040053 setVisibility: function (visible) {
54 this.el.style('visibility', visible ? 'visible' : 'hidden');
55 },
Steven Burrowsad74af82017-04-28 15:27:19 -040056 setScale: function () {
57 this.content.style('transform',
58 'scale(' + t2zs.adjustmentScale(20, 30) + ')');
Steven Burrowsca1a39c2017-05-08 17:31:08 -040059 },
60 beforeRender: function () {
61 this.link.linkLabel = this;
62 },
63 remove: function () {
64 this.link.linkLabel = null;
65 this.link.onChange();
66 this.constructor.__super__.remove.apply(this, arguments);
Steven Burrowsad74af82017-04-28 15:27:19 -040067 }
68 });
69 }
70 ]);
71})();