]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Legend is attached to the graph as a plugin.
authorEvert Timberg <evert.timberg+github@gmail.com>
Thu, 26 May 2016 01:23:46 +0000 (21:23 -0400)
committerEvert Timberg <evert.timberg+github@gmail.com>
Thu, 26 May 2016 01:23:46 +0000 (21:23 -0400)
src/chart.js
src/core/core.controller.js
src/core/core.legend.js

index 58061c2ab6c2f6eb4669f74d8837fef239d79c61..f482369e93ac3e444b3edf3365f3d33a399ed4e9 100644 (file)
@@ -6,10 +6,10 @@ require('./core/core.animation')(Chart);
 require('./core/core.controller')(Chart);
 require('./core/core.datasetController')(Chart);
 require('./core/core.layoutService')(Chart);
-require('./core/core.legend')(Chart);
+require('./core/core.scaleService')(Chart);
 require('./core/core.plugin.js')(Chart);
+require('./core/core.legend')(Chart);
 require('./core/core.scale')(Chart);
-require('./core/core.scaleService')(Chart);
 require('./core/core.title')(Chart);
 require('./core/core.tooltip')(Chart);
 
index 36edf9e7a931dbf8368be86d27cf185251434f82..b96f57d49e93908a47564f300fa22a8d9a03ab1d 100644 (file)
@@ -176,16 +176,6 @@ module.exports = function(Chart) {
 
                                Chart.layoutService.addBox(this, this.titleBlock);
                        }
-
-                       if (this.options.legend) {
-                               this.legend = new Chart.Legend({
-                                       ctx: this.chart.ctx,
-                                       options: this.options.legend,
-                                       chart: this
-                               });
-
-                               Chart.layoutService.addBox(this, this.legend);
-                       }
                },
 
                updateLayout: function() {
index b8ae19eb145d899585a339a0b466abfb2b1a7f6d..e3005ddfe3f7fa33efd7088d0cf18acef9607cc5 100644 (file)
@@ -347,4 +347,21 @@ module.exports = function(Chart) {
                }
        });
 
+       // Register the legend plugin
+       Chart.pluginService.register({
+               beforeInit: function(chartInstance) {
+                       var opts = chartInstance.options;
+                       var legendOpts = opts.legend;
+
+                       if (legendOpts) {
+                               chartInstance.legend = new Chart.Legend({
+                                       ctx: chartInstance.chart.ctx,
+                                       options: legendOpts,
+                                       chart: chartInstance
+                               });
+
+                               Chart.layoutService.addBox(chartInstance, chartInstance.legend);
+                       }
+               }
+       })
 };