import React from 'react'; import PropTypes from 'prop-types'; import { createMuiTheme } from '@material-ui/core/styles'; import ThemePallete from 'ba-api/themePalette'; import { PieChart, Pie, Sector } from 'recharts'; import { data6 } from './sampleData'; const theme = createMuiTheme(ThemePallete.greenTheme); const color = ({ primary: theme.palette.primary.main, secondary: theme.palette.secondary.main, }); const renderActiveShape = props => { const RADIAN = Math.PI / 180; const { cx, cy, midAngle, innerRadius, outerRadius, startAngle, endAngle, fill, payload, percent, value } = props; const sin = Math.sin(-RADIAN * midAngle); const cos = Math.cos(-RADIAN * midAngle); const sx = cx + ((outerRadius + 10) * cos); const sy = cy + ((outerRadius + 10) * sin); const mx = cx + ((outerRadius + 30) * cos); const my = cy + ((outerRadius + 30) * sin); const ex = mx + ((cos >= 0 ? 1 : -1) * 22); const ey = my; const textAnchor = cos >= 0 ? 'start' : 'end'; return ( {payload.name} = 0 ? 1 : -1) * 12)} y={ey} textAnchor={textAnchor} fill="#333">{`PV ${value}`} = 0 ? 1 : -1) * 12)} y={ey} dy={18} textAnchor={textAnchor} fill="#999"> {`(Rate ${(percent * 100).toFixed(2)}%)`} ); }; renderActiveShape.propTypes = { cx: PropTypes.number, cy: PropTypes.number, midAngle: PropTypes.number, innerRadius: PropTypes.number, outerRadius: PropTypes.number, startAngle: PropTypes.number, endAngle: PropTypes.number, fill: PropTypes.string, payload: PropTypes.string, percent: PropTypes.number, value: PropTypes.number, }; renderActiveShape.defaultProps = { cx: 0, cy: 0, midAngle: 0, innerRadius: 0, outerRadius: 0, startAngle: 0, endAngle: 0, fill: '#eee', payload: '', percent: 0, value: 0, }; class PieCustomShape extends React.Component { state = { activeIndex: 0 }; onPieEnter(evt) { const index = data6.findIndex(p => p.name === evt.name); this.setState({ activeIndex: index, }); } render() { return ( this.onPieEnter(event)} /> ); } } export default PieCustomShape;