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

Persistent point selection with transforms compatibility #2163

Merged

Conversation

etpinard
Copy link
Contributor

These few commits essentially addresses #2135 (comment) while cleaning up a few things in event data land - mainly making hover and selection event data reuse the same logic.


In brief, this PR adds pointIndex event data field and uses its value to fill in selectedpoints with input indices. Note that pointIndex is the same as pointNumber in all non-transformed traces except histograms. With the help of @monfera 's indexToPoints, this part was relatively easy 🎉

I chose to add a new field instead of fixing the existing pointNumber field to retain backward compatibility (I suspect a certain support-assets project we did back in May would be break if we tweaked pointNumber 😏 ), but yeah pointIndex is what users should use from now on. We could even 🔪 pointNumber in v2.

pointIndex also has a multi-value version called pointIndices for histogram traces and aggregation transforms.

I'll wait for @alexcjohnson to 👍 the commits below before pushing new test cases and incorporating them in #2135

cc @monfera

- 🔪 its select method and reuse Scatter.select instead
  which is much DRYer.
- 🔪 is select method, reuse Scatter.select instead
- using same event-data pipeline for hover and select revealed
  an inconsistency: hover data includes the raw input coords whereas
  selection data includes the scaled coords (as in calcdata).
- tagSelected make heavy use of the transforms _indexToPoints
  map object to determine how input index (called pointIndex)
  are mapped to calcdata index (called pointNumber).
- use pointIndex (not pointNumber) while filling up selectedpoints array
  to match input indices.
- Use tagSelected in scatter, box, and histogram calcSelection methods
  taking care of all trace types that support selections.
- similar to pointNumber and pointNumbers, make the distinction
  between 1-to-1 input to selection/hovered pt and many-to-1 maps
  like for histogram traces and aggregation transforms.
@etpinard
Copy link
Contributor Author

Referencing #2126 (review) which first put forward something similar to this PR's pointIndex.

// Note also that the hover labels show the scaled version.
//
// What about the 'raw' input coordinates?
// Should we include them in parallel here or replace a/b/c with them?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the scaled (normalized) coords are the most useful here, and folks can get the raw data back out easily enough using the indices, lets not add them here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in c8d715b

src/lib/index.js Outdated
}

function isPtIndexValid(v) {
return lib.validate(v, {valType: 'integer', min: 0});
Copy link
Collaborator

Choose a reason for hiding this comment

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

ha, that's super 🌴 but might be a bit slow for this 🌶 path - non-negative integers are just
typeof v === 'number' && v >= 0 && v % 1 === 0 right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

🐎 > 🌴 in 🌶️ code paths

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh hmm I guess this is looking at user input so it should be isNumeric(v) instead of typeof v === 'number' ie allow index '1' as well as 1

Copy link
Contributor Author

@etpinard etpinard Nov 16, 2017

Choose a reason for hiding this comment

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

done in c8d715b 451778b

if(Array.isArray(trace.selectedpoints)) {
var ptNumber2cdIndex = {};

// make histogram-specific pt-number-to-cd-index map object
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't we want this available for use later, ie without a recalc? I would have imagined creating this in the main binning loop and stashing it in the full trace, also possibly creating it as an array rather than a map, seems like that would be more efficient and would work just as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

don't we want this available for use later, ie without a recalc?

I don't think so. Calling restyle with selectedpoints has to trigger a recalc. On user selections, the calcdata items are mutated directly w/o needing to refer back to input data-array indices. Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would have imagined creating this in the main binning loop

Good call, done in -> 7543dc6

Copy link
Collaborator

Choose a reason for hiding this comment

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

Calling restyle with selectedpoints has to trigger a recalc.

hmm ok, I was hoping we could avoid that but we can discuss optimizing that later.

@alexcjohnson
Copy link
Collaborator

💃

@etpinard etpinard merged commit a95e47b into persistent-point-selection Nov 16, 2017
@etpinard etpinard deleted the persistent-point-selection-compat-transforms branch November 16, 2017 19:21
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