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

Improve following behavior when streaming #6318

Merged
merged 8 commits into from
Sep 26, 2024
Merged

Improve following behavior when streaming #6318

merged 8 commits into from
Sep 26, 2024

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Jul 9, 2024

  • Automatically stops following when the user zooms in and starts following when the user resets
  • Ensures that if the stream is out-of-sync with the plot the full data is synced

There still appears to be a race condition in bokeh where if a stream event arrives while the frontend is rendering it can cause "backtracking" glitches.

TODO:

  • Recompute range based on every new data point
  • Fix backtracking (fixed in Panel)
Code
import asyncio
import pandas as pd
import numpy as np

import holoviews as hv
hv.extension('bokeh')

nchannels = 25
buffer = hv.streams.Buffer(data=pd.DataFrame(np.random.randn(10, nchannels).cumsum(axis=1), columns=[chr(65+i) for i in range(nchannels)]))

def out(data):
    return hv.NdOverlay(
        {chr(65+i): hv.Curve(data, 'index', (chr(65+i), 'Amplitude')).opts(subcoordinate_y=True) for i in range(nchannels)}
    )

dmap = hv.DynamicMap(out, streams=[buffer]).opts(legend_position='right', legend_cols=2, responsive=True, min_height=600)

pane = pn.pane.HoloViews(dmap)

async def stream(event):
    for i in range(1, 1000):
        buffer.event(data=pd.DataFrame(np.random.randn(10, nchannels).cumsum(axis=1), columns=[chr(65+i) for i in range(nchannels)], index=np.arange(i*10, i*10+10)))
        await asyncio.sleep(0.01)

pn.Column(pn.widgets.Button(on_click=stream, name='Stream'), pane).servable()

ezgif-3-bde2bf8b98

@philippjfr
Copy link
Member Author

The backtracking behavior was fixed in holoviz/panel#7128

@hoxbro hoxbro added the type: enhancement Minor feature or improvement to an existing feature label Aug 16, 2024
@philippjfr
Copy link
Member Author

With range handling:

ezgif-6-90d086a92b

Copy link

codecov bot commented Sep 25, 2024

Codecov Report

Attention: Patch coverage is 76.40449% with 21 lines in your changes missing coverage. Please review.

Project coverage is 88.48%. Comparing base (3b3f10f) to head (62a20ab).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
holoviews/plotting/bokeh/element.py 65.71% 12 Missing ⚠️
holoviews/plotting/bokeh/plot.py 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6318      +/-   ##
==========================================
- Coverage   88.49%   88.48%   -0.02%     
==========================================
  Files         323      323              
  Lines       68304    68431     +127     
==========================================
+ Hits        60448    60550     +102     
- Misses       7856     7881      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

holoviews/tests/test_streams.py Outdated Show resolved Hide resolved
holoviews/tests/test_streams.py Outdated Show resolved Hide resolved
Co-authored-by: Simon Høxbro Hansen <simon.hansen@me.com>
@philippjfr philippjfr enabled auto-merge (squash) September 26, 2024 10:05
@philippjfr philippjfr merged commit 017361b into main Sep 26, 2024
13 checks passed
@philippjfr philippjfr deleted the stream_following branch September 26, 2024 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants