]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Convert title block to a plugin
authorEvert Timberg <evert.timberg+github@gmail.com>
Thu, 26 May 2016 01:28:02 +0000 (21:28 -0400)
committerEvert Timberg <evert.timberg+github@gmail.com>
Thu, 26 May 2016 01:28:02 +0000 (21:28 -0400)
src/chart.js
src/core/core.controller.js
src/core/core.legend.js
src/core/core.title.js

index f482369e93ac3e444b3edf3365f3d33a399ed4e9..90b9c77ee8af097f3f0e80bd90c4e086e1a7e618 100644 (file)
@@ -8,9 +8,9 @@ require('./core/core.datasetController')(Chart);
 require('./core/core.layoutService')(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.title')(Chart);
+require('./core/core.legend')(Chart);
 require('./core/core.tooltip')(Chart);
 
 require('./elements/element.arc')(Chart);
index b96f57d49e93908a47564f300fa22a8d9a03ab1d..e53faaf6a5e61fca79012048aecc156544bdb2f3 100644 (file)
@@ -167,7 +167,7 @@ module.exports = function(Chart) {
                },
 
                buildSurroundingItems: function() {
-                       if (this.options.title) {
+                       /*if (this.options.title) {
                                this.titleBlock = new Chart.Title({
                                        ctx: this.chart.ctx,
                                        options: this.options.title,
@@ -175,7 +175,7 @@ module.exports = function(Chart) {
                                });
 
                                Chart.layoutService.addBox(this, this.titleBlock);
-                       }
+                       }*/
                },
 
                updateLayout: function() {
index e3005ddfe3f7fa33efd7088d0cf18acef9607cc5..f625bb8818e4b93d33ddf6a9f491f9f49cab8580 100644 (file)
@@ -363,5 +363,5 @@ module.exports = function(Chart) {
                                Chart.layoutService.addBox(chartInstance, chartInstance.legend);
                        }
                }
-       })
+       });
 };
index b6d82c07ed112f61fea26301f54781b53f295cc9..ab969d461c31e3ed1d21e225476f999029c40c5c 100644 (file)
@@ -177,4 +177,22 @@ module.exports = function(Chart) {
                        }
                }
        });
+
+       // Register the title plugin
+       Chart.pluginService.register({
+               beforeInit: function(chartInstance) {
+                       var opts = chartInstance.options;
+                       var titleOpts = opts.title;
+
+                       if (titleOpts) {
+                               chartInstance.titleBlock = new Chart.Title({
+                                       ctx: chartInstance.chart.ctx,
+                                       options: titleOpts,
+                                       chart: chartInstance
+                               });
+
+                               Chart.layoutService.addBox(chartInstance, chartInstance.titleBlock);
+                       }
+               }
+       });
 };
\ No newline at end of file