blob: 9a093e3189e7a0e54c19c0deb328e6427b00566b [file] [log] [blame]
Masayoshi Kobayashie64d44b2014-04-23 11:40:02 -07001function data_convert(registry_raw){
2 var controller_map={};
3 var controllers=[];
4 for (var r in registry_raw){
5 var controller={};
6 if ( !(registry_raw[r][0]['controllerId'] in controller_map) ){
7 controller.name=registry_raw[r][0]['controllerId'];
8 controller.onos=1;
9 controllers.push(controller);
10 controller_map[registry_raw[r][0]['controllerId']] = 1;
11 }
12 }
13// controllers.sort(
14// function(a,b){
15// if(a.name < b.name)
16// return -1;
17// if(a.name > b.name)
18// return 1;
19// return 0;
20// }
21// );
22 return controllers;
23}
24
25function controller_status(registry_url){
26/* var data = [{name:'onos9vpc', onos: 1, cassandra: 1},
27 {name:'onos10vpc', onos: 0, cassandra: 1},
28 {name:'onos11vpc', onos: 1, cassandra: 1},
29 {name:'onos12vpc', onos: 0, cassandra: 1}] */
30
31 var barWidth = 100;
32 var width = (barWidth + 10) * 8
33 var height = 50;
34
35 var ContStatus = d3.select("#onos-status").
36 append("svg:svg").
37 attr("width", 1280).
38 attr("height", 50);
39
40 setInterval(function() {
41 $.ajax({
42 url: registry_url,
43 success: function(registry) {
44 draw(data_convert(registry));
45 },
46 error: function() {
47 return;
48 },
49 dataType: "json"
50 });
51 }, 3000);
52 function draw(json){
53 var data = json;
54 var controller_rect = ContStatus.selectAll("rect").data(data);
55 var controller_text = ContStatus.selectAll("text").data(data);
56
57 var x = d3.scale.linear().domain([0, data.length]).range([0, width]);
58 var y = d3.scale.linear().domain([0, d3.max(data, function(datum) { return datum.onos; })]).rangeRound([0, height]);
59
60 console.log(data)
61 controller_rect.
62 enter().
63 append("svg:rect").
64 attr("x", function(datum, index) { return x(index); }).
65 attr("y", function(datum) { return height - y(datum.onos); }).
66 attr("height", function(datum) { return y(datum.onos); }).
67 attr("width", barWidth).
68 attr("fill", function(datum, index) {
69 if (index == 0){
70 return "red"
71 }else if (index == 1){
72 return "blue"
73 }else if (index == 2){
74 return "green"
75 }else if (index == 3){
76 return "orange"
77 }else if (index == 4){
78 return "cyan"
79 }else if (index == 5){
80 return "magenta"
81 }else if (index == 6){
82 return "yellow"
83 }else if (index == 7){
84 return "purple"
85 }else{
86 return "black"
87 }
88 });
89
90 controller_text.
91 enter().
92 append("svg:text").
93 text(function(datum) { return datum.name; }).
94 attr("x", function(datum, index) { return x(index)+10; }).
95 attr("y", function(datum) { return 30 ; }).
96 attr("height", function(datum) { return y(datum.onos); }).
97 attr("width", barWidth).
98 attr('fill', 'white');
99
100
101 controller_rect.
102 attr("x", function(datum, index) { return x(index); }).
103 attr("y", function(datum) { return height - y(datum.onos); }).
104 attr("height", function(datum) { return y(datum.onos); }).
105 attr("width", barWidth).
106 attr("fill", function(datum, index) {
107 if (index == 0){
108 return "red"
109 }else if (index == 1){
110 return "blue"
111 }else if (index == 2){
112 return "green"
113 }else if (index == 3){
114 return "orange"
115 }else if (index == 4){
116 return "cyan"
117 }else if (index == 5){
118 return "magenta"
119 }else if (index == 6){
120 return "yellow"
121 }else if (index == 7){
122 return "purple"
123 }else{
124 return "black"
125 }
126 });
127
128 controller_text.
129 text(function(datum) { return datum.name; }).
130 attr("x", function(datum, index) { return x(index)+10; }).
131 attr("y", function(datum) { return 30 ; }).
132 attr("height", function(datum) { return y(datum.onos); }).
133 attr("width", barWidth).
134 attr('fill', 'white');
135
136 controller_rect.exit().remove();
137 controller_text.exit().remove();
138 }
139/*
140 $("#more").click( function() {
141 $.ajax({
142 url: 'http://gui.onlab.us:8080/controller_status1',
143 success: function(json) {
144 draw(json);
145 },
146 dataType: "json"
147 });
148 });
149 $("#less").click( function() {
150 $.ajax({
151 url: 'http://gui.onlab.us:8080/controller_status2',
152 success: function(json) {
153 draw(json);
154 },
155 dataType: "json"
156 });
157 });
158*/
159}
160