blob: 0d90963c9e60953ffde32e83e5d64433b4cd5edf [file] [log] [blame]
Matteo Scandolof0446ed2017-08-08 13:05:24 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandoloc46a82d2017-03-24 18:37:18 -070019import * as $ from 'jquery';
20import * as _ from 'lodash';
21
22export interface IRCordGraphReducer {
23 setup(): void;
24}
25
26export class RCordGraphReducer implements IRCordGraphReducer {
27
28 static $inject = [
29 'XosServiceGraphExtender'
30 ];
31
32 constructor(
33 private XosServiceGraphExtender: any
34 ) {
35
36 }
37
38 public setup() {
Matteo Scandoloc46a82d2017-03-24 18:37:18 -070039 this.XosServiceGraphExtender.register('coarse', 'ecord-local', (graph: any): any => {
40 graph.nodes = this.positionCoarseNodes(graph.nodes);
41 return {
42 nodes: graph.nodes,
43 links: graph.links
44 };
45 });
46 }
47
Max Chua7e6ede2017-06-29 14:52:01 -070048 private getSvgDimensions(graph: string): {width: number, height: number} {
Matteo Scandoloc46a82d2017-03-24 18:37:18 -070049 return {
50 width: $(`${graph} svg`).width(),
Max Chua7e6ede2017-06-29 14:52:01 -070051 height: $(`${graph} svg`).height()
Matteo Scandoloc46a82d2017-03-24 18:37:18 -070052 };
53 }
54
55 private positionCoarseNodes(nodes: any[]): any[] {
56 // getting distance between nodes
57 const hStep = this.getSvgDimensions('xos-coarse-tenancy-graph').width / 4;
Matteo Scandolo22f8e822017-09-28 16:35:20 -070058 const vStep = this.getSvgDimensions('xos-coarse-tenancy-graph').height / 5;
Matteo Scandoloc46a82d2017-03-24 18:37:18 -070059
60 const vtr = _.find(nodes, {label: 'vtr'});
61 if (vtr) {
62 vtr.x = hStep * 2;
63 vtr.y = vStep * 1;
64 vtr.fixed = true;
65 }
66
Matteo Scandolo22f8e822017-09-28 16:35:20 -070067 const rcord = _.find(nodes, {label: 'rcord'});
68 if (rcord) {
69 rcord.x = hStep * 0.5;
70 rcord.y = vStep * 2;
71 rcord.fixed = true;
72 }
73
Matteo Scandoloc46a82d2017-03-24 18:37:18 -070074 const volt = _.find(nodes, {label: 'volt'});
75 if (volt) {
76 volt.x = hStep * 1;
77 volt.y = vStep * 2;
78 volt.fixed = true;
79 }
80
81 const vsg = _.find(nodes, {label: 'vsg'});
82 if (vsg) {
83 vsg.x = hStep * 2;
84 vsg.y = vStep * 2;
85 vsg.fixed = true;
86 }
87
88 const vrouter = _.find(nodes, {label: 'vrouter'});
89 if (vrouter) {
90 vrouter.x = hStep * 3;
91 vrouter.y = vStep * 2;
92 vrouter.fixed = true;
93 }
94
Matteo Scandolo22f8e822017-09-28 16:35:20 -070095 const addressmanager = _.find(nodes, {label: 'addressmanager'});
96 if (addressmanager) {
97 addressmanager.x = hStep * 2.5;
98 addressmanager.y = vStep * 1.5;
99 addressmanager.fixed = true;
100 }
101
Matteo Scandoloc46a82d2017-03-24 18:37:18 -0700102 const oc = _.find(nodes, {label: 'ONOS_CORD'});
103 if (oc) {
104 oc.x = hStep + (hStep / 2);
105 oc.y = vStep * 3;
106 oc.fixed = true;
107 }
108
Matteo Scandolo22f8e822017-09-28 16:35:20 -0700109 const vtn = _.find(nodes, {label: 'vtn'});
110 if (vtn) {
111 vtn.x = hStep * 1.5;
112 vtn.y = vStep * 4;
113 vtn.fixed = true;
114 }
115
Matteo Scandoloc46a82d2017-03-24 18:37:18 -0700116 const of = _.find(nodes, {label: 'ONOS_Fabric'});
117 if (of) {
Matteo Scandolo22f8e822017-09-28 16:35:20 -0700118 of.x = hStep * 2.5;
Matteo Scandoloc46a82d2017-03-24 18:37:18 -0700119 of.y = vStep * 3;
120 of.fixed = true;
121 }
122
Matteo Scandolo22f8e822017-09-28 16:35:20 -0700123 const fabric = _.find(nodes, {label: 'fabric'});
124 if (fabric) {
125 fabric.x = hStep * 2.5;
126 fabric.y = vStep * 4;
127 fabric.fixed = true;
128 }
129
130 const exampleservice = _.find(nodes, {label: 'exampleservice'});
131 if (exampleservice) {
132 exampleservice.x = hStep * 3.5;
133 exampleservice.y = vStep * 4.5;
134 exampleservice.fixed = true;
135 }
136
Matteo Scandoloc46a82d2017-03-24 18:37:18 -0700137 return nodes;
138 }
Matteo Scandoloc46a82d2017-03-24 18:37:18 -0700139}