axisModelCreator.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. var zrUtil = require("zrender/lib/core/util");
  20. var axisDefault = require("./axisDefault");
  21. var ComponentModel = require("../model/Component");
  22. var _layout = require("../util/layout");
  23. var getLayoutParams = _layout.getLayoutParams;
  24. var mergeLayoutParam = _layout.mergeLayoutParam;
  25. var OrdinalMeta = require("../data/OrdinalMeta");
  26. /*
  27. * Licensed to the Apache Software Foundation (ASF) under one
  28. * or more contributor license agreements. See the NOTICE file
  29. * distributed with this work for additional information
  30. * regarding copyright ownership. The ASF licenses this file
  31. * to you under the Apache License, Version 2.0 (the
  32. * "License"); you may not use this file except in compliance
  33. * with the License. You may obtain a copy of the License at
  34. *
  35. * http://www.apache.org/licenses/LICENSE-2.0
  36. *
  37. * Unless required by applicable law or agreed to in writing,
  38. * software distributed under the License is distributed on an
  39. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40. * KIND, either express or implied. See the License for the
  41. * specific language governing permissions and limitations
  42. * under the License.
  43. */
  44. // FIXME axisType is fixed ?
  45. var AXIS_TYPES = ['value', 'category', 'time', 'log'];
  46. /**
  47. * Generate sub axis model class
  48. * @param {string} axisName 'x' 'y' 'radius' 'angle' 'parallel'
  49. * @param {module:echarts/model/Component} BaseAxisModelClass
  50. * @param {Function} axisTypeDefaulter
  51. * @param {Object} [extraDefaultOption]
  52. */
  53. function _default(axisName, BaseAxisModelClass, axisTypeDefaulter, extraDefaultOption) {
  54. zrUtil.each(AXIS_TYPES, function (axisType) {
  55. BaseAxisModelClass.extend({
  56. /**
  57. * @readOnly
  58. */
  59. type: axisName + 'Axis.' + axisType,
  60. mergeDefaultAndTheme: function (option, ecModel) {
  61. var layoutMode = this.layoutMode;
  62. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  63. var themeModel = ecModel.getTheme();
  64. zrUtil.merge(option, themeModel.get(axisType + 'Axis'));
  65. zrUtil.merge(option, this.getDefaultOption());
  66. option.type = axisTypeDefaulter(axisName, option);
  67. if (layoutMode) {
  68. mergeLayoutParam(option, inputPositionParams, layoutMode);
  69. }
  70. },
  71. /**
  72. * @override
  73. */
  74. optionUpdated: function () {
  75. var thisOption = this.option;
  76. if (thisOption.type === 'category') {
  77. this.__ordinalMeta = OrdinalMeta.createByAxisModel(this);
  78. }
  79. },
  80. /**
  81. * Should not be called before all of 'getInitailData' finished.
  82. * Because categories are collected during initializing data.
  83. */
  84. getCategories: function (rawData) {
  85. var option = this.option; // FIXME
  86. // warning if called before all of 'getInitailData' finished.
  87. if (option.type === 'category') {
  88. if (rawData) {
  89. return option.data;
  90. }
  91. return this.__ordinalMeta.categories;
  92. }
  93. },
  94. getOrdinalMeta: function () {
  95. return this.__ordinalMeta;
  96. },
  97. defaultOption: zrUtil.mergeAll([{}, axisDefault[axisType + 'Axis'], extraDefaultOption], true)
  98. });
  99. });
  100. ComponentModel.registerSubTypeDefaulter(axisName + 'Axis', zrUtil.curry(axisTypeDefaulter, axisName));
  101. }
  102. module.exports = _default;