-
-
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(arcs): add the ability to pass custom arc label/arc link label c…
…omponents
- Loading branch information
Showing
12 changed files
with
229 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { CSSProperties } from 'react' | ||
import { SpringValue, Interpolation, animated } from 'react-spring' | ||
import { useTheme } from '@nivo/core' | ||
import { DatumWithArcAndColor } from '../types' | ||
|
||
const staticStyle: CSSProperties = { | ||
pointerEvents: 'none', | ||
} | ||
|
||
export interface ArcLabelProps<Datum extends DatumWithArcAndColor> { | ||
datum: Datum | ||
label: string | ||
style: { | ||
progress: SpringValue<number> | ||
transform: Interpolation<string> | ||
textColor: string | ||
} | ||
} | ||
|
||
export const ArcLabel = <Datum extends DatumWithArcAndColor>({ | ||
label, | ||
style, | ||
}: ArcLabelProps<Datum>) => { | ||
const theme = useTheme() | ||
|
||
return ( | ||
<animated.g transform={style.transform} opacity={style.progress} style={staticStyle}> | ||
<animated.text | ||
textAnchor="middle" | ||
dominantBaseline="central" | ||
style={{ | ||
...theme.labels.text, | ||
fill: style.textColor, | ||
}} | ||
> | ||
{label} | ||
</animated.text> | ||
</animated.g> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import { InheritedColorConfig } from '@nivo/colors' | ||
import { ArcLabelComponent } from './ArcLabelsLayer' | ||
import { DatumWithArcAndColor } from '../types' | ||
|
||
// @ts-ignore | ||
export interface ArcLabelsProps<RawDatum, Datum> { | ||
// string | LabelAccessorFunction<RawDatum> | ||
export interface ArcLabelsProps<Datum extends DatumWithArcAndColor> { | ||
// @todo fix label accessor | ||
// string | LabelAccessorFunction<Datum['data']> | ||
arcLabel: any | ||
arcLabelsRadiusOffset: number | ||
arcLabelsSkipAngle: number | ||
arcLabelsTextColor: InheritedColorConfig<Datum> | ||
component: ArcLabelComponent<Datum> | ||
} |
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,27 @@ | ||
import React from 'react' | ||
import { SpringValue, Interpolation, animated } from 'react-spring' | ||
import { DatumWithArcAndColor } from '../types' | ||
|
||
export interface ArcLinkLabelProps<Datum extends DatumWithArcAndColor> { | ||
datum: Datum | ||
style: { | ||
linkColor: SpringValue<string> | ||
thickness: number | ||
opacity: SpringValue<number> | ||
path: Interpolation<string> | ||
} | ||
} | ||
|
||
export const ArcLinkLabel = <Datum extends DatumWithArcAndColor>({ | ||
style, | ||
}: ArcLinkLabelProps<Datum>) => { | ||
return ( | ||
<animated.path | ||
fill="none" | ||
stroke={style.linkColor} | ||
strokeWidth={style.thickness} | ||
opacity={style.opacity} | ||
d={style.path} | ||
/> | ||
) | ||
} |
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.