From 1f3e5a20db82d15fe584fa4bf9291a2106c81a0e Mon Sep 17 00:00:00 2001 From: MDO Date: Tue, 17 May 2016 17:46:18 +0200 Subject: [PATCH] add directive chart-dataset-overload We could not set the options included in the chart dataset. We could only set the global options thanks to the directive chart-options. Therfore we could not set an option per chart like described in Issue https://github.com/jtblin/angular-chart.js/issues/370 . I added a directive chart-dataset-overload. If it is present, createChart will merge both the dataset and the data set overload at the final step of the dataset creation. --- angular-chart.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/angular-chart.js b/angular-chart.js index b90e8dbc..22b403e8 100644 --- a/angular-chart.js +++ b/angular-chart.js @@ -102,7 +102,8 @@ chartColors: '=?', chartClick: '=?', chartHover: '=?', - chartYAxes: '=?' + chartYAxes: '=?', + chartDatasetOverload: '=?' }, link: function (scope, elem/*, attrs */) { var chart; @@ -129,6 +130,7 @@ scope.$watch('chartLabels', resetChart, true); scope.$watch('chartOptions', resetChart, true); scope.$watch('chartColors', resetChart, true); + scope.$watch('chartDatasetOverload', resetChart, true); scope.$watch('chartType', function (newVal, oldVal) { if (isEmpty(newVal)) return; @@ -167,7 +169,7 @@ var colors = getColors(type, scope); var cvs = elem[0], ctx = cvs.getContext('2d'); var data = Array.isArray(scope.chartData[0]) ? - getDataSets(scope.chartLabels, scope.chartData, scope.chartSeries || [], colors, scope.chartYAxes) : + getDataSets(scope.chartLabels, scope.chartData, scope.chartSeries || [], colors, scope.chartYAxes, scope.chartDatasetOverload) : getData(scope.chartLabels, scope.chartData, colors); var options = angular.extend({}, ChartJs.getOptions(type), scope.chartOptions); @@ -274,7 +276,7 @@ return [r, g, b]; } - function getDataSets (labels, data, series, colors, yaxis) { + function getDataSets (labels, data, series, colors, yaxis, datasetOverload) { return { labels: labels, datasets: data.map(function (item, i) { @@ -285,6 +287,9 @@ if (yaxis) { dataset.yAxisID = yaxis[i]; } + if (datasetOverload) { + angular.merge(dataset,datasetOverload[i]) + } return dataset; }) };