import React from 'react'; import sum from 'lodash/sum'; /* !- Constants */ const DEFAULT_COLORS = ['#8fd8b7', '#69b8f4', '#becff6', '#c899f4', '#6b8cef', '#fde35a', '#b7bec7']; const PI = 31.42; const RADIUS =5; /* !- Types */ export interface IData { id?: string, percent: number, color?: string, // title?: string, // @todo } export interface PropTypes { data: IData[], className?: string, strokeColor?: string, strokeWidth?: number, } /** * Pie Chart */ const Pie: React.FC = ({ data = [], className = '', strokeColor = 'transparent', strokeWidth = 0, }) => { const pies = data.map((pie, i) => ({...pie, cumulatePercent: sum(data.slice(0, i + 1).map(({ percent }) => percent )) })); return ( { pies.reverse().map(({ id, percent, cumulatePercent, color }, i) => ( )) } ); } export default Pie;