option.js 2.4 KB

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