Skip to content
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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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.'
},

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Slider component by rreusser · Pull Request #986 · plotly/plotly.js · GitHub
Skip to content
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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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.'
},

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Slider component by rreusser · Pull Request #986 · plotly/plotly.js · GitHub
Skip to content
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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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.'
},

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Slider component by rreusser · Pull Request #986 · plotly/plotly.js · GitHub
Skip to content
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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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.'
},

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Slider component by rreusser · Pull Request #986 · plotly/plotly.js · GitHub
Skip to content
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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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.'
},

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Slider component by rreusser · Pull Request #986 · plotly/plotly.js · GitHub
Skip to content
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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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.'
},

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Slider component by rreusser · Pull Request #986 · plotly/plotly.js · GitHub
Skip to content
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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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.'
},

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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 numberDiff line numberDiff 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Slider component by rreusser · Pull Request #986 · plotly/plotly.js · GitHub
Skip to content
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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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.'
},

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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

@rreusserrreusserSep 29, 2016

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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 numberDiff line numberDiff 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