blob: 5c1ae30f7a67136da0518c3969e15742a9f2f2c6 [file] [log] [blame]
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +00001function controller_status(data_source){
2/* var data = [{name:'onos9vpc', onos: 1, cassandra: 1},
3 {name:'onos10vpc', onos: 0, cassandra: 1},
4 {name:'onos11vpc', onos: 1, cassandra: 1},
5 {name:'onos12vpc', onos: 0, cassandra: 1}] */
6
7 var barWidth = 100;
Masayoshi Kobayashi51496752013-03-25 22:44:23 +00008 var width = (barWidth + 10) * 8
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +00009 var height = 50;
10
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +000011 var Servers = d3.select("#servers").
12 append("svg:svg").
Masayoshi Kobayashi51496752013-03-25 22:44:23 +000013 attr("width", 1280).
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +000014 attr("height", 30);
15
16 var ContStatus = d3.select("#onos-status").
17 append("svg:svg").
Masayoshi Kobayashi51496752013-03-25 22:44:23 +000018 attr("width", 1280).
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +000019 attr("height", 50);
20
21 var CassandraStatus = d3.select("#cassandra-status").
22 append("svg:svg").
Masayoshi Kobayashi51496752013-03-25 22:44:23 +000023 attr("width", 1280).
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +000024 attr("height", 50);
25
26 d3.json(data_source, draw);
Ubuntu765deff2013-02-28 18:39:13 +000027 setInterval(function() {
28 $.ajax({
29 url: data_source,
30 success: function(json) {
31 draw(json)
32 },
33 dataType: "json"
34 });
Tim Lindberg86a85f62013-03-26 11:34:01 -070035 }, 3000);
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +000036
37 function draw(json){
38// var data = json.data;
39 var data = json;
40 var server = Servers.selectAll("text").data(data);
41 var controller_rect = ContStatus.selectAll("rect").data(data);
42 var controller_text = ContStatus.selectAll("text").data(data);
43 var cassandra_rect = CassandraStatus.selectAll("rect").data(data);
44 var cassandra_text = CassandraStatus.selectAll("text").data(data);
45
46 var x = d3.scale.linear().domain([0, data.length]).range([0, width]);
47 var y = d3.scale.linear().domain([0, d3.max(data, function(datum) { return datum.onos; })]).rangeRound([0, height]);
48 var y2 = d3.scale.linear().domain([0, d3.max(data, function(datum) { return datum.cassandra; })]).rangeRound([0, height]);
49
50 console.log(data)
51 server.
52 enter().
53 append("svg:text").
54 attr("x", function(datum, index) { return x(index); }).
55 attr("y", function(datum) { return 20; }).
Ubuntuc016ba12013-02-27 21:53:41 +000056 attr("fill", function(datum, index) {
57 if (index == 0){
58 return "red"
59 }else if (index == 1){
60 return "blue"
61 }else if (index == 2){
62 return "green"
63 }else if (index == 3){
64 return "orange"
Masayoshi Kobayashi51496752013-03-25 22:44:23 +000065 }else if (index == 4){
66 return "cyan"
67 }else if (index == 5){
68 return "magenta"
69 }else if (index == 6){
70 return "yellow"
71 }else if (index == 7){
72 return "purple"
Ubuntuc016ba12013-02-27 21:53:41 +000073 }else{
74 return "black"
75 }
76 }).
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +000077 text(function(datum) { return datum.name; });
78
79 controller_rect.
80 enter().
81 append("svg:rect").
82 attr("x", function(datum, index) { return x(index); }).
83 attr("y", function(datum) { return height - y(datum.onos); }).
84 attr("height", function(datum) { return y(datum.onos); }).
85 attr("width", barWidth).
Ubuntuc016ba12013-02-27 21:53:41 +000086 attr("fill", function(datum, index) {
87 if (index == 0){
88 return "red"
89 }else if (index == 1){
90 return "blue"
91 }else if (index == 2){
92 return "green"
93 }else if (index == 3){
94 return "orange"
Masayoshi Kobayashi51496752013-03-25 22:44:23 +000095 }else if (index == 4){
96 return "cyan"
97 }else if (index == 5){
98 return "magenta"
99 }else if (index == 6){
100 return "yellow"
101 }else if (index == 7){
102 return "purple"
Ubuntuc016ba12013-02-27 21:53:41 +0000103 }else{
104 return "black"
105 }
106 });
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +0000107
108 controller_text.
109 enter().
110 append("svg:text").
111 text(function(){return "ONOS"}).
112 attr("x", function(datum, index) { return x(index)+10; }).
113 attr("y", function(datum) { return 30 ; }).
114 attr("height", function(datum) { return y(datum.onos); }).
115 attr("width", barWidth).
116 attr('fill', 'white');
117
118 cassandra_rect.
119 enter().
120 append("svg:rect").
121 attr("x", function(datum, index) { return x(index); }).
122 attr("y", function(datum) { return height - y2(datum.cassandra); }).
123 attr("height", function(datum) { return y2(datum.cassandra); }).
124 attr("width", barWidth).
125 attr("fill", "#aa0000");
126
127 cassandra_text.
128 enter().
129 append("svg:text").
130 text(function(){return "Cassandra"}).
131 attr("x", function(datum, index) { return x(index); }).
132 attr("y", function(datum) { return 30 ; }).
133 attr("height", function(datum) { return y(datum.onos); }).
134 attr("width", barWidth).
135 attr('fill', 'white');
136
Ubuntuc016ba12013-02-27 21:53:41 +0000137
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +0000138 controller_rect.
139 attr("x", function(datum, index) { return x(index); }).
140 attr("y", function(datum) { return height - y(datum.onos); }).
141 attr("height", function(datum) { return y(datum.onos); }).
142 attr("width", barWidth).
Ubuntuc016ba12013-02-27 21:53:41 +0000143 attr("fill", function(datum, index) {
144 if (index == 0){
145 return "red"
146 }else if (index == 1){
147 return "blue"
148 }else if (index == 2){
149 return "green"
150 }else if (index == 3){
151 return "orange"
Masayoshi Kobayashi51496752013-03-25 22:44:23 +0000152 }else if (index == 4){
153 return "cyan"
154 }else if (index == 5){
155 return "magenta"
156 }else if (index == 6){
157 return "yellow"
158 }else if (index == 7){
159 return "purple"
Ubuntuc016ba12013-02-27 21:53:41 +0000160 }else{
161 return "black"
162 }
163 });
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +0000164
165 controller_text.
166 text(function(){return "ONOS"}).
167 attr("x", function(datum, index) { return x(index)+10; }).
168 attr("y", function(datum) { return 30 ; }).
169 attr("height", function(datum) { return y(datum.onos); }).
170 attr("width", barWidth).
171 attr('fill', 'white');
172
173 cassandra_rect.
174 attr("x", function(datum, index) { return x(index); }).
175 attr("y", function(datum) { return height - y2(datum.cassandra); }).
176 attr("height", function(datum) { return y2(datum.cassandra); }).
177 attr("width", barWidth).
178 attr("fill", "#aa0000");
179
180 cassandra_text.
181 text(function(){return "Cassandra"}).
182 attr("x", function(datum, index) { return x(index); }).
183 attr("y", function(datum) { return 30 ; }).
184 attr("height", function(datum) { return y(datum.cassandra); }).
185 attr("width", barWidth).
186 attr('fill', 'white');
187
188
189 server.exit().remove();
190 controller_rect.exit().remove();
191 controller_text.exit().remove();
192 cassandra_rect.exit().remove();
193 cassandra_text.exit().remove();
Ubuntuc016ba12013-02-27 21:53:41 +0000194
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +0000195 }
Ubuntuc016ba12013-02-27 21:53:41 +0000196/*
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +0000197 $("#more").click( function() {
198 $.ajax({
199 url: 'http://gui.onlab.us:8080/controller_status1',
200 success: function(json) {
201 draw(json);
202 },
203 dataType: "json"
204 });
205 });
206 $("#less").click( function() {
207 $.ajax({
208 url: 'http://gui.onlab.us:8080/controller_status2',
209 success: function(json) {
210 draw(json);
211 },
212 dataType: "json"
213 });
214 });
Ubuntuc016ba12013-02-27 21:53:41 +0000215*/
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +0000216}
217