Commit c890bcbce27ae216314606a08a053f2448b439ab
1 parent
aab8077d
Exists in
master
Review.
Showing
1 changed file
with
10 additions
and
7 deletions
Show diff stats
flaskr/templates/estimation.html
... | ... | @@ -147,7 +147,7 @@ Math.log10 = Math.log10 || function(x) { |
147 | 147 | }; |
148 | 148 | |
149 | 149 | /** |
150 | - * | |
150 | + * Useful for axes' domains on plots. | |
151 | 151 | * @param value |
152 | 152 | * @returns {number} |
153 | 153 | */ |
... | ... | @@ -178,6 +178,9 @@ var ceil_value_to_magnitude = function(value) { |
178 | 178 | jQuery(document).ready(function($){ |
179 | 179 | |
180 | 180 | var vizid = "#cities_footprints_d3viz"; |
181 | + var csvUrl = "/estimation/{{ estimation.public_id }}.csv"; | |
182 | + var x_key = 'city'; | |
183 | + var y_key = 'co2 (g)'; | |
181 | 184 | |
182 | 185 | // Set the dimensions and margins of the graph |
183 | 186 | var margin = {top: 10, right: 30, bottom: 100, left: 100}, |
... | ... | @@ -195,7 +198,7 @@ jQuery(document).ready(function($){ |
195 | 198 | "translate(" + margin.left + "," + margin.top + ")"); |
196 | 199 | |
197 | 200 | // Parse the Data |
198 | - d3.csv("/estimation/{{ estimation.public_id }}.csv", function(data) { | |
201 | + d3.csv(csvUrl, function(data) { | |
199 | 202 | |
200 | 203 | // Extrema |
201 | 204 | var data_y_max = d3.max(data, function(d) { return parseFloat(d['co2 (g)']); }); |
... | ... | @@ -204,7 +207,7 @@ jQuery(document).ready(function($){ |
204 | 207 | // X axis |
205 | 208 | var x = d3.scaleBand() |
206 | 209 | .range([ 0, width ]) |
207 | - .domain(data.map(function(d) { return d.city; })) | |
210 | + .domain(data.map(function(d) { return d[x_key]; })) | |
208 | 211 | .padding(0.2); |
209 | 212 | svg.append("g") |
210 | 213 | .attr("transform", "translate(0," + height + ")") |
... | ... | @@ -225,10 +228,10 @@ jQuery(document).ready(function($){ |
225 | 228 | .data(data) |
226 | 229 | .enter() |
227 | 230 | .append("rect") |
228 | - .attr("x", function(d) { return x(d['city']); }) | |
231 | + .attr("x", function(d) { return x(d[x_key]); }) | |
229 | 232 | .attr("width", x.bandwidth()) |
230 | 233 | .attr("fill", "#d0808b") |
231 | - // Hide bar at the beginning | |
234 | + // Hide bars at the beginning | |
232 | 235 | .attr("height", function(d) { return height - y(0); }) // always equal to 0 |
233 | 236 | .attr("y", function(d) { return y(0); }); |
234 | 237 | |
... | ... | @@ -236,8 +239,8 @@ jQuery(document).ready(function($){ |
236 | 239 | svg.selectAll("rect") |
237 | 240 | .transition() |
238 | 241 | .duration(800) |
239 | - .attr("y", function(d) { return y(d['co2 (g)']); }) | |
240 | - .attr("height", function(d) { return height - y(d['co2 (g)']); }) | |
242 | + .attr("y", function(d) { return y(d[y_key]); }) | |
243 | + .attr("height", function(d) { return height - y(d[y_key]); }) | |
241 | 244 | .delay(function(d, i) { return(i*100); }); |
242 | 245 | |
243 | 246 | // … | ... | ... |