function graph_group($p_metrics, $p_title = '', $p_graph_width = 350, $p_graph_height = 400, $p_baseline = 100) { # $p_metrics is an array of three arrays # $p_metrics['open'] = array( 'enum' => value, ...) # $p_metrics['resolved'] # $p_metrics['closed'] $t_graph_font = graph_get_font(); # count up array portions that are set $t_count = 0; foreach (array('open', 'resolved', 'closed') as $t_label) { if (isset($p_metrics[$t_label]) && is_array($p_metrics[$t_label])) { $t_count += array_sum($p_metrics[$t_label]); } } error_check($t_count, $p_title); # calculate totals $total = graph_total_metrics($p_metrics); if (plugin_config_get('eczlibrary') == ON) { $graph = new ezcGraphBarChart(); $graph->title = $p_title; $graph->background->color = '#FFFFFF'; $graph->options->font = $t_graph_font; $graph->options->font->maxFontSize = 12; $graph->legend = false; foreach (array('open', 'resolved', 'closed') as $t_label) { $graph->data[$t_label] = new ezcGraphArrayDataSet($p_metrics[$t_label]); } $graph->data['total'] = new ezcGraphArrayDataSet($total); //$graph->data['total']->displayType = ezcGraph::LINE; //$graph->data['total']->barMargin = -20; $graph->options->fillLines = 210; $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer(); $graph->xAxis->axisLabelRenderer->angle = 45; $graph->driver = new ezcGraphGdDriver(); //$graph->driver->options->supersampling = 1; $graph->driver->options->jpegQuality = 100; $graph->driver->options->imageFormat = IMG_JPEG; $graph->renderer->options->syncAxisFonts = false; $graph->renderToOutput($p_graph_width, $p_graph_height); } else { # defines margin according to height $graph = new Graph($p_graph_width, $p_graph_height); $graph->img->SetMargin(45, 35, 35, $p_baseline); if (ON == plugin_config_get('jpgraph_antialias')) { $graph->img->SetAntiAliasing(); } $graph->SetScale('textlin'); $graph->SetMarginColor('white'); $graph->SetFrame(false); $graph->title->SetFont($t_graph_font, FS_BOLD); $graph->title->Set($p_title); $graph->xaxis->SetTickLabels(array_keys($p_metrics['open'])); if (FF_FONT2 <= $t_graph_font) { $graph->xaxis->SetLabelAngle(60); } else { $graph->xaxis->SetLabelAngle(90); # can't rotate non truetype fonts } $graph->xaxis->SetFont($t_graph_font); $graph->legend->Pos(0.05, 0.08); $graph->legend->SetFont($t_graph_font); $graph->yaxis->scale->ticks->SetDirection(-1); $graph->yaxis->SetFont($t_graph_font); $graph->yscale->SetGrace(10); # adds on the same graph $tot = new BarPlot(array_values($total)); $tot->SetFillColor('lightblue'); $tot->SetWidth(0.7); $tot->SetLegend(plugin_lang_get('legend_total')); $graph->Add($tot); $p1 = new BarPlot(array_values($p_metrics['open'])); $p1->SetFillColor('yellow'); $p1->SetWidth(1); $p1->SetLegend(plugin_lang_get('legend_opened')); $p2 = new BarPlot(array_values($p_metrics['closed'])); $p2->SetFillColor('blue'); $p2->SetWidth(1); $p2->SetLegend(plugin_lang_get('legend_closed')); $p3 = new BarPlot(array_values($p_metrics['resolved'])); $p3->SetFillColor('red'); $p3->SetWidth(1); $p3->SetLegend(plugin_lang_get('legend_resolved')); $gbplot = new GroupBarPlot(array($p1, $p3, $p2)); $graph->Add($gbplot); if (helper_show_query_count()) { $graph->subtitle->Set(db_count_queries() . ' queries (' . db_time_queries() . 'sec)'); $graph->subtitle->SetFont($t_graph_font, FS_NORMAL, 8); } $graph->Stroke(); } }
function draw_stacked_chart($WIDTH, $HEIGHT, $DATA, $CONFIG, $LEGEND, $FONT, $PALETTE = 'default') { $palettename = return_palette_name($PALETTE); require dirname(__FILE__) . '/lib/ezc/Graph/mahara/palettes/' . $palettename . '.php'; $graph = new ezcGraphBarChart(); $paletteclass = generate_palette_class_name($palettename); $graph->palette = new $paletteclass(); $graph->title = $CONFIG['title']; $graph->subtitle = 'Created: ' . $CONFIG['ctime'] . ', modified: ' . $CONFIG['mtime']; $graph->subtitle->position = ezcGraph::BOTTOM; $graph->legend = true; $graph->legend->position = ezcGraph::BOTTOM; $graph->legend->symbolSize = $FONT['size']; $graph->background->padding = 10; $graph->driver = new ezcGraphGdDriver(); $graph->driver->options->imageFormat = IMG_PNG; switch ($FONT['type']) { case 'serif': $fontname = 'lib/ezc/Graph/mahara/fonts/LiberationSerif-Regular.ttf'; break; case 'sans': $fontname = 'lib/ezc/Graph/mahara/fonts/LiberationSans-Regular.ttf'; break; } $graph->options->font = $fontname; // Stack bars $graph->options->stackBars = true; $graph->options->fillLines = 128; // Alpha (0 <= Alpha <= 255) // Set the maximum font size for all chart elements $graph->options->font->maxFontSize = $FONT['size']; // Set the font size for the title independently to 14 $graph->title->font->maxFontSize = $FONT['titlesize']; $graph->yAxis->min = 0; $graph->yAxis->max = 100; $graph->yAxis->majorStep = 50; $graph->yAxis->minorStep = 10; if ($CONFIG['type'] == 'percent') { $graph->yAxis->formatString = '%d%%'; } if (isset($DATA['marker']) && !empty($DATA['marker'])) { $graph->additionalAxis['border'] = $marker = new ezcGraphChartElementNumericAxis(); $marker->position = ezcGraph::LEFT; //$marker->border = $graph->palette->majorGridColor; $marker->chartPosition = $DATA['marker']; $marker->label = $DATA['percent'] . '% '; } //$EZCDATA = array(); foreach ($DATA['data'] as $key => $value) { $graph->data[$key] = new ezcGraphArrayDataSet($value); } //$CONFIG['charttype'] = 'bar3d'; if (strtolower($CONFIG['chartspace']) == '3d') { $graph->renderer = new ezcGraphRenderer3d(); } //$graph->renderer->options->barMargin = .2; $graph->renderer->options->barPadding = 0.2; /* Build the PNG file and send it to the web browser */ $graph->renderToOutput($WIDTH, $HEIGHT); }