I am creating a heatmap for Ukraine with some economic indicators.
Depending on what radio-button is checked, a different colorscale is used to visualize the different values/indicators.
d3.selectAll('.radio').on('change', function(){
if (document.getElementById('none').checked) {
areas.transition().duration(250)
.attr('fill','steelblue');}
else if (document.getElementById('agr').checked) {
areas.transition().duration(250)
.attr('fill', function(d){return colorScaleagr(d.properties.agricindx)});}
.... and so on.
Right now the tooltip (div) only shows the name of the region that is hovered over. I'd like to display also the value for the region, corresponding to the indicator that is selected at the moment. The tooltip's content (the name) is determined within an event-handler of the path/map element.
var areas = group.append('path')
.attr('d',path)
.attr('class', function(d) { return "subunit" + d.id; })
.attr('fill','steelblue')
.attr('stroke', 'white')
.attr('stroke-width', '1px')
.attr('opacity','0.8')
// Hover & Tooltip
.on("mouseover", function(d) {
d3.select(this).transition().duration(200).style("opacity", 1);
div.transition().duration(300).style("opacity", 1)
div.html(d.properties.name )
.style("left", (d3.mouse(this)[0] + 330) + "px")
.style("top", (d3.mouse(this)[1] + 15) + "px");
})
.on("mousemove", function(d) {
div.html(d.properties.name)
.style("left", (d3.mouse(this)[0] + 350) + "px")
.style("top", (d3.mouse(this)[1] + 25) + "px");
})
.on("mouseout", function(d) {
d3.select(this).transition().duration(200).style("opacity", 0.8);
div.transition().duration(300).style("opacity", 0)
});
So my question now is: How can i take into account the status of the radio-button, whithin the path-element (area) , since the data for the single entities (regions) is stored there. If I try to manipulate the tooltip within the radio-buttion selection, the data is not available to me. I hope I made myself understand :). I appreciate any help.
I think I understand what you are trying to do so here's an attempt of what I would do:
Hope that helps!