react-native-chart-kit
Version:
Beautiful React Native charts for dashboards, reports, and data-rich mobile apps.
55 lines (54 loc) • 2.53 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { getAnimatedPieSliceOpacity, getAnimatedPieSlicePath } from "./selectionAnimation";
export const PieChartSlices = ({ activeSlice, arcs, centerX, centerY, innerRadius, radius, renderer, resolvedTheme, selectedIndex, selectionAnimationState, sliceSeparator, testID }) => {
const Group = renderer.Group;
const Path = renderer.Path;
const renderedArcs = selectedIndex === undefined
? arcs
: [
...arcs.filter((arc) => arc.index !== selectedIndex),
...arcs.filter((arc) => arc.index === selectedIndex)
];
return (_jsx(_Fragment, { children: renderedArcs.map((arc) => {
if (!arc.defined) {
return null;
}
const isSelected = selectedIndex === arc.index;
const opacity = getAnimatedPieSliceOpacity({
activeOpacity: activeSlice.activeOpacity,
inactiveOpacity: activeSlice.inactiveOpacity,
index: arc.index,
state: selectionAnimationState
});
const path = getAnimatedPieSlicePath({
activeOffset: activeSlice.activeOffset,
activeScale: activeSlice.activeScale,
arc,
centerX,
centerY,
innerRadius,
radius,
state: selectionAnimationState
});
const separatorStrokeProps = sliceSeparator.visible
? {
stroke: sliceSeparator.color,
strokeLinejoin: "round",
strokeOpacity: sliceSeparator.opacity,
strokeWidth: sliceSeparator.width
}
: {};
const activeStrokeProps = isSelected && activeSlice.strokeWidth > 0
? {
stroke: activeSlice.strokeColor,
strokeLinejoin: "round",
strokeOpacity: 1,
strokeWidth: activeSlice.strokeWidth
}
: {};
const strokeProps = isSelected
? { ...separatorStrokeProps, ...activeStrokeProps }
: separatorStrokeProps;
return (_jsx(Group, { opacity: opacity, children: _jsx(Path, { d: path, fill: arc.color ?? resolvedTheme.text, testID: `${testID ?? "pie-chart"}-slice.${arc.index}`, ...strokeProps }) }, `pie-slice-${arc.index}`));
}) }));
};