option.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getYAxisWithDefault = exports.transformObjectToArray = exports.getGeometryOption = exports.isColumn = exports.isLine = void 0;
  4. var tslib_1 = require("tslib");
  5. var util_1 = require("@antv/util");
  6. var utils_1 = require("../../../utils");
  7. var constant_1 = require("../constant");
  8. var types_1 = require("../types");
  9. /**
  10. * 根据 GeometryOption 判断 geometry 是否为 line
  11. */
  12. function isLine(geometryOption) {
  13. return (0, util_1.get)(geometryOption, 'geometry') === types_1.DualAxesGeometry.Line;
  14. }
  15. exports.isLine = isLine;
  16. /**
  17. * 根据 GeometryOption 判断 geometry 是否为 Column
  18. */
  19. function isColumn(geometryOption) {
  20. return (0, util_1.get)(geometryOption, 'geometry') === types_1.DualAxesGeometry.Column;
  21. }
  22. exports.isColumn = isColumn;
  23. /**
  24. * 获取 GeometryOption
  25. * @param geometryOption
  26. * @param axis
  27. */
  28. function getGeometryOption(xField, yField, geometryOption) {
  29. // 空默认为线
  30. return isColumn(geometryOption)
  31. ? (0, utils_1.deepAssign)({}, {
  32. geometry: types_1.DualAxesGeometry.Column,
  33. label: geometryOption.label && geometryOption.isRange
  34. ? {
  35. content: function (item) {
  36. var _a;
  37. return (_a = item[yField]) === null || _a === void 0 ? void 0 : _a.join('-');
  38. },
  39. }
  40. : undefined,
  41. }, geometryOption)
  42. : tslib_1.__assign({ geometry: types_1.DualAxesGeometry.Line }, geometryOption);
  43. }
  44. exports.getGeometryOption = getGeometryOption;
  45. /**
  46. * 兼容一些属性 为 arr 和 obj 的两种情况, 如 yAxis,annotations
  47. * 为了防止左右 yField 相同,导致变成 object 之后被覆盖,所以都转变成数组的形式
  48. * @param yField
  49. * @param transformAttribute
  50. */
  51. function transformObjectToArray(yField, transformAttribute) {
  52. var y1 = yField[0], y2 = yField[1];
  53. if ((0, util_1.isArray)(transformAttribute)) {
  54. // 将数组补齐为两个
  55. var a1_1 = transformAttribute[0], a2_1 = transformAttribute[1];
  56. return [a1_1, a2_1];
  57. }
  58. var a1 = (0, util_1.get)(transformAttribute, y1);
  59. var a2 = (0, util_1.get)(transformAttribute, y2);
  60. return [a1, a2];
  61. }
  62. exports.transformObjectToArray = transformObjectToArray;
  63. /**
  64. * 获取默认值
  65. * @param yAxis
  66. * @param axisType
  67. */
  68. function getYAxisWithDefault(yAxis, axisType) {
  69. if (axisType === types_1.AxisType.Left) {
  70. return yAxis === false ? false : (0, utils_1.deepAssign)({}, constant_1.DEFAULT_LEFT_YAXIS_CONFIG, yAxis);
  71. }
  72. else if (axisType === types_1.AxisType.Right) {
  73. return yAxis === false ? false : (0, utils_1.deepAssign)({}, constant_1.DEFAULT_RIGHT_YAXIS_CONFIG, yAxis);
  74. }
  75. return yAxis;
  76. }
  77. exports.getYAxisWithDefault = getYAxisWithDefault;
  78. //# sourceMappingURL=option.js.map