Skip to content

Commit 4d5262f

Browse files
committed
Merge pull request #373 from plotly/range-selector
Feature: Range selectors
2 parents 2d5e3b9 + 6da24e4 commit 4d5262f

21 files changed

+2819
-26
lines changed

Diff for: src/components/legend/draw.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,12 @@ function repositionLegend(gd, traces) {
402402
else {
403403
// approximation to height offset to center the font
404404
// to avoid getBoundingClientRect
405-
textY = tHeight * (0.3 + (1-tLines) / 2);
406-
text.attr('y',textY);
407-
tspans.attr('y',textY);
405+
textY = tHeight * (0.3 + (1 - tLines) / 2);
406+
text.attr('y', textY);
407+
tspans.attr('y', textY);
408408
}
409409

410-
tHeightFull = Math.max(tHeight*tLines, 16) + 3;
410+
tHeightFull = Math.max(tHeight * tLines, 16) + 3;
411411

412412
g.attr('transform',
413413
'translate(' + borderwidth + ',' +

Diff for: src/components/rangeselector/attributes.js

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var fontAttrs = require('../../plots/font_attributes');
12+
var colorAttrs = require('../color/attributes');
13+
var extendFlat = require('../../lib/extend').extendFlat;
14+
var buttonAttrs = require('./button_attributes');
15+
16+
buttonAttrs = extendFlat(buttonAttrs, {
17+
_isLinkedToArray: true,
18+
description: [
19+
'Sets the specifications for each buttons.',
20+
'By default, a range selector comes with no buttons.'
21+
].join(' ')
22+
});
23+
24+
module.exports = {
25+
visible: {
26+
valType: 'boolean',
27+
role: 'info',
28+
description: [
29+
'Determines whether or not this range selector is visible.',
30+
'Note that range selectors are only available for x axes of',
31+
'`type` set to or auto-typed to *date*.'
32+
].join(' ')
33+
},
34+
35+
buttons: buttonAttrs,
36+
37+
x: {
38+
valType: 'number',
39+
min: -2,
40+
max: 3,
41+
role: 'style',
42+
description: 'Sets the x position (in normalized coordinates) of the range selector.'
43+
},
44+
xanchor: {
45+
valType: 'enumerated',
46+
values: ['auto', 'left', 'center', 'right'],
47+
dflt: 'left',
48+
role: 'info',
49+
description: [
50+
'Sets the range selector\'s horizontal position anchor.',
51+
'This anchor binds the `x` position to the *left*, *center*',
52+
'or *right* of the range selector.'
53+
].join(' ')
54+
},
55+
y: {
56+
valType: 'number',
57+
min: -2,
58+
max: 3,
59+
role: 'style',
60+
description: 'Sets the y position (in normalized coordinates) of the range selector.'
61+
},
62+
yanchor: {
63+
valType: 'enumerated',
64+
values: ['auto', 'top', 'middle', 'bottom'],
65+
dflt: 'bottom',
66+
role: 'info',
67+
description: [
68+
'Sets the range selector\'s vertical position anchor',
69+
'This anchor binds the `y` position to the *top*, *middle*',
70+
'or *bottom* of the range selector.'
71+
].join(' ')
72+
},
73+
74+
font: extendFlat({}, fontAttrs, {
75+
description: 'Sets the font of the range selector button text.'
76+
}),
77+
78+
bgcolor: {
79+
valType: 'color',
80+
dflt: colorAttrs.lightLine,
81+
role: 'style',
82+
description: 'Sets the background color of the range selector buttons.'
83+
},
84+
bordercolor: {
85+
valType: 'color',
86+
dflt: colorAttrs.defaultLine,
87+
role: 'style',
88+
description: 'Sets the color of the border enclosing the range selector.'
89+
},
90+
borderwidth: {
91+
valType: 'number',
92+
min: 0,
93+
dflt: 0,
94+
role: 'style',
95+
description: 'Sets the width (in px) of the border enclosing the range selector.'
96+
}
97+
};

Diff for: src/components/rangeselector/button_attributes.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
12+
module.exports = {
13+
step: {
14+
valType: 'enumerated',
15+
role: 'info',
16+
values: ['month', 'year', 'day', 'hour', 'minute', 'second', 'all'],
17+
dflt: 'month',
18+
description: [
19+
'The unit of measurement that the `count` value will set the range by.'
20+
].join(' ')
21+
},
22+
stepmode: {
23+
valType: 'enumerated',
24+
role: 'info',
25+
values: ['backward', 'todate'],
26+
dflt: 'backward',
27+
description: [
28+
'Sets the range update mode.',
29+
'If *backward*, the range update shifts the start of range',
30+
'back *count* times *step* milliseconds.',
31+
'If *todate*, the range update shifts the start of range',
32+
'back to the first timestamp from *count* times',
33+
'*step* milliseconds back.',
34+
'For example, with `step` set to *year* and `count` set to *1*',
35+
'the range update shifts the start of the range back to',
36+
'January 01 of the current year.'
37+
].join(' ')
38+
},
39+
count: {
40+
valType: 'number',
41+
role: 'info',
42+
min: 0,
43+
dflt: 1,
44+
description: [
45+
'Sets the number of steps to take to update the range.',
46+
'Use with `step` to specify the update interval.'
47+
].join(' ')
48+
},
49+
label: {
50+
valType: 'string',
51+
role: 'info',
52+
description: 'Sets the text label to appear on the button.'
53+
}
54+
};

Diff for: src/components/rangeselector/constants.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
12+
module.exports = {
13+
14+
// 'y' position pad above counter axis domain
15+
yPad: 0.02,
16+
17+
// minimum button width (regardless of text size)
18+
minButtonWidth: 30,
19+
20+
// buttons rect radii
21+
rx: 3,
22+
ry: 3,
23+
24+
// color given to active and hovered buttons
25+
activeColor: '#d3d3d3'
26+
};

Diff for: src/components/rangeselector/defaults.js

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Lib = require('../../lib');
12+
13+
var attributes = require('./attributes');
14+
var buttonAttrs = require('./button_attributes');
15+
var constants = require('./constants');
16+
17+
18+
module.exports = function rangeSelectorDefaults(containerIn, containerOut, layout, counterAxes) {
19+
var selectorIn = containerIn.rangeselector || {},
20+
selectorOut = containerOut.rangeselector = {};
21+
22+
function coerce(attr, dflt) {
23+
return Lib.coerce(selectorIn, selectorOut, attributes, attr, dflt);
24+
}
25+
26+
var buttons = buttonsDefaults(selectorIn, selectorOut);
27+
28+
var visible = coerce('visible', buttons.length > 0);
29+
if(!visible) return;
30+
31+
var posDflt = getPosDflt(containerOut, layout, counterAxes);
32+
coerce('x', posDflt[0]);
33+
coerce('y', posDflt[1]);
34+
Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);
35+
36+
coerce('xanchor');
37+
coerce('yanchor');
38+
39+
Lib.coerceFont(coerce, 'font', layout.font);
40+
41+
coerce('bgcolor');
42+
coerce('bordercolor');
43+
coerce('borderwidth');
44+
};
45+
46+
function buttonsDefaults(containerIn, containerOut) {
47+
var buttonsIn = containerIn.buttons || [],
48+
buttonsOut = containerOut.buttons = [];
49+
50+
var buttonIn, buttonOut;
51+
52+
function coerce(attr, dflt) {
53+
return Lib.coerce(buttonIn, buttonOut, buttonAttrs, attr, dflt);
54+
}
55+
56+
for(var i = 0; i < buttonsIn.length; i++) {
57+
buttonIn = buttonsIn[i];
58+
buttonOut = {};
59+
60+
var step = coerce('step');
61+
if(step !== 'all') {
62+
coerce('stepmode');
63+
coerce('count');
64+
}
65+
66+
coerce('label');
67+
68+
buttonsOut.push(buttonOut);
69+
}
70+
71+
return buttonsOut;
72+
}
73+
74+
function getPosDflt(containerOut, layout, counterAxes) {
75+
var anchoredList = counterAxes.filter(function(ax) {
76+
return layout[ax].anchor === containerOut._id;
77+
});
78+
79+
var posY = 0;
80+
for(var i = 0; i < anchoredList.length; i++) {
81+
posY = Math.max(layout[anchoredList[i]].domain[1], posY);
82+
}
83+
84+
return [containerOut.domain[0], posY + constants.yPad];
85+
}

0 commit comments

Comments
 (0)