smooth.js 1.7 KB

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