ParallelView.js 4.9 KB

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