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 all commits
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
269 changes: 269 additions & 0 deletions src/components/sliders/attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

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

var stepsAttrs = {
_isLinkedToArray: true,

method: {
valType: 'enumerated',
values: ['restyle', 'relayout', 'animate', 'update'],
dflt: 'restyle',
role: 'info',
description: [
'Sets the Plotly method to be called when the slider value is changed.'
].join(' ')
},
args: {
valType: 'info_array',
role: 'info',
freeLength: true,
items: [
{ valType: 'any' },
{ valType: 'any' },
{ valType: 'any' }
],
description: [
'Sets the arguments values to be passed to the Plotly',
'method set in `method` on slide.'
].join(' ')
},
label: {
valType: 'string',
role: 'info',
description: 'Sets the text label to appear on the slider'
},
value: {
valType: 'string',
role: 'info',
description: [
'Sets the value of the slider step, used to refer to the step programatically.',
'Defaults to the slider label if not provided.'
].join(' ')
}
};

module.exports = {
visible: {
valType: 'boolean',
role: 'info',
dflt: true,
description: [
'Determines whether or not the slider is visible.'
].join(' ')
},

active: {
valType: 'number',
role: 'info',
min: -10,
dflt: 0,
description: [
'Determines which button (by index starting from 0) is',
'considered active.'
].join(' ')
},

steps: stepsAttrs,

lenmode: {
valType: 'enumerated',
values: ['fraction', 'pixels'],
role: 'info',
dflt: 'fraction',
description: [
'Determines whether this slider length',
'is set in units of plot *fraction* or in *pixels.',
'Use `len` to set the value.'
].join(' ')
},
len: {
valType: 'number',
min: 0,
dflt: 1,
role: 'style',
description: [
'Sets the length of the slider',
'This measure excludes the padding of both ends.',
'That is, the slider\'s length is this length minus the',
'padding on both ends.'
].join(' ')
},
x: {
valType: 'number',
min: -2,
max: 3,
dflt: -0.05,
role: 'style',
description: 'Sets the x position (in normalized coordinates) of the slider.'
},
pad: extendFlat({}, padAttrs, {
description: 'Set the padding of the slider component along each side.'
}),
xanchor: {
valType: 'enumerated',
values: ['auto', 'left', 'center', 'right'],
dflt: 'left',
role: 'info',
description: [
'Sets the slider\'s horizontal position anchor.',
'This anchor binds the `x` position to the *left*, *center*',
'or *right* of the range selector.'
].join(' ')
},
y: {
valType: 'number',
min: -2,
max: 3,
dflt: 1,
role: 'style',
description: 'Sets the y position (in normalized coordinates) of the slider.'
},
yanchor: {
valType: 'enumerated',
values: ['auto', 'top', 'middle', 'bottom'],
dflt: 'bottom',
role: 'info',
description: [
'Sets the slider\'s vertical position anchor',
'This anchor binds the `y` position to the *top*, *middle*',
'or *bottom* of the range selector.'
].join(' ')
},

transition: {
duration: {
valType: 'number',
role: 'info',
min: 0,
dflt: 150,
description: 'Sets the duration of the slider transition'
},
easing: {
valType: 'enumerated',
values: animationAttrs.transition.easing.values,
role: 'info',
dflt: 'cubic-in-out',
description: 'Sets the easing function of the slider transition'
},
},

currentvalue: {
visible: {
valType: 'boolean',
role: 'info',
dflt: true,
description: [
'Shows the currently-selected value above the slider.'
].join(' ')
},

xanchor: {
valType: 'enumerated',
values: ['left', 'center', 'right'],
Copy link
Contributor

Choose a reason for hiding this comment

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

yep, nice job dropping the 'auto' value here.

dflt: 'left',
role: 'info',
description: [
'The alignment of the value readout relative to the length of the slider.'
].join(' ')
},

offset: {
valType: 'number',
dflt: 10,
role: 'info',
description: [
'The amount of space, in pixels, between the current value label',
'and the slider.'
].join(' ')
},

prefix: {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably add a suffix attribute too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. Good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

valType: 'string',
role: 'info',
description: 'When currentvalue.visible is true, this sets the prefix of the label.'
},

suffix: {
valType: 'string',
role: 'info',
description: 'When currentvalue.visible is true, this sets the suffix of the label.'
},
Copy link
Contributor Author

@rreusser rreusser Sep 29, 2016

Choose a reason for hiding this comment

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

@etpinard does the prefix definition look reasonable to you? I'm losing my mind here. The test dashboard fails:

> Plotly.PlotSchema.get().layout.layoutAttributes.sliders.currentvalue.prefix
< undefined

Where my browserifying dev environment succeeds:

> Plotly.PlotSchema.get().layout.layoutAttributes.sliders.currentvalue.prefix
< Object {valType: "string", role: "info", description: "When currentvalue.visible is true, this sets the p…to the current value with a single space between."}

I'm really struggling to find a reason for it. Currently digging into the logic to see if I've committed a crime which would get prefix filtered out sometimes

Copy link
Contributor Author

@rreusser rreusser Sep 29, 2016

Choose a reason for hiding this comment

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

Solved. Problem exists between keyboard, chair, and regex. (previous description lacked .join() 😬 )


font: extendFlat({}, fontAttrs, {
description: 'Sets the font of the current value label text.'
}),
},

font: extendFlat({}, fontAttrs, {
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',
dflt: constants.railBgColor,
description: 'Sets the background color of the slider.'
},
bordercolor: {
valType: 'color',
dflt: constants.railBorderColor,
role: 'style',
description: 'Sets the color of the border enclosing the slider.'
},
borderwidth: {
valType: 'number',
min: 0,
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'
},
};
96 changes: 96 additions & 0 deletions src/components/sliders/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';


module.exports = {

// layout attribute names
name: 'sliders',
itemName: 'slider',

// class names
containerClassName: 'slider-container',
groupClassName: 'slider-group',
inputAreaClass: 'slider-input-area',
railRectClass: 'slider-rail-rect',
railTouchRectClass: 'slider-rail-touch-rect',
gripRectClass: 'slider-grip-rect',
tickRectClass: 'slider-tick-rect',
inputProxyClass: 'slider-input-proxy',
labelsClass: 'slider-labels',
labelGroupClass: 'slider-label-group',
labelClass: 'slider-label',
currentValueClass: 'slider-current-value',

railHeight: 5,

// DOM attribute name in button group keeping track
// of active update menu
menuIndexAttrName: 'slider-active-index',

// id root pass to Plots.autoMargin
autoMarginIdRoot: 'slider-',

// min item width / height
minWidth: 30,
minHeight: 30,

// padding around item text
textPadX: 40,

// font size to height scale
fontSizeToHeight: 1.3,

// arrow offset off right edge
arrowOffsetX: 4,

railRadius: 2,
railWidth: 5,
railBorder: 4,
railBorderWidth: 1,
railBorderColor: '#bec8d9',
railBgColor: '#f8fafc',

// The distance of the rail from the edge of the touchable area
// Slightly less than the step inset because of the curved edges
// of the rail
railInset: 8,

// The distance from the extremal tick marks to the edge of the
// touchable area. This is basically the same as the grip radius,
// but for other styles it wouldn't really need to be.
stepInset: 10,

gripRadius: 10,
gripWidth: 20,
gripHeight: 20,
gripBorder: 20,
gripBorderWidth: 1,
gripBorderColor: '#bec8d9',
gripBgColor: '#f6f8fa',
gripBgActiveColor: '#dbdde0',

labelPadding: 8,
labelOffset: 0,

tickWidth: 1,
tickColor: '#333',
tickOffset: 25,
tickLength: 7,

minorTickOffset: 25,
minorTickColor: '#333',
minorTickLength: 4,

// Extra space below the current value label:
currentValuePadding: 8,
currentValueInset: 0,
};
Loading