From 6b34be5e7efe0be4f92e9f063b825464466f43c2 Mon Sep 17 00:00:00 2001 From: inDream Date: Sat, 4 Feb 2017 23:20:15 +0800 Subject: [PATCH] Init commit --- src/plot_api/plot_api.js | 22 +++++++++++++++++- src/plots/cartesian/axis_defaults.js | 8 +++++++ src/plots/cartesian/layout_attributes.js | 29 ++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index e1c31b6f788..2cc25957a2a 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -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) @@ -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 @@ -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; diff --git a/src/plots/cartesian/axis_defaults.js b/src/plots/cartesian/axis_defaults.js index 21fbe0585cd..8b3f0763f97 100644 --- a/src/plots/cartesian/axis_defaults.js +++ b/src/plots/cartesian/axis_defaults.js @@ -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])) && diff --git a/src/plots/cartesian/layout_attributes.js b/src/plots/cartesian/layout_attributes.js index b917c4cf8e1..d587d61043b 100644 --- a/src/plots/cartesian/layout_attributes.js +++ b/src/plots/cartesian/layout_attributes.js @@ -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'],