blob: 016c7b44ed4538a809db6286dc564c295e2017a6 [file] [log] [blame]
Steven Burrows57e24e92016-08-04 18:38:24 +01001/*
2 * Copyright 2016-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 -- Topology SubRegion Module.
19 Module that holds the sub-regions for a region
20 */
21
22(function () {
23 'use strict';
24
Steven Burrows6deb4ce2016-08-26 16:06:23 +010025 var Collection, Model, is, sus, ts, t2vs;
26
27 var remappedDeviceTypes = {
28 virtual: 'cord'
29 };
30
31 // configuration
32 var devIconDim = 36,
33 labelPad = 10,
34 hostRadius = 14,
35 badgeConfig = {
36 radius: 12,
37 yoff: 5,
38 gdelta: 10
39 },
40 halfDevIcon = devIconDim / 2,
41 devBadgeOff = { dx: -halfDevIcon, dy: -halfDevIcon },
42 hostBadgeOff = { dx: -hostRadius, dy: -hostRadius },
43 status = {
44 i: 'badgeInfo',
45 w: 'badgeWarn',
46 e: 'badgeError'
47 },
48 deviceLabelIndex = 0;
Steven Burrows57e24e92016-08-04 18:38:24 +010049
50 function createSubRegionCollection(data, region) {
51
52 var SubRegionCollection = Collection.extend({
53 model: Model
54 });
55
56 return new SubRegionCollection(data);
57 }
58
Steven Burrows6deb4ce2016-08-26 16:06:23 +010059 function mapDeviceTypeToGlyph(type) {
60 return remappedDeviceTypes[type] || type || 'switch';
61 }
62
63 function iconBox(dim, labelWidth) {
64 return {
65 x: -dim / 2,
66 y: -dim / 2,
67 width: dim + labelWidth,
68 height: dim
69 }
70 }
71
Steven Burrows57e24e92016-08-04 18:38:24 +010072 angular.module('ovTopo2')
73 .factory('Topo2SubRegionService',
Steven Burrows6deb4ce2016-08-26 16:06:23 +010074 ['Topo2Collection', 'Topo2NodeModel', 'IconService', 'SvgUtilService',
75 'ThemeService', 'Topo2ViewService',
Steven Burrows57e24e92016-08-04 18:38:24 +010076
Steven Burrows6deb4ce2016-08-26 16:06:23 +010077 function (_Collection_, _NodeModel_, _is_, _sus_, _ts_, classnames, _t2vs_) {
Steven Burrows57e24e92016-08-04 18:38:24 +010078
Steven Burrows6deb4ce2016-08-26 16:06:23 +010079 t2vs = _t2vs_;
80 is = _is_;
81 sus = _sus_;
82 ts = _ts_;
Steven Burrows57e24e92016-08-04 18:38:24 +010083 Collection = _Collection_;
Steven Burrows6deb4ce2016-08-26 16:06:23 +010084
85 Model = _NodeModel_.extend({
86 initialize: function () {
87 this.set('weight', 0);
88 this.constructor.__super__.initialize.apply(this, arguments);
89 },
90 nodeType: 'sub-region',
91 mapDeviceTypeToGlyph: mapDeviceTypeToGlyph,
92 onEnter: function (el) {
93
94 var node = d3.select(el),
95 glyphId = mapDeviceTypeToGlyph(this.get('type')),
96 label = this.trimLabel(this.label()),
97 glyph, labelWidth;
98
99 this.el = node;
100
101 // Label
102 var labelElements = this.addLabelElements(label);
103 labelWidth = label ? this.computeLabelWidth(node) : 0;
104 labelElements.rect.attr(iconBox(devIconDim, labelWidth));
105
106 // Icon
107 glyph = is.addDeviceIcon(node, glyphId, devIconDim);
108 glyph.attr(iconBox(devIconDim, 0));
109
110 node.attr('transform', sus.translate(-halfDevIcon, -halfDevIcon));
111 this.render();
112 },
113 onExit: function () {},
114 render: function () {}
115 });
Steven Burrows57e24e92016-08-04 18:38:24 +0100116
117 return {
118 createSubRegionCollection: createSubRegionCollection
119 };
120 }
121 ]);
122
123})();