vector.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 as d3path } from 'd3-path';
  13. import { Path } from '@antv/g';
  14. import { applyStyle, arrowPoints, getShapeTheme } from '../utils';
  15. import { select } from '../../utils/selection';
  16. /**
  17. * Connect 2 points with a single line with arrow.
  18. * ----->
  19. */
  20. export const Vector = (options) => {
  21. const { arrow = true, arrowSize = '40%' } = options, style = __rest(options, ["arrow", "arrowSize"]);
  22. return (points, value, coordinate, theme) => {
  23. const { mark, shape, defaultShape, transform } = value;
  24. const _a = getShapeTheme(theme, mark, shape, defaultShape), { defaultColor } = _a, shapeTheme = __rest(_a, ["defaultColor"]);
  25. const { color = defaultColor } = value;
  26. const [from, to] = points;
  27. // Draw line
  28. const path = d3path();
  29. path.moveTo(...from);
  30. path.lineTo(...to);
  31. // Draw 2 arrows.
  32. if (arrow) {
  33. // Calculate arrow end point.
  34. const [arrow1, arrow2] = arrowPoints(from, to, { arrowSize });
  35. path.moveTo(...to);
  36. path.lineTo(...arrow1);
  37. path.moveTo(...to);
  38. path.lineTo(...arrow2);
  39. }
  40. return select(new Path())
  41. .call(applyStyle, shapeTheme)
  42. .style('d', path.toString())
  43. .style('stroke', color || defaultColor)
  44. .style('transform', transform)
  45. .call(applyStyle, style)
  46. .node();
  47. };
  48. };
  49. Vector.props = {
  50. defaultMarker: 'line',
  51. defaultEnterAnimation: 'fadeIn',
  52. defaultUpdateAnimation: 'morphing',
  53. defaultExitAnimation: 'fadeOut',
  54. };
  55. //# sourceMappingURL=vector.js.map