Skip to content

Slider component #986

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 43 commits into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f5bccd5
First cut at slider
rreusser Sep 28, 2016
83483fd
Fix lint errors in slider
rreusser Sep 28, 2016
f69a328
Add slider transitions
rreusser Sep 28, 2016
82ea558
Expand touchable slider area
rreusser Sep 28, 2016
ca5f9f5
Add slider mock
rreusser Sep 28, 2016
c6a3e11
Rename sliders and bump circular require tolerance
rreusser Sep 28, 2016
5b74652
Add trbl padding to sliders
rreusser Sep 28, 2016
e13e0ee
Remove fanciness from slider constants
rreusser Sep 28, 2016
8fe1842
Tweak slider behavior to avoid event -> method loops
rreusser Sep 28, 2016
05ac586
Improve padding logic for updatemenus
rreusser Sep 28, 2016
4604341
Add jasmine tests for updatemenus padding
rreusser Sep 29, 2016
8558be8
add streaming maxpoints max and dflt
cldougl Sep 29, 2016
c673afe
Merge pull request #996 from plotly/maxpt_dflt
cldougl Sep 29, 2016
304174a
Add current value output to sliders
rreusser Sep 29, 2016
fce36fa
Merge pull request #989 from plotly/fix-updatemenus-padding
rreusser Sep 29, 2016
52b4a2a
First cut at slider
rreusser Sep 28, 2016
b161d55
Fix lint errors in slider
rreusser Sep 28, 2016
8d7c40d
Add slider transitions
rreusser Sep 28, 2016
30b5f2d
Expand touchable slider area
rreusser Sep 28, 2016
19442d9
Add slider mock
rreusser Sep 28, 2016
ecb7e87
Rename sliders and bump circular require tolerance
rreusser Sep 28, 2016
9c0f9ac
Add trbl padding to sliders
rreusser Sep 29, 2016
2a6f987
Remove fanciness from slider constants
rreusser Sep 28, 2016
5bd6bdd
Tweak slider behavior to avoid event -> method loops
rreusser Sep 28, 2016
4520a48
Add current value output to sliders
rreusser Sep 29, 2016
88d6728
Tweak slider colors
rreusser Sep 29, 2016
6da5b0f
Fix sliders in plot schema
rreusser Sep 29, 2016
1cad8a4
Merge branch 'slider-component' of github.com:plotly/plotly.js into s…
rreusser Sep 29, 2016
4a9edd0
Working through slider testing issues
rreusser Sep 29, 2016
6cb6d42
Add slider tests
rreusser Oct 3, 2016
4775a47
Test updateevent for sliders
rreusser Oct 3, 2016
a08f084
Update sliders baseline to reflect bugfix
rreusser Oct 3, 2016
5816c24
Fix plot schema error
rreusser Oct 3, 2016
2cfa81b
Remove unneeded lines from sliders test
rreusser Oct 4, 2016
1d52b51
Remove updatevalue and updateevent
rreusser Oct 6, 2016
892583d
Removed unused slider function
rreusser Oct 6, 2016
5015710
Clean up slider options
rreusser Oct 6, 2016
582c643
Remove unneeded/failing slider test
rreusser Oct 6, 2016
70610ec
Add suffix to currentvalue slider label
rreusser Oct 6, 2016
f25127c
don't coerce slider currentvalue attrs when !visible
rreusser Oct 6, 2016
4b608ee
Be more specific about *all* unused slider attrs not set
rreusser Oct 6, 2016
6c9034d
Test mouse movement for sliders
rreusser Oct 6, 2016
21e2f99
Make sure slider Drawing.bBox calls fall back to defined
rreusser Oct 6, 2016
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
56 changes: 46 additions & 10 deletions src/components/sliders/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

var fontAttrs = require('../../plots/font_attributes');
var padAttrs = require('../../plots/pad_attributes');
var colorAttrs = require('../color/attributes');
var extendFlat = require('../../lib/extend').extendFlat;
var animationAttrs = require('../../plots/animation_attributes');
var constants = require('./constants');

var stepsAttrs = {
_isLinkedToArray: true,
Expand All @@ -37,7 +37,7 @@ var stepsAttrs = {
],
description: [
'Sets the arguments values to be passed to the Plotly',
'method set in `method` on click.'
'method set in `method` on slide.'
].join(' ')
},
label: {
Expand Down Expand Up @@ -84,8 +84,7 @@ module.exports = {
role: 'info',
dflt: 'fraction',
description: [
'Determines whether this color bar\'s length',
'(i.e. the measure in the color variation direction)',
'Determines whether this slider length',
'is set in units of plot *fraction* or in *pixels.',
'Use `len` to set the value.'
].join(' ')
Expand All @@ -96,9 +95,9 @@ module.exports = {
dflt: 1,
role: 'style',
description: [
'Sets the length of the color bar',
'Sets the length of the slider',
'This measure excludes the padding of both ends.',
'That is, the color bar length is this length minus the',
'That is, the slider\'s length is this length minus the',
'padding on both ends.'
].join(' ')
},
Expand Down Expand Up @@ -209,22 +208,59 @@ module.exports = {
description: 'Sets the font of the slider step labels.'
}),

activebgcolor: {
valType: 'color',
role: 'style',
dflt: constants.gripBgActiveColor,
description: [
'Sets the background color of the slider grip',
'while dragging.'
].join(' ')
},
bgcolor: {
valType: 'color',
role: 'style',
description: 'Sets the background color of the slider buttons.'
dflt: constants.railBgColor,
description: 'Sets the background color of the slider.'
},
bordercolor: {
valType: 'color',
dflt: colorAttrs.borderLine,
dflt: constants.railBorderColor,
role: 'style',
description: 'Sets the color of the border enclosing the slider.'
},
borderwidth: {
valType: 'number',
min: 0,
dflt: 1,
dflt: constants.railBorderWidth,
role: 'style',
description: 'Sets the width (in px) of the border enclosing the slider.'
}
},
ticklen: {
Copy link
Contributor

Choose a reason for hiding this comment

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

very nice

valType: 'number',
min: 0,
dflt: constants.tickLength,
role: 'style',
description: 'Sets the length in pixels of step tick marks'
},
tickcolor: {
valType: 'color',
dflt: constants.tickColor,
role: 'style',
description: 'Sets the color of the border enclosing the slider.'
},
tickwidth: {
valType: 'number',
min: 0,
dflt: 1,
role: 'style',
description: 'Sets the tick width (in px).'
},
minorticklen: {
valType: 'number',
min: 0,
dflt: constants.minorTickLength,
role: 'style',
description: 'Sets the length in pixels of minor step tick marks'
},
};
1 change: 1 addition & 0 deletions src/components/sliders/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = {
railRadius: 2,
railWidth: 5,
railBorder: 4,
railBorderWidth: 1,
railBorderColor: '#bec8d9',
railBgColor: '#f8fafc',

Expand Down
17 changes: 11 additions & 6 deletions src/components/sliders/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
var Lib = require('../../lib');

var attributes = require('./attributes');
var contants = require('./constants');
var constants = require('./constants');

var name = contants.name;
var name = constants.name;
var stepAttrs = attributes.steps;


Expand Down Expand Up @@ -73,12 +73,17 @@ function sliderDefaults(sliderIn, sliderOut, layoutOut) {
coerce('transition.duration');
coerce('transition.easing');

Lib.coerceFont(coerce, 'font', layoutOut.font);
Lib.coerceFont(coerce, 'currentvalue.font', layoutOut.font);

coerce('bgcolor', layoutOut.paper_bgcolor);
coerce('bgcolor');
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the default bgcolor isn't inherited from layoutOut.paper_bgcolor anymore. Is this on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No good reason except that it didn't actually seem like a desirable default since that would just make the slider transparent-looking instead of filled by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To elaborate slightly, this attribute wasn't used before. Until today it was a hard-coded constant.

Copy link
Contributor

Choose a reason for hiding this comment

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

it didn't actually seem like a desirable default

I agree 100%. I just wanted to make sure the above patch was not a typo 👍

coerce('activebgcolor');
coerce('bordercolor');
coerce('borderwidth');
coerce('ticklen');
coerce('tickwidth');
coerce('tickcolor');
coerce('minorticklen');

Lib.coerceFont(coerce, 'font', layoutOut.font);
Lib.coerceFont(coerce, 'currentvalue.font', sliderOut.font);
Copy link
Contributor

Choose a reason for hiding this comment

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

similarly here, Lib.coerceFont(coerce, 'currentvalue.font', sliderOut.font); should only get coerced if currentvalue.visible is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

function stepsDefaults(sliderIn, sliderOut) {
Expand Down
32 changes: 16 additions & 16 deletions src/components/sliders/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function findDimensions(gd, sliderOpts) {
sliderOpts.labelStride = Math.max(1, Math.ceil(computedSpacePerLabel / availableSpacePerLabel));
sliderOpts.labelHeight = labelHeight;

sliderOpts.height = sliderOpts.currentValueTotalHeight + constants.tickOffset + constants.tickLength + constants.labelOffset + sliderOpts.labelHeight + sliderOpts.pad.t + sliderOpts.pad.b;
sliderOpts.height = sliderOpts.currentValueTotalHeight + constants.tickOffset + sliderOpts.ticklen + constants.labelOffset + sliderOpts.labelHeight + sliderOpts.pad.t + sliderOpts.pad.b;

var xanchor = 'left';
if(anchorUtils.isRightAnchor(sliderOpts)) {
Expand Down Expand Up @@ -292,9 +292,9 @@ function drawGrip(sliderGroup, gd, sliderOpts) {
rx: constants.gripRadius,
ry: constants.gripRadius,
Copy link
Contributor

Choose a reason for hiding this comment

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

My only design comment is: maybe we could make the grip a little more rectangular i.e. more similar to how the range slider looks:

image

... but I'm no design expert.

})
.call(Color.stroke, constants.gripBorderColor)
.call(Color.fill, constants.gripBgColor)
.style('stroke-width', constants.gripBorderWidth + 'px');
.call(Color.stroke, sliderOpts.bordercolor)
.call(Color.fill, sliderOpts.bgcolor)
.style('stroke-width', sliderOpts.borderwidth + 'px');
}

function drawLabel(item, data, sliderOpts) {
Expand Down Expand Up @@ -335,7 +335,7 @@ function drawLabelGroup(sliderGroup, sliderOpts) {

Lib.setTranslate(item,
normalizedValueToPosition(sliderOpts, d.fraction),
constants.tickOffset + constants.tickLength + sliderOpts.labelHeight + constants.labelOffset + sliderOpts.currentValueTotalHeight
constants.tickOffset + sliderOpts.ticklen + sliderOpts.labelHeight + constants.labelOffset + sliderOpts.currentValueTotalHeight
);
});

Expand Down Expand Up @@ -398,7 +398,7 @@ function attachGripEvents(item, gd, sliderGroup, sliderOpts) {

d3.event.stopPropagation();
d3.event.preventDefault();
grip.call(Color.fill, constants.gripBgActiveColor);
grip.call(Color.fill, sliderOpts.activebgcolor);

var normalizedPosition = positionToNormalizedValue(sliderOpts, d3.mouse(node)[0]);
handleInput(gd, sliderGroup, sliderOpts, normalizedPosition, true);
Expand All @@ -409,7 +409,7 @@ function attachGripEvents(item, gd, sliderGroup, sliderOpts) {
});

$gd.on('mouseup', function() {
grip.call(Color.fill, constants.gripBgColor);
grip.call(Color.fill, sliderOpts.bgcolor);
$gd.on('mouseup', null);
$gd.on('mousemove', null);
});
Expand All @@ -426,7 +426,7 @@ function drawTicks(sliderGroup, sliderOpts) {
tick.exit().remove();

tick.attr({
width: constants.tickWidth,
width: sliderOpts.tickwidth + 'px',
'shape-rendering': 'crispEdges'
});

Expand All @@ -435,11 +435,11 @@ function drawTicks(sliderGroup, sliderOpts) {
var item = d3.select(this);

item
.attr({height: isMajor ? constants.tickLength : constants.minorTickLength})
.call(Color.fill, isMajor ? constants.tickColor : constants.minorTickColor);
.attr({height: isMajor ? sliderOpts.ticklen : sliderOpts.minorticklen})
.call(Color.fill, isMajor ? sliderOpts.tickcolor : sliderOpts.tickcolor);

Lib.setTranslate(item,
normalizedValueToPosition(sliderOpts, i / (sliderOpts.steps.length - 1)) - 0.5 * constants.tickWidth,
normalizedValueToPosition(sliderOpts, i / (sliderOpts.steps.length - 1)) - 0.5 * sliderOpts.tickwidth,
(isMajor ? constants.tickOffset : constants.minorTickOffset) + sliderOpts.currentValueTotalHeight
);
});
Expand Down Expand Up @@ -498,9 +498,9 @@ function drawTouchRect(sliderGroup, gd, sliderOpts) {

rect.attr({
width: sliderOpts.inputAreaLength,
height: Math.max(sliderOpts.inputAreaWidth, constants.tickOffset + constants.tickLength + sliderOpts.labelHeight)
height: Math.max(sliderOpts.inputAreaWidth, constants.tickOffset + sliderOpts.ticklen + sliderOpts.labelHeight)
})
.call(Color.fill, constants.gripBgColor)
.call(Color.fill, sliderOpts.bgcolor)
.attr('opacity', 0);

Lib.setTranslate(rect, 0, sliderOpts.currentValueTotalHeight);
Expand All @@ -522,9 +522,9 @@ function drawRail(sliderGroup, sliderOpts) {
ry: constants.railRadius,
'shape-rendering': 'crispEdges'
})
.call(Color.stroke, constants.railBorderColor)
.call(Color.fill, constants.railBgColor)
.style('stroke-width', '1px');
.call(Color.stroke, sliderOpts.bordercolor)
.call(Color.fill, sliderOpts.bgcolor)
.style('stroke-width', sliderOpts.borderwidth + 'px');

Lib.setTranslate(rect,
constants.railInset,
Expand Down
4 changes: 2 additions & 2 deletions src/components/updatemenus/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
var Lib = require('../../lib');

var attributes = require('./attributes');
var contants = require('./constants');
var constants = require('./constants');

var name = contants.name;
var name = constants.name;
var buttonAttrs = attributes.buttons;


Expand Down
Binary file modified test/image/baselines/sliders.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 61 additions & 2 deletions test/image/mocks/sliders.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"xanchor": "right",
"y": -0.1,
"yanchor": "top",
"currentvalue": {
"visible": false
},

"transition": {
"duration": 150,
Expand All @@ -47,7 +50,7 @@

"pad": {
"r": 20,
"t": 20
"t": 60
},

"font": {}
Expand All @@ -69,6 +72,42 @@
"label": "green",
"method": "restyle",
"args": [{"marker.color": "green"}]
}, {
"label": "orange",
"method": "restyle",
"args": [{"marker.color": "orange"}]
}, {
"label": "yellow",
"method": "restyle",
"args": [{"marker.color": "yellow"}]
}, {
"label": "green",
"method": "restyle",
"args": [{"marker.color": "green"}]
}, {
"label": "orange",
"method": "restyle",
"args": [{"marker.color": "orange"}]
}, {
"label": "yellow",
"method": "restyle",
"args": [{"marker.color": "yellow"}]
}, {
"label": "green",
"method": "restyle",
"args": [{"marker.color": "green"}]
}, {
"label": "orange",
"method": "restyle",
"args": [{"marker.color": "orange"}]
}, {
"label": "yellow",
"method": "restyle",
"args": [{"marker.color": "yellow"}]
}, {
"label": "green",
"method": "restyle",
"args": [{"marker.color": "green"}]
}, {
"label": "blue",
"method": "restyle",
Expand All @@ -95,7 +134,27 @@
"t": 20
},

"font": {}
"bgcolor": "red",
"bordercolor": "blue",
"borderwidth": 2,
"activebgcolor": "green",
"ticklen": 20,
"tickcolor": "purple",
"minorticklen": 10,
"tickwidth": 2,

"font": {
"color": "purple",
"size": 15
},
"currentvalue": {
"prefix": "color:",
"xanchor": "right",
"font": {
"color": "orange",
"size": 20
}
}
}],
"xaxis": {
"range": [0, 2],
Expand Down