import {View, Text, TextStyle} from 'react-native'; import {PieChartMain} from './main'; import {PieChartPropsType, pieColors, usePieChart} from 'gifted-charts-core'; import {isWebApp} from '../utils'; import {useState} from 'react'; import {RotatablePie} from '../Components/Rotatable'; export const PieChart = (props: PieChartPropsType) => { if (!props.data) return null; const { radius, extraRadius, selectedIndex, setSelectedIndex, startAngle, total, donut, isThreeD, semiCircle, inwardExtraLengthForFocused, canvasWidth, canvasHeight, innerRadius, innerCircleColor, innerCircleBorderWidth, innerCircleBorderColor, shiftInnerCenterX, shiftInnerCenterY, tiltAngle, isDataShifted, paddingHorizontal, paddingVertical, data, showTooltip, tooltipHorizontalShift, tooltipVerticalShift, tooltipComponent, getTooltipText, tooltipBackgroundColor, tooltipBorderRadius, tooltipWidth, tooltipTextNoOfLines, textColor, textSize, font, fontWeight, fontStyle, tooltipSelectedIndex, setTooltipSelectedIndex, rotatable, } = usePieChart(props); const [touchX, setTouchX] = useState(0); const [touchY, setTouchY] = useState(0); const renderInnerCircle = ( innerRadius: number, innerCircleBorderWidth: number, ) => { if (props.centerLabelComponent || (donut && !isDataShifted)) { return ( {props.centerLabelComponent?.(selectedIndex) ?? null} ); } return null; }; const renderTooltip = () => { return ( (radius + extraRadius) * 1.5 ? props.tooltipHorizontalShift ? touchX - tooltipHorizontalShift : touchX - (tooltipWidth ?? getTooltipText(tooltipSelectedIndex).length * 10) : touchX - tooltipHorizontalShift, top: touchY < 30 ? props.tooltipVerticalShift ? touchY - tooltipVerticalShift : touchY : touchY - tooltipVerticalShift, }}> {data[tooltipSelectedIndex].tooltipComponent ? ( data[tooltipSelectedIndex].tooltipComponent?.() ) : tooltipComponent ? ( tooltipComponent(tooltipSelectedIndex) ) : ( {getTooltipText(tooltipSelectedIndex)} )} ); }; const PieChartBody = () => { return ( {renderInnerCircle(innerRadius, innerCircleBorderWidth)} {props.data.length > 1 && props.data[selectedIndex] && // don't forget to add this one so there are no errors when the data is empty / updating (props.focusOnPress || props.sectionAutoFocus) && selectedIndex !== -1 && ( )} {renderInnerCircle( innerRadius - inwardExtraLengthForFocused, inwardExtraLengthForFocused ? 0 : innerCircleBorderWidth, )} {showTooltip && tooltipSelectedIndex !== -1 ? renderTooltip() : null} ); }; if (rotatable && !semiCircle) { return ( ]} initialAngle={startAngle} size={radius * 2} /> ); } return ; };