Skip to content

Implement Axis boundaries #1353

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
22 changes: 21 additions & 1 deletion src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,8 @@ function _relayout(gd, aobj) {
doplot: false,
docalc: false,
domodebar: false,
layoutReplot: false
layoutReplot: false,
overBounds: false
};

// copies of the change (and previous values of anything affected)
Expand Down Expand Up @@ -1820,6 +1821,19 @@ function _relayout(gd, aobj) {

if(vi === undefined) continue;

if(pleaf === 'range' && parentIn.bound) {
var boundIdx = p.parts[2];
var val = vi;
var bound = parentIn.bound[boundIdx];
if(parentFull.type === 'date') {
val = +new Date(val);
bound = +new Date(bound);
}
if(boundIdx === 0 ? vi < bound : vi > bound) {
flags.overBounds = true;
}
}

redoit[ai] = vi;

// axis reverse is special - it is its own inverse
Expand Down Expand Up @@ -2020,6 +2034,12 @@ function _relayout(gd, aobj) {
}
}

if(flags.overBounds) {
// TODO: Handle per xaxis & yaxis / Set range to max bound
flags.docalc = false;
redoit = {};
}

var oldWidth = gd._fullLayout.width,
oldHeight = gd._fullLayout.height;

Expand Down
8 changes: 8 additions & 0 deletions src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
color: dfltFontColor
});

var validBound = (
(containerIn.bound || []).length === 2 &&
isNumeric(containerOut.r2l(containerIn.bound[0])) &&
isNumeric(containerOut.r2l(containerIn.bound[1]))
);
var autoBound = coerce('autorange', !validBound);
if(autoBound) coerce('bound');

var validRange = (
(containerIn.range || []).length === 2 &&
isNumeric(containerOut.r2l(containerIn.range[0])) &&
Expand Down
29 changes: 29 additions & 0 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,35 @@ module.exports = {
'the axis in question.'
].join(' ')
},
autobound: {
valType: 'boolean',
dflt: true,
role: 'style',
description: [
'Determines the bound of this axis for layout',
'If `bound` is provided, then `autobound` is set to *false*.'
].join(' ')
},
bound: {
valType: 'info_array',
role: 'info',
items: [
{valType: 'any'},
{valType: 'any'}
],
description: [
'Sets the bound of this axis.',
'If the axis `type` is *log*, then you must take the log of your',
'desired bound (e.g. to set the bound from 1 to 100,',
'set the bound from 0 to 2).',
'If the axis `type` is *date*, it should be date strings,',
'like date data, though Date objects and unix milliseconds',
'will be accepted and converted to strings.',
'If the axis `type` is *category*, it should be numbers,',
'using the scale where each category is assigned a serial',
'number from zero in the order it appears.'
].join(' ')
},
autorange: {
valType: 'enumerated',
values: [true, false, 'reversed'],
Expand Down