Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create annotation boxes for each weekends making weekends visible on … #682

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion angular-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
chartColors: '=?',
chartClick: '=?',
chartHover: '=?',
chartDatasetOverride: '=?'
chartDatasetOverride: '=?',
chartShowWeekends: '@?'
},
link: function (scope, elem/*, attrs */) {
if (useExcanvas) window.G_vmlCanvasManager.initElement(elem[0]);
Expand Down Expand Up @@ -178,6 +179,45 @@
// https://github.com/jtblin/angular-chart.js/issues/187
destroyChart(scope);

// Create annotation boxes for each weekends
// making weekends visible on the chart background.
// Requires time on x axis and annotation plugin.
// https://github.com/chartjs/chartjs-plugin-annotation
if (scope.chartShowWeekends) {
var annotationsArray = [];
var begin, end;

angular.forEach(data.labels, function(textDate) {
var dow = (new Date(textDate)).getDay();

if (dow === 5) { // saturday midnight
begin = textDate;
};

if (dow === 0) { // monday midnight
end = textDate;

annotationsArray.push({
type: 'box',
xScaleID: 'x-axis-0',
xMin: begin,
xMax: end,
backgroundColor: 'rgba(150, 150, 200, 0.1)',
});

begin = null;
end = null;
};
});

angular.extend(options, {
annotation: {
drawTime: "beforeDatasetsDraw",
annotations: annotationsArray,
}
});
};

scope.chart = new ChartJs.Chart(ctx, {
type: type,
data: data,
Expand Down