* Select data in range. (For optimization of filter) * (Manually inline code, support 5 million data filtering in data zoom.)
(range: {[dimIdx: number]: [number, number]})
| 665 | * (Manually inline code, support 5 million data filtering in data zoom.) |
| 666 | */ |
| 667 | selectRange(range: {[dimIdx: number]: [number, number]}): DataStore { |
| 668 | const newStore = this.clone(); |
| 669 | |
| 670 | const len = newStore._count; |
| 671 | |
| 672 | if (!len) { |
| 673 | return this; |
| 674 | } |
| 675 | |
| 676 | const dims = keys(range); |
| 677 | const dimSize = dims.length; |
| 678 | if (!dimSize) { |
| 679 | return this; |
| 680 | } |
| 681 | |
| 682 | const originalCount = newStore.count(); |
| 683 | const Ctor = getIndicesCtor(newStore._rawCount); |
| 684 | const newIndices = new Ctor(originalCount); |
| 685 | |
| 686 | let offset = 0; |
| 687 | const dim0 = dims[0]; |
| 688 | |
| 689 | const min = range[dim0][0]; |
| 690 | const max = range[dim0][1]; |
| 691 | const storeArr = newStore._chunks; |
| 692 | |
| 693 | let quickFinished = false; |
| 694 | if (!newStore._indices) { |
| 695 | // Extreme optimization for common case. About 2x faster in chrome. |
| 696 | let idx = 0; |
| 697 | if (dimSize === 1) { |
| 698 | const dimStorage = storeArr[dims[0]]; |
| 699 | for (let i = 0; i < len; i++) { |
| 700 | const val = dimStorage[i]; |
| 701 | // NaN will not be filtered. Consider the case, in line chart, empty |
| 702 | // value indicates the line should be broken. But for the case like |
| 703 | // scatter plot, a data item with empty value will not be rendered, |
| 704 | // but the axis extent may be effected if some other dim of the data |
| 705 | // item has value. Fortunately it is not a significant negative effect. |
| 706 | if ( |
| 707 | (val >= min && val <= max) || isNaN(val as any) |
| 708 | ) { |
| 709 | newIndices[offset++] = idx; |
| 710 | } |
| 711 | idx++; |
| 712 | } |
| 713 | quickFinished = true; |
| 714 | } |
| 715 | else if (dimSize === 2) { |
| 716 | const dimStorage = storeArr[dims[0]]; |
| 717 | const dimStorage2 = storeArr[dims[1]]; |
| 718 | const min2 = range[dims[1]][0]; |
| 719 | const max2 = range[dims[1]][1]; |
| 720 | for (let i = 0; i < len; i++) { |
| 721 | const val = dimStorage[i]; |
| 722 | const val2 = dimStorage2[i]; |
| 723 | // Do not filter NaN, see comment above. |
| 724 | if (( |
no test coverage detected