diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index eb2b6f457b0..01b1cae8ad5 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -50,19 +50,36 @@ module.exports = function(Chart) { return a - b; } - function buildLookupTable(ticks, min, max, linear) { - var ilen = ticks.length; + /** + * 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. Since the + * value is linearly interpolated, only timestamps that break the time linearity are added, + * meaning that in the best case, it contains only 2 objects: {min, 0} and {max, 1}. `pos` is + * a decimal between 0 and 1: 0 being the start of the scale (left or top) and 1 the other + * extremity (left + width or top + height). Note that it would be more optimized to directly + * store pre-computed pixels, but the scale dimensions are not guaranty at the time we need + * to create the lookup table. + * + * @param {Number[]} timestamps - timestamps sorted from lowest to highest + * @param {Boolean} linear - if true, `pos` will be calculated to maintain the time linearity + * along the scale, else timestamps will be spread at the same distance form each other. + */ + function buildLookupTable(timestamps, linear) { + var ilen = timestamps.length; var table = []; - var i, prev, curr, next, pos; + var min, max, i, prev, curr, next, pos; if (ilen === 0) { return table; } + min = timestamps[0]; + max = timestamps[ilen - 1]; + for (i = 0; i