]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix the broken scatter chart. Introduced the concept of a canvas controller that...
authorEvert Timberg <evert.timberg@gmail.com>
Sun, 14 Jun 2015 17:00:09 +0000 (13:00 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Sun, 14 Jun 2015 17:00:09 +0000 (13:00 -0400)
src/charts/chart.line.js
src/charts/chart.rectangularbase.js
src/controllers/controller.canvas.rectangular.js [new file with mode: 0644]
src/core/core.js

index 3f5407a9a83c92675a3ad490a95a1d4c6bd616be..f1d71eb506b9ba545b918375af91d7fc3d1daeb8 100644 (file)
                defaults: defaultConfig,
                initialize: function() {
 
-                       this.controller = new Chart.RectangularElementController(this);
+                       this.elementController = new Chart.RectangularElementController(this);
+                       this.canvasController = new Chart.RectangularCanvasController(this, this.elementController);
 
                        // Create a new line and its points for each dataset and piece of data
                        helpers.each(this.data.datasets, function(dataset, datasetIndex) {
-                               this.controller.addLine(dataset, datasetIndex);
+                               this.elementController.addLine(dataset, datasetIndex);
                                
                                helpers.each(dataset.data, function(dataPoint, index) {
-                                       this.controller.addPoint(dataset, datasetIndex, index);
+                                       this.elementController.addPoint(dataset, datasetIndex, index);
                                }, this);
 
                                // The line chart onlty supports a single x axis because the x axis is always a dataset axis
@@ -46,7 +47,7 @@
                                }
                        }, this);
 
-                       this.__super__.initialize.call(this);
+                       this.canvasController.initialize();
                },
                draw: function(ease) {
 
index eda983e7d670e5b41ecdb6015a53aa3b1697c833..76d03f5e3486ccc2cd50da6ed459cc871919464d 100644 (file)
        Chart.Type.extend({
                name: "RectangularBase",
                defaults: defaultConfig,
-               initialize: function() {
-                       // Events
-                       helpers.bindEvents(this, this.options.events, this.events);
-
-                       // Build and fit the scale. Needs to happen after the axis IDs have been set
-                       this.buildScales();
-
-                       // Create tooltip instance exclusively for this chart with some defaults.
-                       this.tooltip = new Chart.Tooltip({
-                               _chart: this.chart,
-                               _data: this.data,
-                               _options: this.options,
-                       }, this);
-
-                       // Need to fit scales before we reset elements. 
-                       Chart.scaleService.fitScalesForChart(this, this.chart.width, this.chart.height);
-
-                       // Reset so that we animation from the baseline
-                       this.resetElements();
-
-                       // Update that shiz
-                       this.update();
-               },
-               resetElements: function() {
-                       this.controller.resetElements();
-               },
                update: function(animationDuration) {
-
-                       Chart.scaleService.fitScalesForChart(this, this.chart.width, this.chart.height);
-                       this.controller.updateElements();
+                       this.canvasController.update();
                        this.render(animationDuration);
                },
-               buildScales: function() {
-                       // Map of scale ID to scale object so we can lookup later 
-                       this.scales = {};
-
-                       // Build the x axes
-                       helpers.each(this.options.scales.xAxes, function(xAxisOptions) {
-                               var ScaleClass = Chart.scaleService.getScaleConstructor(xAxisOptions.type);
-                               var scale = new ScaleClass({
-                                       ctx: this.chart.ctx,
-                                       options: xAxisOptions,
-                                       data: this.data,
-                                       id: xAxisOptions.id,
-                               });
-
-                               this.scales[scale.id] = scale;
-                       }, this);
-
-                       // Build the y axes
-                       helpers.each(this.options.scales.yAxes, function(yAxisOptions) {
-                               var ScaleClass = Chart.scaleService.getScaleConstructor(yAxisOptions.type);
-                               var scale = new ScaleClass({
-                                       ctx: this.chart.ctx,
-                                       options: yAxisOptions,
-                                       data: this.data,
-                                       id: yAxisOptions.id,
-                               });
-
-                               this.scales[scale.id] = scale;
-                       }, this);
-               },
                draw: helpers.noop,
                events: function(e) {
 
diff --git a/src/controllers/controller.canvas.rectangular.js b/src/controllers/controller.canvas.rectangular.js
new file mode 100644 (file)
index 0000000..b57cfab
--- /dev/null
@@ -0,0 +1,73 @@
+(function() {
+       "use strict";
+
+       var root = this,
+               Chart = root.Chart,
+               helpers = Chart.helpers;
+
+       Chart.RectangularCanvasController = function(chart, elementController) {
+               this.chart = chart;
+               this.elementController = elementController;
+       };
+
+       Chart.RectangularCanvasController.prototype.initialize = function() {
+               this.bindEvents();
+               this.buildScales();
+
+               // Need to fit scales before we reset elements. 
+               Chart.scaleService.fitScalesForChart(this.chart, this.chart.chart.width, this.chart.chart.height);
+               this.elementController.resetElements();
+
+               this.initToolTip();
+
+               this.chart.update();
+       };
+
+       Chart.RectangularCanvasController.prototype.bindEvents = function() {
+               helpers.bindEvents(this.chart, this.chart.options.events, this.chart.events);
+       };
+
+       Chart.RectangularCanvasController.prototype.initToolTip = function() {
+               this.chart.tooltip = new Chart.Tooltip({
+                       _chart: this.chart.chart,
+                       _data: this.chart.data,
+                       _options: this.chart.options,
+               }, this);
+       };
+
+       Chart.RectangularCanvasController.prototype.buildScales = function() {
+               // Map of scale ID to scale object so we can lookup later 
+               this.chart.scales = {};
+
+               // Build the x axes
+               helpers.each(this.chart.options.scales.xAxes, function(xAxisOptions) {
+                       var ScaleClass = Chart.scaleService.getScaleConstructor(xAxisOptions.type);
+                       var scale = new ScaleClass({
+                               ctx: this.chart.chart.ctx,
+                               options: xAxisOptions,
+                               data: this.chart.data,
+                               id: xAxisOptions.id,
+                       });
+
+                       this.chart.scales[scale.id] = scale;
+               }, this);
+
+               // Build the y axes
+               helpers.each(this.chart.options.scales.yAxes, function(yAxisOptions) {
+                       var ScaleClass = Chart.scaleService.getScaleConstructor(yAxisOptions.type);
+                       var scale = new ScaleClass({
+                               ctx: this.chart.chart.ctx,
+                               options: yAxisOptions,
+                               data: this.chart.data,
+                               id: yAxisOptions.id,
+                       });
+
+                       this.chart.scales[scale.id] = scale;
+               }, this);
+       };
+
+       Chart.RectangularCanvasController.prototype.update = function() {
+               Chart.scaleService.fitScalesForChart(this.chart, this.chart.chart.width, this.chart.chart.height);
+               this.elementController.updateElements();
+       };
+}).call(this);
index 9ed29d43e04965e210f3f7d44831e61db44eaf34..6328edd8296093bdcbb8c42176c56ec929eb9ed8 100755 (executable)
 
                        ChartElement.extend = inherits;
 
-                       if (extensions) extend(ChartElement.prototype, extensions);
+                       if (extensions) {
+                               extend(ChartElement.prototype, extensions);
+                       }
 
                        ChartElement.__super__ = parent.prototype;
 
 
                //Copy the prototype object of the this class
                ChartType.prototype = clone(parent.prototype);
-               ChartType.prototype.__super__ = clone(parent.prototype);
-               
+
                //Now overwrite some of the properties in the base class with the new extensions
                extend(ChartType.prototype, extensions);
-
-
                ChartType.extend = Chart.Type.extend;
 
                if (extensions.name || parent.prototype.name) {