AxisModel.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 ComponentModel = require("../../model/Component");
  21. var axisModelCreator = require("../axisModelCreator");
  22. var axisModelCommonMixin = require("../axisModelCommonMixin");
  23. /*
  24. * Licensed to the Apache Software Foundation (ASF) under one
  25. * or more contributor license agreements. See the NOTICE file
  26. * distributed with this work for additional information
  27. * regarding copyright ownership. The ASF licenses this file
  28. * to you under the Apache License, Version 2.0 (the
  29. * "License"); you may not use this file except in compliance
  30. * with the License. You may obtain a copy of the License at
  31. *
  32. * http://www.apache.org/licenses/LICENSE-2.0
  33. *
  34. * Unless required by applicable law or agreed to in writing,
  35. * software distributed under the License is distributed on an
  36. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37. * KIND, either express or implied. See the License for the
  38. * specific language governing permissions and limitations
  39. * under the License.
  40. */
  41. var AxisModel = ComponentModel.extend({
  42. type: 'cartesian2dAxis',
  43. /**
  44. * @type {module:echarts/coord/cartesian/Axis2D}
  45. */
  46. axis: null,
  47. /**
  48. * @override
  49. */
  50. init: function () {
  51. AxisModel.superApply(this, 'init', arguments);
  52. this.resetRange();
  53. },
  54. /**
  55. * @override
  56. */
  57. mergeOption: function () {
  58. AxisModel.superApply(this, 'mergeOption', arguments);
  59. this.resetRange();
  60. },
  61. /**
  62. * @override
  63. */
  64. restoreData: function () {
  65. AxisModel.superApply(this, 'restoreData', arguments);
  66. this.resetRange();
  67. },
  68. /**
  69. * @override
  70. * @return {module:echarts/model/Component}
  71. */
  72. getCoordSysModel: function () {
  73. return this.ecModel.queryComponents({
  74. mainType: 'grid',
  75. index: this.option.gridIndex,
  76. id: this.option.gridId
  77. })[0];
  78. }
  79. });
  80. function getAxisType(axisDim, option) {
  81. // Default axis with data is category axis
  82. return option.type || (option.data ? 'category' : 'value');
  83. }
  84. zrUtil.merge(AxisModel.prototype, axisModelCommonMixin);
  85. var extraOption = {
  86. // gridIndex: 0,
  87. // gridId: '',
  88. // Offset is for multiple axis on the same position
  89. offset: 0
  90. };
  91. axisModelCreator('x', AxisModel, getAxisType, extraOption);
  92. axisModelCreator('y', AxisModel, getAxisType, extraOption);
  93. var _default = AxisModel;
  94. module.exports = _default;