]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Clean up the scale service. It's now more of a helper function for fitting the scales...
authorEvert Timberg <evert.timberg@gmail.com>
Tue, 19 May 2015 22:22:05 +0000 (18:22 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Tue, 19 May 2015 22:22:05 +0000 (18:22 -0400)
src/Chart.Scale.js
src/Chart.Scatter.js

index 96897f671d2aad3b9ca8405cde4ef371728e9f23..b7db8c1bae495925df90089338f9317c708b7b9e 100644 (file)
@@ -9,66 +9,22 @@
        // a service where scales are registered with their respective charts so that changing the 
        // scales does not require 
        Chart.scaleService = {
-               registeredCharts: [],
-               getWrapperForChart: function(chartInstance) {
-                       var wrapper = helpers.findNextWhere(this.registeredCharts, function(charScaleWrapper) {
-                               return charScaleWrapper.chartInstance == chartInstance;
-                       });
-                       
-                       return wrapper;
-               },
-               registerChartScale: function(chartInstance, scaleInstance) {
-                       var chartScaleWrapper = this.getWrapperForChart(chartInstance);
-                       
-                       if (!chartScaleWrapper) {
-                               chartScaleWrapper = {
-                                       scales: [],
-                                       chartInstance: chartInstance,
-                               };
-                               
-                               this.registeredCharts.push(chartScaleWrapper);
-                       }
-                       
-                       chartScaleWrapper.scales.push(scaleInstance);
-               },
-               removeChartScale: function(chartInstance, scaleInstance) {
-                       var chartScaleWrapper = this.getWrapperForChart(chartInstance);
-                       
-                       if (chartScaleWrapper) {
-                               var scaleIndex = helpers.indexOf(scaleWrapper.scales, scaleInstance);
-                               
-                               if (scaleIndex) {
-                                       scaleWrapper.scales.splice(scaleIndex, 1);
-                               }
-                       }
-               },
-               // Remove a chart instance from the scale service. Useful when a chart is destroyed
-               removeChartInstance: function(chartInstance) {
-                       var index = helpers.findNextWhere(this.registeredCharts, function(scaleWrapper) {
-                               return scaleWrapper.chartInstance == chartInstance;
-                       });
-                       
-                       if (index) {
-                               this.registeredCharts.splice(index, 1);
-                       }
-               },
                // The interesting function
                fitScalesForChart: function(chartInstance, width, height) {
-                       var chartScaleWrapper = this.getWrapperForChart(chartInstance);
                        var xPadding = 10;
                        var yPadding = 10;
                        
-                       if (chartScaleWrapper) {
-                               var leftScales = helpers.where(chartScaleWrapper.scales, function(scaleInstance) {
+                       if (chartInstance) {
+                               var leftScales = helpers.where(chartInstance.scales, function(scaleInstance) {
                                        return scaleInstance.options.position == "left";
                                });
-                               var rightScales = helpers.where(chartScaleWrapper.scales, function(scaleInstance) {
+                               var rightScales = helpers.where(chartInstance.scales, function(scaleInstance) {
                                        return scaleInstance.options.position == "right";
                                });
-                               var topScales = helpers.where(chartScaleWrapper.scales, function(scaleInstance) {
+                               var topScales = helpers.where(chartInstance.scales, function(scaleInstance) {
                                        return scaleInstance.options.position == "top";
                                });
-                               var bottomScales = helpers.where(chartScaleWrapper.scales, function(scaleInstance) {
+                               var bottomScales = helpers.where(chartInstance.scales, function(scaleInstance) {
                                        return scaleInstance.options.position == "bottom";
                                });
                                
                                helpers.each(bottomScales, horizontalScalePlacer);
                                
                                // Step 8
-                               chartScaleWrapper.chartInstance.chartArea = {
+                               chartInstance.chartArea = {
                                        left: totalLeftWidth,
                                        top: totalTopHeight,
                                        right: totalLeftWidth + maxChartWidth,
index 8267f2a8bc268028f9b967bcaa60dbb48c663513..d1c2cf10b5e22035afa05a12dba7e2eeffb4e9c8 100644 (file)
                 });
 
                 this.scales[scale.id] = scale;
-                Chart.scaleService.registerChartScale(this, scale);
             }, this);
 
             helpers.each(this.options.scales.yAxes, function(yAxisOptions) {
                 });
 
                 this.scales[scale.id] = scale;
-                Chart.scaleService.registerChartScale(this, scale);
             }, this);
         },
         redraw: function() {
             var easingDecimal = ease || 1;
             this.clear();
                        
-                       var chartScaleWrapper = Chart.scaleService.getWrapperForChart(this);
-                       
                        // Draw all the scales
-                       helpers.each(chartScaleWrapper.scales, function(scale) {
+                       helpers.each(this.scales, function(scale) {
                                scale.draw(this.chartArea);
                        }, this);