-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #779 from hshoff/chris--animated-axis
new(vx-react-spring): add package + AnimatedAxis
- Loading branch information
Showing
27 changed files
with
527 additions
and
169 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
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
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,53 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { Line } from '@vx/shape'; | ||
import { Group } from '@vx/group'; | ||
import { Text } from '@vx/text'; | ||
|
||
import Orientation from '../constants/orientation'; | ||
import { TicksRendererProps, AxisScale } from '../types'; | ||
|
||
export default function Ticks<Scale extends AxisScale>({ | ||
hideTicks, | ||
horizontal, | ||
orientation, | ||
tickClassName, | ||
tickComponent, | ||
tickLabelProps: allTickLabelProps, | ||
tickStroke = '#222', | ||
tickTransform, | ||
ticks, | ||
}: TicksRendererProps<Scale>) { | ||
return ticks.map(({ value, index, from, to, formattedValue }) => { | ||
const tickLabelProps = allTickLabelProps[index] ?? {}; | ||
const tickLabelFontSize = Math.max( | ||
10, | ||
(typeof tickLabelProps.fontSize === 'number' && tickLabelProps.fontSize) || 0, | ||
); | ||
|
||
const tickYCoord = | ||
to.y + (horizontal && orientation !== Orientation.top ? tickLabelFontSize : 0); | ||
|
||
return ( | ||
<Group | ||
key={`vx-tick-${value}-${index}`} | ||
className={cx('vx-axis-tick', tickClassName)} | ||
transform={tickTransform} | ||
> | ||
{!hideTicks && <Line from={from} to={to} stroke={tickStroke} strokeLinecap="square" />} | ||
{tickComponent ? ( | ||
tickComponent({ | ||
...tickLabelProps, | ||
x: to.x, | ||
y: tickYCoord, | ||
formattedValue, | ||
}) | ||
) : ( | ||
<Text x={to.x} y={tickYCoord} {...tickLabelProps}> | ||
{formattedValue} | ||
</Text> | ||
)} | ||
</Group> | ||
); | ||
}); | ||
} |
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.