Skip to content

Commit

Permalink
sankey update defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinerg committed Oct 15, 2018
1 parent b436003 commit fe7ab49
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/traces/sankey/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ var attributes = require('./attributes');
var Color = require('../../components/color');
var tinycolor = require('tinycolor2');
var handleDomainDefaults = require('../../plots/domain').defaults;
var handleFxDefaults = require('../../components/fx/defaults');
var handleHoverLabelDefaults = require('../../components/fx/hoverlabel_defaults');
var fxAttrs = require('../../components/fx/attributes');

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

This comment has been minimized.

Copy link
@alexcjohnson

alexcjohnson Oct 15, 2018

Collaborator

Doing it this way is more efficient than what coerceAxis, as posted in my other comment, does - ie Lib.coerce doesn't need to dive into sub-containers as much. But it also means Lib.coerce doesn't have access to traceOut._template, so if you want to use this pattern you need to explicitly create traceOut.node (and .link) using Template.newContainer.
Also, instead of fxAttrs you should use attributes.node, since fxAttrs won't be quite right in this context.

... and at that point, the rest of the node and link attribute coercion could be more efficient if they use the same coerce function: instead of coerce('node.label') do coerceNode('label').

handleHoverLabelDefaults(traceIn[type], traceOut[type], coerce, layout.hoverlabel);
}

coerce('node.label');
coerce('node.pad');
coerce('node.thickness');
coerce('node.line.color');
coerce('node.line.width');
coerce('node.hoverinfo');
handleFxDefaults(traceIn.node, traceOut.node, defaultColor, layout);
coerceHoverLabel('node');

var colors = layout.colorway;

Expand All @@ -43,7 +50,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('link.line.color');
coerce('link.line.width');
coerce('link.hoverinfo');
handleFxDefaults(traceIn.link, traceOut.link, defaultColor, layout);
coerceHoverLabel('link');

coerce('link.color', traceOut.link.value.map(function() {
return tinycolor(layout.paper_bgcolor).getLuminance() < 0.333 ?
Expand Down

0 comments on commit fe7ab49

Please sign in to comment.