Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/8186_fix.md
Original file line number Diff line number Diff line change
@@ -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` [[#8186](https://github.com/plotly/plotly.js/pull/8186)]
6 changes: 6 additions & 0 deletions src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
5 changes: 3 additions & 2 deletions src/traces/scatter3d/calc_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [
Expand Down
69 changes: 69 additions & 0 deletions test/jasmine/tests/scatter3d_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});