question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multi selection without pressing shift key?

See original GitHub issue

Is it possible to do a multi selection without holding down the shift key?

I would like to single click on fields in the legend chart to toggle selection. Normal behavior is shift-click.

import altair as alt
from vega_datasets import data

cars = data.cars.url

selection = alt.selection_multi(fields=['Origin', 'Cylinders'])

color = alt.condition(selection,
                      alt.Color('Origin:N', legend=None),
                      alt.value('lightgray'))

scatter = alt.Chart(cars).mark_point().encode(
    x='Horsepower:Q',
    y='Miles_per_Gallon:Q',
    color=color,
    tooltip='Name:N'
)

legend = alt.Chart(cars).mark_rect().encode(
    y=alt.Y('Origin:N', axis=alt.Axis(orient='right')),
    x='Cylinders:O',
    color=color
).add_selection(
    selection
)

scatter | legend
image

Things I have tried that had no effect:

selection = alt.selection_multi(on='click', fields=['Origin', 'Cylinders'])
selection = alt.selection_multi(on='mousedown', fields=['Origin', 'Cylinders'])

Using either of

selection = alt.selection_multi(on='click[event.altKey]', fields=['Origin', 'Cylinders'])
selection = alt.selection_multi(toggle='event.altKey', fields=['Origin', 'Cylinders'])

I can change the modifier from shift to alt, but I don’t understand how I can enter no modifier. If I use toggle='' the legend reacts as if using toggle=False.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, May 15, 2020

This part of the docs is generated directly from the descriptions within the Vega-Lite schema, and we have no mechanism to make altair-specific spot-corrections like this. But the docs do mention that toggle takes a string containing a vega expression. Perhaps its not clear that 'true' (the vega expression) is different from true (the boolean default in Vega-Lite, represented by True in Python). If you’re interested, you could send a pull request to the Vega-Lite project clarifying the part of that relevant to Vega-Lite, and it would be reflected in Altair once Altair wraps the Vega-Lite release containing that update.

Regarding the fact that vega-lite true is equivalent to Python True, I’m not certain how we can better convey that given that the docs are auto-generated.

We could theoretically override Vega-Lite docs with Python-specific versions, but that’s not a maintenance burden that I’m willing to take on.

0reactions
morbergcommented, May 21, 2020

The doc modification is now in the latest vega-lite release (4.12.2)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I select multiple objects without holding down shift?
Go to the File - Options and select the icon for multiple objects selection. Once ticked, you can slect the multiple objects without...
Read more >
Unable to use Shift key to select multipl… - Apple Community
Unable to use Shift key to select multiple items in between for selection ; Step 1: Finder > Click Go at the top...
Read more >
can't use shift key to select multiple photos, files or objects
To select multiple files and folders, you hold down Control then click on the icon or image. Shift will simply select everything.
Read more >
Selecting multiple list items - ConfTool
Click the first item, then press the SHIFT key and hold it. Click the last item and release the SHIFT key. To select...
Read more >
How do I select multiple items when there are no check boxes ...
Hold down the shift key and click on the last item in a row that you want selected. The second way to do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found