| 5 | const CIRCLE = Math.PI * 2; |
| 6 | |
| 7 | function makeArcPath(x, y, startAngleArg, endAngleArg, radius, direction) { |
| 8 | let startAngle = startAngleArg; |
| 9 | let endAngle = endAngleArg; |
| 10 | if (endAngle - startAngle >= CIRCLE) { |
| 11 | endAngle = CIRCLE + (endAngle % CIRCLE); |
| 12 | } else { |
| 13 | endAngle = endAngle % CIRCLE; |
| 14 | } |
| 15 | startAngle = startAngle % CIRCLE; |
| 16 | const angle = |
| 17 | startAngle > endAngle |
| 18 | ? CIRCLE - startAngle + endAngle |
| 19 | : endAngle - startAngle; |
| 20 | |
| 21 | if (angle >= CIRCLE) { |
| 22 | return `M${x + radius} ${y} |
| 23 | a${radius} ${radius} 0 0 1 0 ${radius * 2} |
| 24 | a${radius} ${radius} 0 0 1 0 ${radius * -2}`; |
| 25 | } |
| 26 | |
| 27 | const directionFactor = direction === 'counter-clockwise' ? -1 : 1; |
| 28 | endAngle *= directionFactor; |
| 29 | startAngle *= directionFactor; |
| 30 | const startSine = Math.sin(startAngle); |
| 31 | const startCosine = Math.cos(startAngle); |
| 32 | const endSine = Math.sin(endAngle); |
| 33 | const endCosine = Math.cos(endAngle); |
| 34 | |
| 35 | const arcFlag = angle > Math.PI ? 1 : 0; |
| 36 | const reverseFlag = direction === 'counter-clockwise' ? 0 : 1; |
| 37 | |
| 38 | return `M${x + radius * (1 + startSine)} ${y + radius - radius * startCosine} |
| 39 | A${radius} ${radius} 0 ${arcFlag} ${reverseFlag} ${x + |
| 40 | radius * (1 + endSine)} ${y + radius - radius * endCosine}`; |
| 41 | } |
| 42 | |
| 43 | export default class Arc extends Component { |
| 44 | static propTypes = { |