From e7e3cfe20a640b921bcadcfc5190c7f696005ebc Mon Sep 17 00:00:00 2001 From: sushuang Date: Sat, 10 Feb 2018 01:32:35 +0800 Subject: [PATCH] remove stack from data API. --- src/chart/candlestick/candlestickLayout.js | 2 +- src/chart/pie/pieLayout.js | 2 +- src/component/marker/markerHelper.js | 2 +- src/component/visualMap/ContinuousModel.js | 2 +- src/component/visualMap/PiecewiseModel.js | 2 +- src/data/List.js | 57 ++++++++++------------ src/processor/dataFilter.js | 2 +- src/visual/visualSolution.js | 4 +- 8 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/chart/candlestick/candlestickLayout.js b/src/chart/candlestick/candlestickLayout.js index 9cefae2f1..61ffe6560 100644 --- a/src/chart/candlestick/candlestickLayout.js +++ b/src/chart/candlestick/candlestickLayout.js @@ -146,7 +146,7 @@ export default function (ecModel) { return point; } - }, true); + }); }); } diff --git a/src/chart/pie/pieLayout.js b/src/chart/pie/pieLayout.js index 27615366c..e9e2f85b3 100644 --- a/src/chart/pie/pieLayout.js +++ b/src/chart/pie/pieLayout.js @@ -108,7 +108,7 @@ export default function (seriesType, ecModel, api, payload) { }); currentAngle = endAngle; - }, true); + }); // Some sector is constrained by minAngle // Rest sectors needs recalculate angle diff --git a/src/component/marker/markerHelper.js b/src/component/marker/markerHelper.js index b13b81918..17f449e9d 100644 --- a/src/component/marker/markerHelper.js +++ b/src/component/marker/markerHelper.js @@ -209,7 +209,7 @@ export function numCalculate(data, valueDataDim, type) { sum += val; count++; } - }, true); + }); return sum / count; } else { diff --git a/src/component/visualMap/ContinuousModel.js b/src/component/visualMap/ContinuousModel.js index 8c72fbb8d..ff0e506ef 100644 --- a/src/component/visualMap/ContinuousModel.js +++ b/src/component/visualMap/ContinuousModel.js @@ -151,7 +151,7 @@ var ContinuousModel = VisualMapModel.extend({ data.each(this.getDataDimension(data), function (value, dataIndex) { range[0] <= value && value <= range[1] && dataIndices.push(dataIndex); - }, true, this); + }, this); result.push({seriesId: seriesModel.id, dataIndex: dataIndices}); }, this); diff --git a/src/component/visualMap/PiecewiseModel.js b/src/component/visualMap/PiecewiseModel.js index d3b9a5565..91c1b2a12 100644 --- a/src/component/visualMap/PiecewiseModel.js +++ b/src/component/visualMap/PiecewiseModel.js @@ -265,7 +265,7 @@ var PiecewiseModel = VisualMapModel.extend({ // Should always base on model pieceList, because it is order sensitive. var pIdx = VisualMapping.findPieceIndex(value, this._pieceList); pIdx === pieceIndex && dataIndices.push(dataIndex); - }, true, this); + }, this); result.push({seriesId: seriesModel.id, dataIndex: dataIndices}); }, this); diff --git a/src/data/List.js b/src/data/List.js index badc91b33..0054369a9 100644 --- a/src/data/List.js +++ b/src/data/List.js @@ -75,7 +75,6 @@ function transferProperties(a, b) { * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius * Spetial fields: { * ordinalMeta: - * stackable: * createInvertedIndices: * } * @param {module:echarts/model/Model} hostModel @@ -844,7 +843,6 @@ listProto.setCalculationInfo = function (key, value) { /** * Get sum of data in one dimension * @param {string} dim - * @param {boolean} stack */ listProto.getSum = function (dim /*, stack */) { var dimData = this._storage[dim]; @@ -967,11 +965,10 @@ listProto.indexOfRawIndex = function (rawIndex) { * Retreive the index of nearest value * @param {string} dim * @param {number} value - * @param {boolean} stack If given value is after stacked * @param {number} [maxDistance=Infinity] * @return {Array.} Considere multiple points has the same value. */ -listProto.indicesOfNearest = function (dim, value, /*, stack, */ maxDistance) { +listProto.indicesOfNearest = function (dim, value, maxDistance) { var storage = this._storage; var dimData = storage[dim]; var nearestIndices = []; @@ -1102,8 +1099,7 @@ function validateDimensions(list, dims) { * list.each(['x', 'y'], function (x, y, idx) {}); * list.each(function (idx) {}) */ -// FIXME ???? remove stack -listProto.each = function (dims, cb, stack, context) { +listProto.each = function (dims, cb, context, contextCompat) { 'use strict'; if (!this._count) { @@ -1111,12 +1107,15 @@ listProto.each = function (dims, cb, stack, context) { } if (typeof dims === 'function') { - context = stack; - stack = cb; + contextCompat = context; + context = cb; cb = dims; dims = []; } + // contextCompat just for compat echarts3 + context = context || contextCompat || this; + dims = zrUtil.map(normalizeDimensions(dims), this.getDimension, this); if (__DEV__) { @@ -1125,8 +1124,6 @@ listProto.each = function (dims, cb, stack, context) { var dimSize = dims.length; - context = context || this; - for (var i = 0; i < this.count(); i++) { // Simple optimization switch (dimSize) { @@ -1134,16 +1131,16 @@ listProto.each = function (dims, cb, stack, context) { cb.call(context, i); break; case 1: - cb.call(context, this.get(dims[0], i /*, stack */), i); + cb.call(context, this.get(dims[0], i), i); break; case 2: - cb.call(context, this.get(dims[0], i /*, stack */), this.get(dims[1], i /*, stack */), i); + cb.call(context, this.get(dims[0], i), this.get(dims[1], i), i); break; default: var k = 0; var value = []; for (; k < dimSize; k++) { - value[k] = this.get(dims[k], i /*, stack */); + value[k] = this.get(dims[k], i); } // Index value[k] = i; @@ -1156,11 +1153,9 @@ listProto.each = function (dims, cb, stack, context) { * Data filter * @param {string|Array.} * @param {Function} cb - * @param {boolean} [stack=false] * @param {*} [context=this] */ -// ???? REMOVE STACK -listProto.filterSelf = function (dimensions, cb, stack, context) { +listProto.filterSelf = function (dimensions, cb, context, contextCompat) { 'use strict'; if (!this._count) { @@ -1168,14 +1163,14 @@ listProto.filterSelf = function (dimensions, cb, stack, context) { } if (typeof dimensions === 'function') { - context = stack; - stack = cb; + contextCompat = context; + context = cb; cb = dimensions; dimensions = []; } - stack = stack || false; - context = context || this; + // contextCompat just for compat echarts3 + context = context || contextCompat || this; dimensions = zrUtil.map( normalizeDimensions(dimensions), this.getDimension, this @@ -1203,13 +1198,11 @@ listProto.filterSelf = function (dimensions, cb, stack, context) { keep = cb.call(context, i); } else if (dimSize === 1) { - // var val = stack ? this.get(dim0, i, true) : this._getFast(dim0, rawIdx); var val = this._getFast(dim0, rawIdx); keep = cb.call(context, val, i); } else { for (var k = 0; k < dimSize; k++) { - // value[k] = stack ? this.get(dimensions[k], i, true) : this._getFast(dim0, rawIdx); value[k] = this._getFast(dim0, rawIdx); } value[k] = i; @@ -1360,25 +1353,26 @@ listProto.selectRange = function (range /*, stack */) { * Data mapping to a plain array * @param {string|Array.} [dimensions] * @param {Function} cb - * @param {boolean} [stack=false] * @param {*} [context=this] * @return {Array} */ -// ??? REMOVE STACK -listProto.mapArray = function (dimensions, cb, stack, context) { +listProto.mapArray = function (dimensions, cb, context, contextCompat) { 'use strict'; if (typeof dimensions === 'function') { - context = stack; - stack = cb; + contextCompat = context; + context = cb; cb = dimensions; dimensions = []; } + // contextCompat just for compat echarts3 + context = context || contextCompat || this; + var result = []; this.each(dimensions, function () { result.push(cb && cb.apply(this, arguments)); - }, stack, context); + }, context); return result; }; @@ -1429,14 +1423,15 @@ function getInitialExtent() { * Data mapping to a new List with given dimensions * @param {string|Array.} dimensions * @param {Function} cb - * @param {boolean} [stack=false] * @param {*} [context=this] * @return {Array} */ -// ???? REMOVE STACK -listProto.map = function (dimensions, cb, stack, context) { +listProto.map = function (dimensions, cb, context, contextCompat) { 'use strict'; + // contextCompat just for compat echarts3 + context = context || contextCompat || this; + dimensions = zrUtil.map( normalizeDimensions(dimensions), this.getDimension, this ); diff --git a/src/processor/dataFilter.js b/src/processor/dataFilter.js index 753a90e67..e2445059e 100644 --- a/src/processor/dataFilter.js +++ b/src/processor/dataFilter.js @@ -18,7 +18,7 @@ export default function (seriesType) { } } return true; - }, this); + }); } }; } \ No newline at end of file diff --git a/src/visual/visualSolution.js b/src/visual/visualSolution.js index ae2a5dc0b..13446c6d9 100644 --- a/src/visual/visualSolution.js +++ b/src/visual/visualSolution.js @@ -115,10 +115,10 @@ export function applyVisual(stateList, visualMappings, data, getValueState, scop } if (dimension == null) { - data.each(eachItem, true); + data.each(eachItem); } else { - data.each([dimension], eachItem, true); + data.each([dimension], eachItem); } function eachItem(valueOrIndex, index) { -- GitLab