* Returns an array of {time, pos} objects used to interpolate a specific `time` or position * (`pos`) on the scale, by searching entries before and after the requested value. `pos` is * a decimal between 0 and 1: 0 being the start of the scale (left or top) and 1 the other * extremity (left +
(timestamps)
| 77 | * @protected |
| 78 | */ |
| 79 | buildLookupTable(timestamps) { |
| 80 | const {min, max} = this; |
| 81 | const items = []; |
| 82 | const table = []; |
| 83 | let i, ilen, prev, curr, next; |
| 84 | |
| 85 | for (i = 0, ilen = timestamps.length; i < ilen; ++i) { |
| 86 | curr = timestamps[i]; |
| 87 | if (curr >= min && curr <= max) { |
| 88 | items.push(curr); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if (items.length < 2) { |
| 93 | // In case there is less that 2 timestamps between min and max, the scale is defined by min and max |
| 94 | return [ |
| 95 | {time: min, pos: 0}, |
| 96 | {time: max, pos: 1} |
| 97 | ]; |
| 98 | } |
| 99 | |
| 100 | for (i = 0, ilen = items.length; i < ilen; ++i) { |
| 101 | next = items[i + 1]; |
| 102 | prev = items[i - 1]; |
| 103 | curr = items[i]; |
| 104 | |
| 105 | // only add points that breaks the scale linearity |
| 106 | if (Math.round((next + prev) / 2) !== curr) { |
| 107 | table.push({time: curr, pos: i / (ilen - 1)}); |
| 108 | } |
| 109 | } |
| 110 | return table; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Generates all timestamps defined in the data. |