MCPcopy
hub / github.com/apache/echarts / minmaxDownSample

Method minmaxDownSample

src/data/DataStore.ts:969–1031  ·  view source on GitHub ↗

* Large data down sampling using min-max * @param {string} valueDimension * @param {number} rate

(
        valueDimension: DimensionIndex,
        rate: number
    )

Source from the content-addressed store, hash-verified

967 * @param {number} rate
968 */
969 minmaxDownSample(
970 valueDimension: DimensionIndex,
971 rate: number
972 ): DataStore {
973 const target = this.clone([valueDimension], true);
974 const targetStorage = target._chunks;
975
976 const frameSize = Math.floor(1 / rate);
977
978 const dimStore = targetStorage[valueDimension];
979 const len = this.count();
980
981 // Each frame results in 2 data points, one for min and one for max
982 const newIndices = new (getIndicesCtor(this._rawCount))(Math.ceil(len / frameSize) * 2);
983
984 let offset = 0;
985 for (let i = 0; i < len; i += frameSize) {
986 let minIndex = i;
987 let minValue = dimStore[this.getRawIndex(minIndex)];
988 let maxIndex = i;
989 let maxValue = dimStore[this.getRawIndex(maxIndex)];
990
991 let thisFrameSize = frameSize;
992 // Handle final smaller frame
993 if (i + frameSize > len) {
994 thisFrameSize = len - i;
995 }
996 // Determine min and max within the current frame
997 for (let k = 0; k < thisFrameSize; k++) {
998 const rawIndex = this.getRawIndex(i + k);
999 const value = dimStore[rawIndex];
1000
1001 if (value < minValue) {
1002 minValue = value;
1003 minIndex = i + k;
1004 }
1005 if (value > maxValue) {
1006 maxValue = value;
1007 maxIndex = i + k;
1008 }
1009 }
1010
1011 const rawMinIndex = this.getRawIndex(minIndex);
1012 const rawMaxIndex = this.getRawIndex(maxIndex);
1013
1014 // Set the order of the min and max values, based on their ordering in the frame
1015 if (minIndex < maxIndex) {
1016 newIndices[offset++] = rawMinIndex;
1017 newIndices[offset++] = rawMaxIndex;
1018 }
1019 else {
1020 newIndices[offset++] = rawMaxIndex;
1021 newIndices[offset++] = rawMinIndex;
1022 }
1023 }
1024
1025 target._count = offset;
1026 target._indices = newIndices;

Callers 1

dataSampleFunction · 0.45

Calls 5

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

Tested by

no test coverage detected