Skip to content

Commit 7a95090

Browse files
authored
Merge pull request #1466 from plotly/gl3d-ordering
Preserving gl3d trace ordering on restyle
2 parents fb547aa + 27e2a0c commit 7a95090

File tree

6 files changed

+808
-737
lines changed

6 files changed

+808
-737
lines changed

src/plots/gl3d/scene.js

+5
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ proto.plot = function(sceneData, fullLayout, layout) {
419419
delete this.traces[traceIds[i]];
420420
}
421421

422+
// order object per trace index
423+
this.glplot.objects.sort(function(a, b) {
424+
return a._trace.data.index - b._trace.data.index;
425+
});
426+
422427
// Update ranges (needs to be called *after* objects are added due to updates)
423428
var sceneBounds = [[0, 0, 0], [0, 0, 0]],
424429
axisDataRange = [],

src/traces/mesh3d/convert.js

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ function createMesh3DTrace(scene, data) {
152152
var gl = scene.glplot.gl;
153153
var mesh = createMesh({gl: gl});
154154
var result = new Mesh3DTrace(scene, mesh, data.uid);
155+
mesh._trace = result;
155156
result.update(data);
156157
scene.glplot.add(mesh);
157158
return result;

src/traces/scatter3d/convert.js

+5
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ proto.update = function(data) {
314314
if(this.linePlot) this.linePlot.update(lineOptions);
315315
else {
316316
this.linePlot = createLinePlot(lineOptions);
317+
this.linePlot._trace = this;
317318
this.scene.glplot.add(this.linePlot);
318319
}
319320
} else if(this.linePlot) {
@@ -345,6 +346,7 @@ proto.update = function(data) {
345346
if(this.scatterPlot) this.scatterPlot.update(scatterOptions);
346347
else {
347348
this.scatterPlot = createScatterPlot(scatterOptions);
349+
this.scatterPlot._trace = this;
348350
this.scatterPlot.highlightScale = 1;
349351
this.scene.glplot.add(this.scatterPlot);
350352
}
@@ -375,6 +377,7 @@ proto.update = function(data) {
375377
if(this.textMarkers) this.textMarkers.update(textOptions);
376378
else {
377379
this.textMarkers = createScatterPlot(textOptions);
380+
this.textMarkers._trace = this;
378381
this.textMarkers.highlightScale = 1;
379382
this.scene.glplot.add(this.textMarkers);
380383
}
@@ -403,6 +406,7 @@ proto.update = function(data) {
403406
}
404407
} else if(options.errorBounds) {
405408
this.errorBars = createErrorBars(errorOptions);
409+
this.errorBars._trace = this;
406410
this.scene.glplot.add(this.errorBars);
407411
}
408412

@@ -419,6 +423,7 @@ proto.update = function(data) {
419423
} else {
420424
delaunayOptions.gl = gl;
421425
this.delaunayMesh = createMesh(delaunayOptions);
426+
this.delaunayMesh._trace = this;
422427
this.scene.glplot.add(this.delaunayMesh);
423428
}
424429
} else if(this.delaunayMesh) {

src/traces/surface/convert.js

+1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ function createSurfaceTrace(scene, data) {
368368
var gl = scene.glplot.gl;
369369
var surface = createSurface({ gl: gl });
370370
var result = new SurfaceTrace(scene, surface, data.uid);
371+
surface._trace = result;
371372
result.update(data);
372373
scene.glplot.add(surface);
373374
return result;

test/jasmine/tests/gl_plot_interact_basic_test.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ function verifyInteractionEffects(tuple) {
4949
}
5050

5151
function testEvents(plot) {
52-
return plot
53-
.then(function(graphDiv) {
54-
var tuple = addEventCallback(graphDiv); // TODO disuse tuple with ES6
55-
verifyInteractionEffects(tuple);
56-
});
52+
return plot.then(function(graphDiv) {
53+
var tuple = addEventCallback(graphDiv);
54+
verifyInteractionEffects(tuple);
55+
});
5756
}
5857

5958
describe('gl3d plots', function() {
@@ -71,13 +70,13 @@ describe('gl3d plots', function() {
7170

7271
it('should respond to drag interactions with mock of unset camera', function(done) {
7372
testEvents(makePlot(gd, require('@mocks/gl3d_scatter3d-connectgaps.json')))
74-
.then(null, failTest) // current linter balks on .catch with 'dot-notation'; fixme a linter
73+
.catch(failTest)
7574
.then(done);
7675
});
7776

7877
it('should respond to drag interactions with mock of partially set camera', function(done) {
7978
testEvents(makePlot(gd, require('@mocks/gl3d_errorbars_zx.json')))
80-
.then(null, failTest)
79+
.catch(failTest)
8180
.then(done);
8281
});
8382
});

0 commit comments

Comments
 (0)