blob: 3004ce8d7baab423a6226e72695fd5cd186cd0e9 [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
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +000021 d3.json(data_source, draw);
Ubuntu765deff2013-02-28 18:39:13 +000022 setInterval(function() {
23 $.ajax({
24 url: data_source,
25 success: function(json) {
26 draw(json)
27 },
28 dataType: "json"
29 });
Tim Lindberg86a85f62013-03-26 11:34:01 -070030 }, 3000);
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +000031
32 function draw(json){
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +000033 var data = json;
34 var server = Servers.selectAll("text").data(data);
35 var controller_rect = ContStatus.selectAll("rect").data(data);
36 var controller_text = ContStatus.selectAll("text").data(data);
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +000037
38 var x = d3.scale.linear().domain([0, data.length]).range([0, width]);
39 var y = d3.scale.linear().domain([0, d3.max(data, function(datum) { return datum.onos; })]).rangeRound([0, height]);
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +000040
41 console.log(data)
42 server.
43 enter().
44 append("svg:text").
45 attr("x", function(datum, index) { return x(index); }).
46 attr("y", function(datum) { return 20; }).
Ubuntuc016ba12013-02-27 21:53:41 +000047 attr("fill", function(datum, index) {
48 if (index == 0){
49 return "red"
50 }else if (index == 1){
51 return "blue"
52 }else if (index == 2){
53 return "green"
54 }else if (index == 3){
55 return "orange"
Masayoshi Kobayashi51496752013-03-25 22:44:23 +000056 }else if (index == 4){
57 return "cyan"
58 }else if (index == 5){
59 return "magenta"
60 }else if (index == 6){
61 return "yellow"
62 }else if (index == 7){
63 return "purple"
Ubuntuc016ba12013-02-27 21:53:41 +000064 }else{
65 return "black"
66 }
67 }).
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +000068 text(function(datum) { return datum.name; });
69
70 controller_rect.
71 enter().
72 append("svg:rect").
73 attr("x", function(datum, index) { return x(index); }).
74 attr("y", function(datum) { return height - y(datum.onos); }).
75 attr("height", function(datum) { return y(datum.onos); }).
76 attr("width", barWidth).
Ubuntuc016ba12013-02-27 21:53:41 +000077 attr("fill", function(datum, index) {
78 if (index == 0){
79 return "red"
80 }else if (index == 1){
81 return "blue"
82 }else if (index == 2){
83 return "green"
84 }else if (index == 3){
85 return "orange"
Masayoshi Kobayashi51496752013-03-25 22:44:23 +000086 }else if (index == 4){
87 return "cyan"
88 }else if (index == 5){
89 return "magenta"
90 }else if (index == 6){
91 return "yellow"
92 }else if (index == 7){
93 return "purple"
Ubuntuc016ba12013-02-27 21:53:41 +000094 }else{
95 return "black"
96 }
97 });
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +000098
99 controller_text.
100 enter().
101 append("svg:text").
102 text(function(){return "ONOS"}).
103 attr("x", function(datum, index) { return x(index)+10; }).
104 attr("y", function(datum) { return 30 ; }).
105 attr("height", function(datum) { return y(datum.onos); }).
106 attr("width", barWidth).
107 attr('fill', 'white');
108
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +0000109 controller_rect.
110 attr("x", function(datum, index) { return x(index); }).
111 attr("y", function(datum) { return height - y(datum.onos); }).
112 attr("height", function(datum) { return y(datum.onos); }).
113 attr("width", barWidth).
Ubuntuc016ba12013-02-27 21:53:41 +0000114 attr("fill", function(datum, index) {
115 if (index == 0){
116 return "red"
117 }else if (index == 1){
118 return "blue"
119 }else if (index == 2){
120 return "green"
121 }else if (index == 3){
122 return "orange"
Masayoshi Kobayashi51496752013-03-25 22:44:23 +0000123 }else if (index == 4){
124 return "cyan"
125 }else if (index == 5){
126 return "magenta"
127 }else if (index == 6){
128 return "yellow"
129 }else if (index == 7){
130 return "purple"
Ubuntuc016ba12013-02-27 21:53:41 +0000131 }else{
132 return "black"
133 }
134 });
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +0000135
136 controller_text.
137 text(function(){return "ONOS"}).
138 attr("x", function(datum, index) { return x(index)+10; }).
139 attr("y", function(datum) { return 30 ; }).
140 attr("height", function(datum) { return y(datum.onos); }).
141 attr("width", barWidth).
142 attr('fill', 'white');
143
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +0000144 server.exit().remove();
145 controller_rect.exit().remove();
146 controller_text.exit().remove();
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +0000147 }
Masayoshi Kobayashifc5e2372013-02-27 20:21:28 +0000148}
149