/**
  * @return Chart
  */
 public function buildGraph()
 {
     $graph = new Chart($this->width, $this->height);
     $graph->SetScale("datlin");
     $graph->title->Set($this->title);
     $graph->subtitle->Set($this->description);
     $colors = $graph->getThemedColors();
     $graph->xaxis->SetTickLabels($this->burndown_data->getHumanReadableDates());
     $remaining_effort = new LinePlot($this->burndown_data->getRemainingEffort());
     $remaining_effort->SetColor($colors[1] . ':0.7');
     $remaining_effort->SetWeight(2);
     $remaining_effort->SetLegend('Remaining effort');
     $remaining_effort->mark->SetType(MARK_FILLEDCIRCLE);
     $remaining_effort->mark->SetColor($colors[1] . ':0.7');
     $remaining_effort->mark->SetFillColor($colors[1]);
     $remaining_effort->mark->SetSize(3);
     $graph->Add($remaining_effort);
     $ideal_burndown = new LinePlot($this->burndown_data->getIdealEffort());
     $ideal_burndown->SetColor($colors[0] . ':1.25');
     $ideal_burndown->SetLegend('Ideal Burndown');
     $graph->Add($ideal_burndown);
     return $graph;
 }
 /**
  * Manage graph axis
  *
  * @return Chart
  */
 private function prepareGraph()
 {
     $nbRepo = count($this->repoList);
     $graph = new Chart(500, 300 + 16 * $nbRepo);
     $graph->SetScale('textint');
     $graph->img->SetMargin(40, 20, 20, 80 + 16 * $nbRepo);
     $graph->SetMarginColor('white');
     $graph->title->Set($GLOBALS['Language']->getText('plugin_git', 'widget_project_pushes_title'));
     $graph->xaxis->SetLabelMargin(30);
     $graph->xaxis->SetLabelAlign('right', 'center');
     $graph->xaxis->SetTickLabels($this->dates);
     $graph->yaxis->SetPos('min');
     $graph->yaxis->SetTitle($GLOBALS['Language']->getText('plugin_git', 'widget_project_pushes_label'), 'center');
     $graph->yaxis->title->SetAngle(90);
     $graph->yaxis->title->Align('center', 'top');
     $graph->yaxis->SetTitleMargin(30);
     $graph->yaxis->SetLabelAlign('center', 'top');
     $graph->legend->Pos(0.1, 0.98, 'right', 'bottom');
     return $graph;
 }
 /**
  *
  * @param Integer $groupId
  * @param String  $groupBy
  * @param Date    $startDate
  * @param Date    $endDate
  * @param Boolean $absolute Is y-axis relative to data set or absolute (starting from 0)
  */
 function displayProjectTotalSizeGraph($groupId, $groupBy, $startDate, $endDate, $absolute = true)
 {
     $graph = new Chart(420, 340, "auto");
     $graph->img->SetMargin(70, 50, 30, 70);
     $graph->SetScale("textlin");
     $graph->title->Set("Total project size growth over the time");
     $graph->yaxis->title->Set("Size");
     $graph->yaxis->SetTitleMargin(60);
     $graph->yaxis->setLabelFormatCallback(array($this, 'sizeReadable'));
     if ($absolute) {
         $graph->yaxis->scale->SetAutoMin(0);
     }
     $data = $this->_dum->getWeeklyEvolutionProjectTotalSize($groupId, $groupBy, $startDate, $endDate);
     if (is_array($data) && count($data) > 1) {
         $dates = array();
         $ydata = array();
         foreach ($data as $xdate => $values) {
             $dates[] = $xdate;
             $ydata[] = (double) $values;
         }
         $lineplot = new LinePlot($ydata);
         $color = '#6BA132';
         $lineplot->SetColor($color);
         $lineplot->SetFillColor($color . ':1.5');
         $lineplot->value->SetFont($graph->getFont(), FS_NORMAL, 8);
         $lineplot->value->setFormatCallback(array($this, 'sizeReadable'));
         $graph->Add($lineplot);
         $graph->xaxis->title->Set("Weeks");
         $graph->xaxis->SetTitleMargin(35);
         $graph->xaxis->SetTickLabels($dates);
         $graph->Stroke();
     } else {
         $this->displayError($GLOBALS['Language']->getText('plugin_statistics', 'no_data_error'));
     }
 }
 function process($owner_type, $owner_id)
 {
     $dao = new SvnCommitsDao(CodendiDataAccess::instance());
     //The default duration is 3 months back
     $nb_weeks = 4 * 3;
     $duration = 7 * $nb_weeks;
     $day = 24 * 3600;
     $week = 7 * $day;
     //compute the stats
     $stats = array();
     $nb_of_commits = array();
     foreach ($dao->statsByGroupId($owner_id, $duration) as $row) {
         $stats[$row['whoid']]['by_day'][$row['day'] * $day] = $row['nb_commits'];
         $stats[$row['whoid']]['by_week'][$row['week']] = $row['nb_commits'];
         $this->tmp_nb_of_commit[$row['whoid']] = (isset($this->tmp_nb_of_commit[$row['whoid']]) ? $this->tmp_nb_of_commit[$row['whoid']] : 0) + $row['nb_commits'];
     }
     if (count($stats)) {
         //sort the results
         uksort($stats, array($this, 'sortByTop'));
         $today = $_SERVER['REQUEST_TIME'];
         $start_of_period = strtotime("-{$nb_weeks} weeks");
         //fill-in the holes
         $tmp_stats = array();
         foreach ($stats as $whoid => $stat) {
             $tmp_stats = array();
             for ($i = $start_of_period; $i <= $today; $i += $week) {
                 $w = (int) date('W', $i);
                 $tmp_stats[$w] = isset($stat['by_week'][$w]) ? $stat['by_week'][$w] : '0';
             }
             $stats[$whoid]['by_week'] = $tmp_stats;
         }
         //fill-in the labels
         $dates = array();
         for ($i = $start_of_period; $i <= $today; $i += $week) {
             $dates[] = date('M d', $i);
         }
         $nb_commiters = count($stats);
         $widgetFormatter = new Widget_ProjectSvnStats_Layout($nb_commiters);
         $legendRatio = $widgetFormatter->legend_ratio;
         $chartWidth = $widgetFormatter->getChartWidth();
         $chartHeigh = $widgetFormatter->getChartHeigh();
         $legend_x_position = $widgetFormatter->getLegendXPosition();
         $legend_y_position = $widgetFormatter->getLegendYPosition();
         $imgBottomMargin = $widgetFormatter->getImageBottomMargin();
         $legendAlign = $widgetFormatter->getLegendAlign();
         // @TODO: Centralize stuff at Chart class level to properly render a Jpgraph chart with a large number of legend items
         //Build the chart
         $c = new Chart($chartWidth, $chartHeigh);
         $c->SetScale('textlin');
         $c->img->SetMargin(40, 20, 20, $imgBottomMargin);
         $c->xaxis->SetTickLabels($dates);
         $c->legend->Pos($legend_x_position, $legend_y_position, 'left', $legendAlign);
         if ($legendRatio >= 1) {
             $c->legend->setColumns(2);
         }
         $colors = array_reverse(array_slice($GLOBALS['HTML']->getChartColors(), 0, $nb_commiters));
         $nb_colors = count($colors);
         $bars = array();
         $i = 0;
         foreach ($stats as $whoid => $stat) {
             $l = new BarPlot(array_values($stat['by_week']));
             $color = $colors[$i++ % $nb_colors];
             $l->SetColor($color . ':0.7');
             $l->setFillColor($color);
             if ($user = UserManager::instance()->getUserById($whoid)) {
                 $l->SetLegend(UserHelper::instance()->getDisplayNameFromUser($user));
             } else {
                 $l->SetLegend('Unknown user (' . (int) $whoid . ')');
             }
             $bars[] = $l;
         }
         $gbplot = new AccBarPlot($bars);
         $c->Add($gbplot);
     } else {
         $error = "No commits in the last {$duration} days";
         $c = new ErrorChart("No logged commits", $error, 400, 300);
     }
     echo $c->stroke();
 }