{"size": 965, "ext": "js", "max_stars_repo_path": "src/atoms/PlanetoidStripe.js", "max_stars_repo_name": "xavcz/react-orbital", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/atoms/PlanetoidStripe.js", "max_issues_repo_name": "xavcz/react-orbital", "max_issues_repo_issues_event_min_datetime": "2017-04-28T07:16:07.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-28T09:29:34.000Z", "max_forks_repo_path": "src/atoms/PlanetoidStripe.js", "max_forks_repo_name": "xavcz/react-orbital", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 26.8055555556, "max_line_length": 71, "alphanum_fraction": 0.6580310881}
import React, { PropTypes } from 'react';

const PlanetoidStripe = ({ cx, cy, r, angle, length, offset = 0 }) => {
  // convert angle in radian
  const angleRadian = angle * Math.PI / 180;

  // make the stripe goes from left to right or right to left
  // depending on the angle in degree
  const direction = angle >= 80 || angle <= -80 ? -1 : 1;

  // base coordinate for the line to start from the planetoid edge
  const x = cx - r * Math.cos(angleRadian);
  const y = cy - r * Math.sin(angleRadian);

  const stripeDefinition = {
    x1: x + direction * offset,
    y1: y,
    x2: x + direction * (length + offset),
    y2: y,
  };

  return <line {...stripeDefinition} />;
};

PlanetoidStripe.propTypes = {
  angle: PropTypes.number.isRequired,
  // from the planetoid
  radius: PropTypes.number,
  cx: PropTypes.number,
  cy: PropTypes.number,
  // passed in degree, will be converted in radian
  offset: PropTypes.number,
};

export default PlanetoidStripe;
