BrushView.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  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. import { __extends } from "tslib";
  41. import * as zrUtil from 'zrender/lib/core/util.js';
  42. import BrushController from '../helper/BrushController.js';
  43. import { layoutCovers } from './visualEncoding.js';
  44. import ComponentView from '../../view/Component.js';
  45. var BrushView =
  46. /** @class */
  47. function (_super) {
  48. __extends(BrushView, _super);
  49. function BrushView() {
  50. var _this = _super !== null && _super.apply(this, arguments) || this;
  51. _this.type = BrushView.type;
  52. return _this;
  53. }
  54. BrushView.prototype.init = function (ecModel, api) {
  55. this.ecModel = ecModel;
  56. this.api = api;
  57. this.model;
  58. (this._brushController = new BrushController(api.getZr())).on('brush', zrUtil.bind(this._onBrush, this)).mount();
  59. };
  60. BrushView.prototype.render = function (brushModel, ecModel, api, payload) {
  61. this.model = brushModel;
  62. this._updateController(brushModel, ecModel, api, payload);
  63. };
  64. BrushView.prototype.updateTransform = function (brushModel, ecModel, api, payload) {
  65. // PENDING: `updateTransform` is a little tricky, whose layout need
  66. // to be calculate mandatorily and other stages will not be performed.
  67. // Take care the correctness of the logic. See #11754 .
  68. layoutCovers(ecModel);
  69. this._updateController(brushModel, ecModel, api, payload);
  70. };
  71. BrushView.prototype.updateVisual = function (brushModel, ecModel, api, payload) {
  72. this.updateTransform(brushModel, ecModel, api, payload);
  73. };
  74. BrushView.prototype.updateView = function (brushModel, ecModel, api, payload) {
  75. this._updateController(brushModel, ecModel, api, payload);
  76. };
  77. BrushView.prototype._updateController = function (brushModel, ecModel, api, payload) {
  78. // Do not update controller when drawing.
  79. (!payload || payload.$from !== brushModel.id) && this._brushController.setPanels(brushModel.brushTargetManager.makePanelOpts(api)).enableBrush(brushModel.brushOption).updateCovers(brushModel.areas.slice());
  80. }; // updateLayout: updateController,
  81. // updateVisual: updateController,
  82. BrushView.prototype.dispose = function () {
  83. this._brushController.dispose();
  84. };
  85. BrushView.prototype._onBrush = function (eventParam) {
  86. var modelId = this.model.id;
  87. var areas = this.model.brushTargetManager.setOutputRanges(eventParam.areas, this.ecModel); // Action is not dispatched on drag end, because the drag end
  88. // emits the same params with the last drag move event, and
  89. // may have some delay when using touch pad, which makes
  90. // animation not smooth (when using debounce).
  91. (!eventParam.isEnd || eventParam.removeOnClick) && this.api.dispatchAction({
  92. type: 'brush',
  93. brushId: modelId,
  94. areas: zrUtil.clone(areas),
  95. $from: modelId
  96. });
  97. eventParam.isEnd && this.api.dispatchAction({
  98. type: 'brushEnd',
  99. brushId: modelId,
  100. areas: zrUtil.clone(areas),
  101. $from: modelId
  102. });
  103. };
  104. BrushView.type = 'brush';
  105. return BrushView;
  106. }(ComponentView);
  107. export default BrushView;