Skip to content

Commit 5cfc6b1

Browse files
authored
Merge pull request #2801 from plotly/scattergl-select-after-resize-fix
Use updated fullLayout._size in scene.clear
2 parents 32e6984 + 97b8def commit 5cfc6b1

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

src/traces/scattergl/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ function sceneOptions(gd, subplot, trace, positions, x, y) {
188188
// make sure scene exists on subplot, return it
189189
function sceneUpdate(gd, subplot) {
190190
var scene = subplot._scene;
191-
var fullLayout = gd._fullLayout;
192191

193192
var resetOpts = {
194193
// number of traces in subplot, since scene:subplot → 1:1
@@ -290,8 +289,8 @@ function sceneUpdate(gd, subplot) {
290289
scene.dirty = false;
291290
};
292291

293-
// make sure canvas is clear
294292
scene.clear = function clear() {
293+
var fullLayout = gd._fullLayout;
295294
var vpSize = fullLayout._size;
296295
var width = fullLayout.width;
297296
var height = fullLayout.height;

test/jasmine/tests/gl2d_click_test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var click = require('../assets/timed_click');
1717
var hover = require('../assets/hover');
1818
var delay = require('../assets/delay');
1919
var mouseEvent = require('../assets/mouse_event');
20+
var readPixel = require('../assets/read_pixel');
2021

2122
// contourgl is not part of the dist plotly.js bundle initially
2223
Plotly.register([
@@ -901,4 +902,63 @@ describe('@noCI @gl Test gl2d lasso/select:', function() {
901902
.catch(failTest)
902903
.then(done);
903904
});
905+
906+
it('should work after a width/height relayout', function(done) {
907+
gd = createGraphDiv();
908+
909+
var w = 500;
910+
var h = 500;
911+
var w2 = 800;
912+
var h2 = 600;
913+
var pad = 20;
914+
915+
function _read(query) {
916+
var canvas = gd.querySelector(query);
917+
return readPixel(canvas, 0, 0, gd.layout.width, gd.layout.height)
918+
.reduce(function(acc, v) { return acc + v; }, 0);
919+
}
920+
921+
function readContext() { return _read('.gl-canvas-context'); }
922+
923+
function readFocus() { return _read('.gl-canvas-focus'); }
924+
925+
Plotly.plot(gd, [{
926+
type: 'scattergl',
927+
mode: 'markers',
928+
y: [2, 1, 2]
929+
}], {
930+
dragmode: 'select',
931+
margin: {t: 0, b: 0, l: 0, r: 0},
932+
width: w, height: h
933+
})
934+
.then(delay(100))
935+
.then(function() {
936+
expect(readContext()).toBeGreaterThan(1e4, 'base context');
937+
expect(readFocus()).toBe(0, 'base focus');
938+
})
939+
.then(function() { return select([[pad, pad], [w - pad, h - pad]]); })
940+
.then(function() {
941+
expect(readContext()).toBe(0, 'select context');
942+
expect(readFocus()).toBeGreaterThan(1e4, 'select focus');
943+
})
944+
.then(function() {
945+
return Plotly.update(gd,
946+
{selectedpoints: null},
947+
{width: w2, height: h2}
948+
);
949+
})
950+
.then(function() {
951+
expect(readContext()).toBeGreaterThan(1e4, 'update context');
952+
expect(readFocus()).toBe(0, 'update focus');
953+
})
954+
.then(function() { return select([[pad, pad], [w2 - pad, h2 - pad]]); })
955+
.then(function() {
956+
// make sure full w2/h2 context canvas is cleared!
957+
// from https://github.com/plotly/plotly.js/issues/2731<Paste>
958+
expect(readContext()).toBe(0, 'update+select context');
959+
expect(readFocus()).toBeGreaterThan(1e4, 'update+select focus');
960+
})
961+
.catch(failTest)
962+
.then(done);
963+
});
904964
});

0 commit comments

Comments
 (0)