-
-
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(bar): use @nivo/axes instead of @nivo/core for SVG axes
- Loading branch information
Raphaël Benitte
committed
Sep 8, 2018
1 parent
203f719
commit 3b22c6f
Showing
14 changed files
with
3,832 additions
and
3,714 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,82 @@ | ||
/* | ||
* 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, { Fragment, PureComponent } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { motionPropTypes, axisThemePropType } from '@nivo/core' | ||
import Axis from './Axis' | ||
import { axisPropType } from '../props' | ||
|
||
const positions = ['top', 'right', 'bottom', 'left'] | ||
|
||
export default class Axes extends PureComponent { | ||
static propTypes = { | ||
xScale: PropTypes.func.isRequired, | ||
yScale: PropTypes.func.isRequired, | ||
width: PropTypes.number.isRequired, | ||
height: PropTypes.number.isRequired, | ||
top: axisPropType, | ||
right: axisPropType, | ||
bottom: axisPropType, | ||
left: axisPropType, | ||
theme: PropTypes.shape({ | ||
axis: axisThemePropType.isRequired, | ||
}).isRequired, | ||
...motionPropTypes, | ||
} | ||
|
||
render() { | ||
const { | ||
xScale, | ||
yScale, | ||
width, | ||
height, | ||
top, | ||
right, | ||
bottom, | ||
left, | ||
theme, | ||
animate, | ||
motionStiffness, | ||
motionDamping, | ||
} = this.props | ||
|
||
const axes = { top, right, bottom, left } | ||
|
||
return ( | ||
<Fragment> | ||
{positions.map(position => { | ||
const axis = axes[position] | ||
|
||
if (!axis) return null | ||
|
||
const isXAxis = position === 'top' || position === 'bottom' | ||
const ticksPosition = | ||
position === 'top' || position === 'left' ? 'before' : 'after' | ||
|
||
return ( | ||
<Axis | ||
key={position} | ||
{...axis} | ||
axis={isXAxis ? 'x' : 'y'} | ||
x={position === 'right' ? width : 0} | ||
y={position === 'bottom' ? height : 0} | ||
scale={isXAxis ? xScale : yScale} | ||
length={isXAxis ? width : height} | ||
ticksPosition={ticksPosition} | ||
theme={theme} | ||
animate={animate} | ||
motionDamping={motionDamping} | ||
motionStiffness={motionStiffness} | ||
/> | ||
) | ||
})} | ||
</Fragment> | ||
) | ||
} | ||
} |
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,29 @@ | ||
/* | ||
* 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 PropTypes from 'prop-types' | ||
|
||
export const axisPropTypes = { | ||
ticksPosition: PropTypes.oneOf(['before', 'after']), | ||
tickValues: PropTypes.oneOfType([ | ||
PropTypes.number, | ||
PropTypes.arrayOf( | ||
PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.instanceOf(Date)]) | ||
), | ||
]), | ||
tickSize: PropTypes.number, | ||
tickPadding: PropTypes.number, | ||
tickRotation: PropTypes.number, | ||
tickFormat: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), | ||
renderTick: PropTypes.func, | ||
legend: PropTypes.node, | ||
legendPosition: PropTypes.oneOf(['start', 'middle', 'end']), | ||
legendOffset: PropTypes.number, | ||
} | ||
|
||
export const axisPropType = PropTypes.shape(axisPropTypes) |
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
Oops, something went wrong.