-
Notifications
You must be signed in to change notification settings - Fork 794
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
Binding documentation #1113
Binding documentation #1113
Conversation
Having issues with RST header sizing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start overall! A few comments throughout.
doc/user_guide/interactions.rst
Outdated
|
||
- the :class:`selection` object which captures interactions from the mouse or through other inputs to effect the chart. Inputs can either be events like moust clicks or drags. Inputs can also be elemnts like a drop-down, radio button or slider. Selections can be used alone but if you want to have change any element of your chart you will need to connect them to a *condition*. | ||
- the :class:`condition` function takes the selection input and changes an element of the chart based on that input. | ||
- the :class:`bind` property of a selection which establishes a two-way binding between the selection and an input element of your chart. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace :class:`selection`
with :func:`selection`
and :class:`condition`
with :func:`condition`
.
bind
is neither a class nor a function in Altair, so there's no appropriate sphinx directive to refer to it. You can just use ``bind``
.
doc/user_guide/interactions.rst
Outdated
@@ -236,9 +251,101 @@ over them with your mouse: | |||
multi_mouseover = alt.selection_multi(on='mouseover', toggle=False, empty='none') | |||
make_example(multi_mouseover) | |||
|
|||
Binding: Adding Data Driven Inputs | |||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |||
With an understanding of the selection types and conditions, you can now add data-driven input elements to the charts using the :class:`bind`. As specified by `Vega-lite binding <https://vega.github.io/vega-lite/docs/bind.html#input-element-binding>`_, selections can be bound two-ways: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:class:`bind`
-> ``bind`` attribute
?
doc/user_guide/interactions.rst
Outdated
) | ||
|
||
|
||
scatter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than assigning the chart to scatter
and putting scatter
below, just leave out the assignment altogether.
doc/user_guide/interactions.rst
Outdated
^^^^^^^^^^^^^^^^^^^^^ | ||
With single selections, an input element can be added to the chart to establish a binding between the input and the selection. | ||
|
||
For instance, using our example from above a dropdown can be used to highlight cars from a specific :origin: : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with this :origin:
syntax in RST. What does it do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change :origin:
to ``origin``
? Or just origin
?
doc/user_guide/interactions.rst
Outdated
|
||
For instance, using our example from above a dropdown can be used to highlight cars from a specific :origin: : | ||
|
||
.. altair-plot:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line is required after the altair-plot
directive
|
||
Bindings and input elements can also be used to filter data on the client side. Reducing noise in the chart and allowing the user to see just certain selected elements: | ||
|
||
.. altair-plot:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add blank line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch. I only found one other reference (on the weather chart which was funny given that I missed it before) I think we should be there.
doc/user_guide/interactions.rst
Outdated
) | ||
|
||
|
||
scatter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't assign to scatter (as above)
^^^^^^^^^^^^^ | ||
With interval selections, the bind property can be set to the value of :"scales":. In these cases, the binding will automatically respond to the panning and zooming along the chart: | ||
|
||
.. altair-plot:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line
doc/user_guide/interactions.rst
Outdated
alt.Color('Origin:N', legend=None), | ||
alt.value('lightgray')) | ||
|
||
scatter = alt.Chart(cars).mark_point().encode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove assignment
If you're willing to tackle it, it might be useful to add some examples of the various input bindings in the gallery. The only one we have now is a bit more complicated than I'd like it to be. |
(That would also lead to fewer N/A entries in the table!) |
@jakevdp I also was going to add this as just a good interaction example. (you are the original author of the vega example but I can't quite get the interval select to work when you select from the scatter and the bars adjust. |
I totally agree. I will try to make a compound chart that has drop down radio buttons, and the rest. |
We do have a version of that in the gallery: https://altair-viz.github.io/gallery/seattle_weather_interactive.html |
🤦 totally missed this. |
Do you think it is possible to change the x or y fields through a selection? I was thinking of this example Scatter Plot With Varying Dimension. I think this is possible with with an expression referring to the signal value. If it is possible it could be really helpful as example of a selection not referring to an encoding. If not, I am still going to use this movie dataset because it's rich scatter plot that benefits from filters and highlights based on inputs. I can do radio buttons to highlight movies of a certain imdb rating. Maybe a slider to filter the gross total of each film. I probably won't recreate the null values though that is a nice feature. |
No, that's not possible in Vega-Lite. |
You can work around it by stacking the two columns, adding an indicator variable, and filtering on that indicator variable. |
One of the issues with bindings is that they are not initialized properly, and do not apply any selection or filtering until the user interacts with them. This is particularly problematic in the case of multiple bindings, because you have to click all of them at least once before they will interact properly. That's one reason I haven't done much with docs or examples of bindings up to this point. It's being addressed in vega-lite: see vega/vega-lite#4139 |
Ok, I reformatted the example to avoid the initialization problem and focus on teaching how the bindings can work in different ways. I recommend building the gallery page to view it. The issue I ran into was that the dates in the data file are "4-Mar-74" which means i really needed a function to parse them and I couldn't use an expression. I thought I found a clever workaround to download the data into a dataframe first but it appears that did not work in CI (it did work locally). I will try and fix the build error but for now you can sample it. |
Yeah, we try to avoid anything requiring HTTP access in the example scripts, so that tests can be run in contexts with no web access. Vega-Lite will parse the date properly if it's used in a temporal encoding within the chart. If you're not using the column in an encoding but you still want it parsed as a date, you can use the |
OK Everything is all set now I think. We have a solid example of all the bindings and a decent write up of how the bindings actually work and connect to the selections. Let me know what you think happy to keep tinkering or we can brainstorm some more examples. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! A couple more minor comments and then we can merge.
@@ -1,19 +1,31 @@ | |||
.. currentmodule:: altair | |||
|
|||
.. _user-guide-selections: | |||
.. _user-guide-interactions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the user-guide-selections
cross reference is used a couple times elsewhere in the docs. Since you're renaming it here, it should be renamed elsewhere as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed this in previous. Updated found one reference as stated above.
doc/user_guide/interactions.rst
Outdated
^^^^^^^^^^^^^^^^^^^^^ | ||
With single selections, an input element can be added to the chart to establish a binding between the input and the selection. | ||
|
||
For instance, using our example from above a dropdown can be used to highlight cars from a specific :origin: : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change :origin:
to ``origin``
? Or just origin
?
1. Find all references to `user-guide-selections` and update to refer to the new page name 2. change coding style on chart reference in interactions.
All set on latest commit. If I am too much trouble you can throw me another one from #1060. |
Looks good – thanks so much for all your work on this! |
This pull request is to facilitate discussion of the binding documentation for which documentation help was requested in #1060
this has been my approach:
interactions
.I am attaching a small screen recording of the two examples:
Opening the PR for general feedback I don't think its ready but I need some ideas on next steps.