From 8ad5eb58b01e068428652aabcb519281ab6c0461 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 24 Feb 2015 16:20:47 +0100 Subject: bargraph: optional width/height parameters --- public/js/d3funcs.js | 15 +++++++++++---- templates/main.html.ep | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/public/js/d3funcs.js b/public/js/d3funcs.js index 15fe5eb..f7f698d 100644 --- a/public/js/d3funcs.js +++ b/public/js/d3funcs.js @@ -1,8 +1,15 @@ -show_bargraph = function(datasource, title, xLabel, yLabel, yFormat) { +show_bargraph = function(datasource, title, xLabel, yLabel, yFormat, width, height) { - var margin = {top: 40, right: 20, bottom: 30, left: 40}, - width = 960 - margin.left - margin.right, - height = 500 - margin.top - margin.bottom; + var margin = {top: 40, right: 20, bottom: 30, left: 40}; + + if (!width) { + width = 960; + } + if (!height) { + height = 500; + } + width -= margin.left + margin.right; + height -= margin.top + margin.bottom; var x = d3.scale.ordinal() .rangeRoundBands([0, width], .1); diff --git a/templates/main.html.ep b/templates/main.html.ep index 6038879..ecf3f76 100644 --- a/templates/main.html.ep +++ b/templates/main.html.ep @@ -13,7 +13,7 @@ show_bargraph('/2ddata.tsv?aggregate=weekday&metric=cancel_rate', 'Anteil Zugaus 'Wochentag', 'Ausfälle', '.1%'); show_bargraph('/2ddata.tsv?aggregate=weekhour&metric=delay', 'Durchschnittliche Verspätung nach Wochentag und Uhrzeit', - 'Tag/Stunde', 'Minuten', '.1f'); + 'Tag/Stunde', 'Minuten', '.1f', 2048, 400); show_bargraph('/2ddata.tsv?aggregate=line&metric=delay', 'Durchschnittliche Verspätung nach Linie', 'Typ', 'Minuten', '.1f'); -- cgit v1.2.3