Series.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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 * as zrUtil from 'zrender/lib/core/util.js';
  42. import env from 'zrender/lib/core/env.js';
  43. import * as modelUtil from '../util/model.js';
  44. import ComponentModel from './Component.js';
  45. import { PaletteMixin } from './mixin/palette.js';
  46. import { DataFormatMixin } from '../model/mixin/dataFormat.js';
  47. import { getLayoutParams, mergeLayoutParam, fetchLayoutMode } from '../util/layout.js';
  48. import { createTask } from '../core/task.js';
  49. import { mountExtend } from '../util/clazz.js';
  50. import { SourceManager } from '../data/helper/sourceManager.js';
  51. import { defaultSeriesFormatTooltip } from '../component/tooltip/seriesFormatTooltip.js';
  52. var inner = modelUtil.makeInner();
  53. function getSelectionKey(data, dataIndex) {
  54. return data.getName(dataIndex) || data.getId(dataIndex);
  55. }
  56. export var SERIES_UNIVERSAL_TRANSITION_PROP = '__universalTransitionEnabled';
  57. var SeriesModel = /** @class */function (_super) {
  58. __extends(SeriesModel, _super);
  59. function SeriesModel() {
  60. // [Caution]: Because this class or desecendants can be used as `XXX.extend(subProto)`,
  61. // the class members must not be initialized in constructor or declaration place.
  62. // Otherwise there is bad case:
  63. // class A {xxx = 1;}
  64. // enableClassExtend(A);
  65. // class B extends A {}
  66. // var C = B.extend({xxx: 5});
  67. // var c = new C();
  68. // console.log(c.xxx); // expect 5 but always 1.
  69. var _this = _super !== null && _super.apply(this, arguments) || this;
  70. // ---------------------------------------
  71. // Props about data selection
  72. // ---------------------------------------
  73. _this._selectedDataIndicesMap = {};
  74. return _this;
  75. }
  76. SeriesModel.prototype.init = function (option, parentModel, ecModel) {
  77. this.seriesIndex = this.componentIndex;
  78. this.dataTask = createTask({
  79. count: dataTaskCount,
  80. reset: dataTaskReset
  81. });
  82. this.dataTask.context = {
  83. model: this
  84. };
  85. this.mergeDefaultAndTheme(option, ecModel);
  86. var sourceManager = inner(this).sourceManager = new SourceManager(this);
  87. sourceManager.prepareSource();
  88. var data = this.getInitialData(option, ecModel);
  89. wrapData(data, this);
  90. this.dataTask.context.data = data;
  91. if (process.env.NODE_ENV !== 'production') {
  92. zrUtil.assert(data, 'getInitialData returned invalid data.');
  93. }
  94. inner(this).dataBeforeProcessed = data;
  95. // If we reverse the order (make data firstly, and then make
  96. // dataBeforeProcessed by cloneShallow), cloneShallow will
  97. // cause data.graph.data !== data when using
  98. // module:echarts/data/Graph or module:echarts/data/Tree.
  99. // See module:echarts/data/helper/linkSeriesData
  100. // Theoretically, it is unreasonable to call `seriesModel.getData()` in the model
  101. // init or merge stage, because the data can be restored. So we do not `restoreData`
  102. // and `setData` here, which forbids calling `seriesModel.getData()` in this stage.
  103. // Call `seriesModel.getRawData()` instead.
  104. // this.restoreData();
  105. autoSeriesName(this);
  106. this._initSelectedMapFromData(data);
  107. };
  108. /**
  109. * Util for merge default and theme to option
  110. */
  111. SeriesModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
  112. var layoutMode = fetchLayoutMode(this);
  113. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  114. // Backward compat: using subType on theme.
  115. // But if name duplicate between series subType
  116. // (for example: parallel) add component mainType,
  117. // add suffix 'Series'.
  118. var themeSubType = this.subType;
  119. if (ComponentModel.hasClass(themeSubType)) {
  120. themeSubType += 'Series';
  121. }
  122. zrUtil.merge(option, ecModel.getTheme().get(this.subType));
  123. zrUtil.merge(option, this.getDefaultOption());
  124. // Default label emphasis `show`
  125. modelUtil.defaultEmphasis(option, 'label', ['show']);
  126. this.fillDataTextStyle(option.data);
  127. if (layoutMode) {
  128. mergeLayoutParam(option, inputPositionParams, layoutMode);
  129. }
  130. };
  131. SeriesModel.prototype.mergeOption = function (newSeriesOption, ecModel) {
  132. // this.settingTask.dirty();
  133. newSeriesOption = zrUtil.merge(this.option, newSeriesOption, true);
  134. this.fillDataTextStyle(newSeriesOption.data);
  135. var layoutMode = fetchLayoutMode(this);
  136. if (layoutMode) {
  137. mergeLayoutParam(this.option, newSeriesOption, layoutMode);
  138. }
  139. var sourceManager = inner(this).sourceManager;
  140. sourceManager.dirty();
  141. sourceManager.prepareSource();
  142. var data = this.getInitialData(newSeriesOption, ecModel);
  143. wrapData(data, this);
  144. this.dataTask.dirty();
  145. this.dataTask.context.data = data;
  146. inner(this).dataBeforeProcessed = data;
  147. autoSeriesName(this);
  148. this._initSelectedMapFromData(data);
  149. };
  150. SeriesModel.prototype.fillDataTextStyle = function (data) {
  151. // Default data label emphasis `show`
  152. // FIXME Tree structure data ?
  153. // FIXME Performance ?
  154. if (data && !zrUtil.isTypedArray(data)) {
  155. var props = ['show'];
  156. for (var i = 0; i < data.length; i++) {
  157. if (data[i] && data[i].label) {
  158. modelUtil.defaultEmphasis(data[i], 'label', props);
  159. }
  160. }
  161. }
  162. };
  163. /**
  164. * Init a data structure from data related option in series
  165. * Must be overridden.
  166. */
  167. SeriesModel.prototype.getInitialData = function (option, ecModel) {
  168. return;
  169. };
  170. /**
  171. * Append data to list
  172. */
  173. SeriesModel.prototype.appendData = function (params) {
  174. // FIXME ???
  175. // (1) If data from dataset, forbidden append.
  176. // (2) support append data of dataset.
  177. var data = this.getRawData();
  178. data.appendData(params.data);
  179. };
  180. /**
  181. * Consider some method like `filter`, `map` need make new data,
  182. * We should make sure that `seriesModel.getData()` get correct
  183. * data in the stream procedure. So we fetch data from upstream
  184. * each time `task.perform` called.
  185. */
  186. SeriesModel.prototype.getData = function (dataType) {
  187. var task = getCurrentTask(this);
  188. if (task) {
  189. var data = task.context.data;
  190. return dataType == null || !data.getLinkedData ? data : data.getLinkedData(dataType);
  191. } else {
  192. // When series is not alive (that may happen when click toolbox
  193. // restore or setOption with not merge mode), series data may
  194. // be still need to judge animation or something when graphic
  195. // elements want to know whether fade out.
  196. return inner(this).data;
  197. }
  198. };
  199. SeriesModel.prototype.getAllData = function () {
  200. var mainData = this.getData();
  201. return mainData && mainData.getLinkedDataAll ? mainData.getLinkedDataAll() : [{
  202. data: mainData
  203. }];
  204. };
  205. SeriesModel.prototype.setData = function (data) {
  206. var task = getCurrentTask(this);
  207. if (task) {
  208. var context = task.context;
  209. // Consider case: filter, data sample.
  210. // FIXME:TS never used, so comment it
  211. // if (context.data !== data && task.modifyOutputEnd) {
  212. // task.setOutputEnd(data.count());
  213. // }
  214. context.outputData = data;
  215. // Caution: setData should update context.data,
  216. // Because getData may be called multiply in a
  217. // single stage and expect to get the data just
  218. // set. (For example, AxisProxy, x y both call
  219. // getData and setDate sequentially).
  220. // So the context.data should be fetched from
  221. // upstream each time when a stage starts to be
  222. // performed.
  223. if (task !== this.dataTask) {
  224. context.data = data;
  225. }
  226. }
  227. inner(this).data = data;
  228. };
  229. SeriesModel.prototype.getEncode = function () {
  230. var encode = this.get('encode', true);
  231. if (encode) {
  232. return zrUtil.createHashMap(encode);
  233. }
  234. };
  235. SeriesModel.prototype.getSourceManager = function () {
  236. return inner(this).sourceManager;
  237. };
  238. SeriesModel.prototype.getSource = function () {
  239. return this.getSourceManager().getSource();
  240. };
  241. /**
  242. * Get data before processed
  243. */
  244. SeriesModel.prototype.getRawData = function () {
  245. return inner(this).dataBeforeProcessed;
  246. };
  247. SeriesModel.prototype.getColorBy = function () {
  248. var colorBy = this.get('colorBy');
  249. return colorBy || 'series';
  250. };
  251. SeriesModel.prototype.isColorBySeries = function () {
  252. return this.getColorBy() === 'series';
  253. };
  254. /**
  255. * Get base axis if has coordinate system and has axis.
  256. * By default use coordSys.getBaseAxis();
  257. * Can be overridden for some chart.
  258. * @return {type} description
  259. */
  260. SeriesModel.prototype.getBaseAxis = function () {
  261. var coordSys = this.coordinateSystem;
  262. // @ts-ignore
  263. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  264. };
  265. /**
  266. * Retrieve the index of nearest value in the view coordinate.
  267. * Data position is compared with each axis's dataToCoord.
  268. *
  269. * @param axisDim axis dimension
  270. * @param dim data dimension
  271. * @param value
  272. * @param [maxDistance=Infinity] The maximum distance in view coordinate space
  273. * @return If and only if multiple indices has
  274. * the same value, they are put to the result.
  275. */
  276. SeriesModel.prototype.indicesOfNearest = function (axisDim, dim, value, maxDistance) {
  277. var data = this.getData();
  278. var coordSys = this.coordinateSystem;
  279. var axis = coordSys && coordSys.getAxis(axisDim);
  280. if (!coordSys || !axis) {
  281. return [];
  282. }
  283. var targetCoord = axis.dataToCoord(value);
  284. if (maxDistance == null) {
  285. maxDistance = Infinity;
  286. }
  287. var nearestIndices = [];
  288. var minDist = Infinity;
  289. var minDiff = -1;
  290. var nearestIndicesLen = 0;
  291. data.each(dim, function (dimValue, idx) {
  292. var dataCoord = axis.dataToCoord(dimValue);
  293. var diff = targetCoord - dataCoord;
  294. var dist = Math.abs(diff);
  295. if (dist <= maxDistance) {
  296. // When the `value` is at the middle of `this.get(dim, i)` and `this.get(dim, i+1)`,
  297. // we'd better not push both of them to `nearestIndices`, otherwise it is easy to
  298. // get more than one item in `nearestIndices` (more specifically, in `tooltip`).
  299. // So we choose the one that `diff >= 0` in this case.
  300. // But if `this.get(dim, i)` and `this.get(dim, j)` get the same value, both of them
  301. // should be push to `nearestIndices`.
  302. if (dist < minDist || dist === minDist && diff >= 0 && minDiff < 0) {
  303. minDist = dist;
  304. minDiff = diff;
  305. nearestIndicesLen = 0;
  306. }
  307. if (diff === minDiff) {
  308. nearestIndices[nearestIndicesLen++] = idx;
  309. }
  310. }
  311. });
  312. nearestIndices.length = nearestIndicesLen;
  313. return nearestIndices;
  314. };
  315. /**
  316. * Default tooltip formatter
  317. *
  318. * @param dataIndex
  319. * @param multipleSeries
  320. * @param dataType
  321. * @param renderMode valid values: 'html'(by default) and 'richText'.
  322. * 'html' is used for rendering tooltip in extra DOM form, and the result
  323. * string is used as DOM HTML content.
  324. * 'richText' is used for rendering tooltip in rich text form, for those where
  325. * DOM operation is not supported.
  326. * @return formatted tooltip with `html` and `markers`
  327. * Notice: The override method can also return string
  328. */
  329. SeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  330. return defaultSeriesFormatTooltip({
  331. series: this,
  332. dataIndex: dataIndex,
  333. multipleSeries: multipleSeries
  334. });
  335. };
  336. SeriesModel.prototype.isAnimationEnabled = function () {
  337. var ecModel = this.ecModel;
  338. // Disable animation if using echarts in node but not give ssr flag.
  339. // In ssr mode, renderToString will generate svg with css animation.
  340. if (env.node && !(ecModel && ecModel.ssr)) {
  341. return false;
  342. }
  343. var animationEnabled = this.getShallow('animation');
  344. if (animationEnabled) {
  345. if (this.getData().count() > this.getShallow('animationThreshold')) {
  346. animationEnabled = false;
  347. }
  348. }
  349. return !!animationEnabled;
  350. };
  351. SeriesModel.prototype.restoreData = function () {
  352. this.dataTask.dirty();
  353. };
  354. SeriesModel.prototype.getColorFromPalette = function (name, scope, requestColorNum) {
  355. var ecModel = this.ecModel;
  356. // PENDING
  357. var color = PaletteMixin.prototype.getColorFromPalette.call(this, name, scope, requestColorNum);
  358. if (!color) {
  359. color = ecModel.getColorFromPalette(name, scope, requestColorNum);
  360. }
  361. return color;
  362. };
  363. /**
  364. * Use `data.mapDimensionsAll(coordDim)` instead.
  365. * @deprecated
  366. */
  367. SeriesModel.prototype.coordDimToDataDim = function (coordDim) {
  368. return this.getRawData().mapDimensionsAll(coordDim);
  369. };
  370. /**
  371. * Get progressive rendering count each step
  372. */
  373. SeriesModel.prototype.getProgressive = function () {
  374. return this.get('progressive');
  375. };
  376. /**
  377. * Get progressive rendering count each step
  378. */
  379. SeriesModel.prototype.getProgressiveThreshold = function () {
  380. return this.get('progressiveThreshold');
  381. };
  382. // PENGING If selectedMode is null ?
  383. SeriesModel.prototype.select = function (innerDataIndices, dataType) {
  384. this._innerSelect(this.getData(dataType), innerDataIndices);
  385. };
  386. SeriesModel.prototype.unselect = function (innerDataIndices, dataType) {
  387. var selectedMap = this.option.selectedMap;
  388. if (!selectedMap) {
  389. return;
  390. }
  391. var selectedMode = this.option.selectedMode;
  392. var data = this.getData(dataType);
  393. if (selectedMode === 'series' || selectedMap === 'all') {
  394. this.option.selectedMap = {};
  395. this._selectedDataIndicesMap = {};
  396. return;
  397. }
  398. for (var i = 0; i < innerDataIndices.length; i++) {
  399. var dataIndex = innerDataIndices[i];
  400. var nameOrId = getSelectionKey(data, dataIndex);
  401. selectedMap[nameOrId] = false;
  402. this._selectedDataIndicesMap[nameOrId] = -1;
  403. }
  404. };
  405. SeriesModel.prototype.toggleSelect = function (innerDataIndices, dataType) {
  406. var tmpArr = [];
  407. for (var i = 0; i < innerDataIndices.length; i++) {
  408. tmpArr[0] = innerDataIndices[i];
  409. this.isSelected(innerDataIndices[i], dataType) ? this.unselect(tmpArr, dataType) : this.select(tmpArr, dataType);
  410. }
  411. };
  412. SeriesModel.prototype.getSelectedDataIndices = function () {
  413. if (this.option.selectedMap === 'all') {
  414. return [].slice.call(this.getData().getIndices());
  415. }
  416. var selectedDataIndicesMap = this._selectedDataIndicesMap;
  417. var nameOrIds = zrUtil.keys(selectedDataIndicesMap);
  418. var dataIndices = [];
  419. for (var i = 0; i < nameOrIds.length; i++) {
  420. var dataIndex = selectedDataIndicesMap[nameOrIds[i]];
  421. if (dataIndex >= 0) {
  422. dataIndices.push(dataIndex);
  423. }
  424. }
  425. return dataIndices;
  426. };
  427. SeriesModel.prototype.isSelected = function (dataIndex, dataType) {
  428. var selectedMap = this.option.selectedMap;
  429. if (!selectedMap) {
  430. return false;
  431. }
  432. var data = this.getData(dataType);
  433. return (selectedMap === 'all' || selectedMap[getSelectionKey(data, dataIndex)]) && !data.getItemModel(dataIndex).get(['select', 'disabled']);
  434. };
  435. SeriesModel.prototype.isUniversalTransitionEnabled = function () {
  436. if (this[SERIES_UNIVERSAL_TRANSITION_PROP]) {
  437. return true;
  438. }
  439. var universalTransitionOpt = this.option.universalTransition;
  440. // Quick reject
  441. if (!universalTransitionOpt) {
  442. return false;
  443. }
  444. if (universalTransitionOpt === true) {
  445. return true;
  446. }
  447. // Can be simply 'universalTransition: true'
  448. return universalTransitionOpt && universalTransitionOpt.enabled;
  449. };
  450. SeriesModel.prototype._innerSelect = function (data, innerDataIndices) {
  451. var _a, _b;
  452. var option = this.option;
  453. var selectedMode = option.selectedMode;
  454. var len = innerDataIndices.length;
  455. if (!selectedMode || !len) {
  456. return;
  457. }
  458. if (selectedMode === 'series') {
  459. option.selectedMap = 'all';
  460. } else if (selectedMode === 'multiple') {
  461. if (!zrUtil.isObject(option.selectedMap)) {
  462. option.selectedMap = {};
  463. }
  464. var selectedMap = option.selectedMap;
  465. for (var i = 0; i < len; i++) {
  466. var dataIndex = innerDataIndices[i];
  467. // TODO different types of data share same object.
  468. var nameOrId = getSelectionKey(data, dataIndex);
  469. selectedMap[nameOrId] = true;
  470. this._selectedDataIndicesMap[nameOrId] = data.getRawIndex(dataIndex);
  471. }
  472. } else if (selectedMode === 'single' || selectedMode === true) {
  473. var lastDataIndex = innerDataIndices[len - 1];
  474. var nameOrId = getSelectionKey(data, lastDataIndex);
  475. option.selectedMap = (_a = {}, _a[nameOrId] = true, _a);
  476. this._selectedDataIndicesMap = (_b = {}, _b[nameOrId] = data.getRawIndex(lastDataIndex), _b);
  477. }
  478. };
  479. SeriesModel.prototype._initSelectedMapFromData = function (data) {
  480. // Ignore select info in data if selectedMap exists.
  481. // NOTE It's only for legacy usage. edge data is not supported.
  482. if (this.option.selectedMap) {
  483. return;
  484. }
  485. var dataIndices = [];
  486. if (data.hasItemOption) {
  487. data.each(function (idx) {
  488. var rawItem = data.getRawDataItem(idx);
  489. if (rawItem && rawItem.selected) {
  490. dataIndices.push(idx);
  491. }
  492. });
  493. }
  494. if (dataIndices.length > 0) {
  495. this._innerSelect(data, dataIndices);
  496. }
  497. };
  498. // /**
  499. // * @see {module:echarts/stream/Scheduler}
  500. // */
  501. // abstract pipeTask: null
  502. SeriesModel.registerClass = function (clz) {
  503. return ComponentModel.registerClass(clz);
  504. };
  505. SeriesModel.protoInitialize = function () {
  506. var proto = SeriesModel.prototype;
  507. proto.type = 'series.__base__';
  508. proto.seriesIndex = 0;
  509. proto.ignoreStyleOnData = false;
  510. proto.hasSymbolVisual = false;
  511. proto.defaultSymbol = 'circle';
  512. // Make sure the values can be accessed!
  513. proto.visualStyleAccessPath = 'itemStyle';
  514. proto.visualDrawType = 'fill';
  515. }();
  516. return SeriesModel;
  517. }(ComponentModel);
  518. zrUtil.mixin(SeriesModel, DataFormatMixin);
  519. zrUtil.mixin(SeriesModel, PaletteMixin);
  520. mountExtend(SeriesModel, ComponentModel);
  521. /**
  522. * MUST be called after `prepareSource` called
  523. * Here we need to make auto series, especially for auto legend. But we
  524. * do not modify series.name in option to avoid side effects.
  525. */
  526. function autoSeriesName(seriesModel) {
  527. // User specified name has higher priority, otherwise it may cause
  528. // series can not be queried unexpectedly.
  529. var name = seriesModel.name;
  530. if (!modelUtil.isNameSpecified(seriesModel)) {
  531. seriesModel.name = getSeriesAutoName(seriesModel) || name;
  532. }
  533. }
  534. function getSeriesAutoName(seriesModel) {
  535. var data = seriesModel.getRawData();
  536. var dataDims = data.mapDimensionsAll('seriesName');
  537. var nameArr = [];
  538. zrUtil.each(dataDims, function (dataDim) {
  539. var dimInfo = data.getDimensionInfo(dataDim);
  540. dimInfo.displayName && nameArr.push(dimInfo.displayName);
  541. });
  542. return nameArr.join(' ');
  543. }
  544. function dataTaskCount(context) {
  545. return context.model.getRawData().count();
  546. }
  547. function dataTaskReset(context) {
  548. var seriesModel = context.model;
  549. seriesModel.setData(seriesModel.getRawData().cloneShallow());
  550. return dataTaskProgress;
  551. }
  552. function dataTaskProgress(param, context) {
  553. // Avoid repeat cloneShallow when data just created in reset.
  554. if (context.outputData && param.end > context.outputData.count()) {
  555. context.model.getRawData().cloneShallow(context.outputData);
  556. }
  557. }
  558. // TODO refactor
  559. function wrapData(data, seriesModel) {
  560. zrUtil.each(zrUtil.concatArray(data.CHANGABLE_METHODS, data.DOWNSAMPLE_METHODS), function (methodName) {
  561. data.wrapMethod(methodName, zrUtil.curry(onDataChange, seriesModel));
  562. });
  563. }
  564. function onDataChange(seriesModel, newList) {
  565. var task = getCurrentTask(seriesModel);
  566. if (task) {
  567. // Consider case: filter, selectRange
  568. task.setOutputEnd((newList || this).count());
  569. }
  570. return newList;
  571. }
  572. function getCurrentTask(seriesModel) {
  573. var scheduler = (seriesModel.ecModel || {}).scheduler;
  574. var pipeline = scheduler && scheduler.getPipeline(seriesModel.uid);
  575. if (pipeline) {
  576. // When pipline finished, the currrentTask keep the last
  577. // task (renderTask).
  578. var task = pipeline.currentTask;
  579. if (task) {
  580. var agentStubMap = task.agentStubMap;
  581. if (agentStubMap) {
  582. task = agentStubMap.get(seriesModel.uid);
  583. }
  584. }
  585. return task;
  586. }
  587. }
  588. export default SeriesModel;