Skip to content

scrollable dropdown menus #1214

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2ec79e7
updatemenus: don't setTranslate button container
n-riesco Nov 25, 2016
5a4ecf3
updatemenus: add scroll bars if needed
n-riesco Nov 24, 2016
66e503c
updatemenus: Fix image test failure
n-riesco Jan 26, 2017
9a0aa64
Merge branch 'master' into pr-20161121-scrollable-dropdown-menus
n-riesco Jan 26, 2017
8df8fd6
updatemenus: Update copyright notice
n-riesco Jan 26, 2017
7057bc7
updatemenus: make ScrollBox#setTranslate public
n-riesco Jan 30, 2017
8d1f333
updatemenus: fix positioning of scrollbars
n-riesco Jan 30, 2017
563009b
updatemenus: center dropmenu on active option
n-riesco Jan 30, 2017
ef5210e
updatemenus: hide scrollbar if header clicked
n-riesco Jan 30, 2017
f17773f
updatemenu: ScrollBox#setTranslate to take pixels
n-riesco Jan 31, 2017
9e3ac1b
updatemenus: fix smooth dropdown folding
n-riesco Jan 31, 2017
13508da
updatemenus: handle mouse wheel events
n-riesco Jan 31, 2017
8ab3ebe
updatemenus: refactor where scrollbox is created
n-riesco Feb 1, 2017
4975401
updatemenus: add <rect> background to scrollbox
n-riesco Feb 1, 2017
3b17d1d
updatemenus: remove un/foldDropdownMenu
n-riesco Feb 2, 2017
b155a8a
updatemenu: fix computation of scrollbox size
n-riesco Feb 2, 2017
109f284
updatemenus: fix positioning of scrollbox
n-riesco Feb 3, 2017
e7c3ae3
Lib: Fix regexp in getTranslate
n-riesco Feb 3, 2017
89c615d
updatemenus: test scrollbox
n-riesco Feb 3, 2017
a554ea6
Merge branch 'master' into PR #1214
n-riesco Feb 3, 2017
79f1107
Drawing: test setTranslate works with negatives
n-riesco Feb 3, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updatemenus: fix positioning of scrollbox
* Account for the direction of the scrollbox to determine to which side
  the scrollbox will be anchored.
  • Loading branch information
n-riesco committed Feb 3, 2017
commit 109f2849c45b062cd5deea830b8d2c93309c1754
2 changes: 2 additions & 0 deletions src/components/updatemenus/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ function drawButtons(gd, gHeader, gButton, scrollBox, menuOpts) {
scrollBoxPosition.h = Math.max(menuOpts.openHeight, menuOpts.headerHeight);
}

scrollBoxPosition.direction = menuOpts.direction;

if(scrollBox) {
if(buttons.size()) {
drawScrollBox(gd, gHeader, gButton, scrollBox, menuOpts, scrollBoxPosition);
Expand Down
81 changes: 48 additions & 33 deletions src/components/updatemenus/scrollbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ ScrollBox.barColor = '#808BA4';
* @param {number} position.t Top side (in pixels)
* @param {number} position.w Width (in pixels)
* @param {number} position.h Height (in pixels)
* @param {string} [position.direction='down']
* Either 'down', 'left', 'right' or 'up'
* @param {number} [translateX=0] Horizontal offset (in pixels)
* @param {number} [translateY=0] Vertical offset (in pixels)
*/
Expand All @@ -88,48 +90,55 @@ ScrollBox.prototype.enable = function enable(position, translateX, translateY) {
w = this.position.w,
t = this.position.t,
h = this.position.h,
direction = this.position.direction,
isDown = (direction === 'down'),
isLeft = (direction === 'left'),
isRight = (direction === 'right'),
isUp = (direction === 'up'),
boxW = w,
boxH = h,
boxL, boxR,
boxT, boxB;

if(boxW > fullWidth) boxW = fullWidth / 4;
if(boxH > fullHeight) boxH = fullHeight / 4;

var minSize = 4 + (ScrollBox.barLength + 2 * ScrollBox.barPad);
boxW = Math.max(boxW, minSize);
boxH = Math.max(boxH, minSize);
if(!isDown && !isLeft && !isRight && !isUp) {
this.position.direction = 'down';
isDown = true;
}

if(0 <= l && l <= fullWidth) {
var isVertical = isDown || isUp;
if(isVertical) {
boxL = l;
boxR = boxL + boxW;
}
else {
// align left
boxL = 0;
boxR = boxL + boxW;
}

if(0 <= t && t <= fullHeight) {
boxT = t;
boxB = boxT + boxH;
if(isDown) {
// anchor to top side
boxT = t;
boxB = Math.min(boxT + boxH, fullHeight);
boxH = boxB - boxT;
}
else {
// anchor to bottom side
boxB = t + boxH;
boxT = Math.max(boxB - boxH, 0);
boxH = boxB - boxT;
}
}
else {
// align top
boxT = 0;
boxT = t;
boxB = boxT + boxH;
}

if(boxR > fullWidth) {
// align right
boxR = fullWidth;
boxL = boxR - boxW;
}

if(boxB > fullHeight) {
// align bottom
boxB = fullHeight;
boxT = boxB - boxH;
if(isLeft) {
// anchor to right side
boxR = l + boxW;
boxL = Math.max(boxR - boxW, 0);
boxW = boxR - boxL;
}
else {
// anchor to left side
boxL = l;
boxR = Math.min(boxL + boxW, fullWidth);
boxW = boxR - boxL;
}
}

this._box = {
Expand All @@ -143,8 +152,11 @@ ScrollBox.prototype.enable = function enable(position, translateX, translateY) {
var needsHorizontalScrollBar = (w > boxW),
hbarW = ScrollBox.barLength + 2 * ScrollBox.barPad,
hbarH = ScrollBox.barWidth + 2 * ScrollBox.barPad,
hbarL = boxL,
hbarT = (boxB + hbarH < fullHeight) ? boxB : fullHeight - hbarH;
// draw horizontal scrollbar on the bottom side
hbarL = l,
hbarT = t + h;

if(hbarT + hbarH > fullHeight) hbarT = fullHeight - hbarH;

var hbar = this.container.selectAll('rect.scrollbar-horizontal').data(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this ever going to be implemented?

We made the decision to not allow horizontal scrolling legends. I doubt that dropdown buttons should scroll horizontally in any scenario.

I'd say we can get away with 🔪 this logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we cut horizontal scrollbars, dropdown menus with direction: 'left' | 'right' will be limited to fit within the plot area.

For legends, we could make Scrollbox provide the option to disable the horizontal scrollbar.

(needsHorizontalScrollBar) ? [0] : []);
Expand Down Expand Up @@ -181,8 +193,11 @@ ScrollBox.prototype.enable = function enable(position, translateX, translateY) {
var needsVerticalScrollBar = (h > boxH),
vbarW = ScrollBox.barWidth + 2 * ScrollBox.barPad,
vbarH = ScrollBox.barLength + 2 * ScrollBox.barPad,
vbarL = (boxR + vbarW < fullWidth) ? boxR : fullWidth - vbarW,
vbarT = boxT;
// draw vertical scrollbar on the right side
vbarL = l + w,
vbarT = t;

if(vbarL + vbarW > fullWidth) vbarL = fullWidth - vbarW;

var vbar = this.container.selectAll('rect.scrollbar-vertical').data(
(needsVerticalScrollBar) ? [0] : []);
Expand Down