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 range control to plot #223

Merged
merged 2 commits into from
Nov 14, 2024
Merged

Conversation

benjeffery
Copy link
Member

@benjeffery benjeffery commented Nov 7, 2024

Closes #198

I've spent too much time trying to get bidirectional binding working here without any luck. So for now the scrolling on the plot doesn't update the control. Annoyingly I can get it to work in a toy example:

import panel as pn
import holoviews as hv
import hvplot.pandas
import numpy as np
import pandas as pd

pn.extension()
hv.extension('bokeh')

x = np.linspace(0, 100, 1000)
y = np.sin(x/10) + np.random.randn(len(x))*0.1
df = pd.DataFrame({'x': x, 'y': y})

x_range = pn.widgets.TextInput(value='0:100', name='X Range (start:stop)')

def parse_range(range_str):
    try:
        start, end = map(float, range_str.split(':'))
        return (start, end)
    except (ValueError, TypeError):
        return (0, 100)  # Default range if parsing fails

def get_plot(range_str):
    x_range = parse_range(range_str)
    return df.hvplot.line(x='x', y='y').opts(xlim=x_range, framewise=True)

dmap = hv.DynamicMap(pn.bind(get_plot, x_range))

range_stream = hv.streams.RangeX(source=dmap)

def update_widget(event):
    if event.new is not None:
        new_start, new_end = event.new
        new_value = f"{new_start}:{new_end}"
        if new_value != x_range.value:
            x_range.value = new_value

range_stream.param.watch(update_widget, 'x_range')

pn.Column(x_range, dmap).servable()

Copy link

Automated Screenshots

These screenshots are automatically updated as the PR changes.

Click to view screenshots

edges.png

edges.png

mutations.png

mutations.png

nodes.png

nodes.png

out_edges.png

out_edges.png

out_mutations.png

out_mutations.png

out_nodes.png

out_nodes.png

overview.png

overview.png

tables.png

tables.png

trees.png

trees.png

github-actions bot pushed a commit that referenced this pull request Nov 13, 2024
@coveralls
Copy link

coveralls commented Nov 13, 2024

Pull Request Test Coverage Report for Build 11837220564

Details

  • 29 of 34 (85.29%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.2%) to 89.035%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tsbrowse/plot_helpers.py 7 8 87.5%
tsbrowse/pages/edges.py 11 13 84.62%
tsbrowse/pages/mutations.py 11 13 84.62%
Totals Coverage Status
Change from base Build 11837217838: -0.2%
Covered Lines: 812
Relevant Lines: 912

💛 - Coveralls

github-actions bot pushed a commit that referenced this pull request Nov 13, 2024
@benjeffery benjeffery marked this pull request as ready for review November 13, 2024 17:04
github-actions bot pushed a commit that referenced this pull request Nov 14, 2024
@benjeffery benjeffery merged commit 84b2d04 into tskit-dev:main Nov 14, 2024
5 of 6 checks passed
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.

defining a viewport with controls
2 participants