Skip to content
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

scatter3d now performs axis transformation on error bars #2992

Merged
merged 5 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 8 additions & 7 deletions src/traces/scatter3d/calc_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

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

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

var point = axis.d2l(data[i], 0, calendar) * scaleFactor; // A bit wasteful
result[i] = [
-errors[0] * scaleFactor,
errors[1] * scaleFactor
(axis.d2l(data[i] - errors[0], 0, calendar) * scaleFactor) - point || -point,
(axis.d2l(data[i] + errors[1], 0, calendar) * scaleFactor) - point || -point
antoinerg marked this conversation as resolved.
Show resolved Hide resolved
];
}

Expand All @@ -35,11 +36,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, data.xcalendar),
calculateAxisErrors(data.y, data.error_y, scaleFactor[1], sceneLayout.yaxis, data.ycalendar),
calculateAxisErrors(data.z, data.error_z, scaleFactor[2], sceneLayout.zaxis, data.zcalendar)
];

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

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

var errorParams = calculateErrorParams([data.error_x, data.error_y, data.error_z]);
params.errorColor = errorParams.color;
Expand Down
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.
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": [1e+00, 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, 2e+01, 1e+1, 9e+03, 5e+03,
0.9e+05, 1e+05, 1e+07, 9e+08, 1e+09
],
"type": "data",
"visible": true
}
}],
"layout": {
"scene": {
"zaxis": {
"type": "log"
}
},
"width": 800,
"height": 800
}
}