123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632 |
- var _config = require("../../config");
- var __DEV__ = _config.__DEV__;
- var echarts = require("../../echarts");
- var zrUtil = require("zrender/lib/core/util");
- var env = require("zrender/lib/core/env");
- var modelUtil = require("../../util/model");
- var helper = require("./helper");
- var AxisProxy = require("./AxisProxy");
- var each = zrUtil.each;
- var eachAxisDim = helper.eachAxisDim;
- var DataZoomModel = echarts.extendComponentModel({
- type: 'dataZoom',
- dependencies: ['xAxis', 'yAxis', 'zAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'series'],
-
- defaultOption: {
- zlevel: 0,
- z: 4,
-
- orient: null,
-
- xAxisIndex: null,
-
- yAxisIndex: null,
-
- filterMode: 'filter',
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- throttle: null,
-
-
-
-
- start: 0,
-
- end: 100,
-
- startValue: null,
-
- endValue: null,
-
- minSpan: null,
-
- maxSpan: null,
-
- minValueSpan: null,
-
- maxValueSpan: null,
-
- rangeMode: null
- },
-
- init: function (option, parentModel, ecModel) {
-
- this._dataIntervalByAxis = {};
-
- this._dataInfo = {};
-
- this._axisProxies = {};
-
- this.textStyleModel;
-
- this._autoThrottle = true;
-
- this._rangePropMode = ['percent', 'percent'];
- var inputRawOption = retrieveRawOption(option);
-
- this.settledOption = inputRawOption;
- this.mergeDefaultAndTheme(option, ecModel);
- this.doInit(inputRawOption);
- },
-
- mergeOption: function (newOption) {
- var inputRawOption = retrieveRawOption(newOption);
- zrUtil.merge(this.option, newOption, true);
- zrUtil.merge(this.settledOption, inputRawOption, true);
- this.doInit(inputRawOption);
- },
-
- doInit: function (inputRawOption) {
- var thisOption = this.option;
- if (!env.canvasSupported) {
- thisOption.realtime = false;
- }
- this._setDefaultThrottle(inputRawOption);
- updateRangeUse(this, inputRawOption);
- var settledOption = this.settledOption;
- each([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
-
-
-
- if (this._rangePropMode[index] === 'value') {
- thisOption[names[0]] = settledOption[names[0]] = null;
- }
- }, this);
- this.textStyleModel = this.getModel('textStyle');
- this._resetTarget();
- this._giveAxisProxies();
- },
-
- _giveAxisProxies: function () {
- var axisProxies = this._axisProxies;
- this.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel, ecModel) {
- var axisModel = this.dependentModels[dimNames.axis][axisIndex];
- var axisProxy = axisModel.__dzAxisProxy || (
- axisModel.__dzAxisProxy = new AxisProxy(dimNames.name, axisIndex, this, ecModel));
-
- axisProxies[dimNames.name + '_' + axisIndex] = axisProxy;
- }, this);
- },
-
- _resetTarget: function () {
- var thisOption = this.option;
- var autoMode = this._judgeAutoMode();
- eachAxisDim(function (dimNames) {
- var axisIndexName = dimNames.axisIndex;
- thisOption[axisIndexName] = modelUtil.normalizeToArray(thisOption[axisIndexName]);
- }, this);
- if (autoMode === 'axisIndex') {
- this._autoSetAxisIndex();
- } else if (autoMode === 'orient') {
- this._autoSetOrient();
- }
- },
-
- _judgeAutoMode: function () {
-
-
-
- var thisOption = this.option;
- var hasIndexSpecified = false;
- eachAxisDim(function (dimNames) {
-
-
-
- if (thisOption[dimNames.axisIndex] != null) {
- hasIndexSpecified = true;
- }
- }, this);
- var orient = thisOption.orient;
- if (orient == null && hasIndexSpecified) {
- return 'orient';
- } else if (!hasIndexSpecified) {
- if (orient == null) {
- thisOption.orient = 'horizontal';
- }
- return 'axisIndex';
- }
- },
-
- _autoSetAxisIndex: function () {
- var autoAxisIndex = true;
- var orient = this.get('orient', true);
- var thisOption = this.option;
- var dependentModels = this.dependentModels;
- if (autoAxisIndex) {
-
- var dimName = orient === 'vertical' ? 'y' : 'x';
- if (dependentModels[dimName + 'Axis'].length) {
- thisOption[dimName + 'AxisIndex'] = [0];
- autoAxisIndex = false;
- } else {
- each(dependentModels.singleAxis, function (singleAxisModel) {
- if (autoAxisIndex && singleAxisModel.get('orient', true) === orient) {
- thisOption.singleAxisIndex = [singleAxisModel.componentIndex];
- autoAxisIndex = false;
- }
- });
- }
- }
- if (autoAxisIndex) {
-
- eachAxisDim(function (dimNames) {
- if (!autoAxisIndex) {
- return;
- }
- var axisIndices = [];
- var axisModels = this.dependentModels[dimNames.axis];
- if (axisModels.length && !axisIndices.length) {
- for (var i = 0, len = axisModels.length; i < len; i++) {
- if (axisModels[i].get('type') === 'category') {
- axisIndices.push(i);
- }
- }
- }
- thisOption[dimNames.axisIndex] = axisIndices;
- if (axisIndices.length) {
- autoAxisIndex = false;
- }
- }, this);
- }
- if (autoAxisIndex) {
-
-
-
-
-
-
- this.ecModel.eachSeries(function (seriesModel) {
- if (this._isSeriesHasAllAxesTypeOf(seriesModel, 'value')) {
- eachAxisDim(function (dimNames) {
- var axisIndices = thisOption[dimNames.axisIndex];
- var axisIndex = seriesModel.get(dimNames.axisIndex);
- var axisId = seriesModel.get(dimNames.axisId);
- var axisModel = seriesModel.ecModel.queryComponents({
- mainType: dimNames.axis,
- index: axisIndex,
- id: axisId
- })[0];
- axisIndex = axisModel.componentIndex;
- if (zrUtil.indexOf(axisIndices, axisIndex) < 0) {
- axisIndices.push(axisIndex);
- }
- });
- }
- }, this);
- }
- },
-
- _autoSetOrient: function () {
- var dim;
- this.eachTargetAxis(function (dimNames) {
- !dim && (dim = dimNames.name);
- }, this);
- this.option.orient = dim === 'y' ? 'vertical' : 'horizontal';
- },
-
- _isSeriesHasAllAxesTypeOf: function (seriesModel, axisType) {
-
-
-
- var is = true;
- eachAxisDim(function (dimNames) {
- var seriesAxisIndex = seriesModel.get(dimNames.axisIndex);
- var axisModel = this.dependentModels[dimNames.axis][seriesAxisIndex];
- if (!axisModel || axisModel.get('type') !== axisType) {
- is = false;
- }
- }, this);
- return is;
- },
-
- _setDefaultThrottle: function (inputRawOption) {
-
- if (inputRawOption.hasOwnProperty('throttle')) {
- this._autoThrottle = false;
- }
- if (this._autoThrottle) {
- var globalOption = this.ecModel.option;
- this.option.throttle = globalOption.animation && globalOption.animationDurationUpdate > 0 ? 100 : 20;
- }
- },
-
- getFirstTargetAxisModel: function () {
- var firstAxisModel;
- eachAxisDim(function (dimNames) {
- if (firstAxisModel == null) {
- var indices = this.get(dimNames.axisIndex);
- if (indices.length) {
- firstAxisModel = this.dependentModels[dimNames.axis][indices[0]];
- }
- }
- }, this);
- return firstAxisModel;
- },
-
- eachTargetAxis: function (callback, context) {
- var ecModel = this.ecModel;
- eachAxisDim(function (dimNames) {
- each(this.get(dimNames.axisIndex), function (axisIndex) {
- callback.call(context, dimNames, axisIndex, this, ecModel);
- }, this);
- }, this);
- },
-
- getAxisProxy: function (dimName, axisIndex) {
- return this._axisProxies[dimName + '_' + axisIndex];
- },
-
- getAxisModel: function (dimName, axisIndex) {
- var axisProxy = this.getAxisProxy(dimName, axisIndex);
- return axisProxy && axisProxy.getAxisModel();
- },
-
- setRawRange: function (opt) {
- var thisOption = this.option;
- var settledOption = this.settledOption;
- each([['start', 'startValue'], ['end', 'endValue']], function (names) {
-
-
-
-
-
-
-
-
-
- if (opt[names[0]] != null || opt[names[1]] != null) {
- thisOption[names[0]] = settledOption[names[0]] = opt[names[0]];
- thisOption[names[1]] = settledOption[names[1]] = opt[names[1]];
- }
- }, this);
- updateRangeUse(this, opt);
- },
-
- setCalculatedRange: function (opt) {
- var option = this.option;
- each(['start', 'startValue', 'end', 'endValue'], function (name) {
- option[name] = opt[name];
- });
- },
-
- getPercentRange: function () {
- var axisProxy = this.findRepresentativeAxisProxy();
- if (axisProxy) {
- return axisProxy.getDataPercentWindow();
- }
- },
-
- getValueRange: function (axisDimName, axisIndex) {
- if (axisDimName == null && axisIndex == null) {
- var axisProxy = this.findRepresentativeAxisProxy();
- if (axisProxy) {
- return axisProxy.getDataValueWindow();
- }
- } else {
- return this.getAxisProxy(axisDimName, axisIndex).getDataValueWindow();
- }
- },
-
- findRepresentativeAxisProxy: function (axisModel) {
- if (axisModel) {
- return axisModel.__dzAxisProxy;
- }
- var axisProxies = this._axisProxies;
- for (var key in axisProxies) {
- if (axisProxies.hasOwnProperty(key) && axisProxies[key].hostedBy(this)) {
- return axisProxies[key];
- }
- }
-
-
-
-
- for (var key in axisProxies) {
- if (axisProxies.hasOwnProperty(key) && !axisProxies[key].hostedBy(this)) {
- return axisProxies[key];
- }
- }
- },
-
- getRangePropMode: function () {
- return this._rangePropMode.slice();
- }
- });
- function retrieveRawOption(option) {
- var ret = {};
- each(['start', 'end', 'startValue', 'endValue', 'throttle'], function (name) {
- option.hasOwnProperty(name) && (ret[name] = option[name]);
- });
- return ret;
- }
- function updateRangeUse(dataZoomModel, inputRawOption) {
- var rangePropMode = dataZoomModel._rangePropMode;
- var rangeModeInOption = dataZoomModel.get('rangeMode');
- each([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
- var percentSpecified = inputRawOption[names[0]] != null;
- var valueSpecified = inputRawOption[names[1]] != null;
- if (percentSpecified && !valueSpecified) {
- rangePropMode[index] = 'percent';
- } else if (!percentSpecified && valueSpecified) {
- rangePropMode[index] = 'value';
- } else if (rangeModeInOption) {
- rangePropMode[index] = rangeModeInOption[index];
- } else if (percentSpecified) {
-
- rangePropMode[index] = 'percent';
- }
- });
- }
- var _default = DataZoomModel;
- module.exports = _default;
|