arc.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var __rest = (this && this.__rest) || function (s, e) {
  2. var t = {};
  3. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  4. t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  6. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  7. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  8. t[p[i]] = s[p[i]];
  9. }
  10. return t;
  11. };
  12. import { Path } from '@antv/g';
  13. import { path as d3path } from 'd3-path';
  14. import { appendArc, applyStyle, getShapeTheme } from '../utils';
  15. import { select } from '../../utils/selection';
  16. import { isPolar } from '../../utils/coordinate';
  17. import { dist, mid } from '../../utils/vector';
  18. /**
  19. * Connect points for 2 points:
  20. * - In rect, draw half circle.
  21. * - In polar, draw quadratic curve.
  22. */
  23. export const Arc = (options) => {
  24. const style = __rest(options, []);
  25. return (points, value, coordinate, theme) => {
  26. const { mark, shape, defaultShape } = value;
  27. const _a = getShapeTheme(theme, mark, shape, defaultShape), { defaultColor } = _a, shapeTheme = __rest(_a, ["defaultColor"]);
  28. const { color = defaultColor, transform } = value;
  29. const [from, to] = points;
  30. const path = d3path();
  31. path.moveTo(from[0], from[1]);
  32. if (isPolar(coordinate)) {
  33. const center = coordinate.getCenter();
  34. path.quadraticCurveTo(center[0], center[1], to[0], to[1]);
  35. }
  36. else {
  37. const center = mid(from, to);
  38. const raduis = dist(from, to) / 2;
  39. appendArc(path, from, to, center, raduis);
  40. }
  41. return select(new Path())
  42. .call(applyStyle, shapeTheme)
  43. .style('d', path.toString())
  44. .style('stroke', color)
  45. .style('transform', transform)
  46. .call(applyStyle, style)
  47. .node();
  48. };
  49. };
  50. Arc.props = {
  51. defaultMarker: 'smooth',
  52. defaultEnterAnimation: 'fadeIn',
  53. defaultUpdateAnimation: 'morphing',
  54. defaultExitAnimation: 'fadeOut',
  55. };
  56. //# sourceMappingURL=arc.js.map