function addPlots($data) { $plots = array(); $labels = array(); $i = 0; foreach ($data as $key => $plot_data) { $plot = new BarPlot(array_values($plot_data)); $plot->setLegend(prettify($key)); $plot->setFillColor(self::$colours[$i]); $i++; $plots[] = $plot; $labels = array_merge($labels, array_keys($plot_data)); } $group_plot = new GroupBarPlot($plots); $this->grapher->add($group_plot); $this->grapher->xaxis->setTickLabels($labels); }
/** * Build a JpGraph barPlot object with retrived data. * * @return BarPlot */ private function displayRepositoryPushesByWeek() { $nbRepo = count($this->repoList); $colors = array_slice($GLOBALS['HTML']->getChartColors(), 0, $nbRepo); $nbColors = count($colors); $i = 0; $bplot = array(); foreach ($this->repoList as $repository) { $this->legend = null; $pushes = $this->getRepositoryPushesByWeek($repository); if ($this->displayChart) { $b2plot = new BarPlot($pushes); $color = $colors[$i++ % $nbColors]; $b2plot->SetColor($color . ':0.7'); $b2plot->setFillColor($color); if (!empty($this->legend)) { $b2plot->SetLegend($this->legend); } $bplot[] = $b2plot; } } return $bplot; }
/** * Collects and renders visitor/week report data */ public function visitor_week() { $myConfig = $this->getConfig(); $oDb = oxDb::getDb(); $aDataX = array(); $aDataX2 = array(); $aDataX3 = array(); $aDataX4 = array(); $aDataX5 = array(); $aDataX6 = array(); $aDataY = array(); $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_to")))); $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_from")))); $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid order by oxtime"; $aTemp = array(); $rs = $oDb->execute($sSQL); if ($rs != false && $rs->recordCount() > 0) { while (!$rs->EOF) { $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++; $rs->moveNext(); } } // initializing list($iFrom, $iTo) = $this->getWeekRange(); for ($i = $iFrom; $i < $iTo; $i++) { $aDataX[$i] = 0; $aDataX2[$i] = 0; $aDataX3[$i] = 0; $aDataX4[$i] = 0; $aDataX5[$i] = 0; $aDataX6[$i] = 0; $aDataY[] = "KW " . $i; } foreach ($aTemp as $key => $value) { $aDataX[$key] = $value; $aDataX2[$key] = 0; $aDataX3[$key] = 0; $aDataX4[$key] = 0; $aDataX5[$key] = 0; $aDataX6[$key] = 0; $aDataY[] = "KW " . $key; } // collects sessions what executed 'order' function $sQ = "select oxtime, oxsessid FROM `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid"; $aTempOrder = $this->_collectSessions($sQ); // collects sessions what executed order class $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid"; $aTempExecOrdersSessions = $this->_collectOrderSessions($sQ, $aTempOrder, $aDataX6, false); // collects sessions what executed payment class $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'payment' and oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid"; $aTempPaymentSessions = $this->_collectPaymentSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aDataX2, false); // collects sessions what executed 'user' class $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'user' and oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid"; $aTempUserSessions = $this->_collectUserSessionsForVisitorMonth($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aDataX2, false); // collects sessions what executed 'tobasket' function $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'basket' and oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid"; $this->_collectToBasketSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, $aDataX4, false); // orders made $sQ = "select oxorderdate from oxorder where oxorderdate >= {$sTimeFrom} and oxorderdate <= {$sTimeTo} order by oxorderdate"; $this->_collectOrdersMade($sQ, $aDataX5, false); header("Content-type: image/png"); // New graph with a drop shadow $graph = $this->getGraph(max(800, count($aDataX) * 80), 600); // Description $graph->xaxis->setTickLabels($aDataY); // Set title and subtitle $graph->title->set("Woche"); // Create the bar plot $bplot2 = new BarPlot(array_values($aDataX2)); $bplot2->setFillColor("#9966cc"); $bplot2->setLegend("Best.Abbr. in Bezahlmethoden"); // Create the bar plot $bplot3 = new BarPlot(array_values($aDataX3)); $bplot3->setFillColor("#ffcc00"); $bplot3->setLegend("Best.Abbr. in Benutzer"); // Create the bar plot $bplot4 = new BarPlot(array_values($aDataX4)); $bplot4->setFillColor("#6699ff"); $bplot4->setLegend("Best.Abbr. in Warenkorb"); // Create the bar plot $bplot6 = new BarPlot(array_values($aDataX6)); $bplot6->setFillColor("#ff0099"); $bplot6->setLegend("Best.Abbr. in Bestellbestaetigung"); // Create the bar plot $bplot5 = new BarPlot(array_values($aDataX5)); $bplot5->setFillColor("silver"); $bplot5->setLegend("Bestellungen"); // Create the grouped bar plot $gbplot = new groupBarPlot(array($bplot4, $bplot3, $bplot2, $bplot6, $bplot5)); $graph->add($gbplot); // Finally output the image $graph->stroke(); }
/** * Collects and renders visitor/week report data */ public function visitor_week() { $myConfig = $this->getConfig(); $oDb = oxDb::getDb(); $aDataX = array(); $aDataY = array(); $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_to")))); $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_from")))); $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid order by oxtime"; $aTemp = array(); $rs = $oDb->execute($sSQL); if ($rs != false && $rs->recordCount() > 0) { while (!$rs->EOF) { //$aTemp[date( "W", strtotime( $rs->fields[0]))]++; $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++; $rs->moveNext(); } } // initializing list($iFrom, $iTo) = $this->getWeekRange(); for ($i = $iFrom; $i < $iTo; $i++) { $aDataX[$i] = 0; $aDataX2[$i] = 0; $aDataX3[$i] = 0; $aDataY[] = "KW " . $i; } foreach ($aTemp as $key => $value) { $aDataX[$key] = $value; $aDataX2[$key] = 0; $aDataX3[$key] = 0; $aDataY[] = "KW " . $key; } // buyer $sSQL = "select oxorderdate from oxorder where oxorderdate >= {$sTimeFrom} and oxorderdate <= {$sTimeTo} order by oxorderdate"; $aTemp = array(); $rs = $oDb->execute($sSQL); if ($rs != false && $rs->recordCount() > 0) { while (!$rs->EOF) { //$aTemp[date( "W", strtotime( $rs->fields[0]))]++; $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++; $rs->moveNext(); } } foreach ($aTemp as $key => $value) { $aDataX2[$key] = $value; } // newcustomer $sSQL = "select oxcreate from oxuser where oxcreate >= {$sTimeFrom} and oxcreate <= {$sTimeTo} order by oxcreate"; $aTemp = array(); $rs = $oDb->execute($sSQL); if ($rs != false && $rs->recordCount() > 0) { while (!$rs->EOF) { //$aTemp[date( "W", strtotime( $rs->fields[0]))]++; $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++; $rs->moveNext(); } } foreach ($aTemp as $key => $value) { $aDataX3[$key] = $value; } header("Content-type: image/png"); // New graph with a drop shadow $graph = new Graph(max(800, count($aDataX) * 80), 600); $graph->setBackgroundImage($myConfig->getImageDir(true) . "/reportbgrnd.jpg", BGIMG_FILLFRAME); // Use a "text" X-scale $graph->setScale("textlin"); // Label align for X-axis $graph->xaxis->setLabelAlign('center', 'top', 'right'); // Label align for Y-axis $graph->yaxis->setLabelAlign('right', 'bottom'); $graph->setShadow(); // Description $graph->xaxis->setTickLabels($aDataY); // Set title and subtitle $graph->title->set("Woche"); // Use built in font $graph->title->setFont(FF_FONT1, FS_BOLD); $aDataFinalX = array(); foreach ($aDataX as $dData) { $aDataFinalX[] = $dData; } // Create the bar plot $bplot = new BarPlot($aDataFinalX); $bplot->setFillGradient("navy", "lightsteelblue", GRAD_VER); $bplot->setLegend("Besucher"); $aDataFinalX2 = array(); foreach ($aDataX2 as $dData) { $aDataFinalX2[] = $dData; } // Create the bar plot $bplot2 = new BarPlot($aDataFinalX2); $bplot2->setFillColor("orange"); $bplot2->setLegend("Kaeufer"); $aDataFinalX3 = array(); foreach ($aDataX3 as $dData) { $aDataFinalX3[] = $dData; } // Create the bar plot $bplot3 = new BarPlot($aDataFinalX3); $bplot3->setFillColor("silver"); $bplot3->setLegend("Neukunden"); // Create the grouped bar plot $gbplot = new groupBarPlot(array($bplot, $bplot2, $bplot3)); $graph->add($gbplot); // Finally output the image $graph->stroke(); }
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(); }
function generateStackedBarGraph($data, $legend_index = 0, $image = false, $aFillColors = array('red', 'green', 'orange', 'yellow', 'aqua', 'lime', 'teal', 'purple1', 'lightblue', 'blue'), $length = 500, $width = 300, $fontFamily = FF_FONT1, $fontStyle = FS_BOLD, $fontSize = '', $fontColor = 'black', $marginColor = 'white') { include_once XHELP_JPGRAPH_PATH . '/jpgraph_bar.php'; $graph = new Graph($length, $width); $graph->title->Set($this->meta['name']); $graph->SetScale("textint"); $graph->yaxis->scale->SetGrace(30); //$graph->ygrid->Show(true,true); $graph->ygrid->SetColor('gray', 'lightgray@0.5'); // Setup graph colors $graph->SetMarginColor($marginColor); $datazero = array(0, 0, 0, 0); // Create the "dummy" 0 bplot $bplotzero = new BarPlot($datazero); // Set names as x-axis label $graph->xaxis->SetTickLabels($data[$legend_index]); // for loop through data array starting with element 1 $aPlots = array(); for ($i = 1; $i < count($data); $i++) { $ybplot1 = new BarPlot($data[$i]); $ybplot1->setFillColor($aFillColors[$i]); $ybplot1->value->Show(); $ybplot1->value->SetFont($fontFamily, $fontStyle, $fontSize); $ybplot1->value->SetColor($fontColor); $aPlots[] = $ybplot1; } //$ybplot = new AccBarPlot(array($ybplot1,$bplotzero)); $ybplot = new AccBarPlot($aPlots, $bplotzero); $graph->Add($ybplot); // Set graph background image $graph->SetBackgroundImage($image, BGIMG_FILLFRAME); $graph->Stroke(); }