$graph->yaxis->HideLabels(); $graph->img->SetMargin($margex, 1, 1, $marge); $graph->SetFrame(true, 'black', 0); $graph->SetBox(true, 'black', 0); $graph->ygrid->SetWeight(0, 0); $graph->xaxis->HideLine(); $graph->xaxis->SetTickLabels($datax); $graph->xaxis->SetLabelAngle(90); $graph->xaxis->SetTextTickInterval(12, 0); $graph->xaxis->SetLabelMargin(2); // Now create a bar pot $bplot = new BarPlot($datay_bid); $bplot->SetFillColor('white'); // ...and add it to the graPH $graph->Add($bplot); $mgraph = new MGraph(); $xpos1 = 3; $ypos1 = 0; $xpos2 = 3; $ypos2 = 100; $mgraph->Add($graph, 3, 0); for ($i = 0; $i < count($feat_graph); $i++) { $mgraph->Add($feat_graph[$i], 3, $height_bid + $i * $height); } $cnt = 0; foreach ($datay as $feat_type => $val) { foreach ($val as $instrume => $res) { $mgraph->Add(create_graph_barplot($instrume, $res, $width, $height), 3, $height_bid + $cnt * $height); $cnt++; } }
$bplot4 = new BarPlot($y4); // Adjust fill color $bplot4->SetFillColor('purple1'); $graph4->Add($bplot4); // Setup the titles $descibe4 = iconv('UTF-8', 'ASCII//TRANSLIT', tr("octeam_stat_m_caches")); $graph4->title->Set($descibe4); $graph4->xaxis->title->Set(iconv('UTF-8', 'ASCII//TRANSLIT', tr('number_month')) . '2014/2015'); $graph4->xaxis->SetTickLabels($x4); $graph4->yaxis->title->Set($ncaches); $graph4->title->SetFont(FF_FONT1, FS_BOLD); $graph4->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph4->xaxis->title->SetFont(FF_FONT1, FS_BOLD); // Setup the values that are displayed on top of each bar $bplot4->value->Show(); // Must use TTF fonts if we want text at an arbitrary angle $bplot4->value->SetFont(FF_FONT1, FS_BOLD); $bplot4->value->SetAngle(0); $bplot4->value->SetFormat('%d'); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetMargin(10, 10, 10, 10); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->Add($graph); $mgraph->Add($graph3, 0, 220); $mgraph->Add($graph2, 0, 440); $mgraph->Add($graph4, 0, 660); $mgraph->Stroke(); }
// Setup the bar graph //---------------------- $graph2 = new Graph($w, 110); $graph2->SetScale('linlin', 0, 0, $xmin, $xmax); $graph2->SetMargin($lm, $rm, 5, 10); $graph2->SetMarginColor('white'); $graph2->SetFrame(false); $graph2->SetBox(true); $graph2->xgrid->Show(); $graph2->xaxis->SetTickPositions($tickPositions, $minTickPositions); $graph2->xaxis->SetLabelFormatString('My', true); $graph2->xaxis->SetPos('max'); $graph2->xaxis->HideLabels(); $graph2->xaxis->SetTickSide(SIDE_DOWN); $b1 = new BarPlot($datay2, $datax); $b1->SetFillColor('teal'); $b1->SetColor('teal:1.2'); $graph2->Add($b1); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetMargin(2, 2, 2, 2); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->Add($graph); $mgraph->Add($graph2, 0, 240); $mgraph->Stroke(); ?>
$graph4->yaxis->title->Set('time(nano-sec)'); $graph4->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph4->ygrid->SetColor('black'); $graph4->yaxis->SetTitleMargin(45); $graph4->yaxis->scale->SetGrace(30); // TITRE: texte $graph4->title->Set("Mesuring latency Mod operation (nano-sec)"); // TITRE: marge et apparence $graph4->title->SetFont(FF_FONT1, FS_BOLD, 11); // Couleurs et transparence par histogramme $bplot4 = new BarPlot($data5); $bplot4->value->Show(); $bplot4->SetFillColor('blue'); $bplot4->value->SetFormat('%01.3f'); $bplot4->value->SetColor("black", "darkred"); $bplot4->SetShadow('black'); $bplot4->SetWidth(0.3); $graph4->Add($bplot4); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetMargin(10, 10, 10, 10); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->SetBackgroundImage('../fond.png'); $mgraph->AddMix($graph, 0, 0, 85); $mgraph->AddMix($graph1, 0, 270, 85); $mgraph->AddMix($graph2, 0, 540, 85); $mgraph->AddMix($graph3, 0, 810, 85); $mgraph->AddMix($graph4, 0, 1080, 85); $mgraph->Stroke();
$graph3->SetFrame(true, 'white', 0); $graph3->SetBox(); $graph3->title->Set('Temperature'); $graph3->title->SetColor('black'); $graph3->title->SetFont(FF_ARIAL, FS_BOLD, 14); $graph3->title->SetMargin(5); $graph3->xaxis->HideLabels(); $graph3->xgrid->Show(); $graph3->yaxis->SetLabelAngle(90); $graph3->yaxis->SetColor('black'); $graph3->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 9); $graph3->yaxis->SetLabelMargin(0); $graph3->yaxis->scale->SetAutoMin(-10); $line3 = new LinePlot($data_windtemp, $xdata); $line3->SetStepStyle(); $line3->SetColor('black'); $graph3->Add($line3); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetMargin(2, 2, 2, 2); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->SetFillColor(BKG_COLOR); $mgraph->Add($graph, 0, 50); $mgraph->Add($graph2, 250, 50); $mgraph->Add($graph3, 460, 50); $mgraph->title->Set('Climate diagram 12 March 2009'); $mgraph->title->SetFont(FF_ARIAL, FS_BOLD, 20); $mgraph->title->SetMargin(8); $mgraph->Stroke();
$graph2 = new Graph($w, 110); $graph2->SetScale('linlin', 0, 0, $xmin, $xmax); $graph2->SetMargin($lm, $rm, 5, 10); $graph2->SetMarginColor('white'); $graph2->SetFrame(false); $graph2->SetBox(true); $graph2->xgrid->Show(); $graph2->xaxis->SetTickPositions($tickPositions, $minTickPositions); $graph2->xaxis->SetLabelFormatString('My', true); $graph2->xaxis->SetPos('max'); $graph2->xaxis->HideLabels(); $graph2->xaxis->SetTickSide(SIDE_DOWN); $b1 = new BarPlot($datay2, $datax); $b1->SetFillColor('teal'); $b1->SetColor('teal:1.2'); $graph2->Add($b1); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetImgFormat('jpeg', 60); $mgraph->SetMargin(2, 2, 2, 2); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->SetBackgroundImage('tiger1.jpg'); $mgraph->AddMix($graph, 0, 0, 85); $mgraph->AddMix($graph2, 0, 250, 85); $mgraph->Stroke(); ?>
} $yTickWidth = "({$yTickWidth}).0"; $yTickWidth = strlen($yTickWidth) * 7; $widthWeek = 70 * $contributionStat['nbCols'] + 100 + $legendWidth; $widthTotal = 70 + 100 + $legendWidth + $yTickWidth; $height = 250; $widthUser = 70 * $userContributions['nbCols'] + 100 + $legendWidth + $yTickWidth; $widthGroup = 70 * count($groupContributions) + 100 + $legendWidth + $yTickWidth; $space = 20; if ($prefs['feature_jpgraph'] == 'y') { require_once 'lib/jpgraph/src/jpgraph.php'; require_once 'lib/jpgraph/src/jpgraph_bar.php'; require_once 'lib/jpgraph/src/jpgraph_mgraph.php'; $imagegallib = TikiLib::lib('imagegal'); $ext = 'jpeg'; $background = new MGraph(); $background->SetImgFormat($ext); $background->SetFrame(true, 'black'); $background->SetMargin(10, 10, 10, 10); } else { require_once 'lib/sheet/grid.php'; require_once 'lib/graph-engine/gd.php'; require_once 'lib/graph-engine/pdflib.php'; require_once 'lib/graph-engine/ps.php'; require_once 'lib/graph-engine/graph.pie.php'; require_once 'lib/graph-engine/graph.bar.php'; require_once 'lib/graph-engine/graph.multiline.php'; $graphType = 'BarStackGraphic'; $ext = 'jpg'; $background = new GD_GRenderer(max($widthUser, $widthWeek), 8 * $height, $ext); $legendWidth = 300;
// TITRE: texte $graph9->title->Set("Mesuring latency Sh process (micro-sec)"); // TITRE: marge et apparence $graph9->title->SetFont(FF_FONT1, FS_BOLD, 11); // Couleurs et transparence par histogramme $bplot9 = new BarPlot($data10); $bplot9->SetFillColor('lightgray'); $bplot9->value->Show(); $bplot9->value->SetFormat('%01.3f'); $bplot9->value->SetColor("black", "darkred"); $bplot9->SetShadow('black'); $bplot9->SetWidth(0.3); $graph9->Add($bplot9); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetMargin(10, 10, 10, 10); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->SetBackgroundImage('../fond.png'); $mgraph->AddMix($graph, 0, 0, 85); $mgraph->AddMix($graph1, 0, 270, 85); $mgraph->AddMix($graph2, 0, 540, 85); $mgraph->AddMix($graph3, 0, 810, 85); $mgraph->AddMix($graph4, 0, 1080, 85); $mgraph->AddMix($graph5, 0, 1350, 85); $mgraph->AddMix($graph6, 0, 1620, 85); $mgraph->AddMix($graph7, 0, 1890, 85); $mgraph->AddMix($graph8, 0, 2110, 85); $mgraph->AddMix($graph9, 0, 2380, 85); $mgraph->Stroke();
$graph2 = new Graph(WIND_WIDTH - 30, WIND_HEIGHT); $graph2->SetScale('datlin'); $graph2->Set90AndMargin(5, 20, 60, 30); $graph2->SetMarginColor(BKG_COLOR); $graph2->SetFrame(true, 'white', 0); $graph2->SetBox(); $graph2->title->Set('Windspeed'); $graph2->title->SetColor('red'); $graph2->title->SetFont(FF_ARIAL, FS_BOLD, 14); $graph2->title->SetMargin(5); $graph2->xaxis->HideLabels(); $graph2->xgrid->Show(); $graph2->yaxis->SetLabelAngle(90); $graph2->yaxis->SetColor('red'); $graph2->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 9); $graph2->yaxis->SetLabelMargin(0); $graph2->yaxis->scale->SetAutoMin(0); $line2 = new LinePlot($data_windspeed, $xdata); $line2->SetStepStyle(); $line2->SetColor('red'); $graph2->Add($line2); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetMargin(2, 2, 2, 2); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->SetFillColor(BKG_COLOR); $mgraph->Add($graph); $mgraph->Add($graph2, 280, 0); $mgraph->Stroke();
$yTickWidth = strlen($yTickWidth) * 7; $widthWeek = 70 * $contributionStat['nbCols'] + 100 + $legendWidth; $widthTotal = 70 + 100 + $legendWidth + $yTickWidth; $height = 250; $widthUser = 70 * $userContributions['nbCols'] + 100 + $legendWidth + $yTickWidth; $widthGroup = 70 * count($groupContributions) + 100 + $legendWidth + $yTickWidth; $space = 20; //echo "$legendWidth _ $xUserTickWidth _ $xGroupTickWidth _ $yTickWidth _$widthWeek _ $widthTotal _ $widthUser _ $widthGroup";die; if ($prefs['feature_jpgraph'] == 'y') { require_once 'lib/jpgraph/src/jpgraph.php'; require_once 'lib/jpgraph/src/jpgraph_bar.php'; require_once 'lib/jpgraph/src/jpgraph_mgraph.php'; global $imagegallib; include_once 'lib/imagegals/imagegallib.php'; $ext = 'jpeg'; $background = new MGraph(); $background->SetImgFormat($ext); $background->SetFrame(true, 'black'); $background->SetMargin(10, 10, 10, 10); } else { require_once 'lib/sheet/grid.php'; require_once 'lib/graph-engine/gd.php'; require_once 'lib/graph-engine/pdflib.php'; require_once 'lib/graph-engine/ps.php'; require_once 'lib/graph-engine/graph.pie.php'; require_once 'lib/graph-engine/graph.bar.php'; require_once 'lib/graph-engine/graph.multiline.php'; $graphType = 'BarStackGraphic'; $background =& new GD_GRenderer(max($widthUser, $widthWeek), 8 * $height, $ext); $ext = 'jpg'; $legendWidth = 300;
require_once 'jpgraph/src/jpgraph.php'; require_once "jpgraph/src/jpgraph_line.php"; require_once "jpgraph/src/jpgraph_date.php"; require_once 'jpgraph/src/jpgraph_mgraph.php'; // etablit la liste des instruments par frequences decroissantes foreach ($rs['OBSERVAT'] as $key => $val) { $data[] = array('observatory' => $val . '/' . $rs['INSTRUME'][$key] . '/' . $rs['TELESCOP'][$key], 'wavemax' => $rs[$key]); $telescops[] = $rs['OBSERVAT'][$key] . '/' . $rs['INSTRUME'][$key] . '/' . $rs['TELESCOP'][$key]; } /*$telescops = $rs['OBSERVAT'];*/ $wavemax = $rs['WAVEMAX']; array_multisort($wavemax, SORT_DESC, $telescops, SORT_ASC, $data); $instrume = array_values(array_unique($telescops)); $tmp = explode(" ", $date); $timestamp_date = strtotime($tmp[0]); $mgraph = new MGraph(); $mgraph->title->Set("HELIO features catalog/Paris Observatory " . $tmp[0]); $mgraph->SetFrame(true); //$mgraph->SetBackgroundImagePos(1, 1); $graph = array(); //$numgraph = 0; for ($i = 0; $i < count($instrume); $i++) { // retourne tous les rangs pour l'instrument courant $keys = array(); foreach ($rs['OBSERVAT'] as $key => $val) { if (!strcmp($instrume[$i], $val . '/' . $rs['INSTRUME'][$key] . '/' . $rs['TELESCOP'][$key])) { $keys[] = $key; } } if ($with_obs) { $fits_path = 'ftp://ftpbass2000.obspm.fr/pub/helio/t2/';
public static function main($argv) { list($type, $id, $cmp_id) = $argv; // General. $o = null; $opts = array('xdim' => SG_DIM_X, 'ydim' => SG_DIM_Y, 'retObj' => true); // Options to pass to mbars(). $count_horiz = SG_CNT_HORIZ; // Number og graphs to place in each horizontal multi graph "row". $graphs = array(); if ($type == SG_T_TEAM) { $o = new Team($_GET['id']); $where = "f_team_id = {$o->team_id}"; } elseif ($type == SG_T_COACH) { $o = new Coach($_GET['id']); $where = "f_coach_id = {$o->coach_id}"; } elseif ($type == SG_T_PLAYER) { $o = new Player($_GET['id']); $where = "f_player_id = {$o->player_id}"; } if ($type != SG_T_LEAGUE && !is_object($o)) { return false; } // Make graphs components for multi graph plot. if ($type == SG_T_LEAGUE) { /* Played matches. */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, 1, 0)) AS 'Games_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('Games' => 'royalblue'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Games played", "Months", "Games", $opts)); /* Active teams */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; array_push($queries, "(SELECT COUNT(DISTINCT(tid)) FROM\n (\n SELECT team1_id AS 'tid', date_played FROM matches WHERE {$range}\n UNION\n SELECT team2_id AS 'tid', date_played FROM matches WHERE {$range}\n ) AS tmptbl) AS 'Active teams_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'\n"); } $query = "SELECT " . implode(', ', $queries); $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('Active teams' => 'olivedrab'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Active teams", "Months", "Teams", $opts)); /* Active coaches */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; array_push($queries, "(SELECT COUNT(DISTINCT(cid)) FROM\n (\n SELECT owned_by_coach_id AS 'cid', date_played FROM matches, teams WHERE team1_id = team_id AND {$range}\n UNION\n SELECT owned_by_coach_id AS 'cid', date_played FROM matches, teams WHERE team2_id = team_id AND {$range}\n ) AS tmptbl) AS 'Active coaches_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'\n"); } $query = "SELECT " . implode(', ', $queries); $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('Active coaches' => 'darkorange1'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Active coaches", "Months", "Coaches", $opts)); /* Played matches. */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH_DAYS) as $i) { # Hack (for display purposes) set month -> year, day -> month $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} DAY)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} DAY)))\n AND\n (DAY(date_played) = DAY(SUBDATE(DATE(NOW()), INTERVAL {$i} DAY)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, 1, 0)) AS 'Games_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} DAY)) AS 'yr_m{$i}'"); array_push($queries, "DAY(SUBDATE(DATE(NOW()), INTERVAL {$i} DAY)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('Games' => 'royalblue'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row, SG_MULTIBAR_HIST_LENGTH_DAYS); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Games played", "Days", "Games", $opts)); /* td & cp. */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, cp, 0)) AS 'CP_m{$i}'"); array_push($queries, "SUM(IF({$range}, td, 0)) AS 'TD_m{$i}'"); # array_push($queries, "SUM(IF($range, intcpt, 0)) AS 'int_m$i'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches, match_data WHERE f_match_id = match_id"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('CP' => 'seagreen', 'TD' => 'indianred'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "CP & TD history", "Months", "Amount", $opts)); /* CAS. */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, bh+si+ki, 0)) AS 'CAS_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches, match_data WHERE f_match_id = match_id"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('CAS' => 'firebrick1'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "CAS history", "Months", "Amount", $opts)); /* SMP. */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "SUM(IF($range, smp1+smp2, 0)) AS 'smp_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # $query = "SELECT ".implode(', ', $queries)." FROM matches"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('smp' => 'blue'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Total given sportsmanship points (smp)", "Months", "Points", $opts)); /* Avg. gate per match. */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "AVG(IF($range, gate/1000, NULL)) AS 'avg_gate_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # # $query = "SELECT ".implode(', ', $queries)." FROM matches"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('avg_gate' => 'blue'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Average gate per match (kilo)", "Months", "Gate", array_merge($opts, array('scale' => 'textlin')))); /* average absolute score diff. */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "AVG(IF($range, ABS(CONVERT(team1_score,SIGNED) - CONVERT(team2_score,SIGNED)), NULL)) AS 'avg_abs_diff_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # $query = "SELECT ".implode(', ', $queries)." FROM matches"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('avg_abs_diff' => 'blue'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Average absolute score difference history", "Months", "Avg. abs. score diff.", array_merge($opts, array('scale' => 'textlin')))); /* Average deta treasury */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "AVG(IF($range, ((income1+income2)/2)/1000, NULL)) AS 'avg_dtreasury_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # $query = "SELECT ".implode(', ', $queries)." FROM matches"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('avg_dtreasury' => 'blue'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Avg. change in team's treasury per match (kilo)", "Months", "Average change", array_merge($opts, array('scale' => 'textlin')))); /* Average fans at match. */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "AVG(IF($range, fans, NULL)) AS 'fans_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # $query = "SELECT ".implode(', ', $queries)." FROM matches"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('fans' => 'blue'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Average fans per match", "Months", "Average fans", array_merge($opts, array('scale' => 'textlin')))); /* Average stars and mercs hirings per match */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "AVG(IF($range, stars, NULL)) AS 'avg_stars_m$i'"); # array_push($queries, "AVG(IF($range, mercs, NULL)) AS 'avg_mercs_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # $tableMercs = "( # SELECT f_match_id, SUM(IF(f_player_id = ".ID_MERCS.", 1, 0)) AS mercs FROM match_data GROUP BY f_match_id # ) AS mercsTbl"; # $tableStars = "( # SELECT f_match_id, SUM(IF(f_player_id <= ".ID_STARS_BEGIN.", 1, 0)) AS stars FROM match_data GROUP BY f_match_id # ) AS starsTbl"; # $query = "SELECT ".implode(', ', $queries)." FROM matches, $tableMercs, $tableStars WHERE mercsTbl.f_match_id = matches.match_id AND starsTbl.f_match_id = matches.match_id"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('avg_stars' => 'red', 'avg_mercs' => 'green'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Avg. stars and mercs per match", "Months", "Average hirings", array_merge($opts, array('scale' => 'textlin')))); /* Injuries */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "SUM(IF($range, IF(inj = ".MNG.", 1, 0)+IF(agn1 = ".MNG.", 1, 0)+IF(agn2 = ".MNG.", 1, 0), 0)) AS 'mng_m$i'"); # array_push($queries, "SUM(IF($range, IF(inj = ".NI.", 1, 0)+IF(agn1 = ".NI.", 1, 0)+IF(agn2 = ".NI.", 1, 0), 0)) AS 'ni_m$i'"); # array_push($queries, "SUM(IF($range, IF(inj = ".MA.", 1, 0)+IF(agn1 = ".MA.", 1, 0)+IF(agn2 = ".MA.", 1, 0), 0)) AS 'ma_m$i'"); # array_push($queries, "SUM(IF($range, IF(inj = ".AV.", 1, 0)+IF(agn1 = ".AV.", 1, 0)+IF(agn2 = ".AV.", 1, 0), 0)) AS 'av_m$i'"); # array_push($queries, "SUM(IF($range, IF(inj = ".AG.", 1, 0)+IF(agn1 = ".AG.", 1, 0)+IF(agn2 = ".AG.", 1, 0), 0)) AS 'ag_m$i'"); # array_push($queries, "SUM(IF($range, IF(inj = ".ST.", 1, 0)+IF(agn1 = ".ST.", 1, 0)+IF(agn2 = ".ST.", 1, 0), 0)) AS 'st_m$i'"); # array_push($queries, "SUM(IF($range, IF(inj = ".DEAD.", 1, 0)+IF(agn1 = ".DEAD.", 1, 0)+IF(agn2 = ".DEAD.", 1, 0), 0)) AS 'dead_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # $query = "SELECT ".implode(', ', $queries)." FROM matches, match_data WHERE f_match_id = match_id"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('mng' => 'green', 'ni' => 'red', 'ma' => 'blue', 'av' => 'aqua', 'ag' => 'brown', 'st' => 'purple', 'dead' => 'slategray'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Types of sustained player injuries/statuses", "Months", "Amount", $opts)); /* Race distribution */ # global $raceididx; # $query = "SELECT DISTINCT(f_race_id) AS 'race', COUNT(f_race_id) 'cnt' FROM teams GROUP BY f_race_id"; # $result = mysql_query($query); # $data = array(); # while ($row = mysql_fetch_assoc($result)) { # $data[$raceididx[$row['race']]." ($row[cnt])"] = $row['cnt']; # } # $graph = new PieGraph($opts['xdim'],$opts['ydim'],"auto"); # $graph->SetShadow(); # $graph->title->Set('Current race distribution'); # $graph->title->SetFont(FF_FONT1,FS_BOLD); # $p1 = new PiePlot(array_values($data)); # $p1->SetLegends(array_keys($data)); # $p1->SetCenter(0.4); # $graph->Add($p1); # array_push($graphs, $graph); /* CAS distribution */ # $query = "SELECT SUM(bh) AS 'bh', SUM(si) AS 'si', SUM(ki) AS 'ki' FROM match_data"; # $result = mysql_query($query); # $o = (object) mysql_fetch_assoc($result); # $data = array("BH ($o->bh)" => $o->bh, "SI ($o->si)" => $o->si, "Ki ($o->ki)" => $o->ki); # $graph = new PieGraph($opts['xdim'],$opts['ydim'],"auto"); # $graph->SetShadow(); # $graph->title->Set('Current CAS distribution'); # $graph->title->SetFont(FF_FONT1,FS_BOLD); # $p1 = new PiePlot(array_values($data)); # $p1->SetLegends(array_keys($data)); # $p1->SetCenter(0.4); # $graph->Add($p1); # array_push($graphs, $graph); } else { /******************** * Current CAS ********************/ if (!$cmp_id && $o->mv_cas != 0) { $data = array("BH ({$o->mv_bh})" => $o->mv_bh, "SI ({$o->mv_si})" => $o->mv_si, "Ki ({$o->mv_ki})" => $o->mv_ki); $graph = new PieGraph($opts['xdim'], $opts['ydim'], "auto"); $graph->SetShadow(); $graph->title->Set('Current CAS distribution'); $graph->title->SetFont(FF_FONT1, FS_BOLD); $p1 = new PiePlot(array_values($data)); $p1->SetLegends(array_keys($data)); $p1->SetCenter(0.4); $graph->Add($p1); array_push($graphs, $graph); } /******************** * BH, SI and Ki ********************/ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, bh, 0)) AS 'BH_m{$i}'"); array_push($queries, "SUM(IF({$range}, si, 0)) AS 'SI_m{$i}'"); array_push($queries, "SUM(IF({$range}, ki, 0)) AS 'Ki_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches, match_data WHERE f_match_id = match_id AND {$where}"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('BH' => 'forestgreen', 'SI' => 'firebrick', 'Ki' => 'blue'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "BH, SI and Ki distribution history", "Months", "Amount", $opts)); /******************** * CP & TD ********************/ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, cp, 0)) AS 'CP_m{$i}'"); array_push($queries, "SUM(IF({$range}, td, 0)) AS 'TD_m{$i}'"); # array_push($queries, "SUM(IF($range, intcpt, 0)) AS 'int_m$i'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches, match_data WHERE f_match_id = match_id AND {$where}"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('CP' => 'forestgreen', 'TD' => 'firebrick'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "CP & TD distribution history", "Months", "Amount", $opts)); /******************** * Injuries ********************/ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, IF(inj = " . MNG . ", 1, 0)+IF(agn1 = " . MNG . ", 1, 0)+IF(agn2 = " . MNG . ", 1, 0), 0)) AS 'MNG_m{$i}'"); array_push($queries, "SUM(IF({$range}, IF(inj = " . NI . ", 1, 0)+IF(agn1 = " . NI . ", 1, 0)+IF(agn2 = " . NI . ", 1, 0), 0)) AS 'Ni_m{$i}'"); array_push($queries, "SUM(IF({$range}, IF(inj = " . MA . ", 1, 0)+IF(agn1 = " . MA . ", 1, 0)+IF(agn2 = " . MA . ", 1, 0), 0)) AS 'MA_m{$i}'"); array_push($queries, "SUM(IF({$range}, IF(inj = " . AV . ", 1, 0)+IF(agn1 = " . AV . ", 1, 0)+IF(agn2 = " . AV . ", 1, 0), 0)) AS 'AV_m{$i}'"); array_push($queries, "SUM(IF({$range}, IF(inj = " . AG . ", 1, 0)+IF(agn1 = " . AG . ", 1, 0)+IF(agn2 = " . AG . ", 1, 0), 0)) AS 'AG_m{$i}'"); array_push($queries, "SUM(IF({$range}, IF(inj = " . ST . ", 1, 0)+IF(agn1 = " . ST . ", 1, 0)+IF(agn2 = " . ST . ", 1, 0), 0)) AS 'ST_m{$i}'"); array_push($queries, "SUM(IF({$range}, IF(inj = " . DEAD . ", 1, 0)+IF(agn1 = " . DEAD . ", 1, 0)+IF(agn2 = " . DEAD . ", 1, 0), 0)) AS 'Dead_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches, match_data WHERE f_match_id = match_id AND {$where}"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('MNG' => 'green', 'Ni' => 'red', 'MA' => 'blue', 'AV' => 'aqua', 'AG' => 'brown', 'ST' => 'purple', 'Dead' => 'slategray'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Types of sustained player injuries/statuses", "Months", "Amount", $opts)); // Only if type = team. if ($type == SG_T_TEAM) { /******************** * Won, lost and draw ********************/ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF((team1_score > team2_score AND team1_id = {$o->team_id} OR team1_score < team2_score AND team2_id = {$o->team_id}) AND {$range}, 1, 0)) AS 'W_m{$i}'"); array_push($queries, "SUM(IF((team1_score < team2_score AND team1_id = {$o->team_id} OR team1_score > team2_score AND team2_id = {$o->team_id}) AND {$range}, 1, 0)) AS 'L_m{$i}'"); array_push($queries, "SUM(IF(team1_score = team2_score AND {$range}, 1, 0)) AS 'D_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches WHERE team1_id = {$o->team_id} OR team2_id = {$o->team_id}"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('W' => 'forestgreen', 'L' => 'firebrick', 'D' => 'blue'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Won, lost and draw distribution history", "Months", "Matches", $opts)); /* Average deta treasury */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "AVG(IF({$range}, IF(team1_id = {$o->team_id}, income1, income2)/1000, NULL)) AS 'Avg. change_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches WHERE team1_id = {$o->team_id} OR team2_id = {$o->team_id}"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('Avg. change' => 'darkolivegreen4'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Avg. change in team's treasury per match (kilo)", "Months", "Average change", array_merge($opts, array('scale' => 'textlin')))); /* SMP. */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, IF(team1_id = {$o->team_id}, smp1, smp2), 0)) AS 'SMP_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches WHERE team1_id = {$o->team_id} OR team2_id = {$o->team_id}"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('SMP' => 'blue'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Total given sportsmanship points (smp)", "Months", "Points", $opts)); } } // Multi plot, baby! $mgraph = new MGraph(); $count = count($graphs); for ($i = $j = 1; $i + ($j - 1) * $count_horiz <= $count; $j += $i == $count_horiz ? 1 : 0, $i = $i == $count_horiz ? 1 : $i + 1) { // i is horiz, j is vert. $mgraph->Add(array_shift($graphs), ($i - 1) * $opts['xdim'], ($j - 1) * $opts['ydim']); } return $mgraph->Stroke(); }
// Setup the wind speed graph $graph2 = new Graph(300, 800); $graph2->SetScale('datlin'); $graph2->Set90AndMargin(50, 30, 60, 30); $graph2->SetMarginColor('lightgray:1.7'); $graph2->SetFrame(true, 'white', 0); $graph2->SetBox(); $graph2->title->Set('Windspeed'); $graph2->title->SetFont(FF_ARIAL, FS_BOLD, 14); $graph2->title->SetMargin(10); $graph2->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 9); $graph2->xaxis->scale->SetDateFormat('h:i'); $graph2->xgrid->Show(); $graph2->yaxis->SetLabelAngle(45); $graph2->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 9); $graph2->yaxis->SetLabelMargin(0); $graph2->yaxis->scale->SetAutoMin(0); $line2 = new LinePlot($data_windspeed, $xdata); $line2->SetStepStyle(); $line2->SetColor('red'); $graph2->Add($line2); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetMargin(2, 2, 2, 2); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->SetFillColor('lightgray'); $mgraph->Add($graph); $mgraph->Add($graph2, 300, 0); $mgraph->Stroke();
public function road($keyword) { $mgr = new MGraph(); return $mgr->allRoadEx($keyword); }
function gantt_chart($p_metrics, $p_title, $p_subtitle, $p_graph_width = 300, $p_graph_height = 380) { $t_graph_font = graph_get_font(); $t_metrics = $p_metrics['metrics']; $t_range = $p_metrics['range']; // Diff in weeks of the range: $t_60s = 60; // 1 minute $t_60min = 60; // 1 hour $t_24h = 24; // 1 day $t_7d = 7; // 1 week $t_minute = $t_60s; $t_hour = $t_60min * $t_minute; $t_day = $t_24h * $t_hour; $t_week = $t_7d * $t_day; $t_gantt_chart_max_rows = plugin_config_get('rows_max'); error_check(is_array($t_metrics) ? count($t_metrics) : 0, $p_title . " (" . $p_subtitle . ")"); if (plugin_config_get('eczlibrary') == ON) { // DO NOTHING SINCE eczlibrary DOES NOT SUPPORT GANTT CHART } else { // A new graph with automatic size $graph = new GanttGraph(0, 0, "auto"); $graph->SetShadow(); // Add title and subtitle $graph->title->Set($p_title); $graph->title->SetFont($t_graph_font, FS_BOLD, 12); $graph->subtitle->Set($p_subtitle); // Show day, week and month scale $graph->ShowHeaders(GANTT_HDAY | GANTT_HWEEK | GANTT_HMONTH); // Instead of week number show the date for the first day in the week // on the week scale $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY); // Make the week scale font smaller than the default $graph->scale->week->SetFont($t_graph_font, FS_NORMAL, 8); // Use the short name of the month together with a 2 digit year // on the month scale $graph->scale->month->SetStyle(MONTHSTYLE_SHORTNAMEYEAR4); $graph->scale->month->SetFontColor("white"); $graph->scale->month->SetBackgroundColor("blue"); // Setup a horizontal grid $graph->hgrid->Show(); $graph->hgrid->SetRowFillColor('darkblue@0.9'); // Setup a vertical grid // $graph->vgrid->Show(); //Setup the divider display $graph->scale->divider->SetWeight(3); $graph->scale->divider->SetColor("darkblue"); $graph->scale->dividerh->SetWeight(3); $graph->scale->dividerh->SetColor("darkblue"); $graph->scale->dividerh->Show(); $graph->scale->actinfo->vgrid->SetStyle('solid'); $graph->scale->actinfo->vgrid->SetColor('darkblue'); $graph->scale->actinfo->vgrid->Show(); // // Set the column headers and font // $graph->scale->actinfo->SetColTitles( array('Task','Start','End'),array(100)); // $graph->scale->actinfo->SetFont( $t_graph_font, FS_BOLD, 10 ); //Adding columns: //The following is an example: 1st element, an array of the columns, // 2nd element an optional array of min width of the columns (here the min width of the 2 first columns) //$graph->scale->actinfo->SetColTitles( // array('Note','Task','Duration','Start','Finish'),array(30,100)); //Adding a table title $graph->scale->tableTitle->Set("{$p_subtitle}"); $graph->scale->tableTitle->SetFont($t_graph_font, FS_NORMAL, 8); $graph->scale->SetTableTitleBackground('darkblue@0.6'); $graph->scale->tableTitle->Show(); // if ( null != $t_constrain ){ // $t_activity->SetConstrain( $t_constrain, CONSTRAIN_ENDSTART ); // } // if ( null != $t_constrain ){ // $t_activity->SetConstrain( $t_constrain['row'], $t_constrain['type'] ); // } // We first need to get the list of rows, in order to know whether to // display the constraint or not (in case of missing referenced row) $t_row_list = array(); foreach ($t_metrics as $t_metric_row) { $t_row_list[] = $t_metric_row[0]; } foreach ($t_metrics as $t_metric_row) { $t_row = $t_metric_row[0] % $t_gantt_chart_max_rows; $t_activity_type = $t_metric_row[1]; $t_bug_id = $t_metric_row[2]; $t_start_date = $t_metric_row[3]; $t_end_date = $t_metric_row[4]; $t_extra = " {$t_bug_id}" . $t_metric_row[5]; $t_level = $t_metric_row[6]; $t_constraints = $t_metric_row[7]; if (isset($t_level)) { $t_row_label = utf8_str_pad('', $t_level * 2, ' ') . htmlspecialchars_decode(bug_format_summary($t_bug_id, SUMMARY_FIELD)); } else { $t_row_label = htmlspecialchars_decode(bug_format_summary($t_bug_id, SUMMARY_FIELD)); } // Limit the label to max defined $t_row_label = strlen($t_row_label) > plugin_config_get('label_max') ? substr($t_row_label, 0, plugin_config_get('label_max') - 3) . '...' : $t_row_label; $t_activity_arr = array('left' => null, 'main' => array('row' => $t_row, 'label' => $t_row_label, 'start' => $t_start_date, 'end' => $t_end_date, 'info' => $t_extra), 'right' => null); if ($t_end_date < $t_range['min']) { // complete left bar // ** | o[ ]-[ ]o $t_activity_arr = array('left' => array('row' => $t_row, 'label' => $t_row_label, 'start' => $t_range['min'], 'end' => $t_range['min'], 'info' => "<- " . graph_date_format($t_start_date)), 'main' => null, 'right' => array('row' => $t_row, 'label' => "", 'start' => $t_range['min'] + $t_day, 'end' => $t_range['min'] + $t_day, 'info' => "<<- [" . graph_date_format($t_start_date) . " / " . graph_date_format($t_end_date) . "]" . $t_extra)); } else { if ($t_range['max'] < $t_start_date) { // complete right bar // o[ ]-[ ]o | ** $t_activity_arr = array('left' => array('row' => $t_row, 'label' => $t_row_label, 'start' => $t_range['max'] - $t_day, 'end' => $t_range['max'] - $t_day, 'info' => ""), 'main' => null, 'right' => array('row' => $t_row, 'label' => "", 'start' => $t_range['max'], 'end' => $t_range['max'], 'info' => "[" . graph_date_format($t_start_date) . " / " . graph_date_format($t_end_date) . "] ->>" . $t_extra)); } else { if ($t_start_date < $t_range['min']) { // left bar // * | o[ ]-[ ] $t_activity_arr['left'] = array('row' => $t_row, 'label' => '', 'start' => $t_range['min'], 'end' => $t_range['min'], 'info' => "<- " . graph_date_format($t_start_date)); $t_activity_arr['main']['start'] = $t_range['min'] + $t_day; //4 * $t_day;// @TODO: what happens if duration is less than that } if ($t_range['max'] < $t_end_date) { // right bar // [ ]-[ ]o | * $t_activity_arr['main']['end'] = $t_range['max'] - $t_day; //4 * $t_day; $t_activity_arr['main']['info'] = ""; $t_activity_arr['right'] = array('row' => $t_row, 'label' => "", 'start' => $t_range['max'], 'end' => $t_range['max'], 'info' => graph_date_format($t_end_date) . " ->" . $t_extra); } } } switch ($t_activity_type) { case ACTYPE_NORMAL: if (null != $t_activity_arr['left']) { $t_activity_left = new GanttBar($t_activity_arr['left']['row'], $t_activity_arr['left']['label'], graph_date_format($t_activity_arr['left']['start']), graph_date_format($t_activity_arr['left']['end']), $t_activity_arr['left']['info']); // Add a left marker $t_activity_left->leftMark->Show(); $t_activity_left->leftMark->SetType(MARK_FILLEDCIRCLE); $t_activity_left->leftMark->SetWidth(8); // $t_activity_left->leftMark->SetColor( 'red' ); $t_activity_left->leftMark->SetFillColor('red'); $t_activity_left->leftMark->title->Set(''); $t_activity_left->leftMark->title->SetFont($t_graph_font, FS_NORMAL, 8); $t_activity_left->leftMark->title->SetColor('white'); if (null != gantt_get_resolution_date($t_bug_id)) { $t_activity_left->SetPattern(BAND_RDIAG, get_status_color(bug_get_field($t_bug_id, 'status'))); } $t_activity_left->SetFillColor(get_status_color(bug_get_field($t_bug_id, 'status'))); } if (null != $t_activity_arr['main']) { $t_activity_main = new GanttBar($t_activity_arr['main']['row'], $t_activity_arr['main']['label'], graph_date_format($t_activity_arr['main']['start']), graph_date_format($t_activity_arr['main']['end']), $t_activity_arr['main']['info']); if (null != gantt_get_resolution_date($t_bug_id)) { $t_activity_main->SetPattern(BAND_RDIAG, get_status_color(bug_get_field($t_bug_id, 'status'))); } $t_activity_main->SetFillColor(get_status_color(bug_get_field($t_bug_id, 'status'))); $t_activity_main->title->SetFont($t_graph_font, FS_NORMAL, 8); // Set the constraint if any... foreach ($t_constraints as $t_constraint) { // ... and if possible if (in_array($t_constraint['row'], $t_row_list)) { $t_activity_main->SetConstrain($t_constraint['row'], $t_constraint['type']); } } $graph->add($t_activity_main); } if (null != $t_activity_arr['right']) { $t_activity_right = new GanttBar($t_activity_arr['right']['row'], $t_activity_arr['right']['label'], graph_date_format($t_activity_arr['right']['start']), graph_date_format($t_activity_arr['right']['end']), $t_activity_arr['right']['info']); // Add a left marker $t_activity_right->rightMark->Show(); $t_activity_right->rightMark->SetType(MARK_FILLEDCIRCLE); $t_activity_right->rightMark->SetWidth(8); $t_activity_right->rightMark->SetColor('red'); $t_activity_right->rightMark->SetFillColor('red'); $t_activity_right->rightMark->title->Set(''); $t_activity_right->rightMark->title->SetFont($t_graph_font, FS_NORMAL, 8); $t_activity_right->rightMark->title->SetColor('white'); if (null != gantt_get_resolution_date($t_bug_id)) { $t_activity_right->SetPattern(BAND_RDIAG, get_status_color(bug_get_field($t_bug_id, 'status'))); } $t_activity_right->SetFillColor(get_status_color(bug_get_field($t_bug_id, 'status'))); } if (isset($t_activity_left)) { $graph->add($t_activity_left); } if (isset($t_activity_right)) { $graph->add($t_activity_right); } break; case ACTYPE_MILESTONE: $t_size = 5; if ($t_start_date < $t_range['min']) { $t_extra = "(<-- " . graph_date_format($t_start_date) . ")" . $t_extra; $t_start_date = $t_range['min']; $t_size = 8; } else { if ($t_range['max'] < $t_start_date) { $t_extra = "(--> " . graph_date_format($t_start_date) . ")" . $t_extra; $t_start_date = $t_range['max']; $t_size = 8; } } $t_milestone = new MileStone($t_row, $t_row_label, graph_date_format($t_start_date), $t_extra); $t_milestone->title->SetFont($t_graph_font, FS_NORMAL, 8); $t_milestone->mark->SetType(MARK_FILLEDCIRCLE); $t_milestone->mark->SetWidth($t_size); if (5 != $t_size) { $t_milestone->mark->SetFillColor('red'); } // foreach( $t_constraints as $t_constraint){ // $t_milestone->SetConstrain( $t_constraint['row'], $t_constraint['type'] ); // } $graph->add($t_milestone); break; } } // Setting the min and max date: $t_minmax = $graph->GetBarMinMax(); $t_week_in_seconds = 7 * 24 * 3600; // 1 week offset min: if ($t_minmax[0] - $t_week_in_seconds > 0) { $t_graph_offset_min = $t_minmax[0] - $t_week_in_seconds; } else { $t_graph_offset_min = $t_minmax[0]; } // 2 weeks offset max: $t_graph_offset_max = $t_minmax[1] + 3 * $t_week_in_seconds; $graph->SetDateRange(graph_date_format($t_graph_offset_min), graph_date_format($t_graph_offset_max)); // Add a vertical line for today if in the range of GetBarMinMax() (retruns an arry ($min, $max) ): $t_minmax = $graph->GetBarMinMax(); $t_now = date(config_get('short_date_format')); if ($t_now >= graph_date_format($t_graph_offset_min) && $t_now <= graph_date_format($t_graph_offset_max)) { $t_today = new GanttVLine($t_now, "Today", "darkred", 2, "solid"); $t_today->SetDayOffset(0.5); $graph->add($t_today); } // $t_today = new GanttVLine( "2011-03-01" , "" , "darkred", 2, "solid");// // $t_today->SetDayOffset(0.5); // $graph->add( $t_today ); $t_gantt_chart_height = gantt_chart_get_height($graph); $t_legend = gantt_chart_legend(false); $t_legend_height = 60; // Display the Gantt chart // $graph->Stroke(); //-------------------------------------- // Create a combined graph //-------------------------------------- $mgraph = new MGraph(); $mgraph->Add($graph, 0, 0); $mgraph->Add($t_legend, 0, $t_gantt_chart_height + $t_legend_height); $mgraph->Stroke(); } }