vhv.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.VHV = 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. * Get vhv path in different coordinate.
  23. */
  24. function getVHVPath(from, to, coordinate, ratio) {
  25. const path = (0, d3_path_1.path)();
  26. if ((0, coordinate_1.isPolar)(coordinate)) {
  27. const center = coordinate.getCenter();
  28. const a = (0, vector_1.dist)(from, center);
  29. const b = (0, vector_1.dist)(to, center);
  30. const radius = (b - a) * ratio + a;
  31. path.moveTo(from[0], from[1]);
  32. (0, utils_1.appendArc)(path, from, to, center, radius);
  33. path.lineTo(to[0], to[1]);
  34. return path;
  35. }
  36. if ((0, coordinate_1.isTranspose)(coordinate)) {
  37. path.moveTo(from[0], from[1]);
  38. // VHV in x.
  39. path.lineTo(from[0] + (to[0] - from[0]) * ratio, from[1]);
  40. path.lineTo(from[0] + (to[0] - from[0]) * ratio, to[1]);
  41. path.lineTo(to[0], to[1]);
  42. return path;
  43. }
  44. path.moveTo(from[0], from[1]);
  45. // VHV in y.
  46. path.lineTo(from[0], from[1] + (to[1] - from[1]) * ratio);
  47. path.lineTo(to[0], from[1] + (to[1] - from[1]) * ratio);
  48. path.lineTo(to[0], to[1]);
  49. return path;
  50. }
  51. /**
  52. * Connect 2 points with a VHV line, used in tree.
  53. */
  54. const VHV = (options) => {
  55. const { cornerRatio = 1 / 3 } = options, style = __rest(options, ["cornerRatio"]);
  56. return (points, value, coordinate, theme) => {
  57. const { mark, shape, defaultShape } = value;
  58. const _a = (0, utils_1.getShapeTheme)(theme, mark, shape, defaultShape), { defaultColor } = _a, shapeTheme = __rest(_a, ["defaultColor"]);
  59. const { color = defaultColor, transform } = value;
  60. const [from, to] = points;
  61. const path = getVHVPath(from, to, coordinate, cornerRatio);
  62. return (0, selection_1.select)(new g_1.Path())
  63. .call(utils_1.applyStyle, shapeTheme)
  64. .style('d', path.toString())
  65. .style('stroke', color)
  66. .style('transform', transform)
  67. .call(utils_1.applyStyle, style)
  68. .node();
  69. };
  70. };
  71. exports.VHV = VHV;
  72. exports.VHV.props = {
  73. defaultMarker: 'vhv',
  74. defaultEnterAnimation: 'fadeIn',
  75. defaultUpdateAnimation: 'morphing',
  76. defaultExitAnimation: 'fadeOut',
  77. };
  78. //# sourceMappingURL=vhv.js.map