facetCircle.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 { Container } from '../utils/container';
  13. import { angleWithQuadrant, angleBetween, dist, sub } from '../utils/vector';
  14. import { inferColor, setAnimation, setStyle, toCell, setChildren, setData, } from './facetRect';
  15. import { useDefaultAdaptor } from './utils';
  16. const setScale = useDefaultAdaptor((options) => {
  17. return {
  18. scale: {
  19. x: { guide: { type: 'axisArc' }, paddingOuter: 0, paddingInner: 0.1 },
  20. y: { guide: null, range: [0, 1], paddingOuter: 0, paddingInner: 0.1 },
  21. },
  22. };
  23. });
  24. const setCoordinate = useDefaultAdaptor((options) => {
  25. return {
  26. coordinate: { type: 'polar' },
  27. };
  28. });
  29. const setEncode = (options) => {
  30. const { encode } = options, rest = __rest(options, ["encode"]);
  31. const { position } = encode;
  32. return Object.assign(Object.assign({}, rest), { encode: { x: position } });
  33. };
  34. /**
  35. * Every facet should do not show both axisX and axisY by default.
  36. */
  37. function createGuideFacetCircle(guide) {
  38. return (facet) => null;
  39. }
  40. /**
  41. * Use the inscribed circle of the sector as the
  42. * circumscribed circle of the new bbox.
  43. */
  44. function subLayoutFacetCircle(data) {
  45. const { points } = data;
  46. const [p0, p1, p2, p3] = points;
  47. const sr = dist(p0, p3); // radius of sector
  48. const v0 = sub(p0, p3);
  49. const v1 = sub(p1, p2);
  50. const a01 = angleBetween(v0, v1);
  51. // sr = ir + ir / sin(theta/2)
  52. const t = 1 / Math.sin(a01 / 2);
  53. const ir = sr / (1 + t); // radius of inscribed circle
  54. const s = ir * Math.sqrt(2); // size of the bbox.
  55. // This assume the innerRadius of polar is 0.
  56. // @todo Compute the right origin if it's not 0,
  57. // or maybe pass the coordinates to get the right center.
  58. const [x0, y0] = p2;
  59. const a0 = angleWithQuadrant(v0);
  60. const a3 = a0 + a01 / 2;
  61. const d = ir * t;
  62. const cx = x0 + d * Math.sin(a3); // center x of inscribed circle
  63. const cy = y0 + d * Math.cos(a3); // center y of inscribed circle
  64. return [cx - s / 2, cy - s / 2, s, s];
  65. }
  66. /**
  67. * @todo Pack.
  68. */
  69. export const FacetCircle = () => {
  70. return (options) => {
  71. const newOptions = Container.of(options)
  72. .call(toCell)
  73. .call(setEncode)
  74. .call(inferColor)
  75. .call(setCoordinate)
  76. .call(setData)
  77. .call(setChildren, subLayoutFacetCircle, createGuideFacetCircle, createGuideFacetCircle, { frame: false })
  78. .call(setAnimation)
  79. .call(setStyle)
  80. .call(setScale)
  81. .value();
  82. return [newOptions];
  83. };
  84. };
  85. //# sourceMappingURL=facetCircle.js.map