-
-
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(axes): init migration to typescript
Close #1217
- Loading branch information
Showing
23 changed files
with
503 additions
and
473 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 { Axis } from './Axis' | ||
import { AllScales, AxisProp } from '../types' | ||
|
||
const positions = ['top', 'right', 'bottom', 'left'] as const | ||
|
||
export const Axes = <X extends number | string | Date, Y extends number | string | Date>({ | ||
xScale, | ||
yScale, | ||
width, | ||
height, | ||
top, | ||
right, | ||
bottom, | ||
left, | ||
}: { | ||
xScale: AllScales | ||
yScale: AllScales | ||
width: number | ||
height: number | ||
top?: AxisProp<X> | ||
right?: AxisProp<Y> | ||
bottom?: AxisProp<X> | ||
left?: AxisProp<Y> | ||
}) => { | ||
const axes = { top, right, bottom, left } | ||
|
||
return ( | ||
<> | ||
{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} | ||
/> | ||
) | ||
})} | ||
</> | ||
) | ||
} |
Oops, something went wrong.