BrushView.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 = /** @class */function (_super) {
  46. __extends(BrushView, _super);
  47. function BrushView() {
  48. var _this = _super !== null && _super.apply(this, arguments) || this;
  49. _this.type = BrushView.type;
  50. return _this;
  51. }
  52. BrushView.prototype.init = function (ecModel, api) {
  53. this.ecModel = ecModel;
  54. this.api = api;
  55. this.model;
  56. (this._brushController = new BrushController(api.getZr())).on('brush', zrUtil.bind(this._onBrush, this)).mount();
  57. };
  58. BrushView.prototype.render = function (brushModel, ecModel, api, payload) {
  59. this.model = brushModel;
  60. this._updateController(brushModel, ecModel, api, payload);
  61. };
  62. BrushView.prototype.updateTransform = function (brushModel, ecModel, api, payload) {
  63. // PENDING: `updateTransform` is a little tricky, whose layout need
  64. // to be calculate mandatorily and other stages will not be performed.
  65. // Take care the correctness of the logic. See #11754 .
  66. layoutCovers(ecModel);
  67. this._updateController(brushModel, ecModel, api, payload);
  68. };
  69. BrushView.prototype.updateVisual = function (brushModel, ecModel, api, payload) {
  70. this.updateTransform(brushModel, ecModel, api, payload);
  71. };
  72. BrushView.prototype.updateView = function (brushModel, ecModel, api, payload) {
  73. this._updateController(brushModel, ecModel, api, payload);
  74. };
  75. BrushView.prototype._updateController = function (brushModel, ecModel, api, payload) {
  76. // Do not update controller when drawing.
  77. (!payload || payload.$from !== brushModel.id) && this._brushController.setPanels(brushModel.brushTargetManager.makePanelOpts(api)).enableBrush(brushModel.brushOption).updateCovers(brushModel.areas.slice());
  78. };
  79. // updateLayout: updateController,
  80. // updateVisual: updateController,
  81. BrushView.prototype.dispose = function () {
  82. this._brushController.dispose();
  83. };
  84. BrushView.prototype._onBrush = function (eventParam) {
  85. var modelId = this.model.id;
  86. var areas = this.model.brushTargetManager.setOutputRanges(eventParam.areas, this.ecModel);
  87. // 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;