BrushView.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. var _visualEncoding = require("./visualEncoding");
  23. var layoutCovers = _visualEncoding.layoutCovers;
  24. /*
  25. * Licensed to the Apache Software Foundation (ASF) under one
  26. * or more contributor license agreements. See the NOTICE file
  27. * distributed with this work for additional information
  28. * regarding copyright ownership. The ASF licenses this file
  29. * to you under the Apache License, Version 2.0 (the
  30. * "License"); you may not use this file except in compliance
  31. * with the License. You may obtain a copy of the License at
  32. *
  33. * http://www.apache.org/licenses/LICENSE-2.0
  34. *
  35. * Unless required by applicable law or agreed to in writing,
  36. * software distributed under the License is distributed on an
  37. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38. * KIND, either express or implied. See the License for the
  39. * specific language governing permissions and limitations
  40. * under the License.
  41. */
  42. var _default = echarts.extendComponentView({
  43. type: 'brush',
  44. init: function (ecModel, api) {
  45. /**
  46. * @readOnly
  47. * @type {module:echarts/model/Global}
  48. */
  49. this.ecModel = ecModel;
  50. /**
  51. * @readOnly
  52. * @type {module:echarts/ExtensionAPI}
  53. */
  54. this.api = api;
  55. /**
  56. * @readOnly
  57. * @type {module:echarts/component/brush/BrushModel}
  58. */
  59. this.model;
  60. /**
  61. * @private
  62. * @type {module:echarts/component/helper/BrushController}
  63. */
  64. (this._brushController = new BrushController(api.getZr())).on('brush', zrUtil.bind(this._onBrush, this)).mount();
  65. },
  66. /**
  67. * @override
  68. */
  69. render: function (brushModel) {
  70. this.model = brushModel;
  71. return updateController.apply(this, arguments);
  72. },
  73. /**
  74. * @override
  75. */
  76. updateTransform: function (brushModel, ecModel) {
  77. // PENDING: `updateTransform` is a little tricky, whose layout need
  78. // to be calculate mandatorily and other stages will not be performed.
  79. // Take care the correctness of the logic. See #11754 .
  80. layoutCovers(ecModel);
  81. return updateController.apply(this, arguments);
  82. },
  83. /**
  84. * @override
  85. */
  86. updateView: updateController,
  87. // /**
  88. // * @override
  89. // */
  90. // updateLayout: updateController,
  91. // /**
  92. // * @override
  93. // */
  94. // updateVisual: updateController,
  95. /**
  96. * @override
  97. */
  98. dispose: function () {
  99. this._brushController.dispose();
  100. },
  101. /**
  102. * @private
  103. */
  104. _onBrush: function (areas, opt) {
  105. var modelId = this.model.id;
  106. this.model.brushTargetManager.setOutputRanges(areas, this.ecModel); // Action is not dispatched on drag end, because the drag end
  107. // emits the same params with the last drag move event, and
  108. // may have some delay when using touch pad, which makes
  109. // animation not smooth (when using debounce).
  110. (!opt.isEnd || opt.removeOnClick) && this.api.dispatchAction({
  111. type: 'brush',
  112. brushId: modelId,
  113. areas: zrUtil.clone(areas),
  114. $from: modelId
  115. });
  116. opt.isEnd && this.api.dispatchAction({
  117. type: 'brushEnd',
  118. brushId: modelId,
  119. areas: zrUtil.clone(areas),
  120. $from: modelId
  121. });
  122. }
  123. });
  124. function updateController(brushModel, ecModel, api, payload) {
  125. // Do not update controller when drawing.
  126. (!payload || payload.$from !== brushModel.id) && this._brushController.setPanels(brushModel.brushTargetManager.makePanelOpts(api)).enableBrush(brushModel.brushOption).updateCovers(brushModel.areas.slice());
  127. }
  128. module.exports = _default;