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 SelectionExpr stream #3927

Merged
merged 14 commits into from Sep 12, 2019

Conversation

@jonmmease
Copy link
Collaborator

commented Aug 26, 2019

Overview

This PR adds a new stream called SelectionExprStream. This stream attaches to an element and provides selection_expr and bbox params:

  • selection_expr: When not None, this holds a dim-expression representing the current selection on the element.
  • bbox: When not None, this holds a dict representing the bounding box of the selection. Each key in the dict is a dimension name, and the value is a tuple pair of the min/max values of the selection.

2D Cartesian example

import holoviews as hv
import numpy as np
import pandas as pd
hv.extension('bokeh')

scatter = hv.Scatter(([1, 2, 3], [1, 5, 10]))
expr_stream = hv.streams.SelectionExprStream(scatter)
scatter

Screenshot_20190826_093939

print(expr_stream.selection_expr)
(((dim('x')>=1.6270833696637834)&dim('x')<=2.6270833696637834)&dim('y')>=3.086363863353888)&dim('y')<=6.991322541039838
print(expr_stream.bbox)
{'x': (1.6270833696637834, 2.6270833696637834), 'y': (3.086363863353888, 6.991322541039838)}

Histogram example

hist = hv.Histogram(([1, 2, 3, 4, 5], [1, 5, 2, 3, 7])) 
expr_stream_hist = hv.streams.SelectionExprStream(hist)
hist

Screenshot_20190826_094320

print(expr_stream_hist.selection_expr)
dim('x'), digitize, array([0.5, 1.5, 2.5, 3.5, 4.5, 5.5])), isin, [2, 4])
print(expr_stream_hist.bbox)
{'x': (1.5, 4.5)}

digitize and isin

To support representing histogram selection as a dim expression, I added the numpy digitize and isin functions as dim expression.

Relationship to other PRs

While this PR does not depend on any other open PRs, the selection_expr param is compatible with the selection_expr arg being added to select in #3920.

TODO:

  • Handle/test reversed axes
jonmmease added 6 commits Aug 24, 2019
Add Chart2dSelectionExpr mixin class and add SelectionExprStream to support for Scatter, Curve, ErrorBars, Spikes.

Also add GeometrySelectionExpr mixin to support Geometry elements: Points, VectorField
@jbednar

This comment has been minimized.

Copy link
Member

commented Aug 26, 2019

Nice!

@philippjfr philippjfr added the feature label Aug 27, 2019
@philippjfr

This comment has been minimized.

Copy link
Contributor

commented Aug 27, 2019

Nice! Can _get_selection_expr_for_stream_value have a more generic name? If I'm understanding it right it turns a bbox selection into a dim expression?

@jonmmease

This comment has been minimized.

Copy link
Collaborator Author

commented Aug 27, 2019

Can _get_selection_expr_for_stream_value have a more generic name? If I'm understanding it right it turns a bbox selection into a dim expression?

At the moment that's all it does. I'm imaging that eventually we'll have other streams that will also be able to be converted into dim expression selections. For example, a BoundsPoly stream for lasso selection, or a BoundsSphere stream for 3D selections.

@jlstevens

This comment has been minimized.

Copy link
Contributor

commented Aug 30, 2019

How about calling the stream SelectionExpression? Not all our stream classes need to end in the suffix Stream...

@jonmmease

This comment has been minimized.

Copy link
Collaborator Author

commented Aug 30, 2019

How about calling the stream SelectionExpression? Not all our stream classes need to end in the suffix Stream...

Sure, sounds good

@jonmmease jonmmease changed the title Add SelectionExprStream Add SelectionExpr stream Sep 3, 2019
@jonmmease

This comment has been minimized.

Copy link
Collaborator Author

commented Sep 3, 2019

@jlstevens SelectionExpressionStream renamed SelectionExpression and I added support for handling the invert_axes, invert_xaxis, and invert_yaxis options. Let me know if anything else you'd like to see before we merge this!

@jonmmease

This comment has been minimized.

Copy link
Collaborator Author

commented Sep 10, 2019

Any other thoughts before merging this one @jlstevens @philippjfr?

@philippjfr

This comment has been minimized.

Copy link
Contributor

commented Sep 12, 2019

Looks good to me.

@philippjfr philippjfr merged commit a1e0c03 into master Sep 12, 2019
3 of 4 checks passed
3 of 4 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.05%) to 88.123%
Details
@philippjfr philippjfr deleted the dim_expression_isin branch Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.