-
Notifications
You must be signed in to change notification settings - Fork 611
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
Interacting with Legends & Axes #1657
Comments
Thanks for asking. This will likely be a part of v2.x release. |
Interactions with legends was a bit tricky with vega (at least v2). Has that changed? cc @arvind |
Yes, with Vega 3, axes and legends can now be interacted with. So this should be supported with Vega-Lite 2.0. The open question with interactions, however, is what defaults should be. For example, if a legend is added to the visualization, should it be interactive by default? Should the interaction it supports also extend to interacting with the plotted data points as well? Etc. |
We should definitely try to support these kinds of interaction! Not sure if interactive-by-default is the right way to go, but we would need to be able to provide explicit control in either case. This relates to the selection There is also the potential issue that users might just want to be able to (more or less) say: "I want to enable selections on this legend (or axis)" without having to think about the appropriate selection type (interval, etc). |
I don't think we want any interactions by default. The problem is that I don't know what channel we would use (e.g. for highlighting) and how we resolve conflicts if the user uses that channel to encode data. |
RE: default interaction, let's create a new issue (#1658) to discuss that |
For what it's worth, NVD3 chart legends are interactive by default. |
We have this on the roadmap for 2.1 |
Given that we will follow semantic versioning, it is probably more accurate to say "very early versions of 2.x minor release". |
I think this would be awesome to improve some of the default interactions in pdvega. CC @jakevdp |
Here is the Vega example https://vega.github.io/vega/examples/interactive-legend/ |
I need to enhance some of my Vega specs to be more interactive, so I experimented migrating them to Vega-Lite, allowing me to easily add zoom (https://vega.github.io/vega-lite/docs/zoom.html). I was previously only (somewhat) familiar with Vega specs, so this is the first time I've tried Vega-Lite. My port has been mostly successful with the notable exception of my Vega spec's use of https://vega.github.io/vega/examples/interactive-legend/. After searching, I found this open issue 1657. Do you have any practical recommendations on how I might proceed? I think my options are:
I'm leaning slightly towards option 3, but before I jump into this rabbit hole, I thought I'd solicit any helpful advice. Thanks in advance, |
You can try to manually change a spec to manually perform 3 to see how much change is needed and how you might do it automatically. I think it will be the easiest option. Please report back so we can see how much code we need to add to Vega-Lite to add this feature. |
+1! This would be an awesome feature to add. In keeping with Vega-Lite philosophy, maybe just a Thanks, |
During the Altair tutorial yesterday, I realized you could hack a clickable legend in the current release using selections 😄 {
"config": {"view": {"width": 400, "height": 300}},
"hconcat": [
{
"mark": "point",
"encoding": {
"color": {"type": "nominal", "field": "Origin", "legend": null},
"x": {"type": "quantitative", "field": "Horsepower"},
"y": {"type": "quantitative", "field": "Miles_per_Gallon"}
},
"transform": [{"filter": {"selection": "legend"}}]
},
{
"mark": "point",
"encoding": {
"color": {
"condition": {
"type": "nominal",
"aggregate": "min",
"field": "Origin",
"legend": null,
"selection": "legend"
},
"value": "lightgray"
},
"y": {"type": "nominal", "field": "Origin", "title": null}
},
"selection": {
"legend": {
"type": "multi",
"encodings": ["color"],
"on": "click",
"toggle": "event.shiftKey",
"resolve": "global",
"empty": "all"
}
}
}
],
"data": {"url": "data/cars.json"},
"$schema": "https://vega.github.io/schema/vega-lite/v2.4.1.json"
} |
Nice hack! It would be great to eventually have VL/Altair produce true interactive legends that Vega already supports: https://vega.github.io/vega/examples/interactive-legend/ |
Although, the VegaLite code for interactive legend seems a bit obscure with event handling. Adding |
https://tech.shutterstock.com/rickshaw/ is another library that has some support for this. |
@arvind - if interacting with legend is simply applying encoding projection to the channels with legend, I'm wondering how our grammar would extend to interacting with axes. Simplying having a projection on x and y won't convey that users want the interaction to apply to axis, not the plot (like the axis brush in this Vega example). |
I see a couple of different ways of enabling interactive legends in Vega-Lite:
I've been thinking about interactive legends long enough that it's no longer clear which set of tradeoff are more desirable, so I'd love folks' thoughts! |
Thanks for working through this! My preference is to define interactive legend support in terms of our existing selection abstraction. Once suitably defined, we could later consider syntactic sugar / shortcuts. Alternatively, higher level APIs like Altair could define their own shortcuts, like the existing I would expect legend selections to be similar to bound input widgets: a specific opt-in condition. So, I would not expect a legend to automatically become interactive if a selection was defined over it's domain; I would instead expect to specify a selection parameter indicating that legend "binding" was desired. Perhaps we could even reuse the existing I think selections that map across multiple legends are complicated to reason about given the partial population semantics. Might it be simpler to only allow selections for individual legends, and require users to use boolean operators to combine multiple selections if desired? In this case, it would be a schema violation to define a legend-bound selection over multiple fields / encodings that are not contained within a single legend. As previously discussed for bound widgets, I would also expect interactive legend selections to not include direct manipulation events on the chart itself by default. I would also be fine with an initial implementation that does not support the combination of interactive legends and direct manipulation in the chart (unless achieved through boolean combinations of multiple, separately defined selections). Obviously there is some overhead for users to learn that, for example, they need to use single or multi selections for symbol legends and interval selections for quantitative legends. (Note that I don't see the latter included in current proposals, but we should at least track it for the future?) I'm not too concerned about selection type overhead, but perhaps there is an allowable shortcut here... Could one omit the selection type if bound to a legend, and infer it from the encoding information? Doesn't seem a high priority to me, though. |
On the topic of interactive color gradient legends, I mocked up a Vega spec that includes a legend-bound brush. Rather than "inject" a mark into a legend group, it simply layers a brush mark on top, while getting the necessary geometry information as part of event handling. There are two problems remaining, though:
UPDATE (Sep 14): I opened a PR on d3-scale to add |
Hi all - @jakevdp pointed me to this thread based on a conversation we were having about the value of non-linear interactive color legends. Just wanted to add my support for:
For some context/motivation, I spoke about the relationship between color map and the question you want to ask the data (different color maps ask different questions of the data) in this talk at SciPy in 2018. At work, I've created interactive color legends for data vis-based analysis tools. (on a related topic, I've also been finding it quite useful recently to discretize my continuous colormaps a la Adam Pearce's coloring maps blog post (@1wheel on github). thanks all! |
Thanks for the input @zanarmstrong! As discussed above, we're looking into supporting interaction with color gradient legends too, so these are useful points to keep in mind. Discretized color maps (e.g., using |
Just found this, related, though more about axis rather than legends #7394 EDIT: Turns out to be same issue, so adding example inline here It is already possible to bind selection to a legend (https://vega.github.io/vega-lite/docs/bind.html) However sometimes it is a lot more convenient to be interaction with axis label instead, especially when the data point represented is so small that it is very difficult to select it otherwise. Here's an illustration of the problem. Here's what I'm thinking of "params": [{
"name": "currency",
"select": {"type": "point"},
"bind": "axisLabel"
}] |
NVD3, and possibly other charting libraries, allow users to filter charts by interacting with the chart legend:
This is useful for exploratory analysis, and makes toggling categories very easy.
Feature
Is it planned/possible for vega-lite charts to have interactive legends for filtering chart data?
The text was updated successfully, but these errors were encountered: