-
-
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
Remove internal option layout.autosize='initial' (Fixes #537) #577
Conversation
* Commit 5df675a (fix demo/outside legend bug and null data autoscale bug) introduced a guard in plotAutoSize to avoid calling layoutStyles while autosize is set to 'initial'. * Commit ee974d9 (autosizing in shareplots, autosize aspect ratio restrictions and ...) removed the call to layoutStyles but forgot to remove the guard. * This commit removes the guard. * Checked that all the jasmine and image tests still pass.
* Moved initial call to `plotAutoSize` into `Plots.supplyDefaults(gd)`. * Replaced `{ autosize: 'initial' }` with the flag `gd._fullLayout._initialAutoSizeIsDone`. * `{ autosize: false }` the values of width and height undefined in `gd.layout` will be autosized only once. * `{ autosize: true }` only autosizes the values of width and height undefined in `gd.layout`. Fixes plotly#537
* Previous image didn't honour the width and height set in the layout.
* Added test to check `Plotly.newPlot` respects `layout.width` and `layout.height`.
newWidth, | ||
newHeight; | ||
|
||
if(typeof gd.emit === 'function') gd.emit('plotly_autosize'); |
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.
why do we need this?
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.e. that if(typeof gd.emit === 'function')
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.
Otherwise I get errors in the console (perhaps some test are mocking gd with something other than a DOM element?). I will come back to you on this tomorrow.
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.
Good call. Plots.supplyDefaults
should work with plain objects.
Could we make this check more robust? I'd vote for using Lib.isPlotDiv
.
|
||
Plotly.plot(gd, data).then(function() { | ||
Plotly.newPlot(gd, data, { height: 50 }).then(function() { | ||
expect(gd._fullLayout.height).toBe(50); |
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.
we should also check to svg
attributes too to make sure that it updated properly.
@n-riesco looks like you're on the right path.
Yep. Great idea. 👍
Hmm. Is this the current behavior? Shouldn't
Great. Unfortunately, the plotly.js auto-size routine has very poor test coverage; I'm a little concerned with merging this PR. @n-riesco could make sure that all code paths in |
On 30/05/16 17:32, Étienne Tétreault-Pinard wrote:
The current behaviour is that if layout.width or layout.height are undefined, then layout.autosize is set to 'initial'.
OK. I'll add more tests. |
@n-riesco this is great, that's definitely where the autosize code belongs. My only question (which goes along with @etpinard 's concern about test coverage - there are tons of cases to consider) is whether there are cases we'd like This then begs the question (that we probably don't need to delve into now, might be a rabbit hole, but something to keep in mind for later) of whether we actually gain anything with the initial / redraw distinction. Either I'm missing something or it used to work differently, but I don't see that |
Below are the tests I'm planning to add:
For each test, I'll check fullLayout width and height after plot and after relayout. These tests should cover the main execution paths in plotAutoSize. Additional tests (from comments):
|
@n-riesco your plans sounds good! |
* Fix bug in `plotAutoSize`, triggered when `autosize` and `frameMagins` are both enabled and `gd` is a plain object. * Ensure `autosize` doesn't set values of width and height smaller than the minimum defined in the corresponding layout attribute.
* Do not do the initial autosize if both config.autosizable and layout.autosize are false.
* Fix bug introduced in the commit for respecting `config.autosizable`.
While writing the tests for this PR, I noticed that
I've updated this PR so that |
The PR is ready for review again. |
factor = 1 - 2 * frameMargins; | ||
|
||
var gdBB; | ||
try { |
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 think we should avoid using try-catch
as much as possible - because they are very slow.
Here too, I'd vote for using Lib.isPlotDiv
. But, I'm open to other (possible more strict) suggestions.
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.
How about?
var gdBB = fullLayout._container && fullLayout._container.node ?
fullLayout._container.node().getBoundingClientRect() : {
width: fullLayout.width,
height: fullLayout.height
};
* Initialise `layout.width` and `layout.height` if `autosize` is false.
@etpinard About For Plotly v2, I would suggest to combine {
autosize: {
valType: 'enumerated',
role: 'info',
values: ['never', 'initial', 'always'],
description: [
'Determines how a layout width or height',
'that has been left undefined by the user',
'is set.',
'If *never*, the default values of width and height will be used.',
'If *initial*, an undefined layout width or height',
'will be initialized on the first call to plot.'
'If *always*, an undefined layout width or height',
'will be set on the first call to plot and subsequent calls to relayout.'
].join(' ')
}
} |
PR ready for review again. |
} catch(err) { | ||
gdBB = { | ||
var gdBB = fullLayout._container && fullLayout._container.node ? | ||
fullLayout._container.node().getBoundingClientRect() : { |
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.
Good. 👍
I've added tests for the commits you suggested and this uncovered an issue with 862578e and another with The PR is ready for review again. |
Great. I tested your branch and I couldn't find any edge cases that you might have missed. 🎉 This for sure wins the PR of the week 🏆 I'll make two minor comments on the line diff (nothing major) and then it'll be time to 💃 . |
@@ -47,11 +47,16 @@ module.exports = { | |||
autosize: { | |||
valType: 'enumerated', | |||
role: 'info', | |||
// TODO: better handling of 'initial' | |||
values: [true, false, 'initial'], | |||
values: [false, true], |
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.
we should change the valType
to 'boolean'
and remove the values
field.
@@ -326,7 +383,7 @@ describe('Test Plots', function() { | |||
beforeEach(function(done) { | |||
gd = createGraphDiv(); | |||
|
|||
Plotly.plot(gd, [{ x: [1, 2, 3], y: [2, 3, 4] }], {}) | |||
Plotly.plot(gd, [{ x: [1, 2, 3], y: [2, 3, 4] }], { autosize: true }) |
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.
@n-riesco , @chriddyp and I are testing the mapbox
branch (which is rebased on top of the latest master
) in the plot.ly workspace at the moment and we some issues.
Looks like this PR here is backward incompatible and the line ⏫ is a symptom.
More clearly,
Plotly.plot(gd, data);
should go through the plotAutoSize
routine on the initial Plotly.plot
call.
I believe changing the autosize
attribute dflt
to true
would solve this. What are your thoughts on that?
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.
@etpinard An alternative that would be fully backwards-compatible is that Plot.resize(gd)
deletes gd.layout.width
and gd.layout.height
and calls Plotly.relayout(gd, { autosize: true });
. I'll prepare a PR so that you can check that it'd fix the issue in the mapbox
branch.
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.
See #629
As per-slack conversation with @n-riesco , I'm reverting this PR and will spend more time testing in plot.ly's workspace before the next minor release - to make sure we handle all edge cases in a backward-compatible way. |
plotAutoSize
intoPlots.supplyDefaults(gd)
.{ autosize: 'initial' }
with the flaggd._fullLayout._initialAutoSizeIsDone
.{ autosize: false }
the values of width and height undefined ingd.layout
will be autosized only once.{ autosize: true }
only autosizes the values of width and heightundefined in
gd.layout
.Fixes #537