From 0ab7a4cf0bf45c86583262ea57a76360a2d37f3b Mon Sep 17 00:00:00 2001 From: pah100 Date: Fri, 27 May 2016 21:39:26 +0800 Subject: [PATCH] parallel support smooth, progressive --- src/chart/parallel/ParallelSeries.js | 11 +- src/chart/parallel/ParallelView.js | 132 ++++++---------- src/component/tooltip/TooltipView.js | 4 +- src/data/List.js | 3 +- src/util/model.js | 2 +- test/parallel-nutrients.html | 219 +++++++++++++++++++++++++++ 6 files changed, 280 insertions(+), 91 deletions(-) create mode 100644 test/parallel-nutrients.html diff --git a/src/chart/parallel/ParallelSeries.js b/src/chart/parallel/ParallelSeries.js index d283d9b26..193cf1f91 100644 --- a/src/chart/parallel/ParallelSeries.js +++ b/src/chart/parallel/ParallelSeries.js @@ -32,6 +32,9 @@ define(function(require) { translateCategoryValue(axisModel, dim, rawData); return {name: dim, type: 'ordinal'}; } + else if (modelDimsIndex < 0) { + return {name: dim, type: 'unknown'}; + } else { return dim; } @@ -40,6 +43,11 @@ define(function(require) { var list = new List(dataDimsInfo, this); list.initData(rawData); + // Anication is forbiden in large data mode. + if (this.option.large) { + this.option.animation = false; + } + return list; }, @@ -90,7 +98,8 @@ define(function(require) { type: 'solid' } }, - // smooth: false + progressive: false, // 100 + smooth: false, animationEasing: 'linear' } diff --git a/src/chart/parallel/ParallelView.js b/src/chart/parallel/ParallelView.js index 2881c70f0..45d381f41 100644 --- a/src/chart/parallel/ParallelView.js +++ b/src/chart/parallel/ParallelView.js @@ -2,6 +2,9 @@ define(function (require) { var graphic = require('../../util/graphic'); var zrUtil = require('zrender/core/util'); + var polyHelper = require('../line/poly'); + + var SMOOTH = 0.3; var ParallelView = require('../../view/Chart').extend({ @@ -31,6 +34,9 @@ define(function (require) { var oldData = this._data; var coordSys = seriesModel.coordinateSystem; var dimensions = coordSys.dimensions; + var option = seriesModel.option; + var progressive = option.progressive; + var smooth = option.smooth ? SMOOTH : null; data.diff(oldData) .add(add) @@ -39,19 +45,18 @@ define(function (require) { .execute(); // Update style - data.eachItemGraphicEl(function (elGroup, idx) { + data.eachItemGraphicEl(function (line, idx) { var itemModel = data.getItemModel(idx); var lineStyleModel = itemModel.getModel('lineStyle.normal'); - elGroup.eachChild(function (child) { - child.useStyle(zrUtil.extend( - lineStyleModel.getLineStyle(), - { - fill: null, - stroke: data.getItemVisual(idx, 'color'), - opacity: data.getItemVisual(idx, 'opacity') - } - )); - }); + + line.useStyle(zrUtil.extend( + lineStyleModel.getLineStyle(), + { + fill: null, + stroke: data.getItemVisual(idx, 'color'), + opacity: data.getItemVisual(idx, 'opacity') + } + )); }); // First create @@ -66,64 +71,23 @@ define(function (require) { this._data = data; function add(newDataIndex) { - var values = data.getValues(dimensions, newDataIndex); - var elGroup = new graphic.Group(); - dataGroup.add(elGroup); - - eachAxisPair( - values, dimensions, coordSys, - function (pointPair, pairIndex) { - // FIXME - // init animation - if (pointPair) { - elGroup.add(createEl(pointPair)); - } - } - ); - - data.setItemGraphicEl(newDataIndex, elGroup); + var points = createLinePoints(data, newDataIndex, dimensions, coordSys); + var line = createPoly(points, newDataIndex, progressive, smooth); + dataGroup.add(line); + data.setItemGraphicEl(newDataIndex, line); } function update(newDataIndex, oldDataIndex) { - var values = data.getValues(dimensions, newDataIndex); - var elGroup = oldData.getItemGraphicEl(oldDataIndex); - var newEls = []; - var elGroupIndex = 0; - - eachAxisPair( - values, dimensions, coordSys, - function (pointPair, pairIndex) { - var el = elGroup.childAt(elGroupIndex++); - - if (pointPair && !el) { - newEls.push(createEl(pointPair)); - } - else if (pointPair) { - graphic.updateProps(el, { - shape: { - points: pointPair - } - }, seriesModel, newDataIndex); - } - } - ); - - // Remove redundent els - for (var i = elGroup.childCount() - 1; i >= elGroupIndex; i--) { - elGroup.remove(elGroup.childAt(i)); - } - - // Add new els - for (var i = 0, len = newEls.length; i < len; i++) { - elGroup.add(newEls[i]); - } - - data.setItemGraphicEl(newDataIndex, elGroup); + var line = oldData.getItemGraphicEl(oldDataIndex); + var points = createLinePoints(data, newDataIndex, dimensions, coordSys); + line.shape.points = points; + line.dirty(); + data.setItemGraphicEl(newDataIndex, line); } function remove(oldDataIndex) { - var elGroup = oldData.getItemGraphicEl(oldDataIndex); - dataGroup.remove(elGroup); + var line = oldData.getItemGraphicEl(oldDataIndex); + dataGroup.remove(line); } }, @@ -158,35 +122,29 @@ define(function (require) { return rectEl; } - function eachAxisPair(values, dimensions, coordSys, cb) { - for (var i = 0, len = dimensions.length - 1; i < len; i++) { - var dimA = dimensions[i]; - var dimB = dimensions[i + 1]; - var valueA = values[i]; - var valueB = values[i + 1]; - - cb( - (isEmptyValue(valueA, coordSys.getAxis(dimA).type) - || isEmptyValue(valueB, coordSys.getAxis(dimB).type) - ) - ? null - : [ - coordSys.dataToPoint(valueA, dimA), - coordSys.dataToPoint(valueB, dimB) - ], - i - ); - } + function createPoly(points, dataIndex, progressive, smooth) { + return new polyHelper.Polyline({ + shape: { + points: points, + smooth: smooth + }, + silent: true, + progressive: progressive ? Math.round(dataIndex / progressive) : 0, + z2: 10 + }); } - function createEl(pointPair) { - return new graphic.Polyline({ - shape: {points: pointPair}, - silent: true + function createLinePoints(data, dataIndex, dimensions, coordSys) { + var points = []; + zrUtil.each(dimensions, function (dimName) { + var value = data.get(dimName, dataIndex); + if (!isEmptyValue(value, coordSys.getAxis(dimName).type)) { + points.push(coordSys.dataToPoint(value, dimName)); + } }); + return points; } - // FIXME // 公用方法? function isEmptyValue(val, axisType) { diff --git a/src/component/tooltip/TooltipView.js b/src/component/tooltip/TooltipView.js index 50b0f360a..ddb437cd4 100644 --- a/src/component/tooltip/TooltipView.js +++ b/src/component/tooltip/TooltipView.js @@ -1104,7 +1104,9 @@ define(function (require) { }); } else { - this.group.hide(); + if (this.group.children().length) { + this.group.hide(); + } } }, diff --git a/src/data/List.js b/src/data/List.js index d1c42ce34..3272dc7fe 100644 --- a/src/data/List.js +++ b/src/data/List.js @@ -17,7 +17,8 @@ define(function (require) { // Ordinal data type can be string or int 'ordinal': Array, 'number': Array, - 'time': Array + 'time': Array, + 'unknown': Array }; var Model = require('../model/Model'); diff --git a/src/util/model.js b/src/util/model.js index 4b9b2339a..b070cd529 100644 --- a/src/util/model.js +++ b/src/util/model.js @@ -195,7 +195,7 @@ define(function(require) { modelUtil.converDataValue = function (value, dimInfo) { // Performance sensitive. var dimType = dimInfo && dimInfo.type; - if (dimType === 'ordinal') { + if (dimType === 'ordinal' || dimType === 'unknown') { return value; } diff --git a/test/parallel-nutrients.html b/test/parallel-nutrients.html new file mode 100644 index 000000000..7136cf175 --- /dev/null +++ b/test/parallel-nutrients.html @@ -0,0 +1,219 @@ + + + + + + + + + + + + +
+ + + \ No newline at end of file -- GitLab