Replace dimplejs by c3js for chart drawing

This commit is contained in:
Frederic Guillot
2015-06-21 21:12:24 -04:00
parent 1465ca1ae1
commit 81e40e2c91
36 changed files with 320 additions and 366 deletions

View File

@@ -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']),
)));
}
}

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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.',
);

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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.' => '',
);

View File

@@ -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

View File

@@ -6,7 +6,7 @@
<p class="alert"><?= t('Not enough data to show the graph.') ?></p>
<?php else: ?>
<section id="analytic-burndown">
<div id="chart" data-url="<?= $this->url->href('analytic', 'burndown', array('project_id' => $project['id'], 'from' => $values['from'], 'to' => $values['to'])) ?>"></div>
<div id="chart" data-metrics='<?= json_encode($metrics) ?>' data-date-format="<?= e('%%Y-%%m-%%d') ?>" data-label-total="<?= t('Total for all columns') ?>"></div>
</section>
<?php endif ?>

View File

@@ -3,10 +3,10 @@
</div>
<?php if (! $display_graph): ?>
<p class="alert"><?= t('Not enough data to show the graph.') ?></p>
<p class="alert"><?= t('You need at least 2 days of data to show the chart.') ?></p>
<?php else: ?>
<section id="analytic-cfd">
<div id="chart" data-url="<?= $this->url->href('analytic', 'cfd', array('project_id' => $project['id'], 'from' => $values['from'], 'to' => $values['to'])) ?>"></div>
<div id="chart" data-metrics='<?= json_encode($metrics) ?>' data-date-format="<?= e('%%Y-%%m-%%d') ?>"></div>
</section>
<?php endif ?>

View File

@@ -1,5 +1,5 @@
<?= $this->asset->js('assets/js/vendor/d3.v3.4.8.min.js') ?>
<?= $this->asset->js('assets/js/vendor/dimple.v2.1.2.min.js') ?>
<?= $this->asset->js('assets/js/vendor/d3.v3.min.js') ?>
<?= $this->asset->js('assets/js/vendor/c3.min.js') ?>
<section id="main">
<div class="page-header">

View File

@@ -7,7 +7,7 @@
<?php else: ?>
<section id="analytic-task-repartition">
<div id="chart" data-url="<?= $this->url->href('analytic', 'tasks', array('project_id' => $project['id'])) ?>"></div>
<div id="chart" data-metrics='<?= json_encode($metrics) ?>'></div>
<table>
<tr>

View File

@@ -7,7 +7,7 @@
<?php else: ?>
<section id="analytic-user-repartition">
<div id="chart" data-url="<?= $this->url->href('analytic', 'users', array('project_id' => $project['id'])) ?>"></div>
<div id="chart" data-metrics='<?= json_encode($metrics) ?>'></div>
<table>
<tr>

View File

@@ -1,5 +1,5 @@
<?= $this->asset->js('assets/js/vendor/d3.v3.4.8.min.js') ?>
<?= $this->asset->js('assets/js/vendor/dimple.v2.1.2.min.js') ?>
<?= $this->asset->js('assets/js/vendor/d3.v3.min.js') ?>
<?= $this->asset->js('assets/js/vendor/c3.min.js') ?>
<div class="page-header">
<h2><?= t('Budget overview') ?></h2>
@@ -8,7 +8,8 @@
<?php if (! empty($daily_budget)): ?>
<div id="budget-chart">
<div id="chart"
data-serie='<?= json_encode($daily_budget) ?>'
data-date-format="<?= e('%%Y-%%m-%%d') ?>"
data-metrics='<?= json_encode($daily_budget) ?>'
data-labels='<?= json_encode(array('in' => t('Budget line'), 'out' => t('Expenses'), 'left' => t('Remaining'), 'value' => t('Amount'), 'date' => t('Date'), 'type' => t('Type'))) ?>'></div>
</div>
<hr/>