Skip to content

Commit e13e0ee

Browse files
committed
Remove fanciness from slider constants
1 parent 5b74652 commit e13e0ee

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

src/components/sliders/constants.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ module.exports = {
4848
// font size to height scale
4949
fontSizeToHeight: 1.3,
5050

51-
// item rect radii
52-
rx: 2,
53-
ry: 2,
54-
55-
// item text x offset off left edge
56-
textOffsetX: 12,
57-
58-
// item text y offset (w.r.t. middle)
59-
textOffsetY: 3,
60-
6151
// arrow offset off right edge
6252
arrowOffsetX: 4,
6353

@@ -67,6 +57,16 @@ module.exports = {
6757
railBorderColor: '#bec8d9',
6858
railBgColor: '#ebedf0',
6959

60+
// The distance of the rail from the edge of the touchable area
61+
// Slightly less than the step inset because of the curved edges
62+
// of the rail
63+
railInset: 8,
64+
65+
// The distance from the extremal tick marks to the edge of the
66+
// touchable area. This is basically the same as the grip radius,
67+
// but for other styles it wouldn't really need to be.
68+
stepInset: 10,
69+
7070
gripRadius: 10,
7171
gripWidth: 20,
7272
gripHeight: 20,
@@ -76,15 +76,15 @@ module.exports = {
7676
gripBgColor: '#ebedf0',
7777
gripBgActiveColor: '#dbdde0',
7878

79-
// Padding in the direction perpendicular to the length of the rail:
80-
// (which, at the moment is always vertical, but for the sake of the future...)
81-
widthPadding: 10,
79+
labelPadding: 8,
80+
labelOffset: 0,
8281

83-
labelPadding: 4,
8482
tickWidth: 1,
8583
tickColor: '#333',
8684
tickOffset: 25,
8785
tickLength: 7,
86+
87+
minorTickOffset: 25,
8888
minorTickColor: '#333',
8989
minorTickLength: 4,
9090
};

src/components/sliders/draw.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,14 @@ function findDimensions(gd, sliderOpts) {
146146
// The length of the rail, *excluding* padding on either end:
147147
sliderOpts.inputAreaStart = 0;
148148
sliderOpts.inputAreaLength = Math.round(sliderOpts.outerLength - sliderOpts.pad.l - sliderOpts.pad.r);
149-
sliderOpts.railInset = Math.round(Math.max(0, constants.gripWidth - constants.railWidth) * 0.5);
150-
sliderOpts.stepInset = Math.round(Math.max(sliderOpts.railInset, constants.gripWidth * 0.5));
151149

152-
var textableInputLength = sliderOpts.inputAreaLength - 2 * sliderOpts.stepInset;
150+
var textableInputLength = sliderOpts.inputAreaLength - 2 * constants.stepInset;
153151
var availableSpacePerLabel = textableInputLength / (sliderOpts.steps.length - 1);
154152
var computedSpacePerLabel = maxLabelWidth + constants.labelPadding;
155153
sliderOpts.labelStride = Math.max(1, Math.ceil(computedSpacePerLabel / availableSpacePerLabel));
156154
sliderOpts.labelHeight = labelHeight;
157155

158-
sliderOpts.height = constants.tickOffset + constants.tickLength + sliderOpts.labelHeight + sliderOpts.pad.t + sliderOpts.pad.b;
156+
sliderOpts.height = constants.tickOffset + constants.tickLength + constants.labelOffset + sliderOpts.labelHeight + sliderOpts.pad.t + sliderOpts.pad.b;
159157

160158
var xanchor = 'left';
161159
if(anchorUtils.isRightAnchor(sliderOpts)) {
@@ -307,7 +305,7 @@ function drawLabelGroup(sliderGroup, sliderOpts) {
307305

308306
Lib.setTranslate(item,
309307
normalizedValueToPosition(sliderOpts, d.fraction),
310-
constants.tickOffset + constants.tickLength + sliderOpts.labelHeight
308+
constants.tickOffset + constants.tickLength + sliderOpts.labelHeight + constants.labelOffset
311309
);
312310
});
313311

@@ -405,7 +403,7 @@ function drawTicks(sliderGroup, sliderOpts) {
405403

406404
Lib.setTranslate(item,
407405
normalizedValueToPosition(sliderOpts, i / (sliderOpts.steps.length - 1)) - 0.5 * constants.tickWidth,
408-
constants.tickOffset
406+
isMajor ? constants.tickOffset : constants.minorTickOffset
409407
);
410408
});
411409

@@ -443,13 +441,13 @@ function setGripPosition(sliderGroup, sliderOpts, position, doTransition) {
443441

444442
// Convert a number from [0-1] to a pixel position relative to the slider group container:
445443
function normalizedValueToPosition(sliderOpts, normalizedPosition) {
446-
return sliderOpts.inputAreaStart + sliderOpts.stepInset +
447-
(sliderOpts.inputAreaLength - 2 * sliderOpts.stepInset) * Math.min(1, Math.max(0, normalizedPosition));
444+
return sliderOpts.inputAreaStart + constants.stepInset +
445+
(sliderOpts.inputAreaLength - 2 * constants.stepInset) * Math.min(1, Math.max(0, normalizedPosition));
448446
}
449447

450448
// Convert a position relative to the slider group to a nubmer in [0, 1]
451449
function positionToNormalizedValue(sliderOpts, position) {
452-
return Math.min(1, Math.max(0, (position - sliderOpts.stepInset - sliderOpts.inputAreaStart) / (sliderOpts.inputAreaLength - 2 * sliderOpts.stepInset - 2 * sliderOpts.inputAreaStart)));
450+
return Math.min(1, Math.max(0, (position - constants.stepInset - sliderOpts.inputAreaStart) / (sliderOpts.inputAreaLength - 2 * constants.stepInset - 2 * sliderOpts.inputAreaStart)));
453451
}
454452

455453
function drawTouchRect(sliderGroup, gd, sliderOpts) {
@@ -466,7 +464,7 @@ function drawTouchRect(sliderGroup, gd, sliderOpts) {
466464
height: Math.max(sliderOpts.inputAreaWidth, constants.tickOffset + constants.tickLength + sliderOpts.labelHeight)
467465
})
468466
.call(Color.fill, constants.gripBgColor)
469-
.attr('opacity', 0.0);
467+
.attr('opacity', 0);
470468

471469
Lib.setTranslate(rect, 0, 0);
472470
}
@@ -478,7 +476,7 @@ function drawRail(sliderGroup, sliderOpts) {
478476
rect.enter().append('rect')
479477
.classed(constants.railRectClass, true);
480478

481-
var computedLength = sliderOpts.inputAreaLength - sliderOpts.railInset * 2;
479+
var computedLength = sliderOpts.inputAreaLength - constants.railInset * 2;
482480

483481
rect.attr({
484482
width: computedLength,
@@ -491,7 +489,7 @@ function drawRail(sliderGroup, sliderOpts) {
491489
.call(Color.fill, constants.railBgColor)
492490
.style('stroke-width', '1px');
493491

494-
Lib.setTranslate(rect, sliderOpts.railInset, (sliderOpts.inputAreaWidth - constants.railWidth) * 0.5);
492+
Lib.setTranslate(rect, constants.railInset, (sliderOpts.inputAreaWidth - constants.railWidth) * 0.5);
495493
}
496494

497495
function clearPushMargins(gd) {

0 commit comments

Comments
 (0)