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

Vega Expressions for Lasso Selection #3388

Merged
merged 17 commits into from
Mar 8, 2022
Merged

Conversation

dvmoritzschoefl
Copy link
Contributor

@dvmoritzschoefl dvmoritzschoefl commented Jan 14, 2022

lassoexample

This PR includes the following vega expressions:

  • lassoPath (generates a svg path from a lasso signal, can be directly used on a path mark)
  • lassoAppend (handles the logic to append a point to the lasso signal)
  • intersectLasso (performs the intersection tests for the lasso and returns the appropriate tuples)

There is an example specification added that allows to test the lasso (called lasso.vg.json). If this PR gets approved, I will create another PR for vega-lite that includes the generator for lasso selections.

Copy link
Member

@arvind arvind left a comment

Choose a reason for hiding this comment

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

Hi @dvmoritzschoefl, this PR looks like a great start. I've left some line/block-level suggestions but three high-level thoughts:

  1. I think it'd be useful to have these lasso functions remain as general purpose as possible rather than tightly coupled with Vega-Lite selections. So, I recommend removing any references to selections here. Instead, have this function return an array of scene graph items within the lasso and, in the expression string generated byVega-Lite, pass this array to the vlSelectionTuples function introduced in add expr functions for extensional selection predicates #3009 and improved in Optimize selection functions for ID-only stores #3397 to extract SELECTION_ID and populate the selection stores.

  2. Relatedly, I'm not sure I'm totally following why we have this function inverting pixels -> data coordinates. Can we not stay entirely in pixel space for the entirety of the hit testing process (i.e., an intersectLasso function instead)? I'm imagining the same steps you have currently (start with a lasso path, calculate the bounding box, intersect it with the scenegraph, and then validate which pointInPolygon), but you'd never make a roundtrip to data space at all. Instead, and following (1) above, we'd only go into data space once we have all the scene graph items that fall within the lasso and just to extract the SELECTION_ID. Does this make sense? I could very well believe I'm missing something though.

  3. A more minor point: in Vega and Vega-Lite, we default to a 2-space indent. Do you mind updating this file to follow that format? Thanks!

packages/vega-functions/src/functions/lasso.js Outdated Show resolved Hide resolved
packages/vega-functions/src/functions/lasso.js Outdated Show resolved Hide resolved
packages/vega-functions/src/functions/lasso.js Outdated Show resolved Hide resolved
dvmoritzschoefl and others added 6 commits January 24, 2022 11:31
Co-authored-by: Arvind Satyanarayan <arvind@users.noreply.github.com>
Co-authored-by: Arvind Satyanarayan <arvind@users.noreply.github.com>
Co-authored-by: Arvind Satyanarayan <arvind@users.noreply.github.com>
@dvmoritzschoefl
Copy link
Contributor Author

Hi @dvmoritzschoefl, this PR looks like a great start. I've left some line/block-level suggestions but three high-level thoughts:

  1. I think it'd be useful to have these lasso functions remain as general purpose as possible rather than tightly coupled with Vega-Lite selections. So, I recommend removing any references to selections here. Instead, have this function return an array of scene graph items within the lasso and, in the expression string generated byVega-Lite, pass this array to the vlSelectionTuples function introduced in add expr functions for extensional selection predicates #3009 and improved in Optimize selection functions for ID-only stores #3397 to extract SELECTION_ID and populate the selection stores.
  2. Relatedly, I'm not sure I'm totally following why we have this function inverting pixels -> data coordinates. Can we not stay entirely in pixel space for the entirety of the hit testing process (i.e., an intersectLasso function instead)? I'm imagining the same steps you have currently (start with a lasso path, calculate the bounding box, intersect it with the scenegraph, and then validate which pointInPolygon), but you'd never make a roundtrip to data space at all. Instead, and following (1) above, we'd only go into data space once we have all the scene graph items that fall within the lasso and just to extract the SELECTION_ID. Does this make sense? I could very well believe I'm missing something though.
  3. A more minor point: in Vega and Vega-Lite, we default to a 2-space indent. Do you mind updating this file to follow that format? Thanks!
  1. I used the functions you mentioned, the function is now called 'intersectLasso' instead and does not use data space
  2. solved
  3. updated to 2-space indent

attached is a working lasso spec
lasso.vg.zip

Copy link
Member

@arvind arvind left a comment

Choose a reason for hiding this comment

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

Hi @dvmoritzschoefl, thanks for making the changes! Looks like we're pretty close. I left a handful of comments, just to make the code a bit more functional rather than imperative. Two other high-level comments:

  • packages/vega/test/specs-valid.json is currently deleted but shouldn't be.
  • docs/*.js will be built as part of the final version release, so you don't need to include them in this PR.

packages/vega-functions/src/functions/lasso.js Outdated Show resolved Hide resolved
packages/vega-functions/src/functions/lasso.js Outdated Show resolved Hide resolved
packages/vega-functions/src/functions/lasso.js Outdated Show resolved Hide resolved
packages/vega-functions/src/functions/lasso.js Outdated Show resolved Hide resolved
packages/vega-functions/src/functions/lasso.js Outdated Show resolved Hide resolved
dvmoritzschoefl and others added 6 commits January 26, 2022 16:32
Co-authored-by: Arvind Satyanarayan <arvind@users.noreply.github.com>
Co-authored-by: Arvind Satyanarayan <arvind@users.noreply.github.com>
Co-authored-by: Arvind Satyanarayan <arvind@users.noreply.github.com>
Co-authored-by: Arvind Satyanarayan <arvind@users.noreply.github.com>
Co-authored-by: Arvind Satyanarayan <arvind@users.noreply.github.com>
Co-authored-by: Arvind Satyanarayan <arvind@users.noreply.github.com>
@lgtm-com
Copy link

lgtm-com bot commented Jan 26, 2022

This pull request introduces 2 alerts when merging df07358 into 0a56954 - view on LGTM.com

new alerts:

  • 2 for Syntax error

* @returns the svg path command that draws the lasso
*/
export function lassoPath(lasso) {
return (lasso ?? []).reduce((svg, [x, y], i) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

using entries().reduce gave an error for me, this version works
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce

@dvmoritzschoefl
Copy link
Contributor Author

Hi @dvmoritzschoefl, thanks for making the changes! Looks like we're pretty close. I left a handful of comments, just to make the code a bit more functional rather than imperative. Two other high-level comments:

  • packages/vega/test/specs-valid.json is currently deleted but shouldn't be.
  • docs/*.js will be built as part of the final version release, so you don't need to include them in this PR.

Yes sry I made a mistake checking these files in, should be ok by now. I changed your suggestions accordingly and made sure the lasso still works.

Copy link
Member

@arvind arvind left a comment

Choose a reason for hiding this comment

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

Thanks @dvmoritzschoefl! The updates look good to me, and apologies for my malformed suggestions — the dangers of writing JavaScript code on-the-fly in the GitHub editor textbox 🤦

I've cc'ed @jheer to take a final look in case he notices anything I missed, and then we can merge 🙂

@arvind arvind requested a review from jheer January 27, 2022 14:24
@dvmoritzschoefl
Copy link
Contributor Author

@arvind very nice, I will adjust the vega-lite PR to those changes tomorrow and ping you when I am finished

@jheer jheer merged commit 9281721 into vega:master Mar 8, 2022
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.

None yet

3 participants