From: Evert Timberg Date: Tue, 19 May 2015 22:22:05 +0000 (-0400) Subject: Clean up the scale service. It's now more of a helper function for fitting the scales... X-Git-Tag: v2.0-alpha~8^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4cc24d475ab69047b0cab2d47f214c334ed1b404;p=thirdparty%2FChart.js.git Clean up the scale service. It's now more of a helper function for fitting the scales. Since each chart needed to know it's scales, there wasn't much point in registering them into the service. When we support overlapping charts, we can do something fancier --- diff --git a/src/Chart.Scale.js b/src/Chart.Scale.js index 96897f671..b7db8c1ba 100644 --- a/src/Chart.Scale.js +++ b/src/Chart.Scale.js @@ -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"; }); @@ -282,7 +238,7 @@ helpers.each(bottomScales, horizontalScalePlacer); // Step 8 - chartScaleWrapper.chartInstance.chartArea = { + chartInstance.chartArea = { left: totalLeftWidth, top: totalTopHeight, right: totalLeftWidth + maxChartWidth, diff --git a/src/Chart.Scatter.js b/src/Chart.Scatter.js index 8267f2a8b..d1c2cf10b 100644 --- a/src/Chart.Scatter.js +++ b/src/Chart.Scatter.js @@ -451,7 +451,6 @@ }); this.scales[scale.id] = scale; - Chart.scaleService.registerChartScale(this, scale); }, this); helpers.each(this.options.scales.yAxes, function(yAxisOptions) { @@ -464,7 +463,6 @@ }); this.scales[scale.id] = scale; - Chart.scaleService.registerChartScale(this, scale); }, this); }, redraw: function() { @@ -475,10 +473,8 @@ 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);