-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Break up legend module #329
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
Changes from 7 commits
a40fc83
b3af445
67eda75
09354bf
1b69395
0b6dfcf
aa13bfb
dcea0dd
a11e698
cdd7240
7b393d4
a7829cf
59b0c52
0007807
335bb40
857878b
dcd0cb5
8440ef1
757ffdf
196d7dc
860e647
dbaf340
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 isTopAnchor(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) | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* 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', | ||
trace; | ||
|
||
for(var i = 0; i < fullData.length; i++) { | ||
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']); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional or should the function name match the export name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo time. Thanks