Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions src/components/legend/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ module.exports = {
font: extendFlat({}, fontAttrs, {
description: 'Sets the font used to text the legend items.'
}),
orientation: {
valType: 'enumerated',
values: ['v', 'h'],
dflt: 'v',
role: 'info',
description: 'Sets the orientation of the legend.'
},
traceorder: {
valType: 'flaglist',
flags: ['reversed', 'grouped'],
Expand Down
31 changes: 26 additions & 5 deletions src/components/legend/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
containerOut = layoutOut.legend = {};

var visibleTraces = 0,
defaultOrder = 'normal';
defaultOrder = 'normal',
defaultX,
defaultY,
defaultXAnchor,
defaultYAnchor;

for(var i = 0; i < fullData.length; i++) {
var trace = fullData[i];
Expand Down Expand Up @@ -58,12 +62,29 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
coerce('borderwidth');
Lib.coerceFont(coerce, 'font', layoutOut.font);

coerce('orientation');
if(containerOut.orientation === 'h') {
var xaxis = layoutIn.xaxis;
if(xaxis && xaxis.rangeslider && xaxis.rangeslider.visible) {
defaultX = 0;
defaultXAnchor = 'left';
defaultY = 1.1;
defaultYAnchor = 'bottom';
}
else {
defaultX = 0;
defaultXAnchor = 'left';
defaultY = -0.1;
defaultYAnchor = 'top';
}
}

coerce('traceorder', defaultOrder);
if(helpers.isGrouped(layoutOut.legend)) coerce('tracegroupgap');

coerce('x');
coerce('xanchor');
coerce('y');
coerce('yanchor');
coerce('x', defaultX);
coerce('xanchor', defaultXAnchor);
coerce('y', defaultY);
coerce('yanchor', defaultYAnchor);
Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);
};
Loading