Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

path.js 1.4KB

1234567891011121314151617181920212223242526
  1. import { checkCollinear, getDistance, moveTo } from './math';
  2. /**
  3. * From https://github.com/unsplash/react-trend/blob/master/src/helpers/DOM.helpers.js#L18
  4. */
  5. export function genPath(points, radius) {
  6. var fill = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  7. var height = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 75;
  8. var start = points.shift();
  9. var end = points[points.length - 1];
  10. return (fill ? 'M' + start.x + ' ' + height + ' L' + start.x + ' ' + start.y : 'M' + start.x + ' ' + start.y) + points.map(function (point, index) {
  11. var next = points[index + 1];
  12. var prev = points[index - 1] || start;
  13. var isCollinear = next && checkCollinear(next, point, prev);
  14. if (!next || isCollinear) {
  15. return 'L' + point.x + ' ' + point.y;
  16. }
  17. var threshold = Math.min(getDistance(prev, point), getDistance(next, point));
  18. var isTooCloseForRadius = threshold / 2 < radius;
  19. var radiusForPoint = isTooCloseForRadius ? threshold / 2 : radius;
  20. var before = moveTo(prev, point, radiusForPoint);
  21. var after = moveTo(next, point, radiusForPoint);
  22. return 'L' + before.x + ' ' + before.y + 'S' + point.x + ' ' + point.y + ' ' + after.x + ' ' + after.y;
  23. }).join('') + (fill ? 'L' + end.x + ' ' + height + ' Z' : '');
  24. }
  25. //# sourceMappingURL=path.js.map