Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +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 Layout Module. |
| 19 | Module that contains the d3.force.layout logic |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 25 | var is; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 26 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 27 | // Configuration |
| 28 | var hostRadius = 14; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 29 | |
| 30 | function init() {} |
| 31 | |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame] | 32 | function nodeEnter(node) { |
| 33 | node.onEnter(this, node); |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 34 | } |
| 35 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 36 | function nodeExit(node) { |
| 37 | node.onExit(this, node); |
| 38 | } |
| 39 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 40 | function hostLabel(d) { |
| 41 | return d.get('id'); |
| 42 | |
| 43 | // var idx = (hostLabelIndex < d.get('labels').length) ? hostLabelIndex : 0; |
| 44 | // return d.labels[idx]; |
| 45 | } |
| 46 | |
| 47 | function hostEnter(d) { |
| 48 | var node = d3.select(this), |
| 49 | gid = d.get('type') || 'unknown', |
| 50 | textDy = hostRadius + 10; |
| 51 | |
| 52 | d.el = node; |
| 53 | // sus.visible(node, api.showHosts()); |
| 54 | |
| 55 | is.addHostIcon(node, hostRadius, gid); |
| 56 | |
| 57 | node.append('text') |
| 58 | .text(hostLabel) |
| 59 | .attr('dy', textDy) |
| 60 | .attr('text-anchor', 'middle'); |
| 61 | } |
| 62 | |
| 63 | function linkEntering(link) { |
| 64 | link.onEnter(this); |
| 65 | } |
| 66 | |
| 67 | angular.module('ovTopo2') |
| 68 | .factory('Topo2D3Service', |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 69 | ['IconService', |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 70 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 71 | function (_is_) { |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 72 | is = _is_; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 73 | |
| 74 | return { |
| 75 | init: init, |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame] | 76 | nodeEnter: nodeEnter, |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 77 | nodeExit: nodeExit, |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 78 | hostEnter: hostEnter, |
| 79 | linkEntering: linkEntering |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 80 | }; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 81 | } |
| 82 | ] |
| 83 | ); |
| 84 | })(); |