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

Add args for initial ranges to RangeToolLink #5800

Merged
merged 12 commits into from Jul 11, 2023
Merged

Add args for initial ranges to RangeToolLink #5800

merged 12 commits into from Jul 11, 2023

Conversation

droumis
Copy link
Member

@droumis droumis commented Jul 10, 2023

fixes #5437

This PR allows users to specify a start and end to the axes ranges in the call to RangeToolLink. Previously, this required a hook (#5437).

Why? Users often need to adjust the initial selection range to have the target plot focused on a subregion, rather than having the entire data range on view at the start. Often, the view of the entire dataset is less useful for initial exploration than a particular focused region, while the entire range still needs to be available for easy pan and zoom navigation. The improvement in this PR will also be helpful for future developments for particularly large amounts of data, where we could set an absolute limit on the viewport range and limit the out-of-viewport data sent to the browser, to prevent crashes or slowdowns. This PR therefore addresses the immediate utility of focused navigation and sets the stage for further developments with large data.

update: changed args and logic to boundsx/y rather than axes_start/end

import pandas as pd
import holoviews as hv
from holoviews import opts
from holoviews.plotting.links import RangeToolLink

hv.extension('bokeh')
from bokeh.sampledata.stocks import AAPL

aapl_df = pd.DataFrame(AAPL['close'], columns=['close'], index=pd.to_datetime(AAPL['date']))
aapl_df.index.name = 'Date'

aapl_curve = hv.Curve(aapl_df, 'Date', ('close', 'Price ($)'))

tgt = aapl_curve.relabel('AAPL close price').opts(width=800, labelled=['y'], toolbar='disable')

src = aapl_curve.opts(width=800, height=100, yaxis=None, default_tools=[])

RangeToolLink(src, tgt, axes=['x', 'y'], boundsx= (pd.to_datetime('2006'), pd.to_datetime('2010')), boundsy=(None, 400))

layout = (tgt + src).cols(1)
layout.opts(opts.Layout(shared_axes=False, merge_tools=False))
image

@droumis droumis requested a review from Hoxbro July 10, 2023 10:07
@codecov-commenter
Copy link

codecov-commenter commented Jul 11, 2023

Codecov Report

Merging #5800 (d9847e3) into main (8e85674) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #5800      +/-   ##
==========================================
- Coverage   88.14%   88.13%   -0.02%     
==========================================
  Files         307      307              
  Lines       62863    62897      +34     
==========================================
+ Hits        55413    55434      +21     
- Misses       7450     7463      +13     
Flag Coverage Δ
ui-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
holoviews/plotting/bokeh/links.py 73.29% <100.00%> (+1.27%) ⬆️
holoviews/plotting/links.py 94.91% <100.00%> (+0.17%) ⬆️
holoviews/tests/plotting/bokeh/test_links.py 98.52% <100.00%> (+0.31%) ⬆️

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@ahuang11 ahuang11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just some suggestions for refactoring.

holoviews/plotting/bokeh/links.py Outdated Show resolved Hide resolved
holoviews/plotting/links.py Outdated Show resolved Hide resolved
holoviews/plotting/links.py Outdated Show resolved Hide resolved
@droumis
Copy link
Member Author

droumis commented Jul 11, 2023

one quirk - when you press the 'reset' button in the Bokeh toolbar, users would probably expect the plot to go back to the initial state that was displayed with constrained rangetool bounds... However, upon 'reset', the rangetool currently fills the whole data space.

I don't think this should block this PR.. just to note for a future enhancement

Copy link
Member

@Hoxbro Hoxbro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments. That definitely are not blockers.

examples/gallery/demos/bokeh/timeseries_range_tool.ipynb Outdated Show resolved Hide resolved
holoviews/plotting/links.py Outdated Show resolved Hide resolved
@Hoxbro
Copy link
Member

Hoxbro commented Jul 11, 2023

Thank you for the PR. Great job!

@Hoxbro Hoxbro merged commit 3d3dad9 into main Jul 11, 2023
14 checks passed
@Hoxbro Hoxbro deleted the rangetool-range branch July 11, 2023 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set initial selected range for RangeToolLink
4 participants