| 488 | } |
| 489 | |
| 490 | private reduceIntervals(indices: number[]) { |
| 491 | //for a series of indices, reduces them to the minimum possible |
| 492 | //intervals on which the search can be performed. |
| 493 | //return value is an array of arrays containing the start and end |
| 494 | //points of the intervals represented by the indices. |
| 495 | const intervals = []; |
| 496 | const nBins = this.model.bins; |
| 497 | const barWidth = (this.model.maxX - this.model.minX) / this.model.bins; |
| 498 | |
| 499 | if (indices.length !== 0) { |
| 500 | indices.sort(); |
| 501 | let start = indices[0]; |
| 502 | let end = indices[0]; |
| 503 | for (let iter = 1; iter < indices.length; iter++) { |
| 504 | if (indices[iter] === end + 1) { |
| 505 | end++; |
| 506 | } else { |
| 507 | intervals.push([ |
| 508 | this.model.xBins[start], |
| 509 | end + 1 == nBins |
| 510 | ? this.model.xBins[nBins - 1] + barWidth |
| 511 | : this.model.xBins[end + 1], |
| 512 | ]); |
| 513 | start = end = indices[iter]; |
| 514 | } |
| 515 | } |
| 516 | intervals.push([ |
| 517 | this.model.xBins[start], |
| 518 | end + 1 == nBins |
| 519 | ? this.model.xBins[nBins - 1] + barWidth |
| 520 | : this.model.xBins[end + 1], |
| 521 | ]); |
| 522 | } |
| 523 | return intervals; |
| 524 | } |
| 525 | |
| 526 | private dataIndexToBarIndex(selected) { |
| 527 | //function to calculate bar indices for a given list of data |