AxisView.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. var _config = require("../../config");
  2. var __DEV__ = _config.__DEV__;
  3. var echarts = require("../../echarts");
  4. var axisPointerModelHelper = require("../axisPointer/modelHelper");
  5. /**
  6. * Base class of AxisView.
  7. */
  8. var AxisView = echarts.extendComponentView({
  9. type: 'axis',
  10. /**
  11. * @private
  12. */
  13. _axisPointer: null,
  14. /**
  15. * @protected
  16. * @type {string}
  17. */
  18. axisPointerClass: null,
  19. /**
  20. * @override
  21. */
  22. render: function (axisModel, ecModel, api, payload) {
  23. // FIXME
  24. // This process should proformed after coordinate systems updated
  25. // (axis scale updated), and should be performed each time update.
  26. // So put it here temporarily, although it is not appropriate to
  27. // put a model-writing procedure in `view`.
  28. this.axisPointerClass && axisPointerModelHelper.fixValue(axisModel);
  29. AxisView.superApply(this, 'render', arguments);
  30. updateAxisPointer(this, axisModel, ecModel, api, payload, true);
  31. },
  32. /**
  33. * Action handler.
  34. * @public
  35. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  36. * @param {module:echarts/model/Global} ecModel
  37. * @param {module:echarts/ExtensionAPI} api
  38. * @param {Object} payload
  39. */
  40. updateAxisPointer: function (axisModel, ecModel, api, payload, force) {
  41. updateAxisPointer(this, axisModel, ecModel, api, payload, false);
  42. },
  43. /**
  44. * @override
  45. */
  46. remove: function (ecModel, api) {
  47. var axisPointer = this._axisPointer;
  48. axisPointer && axisPointer.remove(api);
  49. AxisView.superApply(this, 'remove', arguments);
  50. },
  51. /**
  52. * @override
  53. */
  54. dispose: function (ecModel, api) {
  55. disposeAxisPointer(this, api);
  56. AxisView.superApply(this, 'dispose', arguments);
  57. }
  58. });
  59. function updateAxisPointer(axisView, axisModel, ecModel, api, payload, forceRender) {
  60. var Clazz = AxisView.getAxisPointerClass(axisView.axisPointerClass);
  61. if (!Clazz) {
  62. return;
  63. }
  64. var axisPointerModel = axisPointerModelHelper.getAxisPointerModel(axisModel);
  65. axisPointerModel ? (axisView._axisPointer || (axisView._axisPointer = new Clazz())).render(axisModel, axisPointerModel, api, forceRender) : disposeAxisPointer(axisView, api);
  66. }
  67. function disposeAxisPointer(axisView, ecModel, api) {
  68. var axisPointer = axisView._axisPointer;
  69. axisPointer && axisPointer.dispose(ecModel, api);
  70. axisView._axisPointer = null;
  71. }
  72. var axisPointerClazz = [];
  73. AxisView.registerAxisPointerClass = function (type, clazz) {
  74. axisPointerClazz[type] = clazz;
  75. };
  76. AxisView.getAxisPointerClass = function (type) {
  77. return type && axisPointerClazz[type];
  78. };
  79. var _default = AxisView;
  80. module.exports = _default;