Series.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  263. };
  264. /**
  265. * Retrieve the index of nearest value in the view coordinate.
  266. * Data position is compared with each axis's dataToCoord.
  267. *
  268. * @param axisDim axis dimension
  269. * @param dim data dimension
  270. * @param value
  271. * @param [maxDistance=Infinity] The maximum distance in view coordinate space
  272. * @return If and only if multiple indices has
  273. * the same value, they are put to the result.
  274. */
  275. SeriesModel.prototype.indicesOfNearest = function (axisDim, dim, value, maxDistance) {
  276. var data = this.getData();
  277. var coordSys = this.coordinateSystem;
  278. var axis = coordSys && coordSys.getAxis(axisDim);
  279. if (!coordSys || !axis) {
  280. return [];
  281. }
  282. var targetCoord = axis.dataToCoord(value);
  283. if (maxDistance == null) {
  284. maxDistance = Infinity;
  285. }
  286. var nearestIndices = [];
  287. var minDist = Infinity;
  288. var minDiff = -1;
  289. var nearestIndicesLen = 0;
  290. // Performance-sensitive on large data (triggered by `tooltip`/`axisPointer` frequently).
  291. var dimIdx = data.getDimensionIndex(dim);
  292. var store = data.getStore();
  293. for (var idx = 0, len = store.count(); idx < len; idx++) {
  294. var dimValue = store.get(dimIdx, idx);
  295. var dataCoord = axis.dataToCoord(dimValue);
  296. var diff = targetCoord - dataCoord;
  297. var dist = Math.abs(diff);
  298. if (dist <= maxDistance) {
  299. // When the `value` is at the middle of `this.get(dim, i)` and `this.get(dim, i+1)`,
  300. // we'd better not push both of them to `nearestIndices`, otherwise it is easy to
  301. // get more than one item in `nearestIndices` (more specifically, in `tooltip`).
  302. // So we choose the one that `diff >= 0` in this case.
  303. // But if `this.get(dim, i)` and `this.get(dim, j)` get the same value, both of them
  304. // should be push to `nearestIndices`.
  305. if (dist < minDist || dist === minDist && diff >= 0 && minDiff < 0) {
  306. minDist = dist;
  307. minDiff = diff;
  308. nearestIndicesLen = 0;
  309. }
  310. if (diff === minDiff) {
  311. nearestIndices[nearestIndicesLen++] = idx;
  312. }
  313. }
  314. }
  315. nearestIndices.length = nearestIndicesLen;
  316. return nearestIndices;
  317. };
  318. /**
  319. * Default tooltip formatter
  320. *
  321. * @param dataIndex
  322. * @param multipleSeries
  323. * @param dataType
  324. * @param renderMode valid values: 'html'(by default) and 'richText'.
  325. * 'html' is used for rendering tooltip in extra DOM form, and the result
  326. * string is used as DOM HTML content.
  327. * 'richText' is used for rendering tooltip in rich text form, for those where
  328. * DOM operation is not supported.
  329. * @return formatted tooltip with `html` and `markers`
  330. * Notice: The override method can also return string
  331. */
  332. SeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  333. return defaultSeriesFormatTooltip({
  334. series: this,
  335. dataIndex: dataIndex,
  336. multipleSeries: multipleSeries
  337. });
  338. };
  339. SeriesModel.prototype.isAnimationEnabled = function () {
  340. var ecModel = this.ecModel;
  341. // Disable animation if using echarts in node but not give ssr flag.
  342. // In ssr mode, renderToString will generate svg with css animation.
  343. if (env.node && !(ecModel && ecModel.ssr)) {
  344. return false;
  345. }
  346. var animationEnabled = this.getShallow('animation');
  347. if (animationEnabled) {
  348. if (this.getData().count() > this.getShallow('animationThreshold')) {
  349. animationEnabled = false;
  350. }
  351. }
  352. return !!animationEnabled;
  353. };
  354. SeriesModel.prototype.restoreData = function () {
  355. // See `dataTaskReset`.
  356. this.dataTask.dirty();
  357. };
  358. SeriesModel.prototype.getColorFromPalette = function (name, scope, requestColorNum) {
  359. var ecModel = this.ecModel;
  360. // PENDING
  361. var color = PaletteMixin.prototype.getColorFromPalette.call(this, name, scope, requestColorNum);
  362. if (!color) {
  363. color = ecModel.getColorFromPalette(name, scope, requestColorNum);
  364. }
  365. return color;
  366. };
  367. /**
  368. * Use `data.mapDimensionsAll(coordDim)` instead.
  369. * @deprecated
  370. */
  371. SeriesModel.prototype.coordDimToDataDim = function (coordDim) {
  372. return this.getRawData().mapDimensionsAll(coordDim);
  373. };
  374. /**
  375. * Get progressive rendering count each step
  376. */
  377. SeriesModel.prototype.getProgressive = function () {
  378. return this.get('progressive');
  379. };
  380. /**
  381. * Get progressive rendering count each step
  382. */
  383. SeriesModel.prototype.getProgressiveThreshold = function () {
  384. return this.get('progressiveThreshold');
  385. };
  386. // PENGING If selectedMode is null ?
  387. SeriesModel.prototype.select = function (innerDataIndices, dataType) {
  388. this._innerSelect(this.getData(dataType), innerDataIndices);
  389. };
  390. SeriesModel.prototype.unselect = function (innerDataIndices, dataType) {
  391. var selectedMap = this.option.selectedMap;
  392. if (!selectedMap) {
  393. return;
  394. }
  395. var selectedMode = this.option.selectedMode;
  396. var data = this.getData(dataType);
  397. if (selectedMode === 'series' || selectedMap === 'all') {
  398. this.option.selectedMap = {};
  399. this._selectedDataIndicesMap = {};
  400. return;
  401. }
  402. for (var i = 0; i < innerDataIndices.length; i++) {
  403. var dataIndex = innerDataIndices[i];
  404. var nameOrId = getSelectionKey(data, dataIndex);
  405. selectedMap[nameOrId] = false;
  406. this._selectedDataIndicesMap[nameOrId] = -1;
  407. }
  408. };
  409. SeriesModel.prototype.toggleSelect = function (innerDataIndices, dataType) {
  410. var tmpArr = [];
  411. for (var i = 0; i < innerDataIndices.length; i++) {
  412. tmpArr[0] = innerDataIndices[i];
  413. this.isSelected(innerDataIndices[i], dataType) ? this.unselect(tmpArr, dataType) : this.select(tmpArr, dataType);
  414. }
  415. };
  416. SeriesModel.prototype.getSelectedDataIndices = function () {
  417. if (this.option.selectedMap === 'all') {
  418. return [].slice.call(this.getData().getIndices());
  419. }
  420. var selectedDataIndicesMap = this._selectedDataIndicesMap;
  421. var nameOrIds = zrUtil.keys(selectedDataIndicesMap);
  422. var dataIndices = [];
  423. for (var i = 0; i < nameOrIds.length; i++) {
  424. var dataIndex = selectedDataIndicesMap[nameOrIds[i]];
  425. if (dataIndex >= 0) {
  426. dataIndices.push(dataIndex);
  427. }
  428. }
  429. return dataIndices;
  430. };
  431. SeriesModel.prototype.isSelected = function (dataIndex, dataType) {
  432. var selectedMap = this.option.selectedMap;
  433. if (!selectedMap) {
  434. return false;
  435. }
  436. var data = this.getData(dataType);
  437. return (selectedMap === 'all' || selectedMap[getSelectionKey(data, dataIndex)]) && !data.getItemModel(dataIndex).get(['select', 'disabled']);
  438. };
  439. SeriesModel.prototype.isUniversalTransitionEnabled = function () {
  440. if (this[SERIES_UNIVERSAL_TRANSITION_PROP]) {
  441. return true;
  442. }
  443. var universalTransitionOpt = this.option.universalTransition;
  444. // Quick reject
  445. if (!universalTransitionOpt) {
  446. return false;
  447. }
  448. if (universalTransitionOpt === true) {
  449. return true;
  450. }
  451. // Can be simply 'universalTransition: true'
  452. return universalTransitionOpt && universalTransitionOpt.enabled;
  453. };
  454. SeriesModel.prototype._innerSelect = function (data, innerDataIndices) {
  455. var _a, _b;
  456. var option = this.option;
  457. var selectedMode = option.selectedMode;
  458. var len = innerDataIndices.length;
  459. if (!selectedMode || !len) {
  460. return;
  461. }
  462. if (selectedMode === 'series') {
  463. option.selectedMap = 'all';
  464. } else if (selectedMode === 'multiple') {
  465. if (!zrUtil.isObject(option.selectedMap)) {
  466. option.selectedMap = {};
  467. }
  468. var selectedMap = option.selectedMap;
  469. for (var i = 0; i < len; i++) {
  470. var dataIndex = innerDataIndices[i];
  471. // TODO different types of data share same object.
  472. var nameOrId = getSelectionKey(data, dataIndex);
  473. selectedMap[nameOrId] = true;
  474. this._selectedDataIndicesMap[nameOrId] = data.getRawIndex(dataIndex);
  475. }
  476. } else if (selectedMode === 'single' || selectedMode === true) {
  477. var lastDataIndex = innerDataIndices[len - 1];
  478. var nameOrId = getSelectionKey(data, lastDataIndex);
  479. option.selectedMap = (_a = {}, _a[nameOrId] = true, _a);
  480. this._selectedDataIndicesMap = (_b = {}, _b[nameOrId] = data.getRawIndex(lastDataIndex), _b);
  481. }
  482. };
  483. SeriesModel.prototype._initSelectedMapFromData = function (data) {
  484. // Ignore select info in data if selectedMap exists.
  485. // NOTE It's only for legacy usage. edge data is not supported.
  486. if (this.option.selectedMap) {
  487. return;
  488. }
  489. var dataIndices = [];
  490. if (data.hasItemOption) {
  491. data.each(function (idx) {
  492. var rawItem = data.getRawDataItem(idx);
  493. if (rawItem && rawItem.selected) {
  494. dataIndices.push(idx);
  495. }
  496. });
  497. }
  498. if (dataIndices.length > 0) {
  499. this._innerSelect(data, dataIndices);
  500. }
  501. };
  502. // /**
  503. // * @see {module:echarts/stream/Scheduler}
  504. // */
  505. // abstract pipeTask: null
  506. SeriesModel.registerClass = function (clz) {
  507. return ComponentModel.registerClass(clz);
  508. };
  509. SeriesModel.protoInitialize = function () {
  510. var proto = SeriesModel.prototype;
  511. proto.type = 'series.__base__';
  512. proto.seriesIndex = 0;
  513. proto.ignoreStyleOnData = false;
  514. proto.hasSymbolVisual = false;
  515. proto.defaultSymbol = 'circle';
  516. // Make sure the values can be accessed!
  517. proto.visualStyleAccessPath = 'itemStyle';
  518. proto.visualDrawType = 'fill';
  519. }();
  520. return SeriesModel;
  521. }(ComponentModel);
  522. zrUtil.mixin(SeriesModel, DataFormatMixin);
  523. zrUtil.mixin(SeriesModel, PaletteMixin);
  524. mountExtend(SeriesModel, ComponentModel);
  525. /**
  526. * MUST be called after `prepareSource` called
  527. * Here we need to make auto series, especially for auto legend. But we
  528. * do not modify series.name in option to avoid side effects.
  529. */
  530. function autoSeriesName(seriesModel) {
  531. // User specified name has higher priority, otherwise it may cause
  532. // series can not be queried unexpectedly.
  533. var name = seriesModel.name;
  534. if (!modelUtil.isNameSpecified(seriesModel)) {
  535. seriesModel.name = getSeriesAutoName(seriesModel) || name;
  536. }
  537. }
  538. function getSeriesAutoName(seriesModel) {
  539. var data = seriesModel.getRawData();
  540. var dataDims = data.mapDimensionsAll('seriesName');
  541. var nameArr = [];
  542. zrUtil.each(dataDims, function (dataDim) {
  543. var dimInfo = data.getDimensionInfo(dataDim);
  544. dimInfo.displayName && nameArr.push(dimInfo.displayName);
  545. });
  546. return nameArr.join(' ');
  547. }
  548. function dataTaskCount(context) {
  549. return context.model.getRawData().count();
  550. }
  551. function dataTaskReset(context) {
  552. var seriesModel = context.model;
  553. seriesModel.setData(seriesModel.getRawData().cloneShallow());
  554. return dataTaskProgress;
  555. }
  556. function dataTaskProgress(param, context) {
  557. // Avoid repeat cloneShallow when data just created in reset.
  558. if (context.outputData && param.end > context.outputData.count()) {
  559. context.model.getRawData().cloneShallow(context.outputData);
  560. }
  561. }
  562. // TODO refactor
  563. function wrapData(data, seriesModel) {
  564. zrUtil.each(zrUtil.concatArray(data.CHANGABLE_METHODS, data.DOWNSAMPLE_METHODS), function (methodName) {
  565. data.wrapMethod(methodName, zrUtil.curry(onDataChange, seriesModel));
  566. });
  567. }
  568. function onDataChange(seriesModel, newList) {
  569. var task = getCurrentTask(seriesModel);
  570. if (task) {
  571. // Consider case: filter, selectRange
  572. task.setOutputEnd((newList || this).count());
  573. }
  574. return newList;
  575. }
  576. function getCurrentTask(seriesModel) {
  577. var scheduler = (seriesModel.ecModel || {}).scheduler;
  578. var pipeline = scheduler && scheduler.getPipeline(seriesModel.uid);
  579. if (pipeline) {
  580. // When pipline finished, the currrentTask keep the last
  581. // task (renderTask).
  582. var task = pipeline.currentTask;
  583. if (task) {
  584. var agentStubMap = task.agentStubMap;
  585. if (agentStubMap) {
  586. task = agentStubMap.get(seriesModel.uid);
  587. }
  588. }
  589. return task;
  590. }
  591. }
  592. export default SeriesModel;