Skip to content

Disable Diagonal Selection on cartesian zoombox drag #3923

Open

Description

@AdnanBoota

Hi Team Plotly,

I would like to enable the horizontal and vertical axis selection on bar/line charts, but I want to disable the diagonal selection – i.e. I don’t want to user to simultaneously select both axis, but only one at a time.

I have tried different solutions, but I could not get the desired effect. For example, setting fixedrange:true, disables either vertical or horizontal selection. But, I want to disable only diagonal selection, and keep both horizontal and vertical selections enabled.

Is it possible to have this feature for diagonal selection, like diagonalFixedRange:true? or have a flag to disable just the diagonal selection?

I'm using this library in ReactJS, the Plotly.js update will also ReactJS package?

Thank you very much for you help and the wonderful library 😊.

2019-05-30 13_26_42-Avatera Medical Center

Activity

  1. etpinard commented on May 30, 2019

    @etpinard
    Contributor

    Thanks for writing in!

    By select here I suspect you mean "zoombox" (as set via layout.dragmode: 'zoom'). In this case to achieve what you're looking for, we would probably need to either add an attribute similar to selectdirection but for dragmode: 'zoom' or expose some of these drag-zoom constants:

    // pixels to move mouse before you stop clamping to starting point
    MINDRAG: 8,
    // smallest dimension allowed for a select box
    MINSELECT: 12,
    // smallest dimension allowed for a zoombox
    MINZOOM: 20,

  2. AdnanBoota commented on May 30, 2019

    @AdnanBoota
    Author

    Hi etpinard,

    Thanks for your quick response :)

    Yes, you are right, it's in dragmode: 'zoom' which is the default behavior, and yes it would be great if you can add an attribute similar to selectdirection for dragmode: 'zoom'.

    Would it be possible to have an attribute to just enable/disable diagonal-selection? because the x-axis, y-axis selections are working perfectly with fixedrange:true, just only need to enable/disable diagonal.

    plotly.js/src/plots/cartesian/constants.js

    The MINZOOM constant, can also help for setting the threshold of selection, if easier, i would just only need MINZOOM for setting the threshold of diagonal-selection?

    Again Thanks!
    Adnan

  3. changed the title [-]Disable Diagonal Selection on Line and Bar Charts - fixedrange:true for diagonal-selection[/-] [+]Disable Diagonal Selection on cartesian zoombox drag[/+] on May 30, 2019
  4. added
    feature
    on May 30, 2019
  5. josephernest commented on Aug 8, 2023

    @josephernest

    Thanks @etpinard.
    Does anyone know if it is possible nowadays to only allow "d" (=diagonal=rectangular box zoom=no horizontal/no vertical zoom) also for dragmode: 'zoom' ? @alexcjohnson

    If not already possible, is there a dirty hack / monkeypatching to disable horizontal or vertical zoom ? And only allow rectangular (=diagonal) zoom?

    Maybe a modification of MINSELECT or MINDRAG?

  6. alexcjohnson commented on Aug 13, 2023

    @alexcjohnson
    Collaborator

    @josephernest this feature has yet to be implemented and I'm not aware of any hacks to achieve your goal. We'd be happy to accept a PR adding a zoomdirection attribute.

  7. josephernest commented on Aug 13, 2023

    @josephernest

    @alexcjohnson I'll look at this! Do you think that setting one of these to value 1 would do it?

     // pixels to move mouse before you stop clamping to starting point 
     MINDRAG: 8, 
      
     // smallest dimension allowed for a select box 
     MINSELECT: 12, 
      
     // smallest dimension allowed for a zoombox 
     MINZOOM: 20, 
    
  8. alexcjohnson commented on Aug 13, 2023

    @alexcjohnson
    Collaborator

    I kind of doubt it, but anyway the setting needs to be per-plot, so it would need to be applied at the point of use rather than in this constants file. I think we just need to find the logic around choosing x vs y vs d and have it ignore the disallowed flavors.

    BTW I gather @AdnanBoota has moved on, but if we want to support the original use case zoomdirection would need a value xy in addition to x, y, and d.

  9. self-assigned this
    on Jun 14, 2024
  10. removed their assignment
    on Aug 2, 2024
  11. EliasTalcott commented on Nov 18, 2026

    @EliasTalcott

    Hi @alexcjohnson! This feature would be really useful for a project I am working on. I'd be happy to pick it up if the team is still open to PRs.

    Is a new layout attribute zoomdirection with values x, y, d, and xy (and likely any as a default) still the desired direction here? I noticed selectdirection is a similar layout attribute for selections and uses h and v instead of x and y.

  12. alexcjohnson commented on Nov 18, 2026

    @alexcjohnson
    Collaborator

    Absolutely! And you're right, let me revise my comment about the options to support: selectdirection takes values h, v, d, and any. For consistency we should probably use those same values (h rather than x etc), and rather than adding combinations ad hoc is there a reason not to use a flaglist, so we'd support any of them, not just h+v but also h+d and v+d, as well as h+v+d which would be a synonym for any?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions