diff --git a/samples/doughnut.html b/samples/doughnut.html index f0ebd5129..42647557c 100644 --- a/samples/doughnut.html +++ b/samples/doughnut.html @@ -44,6 +44,7 @@ }; var config = { + type: 'doughnut', data: { datasets: [{ data: [ @@ -123,7 +124,7 @@ window.onload = function() { var ctx = document.getElementById("chart-area").getContext("2d"); - window.myDoughnut = Chart.Doughnut(ctx, config); + window.myDoughnut = new Chart(ctx, config); console.log(window.myDoughnut); updateLegend(); diff --git a/src/charts/Chart.Doughnut.js b/src/charts/Chart.Doughnut.js index 74c917323..ae8ff7760 100644 --- a/src/charts/Chart.Doughnut.js +++ b/src/charts/Chart.Doughnut.js @@ -5,29 +5,7 @@ var Chart = root.Chart; var helpers = Chart.helpers; - var defaultConfig = { - aspectRatio: 1, - legendCallback: function(chart) { - var text = []; - text.push(''); - return text.join(""); - } - }; - Chart.Doughnut = function(context, config) { - config.options = helpers.configMerge(defaultConfig, config.options); config.type = 'doughnut'; return new Chart(context, config); diff --git a/src/charts/Chart.PolarArea.js b/src/charts/Chart.PolarArea.js index 2b44bb9aa..0ddf70433 100644 --- a/src/charts/Chart.PolarArea.js +++ b/src/charts/Chart.PolarArea.js @@ -5,29 +5,7 @@ var Chart = root.Chart; var helpers = Chart.helpers; - var defaultConfig = { - aspectRatio: 1, - legendCallback: function(chart) { - var text = []; - text.push(''); - return text.join(""); - } - }; - Chart.PolarArea = function(context, config) { - config.options = helpers.configMerge(defaultConfig, config.options); config.type = 'polarArea'; return new Chart(context, config); diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index 0efb57fbb..250279a56 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -13,9 +13,35 @@ //Boolean - Whether we animate scaling the Doughnut from the centre animateScale: false, }, + aspectRatio: 1, hover: { mode: 'single' }, + legendCallback: function(chart) { + var text = []; + text.push(''); + return text.join(""); + }, + legend: { + labels: { + generateLabels: function(data) { + return data.labels.slice(); + } + } + }, + //The percentage of the chart that we cut out of the middle. cutoutPercentage: 50, diff --git a/src/controllers/controller.polarArea.js b/src/controllers/controller.polarArea.js index b8fae6f87..06847a31b 100644 --- a/src/controllers/controller.polarArea.js +++ b/src/controllers/controller.polarArea.js @@ -18,6 +18,32 @@ animateRotate: true, animateScale: true, + aspectRatio: 1, + legendCallback: function(chart) { + var text = []; + text.push(''); + return text.join(""); + }, + legend: { + labels: { + generateLabels: function(data) { + return data.labels.slice(); + } + } + }, + // Need to override these to give a nice default tooltips: { callbacks: { diff --git a/src/core/core.legend.js b/src/core/core.legend.js index 5a5274622..1ce764742 100644 --- a/src/core/core.legend.js +++ b/src/core/core.legend.js @@ -22,6 +22,13 @@ callback: function(dataset) { return '' + dataset.label; }, + + // Generates labels shown in the legend + generateLabels: function(data) { + return data.datasets.map(function(dataset) { + return this.options.labels.callback.call(this, dataset); + }, this); + } }, }; @@ -29,10 +36,12 @@ initialize: function(config) { helpers.extend(this, config); - this.options = helpers.configMerge(Chart.defaults.global.legend, config.options); // Contains hit boxes for each dataset (in dataset order) this.legendHitBoxes = []; + + // Are we in doughnut mode which has a different data type + this.doughnutMode = false; }, // These methods are ordered by lifecyle. Utilities then follow. @@ -107,9 +116,7 @@ beforeBuildLabels: helpers.noop, buildLabels: function() { - this.labels = this.chart.data.datasets.map(function(dataset) { - return this.options.labels.callback.call(this, dataset); - }, this); + this.labels = this.options.labels.generateLabels.call(this, this.chart.data); }, afterBuildLabels: helpers.noop, @@ -208,7 +215,6 @@ ctx.font = labelFont; helpers.each(this.labels, function(label, i) { - var dataset = this.chart.data.datasets[i]; var backgroundColor = dataset.backgroundColor; var borderColor = dataset.borderColor;