Skip to content

Commit b6e4653

Browse files
committed
Change updatemenus orientation/openreverse to simply 'direction'
1 parent 5e584bc commit b6e4653

File tree

5 files changed

+34
-48
lines changed

5 files changed

+34
-48
lines changed

src/components/updatemenus/attributes.js

+7-14
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@ module.exports = {
5757
].join(' ')
5858
},
5959

60-
openreverse: {
61-
valType: 'boolean',
62-
role: 'info',
63-
dflt: false,
64-
description: [
65-
'For dropdown menus, opens the menu in the reverse direction'
66-
].join(' ')
67-
},
68-
6960
type: {
7061
valType: 'enumerated',
7162
values: ['dropdown', 'buttons'],
@@ -77,14 +68,16 @@ module.exports = {
7768
].join(' ')
7869
},
7970

80-
orientation: {
71+
direction: {
8172
valType: 'enumerated',
82-
values: ['h', 'v'],
83-
dflt: 'v',
73+
values: ['left', 'right', 'up', 'down'],
74+
dflt: 'down',
8475
role: 'info',
8576
description: [
86-
'Determines whether the menu and buttons are laid out vertically',
87-
'or horizontally'
77+
'Determines the direction in which the buttons are laid out, whether',
78+
'in a dropdown menu or a row/column of buttons. For `left` and `up`,',
79+
'the buttons will still appear in left-to-right or top-to-bottom order',
80+
'respectively.'
8881
].join(' ')
8982
},
9083

src/components/updatemenus/defaults.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ function menuDefaults(menuIn, menuOut, layoutOut) {
4949
if(!visible) return;
5050

5151
coerce('active');
52-
coerce('orientation');
52+
coerce('direction');
5353
coerce('type');
54-
coerce('openreverse');
5554
coerce('showactive');
5655

5756
coerce('x');

src/components/updatemenus/draw.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -256,20 +256,22 @@ function drawButtons(gd, gHeader, gButton, menuOpts) {
256256
var x0 = 0;
257257
var y0 = 0;
258258

259+
var isVertical = ['up', 'down'].indexOf(menuOpts.direction) !== -1;
260+
259261
if(menuOpts.type === 'dropdown') {
260-
if(menuOpts.orientation === 'v') {
262+
if(isVertical) {
261263
y0 = menuOpts.headerHeight + constants.gapButtonHeader;
262264
} else {
263265
x0 = menuOpts.headerWidth + constants.gapButtonHeader;
264266
}
265267
}
266268

267-
if(menuOpts.type === 'dropdown' && menuOpts.openreverse) {
268-
if(menuOpts.orientation === 'v') {
269-
y0 = -constants.gapButtonHeader + constants.gapButton - menuOpts.openHeight;
270-
} else {
271-
x0 = -constants.gapButtonHeader + constants.gapButton - menuOpts.openWidth;
272-
}
269+
if(menuOpts.type === 'dropdown' && menuOpts.direction === 'up') {
270+
y0 = -constants.gapButtonHeader + constants.gapButton - menuOpts.openHeight;
271+
}
272+
273+
if(menuOpts.type === 'dropdown' && menuOpts.direction === 'left') {
274+
x0 = -constants.gapButtonHeader + constants.gapButton - menuOpts.openWidth;
273275
}
274276

275277
var posOpts = {
@@ -399,6 +401,8 @@ function findDimenstions(gd, menuOpts) {
399401
fakeButtons.enter().append('g')
400402
.classed(constants.dropdownButtonClassName, true);
401403

404+
var isVertical = ['up', 'down'].indexOf(menuOpts.direction) !== -1;
405+
402406
// loop over fake buttons to find width / height
403407
fakeButtons.each(function(buttonOpts, i) {
404408
var button = d3.select(this);
@@ -429,7 +433,7 @@ function findDimenstions(gd, menuOpts) {
429433
menuOpts.height1 = Math.max(menuOpts.height1, hEff);
430434
menuOpts.width1 = Math.max(menuOpts.width1, wEff);
431435

432-
if(menuOpts.orientation === 'v') {
436+
if(isVertical) {
433437
menuOpts.totalWidth = Math.max(menuOpts.totalWidth, wEff);
434438
menuOpts.openWidth = menuOpts.totalWidth;
435439
menuOpts.totalHeight += hEff + constants.gapButton;
@@ -442,7 +446,7 @@ function findDimenstions(gd, menuOpts) {
442446
}
443447
});
444448

445-
if(menuOpts.orientation === 'v') {
449+
if(isVertical) {
446450
menuOpts.totalHeight -= constants.gapButton;
447451
} else {
448452
menuOpts.totalWidth -= constants.gapButton;
@@ -453,7 +457,7 @@ function findDimenstions(gd, menuOpts) {
453457
menuOpts.headerHeight = menuOpts.height1;
454458

455459
if(menuOpts.type === 'dropdown') {
456-
if(menuOpts.orientation === 'v') {
460+
if(isVertical) {
457461
menuOpts.width1 += constants.arrowPadX;
458462
menuOpts.totalHeight = menuOpts.height1;
459463
} else {
@@ -514,11 +518,13 @@ function setItemPosition(item, menuOpts, posOpts, overrideOpts) {
514518

515519
Lib.setTranslate(item, borderWidth + posOpts.x, borderWidth + posOpts.y);
516520

521+
var isVertical = ['up', 'down'].indexOf(menuOpts.direction) !== -1;
522+
517523
rect.attr({
518524
x: 0,
519525
y: 0,
520-
width: overrideOpts.width || (menuOpts.orientation === 'v' ? menuOpts.width1 : menuOpts.widths[index]),
521-
height: overrideOpts.height || (menuOpts.orientation === 'v' ? menuOpts.heights[index] : menuOpts.height1)
526+
width: overrideOpts.width || (isVertical ? menuOpts.width1 : menuOpts.widths[index]),
527+
height: overrideOpts.height || (isVertical ? menuOpts.heights[index] : menuOpts.height1)
522528
});
523529

524530
var tHeight = menuOpts.font.size * constants.fontSizeToHeight,
@@ -533,7 +539,7 @@ function setItemPosition(item, menuOpts, posOpts, overrideOpts) {
533539
text.attr(textAttrs);
534540
tspans.attr(textAttrs);
535541

536-
if(menuOpts.orientation === 'v') {
542+
if(isVertical) {
537543
posOpts.y += menuOpts.heights[index] + posOpts.yPad;
538544
} else {
539545
posOpts.x += menuOpts.widths[index] + posOpts.xPad;

test/image/mocks/updatemenus_positioning.json

+5-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"y": 0.66,
4848
"yanchor": "top",
4949
"xanchor": "left",
50-
"orientation": "h"
50+
"direction": "right"
5151
},
5252
{
5353
"buttons": [
@@ -61,8 +61,7 @@
6161
"y": 0.33,
6262
"yanchor": "top",
6363
"xanchor": "left",
64-
"orientation": "h",
65-
"openreverse": true
64+
"direction": "left"
6665
},
6766
{
6867
"buttons": [
@@ -76,8 +75,7 @@
7675
"y": 0.0,
7776
"yanchor": "top",
7877
"xanchor": "left",
79-
"orientation": "v",
80-
"openreverse": true
78+
"direction": "up"
8179
},
8280
{
8381
"buttons": [
@@ -107,7 +105,7 @@
107105
"y": 1.01,
108106
"yanchor": "bottom",
109107
"xanchor": "left",
110-
"orientation": "h",
108+
"direction": "right",
111109
"showactive": false
112110
},
113111
{
@@ -131,7 +129,7 @@
131129
"y": 0.02,
132130
"yanchor": "top",
133131
"xanchor": "right",
134-
"orientation": "h"
132+
"direction": "right"
135133
},
136134
{
137135
"buttons": [

test/jasmine/tests/updatemenus_test.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ describe('update menus defaults', function() {
147147
expect(layoutOut.updatemenus[0].type).toEqual('dropdown');
148148
});
149149

150-
it('should default \'orientation\' to \'v\'', function() {
150+
it('should default \'direction\' to \'down\'', function() {
151151
layoutIn.updatemenus = [{
152152
buttons: [{method: 'relayout', args: ['title', 'Hello World']}]
153153
}];
154154

155155
supply(layoutIn, layoutOut);
156156

157-
expect(layoutOut.updatemenus[0].orientation).toEqual('v');
157+
expect(layoutOut.updatemenus[0].direction).toEqual('down');
158158
});
159159

160160
it('should default \'showactive\' to true', function() {
@@ -166,16 +166,6 @@ describe('update menus defaults', function() {
166166

167167
expect(layoutOut.updatemenus[0].showactive).toEqual(true);
168168
});
169-
170-
it('should default \'openreverse\' to false', function() {
171-
layoutIn.updatemenus = [{
172-
buttons: [{method: 'relayout', args: ['title', 'Hello World']}]
173-
}];
174-
175-
supply(layoutIn, layoutOut);
176-
177-
expect(layoutOut.updatemenus[0].openreverse).toEqual(false);
178-
});
179169
});
180170

181171
describe('update menus buttons', function() {

0 commit comments

Comments
 (0)