diff options
author | Daniel Friesel <derf@finalrewind.org> | 2015-02-19 22:47:58 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2015-02-19 22:47:58 +0100 |
commit | 9f8c64bacc2b791e5e5a029e36999cbfeb88bd79 (patch) | |
tree | 22a72a755f7d8fe976c3bf0cc594ff4f213937f3 /templates | |
parent | f7550f4cd4929bdf19e2cce1447990ae1414a11b (diff) |
add d3js and a barplot playground
Diffstat (limited to 'templates')
-rw-r--r-- | templates/layouts/default.html.ep | 34 | ||||
-rw-r--r-- | templates/main.html.ep | 94 |
2 files changed, 128 insertions, 0 deletions
diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep new file mode 100644 index 0000000..479a282 --- /dev/null +++ b/templates/layouts/default.html.ep @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html> +<head> + <title><%= stash('title') // 'iris-delay-stats' %></title> + <meta charset="utf-8"> +% if ($self->stash('refresh_interval')) { + <meta http-equiv="refresh" content="<%= $self->stash('refresh_interval') %>"/> +% } + + + %= stylesheet '/default.css' + %= javascript '/d3.min.js' + %= javascript '/d3.tip.v0.6.3.js' +</head> +<body style="<%= (stash('hide_opts') ? 'margin: 0; padding: 0;' : q{}) %>"> + +% if (my $error = stash 'error') { +<div class="error">Backend-Fehler:</div> +<div> +<pre> +%= $error +</pre> +</div> +% } + +%= content + +<div class="about"> +<a href="http://finalrewind.org/projects/db-fakedisplay/">dbdb</a> +v<%= stash('version') // '???' %> +</div> + +</body> +</html> diff --git a/templates/main.html.ep b/templates/main.html.ep new file mode 100644 index 0000000..6bca074 --- /dev/null +++ b/templates/main.html.ep @@ -0,0 +1,94 @@ +%= javascript begin + +var margin = {top: 40, right: 20, bottom: 30, left: 40}, + width = 960 - margin.left - margin.right, + height = 500 - margin.top - margin.bottom; + +var formatPercent = d3.format(".0%"); + +var x = d3.scale.ordinal() + .rangeRoundBands([0, width], .1); + +var y = d3.scale.linear() + .range([height, 0]); + +var xAxis = d3.svg.axis() + .scale(x) + .orient("bottom"); + +var yAxis = d3.svg.axis() + .scale(y) + .orient("left"); +// .tickFormat(formatPercent); + +var tip = d3.tip() + .attr('class', 'd3-tip') + .offset([-10, 0]) + .html(function(d) { + return "<strong>Frequency:</strong> <span style='color:red'>" + d.avgdelay + "</span>"; + }) + +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 + ")"); + +svg.call(tip); + +d3.tsv("/by_hour.tsv", type, function(error, data) { + if (error) console.warn(error); + x.domain(data.map(function(d) { return d.hour; })); + y.domain([0, d3.max(data, function(d) { return d.avgdelay; })]); + + svg.append("g") + .attr("class", "x axis") + .attr("transform", "translate(0," + height + ")") + .call(xAxis) + .append("text") + .attr("x", width / 2) + .attr("y", 30) + .style("text-anchor", "middle") + .text("Angebrochene Stunde"); + + 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("Minuten"); + + svg.append("text") + .attr("x", (width / 2)) + .attr("y", 0 - (margin.top / 2)) + .attr("text-anchor", "middle") + .style("font-size", "16px") + .style("text-decoration", "underline") + .text("Durchschnittliche Verspätung nach Uhrzeit"); + + svg.selectAll(".bar") + .data(data) + .enter().append("rect") + .attr("class", "bar") + .attr("x", function(d) { return x(d.hour); }) + .attr("width", x.rangeBand()) + .attr("y", function(d) { return y(d.avgdelay); }) + .attr("height", function(d) { return height - y(d.avgdelay); }) + .on('mouseover', tip.show) + .on('mouseout', tip.hide) + +}); + +function type(d) { + d.avgdelay = +d.avgdelay; + return d; +} + +% end + +<div> +Insgesamt: <%= stash('num_departures') %> Züge. +</div> |