InsideZoomView.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 DataZoomView from './DataZoomView.js';
  42. import sliderMove from '../helper/sliderMove.js';
  43. import * as roams from './roams.js';
  44. import { bind } from 'zrender/lib/core/util.js';
  45. var InsideZoomView = /** @class */function (_super) {
  46. __extends(InsideZoomView, _super);
  47. function InsideZoomView() {
  48. var _this = _super !== null && _super.apply(this, arguments) || this;
  49. _this.type = 'dataZoom.inside';
  50. return _this;
  51. }
  52. InsideZoomView.prototype.render = function (dataZoomModel, ecModel, api) {
  53. _super.prototype.render.apply(this, arguments);
  54. if (dataZoomModel.noTarget()) {
  55. this._clear();
  56. return;
  57. }
  58. // Hence the `throttle` util ensures to preserve command order,
  59. // here simply updating range all the time will not cause missing
  60. // any of the the roam change.
  61. this.range = dataZoomModel.getPercentRange();
  62. // Reset controllers.
  63. roams.setViewInfoToCoordSysRecord(api, dataZoomModel, {
  64. pan: bind(getRangeHandlers.pan, this),
  65. zoom: bind(getRangeHandlers.zoom, this),
  66. scrollMove: bind(getRangeHandlers.scrollMove, this)
  67. });
  68. };
  69. InsideZoomView.prototype.dispose = function () {
  70. this._clear();
  71. _super.prototype.dispose.apply(this, arguments);
  72. };
  73. InsideZoomView.prototype._clear = function () {
  74. roams.disposeCoordSysRecordIfNeeded(this.api, this.dataZoomModel);
  75. this.range = null;
  76. };
  77. InsideZoomView.type = 'dataZoom.inside';
  78. return InsideZoomView;
  79. }(DataZoomView);
  80. var getRangeHandlers = {
  81. zoom: function (coordSysInfo, coordSysMainType, controller, e) {
  82. var lastRange = this.range;
  83. var range = lastRange.slice();
  84. // Calculate transform by the first axis.
  85. var axisModel = coordSysInfo.axisModels[0];
  86. if (!axisModel) {
  87. return;
  88. }
  89. var directionInfo = getDirectionInfo[coordSysMainType](null, [e.originX, e.originY], axisModel, controller, coordSysInfo);
  90. var percentPoint = (directionInfo.signal > 0 ? directionInfo.pixelStart + directionInfo.pixelLength - directionInfo.pixel : directionInfo.pixel - directionInfo.pixelStart) / directionInfo.pixelLength * (range[1] - range[0]) + range[0];
  91. var scale = Math.max(1 / e.scale, 0);
  92. range[0] = (range[0] - percentPoint) * scale + percentPoint;
  93. range[1] = (range[1] - percentPoint) * scale + percentPoint;
  94. // Restrict range.
  95. var minMaxSpan = this.dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  96. sliderMove(0, range, [0, 100], 0, minMaxSpan.minSpan, minMaxSpan.maxSpan);
  97. this.range = range;
  98. if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) {
  99. return range;
  100. }
  101. },
  102. pan: makeMover(function (range, axisModel, coordSysInfo, coordSysMainType, controller, e) {
  103. var directionInfo = getDirectionInfo[coordSysMainType]([e.oldX, e.oldY], [e.newX, e.newY], axisModel, controller, coordSysInfo);
  104. return directionInfo.signal * (range[1] - range[0]) * directionInfo.pixel / directionInfo.pixelLength;
  105. }),
  106. scrollMove: makeMover(function (range, axisModel, coordSysInfo, coordSysMainType, controller, e) {
  107. var directionInfo = getDirectionInfo[coordSysMainType]([0, 0], [e.scrollDelta, e.scrollDelta], axisModel, controller, coordSysInfo);
  108. return directionInfo.signal * (range[1] - range[0]) * e.scrollDelta;
  109. })
  110. };
  111. function makeMover(getPercentDelta) {
  112. return function (coordSysInfo, coordSysMainType, controller, e) {
  113. var lastRange = this.range;
  114. var range = lastRange.slice();
  115. // Calculate transform by the first axis.
  116. var axisModel = coordSysInfo.axisModels[0];
  117. if (!axisModel) {
  118. return;
  119. }
  120. var percentDelta = getPercentDelta(range, axisModel, coordSysInfo, coordSysMainType, controller, e);
  121. sliderMove(percentDelta, range, [0, 100], 'all');
  122. this.range = range;
  123. if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) {
  124. return range;
  125. }
  126. };
  127. }
  128. var getDirectionInfo = {
  129. grid: function (oldPoint, newPoint, axisModel, controller, coordSysInfo) {
  130. var axis = axisModel.axis;
  131. var ret = {};
  132. var rect = coordSysInfo.model.coordinateSystem.getRect();
  133. oldPoint = oldPoint || [0, 0];
  134. if (axis.dim === 'x') {
  135. ret.pixel = newPoint[0] - oldPoint[0];
  136. ret.pixelLength = rect.width;
  137. ret.pixelStart = rect.x;
  138. ret.signal = axis.inverse ? 1 : -1;
  139. } else {
  140. // axis.dim === 'y'
  141. ret.pixel = newPoint[1] - oldPoint[1];
  142. ret.pixelLength = rect.height;
  143. ret.pixelStart = rect.y;
  144. ret.signal = axis.inverse ? -1 : 1;
  145. }
  146. return ret;
  147. },
  148. polar: function (oldPoint, newPoint, axisModel, controller, coordSysInfo) {
  149. var axis = axisModel.axis;
  150. var ret = {};
  151. var polar = coordSysInfo.model.coordinateSystem;
  152. var radiusExtent = polar.getRadiusAxis().getExtent();
  153. var angleExtent = polar.getAngleAxis().getExtent();
  154. oldPoint = oldPoint ? polar.pointToCoord(oldPoint) : [0, 0];
  155. newPoint = polar.pointToCoord(newPoint);
  156. if (axisModel.mainType === 'radiusAxis') {
  157. ret.pixel = newPoint[0] - oldPoint[0];
  158. // ret.pixelLength = Math.abs(radiusExtent[1] - radiusExtent[0]);
  159. // ret.pixelStart = Math.min(radiusExtent[0], radiusExtent[1]);
  160. ret.pixelLength = radiusExtent[1] - radiusExtent[0];
  161. ret.pixelStart = radiusExtent[0];
  162. ret.signal = axis.inverse ? 1 : -1;
  163. } else {
  164. // 'angleAxis'
  165. ret.pixel = newPoint[1] - oldPoint[1];
  166. // ret.pixelLength = Math.abs(angleExtent[1] - angleExtent[0]);
  167. // ret.pixelStart = Math.min(angleExtent[0], angleExtent[1]);
  168. ret.pixelLength = angleExtent[1] - angleExtent[0];
  169. ret.pixelStart = angleExtent[0];
  170. ret.signal = axis.inverse ? -1 : 1;
  171. }
  172. return ret;
  173. },
  174. singleAxis: function (oldPoint, newPoint, axisModel, controller, coordSysInfo) {
  175. var axis = axisModel.axis;
  176. var rect = coordSysInfo.model.coordinateSystem.getRect();
  177. var ret = {};
  178. oldPoint = oldPoint || [0, 0];
  179. if (axis.orient === 'horizontal') {
  180. ret.pixel = newPoint[0] - oldPoint[0];
  181. ret.pixelLength = rect.width;
  182. ret.pixelStart = rect.x;
  183. ret.signal = axis.inverse ? 1 : -1;
  184. } else {
  185. // 'vertical'
  186. ret.pixel = newPoint[1] - oldPoint[1];
  187. ret.pixelLength = rect.height;
  188. ret.pixelStart = rect.y;
  189. ret.signal = axis.inverse ? -1 : 1;
  190. }
  191. return ret;
  192. }
  193. };
  194. export default InsideZoomView;