box.js 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.Box = 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. function getPath(points, coordinate) {
  22. const path = (0, d3_path_1.path)();
  23. if (!(0, coordinate_1.isPolar)(coordinate)) {
  24. path.moveTo(...points[0]);
  25. path.lineTo(...points[1]);
  26. path.moveTo(...points[2]);
  27. path.lineTo(...points[3]);
  28. path.moveTo(...points[4]);
  29. path.lineTo(...points[5]);
  30. path.lineTo(...points[6]);
  31. path.lineTo(...points[7]);
  32. path.closePath();
  33. path.moveTo(...points[8]);
  34. path.lineTo(...points[9]);
  35. path.moveTo(...points[10]);
  36. path.lineTo(...points[11]);
  37. path.moveTo(...points[12]);
  38. path.lineTo(...points[13]);
  39. }
  40. else {
  41. // In polar coordinate.
  42. const center = coordinate.getCenter();
  43. const [x, y] = center;
  44. const startAngle = (0, vector_1.angle)((0, vector_1.sub)(points[0], center));
  45. const endAngle = (0, vector_1.angle)((0, vector_1.sub)(points[1], center));
  46. const radiusHigh = (0, vector_1.dist)(center, points[2]);
  47. const radiusQ3 = (0, vector_1.dist)(center, points[3]);
  48. const radiusMedian = (0, vector_1.dist)(center, points[8]);
  49. const radiusQ1 = (0, vector_1.dist)(center, points[10]);
  50. const radiusLow = (0, vector_1.dist)(center, points[11]);
  51. path.moveTo(...points[0]);
  52. path.arc(x, y, radiusHigh, startAngle, endAngle);
  53. path.arc(x, y, radiusHigh, endAngle, startAngle, true);
  54. path.moveTo(...points[2]);
  55. path.lineTo(...points[3]);
  56. path.moveTo(...points[4]);
  57. path.arc(x, y, radiusQ3, startAngle, endAngle); // 4 -> 5
  58. path.lineTo(...points[6]); // 5 -> 6
  59. path.arc(x, y, radiusQ1, endAngle, startAngle, true); // 6 -> 7
  60. path.closePath();
  61. path.moveTo(...points[8]);
  62. path.arc(x, y, radiusMedian, startAngle, endAngle); // 8 -> 9
  63. path.arc(x, y, radiusMedian, endAngle, startAngle, true); // 9 -> 8
  64. path.moveTo(...points[10]);
  65. path.lineTo(...points[11]);
  66. path.moveTo(...points[12]);
  67. path.arc(x, y, radiusLow, startAngle, endAngle); // 12 -> 13
  68. path.arc(x, y, radiusLow, endAngle, startAngle, true); // 13 -> 12
  69. }
  70. return path;
  71. }
  72. const Box = (options) => {
  73. const style = __rest(options, []);
  74. return (points, value, coordinate, theme) => {
  75. const { mark, shape, defaultShape, color, transform } = value;
  76. const _a = (0, utils_1.getShapeTheme)(theme, mark, shape, defaultShape), { defaultColor, fill = defaultColor, stroke = defaultColor } = _a, shapeTheme = __rest(_a, ["defaultColor", "fill", "stroke"]);
  77. const path = getPath(points, coordinate);
  78. return (0, selection_1.select)(new g_1.Path())
  79. .call(utils_1.applyStyle, shapeTheme)
  80. .style('d', path.toString())
  81. .style('stroke', stroke)
  82. .style('fill', color || fill)
  83. .style('transform', transform)
  84. .call(utils_1.applyStyle, style)
  85. .node();
  86. };
  87. };
  88. exports.Box = Box;
  89. exports.Box.props = {
  90. defaultMarker: 'point',
  91. defaultEnterAnimation: 'fadeIn',
  92. defaultUpdateAnimation: 'morphing',
  93. defaultExitAnimation: 'fadeOut',
  94. };
  95. //# sourceMappingURL=box.js.map