-
-
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
Expose minreducedwidth
and minreducedheight
to API
#6307
Changes from 8 commits
aeaba5c
f826ef7
bb2ca73
1c7cc49
61807ba
d692c7e
7fc8514
c53e084
2fc928d
0effd0f
6a43af4
21f71e6
93b05d3
0fff290
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,55 @@ | ||
{ | ||
"data": [{ | ||
"name": "< D E A T H >", | ||
"marker": { "color": "red" }, | ||
"x": [ | ||
"Antonio Vivaldi", | ||
"Johann Sebastian Bach", | ||
"Wolfgang Amadeus Mozart", | ||
"Ludwig van Beethoven" | ||
], | ||
"y": [ | ||
"1741", | ||
"1750", | ||
"1791", | ||
"1827" | ||
] | ||
}, | ||
{ | ||
"name": "< B I R T H >", | ||
"marker": { "color": "blue" }, | ||
"x": [ | ||
"Antonio Vivaldi", | ||
"Johann Sebastian Bach", | ||
"Wolfgang Amadeus Mozart", | ||
"Ludwig van Beethoven" | ||
], | ||
"y": [ | ||
"1678", | ||
"1685", | ||
"1756", | ||
"1770" | ||
] | ||
}], | ||
"layout": { | ||
"title": { | ||
"text": "Longest and shortest<br>names and time periods" | ||
}, | ||
"width": 240, | ||
"height": 300, | ||
"margin": { | ||
"t": 80, | ||
"b": 20, | ||
"l": 20, | ||
"r": 20, | ||
"minreducedheight": 55 | ||
}, | ||
"yaxis": { | ||
"type": "date", | ||
"automargin": true | ||
}, | ||
"xaxis": { | ||
"automargin": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"data": [{ | ||
"name": "< D E A T H >", | ||
"marker": { "color": "red" }, | ||
"y": [ | ||
"A n t o n i o V i v a l d i", | ||
"J o h a n n S e b a s t i a n B a c h", | ||
"W o l f g a n g A m a d e u s M o z a r t", | ||
"L u d w i g v a n B e e t h o v e n" | ||
], | ||
"x": [ | ||
"1741", | ||
"1750", | ||
"1791", | ||
"1827" | ||
] | ||
}, | ||
{ | ||
"name": "< B I R T H >", | ||
"marker": { "color": "blue" }, | ||
"y": [ | ||
"A n t o n i o V i v a l d i", | ||
"J o h a n n S e b a s t i a n B a c h", | ||
"W o l f g a n g A m a d e u s M o z a r t", | ||
"L u d w i g v a n B e e t h o v e n" | ||
], | ||
"x": [ | ||
"1678", | ||
"1685", | ||
"1756", | ||
"1770" | ||
] | ||
}], | ||
"layout": { | ||
"showlegend": false, | ||
"title": { | ||
"text": "Longest and shortest<br>names and time periods" | ||
}, | ||
"width": 240, | ||
"height": 200, | ||
"margin": { | ||
"t": 80, | ||
"b": 20, | ||
"l": 20, | ||
"r": 20, | ||
"minreducedwidth": 55 | ||
}, | ||
"xaxis": { | ||
"type": "date", | ||
"automargin": true | ||
}, | ||
"yaxis": { | ||
"automargin": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,7 +237,9 @@ describe('Test Plots', function() { | |
t: 100, | ||
b: 80, | ||
pad: 0, | ||
autoexpand: true | ||
autoexpand: true, | ||
minreducedwidth: 64, | ||
minreducedheight: 64 | ||
}; | ||
|
||
supplyLayoutDefaults(layoutIn, layoutOut); | ||
|
@@ -261,7 +263,9 @@ describe('Test Plots', function() { | |
t: 187, | ||
b: 311, | ||
pad: 0, | ||
autoexpand: true | ||
autoexpand: true, | ||
minreducedwidth: 64, | ||
minreducedheight: 64 | ||
}; | ||
|
||
supplyLayoutDefaults(layoutIn, layoutOut); | ||
|
@@ -1326,3 +1330,41 @@ describe('grids', function() { | |
.then(done, done.fail); | ||
}); | ||
}); | ||
|
||
describe('Test Plots with automargin and minreducedwidth/height', function() { | ||
var gd; | ||
|
||
beforeEach(function() { | ||
gd = createGraphDiv(); | ||
}); | ||
|
||
afterEach(destroyGraphDiv); | ||
|
||
it('should resize the plot area when tweaking min-reduced width & height', function(done) { | ||
function assert(attr, exp) { | ||
var xy = d3Select('rect.nsewdrag')[0][0]; | ||
expect(xy.getAttribute(attr)).toEqual(exp); | ||
} | ||
|
||
var fig = require('@mocks/z-automargin-minreducedheight.json'); | ||
|
||
Plotly.newPlot(gd, fig) | ||
.then(function() { | ||
assert('height', '55'); | ||
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. Thanks @archmoj for suggesting this test. Copied it over here but just dropped a couple of the 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 bet it is related to each OS+browser rendering fonts slightly differently. |
||
}) | ||
.then(function() { | ||
return Plotly.relayout(gd, 'margin.minreducedheight', 100); | ||
}) | ||
.then(function() { | ||
assert('height', '100'); | ||
}) | ||
.then(function() { | ||
return Plotly.relayout(gd, 'margin.minreducedwidth', 100); | ||
}) | ||
.then(function() { | ||
assert('width', '100'); | ||
assert('height', '100'); | ||
}) | ||
.then(done, done.fail); | ||
}); | ||
}); |
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.
@alexcjohnson Is there a better place to put these new attributes in?
It looks like these are related to
automargin
notmargin
itself.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.
@archmoj and I discussed this a bit earlier today, and I think the conclusion we came to was: because
margin.autoexpand
controls whether or not these attributes are even relevant, (1) they should stay here, so they're in the same container asautoexpand
, and (2) ifautoexpand
isfalse
we shouldn't even coerce these two new ones. (The general rule is, if an attribute doesn't do anything because of the value of some other attribute(s), it should not be coerced)The only question is whether it's really true that these attributes are irrelevant when
autoexpand=false
. According to its description this would disable automargin from "Legends, colorbars, updatemenus, sliders, axis rangeselector and rangeslider" but what ifxaxis.automargin=true
? Maybe then the margins can still be pushed even ifmargin.autoexpand=false
? That needs to be tested before we make coercion conditional onmargin.autoexpand
- but even if that's the case I think it makes sense to leave these attributes where they are.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.
Addressed in 93b05d3.
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.
yes, @archmoj and I looked into the source code and decided that these attributes would be best placed at the top level of layout parameters as they could be related to
autoexpand
as well (and I think logically make sense alongsideheight
andwidth
).