Skip to content

scatter3d now performs axis transformation on error bars #2992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 17, 2018
Merged
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
6 changes: 5 additions & 1 deletion src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
@@ -523,7 +523,11 @@ proto.plot = function(sceneData, fullLayout, layout) {
var objBounds = obj.bounds;
var pad = obj._trace.data._pad || 0;

sceneBounds[0][i] = Math.min(sceneBounds[0][i], objBounds[0][i] / dataScale[i] - pad);
if(obj.constructor.name === 'ErrorBars' && axis._lowerLogErrorBound) {
sceneBounds[0][i] = Math.min(sceneBounds[0][i], axis._lowerLogErrorBound);
} else {
sceneBounds[0][i] = Math.min(sceneBounds[0][i], objBounds[0][i] / dataScale[i] - pad);
}
sceneBounds[1][i] = Math.max(sceneBounds[1][i], objBounds[1][i] / dataScale[i] + pad);
}

36 changes: 27 additions & 9 deletions src/traces/scatter3d/calc_errors.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@

var Registry = require('../../registry');

function calculateAxisErrors(data, params, scaleFactor) {
function calculateAxisErrors(data, params, scaleFactor, axis) {
if(!params || !params.visible) return null;

var computeError = Registry.getComponentMethod('errorbars', 'makeComputeError')(params);
@@ -19,10 +19,28 @@ function calculateAxisErrors(data, params, scaleFactor) {
for(var i = 0; i < data.length; i++) {
var errors = computeError(+data[i], i);

result[i] = [
-errors[0] * scaleFactor,
errors[1] * scaleFactor
];
if(axis.type === 'log') {
var point = axis.c2l(data[i]);
var min = data[i] - errors[0],
max = data[i] + errors[1];

result[i] = [
(axis.c2l(min, true) - point) * scaleFactor,
(axis.c2l(max, true) - point) * scaleFactor
];

// 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);
}
} else {
result[i] = [
-errors[0] * scaleFactor,
errors[1] * scaleFactor
];
}
}

return result;
@@ -35,11 +53,11 @@ function dataLength(array) {
return 0;
}

function calculateErrors(data, scaleFactor) {
function calculateErrors(data, scaleFactor, sceneLayout) {
var errors = [
calculateAxisErrors(data.x, data.error_x, scaleFactor[0]),
calculateAxisErrors(data.y, data.error_y, scaleFactor[1]),
calculateAxisErrors(data.z, data.error_z, scaleFactor[2])
calculateAxisErrors(data.x, data.error_x, scaleFactor[0], sceneLayout.xaxis),
calculateAxisErrors(data.y, data.error_y, scaleFactor[1], sceneLayout.yaxis),
calculateAxisErrors(data.z, data.error_z, scaleFactor[2], sceneLayout.zaxis)
];

var n = dataLength(errors);
2 changes: 1 addition & 1 deletion src/traces/scatter3d/convert.js
Original file line number Diff line number Diff line change
@@ -252,7 +252,7 @@ function convertPlotlyOptions(scene, data) {
}
}

params.errorBounds = calculateError(data, scaleFactor);
params.errorBounds = calculateError(data, scaleFactor, sceneLayout);

var errorParams = calculateErrorParams([data.error_x, data.error_y, data.error_z]);
params.errorColor = errorParams.color;
Binary file added test/image/baselines/gl3d_error_bars_log.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/gl3d_error_bars_log_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions test/image/mocks/gl3d_error_bars_log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"data": [{
"x": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
"y": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"z": [1e00, 1e+01, 1e+02, 1e+03, 1e+04,
1e+05, 1e+06, 1e+07, 1e+08, 1e+09
],
"type": "scatter3d",
"error_z": {
"array": [1e-01, 1e+00, 1e+02, 9e+03, 5e+03,
0.9e+05, 1e+05, 1e+07, 9e+08, 2e+09
],
"type": "data",
"visible": true
}
}],
"layout": {
"scene": {
"zaxis": {
"type": "log"
}
},
"width": 800,
"height": 800
}
}
22 changes: 22 additions & 0 deletions test/image/mocks/gl3d_error_bars_log_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"data": [{
"x": [0],
"y": [0],
"z": [1e-08],
"type": "scatter3d",
"error_z": {
"array": [0.9e-08],
"type": "data",
"visible": true
}
}],
"layout": {
"scene": {
"zaxis": {
"type": "log"
}
},
"width": 800,
"height": 800
}
}