BrushView.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. var echarts = require("../../echarts");
  2. var zrUtil = require("zrender/lib/core/util");
  3. var BrushController = require("../helper/BrushController");
  4. var _default = echarts.extendComponentView({
  5. type: 'brush',
  6. init: function (ecModel, api) {
  7. /**
  8. * @readOnly
  9. * @type {module:echarts/model/Global}
  10. */
  11. this.ecModel = ecModel;
  12. /**
  13. * @readOnly
  14. * @type {module:echarts/ExtensionAPI}
  15. */
  16. this.api = api;
  17. /**
  18. * @readOnly
  19. * @type {module:echarts/component/brush/BrushModel}
  20. */
  21. this.model;
  22. /**
  23. * @private
  24. * @type {module:echarts/component/helper/BrushController}
  25. */
  26. (this._brushController = new BrushController(api.getZr())).on('brush', zrUtil.bind(this._onBrush, this)).mount();
  27. },
  28. /**
  29. * @override
  30. */
  31. render: function (brushModel) {
  32. this.model = brushModel;
  33. return updateController.apply(this, arguments);
  34. },
  35. /**
  36. * @override
  37. */
  38. updateView: updateController,
  39. /**
  40. * @override
  41. */
  42. updateLayout: updateController,
  43. /**
  44. * @override
  45. */
  46. updateVisual: updateController,
  47. /**
  48. * @override
  49. */
  50. dispose: function () {
  51. this._brushController.dispose();
  52. },
  53. /**
  54. * @private
  55. */
  56. _onBrush: function (areas, opt) {
  57. var modelId = this.model.id;
  58. this.model.brushTargetManager.setOutputRanges(areas, this.ecModel); // Action is not dispatched on drag end, because the drag end
  59. // emits the same params with the last drag move event, and
  60. // may have some delay when using touch pad, which makes
  61. // animation not smooth (when using debounce).
  62. (!opt.isEnd || opt.removeOnClick) && this.api.dispatchAction({
  63. type: 'brush',
  64. brushId: modelId,
  65. areas: zrUtil.clone(areas),
  66. $from: modelId
  67. });
  68. }
  69. });
  70. function updateController(brushModel, ecModel, api, payload) {
  71. // Do not update controller when drawing.
  72. (!payload || payload.$from !== brushModel.id) && this._brushController.setPanels(brushModel.brushTargetManager.makePanelOpts(api)).enableBrush(brushModel.brushOption).updateCovers(brushModel.areas.slice());
  73. }
  74. module.exports = _default;