Let tooltips use time formatted labels if they exist

This commit is contained in:
Tanner Linsley 2015-09-11 12:20:32 -06:00
parent c2a7e4c251
commit 88d30d8c93
2 changed files with 11 additions and 1 deletions

View File

@ -164,7 +164,11 @@
x: medianPosition.x,
y: medianPosition.y,
labels: labels,
title: this._data.labels && this._data.labels.length ? this._data.labels[this._active[0]._index] : '',
title: (function() {
return this._data.timeLabels ? this._data.timeLabels[this._active[0]._index] :
(this._data.labels && this._data.labels.length) ? this._data.labels[this._active[0]._index] :
'';
}).call(this),
legendColors: colors,
legendBackgroundColor: this._options.tooltips.multiKeyBackground,
});

View File

@ -69,6 +69,8 @@
this.labels = [];
// A map of original labelIndex to time labelIndex
this.timeLabelIndexMap = {};
// The time formatted versions of the labels for use by tooltips
this.data.timeLabels = [];
var definedMoments = [];
@ -134,6 +136,10 @@
helpers.each(definedMoments, function(definedMoment, index) {
this.timeLabelIndexMap[index] = momentRangeLength - this.lastMoment.diff(definedMoment, this.timeUnit);
this.data.timeLabels.push(
definedMoment
.format(this.options.time.display ? this.options.time.display : this.displayFormat)
);
}, this);
// For every unit in between the first and last moment, create a moment and add it to the labels tick