-
-
Notifications
You must be signed in to change notification settings - Fork 403
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 support for GridSpace axes in bokeh #1150
Conversation
59c79de
to
6e891bb
Compare
cf8be8d
to
970f557
Compare
Small change to test data due to a small change in how grid plots are padded. Ready to merge now. |
Merge this one last, after all the latest once since it will change the test data and then all other PRs will need rebasing. |
All the other HoloViews PRs are now merged so feel free to rebase now and update the test data as appropriate. |
holoviews/plotting/bokeh/plot.py
Outdated
kwargs['xaxis'] = 'bottom-bare' | ||
kwargs['width'] = 150 | ||
kwargs['xaxis'] = None | ||
kwargs['width'] = self.plot_size+50 | ||
if c != 0 and r == 0: |
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.
Looks like 50
is a magic number...
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.
True, it's the offset used to account for the axis width. Could parameterize it I suppose.
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.
Would be much better to query it than parameterize it. Can it be calculated as outer dimension minus inner dimension, now that the inner dimensions are available in Bokeh JS?
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.
Can it be calculated as outer dimension minus inner dimension, now that the inner dimensions are available in Bokeh JS?
No bokehJS is too late to set this, if it's wrong the layout solver breaks and you never get an inner width.
holoviews/plotting/bokeh/util.py
Outdated
if axis == 'x': | ||
align = 'center' | ||
# Adjust height to compensate for label rotation | ||
height = int(50 + np.abs(np.sin(rotation)) * (nchars*8)) |
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 assume this is the same magic number 50
. Even if it doesn't have to be a parameter, it should at least be a class attribute...
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.
Sure, might be good to parameterize it actually, if you have really long axis labels the layout solver could blow up I suppose and this would let you have some control.
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.
A class attribute seems like a step in the right direction for now. I wouldn't make it a parameter till we have a concrete, real world example of it being 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.
What about the 8 in nchars*8
? Where is the 8 from?
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.
Cheating a bit, it's the fontsize, which I actually don't let you change atm. Could allow changing it and scaling this size accordingly.
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.
Sounds very fragile.
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'm actually surprised how well it works, but it will definitely get more brittle if I add support for fontsizes.
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 also only works because I'm explicitly formatting the ticks as strings, which makes sense in this case, but it is not a general approach because it will break for ticks computed on the frontend.
tests/testrenderclass.py
Outdated
@@ -205,7 +205,7 @@ def test_get_size_grid_plot(self): | |||
grid = GridSpace({(i, j): self.image1 for i in range(3) for j in range(3)}) | |||
plot = self.renderer.get_plot(grid) | |||
w, h = self.renderer.get_size(plot) | |||
self.assertEqual((w, h), (360, 360)) | |||
self.assertEqual((w, h), (418, 410)) |
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.
Interesting that it used to be perfectly square, but isn't anymore. Generally, square plots seems easier when considering layouts etc...
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.
Interesting that it used to be perfectly square, but isn't anymore.
Taking into account the fact that a vertical axis is wider than a horizontal one. Might be worth considering using this calculation more generally because I've found I can compute axes widths pretty accurately.
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.
(Probably not a good idea when a JS formatter is responsible for computing ticks).
holoviews/plotting/bokeh/util.py
Outdated
@@ -125,7 +128,7 @@ def mpl_to_bokeh(properties): | |||
return new_properties | |||
|
|||
|
|||
def layout_padding(plots): | |||
def layout_padding(plots, renderer): | |||
""" | |||
Temporary workaround to allow empty plots in a | |||
row of a bokeh GridPlot type. Should be removed |
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.
The PR reference in this docstring bokeh/bokeh#2891 looks like it was resolved to your satisfaction in June. This suggests either this function should be removed or the docstring updated.
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, will update the docstring (and perhaps reopen the issue). It's not actually fixed.
99cb913
to
cbd8063
Compare
It's great to have this. Should there be an issue at the bokeh repo to gave an API to query anything you currently have hardcoded? |
I don't think there's much bokeh can do as long as the layout solver is run client side and once that has run it's too late because the solver may have failed completely. |
So are these hints, then, not hardcoding? I.e., will the client then figure out the actual values? |
No, it will respect those values but has to draw everything inside those bounds, if things get squeezed too tight it blows up and doesn't render. |
2b7fd52
to
3fdda7d
Compare
@jlstevens Ready to merge. |
Looks good! Merging. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Creates outer dimension axes for GridSpaces, like we support in matplotlib: