MCPcopy
hub / github.com/plouc/nivo / useArcLinkLabels

Function useArcLinkLabels

packages/arcs/src/arc_link_labels/useArcLinkLabels.ts:16–77  ·  view source on GitHub ↗
({
    data,
    skipAngle,
    offset,
    diagonalLength,
    straightLength,
    textOffset = 0,
    label,
    linkColor,
    textColor,
}: {
    data: Datum[]
    skipAngle?: number
    offset?: number
    diagonalLength: number
    straightLength: number
    textOffset: number
    label: PropertyAccessor<Datum, string>
    linkColor: InheritedColorConfig<Datum>
    textColor: InheritedColorConfig<Datum>
})

Source from the content-addressed store, hash-verified

14 * about the parameters.
15 */
16export const useArcLinkLabels = <Datum extends DatumWithArcAndColor>({
17 data,
18 skipAngle,
19 offset,
20 diagonalLength,
21 straightLength,
22 textOffset = 0,
23 label,
24 linkColor,
25 textColor,
26}: {
27 data: Datum[]
28 skipAngle?: number
29 offset?: number
30 diagonalLength: number
31 straightLength: number
32 textOffset: number
33 label: PropertyAccessor<Datum, string>
34 linkColor: InheritedColorConfig<Datum>
35 textColor: InheritedColorConfig<Datum>
36}) => {
37 const getLabel = usePropertyAccessor<Datum, string>(label)
38
39 const theme = useTheme()
40 const getLinkColor = useInheritedColor<Datum>(linkColor, theme)
41 const getTextColor = useInheritedColor<Datum>(textColor, theme)
42
43 const computeExtraProps = useCallback(
44 (link: ArcLinkWithDatum<Datum>) => {
45 const position = {
46 x: link.points[2].x,
47 y: link.points[2].y,
48 }
49 let textAnchor: ArcLinkLabel<Datum>['textAnchor']
50 if (link.side === 'before') {
51 position.x -= textOffset
52 textAnchor = 'end'
53 } else {
54 position.x += textOffset
55 textAnchor = 'start'
56 }
57
58 return {
59 ...position,
60 label: getLabel(link.data),
61 linkColor: getLinkColor(link.data),
62 textAnchor,
63 textColor: getTextColor(link.data),
64 }
65 },
66 [getLabel, getLinkColor, getTextColor, textOffset]
67 )
68
69 return useArcLinks<Datum, Omit<ArcLinkLabel<Datum>, keyof ArcLinkWithDatum<Datum>>>({
70 data,
71 skipAngle,
72 offset,
73 diagonalLength,

Callers 1

InnerPieCanvasFunction · 0.90

Calls 4

usePropertyAccessorFunction · 0.90
useThemeFunction · 0.90
useInheritedColorFunction · 0.90
useArcLinksFunction · 0.90

Tested by

no test coverage detected