-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add additional options for automargin property #6193
Changes from 9 commits
25a54a2
0ed3602
0702b78
35268c7
57452c2
9dfdb91
cf26237
ee97962
eed9bbf
ae1b087
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Add flaglist options including "left", "right", "top", "bottom", "width" and "height" to control the direction of `automargin` on cartesian axes [[#6193](https://github.com/plotly/plotly.js/pull/6193)] |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -39,6 +39,14 @@ var GRID_PATH = { K: 'gridline', L: 'path' }; | |||||
var MINORGRID_PATH = { K: 'minor-gridline', L: 'path' }; | ||||||
var TICK_PATH = { K: 'tick', L: 'path' }; | ||||||
var TICK_TEXT = { K: 'tick', L: 'text' }; | ||||||
var MARGIN_MAPPING = { | ||||||
width: ['x', 'r', 'l', 'xl', 'xr'], | ||||||
height: ['y', 't', 'b', 'yt', 'yb'], | ||||||
right: ['r', 'xr'], | ||||||
left: ['l', 'xl'], | ||||||
top: ['t', 'yt'], | ||||||
bottom: ['b', 'yb'] | ||||||
}; | ||||||
|
||||||
var alignmentConstants = require('../../constants/alignment'); | ||||||
var MID_SHIFT = alignmentConstants.MID_SHIFT; | ||||||
|
@@ -2622,6 +2630,11 @@ axes.drawOne = function(gd, ax, opts) { | |||||
rangeSliderPush = Registry.getComponentMethod('rangeslider', 'autoMarginOpts')(gd, ax); | ||||||
} | ||||||
|
||||||
if(typeof ax.automargin === 'string') { | ||||||
filterPush(push, ax.automargin); | ||||||
filterPush(mirrorPush, ax.automargin); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ha @nickmelnikov82 asked me the same question, my answer:
There are others that aren't even in this section of code, like legends and colorbars. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we want to implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that's interesting... in principle I like this, one place to control all of this rather than requiring you to set it in each axis separately. But it opens a can of worms: by default axes have All that to say: it's a good idea, but it's going to be a bunch of work, so let's not do it now. What we're doing in this PR would be fully compatible with adding that sometime in the future. |
||||||
} | ||||||
|
||||||
Plots.autoMargin(gd, axAutoMarginID(ax), push); | ||||||
Plots.autoMargin(gd, axMirrorAutoMarginID(ax), mirrorPush); | ||||||
Plots.autoMargin(gd, rangeSliderAutoMarginID(ax), rangeSliderPush); | ||||||
|
@@ -2636,6 +2649,25 @@ axes.drawOne = function(gd, ax, opts) { | |||||
return Lib.syncOrAsync(seq); | ||||||
}; | ||||||
|
||||||
function filterPush(push, automargin) { | ||||||
if(!push) return push; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
var keepMargin = Object.keys(MARGIN_MAPPING).reduce(function(data, nextKey) { | ||||||
if(automargin.indexOf(nextKey) !== -1) { | ||||||
MARGIN_MAPPING[nextKey].forEach(function(key) { data[key] = 1;}); | ||||||
} | ||||||
return data; | ||||||
}, {}); | ||||||
|
||||||
Object.keys(push).forEach(function(key) { | ||||||
if(!keepMargin[key]) { | ||||||
if(key.length === 1) push[key] = 0; | ||||||
else delete push[key]; | ||||||
} | ||||||
}); | ||||||
return push; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
function getBoundaryVals(ax, vals) { | ||||||
var out = []; | ||||||
var i; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please elaborate why this change is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just reversing the order of short-circuits to support non-string extras #6193 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @alexcjohnson wrote:
Without this, the flaglist coerce function does not pass non-string values.