]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Factor out `getLabelForIndex` into each scale so we can return appropriate data based...
authoretimberg <evert.timberg@gmail.com>
Sun, 18 Oct 2015 20:13:57 +0000 (16:13 -0400)
committeretimberg <evert.timberg@gmail.com>
Sun, 18 Oct 2015 20:13:57 +0000 (16:13 -0400)
src/core/core.scale.js
src/scales/scale.category.js
src/scales/scale.linear.js
src/scales/scale.logarithmic.js
src/scales/scale.time.js

index 854c48892f2b9ce09d105e4720a41826d718854a..a2e96eee912707d1780e828266d9f79827d1867b 100644 (file)
                        return this.options.position == "top" || this.options.position == "bottom";
                },
 
-               getLabelForIndex: function(index, datasetIndex) {
-                       if (this.isHorizontal()) {
-                               return this.data.datasets[datasetIndex].label || this.data.labels[index];
-                       }
-                       return this.data.datasets[datasetIndex].data[index];
-               },
+               // Used to get the value to display in the tooltip for the data at the given index
+               // function getLabelForIndex(index, datasetIndex)
+               getLabelForIndex: helpers.noop,
 
                // Used to get data value locations.  Value can either be an index or a numerical value
                getPixelForValue: helpers.noop,
index a2e569d4cfaa5e5ee3f9b4851e16ee2644694c25..7c7656bcb56bf1d134cc7825c3a7b27fbcdd1657 100644 (file)
             this.ticks = this.data.labels;
         },
 
+        getLabelForIndex: function(index, datasetIndex) {
+            return this.ticks[index];
+        },
+
         // Used to get data value locations.  Value can either be an index or a numerical value
         getPixelForValue: function(value, index, datasetIndex, includeOffset) {
 
index d522ae91cf6fe7ce972d93459b386f3ddd329e52..9b36820d8beb53b766d3d6cf029088a74ffc5b5b 100644 (file)
                        this.zeroLineIndex = this.ticks.indexOf(0);
                },
 
+               getLabelForIndex: function(index, datasetIndex) {
+                       return this.getRightValue(this.data.datasets[datasetIndex].data[index]);
+               },
+
                // Utils
                getPixelForValue: function(value, index, datasetIndex, includeOffset) {
                        // This must be called after fit has been run so that 
index 2db11bf2801c600137af42d27233bdc2663a5e08..c8ce9bbbaf9ec6ed0c45b1932ea5b85f5bdb3def 100644 (file)
 
                        this.ticks = this.tickValues.slice();
                },
+               // Get the correct tooltip label
+               getLabelForIndex: function(index, datasetIndex) {
+                       return this.getRightValue(this.data.datasets[datasetIndex].data[index]);
+               },
                // Get the correct value. If the value type is object get the x or y based on whether we are horizontal or not
                getRightValue: function(rawValue) {
                        return typeof rawValue === "object" ? (this.isHorizontal() ? rawValue.x : rawValue.y) : rawValue;
index 9ba486ce42297057815110a56cb4ed6f25010d16..87b54ca84487c99ae1b121b8d22b08c60cccfb2d 100644 (file)
                                this.ticks.push(this.firstTick.clone().add(i, this.tickUnit));
                        }
                },
+               // Get tooltip label
+               getLabelForIndex: function(index, datasetIndex) {
+                       return this.data.labels[index];
+               },
                convertTicksToLabels: function() {
                        this.ticks = this.ticks.map(function(tick, index, ticks) {
                                var formattedTick = tick.format(this.options.time.displayFormat ? this.options.time.displayFormat : time.unit[this.tickUnit].display);