Skip to content

Commit 15100f9

Browse files
committed
scatter3d properly handles error bars with negative lower bounds
1 parent 86f4bef commit 15100f9

File tree

6 files changed

+42
-6
lines changed

6 files changed

+42
-6
lines changed

Diff for: src/plots/gl3d/scene.js

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

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

Diff for: src/traces/scatter3d/calc_errors.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,20 @@ function calculateAxisErrors(data, params, scaleFactor, axis) {
2121

2222
if(axis.type === 'log') {
2323
var point = axis.c2l(data[i]);
24+
var min = data[i] - errors[0],
25+
max = data[i] + errors[1];
26+
2427
result[i] = [
25-
(axis.c2l(data[i] - errors[0]) - point || -point) * scaleFactor,
26-
(axis.c2l(data[i] + errors[1]) - point) * scaleFactor
28+
(axis.c2l(min, true) - point) * scaleFactor,
29+
(axis.c2l(max, true) - point) * scaleFactor
2730
];
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+
}
2838
} else {
2939
result[i] = [
3040
-errors[0] * scaleFactor,

Diff for: test/image/baselines/gl3d_error_bars_log.png

-10 Bytes
Loading

Diff for: test/image/baselines/gl3d_error_bars_log_2.png

42.8 KB
Loading

Diff for: test/image/mocks/gl3d_error_bars_log.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"data": [{
33
"x": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
44
"y": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
5-
"z": [1e+00, 1e+01, 1e+02, 1e+03, 1e+04,
5+
"z": [1e00, 1e+01, 1e+02, 1e+03, 1e+04,
66
1e+05, 1e+06, 1e+07, 1e+08, 1e+09
77
],
88
"type": "scatter3d",
99
"error_z": {
10-
"array": [1e-01, 2e+01, 1e+1, 9e+03, 5e+03,
11-
0.9e+05, 1e+05, 1e+07, 9e+08, 1e+09
10+
"array": [1e-01, 1e+00, 1e+02, 9e+03, 5e+03,
11+
0.9e+05, 1e+05, 1e+07, 9e+08, 2e+09
1212
],
1313
"type": "data",
1414
"visible": true

Diff for: test/image/mocks/gl3d_error_bars_log_2.json

+22
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)