Skip to content

Commit 02e325b

Browse files
committed
ensure that old choropleth location are removed on update
1 parent c735931 commit 02e325b

File tree

1 file changed

+44
-43
lines changed

1 file changed

+44
-43
lines changed

src/traces/choropleth/plot.js

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -75,50 +75,51 @@ plotChoropleth.plot = function(geo, choroplethData, geoLayout) {
7575

7676
gChoroplethTraces.exit().remove();
7777

78-
gChoroplethTraces
79-
.each(function(trace) {
80-
var cdi = plotChoropleth.calcGeoJSON(trace, geo.topojson),
81-
cleanHoverLabelsFunc = makeCleanHoverLabelsFunc(geo, trace),
82-
eventDataFunc = makeEventDataFunc(trace);
83-
84-
function handleMouseOver(pt, ptIndex) {
85-
if(!geo.showHover) return;
86-
87-
var xy = geo.projection(pt.properties.ct);
88-
cleanHoverLabelsFunc(pt);
89-
90-
Fx.loneHover({
91-
x: xy[0],
92-
y: xy[1],
93-
name: pt.nameLabel,
94-
text: pt.textLabel
95-
}, {
96-
container: geo.hoverContainer.node()
97-
});
78+
gChoroplethTraces.each(function(trace) {
79+
var cdi = plotChoropleth.calcGeoJSON(trace, geo.topojson),
80+
cleanHoverLabelsFunc = makeCleanHoverLabelsFunc(geo, trace),
81+
eventDataFunc = makeEventDataFunc(trace);
82+
83+
function handleMouseOver(pt, ptIndex) {
84+
if(!geo.showHover) return;
85+
86+
var xy = geo.projection(pt.properties.ct);
87+
cleanHoverLabelsFunc(pt);
88+
89+
Fx.loneHover({
90+
x: xy[0],
91+
y: xy[1],
92+
name: pt.nameLabel,
93+
text: pt.textLabel
94+
}, {
95+
container: geo.hoverContainer.node()
96+
});
97+
98+
geo.graphDiv.emit('plotly_hover', eventDataFunc(pt, ptIndex));
99+
}
98100

99-
geo.graphDiv.emit('plotly_hover', eventDataFunc(pt, ptIndex));
100-
}
101-
102-
function handleClick(pt, ptIndex) {
103-
geo.graphDiv.emit('plotly_click', eventDataFunc(pt, ptIndex));
104-
}
105-
106-
d3.select(this)
107-
.selectAll('path.choroplethlocation')
108-
.data(cdi)
109-
.enter().append('path')
110-
.attr('class', 'choroplethlocation')
111-
.on('mouseover', handleMouseOver)
112-
.on('click', handleClick)
113-
.on('mouseout', function() {
114-
Fx.loneUnhover(geo.hoverContainer);
115-
})
116-
.on('mousedown', function() {
117-
// to simulate the 'zoomon' event
118-
Fx.loneUnhover(geo.hoverContainer);
119-
})
120-
.on('mouseup', handleMouseOver); // ~ 'zoomend'
121-
});
101+
function handleClick(pt, ptIndex) {
102+
geo.graphDiv.emit('plotly_click', eventDataFunc(pt, ptIndex));
103+
}
104+
105+
var paths = d3.select(this).selectAll('path.choroplethlocation')
106+
.data(cdi);
107+
108+
paths.enter().append('path')
109+
.classed('choroplethlocation', true)
110+
.on('mouseover', handleMouseOver)
111+
.on('click', handleClick)
112+
.on('mouseout', function() {
113+
Fx.loneUnhover(geo.hoverContainer);
114+
})
115+
.on('mousedown', function() {
116+
// to simulate the 'zoomon' event
117+
Fx.loneUnhover(geo.hoverContainer);
118+
})
119+
.on('mouseup', handleMouseOver); // ~ 'zoomend'
120+
121+
paths.exit().remove();
122+
});
122123

123124
// some baselayers are drawn over choropleth
124125
gBaseLayerOverChoropleth.selectAll('*').remove();

0 commit comments

Comments
 (0)