123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- import * as zrUtil from 'zrender/lib/core/util.js';
- import * as numberUtil from '../../util/number.js';
- import sliderMove from '../helper/sliderMove.js';
- import { unionAxisExtentFromData } from '../../coord/axisHelper.js';
- import { ensureScaleRawExtentInfo } from '../../coord/scaleRawExtentInfo.js';
- import { getAxisMainType, isCoordSupported } from './helper.js';
- import { SINGLE_REFERRING } from '../../util/model.js';
- var each = zrUtil.each;
- var asc = numberUtil.asc;
- var AxisProxy = function () {
- function AxisProxy(dimName, axisIndex, dataZoomModel, ecModel) {
- this._dimName = dimName;
- this._axisIndex = axisIndex;
- this.ecModel = ecModel;
- this._dataZoomModel = dataZoomModel;
-
-
-
-
-
- }
-
- AxisProxy.prototype.hostedBy = function (dataZoomModel) {
- return this._dataZoomModel === dataZoomModel;
- };
-
- AxisProxy.prototype.getDataValueWindow = function () {
- return this._valueWindow.slice();
- };
-
- AxisProxy.prototype.getDataPercentWindow = function () {
- return this._percentWindow.slice();
- };
- AxisProxy.prototype.getTargetSeriesModels = function () {
- var seriesModels = [];
- this.ecModel.eachSeries(function (seriesModel) {
- if (isCoordSupported(seriesModel)) {
- var axisMainType = getAxisMainType(this._dimName);
- var axisModel = seriesModel.getReferringComponents(axisMainType, SINGLE_REFERRING).models[0];
- if (axisModel && this._axisIndex === axisModel.componentIndex) {
- seriesModels.push(seriesModel);
- }
- }
- }, this);
- return seriesModels;
- };
- AxisProxy.prototype.getAxisModel = function () {
- return this.ecModel.getComponent(this._dimName + 'Axis', this._axisIndex);
- };
- AxisProxy.prototype.getMinMaxSpan = function () {
- return zrUtil.clone(this._minMaxSpan);
- };
-
- AxisProxy.prototype.calculateDataWindow = function (opt) {
- var dataExtent = this._dataExtent;
- var axisModel = this.getAxisModel();
- var scale = axisModel.axis.scale;
- var rangePropMode = this._dataZoomModel.getRangePropMode();
- var percentExtent = [0, 100];
- var percentWindow = [];
- var valueWindow = [];
- var hasPropModeValue;
- each(['start', 'end'], function (prop, idx) {
- var boundPercent = opt[prop];
- var boundValue = opt[prop + 'Value'];
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (rangePropMode[idx] === 'percent') {
- boundPercent == null && (boundPercent = percentExtent[idx]);
-
- boundValue = scale.parse(numberUtil.linearMap(boundPercent, percentExtent, dataExtent));
- } else {
- hasPropModeValue = true;
- boundValue = boundValue == null ? dataExtent[idx] : scale.parse(boundValue);
-
-
-
- boundPercent = numberUtil.linearMap(boundValue, dataExtent, percentExtent);
- }
-
-
-
- valueWindow[idx] = boundValue == null || isNaN(boundValue) ? dataExtent[idx] : boundValue;
- percentWindow[idx] = boundPercent == null || isNaN(boundPercent) ? percentExtent[idx] : boundPercent;
- });
- asc(valueWindow);
- asc(percentWindow);
-
-
-
-
-
- var spans = this._minMaxSpan;
- hasPropModeValue ? restrictSet(valueWindow, percentWindow, dataExtent, percentExtent, false) : restrictSet(percentWindow, valueWindow, percentExtent, dataExtent, true);
- function restrictSet(fromWindow, toWindow, fromExtent, toExtent, toValue) {
- var suffix = toValue ? 'Span' : 'ValueSpan';
- sliderMove(0, fromWindow, fromExtent, 'all', spans['min' + suffix], spans['max' + suffix]);
- for (var i = 0; i < 2; i++) {
- toWindow[i] = numberUtil.linearMap(fromWindow[i], fromExtent, toExtent, true);
- toValue && (toWindow[i] = scale.parse(toWindow[i]));
- }
- }
- return {
- valueWindow: valueWindow,
- percentWindow: percentWindow
- };
- };
-
- AxisProxy.prototype.reset = function (dataZoomModel) {
- if (dataZoomModel !== this._dataZoomModel) {
- return;
- }
- var targetSeries = this.getTargetSeriesModels();
-
- this._dataExtent = calculateDataExtent(this, this._dimName, targetSeries);
-
- this._updateMinMaxSpan();
- var dataWindow = this.calculateDataWindow(dataZoomModel.settledOption);
- this._valueWindow = dataWindow.valueWindow;
- this._percentWindow = dataWindow.percentWindow;
-
- this._setAxisModel();
- };
- AxisProxy.prototype.filterData = function (dataZoomModel, api) {
- if (dataZoomModel !== this._dataZoomModel) {
- return;
- }
- var axisDim = this._dimName;
- var seriesModels = this.getTargetSeriesModels();
- var filterMode = dataZoomModel.get('filterMode');
- var valueWindow = this._valueWindow;
- if (filterMode === 'none') {
- return;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- each(seriesModels, function (seriesModel) {
- var seriesData = seriesModel.getData();
- var dataDims = seriesData.mapDimensionsAll(axisDim);
- if (!dataDims.length) {
- return;
- }
- if (filterMode === 'weakFilter') {
- var store_1 = seriesData.getStore();
- var dataDimIndices_1 = zrUtil.map(dataDims, function (dim) {
- return seriesData.getDimensionIndex(dim);
- }, seriesData);
- seriesData.filterSelf(function (dataIndex) {
- var leftOut;
- var rightOut;
- var hasValue;
- for (var i = 0; i < dataDims.length; i++) {
- var value = store_1.get(dataDimIndices_1[i], dataIndex);
- var thisHasValue = !isNaN(value);
- var thisLeftOut = value < valueWindow[0];
- var thisRightOut = value > valueWindow[1];
- if (thisHasValue && !thisLeftOut && !thisRightOut) {
- return true;
- }
- thisHasValue && (hasValue = true);
- thisLeftOut && (leftOut = true);
- thisRightOut && (rightOut = true);
- }
-
- return hasValue && leftOut && rightOut;
- });
- } else {
- each(dataDims, function (dim) {
- if (filterMode === 'empty') {
- seriesModel.setData(seriesData = seriesData.map(dim, function (value) {
- return !isInWindow(value) ? NaN : value;
- }));
- } else {
- var range = {};
- range[dim] = valueWindow;
-
- seriesData.selectRange(range);
-
- }
- });
- }
- each(dataDims, function (dim) {
- seriesData.setApproximateExtent(valueWindow, dim);
- });
- });
- function isInWindow(value) {
- return value >= valueWindow[0] && value <= valueWindow[1];
- }
- };
- AxisProxy.prototype._updateMinMaxSpan = function () {
- var minMaxSpan = this._minMaxSpan = {};
- var dataZoomModel = this._dataZoomModel;
- var dataExtent = this._dataExtent;
- each(['min', 'max'], function (minMax) {
- var percentSpan = dataZoomModel.get(minMax + 'Span');
- var valueSpan = dataZoomModel.get(minMax + 'ValueSpan');
- valueSpan != null && (valueSpan = this.getAxisModel().axis.scale.parse(valueSpan));
-
- if (valueSpan != null) {
- percentSpan = numberUtil.linearMap(dataExtent[0] + valueSpan, dataExtent, [0, 100], true);
- } else if (percentSpan != null) {
- valueSpan = numberUtil.linearMap(percentSpan, [0, 100], dataExtent, true) - dataExtent[0];
- }
- minMaxSpan[minMax + 'Span'] = percentSpan;
- minMaxSpan[minMax + 'ValueSpan'] = valueSpan;
- }, this);
- };
- AxisProxy.prototype._setAxisModel = function () {
- var axisModel = this.getAxisModel();
- var percentWindow = this._percentWindow;
- var valueWindow = this._valueWindow;
- if (!percentWindow) {
- return;
- }
-
- var precision = numberUtil.getPixelPrecision(valueWindow, [0, 500]);
- precision = Math.min(precision, 20);
-
-
-
-
- var rawExtentInfo = axisModel.axis.scale.rawExtentInfo;
- if (percentWindow[0] !== 0) {
- rawExtentInfo.setDeterminedMinMax('min', +valueWindow[0].toFixed(precision));
- }
- if (percentWindow[1] !== 100) {
- rawExtentInfo.setDeterminedMinMax('max', +valueWindow[1].toFixed(precision));
- }
- rawExtentInfo.freeze();
- };
- return AxisProxy;
- }();
- function calculateDataExtent(axisProxy, axisDim, seriesModels) {
- var dataExtent = [Infinity, -Infinity];
- each(seriesModels, function (seriesModel) {
- unionAxisExtentFromData(dataExtent, seriesModel.getData(), axisDim);
- });
-
-
-
-
-
-
-
-
-
- var axisModel = axisProxy.getAxisModel();
- var rawExtentResult = ensureScaleRawExtentInfo(axisModel.axis.scale, axisModel, dataExtent).calculate();
- return [rawExtentResult.min, rawExtentResult.max];
- }
- export default AxisProxy;
|