UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

143 lines (142 loc) 5.84 kB
import { __extends } from "../../../../tslib/tslib.es6.mjs"; import DataZoomView from "./DataZoomView.mjs"; import sliderMove from "../helper/sliderMove.mjs"; import { setViewInfoToCoordSysRecord, disposeCoordSysRecordIfNeeded } from "./roams.mjs"; import { bind } from "../../../../zrender/lib/core/util.mjs"; var InsideZoomView = function(_super) { __extends(InsideZoomView2, _super); function InsideZoomView2() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.type = "dataZoom.inside"; return _this; } InsideZoomView2.prototype.render = function(dataZoomModel, ecModel, api) { _super.prototype.render.apply(this, arguments); if (dataZoomModel.noTarget()) { this._clear(); return; } this.range = dataZoomModel.getPercentRange(); setViewInfoToCoordSysRecord(api, dataZoomModel, { pan: bind(getRangeHandlers.pan, this), zoom: bind(getRangeHandlers.zoom, this), scrollMove: bind(getRangeHandlers.scrollMove, this) }); }; InsideZoomView2.prototype.dispose = function() { this._clear(); _super.prototype.dispose.apply(this, arguments); }; InsideZoomView2.prototype._clear = function() { disposeCoordSysRecordIfNeeded(this.api, this.dataZoomModel); this.range = null; }; InsideZoomView2.type = "dataZoom.inside"; return InsideZoomView2; }(DataZoomView); var getRangeHandlers = { zoom: function(coordSysInfo, coordSysMainType, controller, e) { var lastRange = this.range; var range = lastRange.slice(); var axisModel = coordSysInfo.axisModels[0]; if (!axisModel) { return; } var directionInfo = getDirectionInfo[coordSysMainType](null, [e.originX, e.originY], axisModel, controller, coordSysInfo); var percentPoint = (directionInfo.signal > 0 ? directionInfo.pixelStart + directionInfo.pixelLength - directionInfo.pixel : directionInfo.pixel - directionInfo.pixelStart) / directionInfo.pixelLength * (range[1] - range[0]) + range[0]; var scale = Math.max(1 / e.scale, 0); range[0] = (range[0] - percentPoint) * scale + percentPoint; range[1] = (range[1] - percentPoint) * scale + percentPoint; var minMaxSpan = this.dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan(); sliderMove(0, range, [0, 100], 0, minMaxSpan.minSpan, minMaxSpan.maxSpan); this.range = range; if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) { return range; } }, pan: makeMover(function(range, axisModel, coordSysInfo, coordSysMainType, controller, e) { var directionInfo = getDirectionInfo[coordSysMainType]([e.oldX, e.oldY], [e.newX, e.newY], axisModel, controller, coordSysInfo); return directionInfo.signal * (range[1] - range[0]) * directionInfo.pixel / directionInfo.pixelLength; }), scrollMove: makeMover(function(range, axisModel, coordSysInfo, coordSysMainType, controller, e) { var directionInfo = getDirectionInfo[coordSysMainType]([0, 0], [e.scrollDelta, e.scrollDelta], axisModel, controller, coordSysInfo); return directionInfo.signal * (range[1] - range[0]) * e.scrollDelta; }) }; function makeMover(getPercentDelta) { return function(coordSysInfo, coordSysMainType, controller, e) { var lastRange = this.range; var range = lastRange.slice(); var axisModel = coordSysInfo.axisModels[0]; if (!axisModel) { return; } var percentDelta = getPercentDelta(range, axisModel, coordSysInfo, coordSysMainType, controller, e); sliderMove(percentDelta, range, [0, 100], "all"); this.range = range; if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) { return range; } }; } var getDirectionInfo = { grid: function(oldPoint, newPoint, axisModel, controller, coordSysInfo) { var axis = axisModel.axis; var ret = {}; var rect = coordSysInfo.model.coordinateSystem.getRect(); oldPoint = oldPoint || [0, 0]; if (axis.dim === "x") { ret.pixel = newPoint[0] - oldPoint[0]; ret.pixelLength = rect.width; ret.pixelStart = rect.x; ret.signal = axis.inverse ? 1 : -1; } else { ret.pixel = newPoint[1] - oldPoint[1]; ret.pixelLength = rect.height; ret.pixelStart = rect.y; ret.signal = axis.inverse ? -1 : 1; } return ret; }, polar: function(oldPoint, newPoint, axisModel, controller, coordSysInfo) { var axis = axisModel.axis; var ret = {}; var polar = coordSysInfo.model.coordinateSystem; var radiusExtent = polar.getRadiusAxis().getExtent(); var angleExtent = polar.getAngleAxis().getExtent(); oldPoint = oldPoint ? polar.pointToCoord(oldPoint) : [0, 0]; newPoint = polar.pointToCoord(newPoint); if (axisModel.mainType === "radiusAxis") { ret.pixel = newPoint[0] - oldPoint[0]; ret.pixelLength = radiusExtent[1] - radiusExtent[0]; ret.pixelStart = radiusExtent[0]; ret.signal = axis.inverse ? 1 : -1; } else { ret.pixel = newPoint[1] - oldPoint[1]; ret.pixelLength = angleExtent[1] - angleExtent[0]; ret.pixelStart = angleExtent[0]; ret.signal = axis.inverse ? -1 : 1; } return ret; }, singleAxis: function(oldPoint, newPoint, axisModel, controller, coordSysInfo) { var axis = axisModel.axis; var rect = coordSysInfo.model.coordinateSystem.getRect(); var ret = {}; oldPoint = oldPoint || [0, 0]; if (axis.orient === "horizontal") { ret.pixel = newPoint[0] - oldPoint[0]; ret.pixelLength = rect.width; ret.pixelStart = rect.x; ret.signal = axis.inverse ? 1 : -1; } else { ret.pixel = newPoint[1] - oldPoint[1]; ret.pixelLength = rect.height; ret.pixelStart = rect.y; ret.signal = axis.inverse ? -1 : 1; } return ret; } }; var InsideZoomView$1 = InsideZoomView; export { InsideZoomView$1 as default };