public function testSetFontForElementWithRendering() { $chart = new ezcGraphLineChart(); $chart->data['sampleData'] = new ezcGraphArrayDataSet(array('sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1)); $chart->options->font->path = $this->basePath . 'font.ttf'; $chart->legend->font->path = $this->basePath . 'font2.ttf'; $chart->render(500, 200); $this->assertEquals($this->basePath . 'font.ttf', $chart->options->font->path, 'General font face should be the old one.'); $this->assertEquals($this->basePath . 'font.ttf', $chart->title->font->path, 'Font face for X axis should be the old one.'); $this->assertTrue($chart->legend->font instanceof ezcGraphFontOptions, 'No fontOptions object was created.'); $this->assertEquals($this->basePath . 'font2.ttf', $chart->legend->font->path, 'Font face for legend has not changed.'); }
public function testRenderTextTopMargin() { $chart = new ezcGraphLineChart(); $chart->data['sample'] = new ezcGraphArrayDataSet(array('foo' => 1, 'bar' => 10)); $chart->title = 'Title of a chart'; $chart->title->position = ezcGraph::TOP; $chart->title->margin = 5; $mockedRenderer = $this->getMock('ezcGraphRenderer2d', array('drawText')); // Y-Axis $mockedRenderer->expects($this->at(0))->method('drawText')->with($this->equalTo(new ezcGraphBoundings(6, 6, 494, 14)), $this->equalTo('Title of a chart'), $this->equalTo(ezcGraph::CENTER | ezcGraph::MIDDLE)); $chart->renderer = $mockedRenderer; $chart->render(500, 200); }
public function testRenderNoLabelRendererZeroAxisSpace() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $chart = new ezcGraphLineChart(); $chart->additionalAxis['marker'] = $marker = new ezcGraphChartElementLabeledAxis(); $chart->additionalAxis['empty'] = $empty = new ezcGraphChartElementLabeledAxis(); $chart->xAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer(); $chart->xAxis->axisSpace = 0; $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer(); $chart->yAxis->axisSpace = 0; $marker->position = ezcGraph::LEFT; $marker->axisSpace = 0; $marker->chartPosition = 1; $empty->position = ezcGraph::RIGHT; $empty->chartPosition = 0.0; $empty->axisSpace = 0; $empty->label = 'Marker'; $chart->data['moreData'] = new ezcGraphArrayDataSet(array('sample 1' => 112, 'sample 2' => 54, 'sample 3' => 12, 'sample 4' => -167, 'sample 5' => 329)); $chart->data['Even more data'] = new ezcGraphArrayDataSet(array('sample 1' => 300, 'sample 2' => -30, 'sample 3' => 220, 'sample 4' => 67, 'sample 5' => 450)); $chart->render(500, 200, $filename); $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'); }
/** * 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); } }
public function testRenderTextBoxesFromBottom() { $chart = new ezcGraphLineChart(); $chart->palette = new ezcGraphPaletteBlack(); $chart->xAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer(); $chart->yAxis->axisLabelRenderer = new ezcGraphAxisBoxedLabelRenderer(); $chart->yAxis->position = ezcGraph::BOTTOM; $chart->data['sampleData'] = new ezcGraphArrayDataSet(array('sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1)); $mockedRenderer = $this->getMock('ezcGraphRenderer2d', array('drawText')); $mockedRenderer->expects($this->at(0))->method('drawText')->with($this->equalTo(new ezcGraphBoundings(102.0, 150.0, 138.0, 178.0), 1.0), $this->equalTo('0'), $this->equalTo(ezcGraph::MIDDLE | ezcGraph::RIGHT)); $mockedRenderer->expects($this->at(4))->method('drawText')->with($this->equalTo(new ezcGraphBoundings(102.0, 22.0, 138.0, 50.0), 1.0), $this->equalTo('400'), $this->equalTo(ezcGraph::MIDDLE | ezcGraph::RIGHT)); $chart->renderer = $mockedRenderer; $chart->render(500, 200); }
public function testStrToTimeLabelConvertionRendering() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $chart = new ezcGraphLineChart(); $chart->data['some data'] = new ezcGraphArrayDataSet(array('1.1.2001' => 12, '1.1.2002' => 324, '1.1.2003' => 238, '1.1.2004' => 123)); $chart->data['some data']->symbol = ezcGraph::DIAMOND; $chart->render(500, 200, $filename); $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'); }
<?php require_once 'tutorial_insert_data.php'; // Receive data from database $db = ezcDbInstance::get(); $query = $db->createSelectQuery(); $query->select('hits')->from('browser_hits'); $statement = $query->prepare(); $statement->execute(); // Create chart from data $chart = new ezcGraphLineChart(); $chart->title = 'Browser statistics'; $chart->options->fillLines = 220; $chart->data['browsers'] = new ezcGraphDatabaseDataSet($statement); $chart->data['average'] = new ezcGraphDataSetAveragePolynom($chart->data['browsers']); $chart->render(400, 150, 'tutorial_single.svg');
/** * Creates and prints the Axis Chart * * @static * */ static function printAxisChart($type = 'overall') { global $CFG_GLPI, $LANG; // Definition of Graph Labels $label = array('overall' => __('Overall satisfaction', 'helpdeskrating'), 'solution' => __('Satisfaction with the solution', 'helpdeskrating'), 'tech' => __('Satisfaction with the technician', 'helpdeskrating'), 'time' => __('Satisfaction with the chronological sequence', 'helpdeskrating')); $uid = PluginHelpdeskratingStatistic::getUserID(); if ($uid) { // Get Graph Data $data = PluginHelpdeskratingStatistic::getTimedRatings($type); if (empty($data)) { echo "<h1>{$label[$type]}</h1>"; echo __('no data available', 'helpdeskrating'); } else { // Create Graph $graph = new ezcGraphLineChart(); $graph->title = $label[$type]; // Set Graph Data foreach ($data as $key => $val) { $graph->data[$key] = new ezcGraphArrayDataSet($val); } // Graph Display options $graph->yAxis->min = 0; $graph->yAxis->max = 6; $graph->yAxis->majorStep = 1; $graph->xAxis = new ezcGraphChartElementNumericAxis(); $graph->xAxis->min = 1; $graph->xAxis->max = 12; $graph->xAxis->majorStep = 1; // Graph Output $filename = $uid . '_' . mt_rand() . '.svg'; $graph->render(800, 300, GLPI_GRAPH_DIR . '/' . $filename); echo "<object data='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file={$filename}'\n type='image/svg+xml' width='800' height='300'>\n <param name='src' value='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file={$filename}'>\n You need a browser capeable of SVG to display this image.\n </object> "; // */ } } }
public function testReturnFrom3dSvgLineChart() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $chart = new ezcGraphLineChart(); $chart->palette = new ezcGraphPaletteBlack(); $chart->renderer = new ezcGraphRenderer3d(); $chart->data['sampleData'] = new ezcGraphArrayDataSet(array('sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1)); $chart->data['moreData'] = new ezcGraphArrayDataSet(array('sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1)); $chart->data['evenMoreData'] = new ezcGraphArrayDataSet(array('sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1)); $chart->data['sampleData']->url = 'http://example.com/'; $chart->render(500, 200, $filename); $reference = $chart->renderer->getElementReferences(); // Check data references $this->assertSame(3, count($reference['data']), '3 datasets expected.'); $this->assertSame(5, count($reference['data']['sampleData']), '5 datapoints expected.'); $this->assertSame(1, count($reference['data']['sampleData']['sample 2']), '1 element for datapoint expected.'); $this->assertSame('ezcGraphCircle_113', $reference['data']['sampleData']['sample 2'][0], 'ezcGraphCircle element expected.'); // Check legend references $this->assertSame(3, count($reference['legend']), '3 legend items expected.'); $this->assertSame(2, count($reference['legend']['moreData']), '2 elements for legend item expected.'); $this->assertSame('ezcGraphCircle_6', $reference['legend']['moreData']['symbol'], 'ezcGraphCircle expected as legend symbol.'); $this->assertSame('ezcGraphTextBox_7', $reference['legend']['moreData']['text'], 'ezcGraphTextBox expected for legend text.'); // Check for legend URLs $this->assertSame(3, count($reference['legend_url']), '3 legend url items expected.'); $this->assertSame(null, $reference['legend_url']['moreData'], 'No link expected for "moreData".'); $this->assertSame('http://example.com/', $reference['legend_url']['sampleData'], 'Link expected for "sampleData".'); }
public function testReRenderChart() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $barChart = new ezcGraphLineChart(); $barChart->data['test'] = new ezcGraphArrayDataSet(array(5, 23, 42)); $color = $barChart->data['test']->color->default; $barChart->render(400, 200, $filename); $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'); // Render a second time with a new dataset, and expect the same result $barChart->data['test'] = new ezcGraphArrayDataSet(array(5, 23, 42)); $barChart->data['test']->color = $color; $barChart->render(400, 200, $filename); $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'); }
public function testRotatedAxisLabel() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $graph = new ezcGraphLineChart(); $graph->palette = new ezcGraphPaletteBlack(); $graph->data['sample1'] = new ezcGraphArrayDataSet(array(1, 4, 6, 8, 2)); $graph->data['sample1']->symbol = ezcGraph::SQUARE; $graph->data['sample2'] = new ezcGraphArrayDataSet(array(4, 6, 8, 2, 1)); $graph->data['sample2']->symbol = ezcGraph::BOX; $graph->xAxis->label = "Some axis label"; $graph->xAxis->labelRotation = 90; $graph->render(560, 250, $filename); $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'); }
public function testShortAxis() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $graph = new ezcGraphLineChart(); $graph->palette = new ezcGraphPaletteBlack(); $graph->legend->position = ezcGraph::BOTTOM; $graph->data['sample'] = new ezcGraphArrayDataSet(array(1, 4, 6, 8, 2)); $graph->renderer = new ezcGraphRenderer3d(); $graph->renderer->options->axisEndStyle = ezcGraph::NO_SYMBOL; $graph->renderer->options->shortAxis = true; $graph->render(560, 250, $filename); $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'); }
public function testRenderWithZeroAxisSpace() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $labelCount = 20; $data = $this->getRandomData($labelCount, 500, 2000, 23); $chart = new ezcGraphLineChart(); $chart->palette = new ezcGraphPaletteBlack(); $chart->data['sample'] = new ezcGraphArrayDataSet($data); // Set manual label count $chart->xAxis->labelCount = 21; $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer(); $chart->xAxis->axisLabelRenderer->angle = 45; $chart->xAxis->axisSpace = 0.1; $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer(); $chart->yAxis->axisSpace = 0; $chart->render(500, 200, $filename); $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'); }
<?php require 'ezc-setup.php'; header('Content-Type: image/svg+xml'); list($domains, $ips) = (require 'data-graph1.php'); $chart = new ezcGraphLineChart(); $chart->title = 'PHP Usage Statistics'; $chart->palette = new ezcGraphPaletteTango(); $chart->options->fillLines = 230; $chart->legend->title = "Legend"; $chart->xAxis->font->maxFontSize = 12; $chart->yAxis->font->maxFontSize = 12; $chart->title->font->maxFontSize = 20; $chart->data['domains'] = new ezcGraphArrayDataSet($domains); $chart->data['domains']->label = 'Domains'; $chart->data['ips'] = new ezcGraphArrayDataSet($ips); $chart->data['ips']->label = 'IP addresses'; $chart->driver = new ezcGraphSvgDriver(); $chart->render(600, 400, 'php://output');
<?php require_once 'tutorial_autoload.php'; $wikidata = (include 'tutorial_wikipedia_data.php'); $graph = new ezcGraphLineChart(); $graph->title = 'Wikipedia articles'; // Add data foreach ($wikidata as $language => $data) { $graph->data[$language] = new ezcGraphArrayDataSet($data); } $graph->yAxis->min = 0; // Use a different axis for the norwegian dataset $graph->additionalAxis['norwegian'] = $nAxis = new ezcGraphChartElementNumericAxis(); $nAxis->position = ezcGraph::BOTTOM; $nAxis->chartPosition = 1; $nAxis->min = 0; $graph->data['Norwegian']->yAxis = $nAxis; // Still use the marker $graph->additionalAxis['border'] = $marker = new ezcGraphChartElementNumericAxis(); $marker->position = ezcGraph::LEFT; $marker->chartPosition = 1 / 3; $graph->render(400, 150, 'tutorial_line_chart_additional_axis.svg');
<?php require_once 'tutorial_autoload.php'; $wikidata = (include 'tutorial_wikipedia_data.php'); $graph = new ezcGraphLineChart(); $graph->title = 'Some random data'; $graph->legend = false; $graph->xAxis = new ezcGraphChartElementNumericAxis(); $graph->xAxis->min = -15; $graph->xAxis->max = 15; $graph->xAxis->majorStep = 5; $data = array(array(), array()); for ($i = -10; $i <= 10; $i++) { $data[0][$i] = mt_rand(-23, 59); $data[1][$i] = mt_rand(-23, 59); } // Add data $graph->data['random blue'] = new ezcGraphArrayDataSet($data[0]); $graph->data['random green'] = new ezcGraphArrayDataSet($data[1]); $graph->render(400, 150, 'tutorial_axis_numeric.svg');
public function testSvgLinkingWithWrongDriver() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $chart = new ezcGraphLineChart(); $chart->data['Line 1'] = new ezcGraphArrayDataSet(array('sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1)); $chart->render(500, 200, $filename); $chart->driver = new ezcGraphGdDriver(); $chart->options->font->path = $this->basePath . 'font.ttf'; try { ezcGraphTools::linkSvgElements($chart); } catch (ezcGraphToolsIncompatibleDriverException $e) { return true; } $this->fail('Expected ezcGraphToolsIncompatibleDriverException.'); }
/** * @dataProvider getAxisConfiguration */ public function testAxisSpaceConfiguration(ezcGraphAxisLabelRenderer $xRenderer, ezcGraphAxisLabelRenderer $yRenderer, $xSpace, $ySpace, $outerSpace, $xAlign, $yAlign) { $filename = $this->tempDir . __FUNCTION__ . '_' . self::$i . '.svg'; $chart = new ezcGraphLineChart(); $chart->palette = new ezcGraphPaletteBlack(); $chart->xAxis->axisLabelRenderer = $xRenderer; $chart->xAxis->axisSpace = $xSpace; $chart->xAxis->outerAxisSpace = $outerSpace; $chart->xAxis->position = $xAlign; $chart->yAxis->axisLabelRenderer = $yRenderer; $chart->yAxis->axisSpace = $ySpace; $chart->yAxis->outerAxisSpace = $outerSpace; $chart->yAxis->position = $yAlign; $chart->data['sampleData'] = new ezcGraphArrayDataSet(array('sample 1' => 250, 'sample 2' => 250, 'sample 3' => 0, 'sample 4' => 0, 'sample 5' => 500, 'sample 6' => 500)); $chart->render(560, 250, $filename); $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '_' . self::$i . '.svg'); }
public function testRenderCompleteLineChart() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $chart = new ezcGraphLineChart(); $chart->data['Sinus'] = new ezcGraphNumericDataSet(-180, 180, create_function('$x', 'return 10 * sin( deg2rad( $x ) );')); $chart->data['Cosinus'] = new ezcGraphNumericDataSet(-180, 180, create_function('$x', 'return 5 * cos( deg2rad( $x ) );')); $chart->xAxis = new ezcGraphChartElementNumericAxis(); $chart->render(500, 200, $filename); $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'); }
public function testRenderCompleteLineChart2() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $chart = new ezcGraphLineChart(); date_default_timezone_set('MET'); $chart->data['Statistical data'] = new ezcGraphArrayDataSet(array('Jun 2006' => 1300000, 'May 2006' => 1200000, 'Apr 2006' => 1100000, 'Mar 2006' => 1100000, 'Feb 2006' => 1000000, 'Jan 2006' => 965000)); $chart->data['Statistical data']->symbol = ezcGraph::BULLET; $chart->data['polynom order 2'] = new ezcGraphDataSetAveragePolynom($chart->data['Statistical data'], 2); $chart->xAxis = new ezcGraphChartElementNumericAxis(); try { $chart->render(500, 200, $filename); } catch (ezcGraphDatasetAverageInvalidKeysException $e) { return true; } $this->fail('Expected ezcGraphDatasetAverageInvalidKeysException.'); }
/** * 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); } }
/** Get groups assigned to tickets between 2 dates * @param $entrees array : array containing data to displayed * @param $options array : options * - title string title displayed (default empty) * - showtotal boolean show total in title (default false) * - width integer width of the graph (default 700) * - height integer height of the graph (default 300) * - unit integer height of the graph (default empty) * - type integer height of the graph (default line) : line bar pie * - csv boolean export to CSV (default true) * @return array contains the distinct groups assigned to a tickets */ static function showGraph(array $entrees, $options = array()) { global $CFG_GLPI, $LANG; //stevenes donato $ScreenWidth = "undefined"; if (!isset($_GET['screen_check']) && !isset($_GET['date1'])) { echo ' <script> document.location="' . $_SERVER["REQUEST_URI"] . '?screen_check=done&Width="+screen.width+"&Height="+screen.height; </script>'; exit; } if (!isset($_GET['screen_check']) && isset($_GET['date1'])) { echo ' <script> document.location="' . $_SERVER["REQUEST_URI"] . '&screen_check=done&Width="+screen.width+"&Height="+screen.height; </script>'; exit; } if (isset($_GET['Width'])) { $ScreenWidth = $_GET['Width']; } else { $ScreenWidth = 400; } //echo "Screen width = $ScreenWidth"; $CFG_GLPI["root_doc"] // stevenes if ($uid = Session::getLoginUserID(false)) { if (!isset($_SESSION['glpigraphtype'])) { $_SESSION['glpigraphtype'] = $CFG_GLPI['default_graphtype']; } $param['showtotal'] = false; $param['title'] = ''; // $param['width'] = $_SESSION['plugin_mobile']['screen_width'] - 50; // $param['width'] = $ScreenWidth - 50; $param['width'] = $ScreenWidth - 50; $param['height'] = 200; $param['unit'] = ''; $param['type'] = 'line'; $param['csv'] = true; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $param[$key] = $val; } } // Clean data if (is_array($entrees) && count($entrees)) { foreach ($entrees as $key => $val) { if (!is_array($val) || count($val) == 0) { unset($entrees[$key]); } } } if (!is_array($entrees) || count($entrees) == 0) { if (!empty($param['title'])) { echo "<h3>" . $param['title'] . " : </h3>" . $LANG['stats'][2] . "<br />"; } return false; } switch ($param['type']) { case 'pie': // Check datas : sum must be > 0 reset($entrees); $sum = array_sum(current($entrees)); while ($sum == 0 && ($data = next($entrees))) { $sum += array_sum($data); } if ($sum == 0) { return false; } $graph = new ezcGraphPieChart(); $graph->palette = new GraphPalette(); $graph->options->font->maxFontSize = 15; $graph->title->background = '#EEEEEC'; $graph->renderer = new ezcGraphRenderer3d(); $graph->renderer->options->pieChartHeight = 20; $graph->renderer->options->moveOut = 0.2; $graph->renderer->options->pieChartOffset = 63; $graph->renderer->options->pieChartGleam = 0.3; $graph->renderer->options->pieChartGleamColor = '#FFFFFF'; $graph->renderer->options->pieChartGleamBorder = 2; $graph->renderer->options->pieChartShadowSize = 5; $graph->renderer->options->pieChartShadowColor = '#BABDB6'; break; case 'bar': $graph = new ezcGraphBarChart(); $graph->options->fillLines = 210; $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer(); $graph->xAxis->axisLabelRenderer->angle = 45; $graph->xAxis->axisSpace = 0.2; $graph->yAxis->min = 0; $graph->palette = new GraphPalette(); $graph->options->font->maxFontSize = 15; $graph->title->background = '#EEEEEC'; $graph->renderer = new ezcGraphRenderer3d(); $graph->renderer->options->legendSymbolGleam = 0.5; $graph->renderer->options->barChartGleam = 0.5; $max = 0; foreach ($entrees as $key => $val) { if (count($val) > $max) { $max = count($val); } } $graph->xAxis->labelCount = $max; break; case 'line': // No break default case // No break default case default: $graph = new ezcGraphLineChart(); $graph->options->fillLines = 210; $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer(); $graph->xAxis->axisLabelRenderer->angle = 45; $graph->xAxis->axisSpace = 0.2; $graph->yAxis->min = 0; $graph->palette = new GraphPalette(); $graph->options->font->maxFontSize = 15; $graph->title->background = '#EEEEEC'; $graph->renderer = new ezcGraphRenderer3d(); $graph->renderer->options->legendSymbolGleam = 0.5; $graph->renderer->options->barChartGleam = 0.5; $graph->renderer->options->depth = 0.07000000000000001; break; } if (!empty($param['title'])) { $pretoadd = ""; $posttoadd = ""; if (!empty($param['unit'])) { $posttoadd = " " . $param['unit']; $pretoadd = " - "; } // Add to title if (count($entrees) == 1) { $param['title'] .= $pretoadd; if ($param['showtotal'] == 1) { reset($entrees); $param['title'] .= array_sum(current($entrees)); } $param['title'] .= $posttoadd; } else { // add sum to legend and unit to title $param['title'] .= $pretoadd . $posttoadd; if ($param['showtotal'] == 1) { $entree_tmp = $entrees; $entrees = array(); foreach ($entree_tmp as $key => $data) { $entrees[$key . " (" . array_sum($data) . ")"] = $data; } } } //$graph->title = $param['title']; echo "<h3>" . $param['title'] . "</h3>"; } if (count($entrees) == 1) { $graph->legend = false; } $graphtype = $_SESSION['glpigraphtype']; if (in_array(navigatorDetect(), array('Android'))) { $graphtype = 'png'; } switch ($graphtype) { case "png": $extension = "png"; $graph->driver = new ezcGraphGdDriver(); $graph->options->font = GLPI_FONT_FREESANS; break; default: $extension = "svg"; break; } $filename = $uid . '_' . mt_rand(); $csvfilename = $filename . '.csv'; $filename .= '.' . $extension; foreach ($entrees as $label => $data) { $graph->data[$label] = new ezcGraphArrayDataSet($data); $graph->data[$label]->symbol = ezcGraph::NO_SYMBOL; } switch ($graphtype) { case "png": $graph->render($param['width'], $param['height'], GLPI_GRAPH_DIR . '/' . $filename); echo "<img src='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file={$filename}'>"; break; default: $graph->render($param['width'], $param['height'], GLPI_GRAPH_DIR . '/' . $filename); echo "<object data='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file={$filename}'\n type='image/svg+xml' width='" . $param['width'] . "' height='" . $param['height'] . "'>\n <param name='src' value='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file={$filename}'>\n You need a browser capeable of SVG to display this image.\n </object> "; break; } // Render CSV if ($param['csv']) { if ($fp = fopen(GLPI_GRAPH_DIR . '/' . $csvfilename, 'w')) { // reformat datas $values = array(); $labels = array(); $row_num = 0; foreach ($entrees as $label => $data) { $labels[$row_num] = $label; if (is_array($data) && count($data)) { foreach ($data as $key => $val) { if (!isset($values[$key])) { $values[$key] = array(); } $values[$key][$row_num] = $val; } } $row_num++; } ksort($values); // Print labels fwrite($fp, $CFG_GLPI["csv_export_delimiter"]); foreach ($labels as $val) { fwrite($fp, $val . $CFG_GLPI["csv_export_delimiter"]); } fwrite($fp, "\n"); foreach ($values as $key => $data) { fwrite($fp, $key . $CFG_GLPI["csv_export_delimiter"]); foreach ($data as $value) { fwrite($fp, $value . $CFG_GLPI["csv_export_delimiter"]); } fwrite($fp, "\n"); } fclose($fp); } } } }
<?php require_once 'tutorial_autoload.php'; $graph = new ezcGraphLineChart(); $graph->title = 'Sinus'; $graph->legend->position = ezcGraph::BOTTOM; $graph->xAxis = new ezcGraphChartElementNumericAxis(); $graph->data['sinus'] = new ezcGraphNumericDataSet(-360, 360, create_function('$x', 'return sin( deg2rad( $x ) );')); $graph->data['sinus']->resolution = 120; $graph->render(400, 150, 'tutorial_dataset_numeric.svg');
public function testLineChartUnsyncedFonts3d() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $chart = new ezcGraphLineChart(); $chart->data['sample'] = new ezcGraphArrayDataSet(array('Mozilla' => 4375, 'IE' => 345, 'Opera' => 1204, 'wget' => 231, 'Safari' => 987)); $chart->renderer = new ezcGraphRenderer3d(); $chart->renderer->options->syncAxisFonts = false; $chart->driver = new ezcGraphSvgDriver(); $chart->render(500, 200, $filename); $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'); }
public function testRenderLineChartWithHighlightedData() { $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)); $chart->data['Line 2'] = new ezcGraphArrayDataSet(array('sample 1' => 543, 'sample 2' => 234, 'sample 3' => 298, 'sample 4' => 5, 'sample 5' => 613)); $chart->data['Line 1']->highlight = true; $chart->data['Line 2']->highlight['sample 5'] = true; $chart->options->highlightSize = 12; $chart->options->highlightFont->color = ezcGraphColor::fromHex('#3465A4'); $chart->options->highlightFont->background = ezcGraphColor::fromHex('#D3D7CF'); $chart->options->highlightFont->border = ezcGraphColor::fromHex('#888A85'); $chart->xAxis->axisLabelRenderer = new ezcGraphAxisBoxedLabelRenderer(); $chart->renderer = new ezcGraphRenderer3d(); $chart->renderer->options->barChartGleam = 0.5; $chart->renderer->options->legendSymbolGleam = 0.5; $chart->render(500, 200, $filename); $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'); }
public function testRenderLineChartBackgroundColorShortcut() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $chart = new ezcGraphLineChart(); $chart->data['sample'] = new ezcGraphArrayDataSet(array('Mozilla' => 4375, 'IE' => 345, 'Opera' => 1204, 'wget' => 231, 'Safari' => 987)); $chart->background = '#2e3436'; $chart->render(500, 200, $filename); $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'); }
public function testSquareAndBoxSymbolsInChart() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $graph = new ezcGraphLineChart(); $graph->palette = new ezcGraphPaletteBlack(); $graph->data['sample1'] = new ezcGraphArrayDataSet(array(1, 4, 6, 8, 2)); $graph->data['sample1']->symbol = ezcGraph::SQUARE; $graph->data['sample2'] = new ezcGraphArrayDataSet(array(4, 6, 8, 2, 1)); $graph->data['sample2']->symbol = ezcGraph::BOX; $graph->render(560, 250, $filename); $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'); }
public function testRenderTitleAndBottomSubtitle() { $chart = new ezcGraphLineChart(); $chart->data['sample'] = new ezcGraphArrayDataSet(array('foo' => 1, 'bar' => 10)); $chart->title = 'Title of a chart'; $chart->subtitle = 'Subtitle of a chart'; $chart->subtitle->position = ezcGraph::BOTTOM; $mockedRenderer = $this->getMock('ezcGraphRenderer2d', array('drawText')); // Y-Axis $mockedRenderer->expects($this->at(0))->method('drawText')->with($this->equalTo(new ezcGraphBoundings(1, 1, 499, 19)), $this->equalTo('Title of a chart'), $this->equalTo(ezcGraph::CENTER | ezcGraph::MIDDLE)); $mockedRenderer->expects($this->at(1))->method('drawText')->with($this->equalTo(new ezcGraphBoundings(1, 183, 499, 199)), $this->equalTo('Subtitle of a chart'), $this->equalTo(ezcGraph::CENTER | ezcGraph::MIDDLE)); $chart->renderer = $mockedRenderer; $chart->render(500, 200); }
/** Get groups assigned to tickets between 2 dates * * @param $entrees array containing data to displayed * @param $options array of possible options: * - title string title displayed (default empty) * - showtotal boolean show total in title (default false) * - width integer width of the graph (default 700) * - height integer height of the graph (default 300) * - unit integer height of the graph (default empty) * - type integer height of the graph (default line) : line bar stack pie * - csv boolean export to CSV (default true) * - datatype string datatype (count or average / default is count) * * @return array contains the distinct groups assigned to a tickets **/ static function showGraph(array $entrees, $options = array()) { global $CFG_GLPI; if ($uid = Session::getLoginUserID(false)) { if (!isset($_SESSION['glpigraphtype'])) { $_SESSION['glpigraphtype'] = $CFG_GLPI['default_graphtype']; } $param['showtotal'] = false; $param['title'] = ''; $param['width'] = 900; $param['height'] = 300; $param['unit'] = ''; $param['type'] = 'line'; $param['csv'] = true; $param['datatype'] = 'count'; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $param[$key] = $val; } } // Clean data if (is_array($entrees) && count($entrees)) { foreach ($entrees as $key => $val) { if (!is_array($val) || count($val) == 0) { unset($entrees[$key]); } } } if (!is_array($entrees) || count($entrees) == 0) { if (!empty($param['title'])) { echo "<div class='center'>" . $param['title'] . "<br>" . __('No item to display') . "</div>"; } return false; } echo "<div class='center-h' style='width:" . $param['width'] . "px'>"; echo "<div>"; switch ($param['type']) { case 'pie': // Check datas : sum must be > 0 reset($entrees); $sum = array_sum(current($entrees)); while ($sum == 0 && ($data = next($entrees))) { $sum += array_sum($data); } if ($sum == 0) { echo "</div></div>"; return false; } $graph = new ezcGraphPieChart(); $graph->palette = new GraphPalette(); $graph->options->font->maxFontSize = 15; $graph->title->background = '#EEEEEC'; $graph->renderer = new ezcGraphRenderer3d(); $graph->renderer->options->pieChartHeight = 20; $graph->renderer->options->moveOut = 0.2; $graph->renderer->options->pieChartOffset = 63; $graph->renderer->options->pieChartGleam = 0.3; $graph->renderer->options->pieChartGleamColor = '#FFFFFF'; $graph->renderer->options->pieChartGleamBorder = 2; $graph->renderer->options->pieChartShadowSize = 5; $graph->renderer->options->pieChartShadowColor = '#BABDB6'; if (count($entrees) == 1) { $graph->legend = false; } break; case 'bar': case 'stack': $graph = new ezcGraphBarChart(); $graph->options->fillLines = 210; $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer(); $graph->xAxis->axisLabelRenderer->angle = 45; $graph->xAxis->axisSpace = 0.2; $graph->yAxis->min = 0; $graph->palette = new GraphPalette(); $graph->options->font->maxFontSize = 15; $graph->title->background = '#EEEEEC'; $graph->renderer = new ezcGraphRenderer3d(); $graph->renderer->options->legendSymbolGleam = 0.5; $graph->renderer->options->barChartGleam = 0.5; if ($param['type'] == 'stack') { $graph->options->stackBars = true; } $max = 0; $valtmp = array(); foreach ($entrees as $key => $val) { foreach ($val as $key2 => $val2) { $valtmp[$key2] = $val2; } } $graph->xAxis->labelCount = count($valtmp); break; case 'line': // No break default case // No break default case default: $graph = new ezcGraphLineChart(); $graph->options->fillLines = 210; $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer(); $graph->xAxis->axisLabelRenderer->angle = 45; $graph->xAxis->axisSpace = 0.2; $graph->yAxis->min = 0; $graph->palette = new GraphPalette(); $graph->options->font->maxFontSize = 15; $graph->title->background = '#EEEEEC'; $graph->renderer = new ezcGraphRenderer3d(); $graph->renderer->options->legendSymbolGleam = 0.5; $graph->renderer->options->barChartGleam = 0.5; $graph->renderer->options->depth = 0.07000000000000001; break; } if (!empty($param['title'])) { $posttoadd = ""; if (!empty($param['unit'])) { $posttoadd = $param['unit']; } // Add to title if (count($entrees) == 1) { if ($param['showtotal'] == 1) { reset($entrees); $param['title'] = sprintf(__('%1$s - %2$s'), $param['title'], round(array_sum(current($entrees)), 2)); } $param['title'] = sprintf(__('%1$s - %2$s'), $param['title'], $posttoadd); } else { // add sum to legend and unit to title $param['title'] = sprintf(__('%1$s - %2$s'), $param['title'], $posttoadd); // Cannot display totals of already average values if ($param['showtotal'] == 1 && $param['datatype'] != 'average') { $entree_tmp = $entrees; $entrees = array(); foreach ($entree_tmp as $key => $data) { $sum = round(array_sum($data)); $entrees[$key . " ({$sum})"] = $data; } } } $graph->title = $param['title']; } switch ($_SESSION['glpigraphtype']) { case "png": $extension = "png"; $graph->driver = new ezcGraphGdDriver(); $graph->options->font = GLPI_FONT_FREESANS; break; default: $extension = "svg"; break; } $filename = $uid . '_' . mt_rand(); $csvfilename = $filename . '.csv'; $filename .= '.' . $extension; foreach ($entrees as $label => $data) { $graph->data[$label] = new ezcGraphArrayDataSet($data); $graph->data[$label]->symbol = ezcGraph::NO_SYMBOL; } switch ($_SESSION['glpigraphtype']) { case "png": $graph->render($param['width'], $param['height'], GLPI_GRAPH_DIR . '/' . $filename); echo "<img src='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file={$filename}'>"; break; default: $graph->render($param['width'], $param['height'], GLPI_GRAPH_DIR . '/' . $filename); echo "<object data='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file={$filename}'\n type='image/svg+xml' width='" . $param['width'] . "' height='" . $param['height'] . "'>\n <param name='src' value='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file={$filename}'>\n __('You need a browser capeable of SVG to display this image.')\n </object> "; break; } // Render CSV if ($param['csv']) { if ($fp = fopen(GLPI_GRAPH_DIR . '/' . $csvfilename, 'w')) { // reformat datas $values = array(); $labels = array(); $row_num = 0; foreach ($entrees as $label => $data) { $labels[$row_num] = $label; if (is_array($data) && count($data)) { foreach ($data as $key => $val) { if (!isset($values[$key])) { $values[$key] = array(); } if ($param['datatype'] == 'average') { $val = round($val, 2); } $values[$key][$row_num] = $val; } } $row_num++; } ksort($values); // Print labels fwrite($fp, $_SESSION["glpicsv_delimiter"]); foreach ($labels as $val) { fwrite($fp, $val . $_SESSION["glpicsv_delimiter"]); } fwrite($fp, "\n"); foreach ($values as $key => $data) { fwrite($fp, $key . $_SESSION["glpicsv_delimiter"]); foreach ($data as $value) { fwrite($fp, $value . $_SESSION["glpicsv_delimiter"]); } fwrite($fp, "\n"); } fclose($fp); } } echo "</div>"; echo "<div class='right' style='width:" . $param['width'] . "px'>"; $graphtype = ''; if ($_SESSION['glpigraphtype'] != 'svg') { $graphtype = "<a href='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?switchto=svg'>" . __('SVG') . "</a>"; } if ($_SESSION['glpigraphtype'] != 'png') { $graphtype = "<a href='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?switchto=png'>" . __('PNG') . "</a>"; } if ($param['csv']) { $graphtype = sprintf(__('%1$s / %2$s'), $graphtype, "<a href='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file={$csvfilename}'>" . __('CSV') . "</a>"); } echo $graphtype; echo "</div>"; echo '</div>'; } }
<?php require_once 'tutorial_autoload.php'; $wikidata = (include 'tutorial_wikipedia_data.php'); $graph = new ezcGraphLineChart(); $graph->title = 'Wikipedia articles'; $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer(); $graph->xAxis->axisLabelRenderer->angle = 45; $graph->xAxis->axisSpace = 0.2; // Add data foreach ($wikidata as $language => $data) { $graph->data[$language] = new ezcGraphArrayDataSet($data); } $graph->data['German']->displayType = ezcGraph::LINE; $graph->options->fillLines = 210; $graph->render(400, 150, 'tutorial_rotated_labels.svg');