vector.js 2.2 KB

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