Skip to content

Commit c422725

Browse files
authoredSep 17, 2018
Merge pull request #2992 from plotly/2962-scatter3d-log-error-bars
scatter3d now performs axis transformation on error bars
2 parents b6d5283 + 15100f9 commit c422725

File tree

7 files changed

+81
-11
lines changed

7 files changed

+81
-11
lines changed
 

‎src/plots/gl3d/scene.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,11 @@ proto.plot = function(sceneData, fullLayout, layout) {
529529
var objBounds = obj.bounds;
530530
var pad = obj._trace.data._pad || 0;
531531

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

‎src/traces/scatter3d/calc_errors.js

+27-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

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

13-
function calculateAxisErrors(data, params, scaleFactor) {
13+
function calculateAxisErrors(data, params, scaleFactor, axis) {
1414
if(!params || !params.visible) return null;
1515

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

22-
result[i] = [
23-
-errors[0] * scaleFactor,
24-
errors[1] * scaleFactor
25-
];
22+
if(axis.type === 'log') {
23+
var point = axis.c2l(data[i]);
24+
var min = data[i] - errors[0],
25+
max = data[i] + errors[1];
26+
27+
result[i] = [
28+
(axis.c2l(min, true) - point) * scaleFactor,
29+
(axis.c2l(max, true) - point) * scaleFactor
30+
];
31+
32+
// Keep track of the lower error bound which isn't negative!
33+
if(min > 0) {
34+
var lower = axis.c2l(min);
35+
if(!axis._lowerLogErrorBound) axis._lowerLogErrorBound = lower;
36+
axis._lowerErrorBound = Math.min(axis._lowerLogErrorBound, lower);
37+
}
38+
} else {
39+
result[i] = [
40+
-errors[0] * scaleFactor,
41+
errors[1] * scaleFactor
42+
];
43+
}
2644
}
2745

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

38-
function calculateErrors(data, scaleFactor) {
56+
function calculateErrors(data, scaleFactor, sceneLayout) {
3957
var errors = [
40-
calculateAxisErrors(data.x, data.error_x, scaleFactor[0]),
41-
calculateAxisErrors(data.y, data.error_y, scaleFactor[1]),
42-
calculateAxisErrors(data.z, data.error_z, scaleFactor[2])
58+
calculateAxisErrors(data.x, data.error_x, scaleFactor[0], sceneLayout.xaxis),
59+
calculateAxisErrors(data.y, data.error_y, scaleFactor[1], sceneLayout.yaxis),
60+
calculateAxisErrors(data.z, data.error_z, scaleFactor[2], sceneLayout.zaxis)
4361
];
4462

4563
var n = dataLength(errors);

‎src/traces/scatter3d/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function convertPlotlyOptions(scene, data) {
252252
}
253253
}
254254

255-
params.errorBounds = calculateError(data, scaleFactor);
255+
params.errorBounds = calculateError(data, scaleFactor, sceneLayout);
256256

257257
var errorParams = calculateErrorParams([data.error_x, data.error_y, data.error_z]);
258258
params.errorColor = errorParams.color;
42.3 KB
Loading
42.8 KB
Loading
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"data": [{
3+
"x": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
4+
"y": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
5+
"z": [1e00, 1e+01, 1e+02, 1e+03, 1e+04,
6+
1e+05, 1e+06, 1e+07, 1e+08, 1e+09
7+
],
8+
"type": "scatter3d",
9+
"error_z": {
10+
"array": [1e-01, 1e+00, 1e+02, 9e+03, 5e+03,
11+
0.9e+05, 1e+05, 1e+07, 9e+08, 2e+09
12+
],
13+
"type": "data",
14+
"visible": true
15+
}
16+
}],
17+
"layout": {
18+
"scene": {
19+
"zaxis": {
20+
"type": "log"
21+
}
22+
},
23+
"width": 800,
24+
"height": 800
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"data": [{
3+
"x": [0],
4+
"y": [0],
5+
"z": [1e-08],
6+
"type": "scatter3d",
7+
"error_z": {
8+
"array": [0.9e-08],
9+
"type": "data",
10+
"visible": true
11+
}
12+
}],
13+
"layout": {
14+
"scene": {
15+
"zaxis": {
16+
"type": "log"
17+
}
18+
},
19+
"width": 800,
20+
"height": 800
21+
}
22+
}

0 commit comments

Comments
 (0)
Please sign in to comment.