-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add additional options for automargin property #6193
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
Changes from 2 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 | ||
---|---|---|---|---|
|
@@ -2622,6 +2622,8 @@ axes.drawOne = function(gd, ax, opts) { | |||
rangeSliderPush = Registry.getComponentMethod('rangeslider', 'autoMarginOpts')(gd, ax); | ||||
} | ||||
|
||||
keepSelectedAutoMargin(ax.automargin, push); | ||||
|
||||
Plots.autoMargin(gd, axAutoMarginID(ax), push); | ||||
Plots.autoMargin(gd, axMirrorAutoMarginID(ax), mirrorPush); | ||||
Plots.autoMargin(gd, rangeSliderAutoMarginID(ax), rangeSliderPush); | ||||
|
@@ -2636,6 +2638,35 @@ axes.drawOne = function(gd, ax, opts) { | |||
return Lib.syncOrAsync(seq); | ||||
}; | ||||
|
||||
function keepSelectedAutoMargin(automargin, push) { | ||||
if(typeof automargin === 'boolean') return push; | ||||
|
||||
var keepMargin = []; | ||||
var mapping = { | ||||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
width: ['x', 'r', 'l'], | ||||
height: ['y', 't', 'b'], | ||||
right: ['r'], | ||||
left: ['l'], | ||||
top: ['t'], | ||||
bottom: ['b'] | ||||
}; | ||||
|
||||
Object.keys(mapping).forEach(function(key) { | ||||
if(automargin.includes(key)) { | ||||
nickmelnikov82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
mapping[key].forEach(function(item) { | ||||
keepMargin.push(item); | ||||
}); | ||||
} | ||||
}); | ||||
|
||||
Object.keys(push).forEach(function(key) { | ||||
if(key.length !== 2 && !keepMargin.includes(key)) { | ||||
alexcjohnson marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
push[key] = 0; | ||||
} | ||||
}); | ||||
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; | ||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -625,7 +625,14 @@ module.exports = { | |||
description: 'Determines whether or not the tick labels are drawn.' | ||||
}, | ||||
automargin: { | ||||
valType: 'boolean', | ||||
valType: 'enumerated', | ||||
values: [ | ||||
true, false, 'height', 'width', | ||||
'top', 'bottom', 'left', 'right', | ||||
'top left', 'top width', 'top right', | ||||
'left height', 'right height', | ||||
'bottom left', 'bottom width', 'bottom right', | ||||
], | ||||
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. Let's use a flaglist: valType: 'flaglist',
flags: ['height', 'width', 'left', 'right', 'top', 'bottom'],
extras: [true, false] That way the order doesn't matter (you use 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. Are there pre-existing instances of "flaglist or boolean" in the schema? I want to make sure the Python codegen will not choke on this. 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. flaglist does not support boolean parameters Line 218 in b194d8c
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. OK that's pretty good evidence that we don't currently have any flaglists with non-string extras 😉 @nicolaskruchten your concern is warranted, plotly.py also includes the string requirement up front. But I really do think this attribute would be better as a flaglist, I'll be happy to modify the Python validator to allow non-string extras. I suppose the alternative would be to make this a new attribute like 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'm fine with tweaking Plotly.py for this 👍 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. Changed the schema. 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.
Having a separate attribute could be safer for Python, R, Scala, etc. APIs. 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'm working on a plotly.py PR right now... will post shortly. |
||||
dflt: false, | ||||
editType: 'ticks', | ||||
description: [ | ||||
|
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.
So
keepSelectedAutoMargin
mutates thepush
variable.It was rather difficult to figure out what this step does here.
How about refactoring like this:
On another note, wondering if mutating
push
should be performed earlier in the process so that the value inmirrorPush
would be accurate?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.
I don't see the point of using a mirror if the result would still be cut off. So there is no need to filter the
mirrorPush
.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.
Actually I think it's correct to filter
mirrorPush
as well. The wholemirrorPush
construction is inside theif(ax.automargin)
block - implying that if you disable automargin, we're not going to push the margins for mirror axes regardless of whether they end up cut off. Therefore you should be able to choose which directions this applies to just as you can the regular axis automargin.