From: Tanner Linsley Date: Fri, 11 Sep 2015 18:20:32 +0000 (-0600) Subject: Let tooltips use time formatted labels if they exist X-Git-Tag: 2.0.0-alpha4~26^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88d30d8c935bdeddc589fe7bc736be1263863b68;p=thirdparty%2FChart.js.git Let tooltips use time formatted labels if they exist --- diff --git a/src/core/core.tooltip.js b/src/core/core.tooltip.js index 3f4a892c4..92e2b1364 100644 --- a/src/core/core.tooltip.js +++ b/src/core/core.tooltip.js @@ -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, }); diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index dc36742ac..cbf6473ca 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -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