From c890bcbce27ae216314606a08a053f2448b439ab Mon Sep 17 00:00:00 2001 From: Antoine Goutenoir Date: Sun, 27 Oct 2019 20:04:43 +0100 Subject: [PATCH] Review. --- flaskr/templates/estimation.html | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/flaskr/templates/estimation.html b/flaskr/templates/estimation.html index 1332bd5..119bff8 100644 --- a/flaskr/templates/estimation.html +++ b/flaskr/templates/estimation.html @@ -147,7 +147,7 @@ Math.log10 = Math.log10 || function(x) { }; /** - * + * Useful for axes' domains on plots. * @param value * @returns {number} */ @@ -178,6 +178,9 @@ var ceil_value_to_magnitude = function(value) { jQuery(document).ready(function($){ var vizid = "#cities_footprints_d3viz"; + var csvUrl = "/estimation/{{ estimation.public_id }}.csv"; + var x_key = 'city'; + var y_key = 'co2 (g)'; // Set the dimensions and margins of the graph var margin = {top: 10, right: 30, bottom: 100, left: 100}, @@ -195,7 +198,7 @@ jQuery(document).ready(function($){ "translate(" + margin.left + "," + margin.top + ")"); // Parse the Data - d3.csv("/estimation/{{ estimation.public_id }}.csv", function(data) { + d3.csv(csvUrl, function(data) { // Extrema var data_y_max = d3.max(data, function(d) { return parseFloat(d['co2 (g)']); }); @@ -204,7 +207,7 @@ jQuery(document).ready(function($){ // X axis var x = d3.scaleBand() .range([ 0, width ]) - .domain(data.map(function(d) { return d.city; })) + .domain(data.map(function(d) { return d[x_key]; })) .padding(0.2); svg.append("g") .attr("transform", "translate(0," + height + ")") @@ -225,10 +228,10 @@ jQuery(document).ready(function($){ .data(data) .enter() .append("rect") - .attr("x", function(d) { return x(d['city']); }) + .attr("x", function(d) { return x(d[x_key]); }) .attr("width", x.bandwidth()) .attr("fill", "#d0808b") - // Hide bar at the beginning + // Hide bars at the beginning .attr("height", function(d) { return height - y(0); }) // always equal to 0 .attr("y", function(d) { return y(0); }); @@ -236,8 +239,8 @@ jQuery(document).ready(function($){ svg.selectAll("rect") .transition() .duration(800) - .attr("y", function(d) { return y(d['co2 (g)']); }) - .attr("height", function(d) { return height - y(d['co2 (g)']); }) + .attr("y", function(d) { return y(d[y_key]); }) + .attr("height", function(d) { return height - y(d[y_key]); }) .delay(function(d, i) { return(i*100); }); // … -- libgit2 0.21.2