-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): GridRadial, GridAngle & GridPolar
- Loading branch information
1 parent
3032ded
commit 9fea2b1
Showing
13 changed files
with
570 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import Line, { LineProps } from '@visx/shape/lib/shapes/Line'; | ||
import { Group } from '@visx/group'; | ||
import { ScaleInput, getTicks } from '@visx/scale'; | ||
import { Point } from '@visx/point'; | ||
|
||
import { CommonGridProps, GridScale } from '../types'; | ||
import polarToCartesian from '../utils/polarToCartesian'; | ||
|
||
export type GridAngleProps<Scale extends GridScale> = CommonGridProps & { | ||
/** `@visx/scale` or `d3-scale` object used to convert value to position. */ | ||
scale: Scale; | ||
/** | ||
* Exact values used to generate grid lines using `scale`. | ||
* Overrides `numTicks` if specified. | ||
*/ | ||
tickValues?: ScaleInput<Scale>[]; | ||
/** | ||
* Radius which determines the start position of polar lines | ||
*/ | ||
innerRadius?: number; | ||
/** | ||
* Radius which determines the end position of polar lines | ||
*/ | ||
outerRadius?: number; | ||
/** | ||
* The class name applied to all polar lines. | ||
*/ | ||
lineClassName?: string; | ||
}; | ||
|
||
export type AllGridAngleProps<Scale extends GridScale> = GridAngleProps<Scale> & | ||
Omit< | ||
LineProps & Omit<React.SVGProps<SVGLineElement>, keyof LineProps>, | ||
keyof GridAngleProps<Scale> | ||
>; | ||
|
||
export default function GridAngle<Scale extends GridScale>({ | ||
className, | ||
innerRadius = 0, | ||
left = 0, | ||
lineClassName, | ||
lineStyle, | ||
numTicks = 10, | ||
outerRadius = 0, | ||
scale, | ||
stroke = '#eaf0f6', | ||
strokeDasharray, | ||
strokeWidth = 1, | ||
tickValues, | ||
top = 0, | ||
...restProps | ||
}: AllGridAngleProps<Scale>) { | ||
const ticks = tickValues ?? getTicks(scale, numTicks); | ||
return ( | ||
<Group className={cx('visx-grid-angle', className)} top={top} left={left}> | ||
{ticks.map((tick, i) => { | ||
const angle = (scale(tick) as number) - Math.PI / 2; | ||
const fromPoint = new Point(polarToCartesian({ angle, radius: innerRadius })); | ||
const toPoint = new Point(polarToCartesian({ angle, radius: outerRadius })); | ||
return ( | ||
<Line | ||
key={`polar-grid-${tick}-${i}`} | ||
className={lineClassName} | ||
from={fromPoint} | ||
to={toPoint} | ||
stroke={stroke} | ||
strokeWidth={strokeWidth} | ||
strokeDasharray={strokeDasharray} | ||
style={lineStyle} | ||
{...restProps} | ||
/> | ||
); | ||
})} | ||
</Group> | ||
); | ||
} |
Oops, something went wrong.