From 8f7bedae00db1f059c193a0e1758f1cd1fc72ff9 Mon Sep 17 00:00:00 2001 From: Dominik Date: Fri, 4 Dec 2026 00:24:52 -0800 Subject: [PATCH 1/7] Pin gl-plot3d, gl-select-static, and gl-scatter3d to the pick pass branches The scene drew its pick buffer in each frame that moved the camera. The new gl-plot3d draws the buffer when a pointer event queries it, and draws none if no object permits a pick. stackgl_modules/index.js is the webpack output of the pinned commits. The pins go away when the gl-vis pull requests merge and release. --- stackgl_modules/index.js | 129 ++++++++++++++++++++++++++++-- stackgl_modules/package-lock.json | 16 ++-- stackgl_modules/package.json | 5 +- 3 files changed, 135 insertions(+), 15 deletions(-) diff --git a/stackgl_modules/index.js b/stackgl_modules/index.js index b812d41f949..45cc7a132f3 100644 --- a/stackgl_modules/index.js +++ b/stackgl_modules/index.js @@ -18881,6 +18881,14 @@ function createScene(options) { mouseListener: null, _stopped: false, + // The pick pass. 'lazy': drawn when a pointer event queries it, or pickIdleDelay ms after the last + // frame that changed it (0: never ahead of the query). 'eager': drawn in every frame that changed it (upstream). + pickMode: options.pickMode || 'lazy', + pickIdleDelay: options.pickIdleDelay === undefined ? 120 : options.pickIdleDelay, + // Query the pick buffers only when the main button goes down (hover is off): pointer moves draw nothing + pickOnPress: false, + pickStats: {draws: 0}, + getAspectratio: function() { return { x: this.aspect[0], @@ -19037,6 +19045,10 @@ function createScene(options) { } scene._stopped = true + if(pickTimer) { + clearTimeout(pickTimer) + pickTimer = null + } window.removeEventListener('resize', resizeListener) canvas.removeEventListener('webglcontextlost', checkContextLoss) @@ -19101,7 +19113,12 @@ function createScene(options) { } scene._mouseRotating = false - for(var i=0; i selection.distance) { @@ -19129,17 +19146,27 @@ function createScene(options) { } } + // A hover that changes nothing in the picture needs no frame: the axis spikes are off and the + // hovered cloud is not drawn larger (highlightScale 1, as plotly sets it). The render callback alone + // then gives the hover label and events, as it does from the frame. + var e = spikes.enabled + var still = !e[0] && !e[1] && !e[2] && !!scene.onrender && pickFrameSeen && + (!prevObj || prevObj.highlightScale === 1) && + (!selection.object || selection.object.highlightScale === 1) if(prevObj && prevObj !== selection.object) { if(prevObj.highlight) { prevObj.highlight(null) } - dirty = true + dirty = dirty || !still } if(selection.object) { if(selection.object.highlight) { selection.object.highlight(selection.data) } - dirty = true + dirty = dirty || !still + } + if(still && !dirty && (prevObj || selection.object)) { + scene.onrender() } change = change || (selection.object !== prevObj) @@ -19170,12 +19197,78 @@ function createScene(options) { canvas.addEventListener('webglcontextlost', checkContextLoss) + var pickTimer = null + var pickFrameSeen = false + var pickEmpty = false + + // True if some object that is drawn into a pick buffer can be picked + function anyPickable() { + for(var i=0; i= 0 && objects[i].drawPick && !objects[i].noPick) { + return true + } + } + return false + } + + // Draw the pick buffers and read them back now, if they are out of date + function ensurePick() { + if(pickTimer) { + clearTimeout(pickTimer) + pickTimer = null + } + if(!pickDirty || !pickFrameSeen || scene._stopped || scene.contextLost) { + return + } + pickDirty = false + renderPick() + // the pick pass draws at pixel ratio 1; objects read their own ratio when a query follows (mesh pick) + for(var i=0; i 0) || scene.pickOnPress) { + return + } + pickTimer = setTimeout(function() { + pickTimer = null + if(scene._prevButtons) { + // nothing is queried while a button is held: look again later + schedulePick() + } else { + ensurePick() + } + }, scene.pickIdleDelay) + } + //Render the scene for mouse picking function renderPick() { if(checkContextLoss()) { return } + // Nothing can be picked (every trace has hoverinfo 'skip'): no pass, and no query reads the buffers + pickEmpty = !anyPickable() + if(pickEmpty) { + return + } + + scene.pickStats.draws++ + gl.colorMask(true, true, true, true) gl.depthMask(true) gl.disable(gl.BLEND) @@ -19340,9 +19433,15 @@ function createScene(options) { } //If state changed, then redraw pick buffers + pickFrameSeen = true if(pickDirty) { - pickDirty = false - renderPick() + if(scene.pickMode === 'lazy') { + // Not in this frame: a pointer event that queries the buffer draws it, or the idle timer does + schedulePick() + } else { + pickDirty = false + renderPick() + } } //Recalculate pixel data @@ -20169,6 +20268,11 @@ proto.pick = function(selected) { if(selected.id !== this.pickId) { return null } + // A cloud that is never picked gives no hit. Nor does one with more points than the 24 bits of the point index + // in the pick buffer can tell apart (the last value means none): its ids would name other points + if(this.noPick || this.pointCount > 16777215) { + return null + } var x = selected.value[2] + (selected.value[1]<<8) + (selected.value[0]<<16) if(x >= this.pointCount || x < 0) { return null @@ -20311,6 +20415,9 @@ proto.update = function(options) { //Set dirty flag this.dirty = true + // A cloud that is never picked (hoverinfo 'skip'). The scene draws no pick pass when no object can be picked. + if('pick' in options) this.noPick = options.pick === false + //Create new buffers var points = options.position @@ -20870,6 +20977,18 @@ proto.query = function(x, y, radius) { Math.sqrt(closest[2])) } +// Read the buffer back now (a pick pass drawn on demand is queried at once) +proto.sync = function() { + if(!this.gl) { + return + } + if(this._readTimeout) { + clearTimeout(this._readTimeout) + } + this._readCallback() + this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null) +} + proto.dispose = function() { if(!this.gl) { return diff --git a/stackgl_modules/package-lock.json b/stackgl_modules/package-lock.json index 0961819ddab..e250c874603 100644 --- a/stackgl_modules/package-lock.json +++ b/stackgl_modules/package-lock.json @@ -16,8 +16,8 @@ "gl-error3d": "^1.0.17", "gl-line3d": "^1.2.2", "gl-mesh3d": "^2.3.2", - "gl-plot3d": "^2.4.7", - "gl-scatter3d": "^1.4.1", + "gl-plot3d": "github:settylab/gl-plot3d#af538fec50f8e212bde2cdfbfcf733bad5d7c771", + "gl-scatter3d": "github:settylab/gl-scatter3d#370d619a7ec1351f87989c9963a37cd4ccb06e5b", "gl-shader": "4.3.1", "gl-spikes3d": "^1.0.11", "gl-streamtube3d": "^1.4.2", @@ -1312,8 +1312,8 @@ }, "node_modules/gl-plot3d": { "version": "2.4.7", - "resolved": "https://registry.npmjs.org/gl-plot3d/-/gl-plot3d-2.4.7.tgz", - "integrity": "sha512-mLDVWrl4Dj0O0druWyHUK5l7cBQrRIJRn2oROEgrRuOgbbrLAzsREKefwMO0bA0YqkiZMFMnV5VvPA9j57X5Xg==", + "resolved": "git+ssh://git@github.com/settylab/gl-plot3d.git#af538fec50f8e212bde2cdfbfcf733bad5d7c771", + "integrity": "sha512-ilgUga590Ge94vR4MMFtq/NWjoTB99XrXnuyNCXFLPcLixAM3gHNMlN2ktcF19dlYKXtQNMA19xCLpkB/BSJXA==", "license": "MIT", "dependencies": { "3d-view": "^2.0.0", @@ -1347,8 +1347,8 @@ }, "node_modules/gl-scatter3d": { "version": "1.4.1", - "resolved": "https://registry.npmjs.org/gl-scatter3d/-/gl-scatter3d-1.4.1.tgz", - "integrity": "sha512-v2nQWSPr9/smu2YB4erhHuUkk+8w2q59CsTPvcK72vFYWCSgU6eeTnu0UlmN634bblbTTa5ap/xrbxJGiKLyrw==", + "resolved": "git+ssh://git@github.com/settylab/gl-scatter3d.git#370d619a7ec1351f87989c9963a37cd4ccb06e5b", + "integrity": "sha512-kyGOqNcQPAiKtDbKqVYRkPFkGsCiMTL7NR3cWqC1f/CsVqWFnCBC3TyHhlMdm1c/m6Ls/naxpysYdv6Jcw/hhw==", "license": "MIT", "dependencies": { "gl-buffer": "^2.1.2", @@ -1364,8 +1364,8 @@ }, "node_modules/gl-select-static": { "version": "2.0.7", - "resolved": "https://registry.npmjs.org/gl-select-static/-/gl-select-static-2.0.7.tgz", - "integrity": "sha512-OvpYprd+ngl3liEatBTdXhSyNBjwvjMSvV2rN0KHpTU+BTi4viEETXNZXFgGXY37qARs0L28ybk3UQEW6C5Nnw==", + "resolved": "git+ssh://git@github.com/settylab/gl-select-static.git#4375784bfd498a0de58a766f4518840df183a99d", + "integrity": "sha512-+qsKdpPCUp8TpeqgqE32Eqd22U5pp9nbTikXePGWQYlapQ9oB9EU6RkxIzw3J0hugpOZ+KE4djSCIN+A7BC3Gg==", "license": "MIT", "dependencies": { "bit-twiddle": "^1.0.2", diff --git a/stackgl_modules/package.json b/stackgl_modules/package.json index a145e05bf6b..0acffbece66 100644 --- a/stackgl_modules/package.json +++ b/stackgl_modules/package.json @@ -19,8 +19,8 @@ "gl-error3d": "^1.0.17", "gl-line3d": "^1.2.2", "gl-mesh3d": "^2.3.2", - "gl-plot3d": "^2.4.7", - "gl-scatter3d": "^1.4.1", + "gl-plot3d": "github:settylab/gl-plot3d#af538fec50f8e212bde2cdfbfcf733bad5d7c771", + "gl-scatter3d": "github:settylab/gl-scatter3d#370d619a7ec1351f87989c9963a37cd4ccb06e5b", "gl-shader": "4.3.1", "gl-spikes3d": "^1.0.11", "gl-streamtube3d": "^1.4.2", @@ -52,6 +52,7 @@ "webpack-cli": "7.2.3" }, "overrides": { + "gl-select-static": "github:settylab/gl-select-static#4375784bfd498a0de58a766f4518840df183a99d", "is-mobile": "^5.0.0", "to-px": "1.0.1" } From 4f93087425c4679110ff31baa5b5c8ef2d6464b0 Mon Sep 17 00:00:00 2001 From: Dominik Date: Fri, 4 Dec 2026 00:24:52 -0800 Subject: [PATCH 2/7] Draw the gl3d pick pass on demand, and none for scenes without hover A scatter3d trace with hoverinfo skip tells the scene that no pointer event can select it. A scene with hovermode false queries the pick buffer only on a button press and emits no hover events. A trace with more points than the 24 bits of a pick id gets no hover and no click, because its ids name other points. --- draftlogs/XXXX_change.md | 1 + draftlogs/XXXX_fix.md | 1 + src/plots/gl3d/scene.js | 10 +- src/traces/scatter3d/convert.js | 25 ++ test/jasmine/tests/gl3d_hover_click_test.js | 341 ++++++++++++++++++++ 5 files changed, 376 insertions(+), 2 deletions(-) create mode 100644 draftlogs/XXXX_change.md create mode 100644 draftlogs/XXXX_fix.md diff --git a/draftlogs/XXXX_change.md b/draftlogs/XXXX_change.md new file mode 100644 index 00000000000..675efb90412 --- /dev/null +++ b/draftlogs/XXXX_change.md @@ -0,0 +1 @@ +- Draw the gl3d pick pass when a pointer event needs it instead of in every frame that moves the camera, skip it when no trace of the scene can be picked, draw no frame for a hover that changes nothing in the picture, and make `scene.hovermode: false` pick only on a button press without emitting hover events [[#XXXX](https://github.com/plotly/plotly.js/pull/XXXX)] diff --git a/draftlogs/XXXX_fix.md b/draftlogs/XXXX_fix.md new file mode 100644 index 00000000000..24e45e3c675 --- /dev/null +++ b/draftlogs/XXXX_fix.md @@ -0,0 +1 @@ +- Fix hover and click on `scatter3d` traces with more than 16,777,215 points naming other points: such a trace is drawn but not picked, with a console warning [[#XXXX](https://github.com/plotly/plotly.js/pull/XXXX)] diff --git a/src/plots/gl3d/scene.js b/src/plots/gl3d/scene.js index e320fe9e780..1f01726f181 100644 --- a/src/plots/gl3d/scene.js +++ b/src/plots/gl3d/scene.js @@ -99,6 +99,8 @@ proto.prepareOptions = function() { axes: scene.axesOptions, spikes: scene.spikeOptions, pickRadius: 10, + // Nothing queries a static scene, so no pick pass runs before a query + pickIdleDelay: scene.staticMode ? 0 : 120, snapToData: true, autoScale: true, autoBounds: false, @@ -456,13 +458,14 @@ proto.render = function() { pointData.bbox = bbox[0]; } + const hoverOn = !!scene.fullSceneLayout.hovermode; if(selection.distance < 5 && (selection.buttons || tabletmode)) { gd.emit('plotly_click', eventData); - } else { + } else if(hoverOn) { gd.emit('plotly_hover', eventData); } - this.oldEventData = eventData; + this.oldEventData = hoverOn ? eventData : undefined; } else { Fx.loneUnhover(svgContainer); if(this.oldEventData) gd.emit('plotly_unhover', this.oldEventData); @@ -1054,6 +1057,9 @@ proto.updateFx = function(dragmode, hovermode) { // to put dragmode and hovermode on the same grounds from relayout scene.fullSceneLayout.hovermode = hovermode; + + // Without hover, only a button press queries the pick buffer, for plotly_click + if (scene.glplot) scene.glplot.pickOnPress = !hovermode; }; function flipPixels(pixels, w, h) { diff --git a/src/traces/scatter3d/convert.js b/src/traces/scatter3d/convert.js index 019d362e5fe..9e14fdd36f4 100644 --- a/src/traces/scatter3d/convert.js +++ b/src/traces/scatter3d/convert.js @@ -186,6 +186,27 @@ function formatParam(paramIn, len, calculate, dflt, extraFn) { return paramOut; } +/** + * Tell if hover and click can never select a point of the trace. + * + * The pick buffer holds 24 bits of the point index. The ids of a longer trace + * name other points, so such a trace gets no hover and no click. The function logs a warning for it. + * + * @param data - the full trace + * @param len - the number of points + * @returns true for `hoverinfo: 'skip'` and for a trace above `maxPickPoints` + */ +function neverPicked(data, len) { + if (data.hoverinfo === 'skip') return true; + const max = createLineWithMarkers.maxPickPoints; + if (len <= max) return false; + Lib.warn( + `scatter3d trace ${data.index} has ${len} points. Hover and click cannot tell more than ${max} apart, ` + + 'so the trace gets neither. Split the trace, or set hoverinfo to *skip*.' + ); + return true; +} + function convertPlotlyOptions(scene, data) { var points = []; var sceneLayout = scene.fullSceneLayout; @@ -421,6 +442,7 @@ proto.update = function (data) { glyph: options.scatterMarker, opacity: scatterOpacity, orthographic: true, + pick: !neverPicked(data, (data.x || []).length), lineWidth: options.scatterLineWidth, lineColor: options.scatterLineColor, project: options.project, @@ -547,4 +569,7 @@ function createLineWithMarkers(scene, data) { return plot; } +// The pick ids of one trace: 0 to 2^24 - 2. The last value means no point. +createLineWithMarkers.maxPickPoints = 16777215; + module.exports = createLineWithMarkers; diff --git a/test/jasmine/tests/gl3d_hover_click_test.js b/test/jasmine/tests/gl3d_hover_click_test.js index 1499eebbf5d..5b5d41d43e1 100644 --- a/test/jasmine/tests/gl3d_hover_click_test.js +++ b/test/jasmine/tests/gl3d_hover_click_test.js @@ -1503,3 +1503,344 @@ describe('hover on traces with (x|y|z|u|v|w)hoverformat and valuehoverformat', f }); }); }); + +function f32(n, seed) { + var a = new Float32Array(n); + var s = seed; + for(var i = 0; i < n; i++) { + s = (s * 1664525 + 1013904223) >>> 0; + a[i] = s / 4294967296; + } + return a; +} + +function cloud(n, extra, seed) { + seed = seed || 0; + var t = {type: 'scatter3d', mode: 'markers', x: f32(n, 1 + seed), y: f32(n, 2 + seed), z: f32(n, 3 + seed), + marker: {size: 10, color: 'blue', line: {width: 0}}}; + for(var k in extra) t[k] = extra[k]; + return t; +} + +var PICK_LAYOUT = {width: 600, height: 400, margin: {l: 0, r: 0, t: 0, b: 0}, showlegend: false, + scene: {camera: {eye: {x: 1.4, y: 1.2, z: 0.9}, projection: {type: 'orthographic'}}}}; +var EYE2 = {x: 0.9, y: 1.6, z: 0.8}; + +describe('Test gl3d pick pass:', function() { + var gd; + + beforeEach(function() { gd = createGraphDiv(); }); + afterEach(function() { + Plotly.purge(gd); + destroyGraphDiv(); + }); + + function glplot() { return gd._fullLayout.scene._scene.glplot; } + function draws() { return glplot().pickStats.draws; } + function layout() { return JSON.parse(JSON.stringify(PICK_LAYOUT)); } + // the points of the hover events of pointer moves over the cloud + function hoverTrail() { + var out = []; + gd.on('plotly_hover', function(e) { + // every frame with a hovered point emits the event again: keep the changes + var p = e.points[0].curveNumber + ':' + e.points[0].pointNumber; + if(out[out.length - 1] !== p) out.push(p); + }); + return out; + } + function moves(list) { + var p = Promise.resolve(); + list.forEach(function(xy) { + p = p.then(function() { mouseEvent('mousemove', xy[0], xy[1]); }).then(delay(60)); + }); + return p; + } + var PATH = [[300, 200], [280, 190], [320, 215], [305, 230]]; + + it('@gl draws no pick pass in the frames of a camera change; the first pointer query draws one', function(done) { + var n0; + Plotly.newPlot(gd, [cloud(3000)], layout()) + .then(delay(100)) + .then(function() { + glplot().pickIdleDelay = 0; + mouseEvent('mousemove', 300, 200); + n0 = draws(); + return Plotly.relayout(gd, 'scene.camera.eye', EYE2); + }) + .then(delay(150)) + .then(function() { + expect(draws()).toBe(n0, 'no pass in the frames after the camera change'); + mouseEvent('mousemove', 310, 205); + expect(draws()).toBe(n0 + 1, 'the pointer query draws it'); + mouseEvent('mousemove', 320, 210); + mouseEvent('mousemove', 290, 190); + expect(draws()).toBe(n0 + 1, 'later queries read the same buffer'); + }) + .then(done, done.fail); + }); + + it('@gl draws the pick pass once the scene has been at rest for pickIdleDelay', function(done) { + var n0; + Plotly.newPlot(gd, [cloud(3000)], layout()) + .then(delay(900)) + .then(function() { + expect(glplot().pickIdleDelay).toBe(120); + n0 = draws(); + expect(n0).toBeGreaterThan(0); + return Plotly.relayout(gd, 'scene.camera.eye', EYE2); + }) + .then(delay(900)) + .then(function() { + expect(draws()).toBe(n0 + 1); + mouseEvent('mousemove', 310, 205); + expect(draws()).toBe(n0 + 1); + }) + .then(done, done.fail); + }); + + it('@gl draws no pick pass during a drag', function(done) { + var n0; + Plotly.newPlot(gd, [cloud(3000)], layout()) + .then(delay(300)) + .then(function() { + mouseEvent('mousemove', 300, 200); + n0 = draws(); + mouseEvent('mousedown', 300, 200, {buttons: 1}); + }) + .then(delay(30)) + .then(function() { mouseEvent('mousemove', 320, 205, {buttons: 1}); }) + .then(delay(200)) + .then(function() { mouseEvent('mousemove', 340, 210, {buttons: 1}); }) + .then(delay(200)) + .then(function() { + expect(draws()).toBe(n0, 'none while the button is held, also past the idle delay'); + mouseEvent('mouseup', 340, 210); + expect(draws()).toBe(n0 + 1, 'the release queries the buffer'); + }) + .then(done, done.fail); + }); + + it('@gl gives the hover points of the eager pick pass after a camera change', function(done) { + var lazy, eager; + Plotly.newPlot(gd, [cloud(3000), cloud(3000, {marker: {size: 10, color: 'red', line: {width: 0}}}, 7)], layout()) + .then(delay(700)) + .then(function() { + glplot().pickIdleDelay = 0; + lazy = hoverTrail(); + return Plotly.relayout(gd, 'scene.camera.eye', EYE2); + }) + .then(delay(700)) + .then(function() { return moves(PATH); }) + .then(function() { + return Plotly.newPlot(gd, [cloud(3000), cloud(3000, {marker: {size: 10, color: 'red', line: {width: 0}}}, 7)], layout()); + }) + .then(delay(700)) + .then(function() { + glplot().pickMode = 'eager'; + eager = hoverTrail(); + return Plotly.relayout(gd, 'scene.camera.eye', EYE2); + }) + .then(delay(700)) + .then(function() { return moves(PATH); }) + .then(function() { + expect(lazy.length).toBeGreaterThan(1); + expect(lazy).toEqual(eager); + }) + .then(done, done.fail); + }); + + it('@gl draws no pick pass when every trace has hoverinfo skip', function(done) { + var trail; + Plotly.newPlot(gd, [cloud(3000, {hoverinfo: 'skip'}), cloud(3000, {hoverinfo: 'skip'}, 7)], layout()) + .then(delay(900)) + .then(function() { + trail = hoverTrail(); + expect(draws()).toBe(0); + return Plotly.relayout(gd, 'scene.camera.eye', EYE2); + }) + .then(delay(700)) + .then(function() { return moves(PATH); }) + .then(function() { + expect(draws()).toBe(0); + expect(trail.length).toBe(0); + // a pickable trace brings the pass back + return Plotly.restyle(gd, {hoverinfo: 'all'}, [1]); + }) + .then(delay(300)) + .then(function() { return moves(PATH); }) + .then(function() { + expect(draws()).toBeGreaterThan(0); + expect(trail.length).toBeGreaterThan(0); + trail.forEach(function(p) { expect(p.charAt(0)).toBe('1'); }); + }) + .then(done, done.fail); + }); + + it('@gl a skip trace in a mixed scene is still drawn into the pick buffer and hides the points behind it', function(done) { + // a wall of skip points in front of a pickable wall, seen along x + function wall(xv, extra) { + var t = cloud(4000, extra); + for(var i = 0; i < 4000; i++) t.x[i] = xv; + t.marker.size = 14; + return t; + } + var L = layout(); + L.scene.camera.eye = {x: 2, y: 0, z: 0}; + var trail; + Plotly.newPlot(gd, [wall(0), wall(1, {hoverinfo: 'skip'})], L) + .then(delay(900)) + .then(function() { + trail = hoverTrail(); + return moves(PATH); + }) + .then(function() { + expect(draws()).toBe(1); + expect(trail.length).toBe(0); + }) + .then(done, done.fail); + }); + + it('@gl hovermode false picks only when the button goes down: no hover events, plotly_click works', function(done) { + var ev = []; + var L = layout(); + L.scene.hovermode = false; + Plotly.newPlot(gd, [cloud(3000)], L) + .then(delay(900)) + .then(function() { + ['plotly_hover', 'plotly_unhover', 'plotly_click'].forEach(function(n) { + gd.on(n, function(e) { ev.push(n.slice(7) + (e && e.points ? ':' + e.points[0].pointNumber : '')); }); + }); + expect(glplot().pickOnPress).toBe(true); + expect(draws()).toBe(0, 'no pass ahead of a query'); + return moves(PATH); + }) + .then(function() { + expect(draws()).toBe(0, 'pointer moves query nothing'); + expect(ev).toEqual([]); + mouseEvent('mousedown', 300, 200, {buttons: 1}); + }) + .then(delay(100)) + .then(function() { + expect(draws()).toBe(1); + expect(ev.length).toBeGreaterThan(0); + ev.forEach(function(e) { expect(e.slice(0, 6)).toBe('click:'); }); + mouseEvent('mouseup', 300, 200); + }) + .then(delay(100)) + .then(function() { + ev.length = 0; + return Plotly.relayout(gd, 'scene.hovermode', 'closest'); + }) + .then(function() { + expect(glplot().pickOnPress).toBe(false); + return moves(PATH); + }) + .then(function() { + expect(ev.filter(function(e) { return e.slice(0, 6) === 'hover:'; }).length).toBeGreaterThan(0); + }) + .then(done, done.fail); + }); + + it('@gl a hover move draws no frame when the axis spikes are off, and gives the same events', function(done) { + function run(spikes) { + var L = layout(); + ['xaxis', 'yaxis', 'zaxis'].forEach(function(a) { L.scene[a] = {showspikes: spikes}; }); + var ev = []; + var frames = 0; + return Plotly.newPlot(gd, [cloud(3000)], L) + .then(delay(900)) + .then(function() { + var o = glplot().objects[0]; + var draw = o.draw; + o.draw = function() { + frames++; + return draw.apply(this, arguments); + }; + gd.on('plotly_hover', function(e) { ev.push('hover:' + e.points[0].pointNumber); }); + gd.on('plotly_unhover', function() { ev.push('unhover'); }); + gd.on('plotly_click', function(e) { ev.push('click:' + e.points[0].pointNumber); }); + return moves(PATH); + }) + .then(function() { mouseEvent('mousedown', 305, 230, {buttons: 1}); }) + .then(delay(60)) + .then(function() { mouseEvent('mouseup', 305, 230); }) + .then(delay(60)) + .then(function() { return moves([[5, 5]]); }) + .then(function() { + expect(document.querySelectorAll('g.hovertext').length).toBe(0); + return {ev: ev, frames: frames}; + }); + } + var off; + run(false) + .then(function(r) { + off = r; + expect(r.frames).toBe(0, 'no frame for the hover moves, the click and the unhover'); + expect(r.ev.length).toBeGreaterThan(PATH.length); + expect(r.ev[r.ev.length - 1]).toBe('unhover'); + return run(true); + }) + .then(function(on) { + expect(on.frames).toBeGreaterThan(PATH.length - 1, 'with spikes every hover move draws a frame'); + expect(off.ev).toEqual(on.ev); + }) + .then(done, done.fail); + }); + + it('@gl a trace with more points than a pick id can tell apart is drawn but never picked, and says so', function(done) { + var convert = require('../../../src/traces/scatter3d/convert'); + var max = convert.maxPickPoints; + expect(max).toBe(16777215); + convert.maxPickPoints = 2000; + spyOn(Lib, 'warn'); + var trail; + Plotly.newPlot(gd, [cloud(3000)], layout()) + .then(delay(900)) + .then(function() { + var o = glplot().objects[0]; + expect(Lib.warn).toHaveBeenCalled(); + expect(Lib.warn.calls.argsFor(0)[0]).toMatch(/3000 points/); + expect(o.pointCount).toBe(3000); + expect(o.noPick).toBe(true); + trail = hoverTrail(); + return moves(PATH); + }) + .then(function() { + expect(trail.length).toBe(0); + expect(draws()).toBe(0); + Lib.warn.calls.reset(); + return Plotly.newPlot(gd, [cloud(2000)], layout()); + }) + .then(delay(900)) + .then(function() { + expect(Lib.warn).not.toHaveBeenCalled(); + trail = hoverTrail(); + return moves(PATH); + }) + .then(function() { + expect(trail.length).toBeGreaterThan(0); + // gl-scatter3d itself gives no hit for a cloud above 2^24 - 1 points + var o = glplot().objects[0]; + var n = o.pointCount; + expect(o.pick({id: o.pickId, value: [0, 0, 7]})).not.toBe(null); + o.pointCount = 16777216; + expect(o.pick({id: o.pickId, value: [0, 0, 7]})).toBe(null); + o.pointCount = n; + }) + .then(function() { convert.maxPickPoints = max; }, function(e) { + convert.maxPickPoints = max; + throw e; + }) + .then(done, done.fail); + }); + + it('@gl a purge with a pending idle timer does not throw', function(done) { + Plotly.newPlot(gd, [cloud(3000)], layout()) + .then(delay(50)) + .then(function() { return Plotly.relayout(gd, 'scene.camera.eye', EYE2); }) + .then(delay(30)) + .then(function() { Plotly.purge(gd); }) + .then(delay(300)) + .then(done, done.fail); + }); +}); From 85178c4d7fde3f27ab7b86d0e382898a8a78628e Mon Sep 17 00:00:00 2001 From: Dominik Date: Sat, 5 Dec 2026 01:08:42 -0800 Subject: [PATCH 3/7] Wait for the scene frame in the pick specs, and test a pointer event before the first frame of a trace Two specs compare a run whose hover events come from the frame with a run whose events come from the pointer handler. They waited 60 ms after each pointer event, and on a slow runner the frame came later, so the frame run lost its last events. They now wait for the frame. The new spec sends a pointer event in the task in which newPlot resolves. It needs the gl-plot3d commit that draws no pick pass on demand before the frame that draws a change. The pin of that commit follows. --- test/jasmine/tests/gl3d_hover_click_test.js | 40 ++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/test/jasmine/tests/gl3d_hover_click_test.js b/test/jasmine/tests/gl3d_hover_click_test.js index 5b5d41d43e1..7311610305c 100644 --- a/test/jasmine/tests/gl3d_hover_click_test.js +++ b/test/jasmine/tests/gl3d_hover_click_test.js @@ -1548,10 +1548,21 @@ describe('Test gl3d pick pass:', function() { }); return out; } + // Wait for the frame of the scene that follows a pointer event. With the pick pass in each frame, or with + // the axis spikes on, the hover events come from that frame, and a frame can take longer than a fixed delay. + const frame = () => + new Promise((resolve) => { + requestAnimationFrame(() => requestAnimationFrame(() => setTimeout(resolve, 0))); + }); function moves(list) { var p = Promise.resolve(); list.forEach(function(xy) { - p = p.then(function() { mouseEvent('mousemove', xy[0], xy[1]); }).then(delay(60)); + p = p + .then(() => { + mouseEvent('mousemove', xy[0], xy[1]); + }) + .then(delay(60)) + .then(frame); }); return p; } @@ -1741,6 +1752,31 @@ describe('Test gl3d pick pass:', function() { .then(done, done.fail); }); + it('@gl gives no hover for a trace before the frame that draws it', function(done) { + // A pointer that rests on a scene sends an event when the canvas appears, before the first frame with the trace. + // The pick pass on demand must find nothing then, as the pick pass in the frame did. + const labels = () => document.querySelectorAll('g.hovertext').length; + Plotly.newPlot(gd, Lib.extendDeep({}, mesh3dcoloringMock)) + .then(() => { + mouseEvent('mousemove', 600, 200); + }) + .then(frame) + .then(() => { + expect(labels()).toBe(0, 'no label for a mesh that no frame drew'); + }) + .then(delay(300)) + .then(() => { + expect(labels()).toBe(0, 'and none later without a pointer event'); + mouseEvent('mousemove', 601, 201); + }) + .then(delay(20)) + .then(frame) + .then(() => { + expect(labels()).toBe(1, 'the mesh is under that pointer: a move at rest finds it'); + }) + .then(done, done.fail); + }); + it('@gl a hover move draws no frame when the axis spikes are off, and gives the same events', function(done) { function run(spikes) { var L = layout(); @@ -1763,8 +1799,10 @@ describe('Test gl3d pick pass:', function() { }) .then(function() { mouseEvent('mousedown', 305, 230, {buttons: 1}); }) .then(delay(60)) + .then(frame) .then(function() { mouseEvent('mouseup', 305, 230); }) .then(delay(60)) + .then(frame) .then(function() { return moves([[5, 5]]); }) .then(function() { expect(document.querySelectorAll('g.hovertext').length).toBe(0); From 4bd6f7d013ce81394790e613084287b090417a3f Mon Sep 17 00:00:00 2001 From: Dominik Date: Sat, 5 Dec 2026 01:48:44 -0800 Subject: [PATCH 4/7] Pin gl-plot3d to the pick pass that waits for the frame of a change The pinned commit draws no pick pass on demand while a change waits for its frame, and queries no pick buffer before a pass has drawn it. Without it, a pointer event between scene.add and the next frame gave a hover label for a trace that no frame had drawn. The stackgl bundle is the webpack output for the pin. --- stackgl_modules/index.js | 13 ++++++++++--- stackgl_modules/package-lock.json | 5 ++--- stackgl_modules/package.json | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/stackgl_modules/index.js b/stackgl_modules/index.js index 45cc7a132f3..62c04a24940 100644 --- a/stackgl_modules/index.js +++ b/stackgl_modules/index.js @@ -18990,6 +18990,7 @@ function createScene(options) { } //Create new pick buffer var nbuffer = createSelect(gl, viewShape) + pickDrawn = false pickBufferIds[i] = numPick pickBuffers.push(nbuffer) pickBufferCount.push(pickCount) @@ -19118,7 +19119,7 @@ function createScene(options) { ensurePick() } - for(var i=0; i selection.distance) { @@ -19200,6 +19201,9 @@ function createScene(options) { var pickTimer = null var pickFrameSeen = false var pickEmpty = false + // False until a pick pass has drawn every pick buffer. A new buffer holds memory from the pool, not a picture, + // so no query reads the buffers before that. + var pickDrawn = false // True if some object that is drawn into a pick buffer can be picked function anyPickable() { @@ -19211,13 +19215,15 @@ function createScene(options) { return false } - // Draw the pick buffers and read them back now, if they are out of date + // Draw the pick buffers and read them back now, if they are out of date. + // Not while a change waits for its frame (an object added, removed or updated, a new size): a pass on demand + // shows what the last frame drew, as the pass in the frame did. That frame starts the idle timer again. function ensurePick() { if(pickTimer) { clearTimeout(pickTimer) pickTimer = null } - if(!pickDirty || !pickFrameSeen || scene._stopped || scene.contextLost) { + if(!pickDirty || !pickFrameSeen || dirty || scene._stopped || scene.contextLost) { return } pickDirty = false @@ -19293,6 +19299,7 @@ function createScene(options) { } buf.end() } + pickDrawn = true } var nBounds = [ diff --git a/stackgl_modules/package-lock.json b/stackgl_modules/package-lock.json index e250c874603..33eeb460df9 100644 --- a/stackgl_modules/package-lock.json +++ b/stackgl_modules/package-lock.json @@ -16,7 +16,7 @@ "gl-error3d": "^1.0.17", "gl-line3d": "^1.2.2", "gl-mesh3d": "^2.3.2", - "gl-plot3d": "github:settylab/gl-plot3d#af538fec50f8e212bde2cdfbfcf733bad5d7c771", + "gl-plot3d": "github:settylab/gl-plot3d#d054d4cfc56c35df9fd603344b48d5a5e0877422", "gl-scatter3d": "github:settylab/gl-scatter3d#370d619a7ec1351f87989c9963a37cd4ccb06e5b", "gl-shader": "4.3.1", "gl-spikes3d": "^1.0.11", @@ -1312,8 +1312,7 @@ }, "node_modules/gl-plot3d": { "version": "2.4.7", - "resolved": "git+ssh://git@github.com/settylab/gl-plot3d.git#af538fec50f8e212bde2cdfbfcf733bad5d7c771", - "integrity": "sha512-ilgUga590Ge94vR4MMFtq/NWjoTB99XrXnuyNCXFLPcLixAM3gHNMlN2ktcF19dlYKXtQNMA19xCLpkB/BSJXA==", + "resolved": "git+ssh://git@github.com/settylab/gl-plot3d.git#d054d4cfc56c35df9fd603344b48d5a5e0877422", "license": "MIT", "dependencies": { "3d-view": "^2.0.0", diff --git a/stackgl_modules/package.json b/stackgl_modules/package.json index 0acffbece66..848bfcfcf30 100644 --- a/stackgl_modules/package.json +++ b/stackgl_modules/package.json @@ -19,7 +19,7 @@ "gl-error3d": "^1.0.17", "gl-line3d": "^1.2.2", "gl-mesh3d": "^2.3.2", - "gl-plot3d": "github:settylab/gl-plot3d#af538fec50f8e212bde2cdfbfcf733bad5d7c771", + "gl-plot3d": "github:settylab/gl-plot3d#d054d4cfc56c35df9fd603344b48d5a5e0877422", "gl-scatter3d": "github:settylab/gl-scatter3d#370d619a7ec1351f87989c9963a37cd4ccb06e5b", "gl-shader": "4.3.1", "gl-spikes3d": "^1.0.11", From 66cec41bad7501a8e4005b15e2ca21d8e68ac2ac Mon Sep 17 00:00:00 2001 From: Dominik Date: Sat, 5 Dec 2026 01:53:20 -0800 Subject: [PATCH 5/7] Name the early pointer spec after what it tests plotly draws the first frame of a scene inside newPlot, so the event of the spec comes right after that frame, not before it. The spec text said otherwise. --- test/jasmine/tests/gl3d_hover_click_test.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/jasmine/tests/gl3d_hover_click_test.js b/test/jasmine/tests/gl3d_hover_click_test.js index 7311610305c..e177d77a028 100644 --- a/test/jasmine/tests/gl3d_hover_click_test.js +++ b/test/jasmine/tests/gl3d_hover_click_test.js @@ -1752,9 +1752,10 @@ describe('Test gl3d pick pass:', function() { .then(done, done.fail); }); - it('@gl gives no hover for a trace before the frame that draws it', function(done) { - // A pointer that rests on a scene sends an event when the canvas appears, before the first frame with the trace. - // The pick pass on demand must find nothing then, as the pick pass in the frame did. + it('@gl gives no hover for a pointer event right after the first frame of a scene', function(done) { + // A pointer that rests on a scene sends an event when the canvas appears, right after the first frame. + // The pick pass in the frame was read back 1 ms later, so that event found nothing, and the pointer got no label + // until it moved. The pick pass on demand must answer the same way. const labels = () => document.querySelectorAll('g.hovertext').length; Plotly.newPlot(gd, Lib.extendDeep({}, mesh3dcoloringMock)) .then(() => { @@ -1762,7 +1763,7 @@ describe('Test gl3d pick pass:', function() { }) .then(frame) .then(() => { - expect(labels()).toBe(0, 'no label for a mesh that no frame drew'); + expect(labels()).toBe(0, 'no label for the event right after the first frame'); }) .then(delay(300)) .then(() => { From 53971c44a3420334a7d5f02c23e9d9bfd07cae0c Mon Sep 17 00:00:00 2001 From: Dominik Date: Sat, 5 Dec 2026 01:59:36 -0800 Subject: [PATCH 6/7] Pin gl-plot3d to the pick pass that waits 1 ms after a frame The pinned commit gives a pick pass on demand 1 ms after a frame that changed the scene, as the read-back of the frame pass did. A pointer event right after the first frame of a scene finds nothing again, so a pointer that rests on a scene gets no hover label until it moves. The stackgl bundle is the webpack output for the pin. --- stackgl_modules/index.js | 15 ++++++++++++++- stackgl_modules/package-lock.json | 4 ++-- stackgl_modules/package.json | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/stackgl_modules/index.js b/stackgl_modules/index.js index 62c04a24940..3b45b9dc891 100644 --- a/stackgl_modules/index.js +++ b/stackgl_modules/index.js @@ -19050,6 +19050,10 @@ function createScene(options) { clearTimeout(pickTimer) pickTimer = null } + if(pickWait) { + clearTimeout(pickWait) + pickWait = null + } window.removeEventListener('resize', resizeListener) canvas.removeEventListener('webglcontextlost', checkContextLoss) @@ -19204,6 +19208,9 @@ function createScene(options) { // False until a pick pass has drawn every pick buffer. A new buffer holds memory from the pool, not a picture, // so no query reads the buffers before that. var pickDrawn = false + // The pick pass of a frame was read back 1 ms after the frame, so a pointer event right after a frame saw the + // picture of the frame before. A pass on demand waits as long: pickWait is set for 1 ms after a frame that changed it. + var pickWait = null // True if some object that is drawn into a pick buffer can be picked function anyPickable() { @@ -19223,7 +19230,7 @@ function createScene(options) { clearTimeout(pickTimer) pickTimer = null } - if(!pickDirty || !pickFrameSeen || dirty || scene._stopped || scene.contextLost) { + if(!pickDirty || !pickFrameSeen || dirty || pickWait || scene._stopped || scene.contextLost) { return } pickDirty = false @@ -19445,6 +19452,12 @@ function createScene(options) { if(scene.pickMode === 'lazy') { // Not in this frame: a pointer event that queries the buffer draws it, or the idle timer does schedulePick() + // (one timer at a time: a scene that draws frame after frame must not hold the wait for good) + if(!pickWait) { + pickWait = setTimeout(function() { + pickWait = null + }, 1) + } } else { pickDirty = false renderPick() diff --git a/stackgl_modules/package-lock.json b/stackgl_modules/package-lock.json index 33eeb460df9..758d09f1d07 100644 --- a/stackgl_modules/package-lock.json +++ b/stackgl_modules/package-lock.json @@ -16,7 +16,7 @@ "gl-error3d": "^1.0.17", "gl-line3d": "^1.2.2", "gl-mesh3d": "^2.3.2", - "gl-plot3d": "github:settylab/gl-plot3d#d054d4cfc56c35df9fd603344b48d5a5e0877422", + "gl-plot3d": "github:settylab/gl-plot3d#e68f3db7da0e319755d8df6aec1c0b6a0e83385b", "gl-scatter3d": "github:settylab/gl-scatter3d#370d619a7ec1351f87989c9963a37cd4ccb06e5b", "gl-shader": "4.3.1", "gl-spikes3d": "^1.0.11", @@ -1312,7 +1312,7 @@ }, "node_modules/gl-plot3d": { "version": "2.4.7", - "resolved": "git+ssh://git@github.com/settylab/gl-plot3d.git#d054d4cfc56c35df9fd603344b48d5a5e0877422", + "resolved": "git+ssh://git@github.com/settylab/gl-plot3d.git#e68f3db7da0e319755d8df6aec1c0b6a0e83385b", "license": "MIT", "dependencies": { "3d-view": "^2.0.0", diff --git a/stackgl_modules/package.json b/stackgl_modules/package.json index 848bfcfcf30..ccd671d851d 100644 --- a/stackgl_modules/package.json +++ b/stackgl_modules/package.json @@ -19,7 +19,7 @@ "gl-error3d": "^1.0.17", "gl-line3d": "^1.2.2", "gl-mesh3d": "^2.3.2", - "gl-plot3d": "github:settylab/gl-plot3d#d054d4cfc56c35df9fd603344b48d5a5e0877422", + "gl-plot3d": "github:settylab/gl-plot3d#e68f3db7da0e319755d8df6aec1c0b6a0e83385b", "gl-scatter3d": "github:settylab/gl-scatter3d#370d619a7ec1351f87989c9963a37cd4ccb06e5b", "gl-shader": "4.3.1", "gl-spikes3d": "^1.0.11", From a2509b54f62bf0cc438c70ab02e0bf493aa48230 Mon Sep 17 00:00:00 2001 From: Dominik Date: Sat, 5 Dec 2026 02:03:43 -0800 Subject: [PATCH 7/7] Pin gl-plot3d to the pick pass that waits 1 ms after a change of the objects The pinned commit gives no pick pass on demand for 1 ms after the first frame that follows scene.add or scene.remove, as the read-back of the frame pass did. A pointer that rests on a scene when it appears gets no hover label until it moves, as before. The pins of the two commits before this one made the wait too wide: it also ran after each frame of a moving camera, and hover specs failed at random. The stackgl bundle is the webpack output for the pin. --- stackgl_modules/index.js | 12 ++++++++++-- stackgl_modules/package-lock.json | 4 ++-- stackgl_modules/package.json | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/stackgl_modules/index.js b/stackgl_modules/index.js index 3b45b9dc891..d3475467f60 100644 --- a/stackgl_modules/index.js +++ b/stackgl_modules/index.js @@ -19022,6 +19022,7 @@ function createScene(options) { pickBufferIds.push(-1) dirty = true pickDirty = true + pickNew = true reallocPickIds() } @@ -19037,6 +19038,7 @@ function createScene(options) { pickBufferIds.pop() dirty = true pickDirty = true + pickNew = true reallocPickIds() } @@ -19211,6 +19213,9 @@ function createScene(options) { // The pick pass of a frame was read back 1 ms after the frame, so a pointer event right after a frame saw the // picture of the frame before. A pass on demand waits as long: pickWait is set for 1 ms after a frame that changed it. var pickWait = null + // True from a change of the objects (add, remove) to the next frame. Only that frame starts the wait: after a frame + // that moves the camera, the pass on demand answers at once, where the frame pass gave the picture of the frame before. + var pickNew = true // True if some object that is drawn into a pick buffer can be picked function anyPickable() { @@ -19452,12 +19457,15 @@ function createScene(options) { if(scene.pickMode === 'lazy') { // Not in this frame: a pointer event that queries the buffer draws it, or the idle timer does schedulePick() - // (one timer at a time: a scene that draws frame after frame must not hold the wait for good) - if(!pickWait) { + if(pickNew) { + if(pickWait) { + clearTimeout(pickWait) + } pickWait = setTimeout(function() { pickWait = null }, 1) } + pickNew = false } else { pickDirty = false renderPick() diff --git a/stackgl_modules/package-lock.json b/stackgl_modules/package-lock.json index 758d09f1d07..2927e14cd37 100644 --- a/stackgl_modules/package-lock.json +++ b/stackgl_modules/package-lock.json @@ -16,7 +16,7 @@ "gl-error3d": "^1.0.17", "gl-line3d": "^1.2.2", "gl-mesh3d": "^2.3.2", - "gl-plot3d": "github:settylab/gl-plot3d#e68f3db7da0e319755d8df6aec1c0b6a0e83385b", + "gl-plot3d": "github:settylab/gl-plot3d#03ca2f651f73835f17e9643480301054c2f4c26e", "gl-scatter3d": "github:settylab/gl-scatter3d#370d619a7ec1351f87989c9963a37cd4ccb06e5b", "gl-shader": "4.3.1", "gl-spikes3d": "^1.0.11", @@ -1312,7 +1312,7 @@ }, "node_modules/gl-plot3d": { "version": "2.4.7", - "resolved": "git+ssh://git@github.com/settylab/gl-plot3d.git#e68f3db7da0e319755d8df6aec1c0b6a0e83385b", + "resolved": "git+ssh://git@github.com/settylab/gl-plot3d.git#03ca2f651f73835f17e9643480301054c2f4c26e", "license": "MIT", "dependencies": { "3d-view": "^2.0.0", diff --git a/stackgl_modules/package.json b/stackgl_modules/package.json index ccd671d851d..ac97e922a08 100644 --- a/stackgl_modules/package.json +++ b/stackgl_modules/package.json @@ -19,7 +19,7 @@ "gl-error3d": "^1.0.17", "gl-line3d": "^1.2.2", "gl-mesh3d": "^2.3.2", - "gl-plot3d": "github:settylab/gl-plot3d#e68f3db7da0e319755d8df6aec1c0b6a0e83385b", + "gl-plot3d": "github:settylab/gl-plot3d#03ca2f651f73835f17e9643480301054c2f4c26e", "gl-scatter3d": "github:settylab/gl-scatter3d#370d619a7ec1351f87989c9963a37cd4ccb06e5b", "gl-shader": "4.3.1", "gl-spikes3d": "^1.0.11",