facetCircle.js 3.2 KB

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