Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 1 | /* |
| 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 Hosts Module. |
| 19 | Module that holds the hosts for a region |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 25 | var Collection, Model; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 26 | |
Steven Burrows | beef935 | 2016-10-21 14:09:50 -0500 | [diff] [blame] | 27 | var hostIconDim = 20, |
| 28 | hostIconDimMin = 15, |
| 29 | hostIconDimMax = 20, |
| 30 | remappedDeviceTypes = {}; |
| 31 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 32 | function createHostCollection(data, region) { |
| 33 | |
| 34 | var HostCollection = Collection.extend({ |
| 35 | model: Model |
| 36 | }); |
| 37 | |
| 38 | var hosts = []; |
| 39 | data.forEach(function (hostsLayer) { |
| 40 | hostsLayer.forEach(function (host) { |
| 41 | hosts.push(host); |
| 42 | }); |
| 43 | }); |
| 44 | |
| 45 | return new HostCollection(hosts); |
| 46 | } |
| 47 | |
| 48 | angular.module('ovTopo2') |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 49 | .factory('Topo2HostService', [ |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 50 | 'Topo2Collection', 'Topo2NodeModel', 'Topo2ViewService', |
Steven Burrows | beef935 | 2016-10-21 14:09:50 -0500 | [diff] [blame] | 51 | 'IconService', 'Topo2ZoomService', |
| 52 | function (_Collection_, _NodeModel_, _t2vs_, is, zs) { |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 53 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 54 | Collection = _Collection_; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 55 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 56 | Model = _NodeModel_.extend({ |
Steven Burrows | beef935 | 2016-10-21 14:09:50 -0500 | [diff] [blame] | 57 | nodeType: 'host', |
| 58 | icon: function () { |
| 59 | var type = this.get('type'); |
| 60 | return remappedDeviceTypes[type] || type || 'endstation'; |
| 61 | }, |
| 62 | setScale: function () { |
| 63 | |
| 64 | var dim = hostIconDim, |
| 65 | multipler = 1; |
| 66 | |
| 67 | if (dim * zs.scale() < hostIconDimMin) { |
| 68 | multipler = hostIconDimMin / (dim * zs.scale()); |
| 69 | } else if (dim * zs.scale() > hostIconDimMax) { |
| 70 | multipler = hostIconDimMax / (dim * zs.scale()); |
| 71 | } |
| 72 | |
| 73 | this.el.select('g').selectAll('*') |
| 74 | .style('transform', 'scale(' + multipler + ')'); |
| 75 | }, |
| 76 | onEnter: function (el) { |
| 77 | var node = d3.select(el), |
| 78 | icon = this.icon(), |
| 79 | textDy = hostIconDim + 15, |
| 80 | iconDim = hostIconDim; |
| 81 | |
| 82 | this.el = node; |
| 83 | |
| 84 | var g = node.append('g') |
| 85 | .attr('class', 'svgIcon hostIcon'); |
| 86 | |
| 87 | g.append('circle').attr('r', hostIconDim); |
| 88 | g.append('use').attr({ |
| 89 | 'xlink:href': '#' + icon, |
| 90 | width: iconDim, |
| 91 | height: iconDim, |
| 92 | x: -iconDim / 2, |
| 93 | y: -iconDim / 2 |
| 94 | }); |
| 95 | |
| 96 | g.append('text') |
| 97 | .text(this.get('id')) |
| 98 | .attr('dy', textDy) |
| 99 | .attr('text-anchor', 'middle'); |
| 100 | |
| 101 | this.setScale(); |
| 102 | } |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 103 | }); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 104 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 105 | return { |
| 106 | createHostCollection: createHostCollection |
| 107 | }; |
| 108 | } |
| 109 | ]); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 110 | |
| 111 | })(); |