AxisView.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 _config = require("../../config");
  20. var __DEV__ = _config.__DEV__;
  21. var echarts = require("../../echarts");
  22. var axisPointerModelHelper = require("../axisPointer/modelHelper");
  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. /**
  42. * Base class of AxisView.
  43. */
  44. var AxisView = echarts.extendComponentView({
  45. type: 'axis',
  46. /**
  47. * @private
  48. */
  49. _axisPointer: null,
  50. /**
  51. * @protected
  52. * @type {string}
  53. */
  54. axisPointerClass: null,
  55. /**
  56. * @override
  57. */
  58. render: function (axisModel, ecModel, api, payload) {
  59. // FIXME
  60. // This process should proformed after coordinate systems updated
  61. // (axis scale updated), and should be performed each time update.
  62. // So put it here temporarily, although it is not appropriate to
  63. // put a model-writing procedure in `view`.
  64. this.axisPointerClass && axisPointerModelHelper.fixValue(axisModel);
  65. AxisView.superApply(this, 'render', arguments);
  66. updateAxisPointer(this, axisModel, ecModel, api, payload, true);
  67. },
  68. /**
  69. * Action handler.
  70. * @public
  71. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  72. * @param {module:echarts/model/Global} ecModel
  73. * @param {module:echarts/ExtensionAPI} api
  74. * @param {Object} payload
  75. */
  76. updateAxisPointer: function (axisModel, ecModel, api, payload, force) {
  77. updateAxisPointer(this, axisModel, ecModel, api, payload, false);
  78. },
  79. /**
  80. * @override
  81. */
  82. remove: function (ecModel, api) {
  83. var axisPointer = this._axisPointer;
  84. axisPointer && axisPointer.remove(api);
  85. AxisView.superApply(this, 'remove', arguments);
  86. },
  87. /**
  88. * @override
  89. */
  90. dispose: function (ecModel, api) {
  91. disposeAxisPointer(this, api);
  92. AxisView.superApply(this, 'dispose', arguments);
  93. }
  94. });
  95. function updateAxisPointer(axisView, axisModel, ecModel, api, payload, forceRender) {
  96. var Clazz = AxisView.getAxisPointerClass(axisView.axisPointerClass);
  97. if (!Clazz) {
  98. return;
  99. }
  100. var axisPointerModel = axisPointerModelHelper.getAxisPointerModel(axisModel);
  101. axisPointerModel ? (axisView._axisPointer || (axisView._axisPointer = new Clazz())).render(axisModel, axisPointerModel, api, forceRender) : disposeAxisPointer(axisView, api);
  102. }
  103. function disposeAxisPointer(axisView, ecModel, api) {
  104. var axisPointer = axisView._axisPointer;
  105. axisPointer && axisPointer.dispose(ecModel, api);
  106. axisView._axisPointer = null;
  107. }
  108. var axisPointerClazz = [];
  109. AxisView.registerAxisPointerClass = function (type, clazz) {
  110. axisPointerClazz[type] = clazz;
  111. };
  112. AxisView.getAxisPointerClass = function (type) {
  113. return type && axisPointerClazz[type];
  114. };
  115. var _default = AxisView;
  116. module.exports = _default;