-
-
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(stream): add stack tooltip on stream chart
- Loading branch information
Raphaël Benitte
committed
Aug 12, 2017
1 parent
16b7f4d
commit 2e67e44
Showing
7 changed files
with
186 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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 pure from 'recompose/pure' | ||
import StreamSlicesItem from './StreamSlicesItem' | ||
|
||
const StreamSlices = ({ slices, height, showTooltip, hideTooltip }) => | ||
<g> | ||
{slices.map(slice => | ||
<StreamSlicesItem | ||
key={slice.index} | ||
slice={slice} | ||
height={height} | ||
showTooltip={showTooltip} | ||
hideTooltip={hideTooltip} | ||
/> | ||
)} | ||
</g> | ||
|
||
StreamSlices.propTypes = { | ||
slices: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
index: PropTypes.number.isRequired, | ||
x: PropTypes.number.isRequired, | ||
stack: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired, | ||
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired, | ||
color: PropTypes.string.isRequired, | ||
}) | ||
).isRequired, | ||
}) | ||
).isRequired, | ||
height: PropTypes.number.isRequired, | ||
showTooltip: PropTypes.func.isRequired, | ||
hideTooltip: PropTypes.func.isRequired, | ||
} | ||
|
||
export default pure(StreamSlices) |
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,73 @@ | ||
/* | ||
* 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 pure from 'recompose/pure' | ||
import withState from 'recompose/withState' | ||
import withHandlers from 'recompose/withHandlers' | ||
import withPropsOnChange from 'recompose/withPropsOnChange' | ||
import TableTooltip from '../../tooltip/TableTooltip' | ||
|
||
const Chip = ({ color }) => | ||
<span style={{ display: 'block', width: '12px', height: '12px', background: color }} /> | ||
|
||
const StreamSlicesItem = ({ slice, height, showTooltip, hideTooltip, isHover }) => | ||
<g transform={`translate(${slice.x}, 0)`}> | ||
{isHover && | ||
<line | ||
x1={0} | ||
x2={0} | ||
y1={0} | ||
y2={height} | ||
stroke="#000" | ||
strokeOpacity={0.35} | ||
strokeWidth={1} | ||
/>} | ||
<rect | ||
x={-20} | ||
width={40} | ||
height={height} | ||
fill="#000" | ||
fillOpacity={0} | ||
onMouseEnter={showTooltip} | ||
onMouseMove={showTooltip} | ||
onMouseLeave={hideTooltip} | ||
/> | ||
</g> | ||
|
||
StreamSlicesItem.propTypes = { | ||
slice: PropTypes.object.isRequired, | ||
height: PropTypes.number.isRequired, | ||
showTooltip: PropTypes.func.isRequired, | ||
hideTooltip: PropTypes.func.isRequired, | ||
isHover: PropTypes.bool.isRequired, | ||
} | ||
|
||
const enhance = compose( | ||
withState('isHover', 'setIsHover', false), | ||
withPropsOnChange(['slice'], ({ slice }) => ({ | ||
tooltip: ( | ||
<TableTooltip rows={slice.stack.map(p => [<Chip color={p.color} />, p.id, p.value])} /> | ||
), | ||
})), | ||
withHandlers({ | ||
showTooltip: ({ showTooltip, setIsHover, tooltip }) => e => { | ||
setIsHover(true) | ||
showTooltip(tooltip, e) | ||
}, | ||
hideTooltip: ({ hideTooltip, setIsHover }) => () => { | ||
setIsHover(false) | ||
hideTooltip() | ||
}, | ||
}), | ||
pure | ||
) | ||
|
||
export default enhance(StreamSlicesItem) |
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,9 @@ | ||
/* | ||
* 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. | ||
*/ | ||
export * from './directions' |
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