MDL-59790 core: fix tooltip for pie chart
authorSimey Lameze <simey@moodle.com>
Fri, 11 Aug 2017 03:07:29 +0000 (11:07 +0800)
committerSimey Lameze <simey@moodle.com>
Wed, 23 Aug 2017 02:03:00 +0000 (10:03 +0800)
lib/amd/build/chart_output_chartjs.min.js
lib/amd/src/chart_output_chartjs.js

index 69b06cd..1a27a54 100644 (file)
Binary files a/lib/amd/build/chart_output_chartjs.min.js and b/lib/amd/build/chart_output_chartjs.min.js differ
index 99656e8..ef34547 100644 (file)
@@ -293,11 +293,19 @@ define([
         var tooltipData = chartData[tooltipItem.index];
 
         // Build default tooltip.
-        var tooltip = this._cleanData(serieLabel) + ': ' + tooltipData;
+        var tooltip = [];
+
+        // Pie and doughnut charts does not have axis.
+        if (tooltipItem.xLabel == '' && tooltipItem.yLabel == '') {
+            var chartLabels = this._cleanData(this._chart.getLabels());
+            tooltip.push(chartLabels[tooltipItem.index]);
+        }
 
         // Add series labels to the tooltip if any.
         if (serieLabels !== null) {
-            tooltip = this._cleanData(serieLabels[tooltipItem.index]);
+            tooltip.push(this._cleanData(serieLabels[tooltipItem.index]));
+        } else {
+            tooltip.push(this._cleanData(serieLabel) + ': ' + tooltipData);
         }
 
         return tooltip;