BrushView.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 echarts = require("../../echarts");
  20. var zrUtil = require("zrender/lib/core/util");
  21. var BrushController = require("../helper/BrushController");
  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. var _default = echarts.extendComponentView({
  41. type: 'brush',
  42. init: function (ecModel, api) {
  43. /**
  44. * @readOnly
  45. * @type {module:echarts/model/Global}
  46. */
  47. this.ecModel = ecModel;
  48. /**
  49. * @readOnly
  50. * @type {module:echarts/ExtensionAPI}
  51. */
  52. this.api = api;
  53. /**
  54. * @readOnly
  55. * @type {module:echarts/component/brush/BrushModel}
  56. */
  57. this.model;
  58. /**
  59. * @private
  60. * @type {module:echarts/component/helper/BrushController}
  61. */
  62. (this._brushController = new BrushController(api.getZr())).on('brush', zrUtil.bind(this._onBrush, this)).mount();
  63. },
  64. /**
  65. * @override
  66. */
  67. render: function (brushModel) {
  68. this.model = brushModel;
  69. return updateController.apply(this, arguments);
  70. },
  71. /**
  72. * @override
  73. */
  74. updateTransform: updateController,
  75. /**
  76. * @override
  77. */
  78. updateView: updateController,
  79. // /**
  80. // * @override
  81. // */
  82. // updateLayout: updateController,
  83. // /**
  84. // * @override
  85. // */
  86. // updateVisual: updateController,
  87. /**
  88. * @override
  89. */
  90. dispose: function () {
  91. this._brushController.dispose();
  92. },
  93. /**
  94. * @private
  95. */
  96. _onBrush: function (areas, opt) {
  97. var modelId = this.model.id;
  98. this.model.brushTargetManager.setOutputRanges(areas, this.ecModel); // Action is not dispatched on drag end, because the drag end
  99. // emits the same params with the last drag move event, and
  100. // may have some delay when using touch pad, which makes
  101. // animation not smooth (when using debounce).
  102. (!opt.isEnd || opt.removeOnClick) && this.api.dispatchAction({
  103. type: 'brush',
  104. brushId: modelId,
  105. areas: zrUtil.clone(areas),
  106. $from: modelId
  107. });
  108. opt.isEnd && this.api.dispatchAction({
  109. type: 'brushEnd',
  110. brushId: modelId,
  111. areas: zrUtil.clone(areas),
  112. $from: modelId
  113. });
  114. }
  115. });
  116. function updateController(brushModel, ecModel, api, payload) {
  117. // Do not update controller when drawing.
  118. (!payload || payload.$from !== brushModel.id) && this._brushController.setPanels(brushModel.brushTargetManager.makePanelOpts(api)).enableBrush(brushModel.brushOption).updateCovers(brushModel.areas.slice());
  119. }
  120. module.exports = _default;