Skip to content
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

Added support for tick formatters in bokeh #728

Merged
merged 4 commits into from
Jun 27, 2016
Merged

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Jun 22, 2016

As the title says this adds support for supplying arbitrary Python functions as tick formatters for the axes. A simple example is a formatter that displays seconds as minutes.

def formatter(seconds):
    m, s = divmod(seconds, 60)
    s = ('%d' % s) if s > 9 else ('0%s' % s)
    return "%d:%s" % (m, s)

hv.Curve(np.random.rand(300)).redim(x=dict(value_format=formatter, unit='min'))

image

Note that this depends on flexx being installed because compiling the python function to JS requires pyscript. Currently it will warn if flexx can't be imported or the function cannot be compiled.

@canavandl
Copy link

Conversely - it supports writing the function in JS or Coffeescript too (without flexx).

@philippjfr
Copy link
Member Author

That's true although I'm not sure how or even if we should expose that in HoloViews. The benefit of supplying a Python function is that it should work for both bokeh and matplotlib and will show up correctly in sliders and titles.

@jbednar
Copy link
Member

jbednar commented Jun 22, 2016

Looks good to me! Not exposing the JS options sounds appropriate; we don't normally expose anything JS in HoloViews, but Bokeh does it throughout, so it's fine that we make a different choice. Happy to have this merged.

@jlstevens
Copy link
Contributor

The flexx dependency looks fine to me as it is a bokeh dependency not a holoviews dependency.

The only thing I would like to check before merging is whether this same interface could be used for the matplotlib backend? Having one function to support two backends would be far better than having to keep switching function (even with redim now available).

@philippjfr
Copy link
Member Author

Just added a small change so that a single argument function is supported in matplotlib. We now consistently support single argument functions everywhere and you can also supply a function with an optional second argument, which will be passed the matplotlib pos argument. It's worth noting that matplotlib and bokeh will likely never be consistent here because the pos argument depends on the zoom level and is therefore pretty much useless in bokeh. Ready to review and merge.

@jlstevens
Copy link
Contributor

Ok, I reviewed it earlier and it looked fine except for that one issue. Merging.

@jlstevens jlstevens merged commit 8a4a34f into master Jun 27, 2016
@jlstevens jlstevens deleted the bokeh_tickformatter branch July 12, 2016 22:57
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants