Closed ramnathv closed 8 years ago
This should work for the geographies:
done: function(map) {
map.svg.selectAll('.datamaps-subunit').on('click', function(geography) {
console.log( map.options.data[geography.id] );
});
}
Ah. I would never have figured that out! For consistency with the popupTemplate
function, do you think it would be better to allow data
to also be explicitly passed to the done
method. I can work with what you have now, but thought it would be good to keep things consistent.
The first version of datamaps had that, but I ended up removing it.
For it to work, I had to hard code the events datamaps would allow to be emitted, like "click .bubble", "mouseenter .datamap-subunit" and so on. I ended up including the 20 or so events I thought would be used, but the decided to change my approach and allow you to listen to any event with d3's selection.on
event handler.
Doing that lose the data
parameter, though, and now a lookup is required.
I dislike the inconsistency and think it should be made consistent, and I want to explore some lightweight options, like:
Inside any event handler, d3.select(this).datum()
should return the geography
as well as the corresponding data
value.
I think that's attainable pretty easily, since right now it already provides the geography.
Is it possible to access the
data
associated with an element when using thedone
method to trigger an action. I see thatgeography
is allowed, but wasn't able to getdata
working, just like inpopupTemplate
.