-
-
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a40fc83
factor out legend helper into separate file + add tests
etpinard b3af445
move auto-anchor logic to own module + add tests
etpinard 67eda75
move legend defaults to own module
etpinard 09354bf
move legend style step to own module:
etpinard 1b69395
move legend-data logic to own module
etpinard 0b6dfcf
move legend draw step to own module:
etpinard aa13bfb
lint
etpinard dcea0dd
fix typo (function name)
etpinard a11e698
lint (mostly infix spacing)
etpinard cdd7240
make legend element a <g> instead of nestead <svg>
etpinard 7b393d4
cropped legend element using clip-path on legend <g>
etpinard a7829cf
rm useless .exit().remove() :
etpinard 59b0c52
robustify top-paper <defs>:
etpinard 0007807
merge top-paper <defs> into main svg on to-svg step
etpinard 335bb40
add in-house getBBox test asset:
etpinard 857878b
add legend and clip path count test,
etpinard dcd0cb5
update baseline:
etpinard 8440ef1
add fallback for FF in getBBox test asset:
etpinard 757ffdf
lint (define variable in block)
etpinard 196d7dc
change top-paper <defs> id to 'topdefs' + uid:
etpinard 860e647
make copy of top-paper childNodes array-like:
etpinard dbaf340
make user-select-none CSS class:
etpinard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we prefer keeping variable declarations at the top even if they're "scoped" to a block like here?
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.
I prefer having:
var trace
inside the block.The diff ⏫ is just showing old code being moved around. I'll change this right up.