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

Add interactor mark selection to vgplot #158

Closed
wants to merge 1 commit into from

Conversation

spren9er
Copy link
Contributor

@spren9er spren9er commented Aug 27, 2023

Why is this pull request necessary?

Currently, when using interactors in vgplot, you need to make sure that the mark you interact with is the last one in your mark stack. This only allows to have interactive behavior with rudimentary plots. Several use cases can't be implemented in vgplot, e.g. having interactors with plots that have

  • text marks in top layer (charts with labels)
  • decorator marks in top layer (grid overlay)

What does this pull request cover?

  • Add optional index attribute for interactors like toggle, highlight, interval and nearest for specific mark selection
  • Add peers attribute to toggle interactor — analog to interval interactors (makes it possible to use toggle in conjunction with charts with text labels)
  • Update highlight-toggle.yaml example (Note: Previously, it was not possible to have toggle behavior for updated chart specification)
    • Add grid mark
    • Add text mark (bar labels)
    • Show index usage
  • Update documentation
    • Add note that mark indexes can be used for selection
    • Add index attribute to interactors
    • Add peers attribute to toggle interactor

How does it work?

Still — by default — interactors are used for the most recently added mark. However, when providing an index to an interactor, the corresponding mark in mark stack of plot will be selected.

Breaking changes

None, as existing API has not changed.

Examples

  • See new higlight-toggle.yaml

  • Example hexbin.yaml could have an intervalXY interactor (currently not possible because of hex grid overlay)

    - mark: hexbin
      data: { from: flights, filterBy: $query }
      x: time
      y: delay
      fill: { count: }
      binWidth: 10
    - mark: hexgrid
      binWidth: 10
    - select: intervalXY
      as: $query
      index: 0

@@ -7,29 +7,37 @@ import { Nearest } from '../interactors/Nearest.js';

function interactor(InteractorClass, options) {
return plot => {
const mark = plot.marks[plot.marks.length - 1];
const mark = findMark(plot.marks, options.index);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach has some possible leakage: the index is used to find the mark, but the index is also passed as an option to the interactor class itself. The index is not currently an option that is formally accepted by those classes; if it were added in the future it would have to conform exactly with how it is being used here.

@jheer
Copy link
Member

jheer commented Aug 29, 2023

Thanks for the PR! I see two separate additions here:

  1. Expose a peers option for the toggle interactor. This looks good to me!
  2. Make marks index-addressable by interactors. I'm not (yet) fully convinced this is necessary. In terms of design, exposing integer indices could be error-prone and brittle. An alternative might be to allow marks to have unique names/ids and let interactors refer to those instead.

Moreover, is addition 2 just a syntactic nicety? One should be able to include an interactor directly after its target mark, in the middle of a list of marks (they don't have to be at the end of a specification). So I'm not yet sure why the mentioned use cases can't be implemented as-is.

@spren9er
Copy link
Contributor Author

spren9er commented Sep 1, 2023

  1. Ok, I created another pull request for adding peers attribute to Toggle, see Add peers attribute to toggle interactor #164.
  2. Thanks for clarification! I was not aware that one can place interactors in the middle of marks.
    This PR was not about adding syntactic nicety, but about adding functionality. It was not clear to me, that it is possible to have interactors between marks. Thus, this PR is obsolete.

@spren9er spren9er closed this Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants