blob: d32b55d07086374d9e95f2c1ce04e206f473f291 [file] [log] [blame]
Steven Burrowsec1f45c2016-08-08 16:14:41 +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/*
18ONOS GUI -- Topology Layout Module.
19Module that contains the d3.force.layout logic
20*/
21
22(function () {
23 'use strict';
24
Steven Burrowsdfa52b02016-09-02 13:50:43 +010025 var is;
Steven Burrowsec1f45c2016-08-08 16:14:41 +010026
Steven Burrowsdfa52b02016-09-02 13:50:43 +010027 // Configuration
28 var hostRadius = 14;
Steven Burrowsec1f45c2016-08-08 16:14:41 +010029
30 function init() {}
31
Steven Burrows6deb4ce2016-08-26 16:06:23 +010032 function nodeEnter(node) {
33 node.onEnter(this, node);
Steven Burrowsec1f45c2016-08-08 16:14:41 +010034 }
35
Steven Burrowsdfa52b02016-09-02 13:50:43 +010036 function nodeExit(node) {
37 node.onExit(this, node);
38 }
39
Steven Burrowsec1f45c2016-08-08 16:14:41 +010040 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 Burrowsdfa52b02016-09-02 13:50:43 +010069 ['IconService',
Steven Burrowsec1f45c2016-08-08 16:14:41 +010070
Steven Burrowsdfa52b02016-09-02 13:50:43 +010071 function (_is_) {
Steven Burrowsec1f45c2016-08-08 16:14:41 +010072 is = _is_;
Steven Burrowsec1f45c2016-08-08 16:14:41 +010073
74 return {
75 init: init,
Steven Burrows6deb4ce2016-08-26 16:06:23 +010076 nodeEnter: nodeEnter,
Steven Burrowsdfa52b02016-09-02 13:50:43 +010077 nodeExit: nodeExit,
Steven Burrowsec1f45c2016-08-08 16:14:41 +010078 hostEnter: hostEnter,
79 linkEntering: linkEntering
Steven Burrowsdfa52b02016-09-02 13:50:43 +010080 };
Steven Burrowsec1f45c2016-08-08 16:14:41 +010081 }
82 ]
83);
84})();