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

[WIP] scrollable dropdown menus #8

Merged
merged 2 commits into from Mar 15, 2017

Conversation

n-riesco
Copy link
Owner

@n-riesco n-riesco commented Dec 1, 2016

This PR addresses one of the points in plotly#810 :

  • provides a helper class ScrollBox (that could be reused to provide scroll boxes elsewhere)

  • implements scrollable dropdown menus:

    • scrollbars are added only if needed
    • user can scroll by dragging a scrollbar
    • user can scroll by dragging the scrollbox (menu buttons skip the click triggered by dragend)

TODO

  • Add jasmine tests

* Don't `Lib.setTranslate` the button container and update the call to
  `Lib.setTranslate` for each button accordingly.

* This change will let us use `Lib.setTranslate` on the button container
  to implement a scroll box.
@n-riesco
Copy link
Owner Author

n-riesco commented Dec 1, 2016

Here's an example to test the functionality:

// Adapted from https://github.com/plotly/plotly.js/pull/770#issuecomment-234669383

var direction = 'down',
    data = [],
    layout = {
        updatemenus: [{
            direction: direction,
            buttons: [{
                method: 'restyle',
                args: ['line.color', 'red'],
                label: 'red'
            }, {
                method: 'restyle',
                args: ['line.color', 'blue'],
                label: 'blue'
            }, {
                method: 'restyle',
                args: ['line.color', 'green'],
                label: 'green'
            }]
        }, {
            y: 0.7,
            direction: direction,
            buttons: []
        }]
    };

for (var i = 0, n = 20; i < n; i++) {
    data.push({
        y: Array.apply(null, Array(10)).map(() => Math.random()),
        line: {
            shape: 'spline',
            color: 'red'
        },
        visible: i === 0,
        name: 'Data set ' + i,
    });

    var visible = Array.apply(null, Array(n)).map((_, j) => i === j);

    layout.updatemenus[1].buttons.push({
        method: 'restyle',
        args: ['visible', visible],
        label: 'Data set ' + i
    });
}

Plotly.plot('graph', data, layout);

@etpinard
Copy link

etpinard commented Dec 1, 2016

Nice solution! Go ahead and move that PR to the main repo!

@n-riesco n-riesco merged commit 5a4ecf3 into master Mar 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants