From 58c285756bea512d18341f701ffc8c5221d6926b Mon Sep 17 00:00:00 2001 From: Eliot5566 Date: Mon, 23 Nov 2026 11:05:52 +0800 Subject: [PATCH 1/2] Use the lowest error bar for the scatter3d log axis range calc_errors kept the lower log error bound of the first point with an error bar instead of the lowest one, so the autorange cut off error bars when the smallest point was not first. The value also stayed on the axis between plots, so Plotly.react kept a stale bound. Keep the minimum and clear the bound before the scene updates its traces. Fixes #8185 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Hq1ACTsK85bRrY28fUQ7b3 --- draftlogs/XXXX_fix.md | 1 + src/plots/gl3d/scene.js | 6 +++ src/traces/scatter3d/calc_errors.js | 5 +- test/jasmine/tests/scatter3d_test.js | 69 ++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 draftlogs/XXXX_fix.md diff --git a/draftlogs/XXXX_fix.md b/draftlogs/XXXX_fix.md new file mode 100644 index 00000000000..7530e675a90 --- /dev/null +++ b/draftlogs/XXXX_fix.md @@ -0,0 +1 @@ +- Fix the `scatter3d` z range on log axes cutting off the lower error bars when the smallest point is not the first one, and keep the range in sync with the data after `Plotly.react` [[#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..43d234f63b8 100644 --- a/src/plots/gl3d/scene.js +++ b/src/plots/gl3d/scene.js @@ -619,6 +619,12 @@ proto.plot = function(sceneData, fullLayout, layout) { // after computeTraceBounds where ax._categories are filled in scene.convertAnnotations(this); + // The traces recompute the lower log error bounds during their update, + // so drop the values from the previous plot first + for(j = 0; j < 3; ++j) { + delete fullSceneLayout[axisProperties[j]]._lowerLogErrorBound; + } + // Update traces for(i = 0; i < sceneData.length; ++i) { data = sceneData[i]; diff --git a/src/traces/scatter3d/calc_errors.js b/src/traces/scatter3d/calc_errors.js index 9406249a871..a0034238f81 100644 --- a/src/traces/scatter3d/calc_errors.js +++ b/src/traces/scatter3d/calc_errors.js @@ -24,8 +24,9 @@ function calculateAxisErrors(data, params, scaleFactor, axis) { // Keep track of the lower error bound which isn't negative! if(min > 0) { var lower = axis.c2l(min); - if(!axis._lowerLogErrorBound) axis._lowerLogErrorBound = lower; - axis._lowerErrorBound = Math.min(axis._lowerLogErrorBound, lower); + if(axis._lowerLogErrorBound === undefined || lower < axis._lowerLogErrorBound) { + axis._lowerLogErrorBound = lower; + } } } else { result[i] = [ diff --git a/test/jasmine/tests/scatter3d_test.js b/test/jasmine/tests/scatter3d_test.js index a5f1a7f8b4d..e4ab10a9c83 100644 --- a/test/jasmine/tests/scatter3d_test.js +++ b/test/jasmine/tests/scatter3d_test.js @@ -345,4 +345,73 @@ describe('Test scatter3d interactions:', function() { }) .then(done, done.fail); }); + + describe('log error bars', function() { + var samples = [ + {z: 1200, err: 300}, + {z: 410, err: 90}, + {z: 95, err: 30}, + {z: 12, err: 8} + ]; + + function makeTrace(rows) { + return { + type: 'scatter3d', + mode: 'markers', + x: rows.map(function(r, i) { return i; }), + y: rows.map(function(r, i) { return i % 2; }), + z: rows.map(function(r) { return r.z; }), + error_z: {array: rows.map(function(r) { return r.err; })} + }; + } + + var layout = {scene: {zaxis: {type: 'log'}}}; + + function zRange() { + return gd._fullLayout.scene.zaxis.range.slice(); + } + + it('@gl should start the z range below the lowest error bar whatever the point order', function(done) { + var ascending; + + Plotly.newPlot(gd, [makeTrace(samples.slice().reverse())], Lib.extendDeep({}, layout)) + .then(function() { + ascending = zRange(); + // the lower error bar of the smallest point ends at 12 - 8 = 4 + expect(ascending[0]).toBeLessThan(Math.log10(4)); + + return Plotly.newPlot(gd, [makeTrace(samples)], Lib.extendDeep({}, layout)); + }) + .then(function() { + expect(zRange()).toBeCloseToArray(ascending, 5); + }) + .then(done, done.fail); + }); + + it('@gl should recompute the lower error bound on react', function(done) { + var wide = samples.map(function(r) { return {z: r.z, err: r.err}; }); + wide[3].err = 11; + var expected; + + Plotly.newPlot(gd, [makeTrace(wide)], Lib.extendDeep({}, layout)) + .then(function() { + expected = zRange(); + + return Plotly.newPlot(gd, [makeTrace(samples)], Lib.extendDeep({}, layout)); + }) + .then(function() { + return Plotly.react(gd, [makeTrace(wide)], Lib.extendDeep({}, layout)); + }) + .then(function() { + expect(zRange()).toBeCloseToArray(expected, 5); + + return Plotly.react(gd, [makeTrace(samples)], Lib.extendDeep({}, layout)); + }) + .then(function() { + // 12 - 8 = 4 is above 12 - 11 = 1, so the range must start higher again + expect(zRange()[0]).toBeGreaterThan(expected[0]); + }) + .then(done, done.fail); + }); + }); }); From 90a39ceac687e3a1d1226035f6029f2e0f2a3f1f Mon Sep 17 00:00:00 2001 From: Eliot5566 Date: Mon, 23 Nov 2026 11:18:15 +0800 Subject: [PATCH 2/2] Rename the draftlog to the PR number Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Hq1ACTsK85bRrY28fUQ7b3 --- draftlogs/{XXXX_fix.md => 8186_fix.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename draftlogs/{XXXX_fix.md => 8186_fix.md} (53%) diff --git a/draftlogs/XXXX_fix.md b/draftlogs/8186_fix.md similarity index 53% rename from draftlogs/XXXX_fix.md rename to draftlogs/8186_fix.md index 7530e675a90..142fe15f65e 100644 --- a/draftlogs/XXXX_fix.md +++ b/draftlogs/8186_fix.md @@ -1 +1 @@ -- Fix the `scatter3d` z range on log axes cutting off the lower error bars when the smallest point is not the first one, and keep the range in sync with the data after `Plotly.react` [[#XXXX](https://github.com/plotly/plotly.js/pull/XXXX)] +- Fix the `scatter3d` z range on log axes cutting off the lower error bars when the smallest point is not the first one, and keep the range in sync with the data after `Plotly.react` [[#8186](https://github.com/plotly/plotly.js/pull/8186)]