提交 c09d2aa5 编写于 作者: P pissang

Add List#selectRange for optimization.

上级 009a8a87
......@@ -335,7 +335,11 @@ AxisProxy.prototype = {
);
}
else {
seriesData.filterSelf(dim, isInWindow);
var range = {};
range[dim] = valueWindow;
// console.time('select');
seriesData.selectRange(range);
// console.timeEnd('select');
}
seriesData.setApproximateExtent(valueWindow, dim);
});
......
......@@ -1018,6 +1018,8 @@ listProto.filterSelf = function (dimensions, cb, stack, context) {
}
stack = stack || false;
context = context || this;
dimensions = zrUtil.map(
normalizeDimensions(dimensions), this.getDimension, this
);
......@@ -1028,8 +1030,6 @@ listProto.filterSelf = function (dimensions, cb, stack, context) {
var value = [];
var dimSize = dimensions.length;
context = context || this;
var offset = 0;
var dim0 = dimensions[0];
......@@ -1067,6 +1067,82 @@ listProto.filterSelf = function (dimensions, cb, stack, context) {
return this;
};
/**
* Select data in range.
*/
listProto.selectRange = function (range, stack) {
'use strict';
stack = stack || false;
var dimensions = [];
for (var dim in range) {
dimensions.push(dim);
}
var dimSize = dimensions.length;
if (!dimSize) {
return;
}
var count = this.count();
var Ctor = getIndicesCtor(count);
var newIndices = new Ctor(count);
var offset = 0;
var dim0 = dimensions[0];
if (dimSize === 1) {
var min = range[dim0][0];
var max = range[dim0][1];
for (var i = 0; i < count; i++) {
var val;
var rawIndex = this.getRawIndex(i);
if (stack) {
val = this.get(dim, i, true);
}
else {
var storage = this._storage;
var chunkIndex = Math.floor(i / this._chunkSize);
var chunkOffset = i % this._chunkSize;
var chunkStore = storage[dim][chunkIndex];
var val = chunkStore[chunkOffset];
}
if (val >= min && val <= max) {
newIndices[offset++] = rawIndex;
}
}
}
else {
for (var i = 0; i < count; i++) {
var keep = true;
for (var k = 0; k < dimSize; k++) {
var dimName = dimensions[k];
var val = this.get(dimName, i, stack);
if (val < range[dimName][0] || val > range[dimName][1]) {
keep = false;
}
}
if (keep) {
newIndices[offset++] = this.getRawIndex(i);
}
}
}
// Set indices after filtered.
if (offset < count) {
this._indices = newIndices;
}
this._count = offset;
// Reset data extent
this._extent = {};
this.getRawIndex = this._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
return this;
};
/**
* Data mapping to a plain array
* @param {string|Array.<string>} [dimensions]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册