ParallelView.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 ComponentView from '../../view/Component.js';
  42. import { each, bind, extend } from 'zrender/lib/core/util.js';
  43. import { createOrUpdate, clear } from '../../util/throttle.js';
  44. var CLICK_THRESHOLD = 5; // > 4
  45. var ParallelView = /** @class */function (_super) {
  46. __extends(ParallelView, _super);
  47. function ParallelView() {
  48. var _this = _super !== null && _super.apply(this, arguments) || this;
  49. _this.type = ParallelView.type;
  50. return _this;
  51. }
  52. ParallelView.prototype.render = function (parallelModel, ecModel, api) {
  53. this._model = parallelModel;
  54. this._api = api;
  55. if (!this._handlers) {
  56. this._handlers = {};
  57. each(handlers, function (handler, eventName) {
  58. api.getZr().on(eventName, this._handlers[eventName] = bind(handler, this));
  59. }, this);
  60. }
  61. createOrUpdate(this, '_throttledDispatchExpand', parallelModel.get('axisExpandRate'), 'fixRate');
  62. };
  63. ParallelView.prototype.dispose = function (ecModel, api) {
  64. clear(this, '_throttledDispatchExpand');
  65. each(this._handlers, function (handler, eventName) {
  66. api.getZr().off(eventName, handler);
  67. });
  68. this._handlers = null;
  69. };
  70. /**
  71. * @internal
  72. * @param {Object} [opt] If null, cancel the last action triggering for debounce.
  73. */
  74. ParallelView.prototype._throttledDispatchExpand = function (opt) {
  75. this._dispatchExpand(opt);
  76. };
  77. /**
  78. * @internal
  79. */
  80. ParallelView.prototype._dispatchExpand = function (opt) {
  81. opt && this._api.dispatchAction(extend({
  82. type: 'parallelAxisExpand'
  83. }, opt));
  84. };
  85. ParallelView.type = 'parallel';
  86. return ParallelView;
  87. }(ComponentView);
  88. var handlers = {
  89. mousedown: function (e) {
  90. if (checkTrigger(this, 'click')) {
  91. this._mouseDownPoint = [e.offsetX, e.offsetY];
  92. }
  93. },
  94. mouseup: function (e) {
  95. var mouseDownPoint = this._mouseDownPoint;
  96. if (checkTrigger(this, 'click') && mouseDownPoint) {
  97. var point = [e.offsetX, e.offsetY];
  98. var dist = Math.pow(mouseDownPoint[0] - point[0], 2) + Math.pow(mouseDownPoint[1] - point[1], 2);
  99. if (dist > CLICK_THRESHOLD) {
  100. return;
  101. }
  102. var result = this._model.coordinateSystem.getSlidedAxisExpandWindow([e.offsetX, e.offsetY]);
  103. result.behavior !== 'none' && this._dispatchExpand({
  104. axisExpandWindow: result.axisExpandWindow
  105. });
  106. }
  107. this._mouseDownPoint = null;
  108. },
  109. mousemove: function (e) {
  110. // Should do nothing when brushing.
  111. if (this._mouseDownPoint || !checkTrigger(this, 'mousemove')) {
  112. return;
  113. }
  114. var model = this._model;
  115. var result = model.coordinateSystem.getSlidedAxisExpandWindow([e.offsetX, e.offsetY]);
  116. var behavior = result.behavior;
  117. behavior === 'jump' && this._throttledDispatchExpand.debounceNextCall(model.get('axisExpandDebounce'));
  118. this._throttledDispatchExpand(behavior === 'none' ? null // Cancel the last trigger, in case that mouse slide out of the area quickly.
  119. : {
  120. axisExpandWindow: result.axisExpandWindow,
  121. // Jumping uses animation, and sliding suppresses animation.
  122. animation: behavior === 'jump' ? null : {
  123. duration: 0 // Disable animation.
  124. }
  125. });
  126. }
  127. };
  128. function checkTrigger(view, triggerOn) {
  129. var model = view._model;
  130. return model.get('axisExpandable') && model.get('axisExpandTriggerOn') === triggerOn;
  131. }
  132. export default ParallelView;