function graph_bydate($p_metrics, $p_labels, $p_title, $p_graph_width = 300, $p_graph_height = 380) { $t_graph_font = graph_get_font(); error_check(is_array($p_metrics) ? count($p_metrics) : 0, lang_get('by_date')); if (plugin_config_get('eczlibrary') == ON) { $t_metrics = array(); $t_dates = array_shift($p_metrics); //[0]; $t_cnt = count($p_metrics); foreach ($t_dates as $i => $val) { //$t_metrics[$val] for ($j = 0; $j < $t_cnt; $j++) { $t_metrics[$j][$val] = $p_metrics[$j][$i]; } } $graph = new ezcGraphLineChart(); $graph->background->color = '#FFFFFF'; $graph->xAxis = new ezcGraphChartElementNumericAxis(); for ($k = 0; $k < $t_cnt; $k++) { $graph->data[$k] = new ezcGraphArrayDataSet($t_metrics[$k]); $graph->data[$k]->label = $p_labels[$k + 1]; } $graph->xAxis->labelCallback = 'graph_date_format'; $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer(); $graph->xAxis->axisLabelRenderer->angle = -45; $graph->legend->position = ezcGraph::BOTTOM; $graph->legend->background = '#FFFFFF80'; $graph->driver = new ezcGraphGdDriver(); //$graph->driver->options->supersampling = 1; $graph->driver->options->jpegQuality = 100; $graph->driver->options->imageFormat = IMG_JPEG; $graph->title = $p_title . ' ' . lang_get('by_date'); $graph->options->font = $t_graph_font; $graph->renderToOutput($p_graph_width, $p_graph_height); } else { $graph = new Graph($p_graph_width, $p_graph_height); $graph->img->SetMargin(40, 140, 40, 100); if (ON == plugin_config_get('jpgraph_antialias')) { $graph->img->SetAntiAliasing(); } $graph->SetScale('linlin'); $graph->SetMarginColor('white'); $graph->SetFrame(false); $graph->title->Set($p_title . ' ' . lang_get('by_date')); $graph->title->SetFont($t_graph_font, FS_BOLD); $graph->legend->Pos(0.01, 0.05, 'right', 'top'); $graph->legend->SetShadow(false); $graph->legend->SetFillColor('white'); $graph->legend->SetLayout(LEGEND_VERT); $graph->legend->SetFont($t_graph_font); $graph->yaxis->scale->ticks->SetDirection(-1); $graph->yaxis->SetFont($t_graph_font); $graph->yaxis->scale->SetAutoMin(0); if (FF_FONT2 <= $t_graph_font) { $graph->xaxis->SetLabelAngle(60); } else { $graph->xaxis->SetLabelAngle(90); # can't rotate non truetype fonts } $graph->xaxis->SetLabelFormatCallback('graph_date_format'); $graph->xaxis->SetFont($t_graph_font); /* $t_line_colours = plugin_config_get( 'jpgraph_colors' ); $t_count_colours = count( $t_line_colours );*/ $t_lines = count($p_metrics) - 1; $t_line = array(); for ($i = 1; $i <= $t_lines; $i++) { $t_line[$i] = new LinePlot($p_metrics[$i], $p_metrics[0]); //$t_line[$i]->SetColor( $t_line_colours[$i % $t_count_colours] ); $t_line[$i]->SetCenter(); $t_line[$i]->SetLegend($p_labels[$i]); $graph->Add($t_line[$i]); } 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(); } }
public function testRenderLineChartToOutput() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $chart = new ezcGraphLineChart(); $chart->palette = new ezcGraphPaletteBlack(); $chart->data['Line 1'] = new ezcGraphArrayDataSet(array('sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1)); ob_start(); // Suppress header already sent warning @$chart->renderToOutput(500, 200); file_put_contents($filename, ob_get_clean()); $this->compare($this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg', $filename); }
/** * Generates a crash report upload statistics graph for currently * selected project and dumps it to stdout. * @param integer $w Desired image width. * @param integer $h Desired image height. * @param integer $period Desired time period (7, 30 or 365). * @throws CHttpException * @return void */ public static function generateUploadStatisticsGraph($w, $h, $period, $file = null) { if (!is_numeric($w) || $w <= 0 || $w > 1024) { throw new CHttpException(403, 'Invalid parameter'); } if (!is_numeric($h) || $h <= 0 || $h > 960) { throw new CHttpException(403, 'Invalid parameter'); } if (!is_numeric($period) || $period <= 0 || $period > 365) { throw new CHttpException(403, 'Invalid parameter'); } // Get current project info $curProjectId = Yii::app()->user->getCurProjectId(); $curVer = Project::PROJ_VER_NOT_SET; $versions = Yii::app()->user->getCurProjectVersions($curVer); // Prepare data $data = array(); $tomorrow = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y")); $finishDate = $tomorrow - 1; $curDate = $finishDate; $dateFrom = $curDate; while ($finishDate - $curDate < $period * 24 * 60 * 60) { // Calc the beginning of time interval if ($period > 30) { $dateFrom = mktime(0, 0, 0, date("m", $curDate) - 1, date("d", $curDate), date("Y", $curDate)); } else { if ($period > 7) { $dateFrom = mktime(0, 0, 0, date("m", $curDate), date("d", $curDate) - 6, date("Y", $curDate)); } else { $dateFrom = mktime(0, 0, 0, date("m", $curDate), date("d", $curDate), date("Y", $curDate)); } } // Get count of crash reports received within the period $criteria = new CDbCriteria(); $criteria->compare('project_id', $curProjectId); if ($curVer != Project::PROJ_VER_ALL) { $criteria->compare('appversion_id', $curVer); } $criteria->addBetweenCondition('received', $dateFrom, $curDate); $count = CrashReport::model()->count($criteria); // Add an item to data $item = array($period > 30 ? date('M y', $curDate) : date('j M', $curDate) => $count); $data = $item + $data; // Next time interval $curDate = $dateFrom - 1; } $graph = new ezcGraphLineChart(); $graph->palette = new ezcGraphPaletteEzBlue(); $graph->data['Versions'] = new ezcGraphArrayDataSet($data); $majorStep = round(max($data)); if ($majorStep == 0) { $majorStep = 1; } $graph->yAxis->majorStep = $majorStep; $graph->yAxis->minorStep = $graph->yAxis->majorStep / 5; $graph->xAxis->labelCount = 30; /*$graph->xAxis = new ezcGraphChartElementDateAxis(); $graph->xAxis->dateFormat = 'M'; $graph->xAxis->endDate = $finishDate; $graph->xAxis->startDate = $dateFrom; $graph->xAxis->interval = ezcGraphChartElementDateAxis::MONTH;*/ //$graph->data['Versions']->highlight = true; $graph->options->fillLines = 210; $graph->legend = false; $graph->legend->position = ezcGraph::RIGHT; $graph->options->font->name = 'Tahoma'; $graph->options->font->maxFontSize = 12; $graph->options->font->minFontSize = 1; if ($file === null) { $graph->renderToOutput($w, $h); } else { $graph->render($w, $h, $file); } }
function graph_cumulative_bydate2($p_metrics, $p_graph_width = 300, $p_graph_height = 380) { $t_graph_font = 'c:\\windows\\fonts\\arial.ttf'; //graph_get_font(); error_check(is_array($p_metrics) ? count($p_metrics) : 0, plugin_lang_get('cumulative') . ' ' . lang_get('by_date')); $graph = new ezcGraphLineChart(); $graph->xAxis = new ezcGraphChartElementNumericAxis(); $graph->data[0] = new ezcGraphArrayDataSet($p_metrics[0]); $graph->data[0]->label = plugin_lang_get('legend_reported'); $graph->data[0]->color = '#FF0000'; $graph->data[1] = new ezcGraphArrayDataSet($p_metrics[1]); $graph->data[1]->label = plugin_lang_get('legend_resolved'); $graph->data[1]->color = '#0000FF'; $graph->data[2] = new ezcGraphArrayDataSet($p_metrics[2]); $graph->data[2]->label = plugin_lang_get('legend_still_open'); $graph->data[2]->color = '#000000'; $graph->additionalAxis[2] = $nAxis = new ezcGraphChartElementNumericAxis(); $nAxis->chartPosition = 1; $nAxis->background = '#005500'; $nAxis->border = '#005500'; $nAxis->position = ezcGraph::BOTTOM; $graph->data[2]->yAxis = $nAxis; $graph->xAxis->labelCallback = 'graph_date_format'; $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer(); $graph->xAxis->axisLabelRenderer->angle = -45; //$graph->xAxis->axisSpace = .8; $graph->legend->position = ezcGraph::BOTTOM; $graph->legend->background = '#FFFFFF80'; $graph->driver = new ezcGraphGdDriver(); //$graph->driver->options->supersampling = 1; $graph->driver->options->jpegQuality = 100; $graph->driver->options->imageFormat = IMG_JPEG; // $graph->img->SetMargin( 40, 40, 40, 170 ); // if( ON == config_get_global( 'jpgraph_antialias' ) ) { // $graph->img->SetAntiAliasing(); // } // $graph->SetScale( 'linlin'); // $graph->yaxis->SetColor("red"); // $graph->SetY2Scale("lin"); // $graph->SetMarginColor( 'white' ); // $graph->SetFrame( false ); $graph->title = plugin_lang_get('cumulative') . ' ' . lang_get('by_date'); $graph->options->font = $t_graph_font; // $graph->title->SetFont( $t_graph_font, FS_BOLD ); /* $graph->legend->Pos( 0.05, 0.9, 'right', 'bottom' ); $graph->legend->SetShadow( false ); $graph->legend->SetFillColor( 'white' ); $graph->legend->SetLayout( LEGEND_HOR ); $graph->legend->SetFont( $t_graph_font ); $graph->yaxis->scale->ticks->SetDirection( -1 ); $graph->yaxis->SetFont( $t_graph_font ); $graph->y2axis->SetFont( $t_graph_font ); if( FF_FONT2 <= $t_graph_font ) { $graph->xaxis->SetLabelAngle( 60 ); } else { $graph->xaxis->SetLabelAngle( 90 ); # can't rotate non truetype fonts } $graph->xaxis->SetLabelFormatCallback( 'graph_date_format' ); $graph->xaxis->SetFont( $t_graph_font ); $p1 = new LinePlot( $reported_plot, $plot_date ); $p1->SetColor( 'blue' ); $p1->SetCenter(); $graph->AddY2( $p1 ); $p3 = new LinePlot( $still_open_plot, $plot_date ); $p3->SetColor( 'red' ); $p3->SetCenter(); $p3->SetLegend( ); $graph->Add( $p3 ); $p2 = new LinePlot( $resolved_plot, $plot_date ); $p2->SetColor( 'black' ); $p2->SetCenter(); $p2->SetLegend( ); $graph->AddY2( $p2 ); */ /* if( helper_show_queries() ) { $graph->subtitle->Set( db_count_queries() . ' queries (' . db_time_queries() . 'sec)' ); $graph->subtitle->SetFont( $t_graph_font, FS_NORMAL, 8 ); }*/ $graph->renderToOutput($p_graph_width, $p_graph_height); }
public function get_graph(array $args) { midgardmvc_core::get_instance()->authorization->require_user(); $stat_types = array('bmi', 'weight', 'vo2max'); $qb = new midgard_query_builder('fi_openkeidas_diary_stat'); $qb->add_constraint('person', '=', midgardmvc_core::get_instance()->authentication->get_person()->id); $qb->add_constraint('stat', 'IN', $stat_types); $qb->add_order('date', 'ASC'); $since = new midgard_datetime('6 months ago'); $qb->add_constraint('date', '>', $since); $stats = $qb->execute(); if (empty($stats)) { throw new midgardmvc_exception_notfound("No stats found"); } $dates = array(); foreach ($stats as $stat) { $date = $stat->date->format('d.m.Y'); if (!isset($dates[$date])) { $dates[$date] = array(); } $dates[$date][] = $stat; } $previous_value = array(); $this->data['stats'] = array(); foreach ($dates as $date => $stats) { foreach ($stats as $stat) { if (!isset($this->data['stats'][$stat->stat])) { $this->data['stats'][$stat->stat] = array(); } $value = round($stat->value, 1); $this->data['stats'][$stat->stat][$date] = $value; $previous_value[$stat->stat] = $value; } foreach ($stat_types as $stat_type) { if (!isset($this->data['stats'][$stat_type])) { continue; } if (!isset($this->data['stats'][$stat_type][$date]) && isset($previous_value[$stat_type])) { $this->data['stats'][$stat_type][$date] = $previous_value[$stat_type]; } } } midgardmvc_core::get_instance()->component->load_library('Graph'); $graph = new ezcGraphLineChart(); foreach ($this->data['stats'] as $name => $stats) { $graph->data[$this->get_label($name)] = new ezcGraphArrayDataSet($stats); $graph->data[$this->get_label($name)]->symbol = ezcGraph::BULLET; } $graph->driver = new fi_openkeidas_diary_graph_gd(); $graph->driver->options->imageFormat = IMG_PNG; $graph->options->font = midgardmvc_core::get_instance()->configuration->graph_font; $graph->legend->position = ezcGraph::BOTTOM; $graph->palette = new ezcGraphPaletteEz(); // render image directly to screen $graph->renderToOutput(575, 200); // wrap up the request midgardmvc_core::get_instance()->dispatcher->end_request(); }
/** * Generates a bug status dynamics graph for current project and desired * time period. * @param integer $w Image width. * @param integer $h Image height. * @param integer $period Time period (7, 30 or 365). * @return void */ public static function generateBugStatusDynamicsGraph($w, $h, $period, $file = null) { if (!is_numeric($w) || $w <= 0 || $w > 1024) { throw new CHttpException(403, 'Invalid parameter'); } if (!is_numeric($h) || $h <= 0 || $h > 960) { throw new CHttpException(403, 'Invalid parameter'); } if (!is_numeric($period) || $period <= 0 || $period > 365) { throw new CHttpException(403, 'Invalid parameter'); } // Get current project info $curProjectId = Yii::app()->user->getCurProjectId(); $curVer = Yii::app()->user->getCurProjectVer(); // Prepare data $dataAll = array(); $dataOpen = array(); $dataClosed = array(); $dataFixed = array(); $dataVerified = array(); $tomorrow = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y")); $finishDate = $tomorrow - 1; $curDate = $finishDate; $dateFrom = $curDate; while ($finishDate - $curDate < $period * 24 * 60 * 60) { // Calc the beginning of time interval if ($period > 30) { $dateFrom = mktime(0, 0, 0, date("m", $curDate) - 1, date("d", $curDate), date("Y", $curDate)); } else { if ($period > 7) { $dateFrom = mktime(0, 0, 0, date("m", $curDate), date("d", $curDate) - 6, date("Y", $curDate)); } else { $dateFrom = mktime(0, 0, 0, date("m", $curDate), date("d", $curDate), date("Y", $curDate)); } } // Get bug changes within the period $criteria = new CDbCriteria(); $criteria->compare('bug.project_id', $curProjectId, false, 'AND'); if ($curVer != -1) { $criteria->compare('bug.appversion_id', $curVer, false, 'AND'); } $criteria->addCondition('t.status_change_id IS NOT NULL', 'AND'); $criteria->addCondition('t.timestamp <=' . $curDate, 'AND'); $criteria->addCondition('t.id IN (SELECT MAX({{bug_change}}.id) FROM {{bug_change}} GROUP BY {{bug_change}}.bug_id)', 'AND'); $criteria->with = array('bug', 'statuschange'); $bugChanges = BugChange::model()->findAll($criteria); $countAll = 0; $countOpen = 0; $countClosed = 0; $countFixed = 0; $countVerified = 0; foreach ($bugChanges as $bugChange) { //print_r($bugChange->statuschange->status); if ($bugChange->statuschange->status < Bug::STATUS_OPEN_MAX) { $countOpen++; } else { if ($bugChange->statuschange->status > Bug::STATUS_OPEN_MAX) { $countClosed++; } } if ($bugChange->statuschange->status == Bug::STATUS_FIXED) { $countFixed++; } if ($bugChange->statuschange->status == Bug::STATUS_VERIFIED) { $countVerified++; } } // Add an item to data $key = $period > 30 ? date('M y', $curDate) : date('j M', $curDate); $dataAll = array($key => $countOpen + $countClosed) + $dataAll; $dataOpen = array($key => $countOpen) + $dataOpen; $dataClosed = array($key => $countClosed) + $dataClosed; $dataFixed = array($key => $countFixed) + $dataFixed; $dataVerified = array($key => $countVerified) + $dataVerified; // Next time interval $curDate = $dateFrom - 1; } /*var_dump($dataAll); var_dump($dataOpen); var_dump($dataClosed); var_dump($dataFixed); var_dump($dataVerified); return;*/ // Create graph $graph = new ezcGraphLineChart(); $graph->palette = new ezcGraphPaletteEzBlue(); $graph->palette->dataSetColor = array('#0000FF', '#FF0000', '#00FF00', '#000000'); $graph->data['All'] = new ezcGraphArrayDataSet($dataAll); $graph->data['Open'] = new ezcGraphArrayDataSet($dataOpen); $graph->data['Fixed'] = new ezcGraphArrayDataSet($dataFixed); $graph->data['Verified'] = new ezcGraphArrayDataSet($dataVerified); $graph->yAxis->majorStep = 10; $graph->yAxis->minorStep = 1; $graph->xAxis->labelCount = 30; $graph->options->fillLines = 210; $graph->legend = true; $graph->legend->position = ezcGraph::BOTTOM; $graph->options->font->name = 'Tahoma'; if ($file === null) { $graph->renderToOutput($w, $h); } else { $graph->render($w, $h, $file); } }
function draw_line_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 ezcGraphLineChart(); $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 = false; $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; // IF $CONFIG['charttype'] == 'area' !!! $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 = 20; $graph->yAxis->minorStep = 10; if ($CONFIG['type'] == 'percent') { $graph->yAxis->formatString = '%d%%'; } $EZCDATA = array(); foreach ($DATA as $value) { if ($CONFIG['type'] == 'percent') { $EZCDATA = array_merge($EZCDATA, array($value['key'] => $value['percent'])); } else { $EZCDATA = array_merge($EZCDATA, array($value['key'] => $value['value'])); } } $graph->data[$CONFIG['title']] = new ezcGraphArrayDataSet($EZCDATA); // IF $CONFIG['charttype'] == 'plotline' !!!, IF $CONFIG['charttype'] == 'line' than ezcGraph::NO_SYMBOL! $graph->data[$CONFIG['title']]->symbol = ezcGraph::BULLET; 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); }
function show_users_graph($x = 0, $y = 0) { global $is_logged_in, $is_admin; if (!$is_admin) { show_header('graph', $is_logged_in); throw new Error("Bad Argument", "You can't view that graph type"); } if (!$x) { $x = isset($_GET['x']) ? get('x') : 720; } if (!$y) { $y = isset($_GET['y']) ? get('y') : 500; } if (!isset($_GET['svg'])) { show_header('graph', $is_logged_in); echo "<div class='content_box'>\n" . "<h3>Users on the Exchange</h3>\n" . "<p>\n" . "<iframe src='?page=graph&type=users&x={$x}&y={$y}&svg' type='image/svg+xml' width='{$x}' height='{$y}' scrolling='no' frameborder='0'>\n" . "</iframe>\n" . "</p>\n" . "</div>\n"; return; } $graph = new ezcGraphLineChart(); $graph->palette = new customPalette(); $graph->options->fillLines = 180; $graph->options->font->maxFontSize = 12; $graph->legend->position = ezcGraph::BOTTOM; $graph->xAxis = new ezcGraphChartElementDateAxis(); $graph->xAxis->dateFormat = 'j M y'; $graph->xAxis->interval = 60 * 60 * 24 * 7 * 4; $users = get_users_graph_data(); $graph->data['Users'] = new ezcGraphArrayDataSet($users); $graph->renderToOutput($x, $y); exit; // we don't want the footer }
$hlp['gesamt'][substr(trim($stsem), -4) - $i] = 0; } $keys[$i] = substr(trim($stsem), -4) - $i; } } } //'0'-er ergänzen for ($i = 0; $i < 5; $i++) { foreach (array_keys($hlp) as $jeder) { if (empty($hlp[$jeder][substr(trim($stsem), -4) - $i])) { $hlp[$jeder][substr(trim($stsem), -4) - $i] = '0'; $keys[$i] = substr(trim($stsem), -4) - $i; } } } } //var_dump($hlp); //die; $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer(); $graph->xAxis->axisLabelRenderer->angle = 0; if (empty($keys)) { die('Keine Daten vorhanden'); } asort($keys, SORT_NUMERIC); foreach ($hlp as $status => $data) { reset($keys); ksort($data, SORT_NUMERIC); $graph->data[$status] = new ezcGraphArrayDataSet($data); } $graph->renderToOutput(500, 500);