Skip to content

Commit 1042f4f

Browse files
committed
get range selector attributes ready for plot schema:
- use isLinkedToArray to describe 'buttons' - crawl through layout attribute to convert all isLinkedToArray attributes to items object that plotly.py can parse - fill in missing descriptions - link range selector attributes in axis attributes
1 parent a671683 commit 1042f4f

File tree

5 files changed

+65
-29
lines changed

5 files changed

+65
-29
lines changed

src/components/rangeselector/attributes.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,26 @@ var colorAttrs = require('../color/attributes');
1313
var extendFlat = require('../../lib/extend').extendFlat;
1414
var buttonAttrs = require('./button_attributes');
1515

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+
});
1623

1724
module.exports = {
1825
visible: {
1926
valType: 'boolean',
27+
role: 'info',
2028
description: [
21-
'Determines whether or not this range selector is visible.'
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 *date*.'
2232
].join(' ')
2333
},
2434

25-
buttons: {
26-
role: 'object',
27-
items: buttonAttrs,
28-
description: [
29-
'buttons!!!'
30-
].join(' ')
31-
},
35+
buttons: buttonAttrs,
3236

3337
x: {
3438
valType: 'number',

src/components/rangeselector/button_attributes.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ module.exports = {
2525
values: ['backward', 'to date'],
2626
dflt: 'backward',
2727
description: [
28-
''
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 *to date*, 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.'
2937
].join(' ')
3038
},
3139
count: {
@@ -34,12 +42,13 @@ module.exports = {
3442
min: 0,
3543
dflt: 1,
3644
description: [
37-
''
45+
'Sets the number of steps to take to update the range.',
46+
'Use with `step` to specify the update interval.'
3847
].join(' ')
3948
},
4049
label: {
4150
valType: 'string',
4251
role: 'info',
43-
description: ''
52+
description: 'Sets the text label to appear on the button.'
4453
}
4554
};

src/plot_api/plot_schema.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ function getLayoutAttributes() {
131131
mergeValTypeAndRole(layoutAttributes);
132132

133133
// generate IS_LINKED_TO_ARRAY structure
134-
layoutAttributes = handleLinkedToArray(layoutAttributes);
134+
handleLinkedToArray(layoutAttributes);
135135

136136
plotSchema.layout = { layoutAttributes: layoutAttributes };
137+
138+
137139
}
138140

139141
function getDefs() {
@@ -304,19 +306,19 @@ function handleSubplotObjs(layoutAttributes) {
304306
}
305307

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

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

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

314316
delete attr[IS_LINKED_TO_ARRAY];
315317

316-
layoutAttributes[k] = { items: {} };
317-
layoutAttributes[k].items[itemName] = attr;
318-
layoutAttributes[k].role = 'object';
319-
});
318+
attrs[attrName] = { items: {} };
319+
attrs[attrName].items[itemName] = attr;
320+
attrs[attrName].role = 'object';
321+
}
320322

321-
return layoutAttributes;
323+
PlotSchema.crawl(layoutAttributes, callback);
322324
}

src/plots/cartesian/layout_attributes.js

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var fontAttrs = require('../font_attributes');
1313
var colorAttrs = require('../../components/color/attributes');
1414
var extendFlat = require('../../lib/extend').extendFlat;
1515
var rangeSliderAttrs = require('../../components/rangeslider/attributes');
16+
var rangeSelectorAttrs = require('../../components/rangeselector/attributes');
17+
1618

1719
module.exports = {
1820
title: {
@@ -82,7 +84,10 @@ module.exports = {
8284
'January 1st 1970 to November 4th, 2013, set the range from 0 to 1380844800000.0'
8385
].join(' ')
8486
},
87+
8588
rangeslider: rangeSliderAttrs,
89+
rangeselector: rangeSelectorAttrs,
90+
8691
fixedrange: {
8792
valType: 'boolean',
8893
dflt: false,

test/jasmine/tests/plotschema_test.js

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var Plotly = require('@lib/index');
22
var Lib = require('@src/lib');
33

4+
45
describe('plot schema', function() {
56
'use strict';
67

@@ -112,17 +113,31 @@ describe('plot schema', function() {
112113
expect(list).toEqual(astrs);
113114
});
114115

115-
it('layout.annotations and layout.shapes should contain `items`', function() {
116-
var astrs = ['annotations', 'shapes'];
116+
it('should convert _isLinkedToArray attributes to items object', function() {
117+
var astrs = [
118+
'annotations', 'shapes',
119+
'xaxis.rangeselector.buttons', 'yaxis.rangeselector.buttons'
120+
];
117121

118122
astrs.forEach(function(astr) {
119-
expect(
120-
isPlainObject(
121-
Lib.nestedProperty(
122-
plotSchema.layout.layoutAttributes, astr
123-
).get().items
124-
)
125-
).toBe(true);
123+
var np = Lib.nestedProperty(
124+
plotSchema.layout.layoutAttributes, astr
125+
);
126+
127+
var name = np.parts[np.parts.length - 1],
128+
itemName = name.substr(0, name.length - 1);
129+
130+
var itemsObj = np.get().items,
131+
itemObj = itemsObj[itemName];
132+
133+
expect(isPlainObject(itemsObj)).toBe(true);
134+
expect(itemsObj.role).toBeUndefined();
135+
expect(Object.keys(itemsObj).length).toEqual(1);
136+
expect(isPlainObject(itemObj)).toBe(true);
137+
expect(itemObj.role).toBe('object');
138+
139+
var role = np.get().role;
140+
expect(role).toEqual('object');
126141
});
127142
});
128143

@@ -158,4 +173,5 @@ describe('plot schema', function() {
158173
}
159174
);
160175
});
176+
161177
});

0 commit comments

Comments
 (0)