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 18 commits
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
2 changes: 1 addition & 1 deletion devtools/test_dashboard/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ window.timeit = function(f, n, nchunk, arg) {

var first = (times[0]).toFixed(4);
var last = (times[n - 1]).toFixed(4);
times.sort();
times.sort(function(a, b) { return a - b; });
var min = (times[0]).toFixed(4);
var max = (times[n - 1]).toFixed(4);
var median = (times[Math.min(Math.ceil(n / 2), n - 1)]).toFixed(4);
Expand Down
95 changes: 0 additions & 95 deletions src/components/annotations/annotation_defaults.js

This file was deleted.

7 changes: 3 additions & 4 deletions src/components/annotations/attributes.js
Original file line number Diff line number Diff line change
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(' ')
}
}
};
});
21 changes: 14 additions & 7 deletions src/components/annotations/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

'use strict';

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

module.exports = {
hasClickToShow: hasClickToShow,
Expand Down Expand Up @@ -41,20 +43,25 @@ function hasClickToShow(gd, hoverData) {
* returns: Promise that the update is complete
*/
function onClick(gd, hoverData) {
var toggleSets = getToggleSets(gd, hoverData),
onSet = toggleSets.on,
offSet = toggleSets.off.concat(toggleSets.explicitOff),
update = {},
i;
var toggleSets = getToggleSets(gd, hoverData);
var onSet = toggleSets.on;
var offSet = toggleSets.off.concat(toggleSets.explicitOff);
var update = {};
var annotationsOut = gd._fullLayout.annotations;
var i, editHelpers;

if(!(onSet.length || offSet.length)) return;

for(i = 0; i < onSet.length; i++) {
update['annotations[' + onSet[i] + '].visible'] = true;
editHelpers = arrayEditor(gd.layout, 'annotations', annotationsOut[onSet[i]]);
editHelpers.modifyItem('visible', true);
Lib.extendFlat(update, editHelpers.getUpdateObj());
}

for(i = 0; i < offSet.length; i++) {
update['annotations[' + offSet[i] + '].visible'] = false;
editHelpers = arrayEditor(gd.layout, 'annotations', annotationsOut[offSet[i]]);
editHelpers.modifyItem('visible', false);
Lib.extendFlat(update, editHelpers.getUpdateObj());
}

return Registry.call('update', gd, {}, update);
Expand Down
86 changes: 81 additions & 5 deletions src/components/annotations/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,91 @@

'use strict';

var Lib = require('../../lib');
var Axes = require('../../plots/cartesian/axes');
var handleArrayContainerDefaults = require('../../plots/array_container_defaults');
var handleAnnotationDefaults = require('./annotation_defaults');
Copy link
Contributor

Choose a reason for hiding this comment

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

YES. Thanks for doing this 💯


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


module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {
var opts = {
handleArrayContainerDefaults(layoutIn, layoutOut, {
name: 'annotations',
handleItemDefaults: handleAnnotationDefaults
};

handleArrayContainerDefaults(layoutIn, layoutOut, opts);
});
};

function handleAnnotationDefaults(annIn, annOut, fullLayout) {
function coerce(attr, dflt) {
return Lib.coerce(annIn, annOut, attributes, attr, dflt);
}

var visible = coerce('visible');
var clickToShow = coerce('clicktoshow');

if(!(visible || clickToShow)) return;

handleAnnotationCommonDefaults(annIn, annOut, fullLayout, coerce);

var showArrow = annOut.showarrow;

// positioning
var axLetters = ['x', 'y'],
arrowPosDflt = [-10, -30],
gdMock = {_fullLayout: fullLayout};
for(var i = 0; i < 2; i++) {
var axLetter = axLetters[i];

// xref, yref
var axRef = Axes.coerceRef(annIn, annOut, gdMock, axLetter, '', 'paper');

// x, y
Axes.coercePosition(annOut, gdMock, coerce, axRef, axLetter, 0.5);

if(showArrow) {
var arrowPosAttr = 'a' + axLetter,
// axref, ayref
aaxRef = Axes.coerceRef(annIn, annOut, gdMock, arrowPosAttr, 'pixel');

// for now the arrow can only be on the same axis or specified as pixels
// TODO: sometime it might be interesting to allow it to be on *any* axis
// but that would require updates to drawing & autorange code and maybe more
if(aaxRef !== 'pixel' && aaxRef !== axRef) {
aaxRef = annOut[arrowPosAttr] = 'pixel';
}

// ax, ay
var aDflt = (aaxRef === 'pixel') ? arrowPosDflt[i] : 0.4;
Axes.coercePosition(annOut, gdMock, coerce, aaxRef, arrowPosAttr, aDflt);
}

// xanchor, yanchor
coerce(axLetter + 'anchor');

// xshift, yshift
coerce(axLetter + 'shift');
}

// if you have one coordinate you should have both
Lib.noneOrAll(annIn, annOut, ['x', 'y']);

// if you have one part of arrow length you should have both
if(showArrow) {
Lib.noneOrAll(annIn, annOut, ['ax', 'ay']);
}

if(clickToShow) {
var xClick = coerce('xclick');
var yClick = coerce('yclick');

// put the actual click data to bind to into private attributes
// so we don't have to do this little bit of logic on every hover event
annOut._xclick = (xClick === undefined) ?
annOut.x :
Axes.cleanPosition(xClick, gdMock, annOut.xref);
annOut._yclick = (yClick === undefined) ?
annOut.y :
Axes.cleanPosition(yClick, gdMock, annOut.yref);
}
}
Loading