From 81e40e2c910f0be3f6031445a4d2c1714cdeb385 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 21 Jun 2015 21:12:24 -0400 Subject: Replace dimplejs by c3js for chart drawing --- app/Controller/Analytic.php | 122 +++++--------- app/Locale/da_DK/translations.php | 3 + app/Locale/de_DE/translations.php | 3 + app/Locale/es_ES/translations.php | 3 + app/Locale/fi_FI/translations.php | 3 + app/Locale/fr_FR/translations.php | 3 + app/Locale/hu_HU/translations.php | 3 + app/Locale/it_IT/translations.php | 3 + app/Locale/ja_JP/translations.php | 3 + app/Locale/nl_NL/translations.php | 3 + app/Locale/pl_PL/translations.php | 3 + app/Locale/pt_BR/translations.php | 3 + app/Locale/ru_RU/translations.php | 3 + app/Locale/sr_Latn_RS/translations.php | 3 + app/Locale/sv_SE/translations.php | 3 + app/Locale/th_TH/translations.php | 3 + app/Locale/tr_TR/translations.php | 3 + app/Locale/zh_CN/translations.php | 3 + app/Model/ProjectDailySummary.php | 5 +- app/Template/analytic/burndown.php | 2 +- app/Template/analytic/cfd.php | 4 +- app/Template/analytic/layout.php | 4 +- app/Template/analytic/tasks.php | 2 +- app/Template/analytic/users.php | 2 +- app/Template/budget/index.php | 7 +- assets/css/app.css | 2 +- assets/css/print.css | 2 +- assets/css/vendor/c3.min.css | 1 + assets/js/app.js | 63 ++++--- assets/js/src/analytic.js | 297 +++++++++++++++------------------ assets/js/src/budget.js | 38 ----- assets/js/vendor/c3.min.js | 5 + assets/js/vendor/d3.v3.4.8.min.js | 5 - assets/js/vendor/d3.v3.min.js | 5 + assets/js/vendor/dimple.v2.1.2.min.js | 3 - scripts/make-assets.sh | 4 +- 36 files changed, 289 insertions(+), 335 deletions(-) create mode 100644 assets/css/vendor/c3.min.css delete mode 100644 assets/js/src/budget.js create mode 100644 assets/js/vendor/c3.min.js delete mode 100644 assets/js/vendor/d3.v3.4.8.min.js create mode 100644 assets/js/vendor/d3.v3.min.js delete mode 100644 assets/js/vendor/dimple.v2.1.2.min.js diff --git a/app/Controller/Analytic.php b/app/Controller/Analytic.php index f31870e0..41fe7169 100644 --- a/app/Controller/Analytic.php +++ b/app/Controller/Analytic.php @@ -34,24 +34,12 @@ class Analytic extends Base public function tasks() { $project = $this->getProject(); - $metrics = $this->projectAnalytic->getTaskRepartition($project['id']); - - if ($this->request->isAjax()) { - $this->response->json(array( - 'metrics' => $metrics, - 'labels' => array( - 'column_title' => t('Column'), - 'nb_tasks' => t('Number of tasks'), - ) - )); - } - else { - $this->response->html($this->layout('analytic/tasks', array( - 'project' => $project, - 'metrics' => $metrics, - 'title' => t('Task repartition for "%s"', $project['name']), - ))); - } + + $this->response->html($this->layout('analytic/tasks', array( + 'project' => $project, + 'metrics' => $this->projectAnalytic->getTaskRepartition($project['id']), + 'title' => t('Task repartition for "%s"', $project['name']), + ))); } /** @@ -62,24 +50,12 @@ class Analytic extends Base public function users() { $project = $this->getProject(); - $metrics = $this->projectAnalytic->getUserRepartition($project['id']); - - if ($this->request->isAjax()) { - $this->response->json(array( - 'metrics' => $metrics, - 'labels' => array( - 'user' => t('User'), - 'nb_tasks' => t('Number of tasks'), - ) - )); - } - else { - $this->response->html($this->layout('analytic/users', array( - 'project' => $project, - 'metrics' => $metrics, - 'title' => t('User repartition for "%s"', $project['name']), - ))); - } + + $this->response->html($this->layout('analytic/users', array( + 'project' => $project, + 'metrics' => $this->projectAnalytic->getUserRepartition($project['id']), + 'title' => t('User repartition for "%s"', $project['name']), + ))); } /** @@ -100,30 +76,20 @@ class Analytic extends Base $to = $values['to']; } - if ($this->request->isAjax()) { - $this->response->json(array( - 'columns' => array_values($this->board->getColumnsList($project['id'])), - 'metrics' => $this->projectDailySummary->getRawMetrics($project['id'], $from, $to), - 'labels' => array( - 'column' => t('Column'), - 'day' => t('Date'), - 'total' => t('Tasks'), - ) - )); - } - else { - $this->response->html($this->layout('analytic/cfd', array( - 'values' => array( - 'from' => $from, - 'to' => $to, - ), - 'display_graph' => $this->projectDailySummary->countDays($project['id'], $from, $to) >= 2, - 'project' => $project, - 'date_format' => $this->config->get('application_date_format'), - 'date_formats' => $this->dateParser->getAvailableFormats(), - 'title' => t('Cumulative flow diagram for "%s"', $project['name']), - ))); - } + $display_graph = $this->projectDailySummary->countDays($project['id'], $from, $to) >= 2; + + $this->response->html($this->layout('analytic/cfd', array( + 'values' => array( + 'from' => $from, + 'to' => $to, + ), + 'display_graph' => $display_graph, + 'metrics' => $display_graph ? $this->projectDailySummary->getAggregatedMetrics($project['id'], $from, $to) : array(), + 'project' => $project, + 'date_format' => $this->config->get('application_date_format'), + 'date_formats' => $this->dateParser->getAvailableFormats(), + 'title' => t('Cumulative flow diagram for "%s"', $project['name']), + ))); } /** @@ -144,27 +110,19 @@ class Analytic extends Base $to = $values['to']; } - if ($this->request->isAjax()) { - $this->response->json(array( - 'metrics' => $this->projectDailySummary->getRawMetricsByDay($project['id'], $from, $to), - 'labels' => array( - 'day' => t('Date'), - 'score' => t('Complexity'), - ) - )); - } - else { - $this->response->html($this->layout('analytic/burndown', array( - 'values' => array( - 'from' => $from, - 'to' => $to, - ), - 'display_graph' => $this->projectDailySummary->countDays($project['id'], $from, $to) >= 2, - 'project' => $project, - 'date_format' => $this->config->get('application_date_format'), - 'date_formats' => $this->dateParser->getAvailableFormats(), - 'title' => t('Burndown chart for "%s"', $project['name']), - ))); - } + $display_graph = $this->projectDailySummary->countDays($project['id'], $from, $to) >= 2; + + $this->response->html($this->layout('analytic/burndown', array( + 'values' => array( + 'from' => $from, + 'to' => $to, + ), + 'display_graph' => $display_graph, + 'metrics' => $display_graph ? $this->projectDailySummary->getAggregatedMetrics($project['id'], $from, $to, 'score') : array(), + 'project' => $project, + 'date_format' => $this->config->get('application_date_format'), + 'date_formats' => $this->dateParser->getAvailableFormats(), + 'title' => t('Burndown chart for "%s"', $project['name']), + ))); } } diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php index bb3c7c81..82f9534c 100644 --- a/app/Locale/da_DK/translations.php +++ b/app/Locale/da_DK/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php index 7d28b219..b004905b 100644 --- a/app/Locale/de_DE/translations.php +++ b/app/Locale/de_DE/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php index a169abfa..8aa56f6c 100644 --- a/app/Locale/es_ES/translations.php +++ b/app/Locale/es_ES/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php index 00514ab1..601ab9fd 100644 --- a/app/Locale/fi_FI/translations.php +++ b/app/Locale/fi_FI/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php index 4a792d07..4f077e93 100644 --- a/app/Locale/fr_FR/translations.php +++ b/app/Locale/fr_FR/translations.php @@ -945,4 +945,7 @@ return array( 'New due date: %B %e, %Y' => 'Nouvelle date d\'échéance : %d/%m/%Y', 'Start date changed: %B %e, %Y' => 'Date de début modifiée : %d/%m/%Y', '%k:%M %p' => '%H:%M', + '%%Y-%%m-%%d' => '%%d/%%m/%%Y', + 'Total for all columns' => 'Total pour toutes les colonnes', + 'You need at least 2 days of data to show the chart.' => 'Vous avez besoin d\'au minimum 2 jours de données pour afficher le graphique.', ); diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php index dc5dbeeb..6c1861eb 100644 --- a/app/Locale/hu_HU/translations.php +++ b/app/Locale/hu_HU/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php index 950bfcd0..7bfa506a 100644 --- a/app/Locale/it_IT/translations.php +++ b/app/Locale/it_IT/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php index 7c64d54d..210621d0 100644 --- a/app/Locale/ja_JP/translations.php +++ b/app/Locale/ja_JP/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/nl_NL/translations.php b/app/Locale/nl_NL/translations.php index d7111b38..9e0cf6fe 100644 --- a/app/Locale/nl_NL/translations.php +++ b/app/Locale/nl_NL/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php index 8e2ac4a0..d2650a89 100644 --- a/app/Locale/pl_PL/translations.php +++ b/app/Locale/pl_PL/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php index f94f0911..041434a2 100644 --- a/app/Locale/pt_BR/translations.php +++ b/app/Locale/pt_BR/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php index 1f3be94f..7e94ecbb 100644 --- a/app/Locale/ru_RU/translations.php +++ b/app/Locale/ru_RU/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/sr_Latn_RS/translations.php b/app/Locale/sr_Latn_RS/translations.php index 028b21e4..8ac8ea31 100644 --- a/app/Locale/sr_Latn_RS/translations.php +++ b/app/Locale/sr_Latn_RS/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php index 93fe05b5..770a68d4 100644 --- a/app/Locale/sv_SE/translations.php +++ b/app/Locale/sv_SE/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php index 122c5f73..b1fb0417 100644 --- a/app/Locale/th_TH/translations.php +++ b/app/Locale/th_TH/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/tr_TR/translations.php b/app/Locale/tr_TR/translations.php index 31f2fd39..cdd4d8cf 100644 --- a/app/Locale/tr_TR/translations.php +++ b/app/Locale/tr_TR/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php index 0260aa26..60634686 100644 --- a/app/Locale/zh_CN/translations.php +++ b/app/Locale/zh_CN/translations.php @@ -943,4 +943,7 @@ return array( // 'New due date: %B %e, %Y' => '', // 'Start date changed: %B %e, %Y' => '', // '%k:%M %p' => '', + // '%%Y-%%m-%%d' => '', + // 'Total for all columns' => '', + // 'You need at least 2 days of data to show the chart.' => '', ); diff --git a/app/Model/ProjectDailySummary.php b/app/Model/ProjectDailySummary.php index 65a612f6..acffa3a9 100644 --- a/app/Model/ProjectDailySummary.php +++ b/app/Model/ProjectDailySummary.php @@ -149,9 +149,10 @@ class ProjectDailySummary extends Base * @param integer $project_id Project id * @param string $from Start date (ISO format YYYY-MM-DD) * @param string $to End date + * @param string $column Column to aggregate * @return array */ - public function getAggregatedMetrics($project_id, $from, $to) + public function getAggregatedMetrics($project_id, $from, $to, $column = 'total') { $columns = $this->board->getColumnsList($project_id); $column_ids = array_keys($columns); @@ -172,7 +173,7 @@ class ProjectDailySummary extends Base $aggregates[$record['day']] = array($record['day']); } - $aggregates[$record['day']][$record['column_id']] = $record['total']; + $aggregates[$record['day']][$record['column_id']] = $record[$column]; } // Aggregate by row diff --git a/app/Template/analytic/burndown.php b/app/Template/analytic/burndown.php index 839573be..48a4c1c1 100644 --- a/app/Template/analytic/burndown.php +++ b/app/Template/analytic/burndown.php @@ -6,7 +6,7 @@

-
+
diff --git a/app/Template/analytic/cfd.php b/app/Template/analytic/cfd.php index 26696b31..ab706d56 100644 --- a/app/Template/analytic/cfd.php +++ b/app/Template/analytic/cfd.php @@ -3,10 +3,10 @@ -

+

-
+
diff --git a/app/Template/analytic/layout.php b/app/Template/analytic/layout.php index de8d0de9..72aab4d8 100644 --- a/app/Template/analytic/layout.php +++ b/app/Template/analytic/layout.php @@ -1,5 +1,5 @@ -asset->js('assets/js/vendor/d3.v3.4.8.min.js') ?> -asset->js('assets/js/vendor/dimple.v2.1.2.min.js') ?> +asset->js('assets/js/vendor/d3.v3.min.js') ?> +asset->js('assets/js/vendor/c3.min.js') ?>