From 663a1c20e6ba0fbf65afcb43f0f48d34f21dcb53 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 5 Jul 2015 21:22:31 -0400 Subject: Add new analytic page: Average time spent into each column --- assets/js/src/analytic.js | 99 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'assets/js/src/analytic.js') diff --git a/assets/js/src/analytic.js b/assets/js/src/analytic.js index bec4d76e..0375f0be 100644 --- a/assets/js/src/analytic.js +++ b/assets/js/src/analytic.js @@ -165,6 +165,99 @@ }); } + // Draw chart for average time spent into each column + function drawAvgTimeColumn() + { + var metrics = $("#chart").data("metrics"); + var plots = [$("#chart").data("label")]; + var categories = []; + + for (var column_id in metrics) { + plots.push(metrics[column_id].average); + categories.push(metrics[column_id].title); + } + + c3.generate({ + data: { + columns: [plots], + type: 'bar' + }, + bar: { + width: { + ratio: 0.5 + } + }, + axis: { + x: { + type: 'category', + categories: categories + }, + y: { + tick: { + format: formatDuration + } + } + }, + legend: { + show: false + } + }); + } + + // Draw chart for average time spent into each column + function drawTaskTimeColumn() + { + var metrics = $("#chart").data("metrics"); + var plots = [$("#chart").data("label")]; + var categories = []; + + for (var i = 0; i < metrics.length; i++) { + plots.push(metrics[i].time_spent); + categories.push(metrics[i].title); + } + + c3.generate({ + data: { + columns: [plots], + type: 'bar' + }, + bar: { + width: { + ratio: 0.5 + } + }, + axis: { + x: { + type: 'category', + categories: categories + }, + y: { + tick: { + format: formatDuration + } + } + }, + legend: { + show: false + } + }); + } + + function formatDuration(d) + { + if (d >= 86400) { + return Math.round(d/86400) + "d"; + } + else if (d >= 3600) { + return Math.round(d/3600) + "h"; + } + else if (d >= 60) { + return Math.round(d/60) + "m"; + } + + return d + "s"; + } + jQuery(document).ready(function() { if (Kanboard.Exists("analytic-task-repartition")) { @@ -182,6 +275,12 @@ else if (Kanboard.Exists("budget-chart")) { drawBudget(); } + else if (Kanboard.Exists("analytic-avg-time-column")) { + drawAvgTimeColumn(); + } + else if (Kanboard.Exists("analytic-task-time-column")) { + drawTaskTimeColumn(); + } }); })(); -- cgit v1.2.3