blob: 66b06e54f82cb172baca402dc9fd57ae7dc2caea [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 },
53 setScale: function () {
54 this.content.style('transform',
55 'scale(' + t2zs.adjustmentScale(20, 30) + ')');
Steven Burrowsca1a39c2017-05-08 17:31:08 -040056 },
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 Burrowsad74af82017-04-28 15:27:19 -040064 }
65 });
66 }
67 ]);
68})();