Skip to content

Commit 10f89d9

Browse files
committed
Time scale performance improvement
1 parent 6e9e52a commit 10f89d9

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/scales/scale.time.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -409,21 +409,12 @@ function ticksFromTimestamps(values, majorUnit) {
409409
/**
410410
* Return the time format for the label with the most parts (milliseconds, second, etc.)
411411
*/
412-
function determineLabelFormat(timestamps) {
412+
function determineLabelFormat(timestamp) {
413413
var presets = adapter.presets();
414-
var ilen = timestamps.length;
415-
var i, ts, hasTime;
416-
417-
for (i = 0; i < ilen; i++) {
418-
ts = timestamps[i];
419-
if (ts % INTERVALS.second.size !== 0) {
420-
return presets.full;
421-
}
422-
if (!hasTime && adapter.startOf(ts, 'day') !== ts) {
423-
hasTime = true;
424-
}
414+
if (timestamp % INTERVALS.second.size !== 0) {
415+
return presets.full;
425416
}
426-
if (hasTime) {
417+
if (adapter.startOf(timestamp, 'day') !== timestamp) {
427418
return presets.time;
428419
}
429420
return presets.date;
@@ -638,7 +629,6 @@ module.exports = Scale.extend({
638629
me._majorUnit = determineMajorUnit(me._unit);
639630
me._table = buildLookupTable(me._timestamps.data, min, max, options.distribution);
640631
me._offsets = computeOffsets(me._table, ticks, min, max, options);
641-
me._labelFormat = determineLabelFormat(me._timestamps.data);
642632

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

657648
if (helpers.isObject(value)) {
658649
label = me.getRightValue(value);
@@ -664,7 +655,8 @@ module.exports = Scale.extend({
664655
return label;
665656
}
666657

667-
return adapter.format(toTimestamp(label, timeOpts), me._labelFormat);
658+
ts = toTimestamp(label, timeOpts);
659+
return adapter.format(ts, determineLabelFormat(ts));
668660
},
669661

670662
/**

0 commit comments

Comments
 (0)