arc.js 2.3 KB

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