Skip to content

Commit

Permalink
Merge pull request #3452 from plotly/bar-errorbar-autorange-fixes
Browse files Browse the repository at this point in the history
Bar & ErrorBar autorange fixes
  • Loading branch information
etpinard committed Jan 22, 2019
2 parents 3b9188d + 7e0a228 commit e4b1a7e
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 217 deletions.
14 changes: 9 additions & 5 deletions src/components/errorbars/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

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

var Registry = require('../../registry');
var Axes = require('../../plots/cartesian/axes');
var Lib = require('../../lib');

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


module.exports = function calc(gd) {
var calcdata = gd.calcdata;

Expand Down Expand Up @@ -73,8 +72,13 @@ function calcOneAxis(calcTrace, trace, axis, coord) {
}
}

var extremes = Axes.findExtremes(axis, vals, {padded: true});
var axId = axis._id;
trace._extremes[axId].min = trace._extremes[axId].min.concat(extremes.min);
trace._extremes[axId].max = trace._extremes[axId].max.concat(extremes.max);
var baseExtremes = trace._extremes[axId];
var extremes = Axes.findExtremes(
axis,
vals,
Lib.extendFlat({tozero: baseExtremes.opts.tozero}, {padded: true})
);
baseExtremes.min = baseExtremes.min.concat(extremes.min);
baseExtremes.max = baseExtremes.max.concat(extremes.max);
}
25 changes: 15 additions & 10 deletions src/plots/cartesian/autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ function doAutoRange(gd, ax) {
* - ax.d2l
* @param {array} data:
* array of numbers (i.e. already run though ax.d2c)
* @param {object} options:
* @param {object} opts:
* available keys are:
* vpad: (number or number array) pad values (data value +-vpad)
* ppad: (number or number array) pad pixels (pixel location +-ppad)
Expand All @@ -308,17 +308,18 @@ function doAutoRange(gd, ax) {
* - val {number}
* - pad {number}
* - extrappad {number}
* - opts {object}: a ref to the passed "options" object
*/
function findExtremes(ax, data, options) {
if(!options) options = {};
function findExtremes(ax, data, opts) {
if(!opts) opts = {};
if(!ax._m) ax.setScale();

var minArray = [];
var maxArray = [];

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

var ppadplus = makePadAccessor((ax._m > 0 ?
options.ppadplus : options.ppadminus) || options.ppad || 0);
opts.ppadplus : opts.ppadminus) || opts.ppad || 0);
var ppadminus = makePadAccessor((ax._m > 0 ?
options.ppadminus : options.ppadplus) || options.ppad || 0);
var vpadplus = makePadAccessor(options.vpadplus || options.vpad);
var vpadminus = makePadAccessor(options.vpadminus || options.vpad);
opts.ppadminus : opts.ppadplus) || opts.ppad || 0);
var vpadplus = makePadAccessor(opts.vpadplus || opts.vpad);
var vpadminus = makePadAccessor(opts.vpadminus || opts.vpad);

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

return {min: minArray, max: maxArray};
return {
min: minArray,
max: maxArray,
opts: opts
};
}

function collapseMinArray(array, newVal, newPad, opts) {
Expand Down
Loading

0 comments on commit e4b1a7e

Please sign in to comment.