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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 19 additions & 27 deletions src/components/rangeselector/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
var Lib = require('../../lib');
var Color = require('../color');
var Template = require('../../plot_api/plot_template');
var handleArrayContainerDefaults = require('../../plots/array_container_defaults');

var attributes = require('./attributes');
var buttonAttrs = require('./button_attributes');
Expand All @@ -25,7 +26,11 @@ module.exports = function handleDefaults(containerIn, containerOut, layout, coun
return Lib.coerce(selectorIn, selectorOut, attributes, attr, dflt);
}

var buttons = buttonsDefaults(selectorIn, selectorOut, calendar);
var buttons = handleArrayContainerDefaults(selectorIn, selectorOut, {
name: 'buttons',
handleItemDefaults: buttonDefaults,
calendar: calendar
});

var visible = coerce('visible', buttons.length > 0);
if(!visible) return;
Expand All @@ -46,43 +51,30 @@ module.exports = function handleDefaults(containerIn, containerOut, layout, coun
coerce('borderwidth');
};

function buttonsDefaults(containerIn, containerOut, calendar) {
var buttonsIn = containerIn.buttons || [],
buttonsOut = containerOut.buttons = [];

var buttonIn, buttonOut;
function buttonDefaults(buttonIn, buttonOut, selectorOut, opts, itemOpts) {
var calendar = opts.calendar;

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

for(var i = 0; i < buttonsIn.length; i++) {
buttonIn = buttonsIn[i];
buttonOut = {};

var visible = coerce('visible', Lib.isPlainObject(buttonIn));
var visible = coerce('visible', !itemOpts.itemIsNotPlainObject);

if(visible) {
var step = coerce('step');
if(step !== 'all') {
if(calendar && calendar !== 'gregorian' && (step === 'month' || step === 'year')) {
buttonOut.stepmode = 'backward';
}
else {
coerce('stepmode');
}

coerce('count');
if(visible) {
var step = coerce('step');
if(step !== 'all') {
if(calendar && calendar !== 'gregorian' && (step === 'month' || step === 'year')) {
buttonOut.stepmode = 'backward';
}
else {
coerce('stepmode');
}

coerce('label');
coerce('count');
}

buttonOut._index = i;
buttonsOut.push(buttonOut);
coerce('label');
}

return buttonsOut;
}

function getPosDflt(containerOut, layout, counterAxes) {
Expand Down
36 changes: 12 additions & 24 deletions src/components/updatemenus/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ function menuDefaults(menuIn, menuOut, layoutOut) {
return Lib.coerce(menuIn, menuOut, attributes, attr, dflt);
}

var buttons = buttonsDefaults(menuIn, menuOut);
var buttons = handleArrayContainerDefaults(menuIn, menuOut, {
name: 'buttons',
handleItemDefaults: buttonDefaults
});

var visible = coerce('visible', buttons.length > 0);
if(!visible) return;
Expand Down Expand Up @@ -62,32 +65,17 @@ function menuDefaults(menuIn, menuOut, layoutOut) {
coerce('borderwidth');
}

function buttonsDefaults(menuIn, menuOut) {
var buttonsIn = menuIn.buttons || [],
buttonsOut = menuOut.buttons = [];

var buttonIn, buttonOut;

function buttonDefaults(buttonIn, buttonOut, selectorOut, opts, itemOpts) {
function coerce(attr, dflt) {
return Lib.coerce(buttonIn, buttonOut, buttonAttrs, attr, dflt);
}

for(var i = 0; i < buttonsIn.length; i++) {
buttonIn = buttonsIn[i];
buttonOut = {};

var visible = coerce('visible', Lib.isPlainObject(buttonIn) &&
(buttonIn.method === 'skip' || Array.isArray(buttonIn.args)));
if(visible) {
coerce('method');
coerce('args');
coerce('label');
coerce('execute');
}

buttonOut._index = i;
buttonsOut.push(buttonOut);
var visible = coerce('visible', !itemOpts.itemIsNotPlainObject &&
(buttonIn.method === 'skip' || Array.isArray(buttonIn.args)));
if(visible) {
coerce('method');
coerce('args');
coerce('label');
coerce('execute');
}

return buttonsOut;
}
93 changes: 36 additions & 57 deletions src/traces/parcoords/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
'use strict';

var Lib = require('../../lib');
var attributes = require('./attributes');
var hasColorscale = require('../../components/colorscale/has_colorscale');
var colorscaleDefaults = require('../../components/colorscale/defaults');
var maxDimensionCount = require('./constants').maxDimensionCount;
var handleDomainDefaults = require('../../plots/domain').defaults;
var handleArrayContainerDefaults = require('../../plots/array_container_defaults');

var attributes = require('./attributes');
var axisBrush = require('./axisbrush');
var maxDimensionCount = require('./constants').maxDimensionCount;
var mergeLength = require('./merge_length');

function handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
var lineColor = coerce('line.color', defaultColor);
Expand All @@ -26,90 +29,66 @@ function handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
// TODO: I think it would be better to keep showing lines beyond the last line color
// but I'm not sure what color to give these lines - probably black or white
// depending on the background color?
traceOut._length = Math.min(traceOut._length, lineColor.length);
return lineColor.length;
}
else {
traceOut.line.color = defaultColor;
}
}
return Infinity;
}

function dimensionsDefaults(traceIn, traceOut) {
var dimensionsIn = traceIn.dimensions || [],
dimensionsOut = traceOut.dimensions = [];

var dimensionIn, dimensionOut, i;
var commonLength = Infinity;

if(dimensionsIn.length > maxDimensionCount) {
Lib.log('parcoords traces support up to ' + maxDimensionCount + ' dimensions at the moment');
dimensionsIn.splice(maxDimensionCount);
}

function dimensionDefaults(dimensionIn, dimensionOut, traceOut, opts, itemOpts) {
function coerce(attr, dflt) {
return Lib.coerce(dimensionIn, dimensionOut, attributes.dimensions, attr, dflt);
}

for(i = 0; i < dimensionsIn.length; i++) {
dimensionIn = dimensionsIn[i];
dimensionOut = {};

if(!Lib.isPlainObject(dimensionIn)) {
continue;
}

var values = coerce('values');
var visible = coerce('visible');
if(!(values && values.length)) {
visible = dimensionOut.visible = false;
}

if(visible) {
coerce('label');
coerce('tickvals');
coerce('ticktext');
coerce('tickformat');
coerce('range');

coerce('multiselect');
var constraintRange = coerce('constraintrange');
if(constraintRange) {
dimensionOut.constraintrange = axisBrush.cleanRanges(constraintRange, dimensionOut);
}
var values = coerce('values');
var visible = coerce('visible');
if(!(values && values.length && !itemOpts.itemIsNotPlainObject)) {
visible = dimensionOut.visible = false;
}

commonLength = Math.min(commonLength, values.length);
if(visible) {
coerce('label');
coerce('tickvals');
coerce('ticktext');
coerce('tickformat');
coerce('range');

coerce('multiselect');
var constraintRange = coerce('constraintrange');
if(constraintRange) {
dimensionOut.constraintrange = axisBrush.cleanRanges(constraintRange, dimensionOut);
}

dimensionOut._index = i;
dimensionsOut.push(dimensionOut);
}

traceOut._length = commonLength;

return dimensionsOut;
}

module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}

var dimensions = dimensionsDefaults(traceIn, traceOut);
var dimensionsIn = traceIn.dimensions;
if(Array.isArray(dimensionsIn) && dimensionsIn.length > maxDimensionCount) {
Lib.log('parcoords traces support up to ' + maxDimensionCount + ' dimensions at the moment');
dimensionsIn.splice(maxDimensionCount);
}

var dimensions = handleArrayContainerDefaults(traceIn, traceOut, {
name: 'dimensions',
handleItemDefaults: dimensionDefaults
});

handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);
var len = handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);

handleDomainDefaults(traceOut, layout, coerce);

if(!Array.isArray(dimensions) || !dimensions.length) {
traceOut.visible = false;
}

// since we're not slicing uneven arrays anymore, stash the length in each dimension
// but we can't do this in dimensionsDefaults (yet?) because line.color can also
// truncate
for(var i = 0; i < dimensions.length; i++) {
if(dimensions[i].visible) dimensions[i]._length = traceOut._length;
}
mergeLength(traceOut, dimensions, 'values', len);

// make default font size 10px (default is 12),
// scale linearly with global font size
Expand Down
36 changes: 36 additions & 0 deletions src/traces/parcoords/merge_length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright 2012-2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

/**
* mergeLength: set trace length as the minimum of all dimension data lengths
* and propagates this length into each dimension
*
* @param {object} traceOut: the fullData trace
* @param {Array(object)} dimensions: array of dimension objects
* @param {string} dataAttr: the attribute of each dimension containing the data
* @param {integer} len: an already-existing length from other attributes
*/
module.exports = function(traceOut, dimensions, dataAttr, len) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nicely done 🥇

if(!len) len = Infinity;
var i, dimi;
for(i = 0; i < dimensions.length; i++) {
dimi = dimensions[i];
if(dimi.visible) len = Math.min(len, dimi[dataAttr].length);
}
if(len === Infinity) len = 0;

traceOut._length = len;
for(i = 0; i < dimensions.length; i++) {
dimi = dimensions[i];
if(dimi.visible) dimi._length = len;
}

return len;
};
54 changes: 14 additions & 40 deletions src/traces/splom/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,30 @@
'use strict';

var Lib = require('../../lib');
var handleArrayContainerDefaults = require('../../plots/array_container_defaults');

var attributes = require('./attributes');
var subTypes = require('../scatter/subtypes');
var handleMarkerDefaults = require('../scatter/marker_defaults');
var mergeLength = require('../parcoords/merge_length');
var OPEN_RE = /-open/;

module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}

var dimLength = handleDimensionsDefaults(traceIn, traceOut);
var dimensions = handleArrayContainerDefaults(traceIn, traceOut, {
name: 'dimensions',
handleItemDefaults: dimensionDefaults
});

var showDiag = coerce('diagonal.visible');
var showUpper = coerce('showupperhalf');
var showLower = coerce('showlowerhalf');

var dimLength = mergeLength(traceOut, dimensions, 'values');

if(!dimLength || (!showDiag && !showUpper && !showLower)) {
traceOut.visible = false;
return;
Expand All @@ -44,51 +51,18 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
};

function handleDimensionsDefaults(traceIn, traceOut) {
var dimensionsIn = traceIn.dimensions;
if(!Array.isArray(dimensionsIn)) return 0;

var dimLength = dimensionsIn.length;
var commonLength = 0;
var dimensionsOut = traceOut.dimensions = new Array(dimLength);
var dimIn;
var dimOut;
var i;

function dimensionDefaults(dimIn, dimOut, traceOut, opts, itemOpts) {
function coerce(attr, dflt) {
return Lib.coerce(dimIn, dimOut, attributes.dimensions, attr, dflt);
}

for(i = 0; i < dimLength; i++) {
dimIn = dimensionsIn[i];
dimOut = dimensionsOut[i] = {};
coerce('label');
coerce('visible');
var values = coerce('values');

// coerce label even if dimensions may be `visible: false`,
// to fill in axis title defaults
coerce('label');

// wait until plot step to filter out visible false dimensions
var visible = coerce('visible');
if(!visible) continue;

var values = coerce('values');
if(!values || !values.length) {
dimOut.visible = false;
continue;
}

commonLength = Math.max(commonLength, values.length);
dimOut._index = i;
}

for(i = 0; i < dimLength; i++) {
dimOut = dimensionsOut[i];
if(dimOut.visible) dimOut._length = commonLength;
if(!(values && values.length && !itemOpts.itemIsNotPlainObject)) {
dimOut.visible = false;
}

traceOut._length = commonLength;

return dimensionsOut.length;
}

function handleAxisDefaults(traceIn, traceOut, layout, coerce) {
Expand Down
Loading