Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions build/plotcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var rules = {
"X a": "text-decoration:none;",
"X a:hover": "text-decoration:none;",
"X .crisp": "shape-rendering:crispEdges;",
"X .user-select-none": "-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;",
"X svg": "overflow:hidden;",
"X svg a": "fill:#447adb;",
"X svg a:hover": "fill:#3c6dc5;",
Expand Down
47 changes: 47 additions & 0 deletions src/components/legend/anchor_utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright 2012-2016, 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';


/**
* Determine the position anchor property of x/y xanchor/yanchor components.
*
* - values < 1/3 align the low side at that fraction,
* - values [1/3, 2/3] align the center at that fraction,
* - values > 2/3 align the right at that fraction.
*/

exports.isRightAnchor = function isRightAnchor(opts) {
return (
opts.xanchor === 'right' ||
(opts.xanchor === 'auto' && opts.x >= 2 / 3)
);
};

exports.isCenterAnchor = function isCenterAnchor(opts) {
return (
opts.xanchor === 'center' ||
(opts.xanchor === 'auto' && opts.x > 1 / 3 && opts.x < 2 / 3)
);
};

exports.isBottomAnchor = function isBottomAnchor(opts) {
return (
opts.yanchor === 'bottom' ||
(opts.yanchor === 'auto' && opts.y <= 1 / 3)
);
};

exports.isMiddleAnchor = function isMiddleAnchor(opts) {
return (
opts.yanchor === 'middle' ||
(opts.yanchor === 'auto' && opts.y > 1 / 3 && opts.y < 2 / 3)
);
};
69 changes: 69 additions & 0 deletions src/components/legend/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright 2012-2016, 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';

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

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


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

var visibleTraces = 0,
defaultOrder = 'normal';

for(var i = 0; i < fullData.length; i++) {
var trace = fullData[i];

if(helpers.legendGetsTrace(trace)) {
visibleTraces++;
// always show the legend by default if there's a pie
if(Plots.traceIs(trace, 'pie')) visibleTraces++;
}

if((Plots.traceIs(trace, 'bar') && layoutOut.barmode==='stack') ||
['tonextx','tonexty'].indexOf(trace.fill)!==-1) {
defaultOrder = helpers.isGrouped({traceorder: defaultOrder}) ?
'grouped+reversed' : 'reversed';
}

if(trace.legendgroup !== undefined && trace.legendgroup !== '') {
defaultOrder = helpers.isReversed({traceorder: defaultOrder}) ?
'reversed+grouped' : 'grouped';
}
}

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

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

if(showLegend === false) return;

coerce('bgcolor', layoutOut.paper_bgcolor);
coerce('bordercolor');
coerce('borderwidth');
Lib.coerceFont(coerce, 'font', layoutOut.font);

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

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