box.js 3.7 KB

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