-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
add support for responsive charts #2974
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
cb37565
069b0e2
08d6736
712652b
d82447a
62145e9
ec9ffa1
1262172
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -385,6 +385,15 @@ function emitAfterPlot(gd) { | |
fullLayout._redrawFromAutoMarginCount--; | ||
} else { | ||
gd.emit('plotly_afterplot'); | ||
|
||
// make the figure responsive | ||
if(gd._context.responsive && !gd._responsiveChartHandler) { | ||
// Keep a reference to the resize handler to purge it down the road | ||
gd._responsiveChartHandler = function() {Plots.resize(gd);}; | ||
|
||
// Listen to window resize | ||
window.addEventListener('resize', gd._responsiveChartHandler); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -3155,6 +3164,11 @@ exports.purge = function purge(gd) { | |
var fullData = gd._fullData || []; | ||
var calcdata = gd.calcdata || []; | ||
|
||
// remove responsive handler | ||
if(gd._responsiveChartHandler) { | ||
window.removeEventListener('resize', gd._responsiveChartHandler); | ||
} | ||
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. We also need to |
||
|
||
// remove gl contexts | ||
Plots.cleanPlot([], {}, fullData, fullLayout, calcdata); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,8 @@ | |
"env": { | ||
"browser": true, | ||
"jasmine": true | ||
}, | ||
"globals": { | ||
"viewport": 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.
Code looks great, but I'm a little surprised to see it so late in the sequence...
resize
has an internal delay, and callsPlotly.relayout
which will wait for any pending drawing on the plot to finish before making its changes. So to avoid missing events that happen halfway through an async draw (mathjax or maps) I'd have thought we should put this in the synchronous block.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.
It doesn't have to be this late. To be honest, I wasn't sure where it'd be best to put it in the sequence. Should I put it at line 193?
plotly.js/src/plot_api/plot_api.js
Lines 190 to 196 in 8457b40
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.
Seems like a good place!
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.
Oh one more thing occurs to me: a user could in principle start with
responsive
and then turn it off usingPlotly.react
... not sure why you'd want to do this, but it should work!