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

Function ArcLabelsLayer

packages/arcs/src/arc_labels/ArcLabelsLayer.tsx:27–82  ·  view source on GitHub ↗
({
    center,
    data,
    transitionMode,
    label: labelAccessor,
    radiusOffset,
    skipAngle,
    skipRadius,
    textColor,
    component = ArcLabel,
}: ArcLabelsLayerProps<Datum>)

Source from the content-addressed store, hash-verified

25}
26
27export const ArcLabelsLayer = <Datum extends DatumWithArcAndColor>({
28 center,
29 data,
30 transitionMode,
31 label: labelAccessor,
32 radiusOffset,
33 skipAngle,
34 skipRadius,
35 textColor,
36 component = ArcLabel,
37}: ArcLabelsLayerProps<Datum>) => {
38 const getLabel = usePropertyAccessor<Datum, string>(labelAccessor)
39 const theme = useTheme()
40 const getTextColor = useInheritedColor<Datum>(textColor, theme)
41
42 const filteredData = useMemo(
43 () =>
44 data.filter(datum => {
45 const angle = Math.abs(radiansToDegrees(datum.arc.endAngle - datum.arc.startAngle))
46 const radius = Math.abs(datum.arc.outerRadius - datum.arc.innerRadius)
47
48 return angle >= skipAngle && radius >= skipRadius
49 }),
50 [data, skipAngle, skipRadius]
51 )
52
53 const { transition, interpolate } = useArcCentersTransition<Datum>(
54 filteredData,
55 radiusOffset,
56 transitionMode
57 )
58
59 const Label: ArcLabelComponent<Datum> = component
60
61 return (
62 <g transform={`translate(${center[0]},${center[1]})`}>
63 {transition((transitionProps, datum) => {
64 return createElement(Label, {
65 key: datum.id,
66 datum,
67 label: getLabel(datum),
68 style: {
69 progress: transitionProps.progress,
70 transform: interpolate(
71 transitionProps.startAngle,
72 transitionProps.endAngle,
73 transitionProps.innerRadius,
74 transitionProps.outerRadius
75 ),
76 textColor: getTextColor(datum),
77 },
78 })
79 })}
80 </g>
81 )
82}

Callers

nothing calls this directly

Calls 5

usePropertyAccessorFunction · 0.90
useThemeFunction · 0.90
useInheritedColorFunction · 0.90
radiansToDegreesFunction · 0.90
useArcCentersTransitionFunction · 0.90

Tested by

no test coverage detected