Skip to content

Commit 8525953

Browse files
committed
add template attributes to array containers
1 parent b3da4e7 commit 8525953

File tree

14 files changed

+142
-122
lines changed

14 files changed

+142
-122
lines changed

src/components/annotations/attributes.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
var ARROWPATHS = require('./arrow_paths');
1212
var fontAttrs = require('../../plots/font_attributes');
1313
var cartesianConstants = require('../../plots/cartesian/constants');
14+
var templatedArray = require('../../plot_api/plot_template').templatedArray;
1415

1516

16-
module.exports = {
17-
_isLinkedToArray: 'annotation',
18-
17+
module.exports = templatedArray('annotation', {
1918
visible: {
2019
valType: 'boolean',
2120
role: 'info',
@@ -543,4 +542,4 @@ module.exports = {
543542
].join(' ')
544543
}
545544
}
546-
};
545+
});

src/components/annotations3d/attributes.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111

1212
var annAtts = require('../annotations/attributes');
1313
var overrideAll = require('../../plot_api/edit_types').overrideAll;
14+
var templatedArray = require('../../plot_api/plot_template').templatedArray;
1415

15-
module.exports = overrideAll({
16-
_isLinkedToArray: 'annotation',
17-
16+
module.exports = overrideAll(templatedArray('annotation', {
1817
visible: annAtts.visible,
1918
x: {
2019
valType: 'any',
@@ -94,4 +93,4 @@ module.exports = overrideAll({
9493
// xref: 'x'
9594
// yref: 'y
9695
// zref: 'z'
97-
}, 'calc', 'from-root');
96+
}), 'calc', 'from-root');

src/components/images/attributes.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
'use strict';
1010

1111
var cartesianConstants = require('../../plots/cartesian/constants');
12+
var templatedArray = require('../../plot_api/plot_template').templatedArray;
1213

1314

14-
module.exports = {
15-
_isLinkedToArray: 'image',
16-
15+
module.exports = templatedArray('image', {
1716
visible: {
1817
valType: 'boolean',
1918
role: 'info',
@@ -178,4 +177,4 @@ module.exports = {
178177
].join(' ')
179178
},
180179
editType: 'arraydraw'
181-
};
180+
});

src/components/rangeselector/attributes.js

+57-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,64 @@
1010

1111
var fontAttrs = require('../../plots/font_attributes');
1212
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: 'button',
13+
var templatedArray = require('../../plot_api/plot_template').templatedArray;
1814

15+
var buttonAttrs = templatedArray('button', {
16+
visible: {
17+
valType: 'boolean',
18+
role: 'info',
19+
dflt: true,
20+
editType: 'plot',
21+
description: 'Determines whether or not this button is visible.'
22+
},
23+
step: {
24+
valType: 'enumerated',
25+
role: 'info',
26+
values: ['month', 'year', 'day', 'hour', 'minute', 'second', 'all'],
27+
dflt: 'month',
28+
editType: 'plot',
29+
description: [
30+
'The unit of measurement that the `count` value will set the range by.'
31+
].join(' ')
32+
},
33+
stepmode: {
34+
valType: 'enumerated',
35+
role: 'info',
36+
values: ['backward', 'todate'],
37+
dflt: 'backward',
38+
editType: 'plot',
39+
description: [
40+
'Sets the range update mode.',
41+
'If *backward*, the range update shifts the start of range',
42+
'back *count* times *step* milliseconds.',
43+
'If *todate*, the range update shifts the start of range',
44+
'back to the first timestamp from *count* times',
45+
'*step* milliseconds back.',
46+
'For example, with `step` set to *year* and `count` set to *1*',
47+
'the range update shifts the start of the range back to',
48+
'January 01 of the current year.',
49+
'Month and year *todate* are currently available only',
50+
'for the built-in (Gregorian) calendar.'
51+
].join(' ')
52+
},
53+
count: {
54+
valType: 'number',
55+
role: 'info',
56+
min: 0,
57+
dflt: 1,
58+
editType: 'plot',
59+
description: [
60+
'Sets the number of steps to take to update the range.',
61+
'Use with `step` to specify the update interval.'
62+
].join(' ')
63+
},
64+
label: {
65+
valType: 'string',
66+
role: 'info',
67+
editType: 'plot',
68+
description: 'Sets the text label to appear on the button.'
69+
},
70+
editType: 'plot',
1971
description: [
2072
'Sets the specifications for each buttons.',
2173
'By default, a range selector comes with no buttons.'

src/components/rangeselector/button_attributes.js

-68
This file was deleted.

src/components/rangeselector/defaults.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ var Template = require('../../plot_api/plot_template');
1414
var handleArrayContainerDefaults = require('../../plots/array_container_defaults');
1515

1616
var attributes = require('./attributes');
17-
var buttonAttrs = require('./button_attributes');
1817
var constants = require('./constants');
1918

2019

@@ -55,7 +54,7 @@ function buttonDefaults(buttonIn, buttonOut, selectorOut, opts) {
5554
var calendar = opts.calendar;
5655

5756
function coerce(attr, dflt) {
58-
return Lib.coerce(buttonIn, buttonOut, buttonAttrs, attr, dflt);
57+
return Lib.coerce(buttonIn, buttonOut, attributes.buttons, attr, dflt);
5958
}
6059

6160
var visible = coerce('visible');

src/components/shapes/attributes.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ var annAttrs = require('../annotations/attributes');
1212
var scatterLineAttrs = require('../../traces/scatter/attributes').line;
1313
var dash = require('../drawing/attributes').dash;
1414
var extendFlat = require('../../lib/extend').extendFlat;
15+
var templatedArray = require('../../plot_api/plot_template').templatedArray;
1516

16-
module.exports = {
17-
_isLinkedToArray: 'shape',
18-
17+
module.exports = templatedArray('shape', {
1918
visible: {
2019
valType: 'boolean',
2120
role: 'info',
@@ -240,4 +239,4 @@ module.exports = {
240239
].join(' ')
241240
},
242241
editType: 'arraydraw'
243-
};
242+
});

src/components/sliders/attributes.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ var padAttrs = require('../../plots/pad_attributes');
1313
var extendDeepAll = require('../../lib/extend').extendDeepAll;
1414
var overrideAll = require('../../plot_api/edit_types').overrideAll;
1515
var animationAttrs = require('../../plots/animation_attributes');
16+
var templatedArray = require('../../plot_api/plot_template').templatedArray;
1617
var constants = require('./constants');
1718

18-
var stepsAttrs = {
19-
_isLinkedToArray: 'step',
20-
19+
var stepsAttrs = templatedArray('step', {
2120
visible: {
2221
valType: 'boolean',
2322
role: 'info',
@@ -78,11 +77,9 @@ var stepsAttrs = {
7877
'specification of `method` and `args`.'
7978
].join(' ')
8079
}
81-
};
82-
83-
module.exports = overrideAll({
84-
_isLinkedToArray: 'slider',
80+
});
8581

82+
module.exports = overrideAll(templatedArray('slider', {
8683
visible: {
8784
valType: 'boolean',
8885
role: 'info',
@@ -293,4 +290,4 @@ module.exports = overrideAll({
293290
role: 'style',
294291
description: 'Sets the length in pixels of minor step tick marks'
295292
}
296-
}, 'arraydraw', 'from-root');
293+
}), 'arraydraw', 'from-root');

src/components/updatemenus/attributes.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ var colorAttrs = require('../color/attributes');
1313
var extendFlat = require('../../lib/extend').extendFlat;
1414
var overrideAll = require('../../plot_api/edit_types').overrideAll;
1515
var padAttrs = require('../../plots/pad_attributes');
16+
var templatedArray = require('../../plot_api/plot_template').templatedArray;
1617

17-
var buttonsAttrs = {
18-
_isLinkedToArray: 'button',
19-
18+
var buttonsAttrs = templatedArray('button', {
2019
visible: {
2120
valType: 'boolean',
2221
role: 'info',
@@ -67,10 +66,9 @@ var buttonsAttrs = {
6766
'specification of `method` and `args`.'
6867
].join(' ')
6968
}
70-
};
69+
});
7170

72-
module.exports = overrideAll({
73-
_isLinkedToArray: 'updatemenu',
71+
module.exports = overrideAll(templatedArray('updatemenu', {
7472
_arrayAttrRegexps: [/^updatemenus\[(0|[1-9][0-9]+)\]\.buttons/],
7573

7674
visible: {
@@ -191,4 +189,4 @@ module.exports = overrideAll({
191189
editType: 'arraydraw',
192190
description: 'Sets the width (in px) of the border enclosing the update menu.'
193191
}
194-
}, 'arraydraw', 'from-root');
192+
}), 'arraydraw', 'from-root');

src/plot_api/plot_template.js

+50-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,56 @@
1212
var Lib = require('../lib');
1313
var plotAttributes = require('../plots/attributes');
1414

15-
var TEMPLATEITEMNAME = exports.TEMPLATEITEMNAME = 'templateitemname';
15+
var TEMPLATEITEMNAME = 'templateitemname';
16+
17+
var templateAttrs = {
18+
name: {
19+
valType: 'string',
20+
role: 'style',
21+
editType: 'none',
22+
description: [
23+
'When used in a template, named items are created in the output figure',
24+
'in addition to any items the figure already has in this array.',
25+
'You can modify these items in the output figure by making your own',
26+
'item with `templateitemname` matching this `name`',
27+
'alongside your modifications (including `visible: false` to hide it).',
28+
'Has no effect outside of a template.'
29+
].join(' ')
30+
}
31+
};
32+
templateAttrs[TEMPLATEITEMNAME] = {
33+
valType: 'string',
34+
role: 'info',
35+
editType: 'calc',
36+
description: [
37+
'Used to refer to a named item in this array in the template. Named',
38+
'items from the template will be created even without a matching item',
39+
'in the input figure, but you can modify one by making an item with',
40+
'`templateitemname` matching its `name`, alongside your',
41+
'modifications (including `visible: false` to hide it).',
42+
'If there is no template or no matching item, this item will be',
43+
'hidden unless you explicitly show it with `visible: true`.'
44+
].join(' ')
45+
};
46+
47+
/**
48+
* templatedArray: decorate an attributes object with templating (and array)
49+
* properties.
50+
*
51+
* @param {string} name: the singular form of the array name. Sets
52+
* `_isLinkedToArray` to this, so the schema knows to treat this as an array.
53+
* @param {object} attrs: the item attributes. Since all callers are expected
54+
* to be constructing this object on the spot, we mutate it here for
55+
* performance, rather than extending a new object with it.
56+
*
57+
* @returns {object}: the decorated `attrs` object
58+
*/
59+
exports.templatedArray = function(name, attrs) {
60+
attrs._isLinkedToArray = name;
61+
attrs.name = templateAttrs.name;
62+
attrs[TEMPLATEITEMNAME] = templateAttrs[TEMPLATEITEMNAME];
63+
return attrs;
64+
};
1665

1766
/**
1867
* traceTemplater: logic for matching traces to trace templates

src/plots/cartesian/layout_attributes.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var fontAttrs = require('../font_attributes');
1212
var colorAttrs = require('../../components/color/attributes');
1313
var dash = require('../../components/drawing/attributes').dash;
1414
var extendFlat = require('../../lib/extend').extendFlat;
15+
var templatedArray = require('../../plot_api/plot_template').templatedArray;
1516

1617
var constants = require('./constants');
1718

@@ -510,9 +511,7 @@ module.exports = {
510511
'*%H~%M~%S.%2f* would display *09~15~23.46*'
511512
].join(' ')
512513
},
513-
tickformatstops: {
514-
_isLinkedToArray: 'tickformatstop',
515-
514+
tickformatstops: templatedArray('tickformatstop', {
516515
visible: {
517516
valType: 'boolean',
518517
role: 'info',
@@ -547,7 +546,7 @@ module.exports = {
547546
].join(' ')
548547
},
549548
editType: 'ticks'
550-
},
549+
}),
551550
hoverformat: {
552551
valType: 'string',
553552
dflt: '',

0 commit comments

Comments
 (0)