Skip to content

Commit

Permalink
add directive chart-dataset-overload
Browse files Browse the repository at this point in the history
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 #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.
  • Loading branch information
MDO-OTB authored and jtblin committed Jun 18, 2016
1 parent d58886f commit 1f3e5a2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions angular-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
chartColors: '=?',
chartClick: '=?',
chartHover: '=?',
chartYAxes: '=?'
chartYAxes: '=?',
chartDatasetOverload: '=?'
},
link: function (scope, elem/*, attrs */) {
var chart;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -285,6 +287,9 @@
if (yaxis) {
dataset.yAxisID = yaxis[i];
}
if (datasetOverload) {
angular.merge(dataset,datasetOverload[i])
}
return dataset;
})
};
Expand Down

0 comments on commit 1f3e5a2

Please sign in to comment.