Skip to content

Commit

Permalink
Time scale performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Feb 3, 2019
1 parent 6e9e52a commit 10f89d9
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,21 +409,12 @@ function ticksFromTimestamps(values, majorUnit) {
/**
* Return the time format for the label with the most parts (milliseconds, second, etc.)
*/
function determineLabelFormat(timestamps) {
function determineLabelFormat(timestamp) {
var presets = adapter.presets();
var ilen = timestamps.length;
var i, ts, hasTime;

for (i = 0; i < ilen; i++) {
ts = timestamps[i];
if (ts % INTERVALS.second.size !== 0) {
return presets.full;
}
if (!hasTime && adapter.startOf(ts, 'day') !== ts) {
hasTime = true;
}
if (timestamp % INTERVALS.second.size !== 0) {
return presets.full;
}
if (hasTime) {
if (adapter.startOf(timestamp, 'day') !== timestamp) {
return presets.time;
}
return presets.date;
Expand Down Expand Up @@ -638,7 +629,6 @@ module.exports = Scale.extend({
me._majorUnit = determineMajorUnit(me._unit);
me._table = buildLookupTable(me._timestamps.data, min, max, options.distribution);
me._offsets = computeOffsets(me._table, ticks, min, max, options);
me._labelFormat = determineLabelFormat(me._timestamps.data);

if (options.ticks.reverse) {
ticks.reverse();
Expand All @@ -653,6 +643,7 @@ module.exports = Scale.extend({
var timeOpts = me.options.time;
var label = data.labels && index < data.labels.length ? data.labels[index] : '';
var value = data.datasets[datasetIndex].data[index];
var ts;

if (helpers.isObject(value)) {
label = me.getRightValue(value);
Expand All @@ -664,7 +655,8 @@ module.exports = Scale.extend({
return label;
}

return adapter.format(toTimestamp(label, timeOpts), me._labelFormat);
ts = toTimestamp(label, timeOpts);
return adapter.format(ts, determineLabelFormat(ts));
},

/**
Expand Down

0 comments on commit 10f89d9

Please sign in to comment.