InsideZoomView.js 7.8 KB

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