coordinate.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. export function isTranspose(coordinate) {
  2. const { transformations } = coordinate.getOptions();
  3. const transposes = transformations
  4. .map(([type]) => type)
  5. .filter((type) => type === 'transpose');
  6. return transposes.length % 2 !== 0;
  7. }
  8. export function isPolar(coordinate) {
  9. const { transformations } = coordinate.getOptions();
  10. return transformations.some(([type]) => type === 'polar');
  11. }
  12. export function isRadial(coordinate) {
  13. const { transformations } = coordinate.getOptions();
  14. return (
  15. // distinguish radial from theta.
  16. transformations.some(([type]) => type === 'reflect') &&
  17. transformations.some(([type]) => type.startsWith('transpose')));
  18. }
  19. export function isHelix(coordinate) {
  20. const { transformations } = coordinate.getOptions();
  21. return transformations.some(([type]) => type === 'helix');
  22. }
  23. export function isParallel(coordinate) {
  24. const { transformations } = coordinate.getOptions();
  25. return transformations.some(([type]) => type === 'parallel');
  26. }
  27. export function isFisheye(coordinate) {
  28. const { transformations } = coordinate.getOptions();
  29. return transformations.some(([type]) => type === 'fisheye');
  30. }
  31. export function isRadar(coordinate) {
  32. return isParallel(coordinate) && isPolar(coordinate);
  33. }
  34. export function isCircular(coordinate) {
  35. return isHelix(coordinate) || isPolar(coordinate);
  36. }
  37. export function isTheta(coordinate) {
  38. return isPolar(coordinate) && isTranspose(coordinate);
  39. }
  40. export function isNonCartesian(coordinate) {
  41. return (isPolar(coordinate) ||
  42. isParallel(coordinate) ||
  43. isRadial(coordinate) ||
  44. isTheta(coordinate));
  45. }
  46. export function getRadius(coordinate) {
  47. if (isCircular(coordinate)) {
  48. const [width, height] = coordinate.getSize();
  49. const polar = coordinate
  50. .getOptions()
  51. .transformations.find((t) => t[0] === 'polar');
  52. // coordinate.size * outerRadius.
  53. if (polar)
  54. return (Math.max(width, height) / 2) * polar[4];
  55. }
  56. return 0;
  57. }
  58. export function radiusOf(coordinate) {
  59. const { transformations } = coordinate.getOptions();
  60. const [, , , innerRadius, outerRadius] = transformations.find((d) => d[0] === 'polar');
  61. return [+innerRadius, +outerRadius];
  62. }
  63. export function angleOf(coordinate, isRadius = true) {
  64. const { transformations } = coordinate.getOptions();
  65. const [, startAngle, endAngle] = transformations.find((d) => d[0] === 'polar');
  66. return isRadius
  67. ? [(+startAngle * 180) / Math.PI, (+endAngle * 180) / Math.PI]
  68. : [startAngle, endAngle];
  69. }
  70. export function getTransformOptions(coordinate, type) {
  71. const { transformations } = coordinate.getOptions();
  72. const [, ...args] = transformations.find((d) => d[0] === type);
  73. return args;
  74. }
  75. //# sourceMappingURL=coordinate.js.map