Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 1 | function 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 Kobayashi | 5149675 | 2013-03-25 22:44:23 +0000 | [diff] [blame] | 8 | var width = (barWidth + 10) * 8 |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 9 | var height = 50; |
| 10 | |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 11 | var Servers = d3.select("#servers"). |
| 12 | append("svg:svg"). |
Masayoshi Kobayashi | 5149675 | 2013-03-25 22:44:23 +0000 | [diff] [blame] | 13 | attr("width", 1280). |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 14 | attr("height", 30); |
| 15 | |
| 16 | var ContStatus = d3.select("#onos-status"). |
| 17 | append("svg:svg"). |
Masayoshi Kobayashi | 5149675 | 2013-03-25 22:44:23 +0000 | [diff] [blame] | 18 | attr("width", 1280). |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 19 | attr("height", 50); |
| 20 | |
| 21 | var CassandraStatus = d3.select("#cassandra-status"). |
| 22 | append("svg:svg"). |
Masayoshi Kobayashi | 5149675 | 2013-03-25 22:44:23 +0000 | [diff] [blame] | 23 | attr("width", 1280). |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 24 | attr("height", 50); |
| 25 | |
| 26 | d3.json(data_source, draw); |
Ubuntu | 765deff | 2013-02-28 18:39:13 +0000 | [diff] [blame] | 27 | setInterval(function() { |
| 28 | $.ajax({ |
| 29 | url: data_source, |
| 30 | success: function(json) { |
| 31 | draw(json) |
| 32 | }, |
| 33 | dataType: "json" |
| 34 | }); |
Tim Lindberg | 86a85f6 | 2013-03-26 11:34:01 -0700 | [diff] [blame] | 35 | }, 3000); |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 36 | |
| 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; }). |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 56 | 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 Kobayashi | 5149675 | 2013-03-25 22:44:23 +0000 | [diff] [blame] | 65 | }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" |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 73 | }else{ |
| 74 | return "black" |
| 75 | } |
| 76 | }). |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 77 | 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). |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 86 | 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 Kobayashi | 5149675 | 2013-03-25 22:44:23 +0000 | [diff] [blame] | 95 | }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" |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 103 | }else{ |
| 104 | return "black" |
| 105 | } |
| 106 | }); |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 107 | |
| 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 | |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 137 | |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 138 | 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). |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 143 | 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 Kobayashi | 5149675 | 2013-03-25 22:44:23 +0000 | [diff] [blame] | 152 | }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" |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 160 | }else{ |
| 161 | return "black" |
| 162 | } |
| 163 | }); |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 164 | |
| 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(); |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 194 | |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 195 | } |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 196 | /* |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 197 | $("#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 | }); |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 215 | */ |
Masayoshi Kobayashi | fc5e237 | 2013-02-27 20:21:28 +0000 | [diff] [blame] | 216 | } |
| 217 | |