Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 18b9337

Browse files
committed
Fix gl_plot_interact
1 parent 3e826eb commit 18b9337

File tree

4 files changed

+21
-34
lines changed

4 files changed

+21
-34
lines changed

src/plots/cartesian/index.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -145,35 +145,16 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
145145

146146
var hadScatter, hasScatter, i;
147147

148-
// destruct scattergl
149-
var oldSceneKeys = Plots.getSubplotIds(oldFullLayout, 'cartesian');
150-
151-
for(i = 0; i < oldSceneKeys.length; i++) {
152-
var id = oldSceneKeys[i],
153-
oldSubplot = oldFullLayout._plots[id];
154-
155-
// old subplot wasn't gl2d; nothing to do
156-
if(!oldSubplot._scene) continue;
157-
158-
// if no traces are present, delete gl2d subplot
159-
var subplotData = Plots.getSubplotData(newFullData, 'gl', id);
160-
161-
if(subplotData.length === 0) {
162-
oldSubplot._scene.destroy();
163-
delete oldFullLayout._plots[id];
164-
}
165-
}
166-
167148

168149
for(i = 0; i < oldModules.length; i++) {
169-
if(oldModules[i].name === 'scatter') {
150+
if(oldModules[i].name === 'scatter' || oldModules[i].name === 'scattergl') {
170151
hadScatter = true;
171152
break;
172153
}
173154
}
174155

175156
for(i = 0; i < newModules.length; i++) {
176-
if(newModules[i].name === 'scatter') {
157+
if(newModules[i].name === 'scatter' || newModules[i].name === 'scattergl') {
177158
hasScatter = true;
178159
break;
179160
}
@@ -191,6 +172,10 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
191172
.selectAll('g.trace')
192173
.remove();
193174
}
175+
176+
if(subplotInfo._scene) {
177+
subplotInfo._scene.destroy();
178+
}
194179
}
195180

196181
oldFullLayout._infolayer.selectAll('g.rangeslider-container')
@@ -240,7 +225,6 @@ exports.drawFramework = function(gd) {
240225
plotinfo.overlays = [];
241226

242227
makeSubplotLayer(plotinfo);
243-
244228
// fill in list of overlay subplots
245229
if(plotinfo.mainplot) {
246230
var mainplot = fullLayout._plots[plotinfo.mainplot];

src/plots/plots.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,6 @@ plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData, trans
13041304
// Remove all plotly attributes from a div so it can be replotted fresh
13051305
// TODO: these really need to be encapsulated into a much smaller set...
13061306
plots.purge = function(gd) {
1307-
13081307
// note: we DO NOT remove _context because it doesn't change when we insert
13091308
// a new plot, and may have been set outside of our scope.
13101309

@@ -1327,6 +1326,9 @@ plots.purge = function(gd) {
13271326
}
13281327
}
13291328

1329+
// remove any planned throttles
1330+
Lib.clearThrottle();
1331+
13301332
// data and layout
13311333
delete gd.data;
13321334
delete gd.layout;

src/traces/scattergl/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ ScatterRegl.calc = function calc(container, trace) {
5454

5555
// FIXME: is it the best way to obtain subplot object from trace
5656
var subplot = layout._plots[trace.xaxis + trace.yaxis];
57-
5857
// makeCalcdata runs d2c (data-to-coordinate) on every point
5958
var x = xaxis.type === 'linear' ? trace.x : xaxis.makeCalcdata(trace, 'x');
6059
var y = yaxis.type === 'linear' ? trace.y : yaxis.makeCalcdata(trace, 'y');
@@ -513,6 +512,8 @@ ScatterRegl.calc = function calc(container, trace) {
513512
scene.markerOptions = null;
514513
scene.errorXOptions = null;
515514
scene.errorYOptions = null;
515+
516+
delete subplot._scene;
516517
};
517518

518519
// highlight selected points

test/jasmine/tests/gl_plot_interact_test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,6 @@ describe('Test gl2d plots', function() {
10711071

10721072
it('should change plot type with incomplete data', function(done) {
10731073
Plotly.plot(gd, [{}]);
1074-
10751074
expect(function() {
10761075
Plotly.restyle(gd, {type: 'scattergl', x: [[1]]}, 0);
10771076
}).not.toThrow();
@@ -1120,7 +1119,7 @@ describe('Test removal of gl contexts', function() {
11201119

11211120
Plots.cleanPlot([], {}, gd._fullData, gd._fullLayout);
11221121

1123-
expect(gd._fullLayout._plots).toEqual({});
1122+
expect(gd._fullLayout._plots.xy._scene).toBeUndefined();
11241123
})
11251124
.then(done);
11261125
});
@@ -1169,7 +1168,7 @@ describe('Test removal of gl contexts', function() {
11691168
.then(done);
11701169
});
11711170

1172-
fit('Plotly.newPlot should remove gl context from the graph div of a gl2d plot', function(done) {
1171+
it('Plotly.newPlot should remove gl context from the graph div of a gl2d plot', function(done) {
11731172
var firstGlplotObject, firstGlContext, firstCanvas;
11741173

11751174
Plotly.plot(gd, [{
@@ -1178,8 +1177,8 @@ describe('Test removal of gl contexts', function() {
11781177
y: [2, 1, 3]
11791178
}])
11801179
.then(function() {
1181-
firstGlplotObject = gd._fullLayout._plots.xy._scene2d.glplot;
1182-
firstGlContext = firstGlplotObject.gl;
1180+
firstGlplotObject = gd._fullLayout._plots.xy._scene;
1181+
firstGlContext = firstGlplotObject.scatter2d.gl;
11831182
firstCanvas = firstGlContext.canvas;
11841183

11851184
expect(firstGlplotObject).toBeDefined();
@@ -1193,8 +1192,8 @@ describe('Test removal of gl contexts', function() {
11931192
}], {});
11941193
})
11951194
.then(function() {
1196-
var secondGlplotObject = gd._fullLayout._plots.xy._scene2d.glplot;
1197-
var secondGlContext = secondGlplotObject.gl;
1195+
var secondGlplotObject = gd._fullLayout._plots.xy._scene;
1196+
var secondGlContext = secondGlplotObject.scatter2d.gl;
11981197
var secondCanvas = secondGlContext.canvas;
11991198

12001199
expect(Object.keys(gd._fullLayout._plots).length === 1);
@@ -1276,7 +1275,8 @@ describe('Test gl plot side effects', function() {
12761275

12771276
return Plotly.deleteTraces(gd, [0]);
12781277
}).then(function() {
1279-
countCanvases(0);
1278+
// deleteTraces should not delete canvases since we may reuse them
1279+
countCanvases(3);
12801280

12811281
return Plotly.purge(gd);
12821282
}).then(done);
@@ -1324,10 +1324,10 @@ describe('Test gl2d interactions', function() {
13241324
dragmode: 'pan'
13251325
})
13261326
.then(function() {
1327-
assertAnnotation([327, 315]);
1327+
assertAnnotation([327, 312]);
13281328

13291329
drag([250, 200], [200, 150]);
1330-
assertAnnotation([277, 265]);
1330+
assertAnnotation([277, 262]);
13311331

13321332
return Plotly.relayout(gd, {
13331333
'xaxis.range': [1.5, 2.5],

0 commit comments

Comments
 (0)