-
-
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.
- Loading branch information
Raphaël Benitte
authored and
Raphaël Benitte
committed
May 16, 2019
1 parent
5501852
commit 9b69845
Showing
36 changed files
with
2,902 additions
and
646 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,60 @@ | ||
/* | ||
* 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, { memo, useCallback } from 'react' | ||
import { useTooltip } from '@nivo/tooltip' | ||
import AreaTooltip from './AreaTooltip' | ||
|
||
const Area = ({ | ||
serie, | ||
areaGenerator, | ||
blendMode, | ||
setCurrentSerie | ||
}) => { | ||
const { showTooltipFromEvent, hideTooltip } = useTooltip() | ||
const onMouseEnter = useCallback( | ||
event => { | ||
showTooltipFromEvent(<AreaTooltip serie={serie}/>, event) | ||
setCurrentSerie(serie.id) | ||
}, | ||
[serie, showTooltipFromEvent, setCurrentSerie] | ||
) | ||
const onMouseMove = useCallback( | ||
event => { | ||
showTooltipFromEvent(<AreaTooltip serie={serie}/>, event) | ||
}, | ||
[serie, showTooltipFromEvent] | ||
) | ||
const onMouseLeave = useCallback(() => { | ||
hideTooltip() | ||
setCurrentSerie(null) | ||
}, [hideTooltip, setCurrentSerie]) | ||
|
||
return ( | ||
<> | ||
<path | ||
d={areaGenerator(serie.areaPoints)} | ||
fill={serie.color} | ||
fillOpacity={serie.style.fillOpacity} | ||
stroke={serie.color} | ||
strokeWidth={serie.style.borderWidth} | ||
strokeOpacity={serie.style.strokeOpacity} | ||
style={{ mixBlendMode: blendMode }} | ||
onMouseEnter={onMouseEnter} | ||
onMouseMove={onMouseMove} | ||
onMouseLeave={onMouseLeave} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
Area.propTypes = { | ||
|
||
} | ||
|
||
export default memo(Area) |
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,179 @@ | ||
/* | ||
* 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, { memo, useState, Fragment } from 'react' | ||
import { withContainer, useDimensions, SvgWrapper } from '@nivo/core' | ||
import { Grid, Axes } from '@nivo/axes' | ||
import { AreaBumpPropTypes, AreaBumpDefaultProps } from './props' | ||
import { useAreaBump } from './hooks' | ||
import Area from './Area' | ||
import AreasLabels from './AreasLabels' | ||
|
||
const AreaBump = props => { | ||
const { | ||
data, | ||
align, | ||
|
||
width, | ||
height, | ||
margin: partialMargin, | ||
|
||
layers, | ||
|
||
interpolation, | ||
spacing, | ||
xPadding, | ||
|
||
colors, | ||
blendMode, | ||
fillOpacity, | ||
activeFillOpacity, | ||
inactiveFillOpacity, | ||
borderWidth, | ||
activeBorderWidth, | ||
inactiveBorderWidth, | ||
borderOpacity, | ||
activeBorderOpacity, | ||
inactiveBorderOpacity, | ||
|
||
startLabel, | ||
startLabelPadding, | ||
startLabelTextColor, | ||
endLabel, | ||
endLabelPadding, | ||
endLabelTextColor, | ||
|
||
enableGridX, | ||
axisTop, | ||
axisBottom, | ||
|
||
isInteractive, | ||
} = props | ||
|
||
const [currentSerie, setCurrentSerie] = useState(null) | ||
|
||
const { margin, innerWidth, innerHeight, outerWidth, outerHeight } = useDimensions( | ||
width, | ||
height, | ||
partialMargin | ||
) | ||
|
||
const { | ||
series, | ||
xScale, | ||
heightScale, | ||
areaGenerator, | ||
getColor, | ||
} = useAreaBump({ | ||
data, | ||
width: innerWidth, | ||
height: innerHeight, | ||
align, | ||
spacing, | ||
xPadding, | ||
interpolation, | ||
colors, | ||
fillOpacity, | ||
activeFillOpacity, | ||
inactiveFillOpacity, | ||
borderWidth, | ||
activeBorderWidth, | ||
inactiveBorderWidth, | ||
borderOpacity, | ||
activeBorderOpacity, | ||
inactiveBorderOpacity, | ||
isInteractive, | ||
current: currentSerie | ||
}) | ||
|
||
const layerById = { | ||
grid: enableGridX && ( | ||
<Grid | ||
key="grid" | ||
width={innerWidth} | ||
height={innerHeight} | ||
xScale={xScale} | ||
/> | ||
), | ||
axes: ( | ||
<Axes | ||
key="axes" | ||
xScale={xScale} | ||
width={innerWidth} | ||
height={innerHeight} | ||
top={axisTop} | ||
bottom={axisBottom} | ||
/> | ||
), | ||
labels: [], | ||
areas: ( | ||
<Fragment key="areas"> | ||
{series.map(serie => ( | ||
<Area | ||
key={serie.id} | ||
areaGenerator={areaGenerator} | ||
serie={serie} | ||
blendMode={blendMode} | ||
setCurrentSerie={setCurrentSerie} | ||
/> | ||
))} | ||
</Fragment> | ||
), | ||
} | ||
|
||
if (startLabel !== false) { | ||
layerById.labels.push( | ||
<AreasLabels | ||
key="start" | ||
series={series} | ||
position="start" | ||
padding={startLabelPadding} | ||
margin={margin} | ||
color={startLabelTextColor} | ||
setCurrentSerie={setCurrentSerie} | ||
/> | ||
) | ||
} | ||
if (endLabel !== false) { | ||
layerById.labels.push( | ||
<AreasLabels | ||
key="end" | ||
series={series} | ||
position="end" | ||
padding={endLabelPadding} | ||
margin={margin} | ||
color={endLabelTextColor} | ||
setCurrentSerie={setCurrentSerie} | ||
/> | ||
) | ||
} | ||
|
||
return ( | ||
<SvgWrapper width={outerWidth} height={outerHeight} margin={margin}> | ||
{layers.map((layer, i) => { | ||
if (typeof layer === 'function') { | ||
return ( | ||
<Fragment key={i}> | ||
{layer({ | ||
innerWidth, | ||
innerHeight, | ||
})} | ||
</Fragment> | ||
) | ||
} | ||
|
||
return layerById[layer] | ||
})} | ||
</SvgWrapper> | ||
) | ||
} | ||
|
||
AreaBump.propTypes = AreaBumpPropTypes | ||
AreaBump.defaultProps = AreaBumpDefaultProps | ||
|
||
export default memo(withContainer(AreaBump)) |
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,24 @@ | ||
/* | ||
* 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, { memo } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { BasicTooltip } from '@nivo/tooltip' | ||
|
||
const AreaTooltip = ({ serie }) => { | ||
return <BasicTooltip id={serie.id} enableChip={true} color={serie.color} /> | ||
} | ||
|
||
AreaTooltip.propTypes = { | ||
serie: PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
color: PropTypes.string.isRequired, | ||
}), | ||
} | ||
|
||
export default memo(AreaTooltip) |
Oops, something went wrong.