Skip to content

Allow clamping select mode to horizontal or vertical #2498

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

Closed
wants to merge 1 commit into from
Closed

Allow clamping select mode to horizontal or vertical #2498

wants to merge 1 commit into from

Conversation

RedShift1
Copy link

Here's some shitty code for feature request #2495. Use layout.dragclamp 'h' or 'v' to clamp the selection horizontally or vertically. There's some duplicated code now, perhaps those polygon manipulations should be moved into their own functions?

Use layout.dragclamp 'h' or 'v' to clamp the selection horizontally or
vertically.
@alexcjohnson
Copy link
Collaborator

Thanks for the PR! You're right though, we can do a bit better - first off, lets think about the attribute name: it doesn't apply to all drags, just selection drags; clamp may be OK, though I kind of like the sound of selectdirection or selectaxis better than selectclamp... dunno, @etpinard any other thoughts?

Next, we need layout.selectclamp (or whatever we call it) to be a recognized attribute here as valType: 'enumerated' with values ['h', 'v', ''] (or perhaps ['h', 'v', 'any']?), coerced from layout into fullLayout here.

Then, as you anticipated, we should avoid duplication. Something like:

var selectDirection = fullLayout.selectclamp;
if(!selectDirection) { // or !== 'any' if we go with that
    if(dy < Math.min(dx * 0.6, MINSELECT)) selectDirection = 'h';
    else if(dx < Math.min(dy * 0.6, MINSELECT)) selectDirection = 'v';
}

if(selectDirection === 'h') {
   // existing code
}
else if(selectDirection === 'v') {
    // ...
}
else {
    // ...
}

Lastly we'll need a test that covers the new functionality, probably here by dragging a diagonal (that would normally give a box constraining both dimensions) after having relayout into each mode and verifying (assertRange(selectedData.range, ...)) that you only constrain the expected dimension.

@RedShift1
Copy link
Author

Once you decide on a name I'll create seperate PRs for

  • Adding the attribute to the layout object
  • Moving the polygon calculations into separate functions
  • Re-implement the logic switching between clamped/non-clamped
  • Tests

@RedShift1
Copy link
Author

Are we good with the "selectdirection" name?

@etpinard
Copy link
Contributor

+1 for selectdirection: 'h' | 'v' | 'any' (the default)

@alexcjohnson
Copy link
Collaborator

superseded by #2506

@RedShift1 RedShift1 deleted the 2495-hv-select branch March 29, 2018 18:59
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.

3 participants