]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Update controllers to handle adding new datasets
authorEvert Timberg <evert.timberg@gmail.com>
Wed, 17 Jun 2015 02:04:52 +0000 (22:04 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Wed, 17 Jun 2015 02:04:52 +0000 (22:04 -0400)
src/controllers/controller.bar.js
src/controllers/controller.doughnut.js
src/controllers/controller.line.js
src/controllers/controller.polarArea.js
src/controllers/controller.radar.js
src/core/core.controller.js

index 0bb92041d6926d7a00c482a14e058cf5ea895a53..e4f7fa918cb67ceaf52419a85b3864e5c28cb4d4 100644 (file)
@@ -40,7 +40,9 @@
                        this.linkScales();
                        this.addElements();
                },
-
+               updateIndex: function(datasetIndex) {
+                       this.index = datasetIndex;
+               },
                linkScales: function() {
                        if (!this.getDataset().xAxisID) {
                                this.getDataset().xAxisID = this.chart.options.scales.xAxes[0].id;
index 795f0d1155cb63f206da7addcab4ab75fb6b1104..dc8cbdc352be3609459a2e26a20aab70238d5990 100644 (file)
@@ -38,7 +38,9 @@
                        this.linkScales();
                        this.addElements();
                },
-
+               updateIndex: function(datasetIndex) {
+                       this.index = datasetIndex;
+               },
                linkScales: function() {
                        // no scales for doughnut
                },
index 19c9d6f53542a8f6b6bf0771d98b10d1ab37b188..2e3e341e299e23b70995a6918ed875be7c57ad0d 100644 (file)
@@ -36,6 +36,9 @@
                        this.linkScales();
                        this.addElements();
                },
+               updateIndex: function(datasetIndex) {
+                       this.index = datasetIndex;
+               },
 
                linkScales: function() {
                        if (!this.getDataset().xAxisID) {
index 2aa0e49891682672660fea5a42aacddac44116c7..733ab9dc6d0b39ef10e7822fe5896af12628fb19 100644 (file)
@@ -30,6 +30,9 @@
                        this.linkScales();
                        this.addElements();
                },
+               updateIndex: function(datasetIndex) {
+                       this.index = datasetIndex;
+               },
 
                linkScales: function() {
                        // no scales for doughnut
index 28c0f2ca8fb8a584aa0f161d04662f5c8f07882b..df35de5b1925ea841e33ef171f1bffad86f57cb8 100644 (file)
@@ -31,6 +31,9 @@
                        this.linkScales();
                        this.addElements();
                },
+               updateIndex: function(datasetIndex) {
+                       this.index = datasetIndex;
+               },
 
                linkScales: function() {
                        // No need. Single scale only
index ac081a748bc9bea39960270b8e068c5b1e35ae56..1d098e8907db884789ba3c8593987365fece9f57 100644 (file)
@@ -52,7 +52,7 @@
                        // Make sure controllers are built first so that each dataset is bound to an axis before the scales
                        // are built
                        this.ensureScalesHaveIDs();
-                       this.buildControllers();
+                       this.buildOrUpdateControllers();
                        this.buildScales();
                        this.resetElements();
                        this.initToolTip();
                        return this;
                },
 
+               addDataset: function addDataset(dataset, index) {
+                       if (index !== undefined) {
+                               this.data.datasets.splice(index, 0, dataset);
+                       } else {
+                               this.data.datasets.push(dataset);
+                       }
+                       
+                       this.buildOrUpdateControllers();
+                       dataset.controller.reset(); // so that animation looks ok
+                       this.update();
+               },
+               removeDataset: function removeDataset(index) {
+                       this.data.datasets.splice(index, 1);
+                       this.buildOrUpdateControllers();
+                       this.update();
+               },
+
                resize: function resize(silent) {
                        this.stop();
                        var canvas = this.chart.canvas,
                        Chart.scaleService.fitScalesForChart(this, this.chart.width, this.chart.height);
                },
 
-               buildControllers: function() {
+               buildOrUpdateControllers: function() {
                        helpers.each(this.data.datasets, function(dataset, datasetIndex) {
                                var type = dataset.type || this.config.type;
                                if (dataset.controller) {