Commit 13b5231b9c346cb664843863a6e75c69d5555a2d
1 parent
a289e7f7
Exists in
master
Add an area to tell which side is aimed by the crusor
Showing
1 changed file
with
26 additions
and
5 deletions
Show diff stats
flaskr/static/js/plots/sorted_emissions_inequality.js
@@ -78,7 +78,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | @@ -78,7 +78,7 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | ||
78 | 78 | ||
79 | } | 79 | } |
80 | 80 | ||
81 | - function refreshCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip) { | 81 | + function refreshCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip, selectedArea) { |
82 | const x = d3.pointer(event)[0]; | 82 | const x = d3.pointer(event)[0]; |
83 | const y = d3.pointer(event)[1]; | 83 | const y = d3.pointer(event)[1]; |
84 | // var y = d3.event.pageY - document.getElementById(<id-of-your-svg>).getBoundingClientRect().y + 10 | 84 | // var y = d3.event.pageY - document.getElementById(<id-of-your-svg>).getBoundingClientRect().y + 10 |
@@ -100,11 +100,13 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | @@ -100,11 +100,13 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | ||
100 | ) { | 100 | ) { |
101 | vertical.style("display", "none"); | 101 | vertical.style("display", "none"); |
102 | horizontal.style("display", "none"); | 102 | horizontal.style("display", "none"); |
103 | + selectedArea.style("display", "none"); | ||
103 | tooltip.style("display", "none"); | 104 | tooltip.style("display", "none"); |
104 | } | 105 | } |
105 | else { | 106 | else { |
106 | vertical.style("display", "inherit"); | 107 | vertical.style("display", "inherit"); |
107 | horizontal.style("display", "inherit"); | 108 | horizontal.style("display", "inherit"); |
109 | + selectedArea.style("display", "inherit"); | ||
108 | tooltip.style("display", "inherit"); | 110 | tooltip.style("display", "inherit"); |
109 | let sliceCollision = getSliceCollision(xInGraph, yInGraph, barSettings); | 111 | let sliceCollision = getSliceCollision(xInGraph, yInGraph, barSettings); |
110 | // console.log(sliceCollision); | 112 | // console.log(sliceCollision); |
@@ -112,7 +114,10 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | @@ -112,7 +114,10 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | ||
112 | if (sliceCollision.isXDriving) { | 114 | if (sliceCollision.isXDriving) { |
113 | vertical.style("left", x + "px"); | 115 | vertical.style("left", x + "px"); |
114 | horizontal.style("top", yScale(sliceCollision.otherAxisLevel) + margin.top + "px"); | 116 | horizontal.style("top", yScale(sliceCollision.otherAxisLevel) + margin.top + "px"); |
115 | - | 117 | + selectedArea.style("top", yScale(sliceCollision.otherAxisLevel) + margin.top + "px"); |
118 | + selectedArea.style("height", yScale(0) - yScale(sliceCollision.otherAxisLevel) + "px"); | ||
119 | + selectedArea.style("left", xScale(0) + margin.left + "px"); | ||
120 | + selectedArea.style("width", x - margin.left - xScale(0) + "px"); | ||
116 | tooltip.text( | 121 | tooltip.text( |
117 | Math.round(xInGraph) + | 122 | Math.round(xInGraph) + |
118 | "% of ๐ attendees emitted " + | 123 | "% of ๐ attendees emitted " + |
@@ -122,7 +127,10 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | @@ -122,7 +127,10 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | ||
122 | } else { | 127 | } else { |
123 | horizontal.style("top", y + "px"); | 128 | horizontal.style("top", y + "px"); |
124 | vertical.style("left", xScale(sliceCollision.otherAxisLevel) + margin.left + "px"); | 129 | vertical.style("left", xScale(sliceCollision.otherAxisLevel) + margin.left + "px"); |
125 | - | 130 | + selectedArea.style("top", margin.top + "px"); |
131 | + selectedArea.style("height", y - margin.top + "px"); | ||
132 | + selectedArea.style("left", xScale(sliceCollision.otherAxisLevel) + margin.left + "px"); | ||
133 | + selectedArea.style("width", xScale(100) - (xScale(sliceCollision.otherAxisLevel)) + "px"); | ||
126 | tooltip.text( | 134 | tooltip.text( |
127 | Math.round(100.0 - sliceCollision.otherAxisLevel) + | 135 | Math.round(100.0 - sliceCollision.otherAxisLevel) + |
128 | "% of ๐ attendees emitted " + | 136 | "% of ๐ attendees emitted " + |
@@ -180,12 +188,25 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | @@ -180,12 +188,25 @@ function draw_sorted_emissions_inequality(containerSelector, csvUrl) { | ||
180 | .style("border", "1px solid grey") | 188 | .style("border", "1px solid grey") |
181 | .style("background", "rgba(255, 255, 255, 0.7)"); | 189 | .style("background", "rgba(255, 255, 255, 0.7)"); |
182 | 190 | ||
191 | + let selectedArea = d3.select(containerSelector) | ||
192 | + .append("div") | ||
193 | + .attr("class", "no-pointer-events") | ||
194 | + .style("display", "none") | ||
195 | + .style("position", "absolute") | ||
196 | + .style("z-index", "-50") | ||
197 | + .style("width", "0px") | ||
198 | + .style("height", (height) + "px") | ||
199 | + .style("top", (margin.top) + "px") | ||
200 | + .style("bottom", "30px") | ||
201 | + .style("left", "0px") | ||
202 | + .style("background", "rgba(60, 200, 60, 0.3)"); | ||
203 | + | ||
183 | d3.select(containerSelector) | 204 | d3.select(containerSelector) |
184 | .on("mousemove", function (event) { | 205 | .on("mousemove", function (event) { |
185 | - refreshCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip); | 206 | + refreshCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip, selectedArea); |
186 | }) | 207 | }) |
187 | .on("mouseover", function (event) { | 208 | .on("mouseover", function (event) { |
188 | - refreshCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip); | 209 | + refreshCursorBoxes(event, xScale, yScale, barSettings, vertical, horizontal, tooltip, selectedArea); |
189 | }); | 210 | }); |
190 | } | 211 | } |
191 | 212 |