Skip to content

Feature: Range selectors #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 53 commits into from
Apr 4, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
36968ad
first pass range selector attributes
etpinard Mar 11, 2016
ab6c109
first pass range selector defaults
etpinard Mar 11, 2016
19d81d4
first pass range selector draw method
etpinard Mar 11, 2016
aa84cf0
add 'buttons' to list of non-data array in the plot-schema
etpinard Mar 11, 2016
b5e8301
ensure that range selector attributes are only coerced for date axes
etpinard Mar 14, 2016
80c75c7
pull off update object logic into seperate file:
etpinard Mar 14, 2016
f25213d
put range selector on-par with legend's
etpinard Mar 16, 2016
ef64e20
move RangeSelector.draw to just after Legend.draw
etpinard Mar 17, 2016
26494cf
make range selector border width dflt 1
etpinard Mar 17, 2016
da47cd4
tmp commit (range selector draw)
etpinard Mar 17, 2016
da71911
make range selector module more like range slider:
etpinard Mar 30, 2016
ab27021
first pass range selector attributes
etpinard Mar 11, 2016
de5e6b3
first pass range selector defaults
etpinard Mar 11, 2016
e976877
first pass range selector draw method
etpinard Mar 11, 2016
3fde2f8
add 'buttons' to list of non-data array in the plot-schema
etpinard Mar 11, 2016
121231b
ensure that range selector attributes are only coerced for date axes
etpinard Mar 14, 2016
8c839a1
pull off update object logic into seperate file:
etpinard Mar 14, 2016
48b5c50
put range selector on-par with legend's
etpinard Mar 16, 2016
4c7c99d
move RangeSelector.draw to just after Legend.draw
etpinard Mar 17, 2016
b198529
make range selector border width dflt 1
etpinard Mar 17, 2016
17c8377
tmp commit (range selector draw)
etpinard Mar 17, 2016
0d20931
make range selector module more like range slider:
etpinard Mar 30, 2016
b9e388f
better text positioning in range-select buttons
mdtusz Mar 30, 2016
a5e6aaa
Merge branch 'range-selector' of https://github.com/plotly/plotly.js …
mdtusz Mar 30, 2016
86331c7
lint in Plots.autoMargin
etpinard Mar 31, 2016
c9f76ab
add positionning logic to range selector draw step
etpinard Mar 31, 2016
574a6b3
change default yanchor to 'bottom'
etpinard Mar 31, 2016
beb239b
fixup test description
etpinard Mar 31, 2016
ec0771a
use new Date() to def specs instead of ms:
etpinard Mar 31, 2016
dd4880b
make y position 1.02 by default
etpinard Mar 31, 2016
2264bdd
add 'hour', 'minute' and 'second' button step values
etpinard Mar 31, 2016
f11aef9
Update rangeselector attributes
mdtusz Mar 31, 2016
8b4340e
don't coerce 'stepmode' and 'count' when 'step' is set to 'all'
etpinard Mar 31, 2016
053be81
handle to-date with step > 1 case
etpinard Mar 31, 2016
f49dd51
handle step 'all' case in label text
etpinard Mar 31, 2016
fb056b1
add range selector image mock
etpinard Mar 31, 2016
b2988b4
add a few range selector interaction tests
etpinard Mar 31, 2016
3a812c9
make getUpdateObject use ax._name to build update object
etpinard Mar 31, 2016
1ca424a
fixup test (to accomodate new defaults)
etpinard Mar 31, 2016
a671683
add smart default for range selector 'x' and 'y':
etpinard Mar 31, 2016
1042f4f
get range selector attributes ready for plot schema:
etpinard Apr 1, 2016
46f4a20
add comment about plotly.py in isLinkedToArray plot schema test
etpinard Apr 1, 2016
616d77d
add 'rx' and 'ry' button rect radii
etpinard Apr 1, 2016
86a3167
pass axis name to Plots.autoMargin,
etpinard Apr 1, 2016
4318f45
fix default label text generator
etpinard Apr 1, 2016
f025dc6
add is-active and is-hovered dynamic props to buttons:
etpinard Apr 1, 2016
ade535e
fixup attribute descriptions
etpinard Apr 1, 2016
49507be
change range selector and slider 'borderwidth' dflt to 0.
etpinard Apr 1, 2016
c95b45a
update range selector image test + add one more
etpinard Apr 1, 2016
6a68155
add is-active button update test
etpinard Apr 1, 2016
1275935
rename 'to date' stepmode 'todate'
etpinard Apr 4, 2016
6c3a9d7
update image mock 'to date' -> 'todate'
etpinard Apr 4, 2016
6da24e4
update default button style:
etpinard Apr 4, 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
20 changes: 12 additions & 8 deletions src/components/rangeselector/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@ var colorAttrs = require('../color/attributes');
var extendFlat = require('../../lib/extend').extendFlat;
var buttonAttrs = require('./button_attributes');

buttonAttrs = extendFlat(buttonAttrs, {
_isLinkedToArray: true,
description: [
'Sets the specifications for each buttons.',
'By default, a range selector comes with no buttons.'
].join(' ')
});

module.exports = {
visible: {
valType: 'boolean',
role: 'info',
description: [
'Determines whether or not this range selector is visible.'
'Determines whether or not this range selector is visible.',
'Note that range selectors are only available for x axes of',
'`type` set to *date*.'
].join(' ')
},

buttons: {
role: 'object',
items: buttonAttrs,
description: [
'buttons!!!'
].join(' ')
},
buttons: buttonAttrs,

x: {
valType: 'number',
Expand Down
15 changes: 12 additions & 3 deletions src/components/rangeselector/button_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ module.exports = {
values: ['backward', 'to date'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An important distinction here.

With backward, the starting pt (i.e range[0]) goes back (count * step) in ms.

With to date, the starting pt (i.e range[0]) goes back to the floor of (count * step).

For example, with

{
  step: 'year',
  stepmode: 'to date', 
  count: 1
}

the starting range value is Jan 01 of the last year in the time series.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we go for to date or todate? Other attributes (tozeroy for example) are stripped of whitespace.

Copy link
Member

Choose a reason for hiding this comment

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

I would vote todate for consistency (i.e. w/ tozero-)

dflt: 'backward',
description: [
''
'Sets the range update mode.',
'If *backward*, the range update shifts the start of range',
'back *count* times *step* milliseconds.',
'If *to date*, the range update shifts the start of range',
'back to the first timestamp from *count* times',
'*step* milliseconds back.',
'For example, with `step` set to *year* and `count` set to *1*',
'the range update shifts the start of the range back to',
'January 01 of the current year.'
].join(' ')
},
count: {
Expand All @@ -34,12 +42,13 @@ module.exports = {
min: 0,
dflt: 1,
description: [
''
'Sets the number of steps to take to update the range.',
'Use with `step` to specify the update interval.'
].join(' ')
},
label: {
valType: 'string',
role: 'info',
description: ''
description: 'Sets the text label to appear on the button.'
}
};
20 changes: 11 additions & 9 deletions src/plot_api/plot_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ function getLayoutAttributes() {
mergeValTypeAndRole(layoutAttributes);

// generate IS_LINKED_TO_ARRAY structure
layoutAttributes = handleLinkedToArray(layoutAttributes);
handleLinkedToArray(layoutAttributes);

plotSchema.layout = { layoutAttributes: layoutAttributes };


}

function getDefs() {
Expand Down Expand Up @@ -304,19 +306,19 @@ function handleSubplotObjs(layoutAttributes) {
}

function handleLinkedToArray(layoutAttributes) {
Object.keys(layoutAttributes).forEach(function(k) {
var attr = extendDeep({}, layoutAttributes[k]);

function callback(attr, attrName, attrs) {
if(attr[IS_LINKED_TO_ARRAY] !== true) return;

var itemName = k.substr(0, k.length-1); // TODO more robust logic
// TODO more robust logic
var itemName = attrName.substr(0, attrName.length - 1);

delete attr[IS_LINKED_TO_ARRAY];

layoutAttributes[k] = { items: {} };
layoutAttributes[k].items[itemName] = attr;
layoutAttributes[k].role = 'object';
});
attrs[attrName] = { items: {} };
attrs[attrName].items[itemName] = attr;
attrs[attrName].role = 'object';
}

return layoutAttributes;
PlotSchema.crawl(layoutAttributes, callback);
}
5 changes: 5 additions & 0 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var fontAttrs = require('../font_attributes');
var colorAttrs = require('../../components/color/attributes');
var extendFlat = require('../../lib/extend').extendFlat;
var rangeSliderAttrs = require('../../components/rangeslider/attributes');
var rangeSelectorAttrs = require('../../components/rangeselector/attributes');


module.exports = {
title: {
Expand Down Expand Up @@ -82,7 +84,10 @@ module.exports = {
'January 1st 1970 to November 4th, 2013, set the range from 0 to 1380844800000.0'
].join(' ')
},

rangeslider: rangeSliderAttrs,
rangeselector: rangeSelectorAttrs,

fixedrange: {
valType: 'boolean',
dflt: false,
Expand Down
34 changes: 25 additions & 9 deletions test/jasmine/tests/plotschema_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var Plotly = require('@lib/index');
var Lib = require('@src/lib');


describe('plot schema', function() {
'use strict';

Expand Down Expand Up @@ -112,17 +113,31 @@ describe('plot schema', function() {
expect(list).toEqual(astrs);
});

it('layout.annotations and layout.shapes should contain `items`', function() {
var astrs = ['annotations', 'shapes'];
it('should convert _isLinkedToArray attributes to items object', function() {
var astrs = [
'annotations', 'shapes',
'xaxis.rangeselector.buttons', 'yaxis.rangeselector.buttons'
];

astrs.forEach(function(astr) {
expect(
isPlainObject(
Lib.nestedProperty(
plotSchema.layout.layoutAttributes, astr
).get().items
)
).toBe(true);
var np = Lib.nestedProperty(
plotSchema.layout.layoutAttributes, astr
);

var name = np.parts[np.parts.length - 1],
itemName = name.substr(0, name.length - 1);

var itemsObj = np.get().items,
itemObj = itemsObj[itemName];

expect(isPlainObject(itemsObj)).toBe(true);
expect(itemsObj.role).toBeUndefined();
expect(Object.keys(itemsObj).length).toEqual(1);
expect(isPlainObject(itemObj)).toBe(true);
expect(itemObj.role).toBe('object');

var role = np.get().role;
expect(role).toEqual('object');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cldougl @theengineear ⏫ needs to be satisfied for plotly.py to build to correct graph object.

Copy link
Contributor

Choose a reason for hiding this comment

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

@delekru https://github.com/delekru @etpinard @chriddyp
Can we please use Highchart's button styling? I think they did a good job
and its what users are familiar with:
http://www.highcharts.com/stock/demo/basic-line

On Fri, Apr 1, 2016 at 4:20 PM, Étienne Tétreault-Pinard <
[email protected]> wrote:

In test/jasmine/tests/plotschema_test.js
#373 (comment):

  •        );
    
  •        var name = np.parts[np.parts.length - 1],
    
  •            itemName = name.substr(0, name.length - 1);
    
  •        var itemsObj = np.get().items,
    
  •            itemObj = itemsObj[itemName];
    
  •        expect(isPlainObject(itemsObj)).toBe(true);
    
  •        expect(itemsObj.role).toBeUndefined();
    
  •        expect(Object.keys(itemsObj).length).toEqual(1);
    
  •        expect(isPlainObject(itemObj)).toBe(true);
    
  •        expect(itemObj.role).toBe('object');
    
  •        var role = np.get().role;
    
  •        expect(role).toEqual('object');
    

@cldougl https://github.com/cldougl @theengineear
https://github.com/theengineear [image: ⏫] needs to be
satisfied for plotly.py to build to correct graph object.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/plotly/plotly.js/pull/373/files/a671683931ac3856674bce3af7b5d988c0857cb5..1042f4f656c3e1ac14a365477a93c6d66d44b855#r58269266

});
});

Expand Down Expand Up @@ -158,4 +173,5 @@ describe('plot schema', function() {
}
);
});

});