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

Tooltip is not working with condition #3196

Closed
sfc-gh-cheliu opened this issue Sep 18, 2023 · 8 comments
Closed

Tooltip is not working with condition #3196

sfc-gh-cheliu opened this issue Sep 18, 2023 · 8 comments
Labels

Comments

@sfc-gh-cheliu
Copy link

Error message:
SchemaValidationError: Tooltip has no parameter named 'condition' Existing parameter names are: shorthand bin format title aggregate condition formatType type bandPosition field timeUnit See the help for Tooltip to read the full description of these parameters

Repro:
selection_chart.encoding.tooltip[0].condition = alt.condition(alt.datum.type1 > 0, 'type1', alt.value(''))
or
"tooltip": [alt.Tooltip('Date'), alt.Tooltip('type1:Q', condition=alt.condition(alt.datum.type1 > 0, 'type1', alt.value('')))]

@binste
Copy link
Contributor

binste commented Sep 19, 2023

I'm not sure why this fails but you should be able to achieve the same thing by calculating a new field using transform_calculate and then using that one in the tooltip instead of type1. Would that work for you?

@sfc-gh-cheliu
Copy link
Author

@binste Thanks, that's good to know. Actually, I want to filter out zero/nan values in the tooltip and possibly sort the tooltip by values: vega/vega-lite#9152, so I'm not sure whether condition could satisfy this need (I doubt it will still show the field in the tooltip anyway, just with a different value?). I've had some conversation with @joelostblom here #2393. Appreciate it if you could give some guidance for this!

@binste
Copy link
Contributor

binste commented Sep 19, 2023

I never tried setting a condition on a tooltip but I'd expect that it would still show an entry in the tooltip for that field but you can choose what value is shown but that's just a guess. I'm also curious to see if someone knows more in the Vega-Lite issue you opened :)

@sfc-gh-cheliu
Copy link
Author

@binste Thanks. From your knowledge, would this be possible by modifying the altair side only? I'm trying to understand how altair passes these tooltip specification to the frontend, for now I only see it's a list of Tooltip objects with shorthand set to the field/column name:

[ 0:"Tooltip({ shorthand: 'Date' })" 1:"Tooltip({ shorthand: 'type1' })" 2:"Tooltip({ shorthand: 'type2' })" 3:"Tooltip({ shorthand: 'type3' })" 4:"Tooltip({ shorthand: 'type4' })" 5:"Tooltip({ shorthand: 'type5' })" 6:"Tooltip({ shorthand: 'type6' })" 7:"Tooltip({ shorthand: 'type7' })" 8:"Tooltip({ shorthand: 'type8' })" ]

@binste
Copy link
Contributor

binste commented Sep 19, 2023

Altair produces Vega-Lite specifications, see Altair Internals. These specifications are often passed to vega-embed to be rendered in a frontend such as when you display an Altair chart in a Jupyter notebook.

This means that you can't modify Altair to change the rendering as Altair is not involved in the rendering process at all. Hence, what you are looking for is only possible in Altair if it is possible in Vega-Lite.

I hope this helps.

@sfc-gh-cheliu
Copy link
Author

sfc-gh-cheliu commented Sep 19, 2023

@binste This is super helpful, thanks!
A QQ: what is the best approach to test local changes of vega-lite? At the beginning I followed the instructions in https://github.com/vega/editor - running yarn link in vega-lite and yarn link vega-lite in editor, but there's an error and I opened an issue here vega/editor#1366. It seems related to vega/editor#1346 but I've tried cloning an older version mentioned there but no luck.

@sfc-gh-cheliu sfc-gh-cheliu changed the title Tooltip is not working with condition it's a listed parameter of the class Tooltip is not working with condition Sep 19, 2023
@binste
Copy link
Contributor

binste commented Sep 20, 2023

Sorry I can't help you with that as I'm not very familiar with developing Vega-Lite. But using the editor in the way you described it is the best way I'm aware of.

@joelostblom
Copy link
Contributor

It seems like although the tooltip encoding supports multiple fields there is no way to express this in a condition. This would need to be added in VL and the relevant issue tracking it is now vega/vega-lite#8750. I'm closing this as there is no action to take in altair. The functionality will be available after it is implemented in VL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants