Skip to content

Commit e4b1a7e

Browse files
authored
Merge pull request #3452 from plotly/bar-errorbar-autorange-fixes
Bar & ErrorBar autorange fixes
2 parents 3b9188d + 7e0a228 commit e4b1a7e

9 files changed

+225
-217
lines changed

src/components/errorbars/calc.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var isNumeric = require('fast-isnumeric');
1312

1413
var Registry = require('../../registry');
1514
var Axes = require('../../plots/cartesian/axes');
15+
var Lib = require('../../lib');
1616

1717
var makeComputeError = require('./compute_error');
1818

19-
2019
module.exports = function calc(gd) {
2120
var calcdata = gd.calcdata;
2221

@@ -73,8 +72,13 @@ function calcOneAxis(calcTrace, trace, axis, coord) {
7372
}
7473
}
7574

76-
var extremes = Axes.findExtremes(axis, vals, {padded: true});
7775
var axId = axis._id;
78-
trace._extremes[axId].min = trace._extremes[axId].min.concat(extremes.min);
79-
trace._extremes[axId].max = trace._extremes[axId].max.concat(extremes.max);
76+
var baseExtremes = trace._extremes[axId];
77+
var extremes = Axes.findExtremes(
78+
axis,
79+
vals,
80+
Lib.extendFlat({tozero: baseExtremes.opts.tozero}, {padded: true})
81+
);
82+
baseExtremes.min = baseExtremes.min.concat(extremes.min);
83+
baseExtremes.max = baseExtremes.max.concat(extremes.max);
8084
}

src/plots/cartesian/autorange.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ function doAutoRange(gd, ax) {
290290
* - ax.d2l
291291
* @param {array} data:
292292
* array of numbers (i.e. already run though ax.d2c)
293-
* @param {object} options:
293+
* @param {object} opts:
294294
* available keys are:
295295
* vpad: (number or number array) pad values (data value +-vpad)
296296
* ppad: (number or number array) pad pixels (pixel location +-ppad)
@@ -308,17 +308,18 @@ function doAutoRange(gd, ax) {
308308
* - val {number}
309309
* - pad {number}
310310
* - extrappad {number}
311+
* - opts {object}: a ref to the passed "options" object
311312
*/
312-
function findExtremes(ax, data, options) {
313-
if(!options) options = {};
313+
function findExtremes(ax, data, opts) {
314+
if(!opts) opts = {};
314315
if(!ax._m) ax.setScale();
315316

316317
var minArray = [];
317318
var maxArray = [];
318319

319320
var len = data.length;
320-
var extrapad = options.padded || false;
321-
var tozero = options.tozero && (ax.type === 'linear' || ax.type === '-');
321+
var extrapad = opts.padded || false;
322+
var tozero = opts.tozero && (ax.type === 'linear' || ax.type === '-');
322323
var isLog = ax.type === 'log';
323324
var hasArrayOption = false;
324325
var i, v, di, dmin, dmax, ppadiplus, ppadiminus, vmin, vmax;
@@ -335,11 +336,11 @@ function findExtremes(ax, data, options) {
335336
}
336337

337338
var ppadplus = makePadAccessor((ax._m > 0 ?
338-
options.ppadplus : options.ppadminus) || options.ppad || 0);
339+
opts.ppadplus : opts.ppadminus) || opts.ppad || 0);
339340
var ppadminus = makePadAccessor((ax._m > 0 ?
340-
options.ppadminus : options.ppadplus) || options.ppad || 0);
341-
var vpadplus = makePadAccessor(options.vpadplus || options.vpad);
342-
var vpadminus = makePadAccessor(options.vpadminus || options.vpad);
341+
opts.ppadminus : opts.ppadplus) || opts.ppad || 0);
342+
var vpadplus = makePadAccessor(opts.vpadplus || opts.vpad);
343+
var vpadminus = makePadAccessor(opts.vpadminus || opts.vpad);
343344

344345
if(!hasArrayOption) {
345346
// with no arrays other than `data` we don't need to consider
@@ -403,7 +404,11 @@ function findExtremes(ax, data, options) {
403404
for(i = 0; i < iMax; i++) addItem(i);
404405
for(i = len - 1; i >= iMax; i--) addItem(i);
405406

406-
return {min: minArray, max: maxArray};
407+
return {
408+
min: minArray,
409+
max: maxArray,
410+
opts: opts
411+
};
407412
}
408413

409414
function collapseMinArray(array, newVal, newPad, opts) {

0 commit comments

Comments
 (0)