-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Legend for deck.gl scatterplot (#4572)
* Initial work * Working version * Specify legend position * Max height with scroll * Fix lint * Better compatibility with nvd3 * Fix object.keys polyfill version * Fix lint
- Loading branch information
1 parent
86a03d1
commit 7089344
Showing
8 changed files
with
188 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,22 @@ | ||
div.legend { | ||
font-size: 90%; | ||
position: absolute; | ||
background: #fff; | ||
box-shadow: 0 0 4px rgba(0, 0, 0, 0.15); | ||
margin: 24px; | ||
padding: 12px 24px; | ||
outline: none; | ||
overflow-y: scroll; | ||
max-height: 200px; | ||
} | ||
|
||
ul.categories { | ||
list-style: none; | ||
padding-left: 0; | ||
margin: 0; | ||
} | ||
|
||
ul.categories li a { | ||
color: rgb(51, 51, 51); | ||
text-decoration: none; | ||
} |
This file contains 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,58 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import './Legend.css'; | ||
|
||
const propTypes = { | ||
categories: PropTypes.object, | ||
toggleCategory: PropTypes.func, | ||
showSingleCategory: PropTypes.func, | ||
position: PropTypes.oneOf(['tl', 'tr', 'bl', 'br']), | ||
}; | ||
|
||
const defaultProps = { | ||
categories: {}, | ||
toggleCategory: () => {}, | ||
showSingleCategory: () => {}, | ||
position: 'tr', | ||
}; | ||
|
||
export default class Legend extends React.PureComponent { | ||
render() { | ||
if (Object.keys(this.props.categories).length === 0) { | ||
return null; | ||
} | ||
|
||
const categories = Object.entries(this.props.categories).map(([k, v]) => { | ||
const style = { color: 'rgba(' + v.color.join(', ') + ')' }; | ||
const icon = v.enabled ? '\u25CF' : '\u25CB'; | ||
return ( | ||
<li> | ||
<a | ||
href="#" | ||
onClick={() => this.props.toggleCategory(k)} | ||
onDoubleClick={() => this.props.showSingleCategory(k)} | ||
> | ||
<span style={style}>{icon}</span> {k} | ||
</a> | ||
</li> | ||
); | ||
}); | ||
|
||
const vertical = this.props.position.charAt(0) === 't' ? 'top' : 'bottom'; | ||
const horizontal = this.props.position.charAt(1) === 'r' ? 'right' : 'left'; | ||
const style = { | ||
[vertical]: '0px', | ||
[horizontal]: '10px', | ||
}; | ||
|
||
return ( | ||
<div className={'legend'} style={style}> | ||
<ul className={'categories'}>{categories}</ul> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Legend.propTypes = propTypes; | ||
Legend.defaultProps = defaultProps; |
This file contains 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
This file contains 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
This file contains 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