Files
OpenSpace/monitor/index.html
2016-06-27 18:08:26 -04:00

129 lines
3.6 KiB
HTML

<html lang="en">
<head>
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="http://getbootstrap.com/examples/justified-nav/justified-nav.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body>
<button id="start-stop" onclick="startStop()">Start / Stop</button>
<svg></svg>
</body>
<script type="text/javascript">
var updateInterval = undefined;
function startStop(){
if(updateInterval === undefined){
console.log("Start updating");
updateInterval = setInterval(doVis, 1000);
doVis(); // Do one immediately
}
else{
console.log("Stop updating");
clearInterval(updateInterval);
updateInterval = undefined;
}
}
function doVis(){
var filename = "../data/scene/debugglobe/test_stats";
var margin = {top: 20, right: 80, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var parseDate = d3.time.format("%Y%m").parse;
var x = d3.time.scale()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
var color = d3.scale.category10();
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var line = d3.svg.line()
//.interpolate("basis")
.x(function(d) { return x(d.time); })
.y(function(d) { return y(d.value); });
d3.select("svg").remove();
var svg = d3.select("body").append('svg')
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.csv(filename, function(error, data) {
if (error) throw error;
color.domain(d3.keys(data[0]).filter(function(key) { return key !== "time"; }));
data.forEach(function(d) {
d.time = new Date(+d.time);
});
var cities = color.domain().map(function(name) {
return {
name: name,
values: data.map(function(d) {
return {time: d.time, value: +d[name]};
})
};
});
x.domain(d3.extent(data, function(d) { return d.time; }));
y.domain([
d3.min(cities, function(c) { return d3.min(c.values, function(v) { return v.value; }); }),
d3.max(cities, function(c) { return d3.max(c.values, function(v) { return v.value; }); })
]);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("");
var city = svg.selectAll(".city")
.data(cities)
.enter().append("g")
.attr("class", "city");
city.append("path")
.attr("class", "line")
.attr("d", function(d) { return line(d.values); })
.style("stroke", function(d) { return color(d.name); });
city.append("text")
.datum(function(d) { return {name: d.name, value: d.values[d.values.length - 1]}; })
.attr("transform", function(d) { return "translate(" + x(d.value.time) + "," + y(d.value.value) + ")"; })
.attr("x", 3)
.attr("dy", ".35em")
.text(function(d) { return d.name; });
});
}
doVis();
</script>
</html>