axisModelCreator.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { __extends } from "tslib";
  41. import axisDefault from './axisDefault.js';
  42. import { getLayoutParams, mergeLayoutParam, fetchLayoutMode } from '../util/layout.js';
  43. import OrdinalMeta from '../data/OrdinalMeta.js';
  44. import { AXIS_TYPES } from './axisCommonTypes.js';
  45. import { each, merge } from 'zrender/lib/core/util.js';
  46. /**
  47. * Generate sub axis model class
  48. * @param axisName 'x' 'y' 'radius' 'angle' 'parallel' ...
  49. */
  50. export default function axisModelCreator(registers, axisName, BaseAxisModelClass, extraDefaultOption) {
  51. each(AXIS_TYPES, function (v, axisType) {
  52. var defaultOption = merge(merge({}, axisDefault[axisType], true), extraDefaultOption, true);
  53. var AxisModel = /** @class */function (_super) {
  54. __extends(AxisModel, _super);
  55. function AxisModel() {
  56. var _this = _super !== null && _super.apply(this, arguments) || this;
  57. _this.type = axisName + 'Axis.' + axisType;
  58. return _this;
  59. }
  60. AxisModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  61. var layoutMode = fetchLayoutMode(this);
  62. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  63. var themeModel = ecModel.getTheme();
  64. merge(option, themeModel.get(axisType + 'Axis'));
  65. merge(option, this.getDefaultOption());
  66. option.type = getAxisType(option);
  67. if (layoutMode) {
  68. mergeLayoutParam(option, inputPositionParams, layoutMode);
  69. }
  70. };
  71. AxisModel.prototype.optionUpdated = function () {
  72. var thisOption = this.option;
  73. if (thisOption.type === 'category') {
  74. this.__ordinalMeta = OrdinalMeta.createByAxisModel(this);
  75. }
  76. };
  77. /**
  78. * Should not be called before all of 'getInitailData' finished.
  79. * Because categories are collected during initializing data.
  80. */
  81. AxisModel.prototype.getCategories = function (rawData) {
  82. var option = this.option;
  83. // FIXME
  84. // warning if called before all of 'getInitailData' finished.
  85. if (option.type === 'category') {
  86. if (rawData) {
  87. return option.data;
  88. }
  89. return this.__ordinalMeta.categories;
  90. }
  91. };
  92. AxisModel.prototype.getOrdinalMeta = function () {
  93. return this.__ordinalMeta;
  94. };
  95. AxisModel.type = axisName + 'Axis.' + axisType;
  96. AxisModel.defaultOption = defaultOption;
  97. return AxisModel;
  98. }(BaseAxisModelClass);
  99. registers.registerComponentModel(AxisModel);
  100. });
  101. registers.registerSubTypeDefaulter(axisName + 'Axis', getAxisType);
  102. }
  103. function getAxisType(option) {
  104. // Default axis with data is category axis
  105. return option.type || (option.data ? 'category' : 'value');
  106. }