-
-
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(bump): add ability to use custom point component
- Loading branch information
Showing
8 changed files
with
124 additions
and
29 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,37 @@ | ||
/* | ||
* 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' | ||
|
||
const pointStyle = { pointerEvents: 'none' } | ||
|
||
const Point = ({ x, y, size, color, borderColor, borderWidth }) => { | ||
return ( | ||
<circle | ||
cx={x} | ||
cy={y} | ||
r={size / 2} | ||
fill={color} | ||
strokeWidth={borderWidth} | ||
stroke={borderColor} | ||
style={pointStyle} | ||
/> | ||
) | ||
} | ||
|
||
Point.propTypes = { | ||
x: PropTypes.number.isRequired, | ||
y: PropTypes.number.isRequired, | ||
size: PropTypes.number.isRequired, | ||
color: PropTypes.string.isRequired, | ||
borderColor: PropTypes.string.isRequired, | ||
borderWidth: PropTypes.number.isRequired, | ||
} | ||
|
||
export default memo(Point) |
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,5 @@ | ||
globals: | ||
module: true | ||
|
||
rules: | ||
react/prop-types: 0 |
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,45 @@ | ||
import React from 'react' | ||
import { storiesOf } from '@storybook/react' | ||
import range from 'lodash/range' | ||
import shuffle from 'lodash/shuffle' | ||
import { Bump } from '../src' | ||
|
||
const generateData = () => { | ||
const years = range(2000, 2005) | ||
const ranks = range(1, 7) | ||
|
||
const series = ranks.map(rank => { | ||
return { | ||
id: `Serie ${rank}`, | ||
data: [], | ||
} | ||
}) | ||
|
||
years.forEach(year => { | ||
shuffle(ranks).forEach((rank, i) => { | ||
series[i].data.push({ | ||
x: year, | ||
y: rank, | ||
}) | ||
}) | ||
}) | ||
|
||
return series | ||
} | ||
|
||
const commonProps = { | ||
width: 900, | ||
height: 360, | ||
margin: { top: 40, right: 100, bottom: 40, left: 100 }, | ||
titleOffsetX: -80, | ||
data: generateData(), | ||
spacing: 80, | ||
} | ||
|
||
const stories = storiesOf('Bump', module) | ||
|
||
stories.add('default', () => <Bump {...commonProps} />) | ||
|
||
stories.add('Custom points', () => <Bump {...commonProps} />) | ||
|
||
stories.add('Missing data', () => <Bump {...commonProps} />) |
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