You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all, have a question regarding the slider interactivity feature: When I was experimenting with the multiple interactions example via the movies dataset I tried to see how the graph display would work if I wanted to create a single graph where multiple interactions can be used at the same time rather than how it worked in the 4x4 example where interactions applied to separate graphs. A feature I wanted to implement with this type of graph in turn is that any filter could be reset if the user opted to view films from all genres, years and/or ratings again. The main issue I'm encountering though is that although I think I've been able to correctly implement something along the lines of this for radio buttons and dropdown filters (barring inconsistent colors being introduced across years, which I believe I can fix), I'm not sure how to do it for sliders (which in this case is used to select films from a certain year). From the documentation I reviewed regarding sliders in particular, it seems like it will only take a range between a min and max without the ability to add a special index for "all" films but maybe there's a way to do it within that command or within a separate command that I'm missing. I'll paste a modified version of the multiple interactions example to show what I'm doing in terms of modifying the base graph and adding all interaction parameter. Thanks in advance to anybody reading:
importaltairasaltfromvega_datasetsimportdatamovies=alt.UrlData(
data.movies.url,
format=alt.DataFormat(parse={"Release_Date":"date"})
)
ratingfilters= ['G', 'NC-17', 'PG', 'PG-13', 'R'] #this is created separately for the Altair filter command, that way we're not selecting films with rating as "None"ratings= ['G', 'NC-17', 'PG', 'PG-13', 'R', None] #this will be for the options available, None means all ratingsratingslabels= ['G', 'NC-17', 'PG', 'PG-13', 'R', 'All'] #this creates the labels relative to the ratings listgenres= [
None, 'Action', 'Adventure', 'Black Comedy', 'Comedy', #for the options bind with all genres as an option'Concert/Performance', 'Documentary', 'Drama', 'Horror', 'Musical',
'Romantic Comedy', 'Thriller/Suspense', 'Western'
]
genrelabels= [
'All', 'Action', 'Adventure', 'Black Comedy', 'Comedy', #"all" will select the None option'Concert/Performance', 'Documentary', 'Drama', 'Horror', 'Musical',
'Romantic Comedy', 'Thriller/Suspense', 'Western'
]
base=alt.Chart(movies, width=200, height=200).mark_point(filled=True).transform_calculate(
Rounded_IMDB_Rating="floor(datum.IMDB_Rating)",
Hundred_Million_Production="datum.Production_Budget > 100000000.0 ? 1 : 0", #keeping this column calc. for posterity, but will not create a checkbox option for nowRelease_Year="year(datum.Release_Date)",
).transform_filter(
alt.datum.IMDB_Rating>0
).transform_filter(
alt.FieldOneOfPredicate(field='MPAA_Rating', oneOf=ratingfilters)
).encode(
x=alt.X('Worldwide_Gross:Q').scale(domain=(100000,10**9), clamp=True),
y=alt.Y('IMDB_Rating:Q').scale(domain=(1,10)), #adding an explicit 1 to 10 scale just so it doesn't adjust during filterstooltip="Title:N"
).properties(
title="Multiple Interactions on One Graph Test"
)
# A dropdown filtergenre_dropdown=alt.binding_select(options=genres, labels=genrelabels, name="Genre")
genre_select=alt.selection_point(fields=['Major_Genre'], bind=genre_dropdown)
base=base.add_params(
genre_select
).transform_filter(
genre_select
)
# A slider filteryear_slider=alt.binding_range(min=1969, max=2018, step=1, name="Release Year") #this is where i'm unclear as to how to add a reset filter-like optionslider_selection=alt.selection_point(bind=year_slider, fields=['Release_Year'])
base=base.add_params(
slider_selection
).transform_filter(
slider_selection
)
#color changing marksrating_radio=alt.binding_radio(options=ratings, labels=ratingslabels, name="Rating")
rating_select=alt.selection_point(fields=['MPAA_Rating'], bind=rating_radio)
rating_color_condition=alt.condition(
rating_select,
alt.Color('MPAA_Rating:N').legend(None),
alt.value('lightgray')
)
base=base.add_params(
rating_select
).encode(
color=rating_color_condition
)
base
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi all, have a question regarding the slider interactivity feature: When I was experimenting with the multiple interactions example via the movies dataset I tried to see how the graph display would work if I wanted to create a single graph where multiple interactions can be used at the same time rather than how it worked in the 4x4 example where interactions applied to separate graphs. A feature I wanted to implement with this type of graph in turn is that any filter could be reset if the user opted to view films from all genres, years and/or ratings again. The main issue I'm encountering though is that although I think I've been able to correctly implement something along the lines of this for radio buttons and dropdown filters (barring inconsistent colors being introduced across years, which I believe I can fix), I'm not sure how to do it for sliders (which in this case is used to select films from a certain year). From the documentation I reviewed regarding sliders in particular, it seems like it will only take a range between a min and max without the ability to add a special index for "all" films but maybe there's a way to do it within that command or within a separate command that I'm missing. I'll paste a modified version of the multiple interactions example to show what I'm doing in terms of modifying the base graph and adding all interaction parameter. Thanks in advance to anybody reading:
Beta Was this translation helpful? Give feedback.
All reactions