koder aka kdanilov | 36e3a6e | 2015-04-25 21:21:58 +0300 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <meta charset="utf-8"> |
| 3 | <style> |
| 4 | @import url(http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:400,700); |
| 5 | @import url(http://square.github.io/cubism/style.css); |
| 6 | </style> |
| 7 | <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> |
| 8 | <script src="http://square.github.io/cubism/cubism.v1.js"></script> |
| 9 | <div id="body"> <div id="graph" /></div> |
| 10 | |
| 11 | <script> |
| 12 | |
| 13 | // create context and horizon |
| 14 | var context = cubism.context().serverDelay(3 * 1000).step(1000).size(1000) |
| 15 | var horizon = context.horizon().extent([0, 100]) |
| 16 | |
| 17 | // define metric accessor |
| 18 | function wally_source(name) { |
| 19 | function selector(start, stop, step, callback){ |
| 20 | function on_result(data) { |
| 21 | callback(null, data); |
| 22 | }; |
| 23 | |
| 24 | url = "/sensors?start=" + start + "&stop=" + stop + "&step=" + step + "&name=" + name; |
| 25 | d3.json(url, on_result); |
| 26 | } |
| 27 | |
| 28 | return context.metric(selector, name); |
| 29 | } |
| 30 | |
| 31 | // draw graph |
| 32 | var metrics = ["testnodes:io_q", "testnodes:cpu"]; |
| 33 | horizon.metric(wally_source); |
| 34 | |
| 35 | d3.select("#graph").selectAll(".horizon") |
| 36 | .data(metrics) |
| 37 | .enter() |
| 38 | .append("div") |
| 39 | .attr("class", "horizon") |
| 40 | .call(horizon.height(120)); |
| 41 | |
| 42 | // set rule |
| 43 | d3.select("#body").append("div") |
| 44 | .attr("class", "rule") |
| 45 | .call(context.rule()); |
| 46 | |
| 47 | // set focus |
| 48 | context.on("focus", function(i) { |
| 49 | d3.selectAll(".value") |
| 50 | .style( "right", i == null ? null : context.size() - i + "px"); |
| 51 | }); |
| 52 | |
| 53 | // set axis |
| 54 | var axis = context.axis() |
| 55 | d3.select("#graph").append("div").attr("class", "axis").append("g").call(axis); |
| 56 | |
| 57 | </script> |