MCPcopy Index your code
hub / github.com/apache/echarts / downSample

Method downSample

src/data/DataStore.ts:1038–1090  ·  view source on GitHub ↗

* Large data down sampling on given dimension * @param sampleIndex Sample index for name and id

(
        dimension: DimensionIndex,
        rate: number,
        sampleValue: (frameValues: ArrayLike<ParsedValue>) => ParsedValueNumeric,
        sampleIndex: (frameValues: ArrayLike<ParsedValue>, value: ParsedValueNumeric) => number
    )

Source from the content-addressed store, hash-verified

1036 * @param sampleIndex Sample index for name and id
1037 */
1038 downSample(
1039 dimension: DimensionIndex,
1040 rate: number,
1041 sampleValue: (frameValues: ArrayLike<ParsedValue>) => ParsedValueNumeric,
1042 sampleIndex: (frameValues: ArrayLike<ParsedValue>, value: ParsedValueNumeric) => number
1043 ): DataStore {
1044 const target = this.clone([dimension], true);
1045 const targetStorage = target._chunks;
1046
1047 const frameValues = [];
1048 let frameSize = Math.floor(1 / rate);
1049
1050 const dimStore = targetStorage[dimension];
1051 const len = this.count();
1052 const rawExtentOnDim = target._rawExtent[dimension] = initExtentForUnion();
1053
1054 const newIndices = new (getIndicesCtor(this._rawCount))(Math.ceil(len / frameSize));
1055
1056 let offset = 0;
1057 for (let i = 0; i < len; i += frameSize) {
1058 // Last frame
1059 if (frameSize > len - i) {
1060 frameSize = len - i;
1061 frameValues.length = frameSize;
1062 }
1063 for (let k = 0; k < frameSize; k++) {
1064 const dataIdx = this.getRawIndex(i + k);
1065 frameValues[k] = dimStore[dataIdx];
1066 }
1067 const value = sampleValue(frameValues);
1068 const sampleFrameIdx = this.getRawIndex(
1069 Math.min(i + sampleIndex(frameValues, value) || 0, len - 1)
1070 );
1071 // Only write value on the filtered data
1072 (dimStore as number[])[sampleFrameIdx] = value;
1073
1074 if (value < rawExtentOnDim[0]) {
1075 rawExtentOnDim[0] = value;
1076 }
1077 if (value > rawExtentOnDim[1]) {
1078 rawExtentOnDim[1] = value;
1079 }
1080
1081 newIndices[offset++] = sampleFrameIdx;
1082 }
1083
1084 target._count = offset;
1085 target._indices = newIndices;
1086
1087 target._updateGetRawIdx();
1088
1089 return target;
1090 }
1091
1092 /**
1093 * Data iteration

Callers 1

dataSampleFunction · 0.45

Calls 6

cloneMethod · 0.95
countMethod · 0.95
initExtentForUnionFunction · 0.90
getIndicesCtorFunction · 0.85
_updateGetRawIdxMethod · 0.80
getRawIndexMethod · 0.65

Tested by

no test coverage detected