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

Skip to content

Commit 9b73d70

Browse files
committed
Make proper canvas recycling
1 parent 0454d64 commit 9b73d70

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

src/plot_api/plot_api.js

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,30 @@ Plotly.plot = function(gd, data, layout, config) {
194194
}
195195
}
196196

197-
if(fullLayout._hasCategory('gl') && fullLayout._glcanvas.empty()) {
198-
fullLayout._glcanvas.enter().append('canvas')
199-
.attr('class', function(d) {
200-
return 'gl-canvas gl-canvas-' + d.key.replace('Layer', '');
201-
})
202-
.style('position', 'absolute')
203-
.style('top', 0)
204-
.style('left', 0)
205-
.style('width', '100%')
206-
.style('height', '100%')
207-
.style('pointer-events', 'none')
208-
.style('overflow', 'visible');
209-
}
210-
211-
fullLayout._glcanvas
197+
fullLayout._glcanvas = fullLayout._glcontainer.selectAll('.gl-canvas').data(fullLayout._hasCategory('gl') ? [{
198+
key: 'contextLayer'
199+
}, {
200+
key: 'focusLayer'
201+
}, {
202+
key: 'pickLayer'
203+
}] : []);
204+
205+
fullLayout._glcanvas.enter().append('canvas')
206+
.attr('class', function(d) {
207+
return 'gl-canvas gl-canvas-' + d.key.replace('Layer', '');
208+
})
209+
.style('position', 'absolute')
210+
.style('top', 0)
211+
.style('left', 0)
212+
.style('width', '100%')
213+
.style('height', '100%')
214+
.style('pointer-events', 'none')
215+
.style('overflow', 'visible')
212216
.attr('width', fullLayout.width)
213217
.attr('height', fullLayout.height);
214218

219+
fullLayout._glcanvas.exit().remove();
220+
215221
return Lib.syncOrAsync([
216222
subroutines.layoutStyles
217223
], gd);
@@ -3049,15 +3055,7 @@ function makePlotFramework(gd) {
30493055

30503056
fullLayout._glcontainer.enter().append('div')
30513057
.classed('gl-container', true);
3052-
3053-
fullLayout._glcanvas = fullLayout._glcontainer.selectAll('.gl-canvas')
3054-
.data([{
3055-
key: 'contextLayer'
3056-
}, {
3057-
key: 'focusLayer'
3058-
}, {
3059-
key: 'pickLayer'
3060-
}]);
3058+
fullLayout._glcanvas;
30613059

30623060
fullLayout._paperdiv.selectAll('.main-svg').remove();
30633061

0 commit comments

Comments
 (0)