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.5KB

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