axisModelCreator.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 =
  54. /** @class */
  55. function (_super) {
  56. __extends(AxisModel, _super);
  57. function AxisModel() {
  58. var _this = _super !== null && _super.apply(this, arguments) || this;
  59. _this.type = axisName + 'Axis.' + axisType;
  60. return _this;
  61. }
  62. AxisModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  63. var layoutMode = fetchLayoutMode(this);
  64. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  65. var themeModel = ecModel.getTheme();
  66. merge(option, themeModel.get(axisType + 'Axis'));
  67. merge(option, this.getDefaultOption());
  68. option.type = getAxisType(option);
  69. if (layoutMode) {
  70. mergeLayoutParam(option, inputPositionParams, layoutMode);
  71. }
  72. };
  73. AxisModel.prototype.optionUpdated = function () {
  74. var thisOption = this.option;
  75. if (thisOption.type === 'category') {
  76. this.__ordinalMeta = OrdinalMeta.createByAxisModel(this);
  77. }
  78. };
  79. /**
  80. * Should not be called before all of 'getInitailData' finished.
  81. * Because categories are collected during initializing data.
  82. */
  83. AxisModel.prototype.getCategories = function (rawData) {
  84. var option = this.option; // FIXME
  85. // warning if called before all of 'getInitailData' finished.
  86. if (option.type === 'category') {
  87. if (rawData) {
  88. return option.data;
  89. }
  90. return this.__ordinalMeta.categories;
  91. }
  92. };
  93. AxisModel.prototype.getOrdinalMeta = function () {
  94. return this.__ordinalMeta;
  95. };
  96. AxisModel.type = axisName + 'Axis.' + axisType;
  97. AxisModel.defaultOption = defaultOption;
  98. return AxisModel;
  99. }(BaseAxisModelClass);
  100. registers.registerComponentModel(AxisModel);
  101. });
  102. registers.registerSubTypeDefaulter(axisName + 'Axis', getAxisType);
  103. }
  104. function getAxisType(option) {
  105. // Default axis with data is category axis
  106. return option.type || (option.data ? 'category' : 'value');
  107. }