Skip to content
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

Templates #2761

Merged
merged 24 commits into from Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b8950c5
fix devtools timeit sorting
alexcjohnson Jun 19, 2018
355fb09
stop pushing tickmode back to axis in for a particular edge case
alexcjohnson Jun 18, 2018
8ddcfd6
minor simplification in pie defaults
alexcjohnson Jun 21, 2018
b5ccfbe
combine annotation defaults files & shape defaults files
alexcjohnson Jun 21, 2018
86e09bb
add visible attribute to lots of container array items:
alexcjohnson Jun 20, 2018
3dee25c
use handleArrayContainerDefaults for various array containers:
alexcjohnson Jun 21, 2018
5cca8d3
templates - big commit implementing most of it, coerce-level integration
bpostlethwaite Apr 12, 2018
b3da4e7
:hocho: itemIsNotPlainObject from handleArrayContainerDefaults
alexcjohnson Jun 26, 2018
8525953
add template attributes to array containers
alexcjohnson Jun 26, 2018
e306d1c
template-safe axis default color inheritance logic
alexcjohnson Jun 27, 2018
8e2a321
template-safe GUI editing of array objects
alexcjohnson Jun 27, 2018
4346611
template mock
alexcjohnson Jun 27, 2018
fb489aa
tickformatstops.visible -> enabled
alexcjohnson Jun 28, 2018
bc21cc8
:hocho: done TODO
alexcjohnson Jun 28, 2018
8490804
fix test failures - and simplify handleArrayContainerDefaults even mo…
alexcjohnson Jun 28, 2018
c2bcfe3
fix makeTemplate and test it & template interactions
alexcjohnson Jul 1, 2018
890a324
fix Plotly.validate with attributes that end in numbers
alexcjohnson Jul 2, 2018
aed44dc
Plotly.validateTemplate
alexcjohnson Jul 3, 2018
6df61e0
loosen template default item interaction tests to pass on CI
alexcjohnson Jul 3, 2018
ef4c3cc
TODO -> note re: axis.type _noTemplate
alexcjohnson Jul 3, 2018
b1c6f0a
_noTemplating for angularaxis.type
alexcjohnson Jul 3, 2018
818cac9
:cow2: test name typo
alexcjohnson Jul 3, 2018
15931cf
recurse into (template)layout looking for unused containers
alexcjohnson Jul 3, 2018
8598bc9
:hocho: obsolete code
alexcjohnson Jul 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/components/annotations/attributes.js
Expand Up @@ -11,11 +11,10 @@
var ARROWPATHS = require('./arrow_paths');
var fontAttrs = require('../../plots/font_attributes');
var cartesianConstants = require('../../plots/cartesian/constants');
var templatedArray = require('../../plot_api/plot_template').templatedArray;


module.exports = {
_isLinkedToArray: 'annotation',

module.exports = templatedArray('annotation', {
visible: {
valType: 'boolean',
role: 'info',
Expand Down Expand Up @@ -543,4 +542,4 @@ module.exports = {
].join(' ')
}
}
};
});
7 changes: 3 additions & 4 deletions src/components/annotations3d/attributes.js
Expand Up @@ -11,10 +11,9 @@

var annAtts = require('../annotations/attributes');
var overrideAll = require('../../plot_api/edit_types').overrideAll;
var templatedArray = require('../../plot_api/plot_template').templatedArray;

module.exports = overrideAll({
_isLinkedToArray: 'annotation',

module.exports = overrideAll(templatedArray('annotation', {
visible: annAtts.visible,
x: {
valType: 'any',
Expand Down Expand Up @@ -94,4 +93,4 @@ module.exports = overrideAll({
// xref: 'x'
// yref: 'y
// zref: 'z'
}, 'calc', 'from-root');
}), 'calc', 'from-root');
7 changes: 3 additions & 4 deletions src/components/images/attributes.js
Expand Up @@ -9,11 +9,10 @@
'use strict';

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


module.exports = {
_isLinkedToArray: 'image',

module.exports = templatedArray('image', {
visible: {
valType: 'boolean',
role: 'info',
Expand Down Expand Up @@ -178,4 +177,4 @@ module.exports = {
].join(' ')
},
editType: 'arraydraw'
};
});
62 changes: 57 additions & 5 deletions src/components/rangeselector/attributes.js
Expand Up @@ -10,12 +10,64 @@

var fontAttrs = require('../../plots/font_attributes');
var colorAttrs = require('../color/attributes');
var extendFlat = require('../../lib/extend').extendFlat;
var buttonAttrs = require('./button_attributes');

buttonAttrs = extendFlat(buttonAttrs, {
_isLinkedToArray: 'button',
var templatedArray = require('../../plot_api/plot_template').templatedArray;

var buttonAttrs = templatedArray('button', {
visible: {
valType: 'boolean',
role: 'info',
dflt: true,
editType: 'plot',
description: 'Determines whether or not this button is visible.'
},
step: {
valType: 'enumerated',
role: 'info',
values: ['month', 'year', 'day', 'hour', 'minute', 'second', 'all'],
dflt: 'month',
editType: 'plot',
description: [
'The unit of measurement that the `count` value will set the range by.'
].join(' ')
},
stepmode: {
valType: 'enumerated',
role: 'info',
values: ['backward', 'todate'],
dflt: 'backward',
editType: 'plot',
description: [
'Sets the range update mode.',
'If *backward*, the range update shifts the start of range',
'back *count* times *step* milliseconds.',
'If *todate*, 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.',
'Month and year *todate* are currently available only',
'for the built-in (Gregorian) calendar.'
].join(' ')
},
count: {
valType: 'number',
role: 'info',
min: 0,
dflt: 1,
editType: 'plot',
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',
editType: 'plot',
description: 'Sets the text label to appear on the button.'
},
editType: 'plot',
description: [
'Sets the specifications for each buttons.',
'By default, a range selector comes with no buttons.'
Expand Down
68 changes: 0 additions & 68 deletions src/components/rangeselector/button_attributes.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/components/rangeselector/defaults.js
Expand Up @@ -14,7 +14,6 @@ var Template = require('../../plot_api/plot_template');
var handleArrayContainerDefaults = require('../../plots/array_container_defaults');

var attributes = require('./attributes');
var buttonAttrs = require('./button_attributes');
var constants = require('./constants');


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

function coerce(attr, dflt) {
return Lib.coerce(buttonIn, buttonOut, buttonAttrs, attr, dflt);
return Lib.coerce(buttonIn, buttonOut, attributes.buttons, attr, dflt);
}

var visible = coerce('visible');
Expand Down
7 changes: 3 additions & 4 deletions src/components/shapes/attributes.js
Expand Up @@ -12,10 +12,9 @@ var annAttrs = require('../annotations/attributes');
var scatterLineAttrs = require('../../traces/scatter/attributes').line;
var dash = require('../drawing/attributes').dash;
var extendFlat = require('../../lib/extend').extendFlat;
var templatedArray = require('../../plot_api/plot_template').templatedArray;

module.exports = {
_isLinkedToArray: 'shape',

module.exports = templatedArray('shape', {
visible: {
valType: 'boolean',
role: 'info',
Expand Down Expand Up @@ -240,4 +239,4 @@ module.exports = {
].join(' ')
},
editType: 'arraydraw'
};
});
13 changes: 5 additions & 8 deletions src/components/sliders/attributes.js
Expand Up @@ -13,11 +13,10 @@ var padAttrs = require('../../plots/pad_attributes');
var extendDeepAll = require('../../lib/extend').extendDeepAll;
var overrideAll = require('../../plot_api/edit_types').overrideAll;
var animationAttrs = require('../../plots/animation_attributes');
var templatedArray = require('../../plot_api/plot_template').templatedArray;
var constants = require('./constants');

var stepsAttrs = {
_isLinkedToArray: 'step',

var stepsAttrs = templatedArray('step', {
visible: {
valType: 'boolean',
role: 'info',
Expand Down Expand Up @@ -78,11 +77,9 @@ var stepsAttrs = {
'specification of `method` and `args`.'
].join(' ')
}
};

module.exports = overrideAll({
_isLinkedToArray: 'slider',
});

module.exports = overrideAll(templatedArray('slider', {
visible: {
valType: 'boolean',
role: 'info',
Expand Down Expand Up @@ -293,4 +290,4 @@ module.exports = overrideAll({
role: 'style',
description: 'Sets the length in pixels of minor step tick marks'
}
}, 'arraydraw', 'from-root');
}), 'arraydraw', 'from-root');
12 changes: 5 additions & 7 deletions src/components/updatemenus/attributes.js
Expand Up @@ -13,10 +13,9 @@ var colorAttrs = require('../color/attributes');
var extendFlat = require('../../lib/extend').extendFlat;
var overrideAll = require('../../plot_api/edit_types').overrideAll;
var padAttrs = require('../../plots/pad_attributes');
var templatedArray = require('../../plot_api/plot_template').templatedArray;

var buttonsAttrs = {
_isLinkedToArray: 'button',

var buttonsAttrs = templatedArray('button', {
visible: {
valType: 'boolean',
role: 'info',
Expand Down Expand Up @@ -67,10 +66,9 @@ var buttonsAttrs = {
'specification of `method` and `args`.'
].join(' ')
}
};
});

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

visible: {
Expand Down Expand Up @@ -191,4 +189,4 @@ module.exports = overrideAll({
editType: 'arraydraw',
description: 'Sets the width (in px) of the border enclosing the update menu.'
}
}, 'arraydraw', 'from-root');
}), 'arraydraw', 'from-root');
51 changes: 50 additions & 1 deletion src/plot_api/plot_template.js
Expand Up @@ -12,7 +12,56 @@
var Lib = require('../lib');
var plotAttributes = require('../plots/attributes');

var TEMPLATEITEMNAME = exports.TEMPLATEITEMNAME = 'templateitemname';
var TEMPLATEITEMNAME = 'templateitemname';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm usually not a fan of three-word attribute names, but I can't really think of a better alternative, so 👍


var templateAttrs = {
name: {
valType: 'string',
role: 'style',
editType: 'none',
description: [
'When used in a template, named items are created in the output figure',
'in addition to any items the figure already has in this array.',
'You can modify these items in the output figure by making your own',
'item with `templateitemname` matching this `name`',
'alongside your modifications (including `visible: false` to hide it).',
'Has no effect outside of a template.'
].join(' ')
}
};
templateAttrs[TEMPLATEITEMNAME] = {
valType: 'string',
role: 'info',
editType: 'calc',
description: [
'Used to refer to a named item in this array in the template. Named',
'items from the template will be created even without a matching item',
'in the input figure, but you can modify one by making an item with',
'`templateitemname` matching its `name`, alongside your',
'modifications (including `visible: false` to hide it).',
'If there is no template or no matching item, this item will be',
'hidden unless you explicitly show it with `visible: true`.'
].join(' ')
};

/**
* templatedArray: decorate an attributes object with templating (and array)
* properties.
*
* @param {string} name: the singular form of the array name. Sets
* `_isLinkedToArray` to this, so the schema knows to treat this as an array.
* @param {object} attrs: the item attributes. Since all callers are expected
* to be constructing this object on the spot, we mutate it here for
* performance, rather than extending a new object with it.
*
* @returns {object}: the decorated `attrs` object
*/
exports.templatedArray = function(name, attrs) {
attrs._isLinkedToArray = name;
attrs.name = templateAttrs.name;
attrs[TEMPLATEITEMNAME] = templateAttrs[TEMPLATEITEMNAME];
return attrs;
};

/**
* traceTemplater: logic for matching traces to trace templates
Expand Down
7 changes: 3 additions & 4 deletions src/plots/cartesian/layout_attributes.js
Expand Up @@ -12,6 +12,7 @@ var fontAttrs = require('../font_attributes');
var colorAttrs = require('../../components/color/attributes');
var dash = require('../../components/drawing/attributes').dash;
var extendFlat = require('../../lib/extend').extendFlat;
var templatedArray = require('../../plot_api/plot_template').templatedArray;

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

Expand Down Expand Up @@ -510,9 +511,7 @@ module.exports = {
'*%H~%M~%S.%2f* would display *09~15~23.46*'
].join(' ')
},
tickformatstops: {
_isLinkedToArray: 'tickformatstop',

tickformatstops: templatedArray('tickformatstop', {
visible: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe enabled (similar to transforms) here would make more sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

.... but maybe it isn't worth breaking symmetric with all other templated arrays 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, enabled certainly makes more sense here. I thought about that but deferred to symmetry at the time. But the way this ended up working out, it would be easy to make visibilityAttr: 'enabled' or something an option to handleArrayContainerDefaults. I'll give that a try.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

switched to enabled in fb489aa

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm glad this wasn't too hard to implement 🎉

valType: 'boolean',
role: 'info',
Expand Down Expand Up @@ -547,7 +546,7 @@ module.exports = {
].join(' ')
},
editType: 'ticks'
},
}),
hoverformat: {
valType: 'string',
dflt: '',
Expand Down