-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pie): add support for onClick event
- Loading branch information
Raphaël Benitte
authored and
Raphaël Benitte
committed
May 18, 2018
1 parent
129572e
commit b171044
Showing
7 changed files
with
157 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[*.js] | ||
indent_style = space | ||
indent_size = 4 | ||
max_line_length = 100 |
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,89 @@ | ||
/* | ||
* This file is part of the nivo project. | ||
* | ||
* Copyright 2016-present, Raphaël Benitte. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import compose from 'recompose/compose' | ||
import withPropsOnChange from 'recompose/withPropsOnChange' | ||
import pure from 'recompose/pure' | ||
import { BasicTooltip } from '@nivo/core' | ||
|
||
const PieSlice = ({ | ||
data, | ||
|
||
path, | ||
color, | ||
fill, | ||
borderWidth, | ||
borderColor, | ||
|
||
showTooltip, | ||
hideTooltip, | ||
onClick, | ||
tooltipFormat, | ||
|
||
theme, | ||
}) => { | ||
const handleTooltip = e => | ||
showTooltip( | ||
<BasicTooltip | ||
id={data.label} | ||
value={data.value} | ||
enableChip={true} | ||
color={color} | ||
theme={theme} | ||
format={tooltipFormat} | ||
/>, | ||
e | ||
) | ||
|
||
return ( | ||
<path | ||
key={data.id} | ||
d={path} | ||
fill={fill} | ||
strokeWidth={borderWidth} | ||
stroke={borderColor} | ||
onMouseEnter={handleTooltip} | ||
onMouseMove={handleTooltip} | ||
onMouseLeave={hideTooltip} | ||
onClick={onClick} | ||
/> | ||
) | ||
} | ||
|
||
PieSlice.propTypes = { | ||
data: PropTypes.shape({ | ||
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, | ||
value: PropTypes.number.isRequired, | ||
}).isRequired, | ||
|
||
path: PropTypes.string.isRequired, | ||
color: PropTypes.string.isRequired, | ||
fill: PropTypes.string.isRequired, | ||
borderWidth: PropTypes.number.isRequired, | ||
borderColor: PropTypes.string.isRequired, | ||
|
||
tooltipFormat: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), | ||
showTooltip: PropTypes.func.isRequired, | ||
hideTooltip: PropTypes.func.isRequired, | ||
onClick: PropTypes.func, | ||
|
||
theme: PropTypes.shape({ | ||
tooltip: PropTypes.shape({}).isRequired, | ||
}).isRequired, | ||
} | ||
|
||
const enhance = compose( | ||
withPropsOnChange(['data', 'onClick'], ({ data, onClick }) => ({ | ||
onClick: event => onClick(data, event), | ||
})), | ||
pure | ||
) | ||
|
||
export default enhance(PieSlice) |
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