Skip to content

Commit 5b74652

Browse files
committed
Add trbl padding to sliders
1 parent c6a3e11 commit 5b74652

File tree

4 files changed

+57
-24
lines changed

4 files changed

+57
-24
lines changed

src/components/sliders/attributes.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'use strict';
1010

1111
var fontAttrs = require('../../plots/font_attributes');
12+
var padAttrs = require('../../plots/pad_attributes');
1213
var colorAttrs = require('../color/attributes');
1314
var extendFlat = require('../../lib/extend').extendFlat;
1415
var animationAttrs = require('../../plots/animation_attributes');
@@ -22,7 +23,7 @@ var stepsAttrs = {
2223
dflt: 'restyle',
2324
role: 'info',
2425
description: [
25-
'Sets the Plotly method to be called on click.'
26+
'Sets the Plotly method to be called when the slider value is changed.'
2627
].join(' ')
2728
},
2829
args: {
@@ -95,10 +96,11 @@ module.exports = {
9596
'value when an event of type `updateevent` is received. If',
9697
'undefined, the data argument itself is used. If a string,',
9798
'that property is used, and if a string with dots, e.g.',
98-
'`item.0.label`, then `data[\'item\'][0][\'label\']` will',
99-
'be used. If an array, it is matched to the respective',
100-
'updateevent item or if there is no corresponding updatevalue',
101-
'for a particular updateevent, it is interpreted as `undefined` and defaults to the data property itself.'
99+
'`item.0.label`, then `data[0].label` is used. If an array,',
100+
'it is matched to the respective updateevent item or if there',
101+
'is no corresponding updatevalue for a particular updateevent,',
102+
'it is interpreted as `undefined` and defaults to the data',
103+
'property itself.'
102104
].join(' ')
103105
},
104106

@@ -134,20 +136,9 @@ module.exports = {
134136
role: 'style',
135137
description: 'Sets the x position (in normalized coordinates) of the slider.'
136138
},
137-
xpad: {
138-
valType: 'number',
139-
min: 0,
140-
dflt: 10,
141-
role: 'style',
142-
description: 'Sets the amount of padding (in px) along the x direction'
143-
},
144-
ypad: {
145-
valType: 'number',
146-
min: 0,
147-
dflt: 10,
148-
role: 'style',
149-
description: 'Sets the amount of padding (in px) along the x direction'
150-
},
139+
pad: extendFlat({}, padAttrs, {
140+
description: 'Set the padding of the slider component along each side.'
141+
}),
151142
xanchor: {
152143
valType: 'enumerated',
153144
values: ['auto', 'left', 'center', 'right'],

src/components/sliders/defaults.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ function sliderDefaults(sliderIn, sliderOut, layoutOut) {
6060
coerce('len');
6161
coerce('lenmode');
6262

63-
coerce('xpad');
64-
coerce('ypad');
63+
coerce('pad.t');
64+
coerce('pad.r');
65+
coerce('pad.b');
66+
coerce('pad.l');
6567

6668
coerce('updateevent');
6769
coerce('updatevalue');

src/components/sliders/draw.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function findDimensions(gd, sliderOpts) {
145145

146146
// The length of the rail, *excluding* padding on either end:
147147
sliderOpts.inputAreaStart = 0;
148-
sliderOpts.inputAreaLength = Math.round(sliderOpts.outerLength - sliderOpts.xpad * 2);
148+
sliderOpts.inputAreaLength = Math.round(sliderOpts.outerLength - sliderOpts.pad.l - sliderOpts.pad.r);
149149
sliderOpts.railInset = Math.round(Math.max(0, constants.gripWidth - constants.railWidth) * 0.5);
150150
sliderOpts.stepInset = Math.round(Math.max(sliderOpts.railInset, constants.gripWidth * 0.5));
151151

@@ -155,7 +155,7 @@ function findDimensions(gd, sliderOpts) {
155155
sliderOpts.labelStride = Math.max(1, Math.ceil(computedSpacePerLabel / availableSpacePerLabel));
156156
sliderOpts.labelHeight = labelHeight;
157157

158-
sliderOpts.height = constants.tickOffset + constants.tickLength + sliderOpts.labelHeight + sliderOpts.ypad * 2;
158+
sliderOpts.height = constants.tickOffset + constants.tickLength + sliderOpts.labelHeight + sliderOpts.pad.t + sliderOpts.pad.b;
159159

160160
var xanchor = 'left';
161161
if(anchorUtils.isRightAnchor(sliderOpts)) {
@@ -202,7 +202,7 @@ function drawSlider(gd, sliderGroup, sliderOpts) {
202202
.call(drawGrip, gd, sliderOpts);
203203

204204
// Position the rectangle:
205-
Lib.setTranslate(sliderGroup, sliderOpts.lx + sliderOpts.xpad, sliderOpts.ly + sliderOpts.ypad);
205+
Lib.setTranslate(sliderGroup, sliderOpts.lx + sliderOpts.pad.l, sliderOpts.ly + sliderOpts.pad.t);
206206

207207
// Every time the slider is draw from scratch, just detach and reattach the event listeners.
208208
// This could perhaps be avoided.

src/plots/pad_attributes.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = {
12+
t: {
13+
valType: 'number',
14+
min: 0,
15+
dflt: 0,
16+
role: 'style',
17+
description: 'The amount of padding (in px) along the top of the component.'
18+
},
19+
r: {
20+
valType: 'number',
21+
min: 0,
22+
dflt: 0,
23+
role: 'style',
24+
description: 'The amount of padding (in px) on the right side of the component.'
25+
},
26+
b: {
27+
valType: 'number',
28+
min: 0,
29+
dflt: 0,
30+
role: 'style',
31+
description: 'The amount of padding (in px) along the bottom of the component.'
32+
},
33+
l: {
34+
valType: 'number',
35+
min: 0,
36+
dflt: 0,
37+
role: 'style',
38+
description: 'The amount of padding (in px) on the left side of the component.'
39+
}
40+
};

0 commit comments

Comments
 (0)