]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix: no tooltips when missing data for one or more dataset
authorPascoual <pascoualito@gmail.com>
Mon, 9 Nov 2015 23:53:08 +0000 (00:53 +0100)
committerPascoual <pascoualito@gmail.com>
Mon, 9 Nov 2015 23:53:08 +0000 (00:53 +0100)
src/core/core.controller.js
src/core/core.tooltip.js

index 8c46fd4dfa5700b17ffecb8dd0609e55d514c19a..1d3e42ccb267e8e05192d4732479bf13b60031b6 100644 (file)
                                        case 'label':
                                        case 'dataset':
                                                for (var i = 0; i < this.lastActive.length; i++) {
-                                                       this.data.datasets[this.lastActive[i]._datasetIndex].controller.removeHoverStyle(this.lastActive[i], this.lastActive[i]._datasetIndex, this.lastActive[i]._index);
+                            if (this.lastActive[i])
+                                                           this.data.datasets[this.lastActive[i]._datasetIndex].controller.removeHoverStyle(this.lastActive[i], this.lastActive[i]._datasetIndex, this.lastActive[i]._index);
                                                }
                                                break;
                                        default:
                                        case 'label':
                                        case 'dataset':
                                                for (var j = 0; j < this.active.length; j++) {
-                                                       this.data.datasets[this.active[j]._datasetIndex].controller.setHoverStyle(this.active[j]);
+                            if (this.active[j])
+                                                           this.data.datasets[this.active[j]._datasetIndex].controller.setHoverStyle(this.active[j]);
                                                }
                                                break;
                                        default:
index 03b833dff107b7a50325de6e932ac077e6badb4f..9b87df38836cb06f9ff21e9c0ca55fad2b6fde4f 100644 (file)
                        var yPositions = [];
 
                        helpers.each(elements, function(el){
-                               var pos = el.tooltipPosition();
-                               xPositions.push(pos.x);
-                               yPositions.push(pos.y);
+                               if(el) {
+                                       var pos = el.tooltipPosition();
+                                       xPositions.push(pos.x);
+                                       yPositions.push(pos.y);
+                               }
                        });
 
                        var x = 0, y = 0;
                                                        return;
                                                }
                                                var currentElement = dataset.metaData[element._index];
-                                               var yScale = element._yScale || element._scale; // handle radar || polarArea charts
-
-                                               tooltipItems.push({
-                                                       xLabel: currentElement._xScale ? currentElement._xScale.getLabelForIndex(currentElement._index, currentElement._datasetIndex) : '',
-                                                       yLabel: yScale ? yScale.getLabelForIndex(currentElement._index, currentElement._datasetIndex) : '',
-                                                       index: element._index,
-                                                       datasetIndex: datasetIndex,
-                                               });
+                                               if (currentElement) {
+                                                       var yScale = element._yScale || element._scale; // handle radar || polarArea charts
+
+                                                       tooltipItems.push({
+                                                               xLabel: currentElement._xScale ? currentElement._xScale.getLabelForIndex(currentElement._index, currentElement._datasetIndex) : '',
+                                                               yLabel: yScale ? yScale.getLabelForIndex(currentElement._index, currentElement._datasetIndex) : '',
+                                                               index: element._index,
+                                                               datasetIndex: datasetIndex,
+                                                       });
+                                               }
                                        });
 
                                        helpers.each(this._active, function(active, i) {
-                                               labelColors.push({
-                                                       borderColor: active._view.borderColor,
-                                                       backgroundColor: active._view.backgroundColor
-                                               });
+                                               if (active) {
+                                                 labelColors.push({
+                                                       borderColor: active._view.borderColor,
+                                                       backgroundColor: active._view.backgroundColor
+                                                 });
+                                               }
                                        }, this);
 
                                        tooltipPosition = this.getAveragePosition(this._active);