From 85984e428e4ffcdc5be1b18337a8ba7a9e9f8a85 Mon Sep 17 00:00:00 2001 From: Antoine Goutenoir Date: Fri, 2 Oct 2020 06:18:53 +0200 Subject: [PATCH] design: improve the margins and publish the new plot --- flaskr/static/js/plots/sorted_emissions_inequality.js | 34 ++++++++++++++++++++-------------- flaskr/templates/estimation.html | 17 ++++++++++++++++- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/flaskr/static/js/plots/sorted_emissions_inequality.js b/flaskr/static/js/plots/sorted_emissions_inequality.js index 606bfc6..8ae1fb0 100644 --- a/flaskr/static/js/plots/sorted_emissions_inequality.js +++ b/flaskr/static/js/plots/sorted_emissions_inequality.js @@ -1,7 +1,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { // set the dimensions and margins of the graph - let margin = {top: 30, right: 10, bottom: 62, left: 72}, + let margin = {top: 50, right: 30, bottom: 80, left: 75}, width = 600 - margin.left - margin.right, height = 700 - margin.top - margin.bottom; @@ -78,7 +78,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { } - function setupCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip) { + function refreshCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip) { const x = d3.pointer(event)[0]; const y = d3.pointer(event)[1]; // var y = d3.event.pageY - document.getElementById().getBoundingClientRect().y + 10 @@ -109,19 +109,26 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { let sliceCollision = getSliceCollision(xInGraph, yInGraph, barSettings); // console.log(sliceCollision); if (sliceCollision) { - if (sliceCollision.isXDriving) { vertical.style("left", x + "px"); horizontal.style("top", yScale(sliceCollision.otherAxisLevel) + margin.top + "px"); - tooltip.text(Math.round(xInGraph) + "% of participants emitted " + Math.round(sliceCollision.otherAxisLevel) + "% of CO\u2082eq"); + tooltip.text( + Math.round(xInGraph) + + "% of 🖘 attendees emitted " + + Math.round(sliceCollision.otherAxisLevel) + + "% of CO\u2082 equivalent" + ); } else { horizontal.style("top", y + "px"); vertical.style("left", xScale(sliceCollision.otherAxisLevel) + margin.left + "px"); - // noinspection JSSuspiciousNameCombination o.O - tooltip.text(Math.round(100.0 - sliceCollision.otherAxisLevel) + "% of participants emitted " + Math.round(100.0 - yInGraph) + "% of CO\u2082eq"); - // tooltip.text(sliceCollision.otherAxisLevel + " " + yInGraph); + tooltip.text( + Math.round(100.0 - sliceCollision.otherAxisLevel) + + "% of 🖙 attendees emitted " + + Math.round(100.0 - yInGraph) + + "% of CO\u2082 equivalent" + ); } } @@ -160,7 +167,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { let tooltip = d3.select(containerSelector) .append("div") - .attr("class", "no-pointer-events") + .attr("class", "no-pointer-events plot-tooltip") .style("display", "none") .style("position", "absolute") .style("z-index", "20") @@ -175,10 +182,10 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { d3.select(containerSelector) .on("mousemove", function (event) { - setupCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip); + refreshCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip); }) .on("mouseover", function (event) { - setupCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip); + refreshCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip); }); } @@ -232,7 +239,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { } return 0; }); - console.log(data); + // console.log(data); let dataIndex = 0; data.forEach((datum, index) => { let trainAttendee = parseInt(datum["train trips_amount"]); @@ -255,8 +262,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { //Title svg.append("text") .attr("transform", - "translate(" + (70 + margin.left) + ", -12)") - .style("text-anchor", "middle") + "translate(" + (0) + ", -15)") .style("font-weight", "bold") .style("font-size", "130%") .text("Sorted carbon emissions"); @@ -291,7 +297,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { svg.append("text") .attr("transform", "rotate(-90)") - .attr("y", 0 - margin.left) + .attr("y", 0 - 4*margin.left/5) .attr("x", 0 - (height / 2)) .attr("dy", "1em") .style("text-anchor", "middle") diff --git a/flaskr/templates/estimation.html b/flaskr/templates/estimation.html index 0b89a27..7eda3a2 100644 --- a/flaskr/templates/estimation.html +++ b/flaskr/templates/estimation.html @@ -122,6 +122,16 @@ {% endif %} {#############################################################################} +{# SORTED EMISSIONS INEQUALITY ##########################################} +{# That plot makes no sense with our many to many data. #} +{% if not estimation.is_many_to_many() %} +
+
+
+
+{% endif %} +{#############################################################################} + {% endif %}{# not estimation.has_failed() #} @@ -244,11 +254,12 @@ +