Skip to content

Commit 18e2d2b

Browse files
committed
sort scattergl objects
- at end of .update step - to preserve order on updates
1 parent f127872 commit 18e2d2b

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/traces/scattergl/convert.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,24 @@ function LineWithMarkers(scene, uid) {
6565
[0, 0, 0, 1],
6666
[0, 0, 0, 1],
6767
[0, 0, 0, 1]],
68-
dashes: [1]
69-
});
68+
dashes: [1],
69+
}, 0);
7070

7171
this.errorX = this.initObject(createError, {
7272
positions: new Float64Array(0),
7373
errors: new Float64Array(0),
7474
lineWidth: 1,
7575
capSize: 0,
7676
color: [0, 0, 0, 1]
77-
});
77+
}, 1);
7878

7979
this.errorY = this.initObject(createError, {
8080
positions: new Float64Array(0),
8181
errors: new Float64Array(0),
8282
lineWidth: 1,
8383
capSize: 0,
8484
color: [0, 0, 0, 1]
85-
});
85+
}, 2);
8686

8787
var scatterOptions0 = {
8888
positions: new Float64Array(0),
@@ -97,24 +97,23 @@ function LineWithMarkers(scene, uid) {
9797
borderColor: [0, 0, 0, 1]
9898
};
9999

100-
this.scatter = this.initObject(createScatter, scatterOptions0);
101-
this.fancyScatter = this.initObject(createFancyScatter, scatterOptions0);
100+
this.scatter = this.initObject(createScatter, scatterOptions0, 3);
101+
this.fancyScatter = this.initObject(createFancyScatter, scatterOptions0, 4);
102102
}
103103

104104
var proto = LineWithMarkers.prototype;
105105

106-
proto.initObject = function(createFn, options) {
106+
proto.initObject = function(createFn, options, index) {
107107
var _this = this;
108108
var glplot = _this.scene.glplot;
109109
var options0 = Lib.extendFlat({}, options);
110110
var obj = null;
111111

112-
// TODO how to handle ordering ???
113-
114112
function update() {
115113
if(!obj) {
116114
obj = createFn(glplot, options);
117115
obj._trace = _this;
116+
obj._index = index;
118117
}
119118
obj.update(options);
120119
return obj;
@@ -254,12 +253,6 @@ function _convertColor(colors, opacities, count) {
254253
return result;
255254
}
256255

257-
/* Order is important here to get the correct laying:
258-
* - lines
259-
* - errorX
260-
* - errorY
261-
* - markers
262-
*/
263256
proto.update = function(options) {
264257

265258
if(options.visible !== true) {
@@ -297,6 +290,15 @@ proto.update = function(options) {
297290
this.updateFast(options);
298291
}
299292

293+
// sort objects so that order is preserve on updates:
294+
// - lines
295+
// - errorX
296+
// - errorY
297+
// - markers
298+
this.scene.glplot.objects.sort(function(a, b) {
299+
return a._index - b._index;
300+
});
301+
300302
// not quite on-par with 'scatter', but close enough for now
301303
// does not handle the colorscale case
302304
this.color = getTraceColor(options, {});

0 commit comments

Comments
 (0)