From a7c2f7136a38f6f7b7db0ad7e4a13e21485e89df Mon Sep 17 00:00:00 2001 From: lang Date: Wed, 16 Sep 2015 14:47:36 +0800 Subject: [PATCH] Line fix after new List --- src/chart/helper/DataSymbol.js | 10 +--------- src/chart/line/LineView.js | 17 +++++++++-------- src/data/List.js | 2 +- test/ut/spec/data/List.js | 6 +----- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/chart/helper/DataSymbol.js b/src/chart/helper/DataSymbol.js index 523e2d12e..973590195 100644 --- a/src/chart/helper/DataSymbol.js +++ b/src/chart/helper/DataSymbol.js @@ -4,10 +4,6 @@ define(function (require) { var Group = require('zrender/container/Group'); var symbolCreators = require('../../util/symbol'); - function getSymbolElement(dataItem) { - return dataItem.__symbolEl; - } - function createSymbol(data, idx, enableAnimation) { var point = data.getItemLayout(idx); var color = data.getItemVisual(idx, 'color'); @@ -63,10 +59,6 @@ define(function (require) { return this._data; }, - getSymbolElements: function () { - return this._data.map(getSymbolElement); - }, - updateData: function (data, enableAnimation) { var group = this.group; @@ -110,7 +102,7 @@ define(function (require) { else { el.attr({ scale: [symbolSize, symbolSize], - position: point + position: point.slice() }); } diff --git a/src/chart/line/LineView.js b/src/chart/line/LineView.js index 9f40033b3..84dfae36f 100644 --- a/src/chart/line/LineView.js +++ b/src/chart/line/LineView.js @@ -38,9 +38,10 @@ define(function(require) { var lineStyleNormalModel = seriesModel.getModel('itemStyle.normal.lineStyle'); var points = data.map(data.getItemLayout, true); - var pointsWithName = data.map(function (dataItem, idx) { + var pointsWithName = data.map(function (idx) { return { - name: dataItem.name, + // TODO Use category names if possible + name: data.getRawIndex(idx), point: points[idx] }; }); @@ -95,7 +96,7 @@ define(function(require) { dataSymbol.updateData(data, false); // In the case data zoom triggerred refreshing frequently // Data may not change if line has a category axis. So it should animate nothing - if (! isPointsSame(this._pointsWithName, pointsWithName)) { + if (!isPointsSame(this._pointsWithName, pointsWithName)) { this._updateAnimation(data, pointsWithName); } // Add back @@ -111,7 +112,6 @@ define(function(require) { var polyline = this._polyline; var diff = lineAnimationDiff(this._pointsWithName, pointsWithName); polyline.shape.points = diff.current; - // FIXME Handle the situation of adding and removing data polyline.animateTo({ shape: { points: diff.next @@ -120,7 +120,7 @@ define(function(require) { var updatedDataIndices = []; var diffStatus = diff.status; - var symbolElements = this._dataSymbol.getSymbolElements(); + var data = this._dataSymbol.getData(); for (var i = 0; i < diffStatus.length; i++) { if (diffStatus[i] === '=') { @@ -132,12 +132,13 @@ define(function(require) { polyline.animators[0].during(function () { // Symbol elements may be more than updatedDataIndices if there is new added data for (var i = 0; i < updatedDataIndices.length; i++) { + var el = data.getItemGraphicEl(i); vector.copy( - symbolElements[i].position, - // synchronizing whith the point on line + el.position, + // synchronizing with the point on line polyline.shape.points[updatedDataIndices[i]] ); - symbolElements[i].dirty(); + el.dirty(); } }); } diff --git a/src/data/List.js b/src/data/List.js index 730ee8b53..1721e44f7 100644 --- a/src/data/List.js +++ b/src/data/List.js @@ -293,7 +293,7 @@ define(function (require) { /** * Get raw data index */ - listProto.getDataIndex = function (idx) { + listProto.getRawIndex = function (idx) { return this.indices[idx]; }; diff --git a/test/ut/spec/data/List.js b/test/ut/spec/data/List.js index 07f4c511f..fb1889814 100644 --- a/test/ut/spec/data/List.js +++ b/test/ut/spec/data/List.js @@ -87,17 +87,13 @@ describe('List', function () { testCase('Data types', function (List) { var list = new List([{ - name: 'name', - type: 'string' - }, { name: 'x', type: 'int' }, { name: 'y', type: 'float' }]); - list.initData([['foo', 1.1, 1.1]]); - expect(list.get('name', 0)).toEqual('foo'); + list.initData([[1.1, 1.1]]); expect(list.get('x', 0)).toEqual(1); expect(list.get('y', 0)).toBeCloseTo(1.1, 5); }); -- GitLab