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

ENH: add selector value access for expressions #1599

Merged
merged 2 commits into from
Jul 7, 2019

Conversation

jakevdp
Copy link
Collaborator

@jakevdp jakevdp commented Jul 5, 2019

Addresses #1013

This PR adds the ability to access selector values within filter & condition expressions; for example:

import altair as alt
import pandas as pd
import numpy as np

df = pd.DataFrame({
    'xval': range(100),
    'yval': np.random.randn(100).cumsum()
})

slider = alt.binding_range(min=0, max=100, step=1, name='cutoff')
selector = alt.selection_single(fields=['cutoff'], bind=slider, init={'cutoff': 50})

alt.Chart(df).mark_point().encode(
    x='xval',
    y='yval',
    color=alt.condition(alt.datum.xval < selector.cutoff, alt.value('red'), alt.value('blue'))
).add_selection(
    selector
)

Screen Shot 2019-07-05 at 8 18 50 AM

@jakevdp
Copy link
Collaborator Author

jakevdp commented Jul 5, 2019

It would be useful to add an example and some documentation as well.

@jakevdp jakevdp merged commit 079f872 into vega:master Jul 7, 2019
@jakevdp jakevdp deleted the selector-val branch July 7, 2019 13:47
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.

1 participant