Skip to content

Commit

Permalink
Remove non-working example of empty selections
Browse files Browse the repository at this point in the history
  • Loading branch information
joelostblom committed Oct 3, 2024
1 parent aa3b283 commit 6018196
Showing 1 changed file with 10 additions and 48 deletions.
58 changes: 10 additions & 48 deletions doc/user_guide/interactions/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -579,71 +579,34 @@ Parameter Composition
Altair also supports combining multiple parameters using the ``&``, ``|``
and ``~`` for respectively ``AND``, ``OR`` and ``NOT`` logical composition
operands.
These parameter compositions can be used with both filters and conditions in Altair.
In the following example,
only the points that fall within the interval selections of both the scatter plots
will be counted in the bar chart
(so you will need to make a selection in both charts
before the bars shows up).

.. altair-plot::

# empty=False ensure that no points are selected before a selection is drawn
brush = alt.selection_interval(empty=False)
brush2 = alt.selection_interval(empty=False)

points = alt.Chart(cars).mark_point(size=10).encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
color='Origin:N'
)

points2 = points.encode(
x='Acceleration:Q',
y='Miles_per_Gallon:Q',
)

bars = alt.Chart(cars).mark_bar().encode(
x='count()',
y='Origin:N',
color='Origin:N'
).transform_filter(
brush & brush2
)

(points.add_params(brush) | points2.add_params(brush2)) & bars

To illustrate how a more complex parameter composition
can be applied to a conditional encoding,
we can return to our heatmap example.
Let's construct a scenario where there are two people who can make an interval
Returning to our heatmap examples,
we can construct a scenario where there are two people who can make an interval
selection in the same chart. The person Alex makes a selection box when the
alt-key (macOS: option-key) is selected and Morgan can make a selection
box when the shift-key is selected.
Now, we color the chart marks when they fall within Alex's or Morgan's
selection, but not both's
We use :class:`BrushConfig` to give the selection box of Morgan a different
style.
Now, we color the rectangles when they fall within Alex's or Morgan's
selection
(note that you need to create both selections before seeing the effect).
Here, we also use We use :class:`BrushConfig` to give the selection box of Morgan a different
style to be able to tell them apart.

.. altair-plot::

alex = alt.selection_interval(
on="[pointerdown[event.altKey], pointerup] > pointermove",
empty=False,
name='alex'
)
morgan = alt.selection_interval(
on="[pointerdown[event.shiftKey], pointerup] > pointermove",
mark=alt.BrushConfig(fill="#fdbb84", fillOpacity=0.5, stroke="#e34a33"),
empty=False,
name='morgan'
)

exlusive_or = (alex | morgan) & ~(alex & morgan)

alt.Chart(cars).mark_rect().encode(
x='Cylinders:O',
y='Origin:O',
color=alt.when(exlusive_or).then("count()").otherwise(alt.value("grey")),
color=alt.condition(alex | morgan, 'count()', alt.ColorValue("grey"))
).add_params(
alex, morgan
).properties(
Expand All @@ -653,10 +616,9 @@ style to be able to tell them apart.

With these operators, selections can be combined in arbitrary ways:

- ``alex | morgan``: to select the rectangles that fall inside either
Alex's or Morgans' selection.
- ``~(alex & morgan)``: to select the rectangles that fall outside
Alex's and Morgan's selections.

- ``alex | ~morgan``: to select the rectangles that fall within Alex's
selection or outside the selection of Morgan

Expand Down

0 comments on commit 6018196

Please sign in to comment.