smooth.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.Smooth = 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. /**
  20. * Connect 2 points with a smooth line, used in tree.
  21. */
  22. const Smooth = (options) => {
  23. const style = __rest(options, []);
  24. return (points, value, coordinate, theme) => {
  25. const { mark, shape, defaultShape } = value;
  26. const _a = (0, utils_1.getShapeTheme)(theme, mark, shape, defaultShape), { defaultColor } = _a, shapeTheme = __rest(_a, ["defaultColor"]);
  27. const { color = defaultColor, transform } = value;
  28. const [from, to] = points;
  29. const path = (0, d3_path_1.path)();
  30. path.moveTo(from[0], from[1]);
  31. path.bezierCurveTo(from[0] / 2 + to[0] / 2, from[1], from[0] / 2 + to[0] / 2, to[1], to[0], to[1]);
  32. return (0, selection_1.select)(new g_1.Path())
  33. .call(utils_1.applyStyle, shapeTheme)
  34. .style('d', path.toString())
  35. .style('stroke', color)
  36. .style('transform', transform)
  37. .call(utils_1.applyStyle, style)
  38. .node();
  39. };
  40. };
  41. exports.Smooth = Smooth;
  42. exports.Smooth.props = {
  43. defaultMarker: 'smooth',
  44. defaultEnterAnimation: 'fadeIn',
  45. defaultUpdateAnimation: 'morphing',
  46. defaultExitAnimation: 'fadeOut',
  47. };
  48. //# sourceMappingURL=smooth.js.map