]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Let tooltips use time formatted labels if they exist
authorTanner Linsley <tannerlinsley@gmail.com>
Fri, 11 Sep 2015 18:20:32 +0000 (12:20 -0600)
committerTanner Linsley <tannerlinsley@gmail.com>
Fri, 11 Sep 2015 18:20:32 +0000 (12:20 -0600)
src/core/core.tooltip.js
src/scales/scale.time.js

index 3f4a892c41a11ba2c9ebefb7cb3b085367502457..92e2b136463f7c5c9a916cf9bfb7714a1553e6a5 100644 (file)
                                                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,
                                        });
index dc36742ac5ea2b2dbad2509dfb4109f24e2630b4..cbf6473ca6ee3def225d64c7bcf5e651d95cc122 100644 (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 = [];
 
 
                        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