Пример #1
0
 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.');
 }
Пример #2
0
 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);
 }
Пример #3
0
 /**
  * @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');
 }
Пример #4
0
 /**
  * Construct pie chart
  *
  * Construct pie chart and assign common setting to fit it to arbit layout
  * settings
  *
  * @param string $title
  * @return void
  */
 public function __construct($title)
 {
     parent::__construct();
     // Use specific arbit palette
     $this->palette = new ChartPalette();
     // Use 2D renderer by default for line charts
     $this->renderer = new \ezcGraphRenderer2d();
     // More beautiful formatting for legend
     $this->renderer->options->dataBorder = 0;
     $this->renderer->options->legendSymbolGleam = 0.3;
     $this->renderer->options->legendSymbolGleamSize = 0.9;
     $this->renderer->options->legendSymbolGleamColor = '#FFFFFF';
     // Line chart formatting options
     $this->options->fillLines = 255;
     $this->renderer->options->shortAxis = true;
     $this->renderer->options->axisEndStyle = \ezcGraph::NO_SYMBOL;
     // Include SVG font for more precise text rendering
     $this->options->font = __DIR__ . '/font.svg';
     // Line chart specific options
     $this->options->lineThickness = 2;
     $this->options->highlightSize = 12;
     $this->options->highlightFont->background = '#eeeeef80';
     $this->options->highlightFont->border = '#babdb6';
     $this->options->highlightFont->borderWidth = 1;
     $this->legend->position = \ezcGraph::BOTTOM;
     $this->legend->borderWidth = 1;
     $this->title->borderWidth = 1;
     $this->title = $title;
     $this->background->image = __DIR__ . '/chart_background.png';
     $this->background->repeat = \ezcGraph::NO_REPEAT;
     $this->background->position = \ezcGraph::CENTER | \ezcGraph::MIDDLE;
     $this->xAxis = new \ezcGraphChartElementDateAxis();
     $this->xAxis->axisLabelRenderer = new \ezcGraphAxisCenteredLabelRenderer();
     $this->yAxis->axisLabelRenderer = new \ezcGraphAxisCenteredLabelRenderer();
     $this->yAxis->font->maxFontSize = 10;
 }
Пример #5
0
<?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');
Пример #6
0
 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');
 }
Пример #7
0
 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.');
 }
Пример #8
0
 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');
 }
Пример #9
0
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();
    }
}
Пример #10
0
 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');
 }
Пример #11
0
 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 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');
 }
Пример #13
0
 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');
 }
Пример #14
0
<?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');
 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);
 }
Пример #17
0
 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');
 }
Пример #18
0
 /**
  * Constructor
  * 
  * @param array $options Default option array
  * @return void
  * @ignore
  */
 public function __construct(array $options = array())
 {
     parent::__construct();
     $this->elements['xAxis']->axisLabelRenderer = new ezcGraphAxisBoxedLabelRenderer();
 }
Пример #19
0
 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.');
 }
Пример #20
0
 /**
  * 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);
     }
 }
Пример #21
0
 /**
  * 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> ";
             // */
         }
     }
 }
Пример #22
0
 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');
 }
<?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');
Пример #24
0
 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');
 }
Пример #25
0
 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');
 }
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);
}
Пример #27
0
 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');
 }
Пример #28
0
 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');