Skip to content

Commit 449dc43

Browse files
committed
fix #2888 - clear scene via gl ref in line2d object
1 parent 4f881fa commit 449dc43

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

src/plots/polar/polar.js

+2
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ proto.updateRadialDrag = function(fullLayout, polarLayout) {
994994
var _module = moduleCalcData[0][0].trace._module;
995995
var polarLayoutNow = gd._fullLayout[_this.id];
996996

997+
if(_this._scene) _this._scene.clear();
997998
_module.plot(gd, _this, moduleCalcDataVisible, polarLayoutNow);
998999

9991000
if(!Registry.traceIs(k, 'gl')) {
@@ -1136,6 +1137,7 @@ proto.updateAngularDrag = function(fullLayout, polarLayout) {
11361137
var moduleCalcData = _this.traceHash[k];
11371138
var moduleCalcDataVisible = Lib.filterVisible(moduleCalcData);
11381139
var _module = moduleCalcData[0][0].trace._module;
1140+
if(_this._scene) _this._scene.clear();
11391141
_module.plot(gd, _this, moduleCalcDataVisible, polarLayoutNow);
11401142
}
11411143
}

src/traces/scattergl/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ function sceneUpdate(gd, subplot) {
302302
}
303303
if(scene.scatter2d) {
304304
clearViewport(scene.scatter2d, vp);
305+
} else if(scene.line2d) {
306+
clearViewport(scene.line2d, vp);
305307
} else if(scene.glText) {
306308
clearViewport(scene.glText[0], vp);
307309
}

src/traces/scatterpolargl/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ function plot(container, subplot, cdata) {
4646
var angularAxis = subplot.angularAxis;
4747

4848
var scene = ScatterGl.sceneUpdate(container, subplot);
49-
scene.clear();
5049

5150
cdata.forEach(function(cdscatter, traceIndex) {
5251
if(!cdscatter || !cdscatter[0] || !cdscatter[0].trace) return;

test/jasmine/tests/polar_test.js

+86
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,92 @@ describe('Test polar interactions:', function() {
10761076
.catch(failTest)
10771077
.then(done);
10781078
});
1079+
1080+
describe('@gl should update scene during drag interactions on radial and angular drag area', function() {
1081+
var objs = ['scatter2d', 'line2d'];
1082+
var scene, gl, nTraces;
1083+
1084+
function _dragRadial() {
1085+
var node = d3.select('.polar > .draglayer > .radialdrag').node();
1086+
var p0 = [375, 200];
1087+
var dp = [-50, 0];
1088+
return drag(node, dp[0], dp[1], null, p0[0], p0[1], 2);
1089+
}
1090+
1091+
function _dragAngular() {
1092+
var node = d3.select('.polar > .draglayer > .angulardrag').node();
1093+
var p0 = [350, 150];
1094+
var dp = [-20, 20];
1095+
return drag(node, dp[0], dp[1], null, p0[0], p0[1]);
1096+
}
1097+
1098+
// once on drag, once on mouseup relayout
1099+
function _assert() {
1100+
expect(gl.clear).toHaveBeenCalledTimes(2);
1101+
gl.clear.calls.reset();
1102+
1103+
objs.forEach(function(o) {
1104+
if(scene[o]) {
1105+
expect(scene[o].draw).toHaveBeenCalledTimes(2 * nTraces);
1106+
scene[o].draw.calls.reset();
1107+
}
1108+
});
1109+
}
1110+
1111+
var specs = [{
1112+
desc: 'scatter marker case',
1113+
// mode: 'markers' by default
1114+
}, {
1115+
desc: 'line case',
1116+
// start with lines to lock down fix for #2888
1117+
patch: function(fig) {
1118+
fig.data.forEach(function(trace) { trace.mode = 'lines'; });
1119+
}
1120+
}, {
1121+
desc: 'line & markers case',
1122+
patch: function(fig) {
1123+
fig.data.forEach(function(trace) { trace.mode = 'markers+lines'; });
1124+
}
1125+
}];
1126+
1127+
specs.forEach(function(s) {
1128+
it('- ' + s.desc, function(done) {
1129+
var fig = Lib.extendDeep({}, require('@mocks/glpolar_scatter.json'));
1130+
scene = null;
1131+
gl = null;
1132+
1133+
fig.layout.hovermode = false;
1134+
fig.layout.width = 400;
1135+
fig.layout.height = 400;
1136+
fig.layout.margin = {l: 50, t: 50, b: 50, r: 50};
1137+
1138+
if(s.patch) s.patch(fig);
1139+
nTraces = fig.data.length;
1140+
1141+
Plotly.newPlot(gd, fig).then(function() {
1142+
scene = gd._fullLayout.polar._subplot._scene;
1143+
1144+
objs.forEach(function(o) {
1145+
if(scene[o]) {
1146+
spyOn(scene[o], 'draw').and.callThrough();
1147+
if(!gl) {
1148+
// all objects have the same _gl ref,
1149+
// spy on it just once
1150+
gl = scene[o].regl._gl;
1151+
spyOn(gl, 'clear').and.callThrough();
1152+
}
1153+
}
1154+
});
1155+
})
1156+
.then(function() { return _dragRadial(); })
1157+
.then(_assert)
1158+
.then(function() { return _dragAngular(); })
1159+
.then(_assert)
1160+
.catch(failTest)
1161+
.then(done);
1162+
});
1163+
});
1164+
});
10791165
});
10801166

10811167
describe('Test polar *gridshape linear* interactions', function() {

0 commit comments

Comments
 (0)