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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add current value output to sliders
  • Loading branch information
rreusser committed Sep 29, 2016
commit 304174a7556d3e64f17f87c379cdc5f478637ad5
44 changes: 43 additions & 1 deletion src/components/sliders/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,50 @@ module.exports = {
},
},

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

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

Choose a reason for hiding this comment

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

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

dflt: 'left',
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.'
]
},

prefix: {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably add a suffix attribute too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. Good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

valType: 'string',
role: 'info',
description: [
'When `currentvalue.visible` is true, this sets the prefix of the lable. If provided,',
'it will be joined to the current value with a single space between.'
].join(' ')
},
Copy link
Contributor Author

@rreusser rreusser Sep 29, 2016

Choose a reason for hiding this comment

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

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

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

Where my browserifying dev environment succeeds:

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

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

Copy link
Contributor Author

@rreusser rreusser Sep 29, 2016

Choose a reason for hiding this comment

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

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


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

font: extendFlat({}, fontAttrs, {
description: 'Sets the font of the slider button text.'
description: 'Sets the font of the slider step labels.'
}),

bgcolor: {
Expand Down
5 changes: 5 additions & 0 deletions src/components/sliders/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
labelsClass: 'slider-labels',
labelGroupClass: 'slider-label-group',
labelClass: 'slider-label',
currentValueClass: 'slider-current-value',

railHeight: 5,

Expand Down Expand Up @@ -87,4 +88,8 @@ module.exports = {
minorTickOffset: 25,
minorTickColor: '#333',
minorTickLength: 4,

// Extra space below the current value label:
currentValuePadding: 8,
currentValueInset: 0,
};
10 changes: 6 additions & 4 deletions src/components/sliders/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ function sliderDefaults(sliderIn, sliderOut, layoutOut) {
coerce('pad.b');
coerce('pad.l');

coerce('currentvalue.visible');
coerce('currentvalue.xanchor');
coerce('currentvalue.prefix');
coerce('currentvalue.offset');
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be:

var currentValue = coerce('currentvalue.visible');

if(currentValue) {
  coerce('currentvalue.xanchor');
  coerce('currentvalue.prefix');
  coerce('currentvalue.offset');
}

so that Plotly.validate can detect e.g.

layout.sliders = [{
  currentvalue: {
    visible: false,
    xanchor: 'left'
}];

// => `xanchor` has no effects

Copy link
Contributor Author

Choose a reason for hiding this comment

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


coerce('updateevent');
coerce('updatevalue');

if(!sliderIn.transition) {
sliderIn.transition = {};
}

coerce('transition.duration');
coerce('transition.easing');

Expand All @@ -84,6 +85,7 @@ function sliderDefaults(sliderIn, sliderOut, layoutOut) {
}

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

coerce('bgcolor', layoutOut.paper_bgcolor);
coerce('bordercolor');
Expand Down
84 changes: 78 additions & 6 deletions src/components/sliders/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ function findDimensions(gd, sliderOpts) {
constants.gripHeight
);

sliderOpts.currentValueMaxWidth = 0;
sliderOpts.currentValueHeight = 0;
sliderOpts.currentValueTotalHeight = 0;

if(sliderOpts.currentvalue.visible) {
// Get the dimensions of the current value label:
var dummyGroup = gd._tester.append('g');

sliderLabels.each(function(stepOpts) {
var curValPrefix = drawCurrentValue(dummyGroup, sliderOpts, stepOpts.label);
var curValSize = curValPrefix.node() && Drawing.bBox(curValPrefix.node());
sliderOpts.currentValueMaxWidth = Math.max(sliderOpts.currentValueMaxWidth, Math.ceil(curValSize.width));
sliderOpts.currentValueHeight = Math.max(sliderOpts.currentValueHeight, Math.ceil(curValSize.height));
});

sliderOpts.currentValueTotalHeight = sliderOpts.currentValueHeight + sliderOpts.currentvalue.offset;

dummyGroup.remove();
}

var graphSize = gd._fullLayout._size;
sliderOpts.lx = graphSize.l + graphSize.w * sliderOpts.x;
sliderOpts.ly = graphSize.t + graphSize.h * (1 - sliderOpts.y);
Expand All @@ -153,7 +173,7 @@ function findDimensions(gd, sliderOpts) {
sliderOpts.labelStride = Math.max(1, Math.ceil(computedSpacePerLabel / availableSpacePerLabel));
sliderOpts.labelHeight = labelHeight;

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

var xanchor = 'left';
if(anchorUtils.isRightAnchor(sliderOpts)) {
Expand Down Expand Up @@ -193,6 +213,7 @@ function findDimensions(gd, sliderOpts) {
function drawSlider(gd, sliderGroup, sliderOpts) {
// These are carefully ordered for proper z-ordering:
sliderGroup
.call(drawCurrentValue, sliderOpts)
.call(drawRail, sliderOpts)
.call(drawLabelGroup, sliderOpts)
.call(drawTicks, sliderOpts)
Expand All @@ -210,6 +231,53 @@ function drawSlider(gd, sliderGroup, sliderOpts) {
setActive(gd, sliderGroup, sliderOpts, sliderOpts.active, true, false);
}

function drawCurrentValue(sliderGroup, sliderOpts, valueOverride) {
if(!sliderOpts.currentvalue.visible) return;

var x0, textAnchor;
var text = sliderGroup.selectAll('text')
.data([0]);

switch(sliderOpts.currentvalue.xanchor) {
case 'right':
// This is anchored left and adjusted by the width of the longest label
// so that the prefix doesn't move. The goal of this is to emphasize
// what's actually changing and make the update less distracting.
x0 = sliderOpts.inputAreaLength - constants.currentValueInset - sliderOpts.currentValueMaxWidth;
textAnchor = 'left';
break;
case 'center':
x0 = sliderOpts.inputAreaLength * 0.5;
textAnchor = 'middle';
break;
default:
x0 = constants.currentValueInset;
textAnchor = 'left';
}

text.enter().append('text')
.classed(constants.labelClass, true)
.classed('user-select-none', true)
.attr('text-anchor', textAnchor);

var str = sliderOpts.currentvalue.prefix ? (sliderOpts.currentvalue.prefix + ' ') : '';

if(typeof valueOverride === 'string') {
str += valueOverride;
} else {
var curVal = sliderOpts.steps[sliderOpts.active].label;
str += curVal;
}

text.call(Drawing.font, sliderOpts.currentvalue.font)
.text(str)
.call(svgTextUtils.convertToTspans);

Lib.setTranslate(text, x0, sliderOpts.currentValueHeight);

return text;
}

function removeListeners(gd, sliderGroup, sliderOpts) {
var listeners = sliderOpts._input.listeners;
var eventNames = sliderOpts._input.eventNames;
Expand Down Expand Up @@ -310,7 +378,7 @@ function drawLabelGroup(sliderGroup, sliderOpts) {

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

Expand Down Expand Up @@ -346,6 +414,7 @@ function setActive(gd, sliderGroup, sliderOpts, index, doCallback, doTransition)
var step = sliderOpts.steps[sliderOpts.active];

sliderGroup.call(setGripPosition, sliderOpts, sliderOpts.active / (sliderOpts.steps.length - 1), doTransition);
sliderGroup.call(drawCurrentValue, sliderOpts);

if(step && step.method && doCallback) {
if(sliderGroup._nextMethod) {
Expand Down Expand Up @@ -429,7 +498,7 @@ function drawTicks(sliderGroup, sliderOpts) {

Lib.setTranslate(item,
normalizedValueToPosition(sliderOpts, i / (sliderOpts.steps.length - 1)) - 0.5 * constants.tickWidth,
isMajor ? constants.tickOffset : constants.minorTickOffset
(isMajor ? constants.tickOffset : constants.minorTickOffset) + sliderOpts.currentValueTotalHeight
);
});

Expand Down Expand Up @@ -462,7 +531,7 @@ function setGripPosition(sliderGroup, sliderOpts, position, doTransition) {

// Lib.setTranslate doesn't work here becasue of the transition duck-typing.
// It's also not necessary because there are no other transitions to preserve.
el.attr('transform', 'translate(' + (x - constants.gripWidth * 0.5) + ',' + 0 + ')');
el.attr('transform', 'translate(' + (x - constants.gripWidth * 0.5) + ',' + (sliderOpts.currentValueTotalHeight) + ')');
}

// Convert a number from [0-1] to a pixel position relative to the slider group container:
Expand Down Expand Up @@ -492,7 +561,7 @@ function drawTouchRect(sliderGroup, gd, sliderOpts) {
.call(Color.fill, constants.gripBgColor)
.attr('opacity', 0);

Lib.setTranslate(rect, 0, 0);
Lib.setTranslate(rect, 0, sliderOpts.currentValueTotalHeight);
}

function drawRail(sliderGroup, sliderOpts) {
Expand All @@ -515,7 +584,10 @@ function drawRail(sliderGroup, sliderOpts) {
.call(Color.fill, constants.railBgColor)
.style('stroke-width', '1px');

Lib.setTranslate(rect, constants.railInset, (sliderOpts.inputAreaWidth - constants.railWidth) * 0.5);
Lib.setTranslate(rect,
constants.railInset,
(sliderOpts.inputAreaWidth - constants.railWidth) * 0.5 + sliderOpts.currentValueTotalHeight
);
}

function clearPushMargins(gd) {
Expand Down