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
4 changes: 3 additions & 1 deletion src/components/colorbar/defaults.js
Expand Up @@ -10,6 +10,8 @@
'use strict';

var Lib = require('../../lib');
var Template = require('../../plot_api/plot_template');

var handleTickValueDefaults = require('../../plots/cartesian/tick_value_defaults');
var handleTickMarkDefaults = require('../../plots/cartesian/tick_mark_defaults');
var handleTickLabelDefaults = require('../../plots/cartesian/tick_label_defaults');
Expand All @@ -18,7 +20,7 @@ var attributes = require('./attributes');


module.exports = function colorbarDefaults(containerIn, containerOut, layout) {
var colorbarOut = containerOut.colorbar = {},
var colorbarOut = Template.newContainer(containerOut, 'colorbar'),
colorbarIn = containerIn.colorbar || {};

function coerce(attr, dflt) {
Expand Down
7 changes: 4 additions & 3 deletions src/components/errorbars/defaults.js
Expand Up @@ -12,14 +12,15 @@ var isNumeric = require('fast-isnumeric');

var Registry = require('../../registry');
var Lib = require('../../lib');
var Template = require('../../plot_api/plot_template');

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


module.exports = function(traceIn, traceOut, defaultColor, opts) {
var objName = 'error_' + opts.axis,
containerOut = traceOut[objName] = {},
containerIn = traceIn[objName] || {};
var objName = 'error_' + opts.axis;
var containerOut = Template.newContainer(traceOut, objName);
var containerIn = traceIn[objName] || {};

function coerce(attr, dflt) {
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
Expand Down
10 changes: 6 additions & 4 deletions src/components/grid/index.js
Expand Up @@ -12,6 +12,7 @@ var Lib = require('../../lib');
var counterRegex = require('../../lib/regex').counter;
var domainAttrs = require('../../plots/domain').attributes;
var cartesianIdRegex = require('../../plots/cartesian/constants').idRegex;
var Template = require('../../plot_api/plot_template');

var gridAttrs = {
rows: {
Expand Down Expand Up @@ -201,7 +202,7 @@ function sizeDefaults(layoutIn, layoutOut) {
if(hasXaxes) dfltColumns = xAxes.length;
}

var gridOut = {};
var gridOut = Template.newContainer(layoutOut, 'grid');

function coerce(attr, dflt) {
return Lib.coerce(gridIn, gridOut, gridAttrs, attr, dflt);
Expand All @@ -210,7 +211,10 @@ function sizeDefaults(layoutIn, layoutOut) {
var rows = coerce('rows', dfltRows);
var columns = coerce('columns', dfltColumns);

if(!(rows * columns > 1)) return;
if(!(rows * columns > 1)) {
delete layoutOut.grid;
return;
}

if(!hasSubplotGrid && !hasXaxes && !hasYaxes) {
var useDefaultSubplots = coerce('pattern') === 'independent';
Expand All @@ -234,8 +238,6 @@ function sizeDefaults(layoutIn, layoutOut) {
x: fillGridPositions('x', coerce, dfltGapX, dfltSideX, columns),
y: fillGridPositions('y', coerce, dfltGapY, dfltSideY, rows, reversed)
};

layoutOut.grid = gridOut;
}

// coerce x or y sizing attributes and return an array of domains for this direction
Expand Down
12 changes: 6 additions & 6 deletions src/components/legend/defaults.js
Expand Up @@ -11,6 +11,7 @@

var Registry = require('../../registry');
var Lib = require('../../lib');
var Template = require('../../plot_api/plot_template');

var attributes = require('./attributes');
var basePlotLayoutAttributes = require('../../plots/layout_attributes');
Expand All @@ -19,7 +20,6 @@ var helpers = require('./helpers');

module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
var containerIn = layoutIn.legend || {};
var containerOut = {};

var visibleTraces = 0;
var defaultOrder = 'normal';
Expand Down Expand Up @@ -47,16 +47,16 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
}
}

function coerce(attr, dflt) {
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
}

var showLegend = Lib.coerce(layoutIn, layoutOut,
basePlotLayoutAttributes, 'showlegend', visibleTraces > 1);

if(showLegend === false) return;

layoutOut.legend = containerOut;
var containerOut = Template.newContainer(layoutOut, 'legend');

function coerce(attr, dflt) {
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
}

coerce('bgcolor', layoutOut.paper_bgcolor);
coerce('bordercolor');
Expand Down
17 changes: 10 additions & 7 deletions src/components/rangeslider/defaults.js
Expand Up @@ -9,9 +9,11 @@
'use strict';

var Lib = require('../../lib');
var Template = require('../../plot_api/plot_template');
var axisIds = require('../../plots/cartesian/axis_ids');

var attributes = require('./attributes');
var oppAxisAttrs = require('./oppaxis_attributes');
var axisIds = require('../../plots/cartesian/axis_ids');

module.exports = function handleDefaults(layoutIn, layoutOut, axName) {
var axIn = layoutIn[axName];
Expand All @@ -25,13 +27,14 @@ module.exports = function handleDefaults(layoutIn, layoutOut, axName) {
}

var containerIn = axIn.rangeslider;
var containerOut = axOut.rangeslider = {};
var containerOut = Template.newContainer(axOut, 'rangeslider');

function coerce(attr, dflt) {
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
}

function coerceRange(rangeContainerIn, rangeContainerOut, attr, dflt) {
var rangeContainerIn, rangeContainerOut;
function coerceRange(attr, dflt) {
return Lib.coerce(rangeContainerIn, rangeContainerOut, oppAxisAttrs, attr, dflt);
}

Expand Down Expand Up @@ -59,8 +62,8 @@ module.exports = function handleDefaults(layoutIn, layoutOut, axName) {
for(var i = 0; i < yNames.length; i++) {
var yName = yNames[i];

var rangeContainerIn = containerIn[yName] || {};
var rangeContainerOut = containerOut[yName] = {};
rangeContainerIn = containerIn[yName] || {};
rangeContainerOut = Template.newContainer(containerOut, yName, 'yaxis');

var yAxOut = layoutOut[yName];

Expand All @@ -69,9 +72,9 @@ module.exports = function handleDefaults(layoutIn, layoutOut, axName) {
rangemodeDflt = 'fixed';
}

var rangeMode = coerceRange(rangeContainerIn, rangeContainerOut, 'rangemode', rangemodeDflt);
var rangeMode = coerceRange('rangemode', rangemodeDflt);
if(rangeMode !== 'match') {
coerceRange(rangeContainerIn, rangeContainerOut, 'range', yAxOut.range.slice());
coerceRange('range', yAxOut.range.slice());
}
yAxOut._rangesliderAutorange = (rangeMode === 'auto');
}
Expand Down
37 changes: 27 additions & 10 deletions src/lib/coerce.js
Expand Up @@ -343,12 +343,12 @@ exports.valObjectMeta = {
return false;
}
for(var j = 0; j < v[i].length; j++) {
if(!exports.validate(v[i][j], arrayItems ? items[i][j] : items)) {
if(!validate(v[i][j], arrayItems ? items[i][j] : items)) {
return false;
}
}
}
else if(!exports.validate(v[i], arrayItems ? items[i] : items)) return false;
else if(!validate(v[i], arrayItems ? items[i] : items)) return false;
}

return true;
Expand All @@ -369,10 +369,17 @@ exports.valObjectMeta = {
* as a convenience, returns the value it finally set
*/
exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt) {
var opts = nestedProperty(attributes, attribute).get(),
propIn = nestedProperty(containerIn, attribute),
propOut = nestedProperty(containerOut, attribute),
v = propIn.get();
var opts = nestedProperty(attributes, attribute).get();
var propIn = nestedProperty(containerIn, attribute);
var propOut = nestedProperty(containerOut, attribute);
var v = propIn.get();

var template = containerOut._template;
if(v === undefined && template) {
v = nestedProperty(template, attribute).get();
// already used the template value, so short-circuit the second check
template = 0;
}

if(dflt === undefined) dflt = opts.dflt;

Expand All @@ -387,9 +394,18 @@ exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt
return v;
}

exports.valObjectMeta[opts.valType].coerceFunction(v, propOut, dflt, opts);
var coerceFunction = exports.valObjectMeta[opts.valType].coerceFunction;
coerceFunction(v, propOut, dflt, opts);

return propOut.get();
var out = propOut.get();
// in case v was provided but invalid, try the template again so it still
// overrides the regular default
if(template && out === dflt && !validate(v, opts)) {
v = nestedProperty(template, attribute).get();
coerceFunction(v, propOut, dflt, opts);
out = propOut.get();
}
return out;
};

/**
Expand Down Expand Up @@ -486,7 +502,7 @@ exports.coerceSelectionMarkerOpacity = function(traceOut, coerce) {
coerce('unselected.marker.opacity', usmoDflt);
};

exports.validate = function(value, opts) {
function validate(value, opts) {
var valObjectDef = exports.valObjectMeta[opts.valType];

if(opts.arrayOk && isArrayOrTypedArray(value)) return true;
Expand All @@ -503,4 +519,5 @@ exports.validate = function(value, opts) {

valObjectDef.coerceFunction(value, propMock, failed, opts);
return out !== failed;
};
}
exports.validate = validate;
1 change: 1 addition & 0 deletions src/plot_api/index.js
Expand Up @@ -31,3 +31,4 @@ exports.setPlotConfig = main.setPlotConfig;
exports.toImage = require('./to_image');
exports.validate = require('./validate');
exports.downloadImage = require('../snapshot/download');
exports.makeTemplate = require('./make_template');