Skip to content

Commit e892923

Browse files
committed
fix ordering for choropleths
1 parent 69dee75 commit e892923

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

src/traces/choropleth/plot.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,8 @@ module.exports = function plot(gd, geo, calcData) {
2222
calcGeoJSON(calcData[i], geo.topojson);
2323
}
2424

25-
function keyFunc(d) { return d[0].trace.uid; }
26-
27-
var gTraces = geo.layers.backplot.select('.choroplethlayer')
28-
.selectAll('g.trace.choropleth')
29-
.data(calcData, keyFunc);
30-
31-
gTraces.enter().append('g')
32-
.attr('class', 'trace choropleth');
33-
34-
gTraces.exit().remove();
35-
36-
gTraces.each(function(calcTrace) {
25+
var choroplethLayer = geo.layers.backplot.select('.choroplethlayer');
26+
Lib.makeTraceGroups(choroplethLayer, calcData, 'trace choropleth').each(function(calcTrace) {
3727
var sel = calcTrace[0].node3 = d3.select(this);
3828

3929
var paths = sel.selectAll('path.choroplethlocation')

test/jasmine/tests/choropleth_test.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var d3 = require('d3');
88
var createGraphDiv = require('../assets/create_graph_div');
99
var destroyGraphDiv = require('../assets/destroy_graph_div');
1010
var mouseEvent = require('../assets/mouse_event');
11+
var failTest = require('../assets/fail_test');
1112

1213
var customAssertions = require('../assets/custom_assertions');
1314
var assertHoverLabelStyle = customAssertions.assertHoverLabelStyle;
@@ -175,7 +176,7 @@ describe('Test choropleth hover:', function() {
175176
});
176177
});
177178

178-
describe('choropleth bad data', function() {
179+
describe('choropleth drawing', function() {
179180
var gd;
180181

181182
beforeEach(function() {
@@ -196,7 +197,38 @@ describe('choropleth bad data', function() {
196197
// only utopia logs - others are silently ignored
197198
expect(Lib.log).toHaveBeenCalledTimes(1);
198199
})
199-
.catch(fail)
200+
.catch(failTest)
201+
.then(done);
202+
});
203+
204+
it('preserves order after hide/show', function(done) {
205+
function getIndices() {
206+
var out = [];
207+
d3.selectAll('.choropleth').each(function(d) { out.push(d[0].trace.index); });
208+
return out;
209+
}
210+
211+
Plotly.newPlot(gd, [{
212+
type: 'choropleth',
213+
locations: ['CAN', 'USA'],
214+
z: [1, 2]
215+
}, {
216+
type: 'choropleth',
217+
locations: ['CAN', 'USA'],
218+
z: [2, 1]
219+
}])
220+
.then(function() {
221+
expect(getIndices()).toEqual([0, 1]);
222+
return Plotly.restyle(gd, 'visible', false, [0]);
223+
})
224+
.then(function() {
225+
expect(getIndices()).toEqual([1]);
226+
return Plotly.restyle(gd, 'visible', true, [0]);
227+
})
228+
.then(function() {
229+
expect(getIndices()).toEqual([0, 1]);
230+
})
231+
.catch(failTest)
200232
.then(done);
201233
});
202234
});

0 commit comments

Comments
 (0)