coordinate.js 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.isReflectY = exports.isRadar = exports.isRadial = exports.isReflect = exports.isTheta = exports.isParallel = exports.isTranspose = exports.isHelix = exports.isPolar = exports.coordOf = exports.coordinate2Transform = exports.createCoordinate = void 0;
  15. const coord_1 = require("@antv/coord");
  16. const library_1 = require("./library");
  17. function createCoordinate(layout, partialOptions, library) {
  18. const [useCoordinate] = (0, library_1.useLibrary)('coordinate', library);
  19. const { innerHeight, innerWidth, insetLeft, insetTop, insetRight, insetBottom, marginLeft, marginTop, } = layout;
  20. const { coordinates: partialTransform = [] } = partialOptions;
  21. const transform = inferCoordinate(partialTransform);
  22. const coordinate = new coord_1.Coordinate(Object.assign(Object.assign({}, layout), { x: insetLeft + marginLeft, y: insetTop + marginTop, width: innerWidth - insetLeft - insetRight, height: innerHeight - insetBottom - insetTop, transformations: transform.map(useCoordinate).flat() }));
  23. return coordinate;
  24. }
  25. exports.createCoordinate = createCoordinate;
  26. function coordinate2Transform(node, library) {
  27. // @ts-ignore
  28. const { coordinate = {} } = node, rest = __rest(node, ["coordinate"]);
  29. const { type, transform = [] } = coordinate, options = __rest(coordinate, ["type", "transform"]);
  30. if (!type)
  31. return Object.assign(Object.assign({}, rest), { coordinates: transform });
  32. const [, createCoordinate] = (0, library_1.useLibrary)('coordinate', library);
  33. const { transform: isTransform = false } = createCoordinate(type).props || {};
  34. if (isTransform) {
  35. throw new Error(`Unknown coordinate: ${type}.`);
  36. }
  37. return Object.assign(Object.assign({}, rest), { coordinates: [Object.assign({ type }, options), ...transform] });
  38. }
  39. exports.coordinate2Transform = coordinate2Transform;
  40. function coordOf(coordinates, type) {
  41. return coordinates.filter((d) => d.type === type);
  42. }
  43. exports.coordOf = coordOf;
  44. /**
  45. * todo Duplication is not considered
  46. */
  47. function isPolar(coordinates) {
  48. return coordOf(coordinates, 'polar').length > 0;
  49. }
  50. exports.isPolar = isPolar;
  51. function isHelix(coordinates) {
  52. return coordOf(coordinates, 'helix').length > 0;
  53. }
  54. exports.isHelix = isHelix;
  55. /**
  56. * todo The number of transposes matters
  57. */
  58. function isTranspose(coordinates) {
  59. return coordOf(coordinates, 'transpose').length % 2 === 1;
  60. }
  61. exports.isTranspose = isTranspose;
  62. function isParallel(coordinates) {
  63. return coordOf(coordinates, 'parallel').length > 0;
  64. }
  65. exports.isParallel = isParallel;
  66. function isTheta(coordinates) {
  67. return coordOf(coordinates, 'theta').length > 0;
  68. }
  69. exports.isTheta = isTheta;
  70. function isReflect(coordinates) {
  71. return coordOf(coordinates, 'reflect').length > 0;
  72. }
  73. exports.isReflect = isReflect;
  74. function isRadial(coordinates) {
  75. return coordOf(coordinates, 'radial').length > 0;
  76. }
  77. exports.isRadial = isRadial;
  78. function isRadar(coordinates) {
  79. return coordOf(coordinates, 'radar').length > 0;
  80. }
  81. exports.isRadar = isRadar;
  82. /**
  83. * todo The axis corresponding to the Y reversal is not reversed
  84. */
  85. function isReflectY(coordinates) {
  86. return coordOf(coordinates, 'reflectY').length > 0;
  87. }
  88. exports.isReflectY = isReflectY;
  89. function inferCoordinate(coordinates) {
  90. if (coordinates.find((d) => d.type === 'cartesian'))
  91. return coordinates;
  92. return [...coordinates, { type: 'cartesian' }];
  93. }
  94. //# sourceMappingURL=coordinate.js.map