Exemplo n.º 1
0
 private function sourceGraph()
 {
     $q = ezcDbInstance::get()->createSelectQuery();
     $q->select('source, count(source)')->from('message')->groupBy('source');
     $s = $q->prepare();
     $s->execute();
     $chart = new ezcGraphPieChart();
     $chart->title = 'Sources';
     $chart->legend = false;
     $chart->palette = new ezcGraphPaletteEz();
     $chart->data['browsers'] = new ezcGraphDatabaseDataSet($s);
     $chart->render(300, 200, '/tmp/graph.png');
     return file_get_contents('/tmp/graph.png');
 }
Exemplo n.º 2
0
 /**
  * Generates a crash report version distribution graph for currently 
  * selected project and dumps it to stdout.
  * @param type $w Desired image width.
  * @param type $h Desired image height.
  * @throws CHttpException
  * @return void
  */
 public static function generateBugStatusDistributionGraph($w, $h, $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');
     }
     // Get current project info
     $curProjectId = Yii::app()->user->getCurProjectId();
     if ($curProjectId == false) {
         throw new CHttpException(403, 'Invalid parameter');
     }
     $curVer = Yii::app()->user->getCurProjectVer();
     // Prepare data
     $criteria = new CDbCriteria();
     $criteria->select = 'status, COUNT(*) as cnt';
     $criteria->group = 'status';
     $criteria->compare('project_id', $curProjectId);
     $criteria->order = 'status DESC';
     if ($curVer != -1) {
         $criteria->compare('appversion_id', $curVer == 0 ? null : $curVer);
     }
     $data = array();
     $models = Bug::model()->findAll($criteria);
     $totalCount = 0;
     $curVerStr = '';
     foreach ($models as $model) {
         $totalCount += $model->cnt;
         $data[Lookup::item('BugStatus', $model->status)] = $model->cnt;
     }
     // Check the case when $data is empty.
     if (count($data) == 0) {
         // Open out file
         if ($file != null) {
             $fout = @fopen($file, 'w');
             if ($fout == false) {
                 @unlink($tmpfile);
                 throw new CHttpException(403, 'Invalid file.');
             }
         }
         // No data available
         $fileName = Yii::app()->basePath . '/../images/no_data_available.png';
         if ($fd = @fopen($fileName, "r")) {
             $fsize = filesize($fileName);
             // Write HTTP headers
             header("Content-type: image/png");
             //header("Content-Disposition: filename=\"".$fileName."\"");
             header("Content-length: {$fsize}");
             header("Cache-control: private");
             //use this to open files directly
             // Write file content
             while (!feof($fd)) {
                 $buffer = fread($fd, 2048);
                 if ($file == null) {
                     echo $buffer;
                 } else {
                     fwrite($fout, $buffer);
                 }
             }
             if ($file != null) {
                 fclose($fout);
             }
             fclose($fd);
         }
         return;
     }
     $graph = new ezcGraphPieChart();
     $graph->palette = new ezcGraphPaletteEzRed();
     $graph->data['Versions'] = new ezcGraphArrayDataSet($data);
     $graph->legend = true;
     $graph->legend->position = ezcGraph::RIGHT;
     $graph->options->font->name = 'Tahoma';
     $graph->options->sum = $totalCount;
     $graph->options->summarizeCaption = 'Others';
     $graph->renderer->options->pieChartGleam = 0.3;
     $graph->renderer->options->pieChartGleamColor = '#FFFFFF';
     $graph->renderer->options->pieChartGleamBorder = 2;
     $graph->renderer = new ezcGraphRenderer3d();
     $graph->renderer->options->pieChartRotation = 0.8;
     $graph->renderer->options->pieChartShadowSize = 10;
     if ($file === null) {
         $graph->renderToOutput($w, $h);
     } else {
         $graph->render($w, $h, $file);
     }
 }
Exemplo n.º 3
0
if (isset($user_status)) {
    // build status chart
    /*TODO Generalize pie chart generation*/
    $graph = new ezcGraphPieChart();
    $graph->palette = new ezcGraphPaletteEzBlue();
    $graph->legend = false;
    $title = 'Status repartition for user ' . $user . ' (count)';
    $graph->data[$title] = new ezcGraphArrayDataSet($user_status);
    $graph->renderer = new ezcGraphRenderer3d();
    $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';
    $graph->renderer->options->pieChartHeight = 5;
    $graph->renderer->options->pieChartRotation = 0.8;
    $graph->driver = new ezcGraphGdDriver();
    $graph->options->font = 'app/img/KhmerOSclassic.ttf';
    $graph->driver->options->imageFormat = IMG_PNG;
    // FIXME change png name depending on user
    $graph->render(532, 195, 'app/img/graph/userStatusPieGraph-' . $user . '.png');
    echo '<h2>' . $title . '</h2>';
    echo '<img src="app/img/graph/userStatusPieGraph-' . $user . '.png"/>';
}
?>



Exemplo n.º 4
0
<?php

require 'Base/src/base.php';
function __autoload($className)
{
    ezcBase::autoload($className);
}
// Require custom palette
require dirname(__FILE__) . '/ez_red.php';
// Create the graph
$graph = new ezcGraphPieChart();
$graph->palette = new ezcGraphPaletteEzRed();
$graph->legend = false;
// Add the data and hilight norwegian data set
$graph->data['week'] = new ezcGraphArrayDataSet(array('Claudia Kosny' => 128, 'Kristof Coomans' => 70, 'Xavier Dutoit' => 64, 'David Jones' => 58, 'Lukasz Serwatka' => 45, 'Norman Leutner' => 22, 'Marko Zmak' => 20, 'sangib das' => 20, 'Nabil Alimi' => 19));
// Set graph title
$graph->title = '10 most active users on forum in last month';
// Use 3d renderer, and beautify it
$graph->renderer = new ezcGraphRenderer3d();
$graph->renderer->options->pieChartShadowSize = 12;
$graph->renderer->options->pieChartGleam = 0.5;
$graph->renderer->options->dataBorder = false;
$graph->renderer->options->pieChartHeight = 16;
$graph->renderer->options->legendSymbolGleam = 0.5;
$graph->renderer->options->pieChartOffset = 100;
$graph->driver = new ezcGraphSvgDriver();
// Output the graph with std SVG driver
$graph->render(500, 200, 'forum_month.svg');
Exemplo n.º 5
0
 public function testRenderer3dPieChartMissingLabels()
 {
     $filename = $this->tempDir . __FUNCTION__ . '.svg';
     $chart = new ezcGraphPieChart();
     $chart->data['TestCase'] = new ezcGraphArrayDataSet(array('Big' => 2.9, 'Small 1' => 0.03, 'Small 2' => 0.04, 'Small 3' => 0.03, 'Last' => 1));
     $chart->renderer = new ezcGraphRenderer3d();
     $chart->renderer->options->dataBorder = false;
     $chart->render(500, 200, $filename);
     $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg');
 }
Exemplo n.º 6
0
 public function testRender3dPieChartWithOneDataPoint()
 {
     $filename = $this->tempDir . __FUNCTION__ . '.svg';
     $chart = new ezcGraphPieChart();
     $chart->data['Skien'] = new ezcGraphArrayDataSet(array('Norwegian' => 10));
     $chart->renderer = new ezcGraphRenderer3d();
     $chart->renderer->options->dataBorder = false;
     $chart->render(500, 300, $filename);
     $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg');
 }
Exemplo n.º 7
0
 public function testPieChartSvgLinkingCustomCursor()
 {
     $filename = $this->tempDir . __FUNCTION__ . '.svg';
     $chart = new ezcGraphPieChart();
     $chart->data['sample'] = new ezcGraphArrayDataSet(array('Mozilla' => 4375, 'IE' => 345, 'Opera' => 1204, 'wget' => 231, 'Safari' => 987));
     $chart->data['sample']->url = 'http://example.org/browsers';
     $chart->data['sample']->url['Mozilla'] = 'http://example.org/browsers/mozilla';
     $chart->data['sample']->highlight['Opera'] = true;
     $chart->driver->options->linkCursor = 'crosshair';
     $chart->render(500, 200, $filename);
     ezcGraphTools::linkSvgElements($chart);
     $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg');
 }
<?php

require_once 'tutorial_autoload.php';
$graph = new ezcGraphPieChart();
$graph->palette = new ezcGraphPaletteEzRed();
$graph->title = 'Access statistics';
$graph->options->label = '%2$d (%3$.1f%%)';
$graph->data['Access statistics'] = new ezcGraphArrayDataSet(array('Mozilla' => 19113, 'Explorer' => 10917, 'Opera' => 1464, 'Safari' => 652, 'Konqueror' => 474));
$graph->data['Access statistics']->highlight['Explorer'] = true;
$graph->renderer = new ezcGraphRenderer3d();
$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->pieChartShadowSize = 5;
$graph->renderer->options->pieChartShadowColor = '#000000';
$graph->renderer->options->legendSymbolGleam = 0.5;
$graph->renderer->options->legendSymbolGleamSize = 0.9;
$graph->renderer->options->legendSymbolGleamColor = '#FFFFFF';
$graph->renderer->options->pieChartSymbolColor = '#55575388';
$graph->renderer->options->pieChartHeight = 5;
$graph->renderer->options->pieChartRotation = 0.8;
$graph->render(400, 150, 'tutorial_pie_chart_3d.svg');
Exemplo n.º 9
0
 public function testPieChartWithoutData()
 {
     try {
         $pieChart = new ezcGraphPieChart();
         $pieChart->render(400, 200);
     } catch (ezcGraphNoDataException $e) {
         return true;
     }
     $this->fail('Expected ezcGraphNoDataException.');
 }
Exemplo n.º 10
0
 public function testBottomLegend()
 {
     $filename = $this->tempDir . __FUNCTION__ . '.svg';
     $chart = new ezcGraphPieChart();
     $chart->data['sample'] = new ezcGraphArrayDataSet(array('Mozilla' => 4375, 'IE' => 345, 'Opera' => 1204, 'wget' => 231, 'Safari' => 987));
     $chart->legend->position = ezcGraph::BOTTOM;
     $chart->legend->padding = 2;
     $chart->render(500, 200, $filename);
     $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg');
 }
Exemplo n.º 11
0
<?php

require_once 'tutorial_autoload.php';
$graph = new ezcGraphPieChart();
$graph->title = 'Access statistics';
$graph->data['Access statistics'] = new ezcGraphArrayDataSet(array('Mozilla' => 19113, 'Explorer' => 10917, 'Opera' => 1464, 'Safari' => 652, 'Konqueror' => 474));
$graph->data['Access statistics']->highlight['Opera'] = true;
$graph->render(400, 150, 'tutorial_simple_pie.svg');
Exemplo n.º 12
0
<?php

require_once 'tutorial_autoload.php';
$graph = new ezcGraphPieChart();
$graph->palette = new ezcGraphPaletteEzBlue();
$graph->title = 'Access statistics';
$graph->options->font->name = 'serif';
$graph->title->background = '#EEEEEC';
$graph->title->font->name = 'sans-serif';
$graph->options->font->maxFontSize = 8;
$graph->data['Access statistics'] = new ezcGraphArrayDataSet(array('Mozilla' => 19113, 'Explorer' => 10917, 'Opera' => 1464, 'Safari' => 652, 'Konqueror' => 474));
$graph->render(400, 150, 'tutorial_chart_title.svg');
Exemplo n.º 13
0
$graph->data['File number per ' . $index] = new ezcGraphArrayDataSet($count);
$graph->data['File number per ' . $index]->highlight['Others'] = true;
$graph->renderer = new ezcGraphRenderer3d();
$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';
$graph->renderer->options->pieChartHeight = 5;
$graph->renderer->options->pieChartRotation = 0.8;
$graph->driver = new ezcGraphGdDriver();
$graph->options->font = 'app/img/arial.ttf';
$graph->driver->options->imageFormat = IMG_PNG;
$graph->render(532, 195, 'app/img/graph/countPieGraph.png');
echo '<h2>File number per ' . $index . '</h2>';
?>

<img src="app/img/graph/countPieGraph.png"/>
<table class="simple">
     <thead>
        <tr>
            <th><?php 
echo ucfirst($index);
?>
</th>
            <th>Space used</th>
            <th>Count</th>
        </tr>
    </thead>
<?php

require_once 'tutorial_autoload.php';
$graph = new ezcGraphPieChart();
$graph->palette = new ezcGraphPaletteEzRed();
$graph->title = 'Access statistics';
$graph->data['Access statistics'] = new ezcGraphArrayDataSet(array('Mozilla' => 19113, 'Explorer' => 10917, 'Opera' => 1464, 'Safari' => 652, 'Konqueror' => 474));
$graph->background->image = 'ez.png';
$graph->background->position = ezcGraph::BOTTOM | ezcGraph::RIGHT;
$graph->background->repeat = ezcGraph::NO_REPEAT;
$graph->render(400, 150, 'tutorial_chart_background.svg');
Exemplo n.º 15
0
 public function testReturnFrom3dSvgPieChartWithGleam()
 {
     $filename = $this->tempDir . __FUNCTION__ . '.svg';
     $chart = new ezcGraphPieChart();
     $chart->renderer = new ezcGraphRenderer3d();
     $chart->renderer->options->pieChartGleam = 0.5;
     $chart->data['sample'] = new ezcGraphArrayDataSet(array('Mozilla' => 4375, 'IE' => 345, 'Opera' => 1204, 'wget' => 231, 'Safari' => 987));
     $chart->render(500, 200, $filename);
     $reference = $chart->renderer->getElementReferences();
     // Check data references
     $this->assertSame(1, count($reference['data']), 'One dataset expected.');
     $this->assertSame(5, count($reference['data']['sample']), '5 datapoints expected.');
     $this->assertSame(3, count($reference['data']['sample']['Mozilla']), '2 elements for datapoint expexted');
     $this->assertSame('ezcGraphCircleSector_45', $reference['data']['sample']['Mozilla'][0], 'ezcGraphCircleSector expected.');
     $this->assertSame('ezcGraphCircleSector_46', $reference['data']['sample']['Mozilla'][1], 'ezcGraphCircleSector expected.');
     $this->assertSame('ezcGraphTextBox_77', $reference['data']['sample']['Mozilla'][2], 'ezcGraphTextBox expected.');
     // Check legend references
     $this->assertSame(5, count($reference['legend']), '5 legend items expected.');
     $this->assertSame(2, count($reference['legend']['IE']), '2 elements for legend item expected.');
     $this->assertSame('ezcGraphPolygon_5', $reference['legend']['IE']['symbol'], 'ezcGraphPolygon expected as legend symbol.');
     $this->assertSame('ezcGraphTextBox_6', $reference['legend']['IE']['text'], 'ezcGraphTextBox expected for legend text.');
     // Check for legend URLs
     $this->assertSame(5, count($reference['legend_url']), '5 legend url items expected.');
     $this->assertSame(null, $reference['legend_url']['Mozilla'], 'No link expected for "moreData".');
 }
Exemplo n.º 16
0
 public function testRenderPieChartBackgroundColorShortcut()
 {
     $filename = $this->tempDir . __FUNCTION__ . '.svg';
     $chart = new ezcGraphPieChart();
     $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');
 }
Exemplo n.º 17
0
$graph->data['Volume per group'] = new ezcGraphArrayDataSet($top_size);
$graph->data['Volume per group']->highlight['Others'] = true;
$graph->renderer = new ezcGraphRenderer3d();
$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';
$graph->renderer->options->pieChartHeight = 5;
$graph->renderer->options->pieChartRotation = 0.8;
$graph->driver = new ezcGraphGdDriver();
$graph->options->font = 'app/img/KhmerOSclassic.ttf';
$graph->driver->options->imageFormat = IMG_PNG;
$graph->render(532, 195, 'app/img/graph/groupVolumePieGraph.png');
echo '<h2>Space used per group </h2>';
?>

<img src="app/img/graph/groupVolumePieGraph.png"/>
<table class="simple">
     <thead>
        <tr>
            <th>Group</th>
            <th>Space used</th>
            <th>Count</th>
        </tr>
    </thead>
    <tbody>
        <?php 
reset($top_size);
Exemplo n.º 18
0
 public function testRenderLabeledFlashPieChart()
 {
     $filename = $this->tempDir . __FUNCTION__ . '.swf';
     $chart = new ezcGraphPieChart();
     $chart->options->font->path = dirname(__FILE__) . '/data/fdb_font.fdb';
     $chart->palette = new ezcGraphPaletteEz();
     $chart->data['sample'] = new ezcGraphArrayDataSet(array('Mozilla' => 4375, 'IE' => 345, 'Opera' => 1204, 'wget' => 231, 'Safari' => 987));
     $chart->data['sample']->highlight['Safari'] = true;
     $chart->renderer = new ezcGraphRenderer3d();
     $chart->renderer->options->pieChartShadowSize = 10;
     $chart->renderer->options->pieChartGleam = 0.5;
     $chart->renderer->options->dataBorder = false;
     $chart->renderer->options->pieChartHeight = 16;
     $chart->renderer->options->legendSymbolGleam = 0.5;
     $chart->driver = new ezcGraphFlashDriver();
     $chart->render(500, 200, $filename);
     $this->swfCompare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf');
 }
<?php

require_once 'tutorial_autoload.php';
$graph = new ezcGraphPieChart();
$graph->palette = new ezcGraphPaletteEz();
$graph->title = 'Access statistics';
$graph->data['Access statistics'] = new ezcGraphArrayDataSet(array('Mozilla' => 19113, 'Explorer' => 10917, 'Opera' => 1464, 'Safari' => 652, 'Konqueror' => 474));
$graph->data['Access statistics']->url = 'http://example.org/';
$graph->data['Access statistics']->url['Mozilla'] = 'http://example.org/mozilla';
$graph->render(400, 200, 'tutorial_reference_svg.svg');
$graph->driver->options->linkCursor = 'crosshair';
ezcGraphTools::linkSvgElements($graph);
Exemplo n.º 20
0
 public function testSvgWithDifferentLocales()
 {
     $this->setLocale(LC_NUMERIC, 'de_DE', 'de_DE.UTF-8', 'de_DE.UTF8', 'deu_deu', 'de', 'ge', 'deutsch', 'de_DE@euro');
     $filename = $this->tempDir . __FUNCTION__ . '.svg';
     $chart = new ezcGraphPieChart();
     $chart->palette = new ezcGraphPaletteEz();
     $chart->options->font = $this->basePath . 'font.svg';
     $chart->data['sample'] = new ezcGraphArrayDataSet(array('Mozilla' => 4375, 'IE' => 345, 'Opera' => 1204, 'wget' => 231, 'Safari' => 987));
     $chart->data['sample']->highlight['Safari'] = true;
     $chart->renderer = new ezcGraphRenderer3d();
     $chart->renderer->options->pieChartShadowSize = 10;
     $chart->renderer->options->pieChartGleam = 0.5;
     $chart->renderer->options->dataBorder = false;
     $chart->renderer->options->pieChartHeight = 16;
     $chart->renderer->options->legendSymbolGleam = 0.5;
     $chart->render(500, 200, $filename);
     $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg');
 }
Exemplo n.º 21
0
 /**
  * Creates and prints the pie chart in the statistic
  *
  * @param String $type
  *
  * @static
  *
  */
 static function printPieChart($type = 'tech')
 {
     global $CFG_GLPI;
     // Definition of Chart Labels
     $label = array('tech' => __('Rating by the user', 'helpdeskrating'), 'user' => __('Rating by the technician', 'helpdeskrating'));
     $uid = PluginHelpdeskratingStatistic::getUserID();
     if ($uid) {
         // Get Graph Data
         $data = PluginHelpdeskratingStatistic::getSpreadingData($type);
         if ($data[__('in progress', 'helpdeskrating')] == 0 && $data[__('closed', 'helpdeskrating')] == 0 && $data[__('rated', 'helpdeskrating')] == 0) {
             echo "<h1>{$label[$type]}</h1>";
             echo __('no data available', 'helpdeskrating');
         } else {
             // Create Graph
             $graph = new ezcGraphPieChart();
             $graph->title = $label[$type];
             // Set Graph Data
             $graph->data['data'] = new ezcGraphArrayDataSet($data);
             // Graph Legend
             $graph->legend->position = ezcGraph::BOTTOM;
             $graph->data['data']->color[__('in progress', 'helpdeskrating')] = '#55575388';
             $graph->data['data']->highlight[__('in progress', 'helpdeskrating')] = true;
             $graph->data['data']->color[__('closed', 'helpdeskrating')] = '#F5900080';
             $graph->data['data']->color[__('rated', 'helpdeskrating')] = '#4E9A0680';
             // Graph Output
             $filename = $uid . '_' . mt_rand() . '.svg';
             $graph->render(400, 300, GLPI_GRAPH_DIR . '/' . $filename);
             echo "<object data='" . $CFG_GLPI['root_doc'] . "/front/graph.send.php?file={$filename}'\n                        type='image/svg+xml' width='400' 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> ";
         }
     }
 }
Exemplo n.º 22
0
<?php

require_once 'tutorial_insert_data.php';
// Receive data from database
$db = ezcDbInstance::get();
$query = $db->createSelectQuery();
$query->select('browser', 'hits')->from('browser_hits');
$statement = $query->prepare();
$statement->execute();
// Create chart from data
$chart = new ezcGraphPieChart();
$chart->title = 'Browser statistics';
$chart->data['browsers'] = new ezcGraphDatabaseDataSet($statement);
$chart->render(400, 200, 'tutorial_simple.svg');
Exemplo n.º 23
0
<?php

require_once 'tutorial_autoload.php';
$graph = new ezcGraphPieChart();
$graph->palette = new ezcGraphPaletteEzGreen();
$graph->title = 'Access statistics';
$graph->driver = new ezcGraphGdDriver();
$graph->options->font = 'tutorial_font.ttf';
$graph->data['Access statistics'] = new ezcGraphArrayDataSet(array('Mozilla' => 19113, 'Explorer' => 10917, 'Opera' => 1464, 'Safari' => 652, 'Konqueror' => 474));
$graph->data['Access statistics']->url = 'http://example.org/';
$graph->data['Access statistics']->url['Mozilla'] = 'http://example.org/mozilla';
$graph->render(400, 200, 'tutorial_reference_gd.png');
?>
<html>
    <head><title>Image map example</title></head>
<body>
<?php 
echo ezcGraphTools::createImageMap($graph, 'GraphPieChartMap');
?>
    <img
        src="tutorial_reference_gd.png"
        width="400" height="200"
        usemap="#GraphPieChartMap" />
</body>
</html>
Exemplo n.º 24
0
<?php

require_once 'tutorial_autoload.php';
$graph = new ezcGraphPieChart();
$graph->title = 'Access statistics';
$graph->legend = false;
$graph->driver = new ezcGraphFlashDriver();
$graph->options->font = 'tutorial_font.fdb';
$graph->driver->options->compression = 7;
$graph->data['Access statistics'] = new ezcGraphArrayDataSet(array('Mozilla' => 19113, 'Explorer' => 10917, 'Opera' => 1464, 'Safari' => 652, 'Konqueror' => 474));
$graph->renderer = new ezcGraphRenderer3d();
$graph->renderer->options->pieChartShadowSize = 10;
$graph->renderer->options->pieChartGleam = 0.5;
$graph->renderer->options->dataBorder = false;
$graph->renderer->options->pieChartHeight = 16;
$graph->renderer->options->legendSymbolGleam = 0.5;
$graph->render(400, 200, 'tutorial_driver_flash.swf');
Exemplo n.º 25
0
<?php

require 'Base/src/base.php';
function __autoload($className)
{
    ezcBase::autoload($className);
}
// Require custom palette
require dirname(__FILE__) . '/ez_green.php';
// Create the graph
$graph = new ezcGraphPieChart();
$graph->palette = new ezcGraphPaletteEzGreen();
$graph->legend = false;
// Add the data and hilight norwegian data set
$graph->data['week'] = new ezcGraphArrayDataSet(array('Lukasz Serwatka' => 1805, 'Paul Forsyth' => 1491, 'Paul Borgermans' => 1316, 'Kristof Coomans' => 956, 'Alex Jones' => 942, 'Bard Farstad' => 941, 'Tony Wood' => 900));
// Set graph title
$graph->title = 'Alltime 10 most active users on forum';
// Use 3d renderer, and beautify it
$graph->renderer = new ezcGraphRenderer3d();
$graph->renderer->options->pieChartShadowSize = 12;
$graph->renderer->options->pieChartGleam = 0.5;
$graph->renderer->options->dataBorder = false;
$graph->renderer->options->pieChartHeight = 16;
$graph->renderer->options->legendSymbolGleam = 0.5;
$graph->renderer->options->pieChartOffset = 100;
$graph->driver = new ezcGraphSvgDriver();
// Output the graph with std SVG driver
$graph->render(500, 200, 'forum_year.svg');
Exemplo n.º 26
0
 /**
  * Generates a crash report OS version distribution graph for currently 
  * selected project and dumps it to stdout.
  * @param type $w Desired image width.
  * @param type $h Desired image height.
  * @throws CHttpException
  * @return void
  */
 public static function generateOSVersionDistributionGraph($w, $h, $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');
     }
     // Get current project info
     $curProjectId = Yii::app()->user->getCurProjectId();
     if ($curProjectId == false) {
         throw new CHttpException(403, 'Invalid parameter');
     }
     // Prepare data
     $criteria = new CDbCriteria();
     $criteria->select = 'os_name_reg, COUNT(*) as cnt';
     $criteria->order = 'cnt DESC';
     $criteria->group = 'os_name_reg';
     $criteria->compare('t.project_id', $curProjectId);
     $curVer = '(not set)';
     $versions = Yii::app()->user->getCurProjectVersions($curVer);
     if ($curVer != -1) {
         $criteria->compare('appversion_id', $curVer == 0 ? null : $curVer);
     }
     $data = array();
     $models = CrashReport::model()->findAll($criteria);
     $totalCount = 0;
     foreach ($models as $model) {
         $totalCount += $model->cnt;
     }
     $itemCount = 0;
     $others = 0;
     foreach ($models as $model) {
         $itemCount++;
         if ($itemCount > 10) {
             $others += $model->cnt;
             continue;
         }
         $osName = strlen($model->os_name_reg) != 0 ? $model->os_name_reg : "(not set)";
         $percent = 100 * $model->cnt / $totalCount;
         $label = sprintf('(%0.1f%%) %s', $percent, $osName);
         $label = MiscHelpers::addEllipsis($label, 60);
         if (array_key_exists($label, $data)) {
             $data[$label] += $model->cnt;
         } else {
             $data[$label] = $model->cnt;
         }
     }
     if ($others > 0) {
         // Add 'Others'
         $percent = 100 * $others / $totalCount;
         $label = sprintf('(%0.1f%%) Others', $percent);
         $data[$label] = $others;
     }
     // Check the case when $data is empty.
     if (count($data) == 0) {
         // Open out file
         if ($file != null) {
             $fout = @fopen($file, 'w');
             if ($fout == false) {
                 @unlink($tmpfile);
                 throw new CHttpException(403, 'Invalid file.');
             }
         }
         // No data available
         $fileName = Yii::app()->basePath . '/../images/no_data_available.png';
         if ($fd = @fopen($fileName, "r")) {
             $fsize = filesize($fileName);
             // Write HTTP headers
             header("Content-type: image/png");
             //header("Content-Disposition: filename=\"".$fileName."\"");
             header("Content-length: {$fsize}");
             header("Cache-control: private");
             //use this to open files directly
             // Write file content
             while (!feof($fd)) {
                 $buffer = fread($fd, 2048);
                 if ($file == null) {
                     echo $buffer;
                 } else {
                     fwrite($fout, $buffer);
                 }
             }
             if ($file != null) {
                 fclose($fout);
             }
             fclose($fd);
         }
         return;
     }
     $graph = new ezcGraphPieChart();
     $graph->palette = new ezcGraphPaletteEzGreen();
     $graph->data['Versions'] = new ezcGraphArrayDataSet($data);
     $graph->legend = true;
     $graph->legend->position = ezcGraph::RIGHT;
     $graph->legend->landscapeSize = 0.5;
     $graph->legend->portraitSize = 0.5;
     $graph->options->sum = $totalCount;
     //$graph->options->summarizeCaption = 'Others';
     $graph->options->label = '%3$.1f%%';
     $graph->options->font->name = 'Tahoma';
     $graph->options->font->maxFontSize = 14;
     $graph->options->font->minFontSize = 1;
     $graph->renderer = new ezcGraphRenderer3d();
     $graph->renderer->options->pieChartRotation = 0.8;
     $graph->renderer->options->pieChartShadowSize = 10;
     //$graph->renderer->options->pieChartGleam = .3;
     //$graph->renderer->options->pieChartGleamColor = '#FFFFFF';
     //$graph->renderer->options->pieChartGleamBorder = 2;
     if ($file === null) {
         $graph->renderToOutput($w, $h);
     } else {
         $graph->render($w, $h, $file);
     }
 }
Exemplo n.º 27
0
<?php

require_once 'tutorial_autoload.php';
$graph = new ezcGraphPieChart();
$graph->title = 'Elections 2005 Germany';
$graph->data['2005'] = new ezcGraphArrayDataSet(array('CDU' => 35.2, 'SPD' => 34.2, 'FDP' => 9.800000000000001, 'Die Gruenen' => 8.1, 'PDS' => 8.699999999999999, 'NDP' => 1.6, 'REP' => 0.6));
$graph->options->label = '%3$.1f%%';
$graph->options->sum = 100;
$graph->options->percentThreshold = 0.02;
$graph->options->summarizeCaption = 'Others';
$graph->render(400, 150, 'tutorial_pie_options.svg');
Exemplo n.º 28
0
 /**
  *  Obtiene los necesarios para ver la asistencias de alumnos
  *
  **/
 protected function obtenerDatos()
 {
     Misc::use_helper('Misc');
     //Iniciando Variables
     $alumno_id = -1;
     $cuenta_id = -1;
     $vista_id = 1;
     // default para vista DIARIO
     $division_id = 0;
     $carrera_id = 0;
     $datos = array();
     $idxAlumno = array();
     $aFeriado = array();
     $aIntervalo = array();
     $optionsDivision = array();
     $optionsCarrera = array();
     $aTemp = array();
     $aFechaTemp = array();
     $aTipoasistencias = array();
     $aPorcentajeAsistencia = array();
     $flag_error = 0;
     $nombre_completo_archivo = "";
     $bool_gd = array_search("gd", get_loaded_extensions());
     // Tomando los datos del formulario y completando variable
     $ciclolectivo_id = $this->getUser()->getAttribute('fk_ciclolectivo_id');
     $ciclolectivo = CiclolectivoPeer::retrieveByPK($ciclolectivo_id);
     $ciclolectivo_fecha_inicio = strtotime($ciclolectivo->getFechaInicio());
     $ciclolectivo_fecha_fin = strtotime($ciclolectivo->getFechaFin());
     // Asigno la fecha de inicio del ciclo lectivo por defecto
     $aFechaActual = getdate($ciclolectivo_fecha_inicio);
     // Tomo el año de la fecha de inicio y de fin del ciclo lectivo
     $anio_desde = date("Y", $ciclolectivo_fecha_inicio);
     $anio_hasta = date("Y", $ciclolectivo_fecha_fin);
     if ($this->getRequestParameter('dia')) {
         $d = $this->getRequestParameter('dia');
     } else {
         $d = $aFechaActual['mday'];
     }
     if ($this->getRequestParameter('mes')) {
         $m = $this->getRequestParameter('mes');
     } else {
         $m = $aFechaActual['mon'];
     }
     if ($this->getRequestParameter('ano')) {
         $y = $this->getRequestParameter('ano');
     } else {
         $y = $aFechaActual['year'];
     }
     if ($this->getRequestParameter('alumno_id')) {
         $alumno_id = $this->getRequestParameter('alumno_id');
         $a = AlumnoPeer::retrieveByPK($alumno_id);
         $cuenta_id = $a->getFkCuentaId();
     }
     if ($this->getRequestParameter('carrera_id')) {
         $carrera_id = $this->getRequestParameter('carrera_id');
     }
     if ($this->getRequestParameter('vistas')) {
         $vista_id = $this->getRequestParameter('vistas');
     }
     $establecimiento_id = $this->getUser()->getAttribute('fk_establecimiento_id');
     $criteria = new Criteria();
     $criteria->add(AnioPeer::FK_ESTABLECIMIENTO_ID, $establecimiento_id);
     if ($this->getRequestParameter('alumno_id')) {
         $criteria->add(RelAlumnoDivisionPeer::FK_ALUMNO_ID, $alumno_id);
         $criteria->addJoin(RelAlumnoDivisionPeer::FK_DIVISION_ID, DivisionPeer::ID);
     }
     if ($this->getRequestParameter('carrera_id')) {
         $criteria->add(AnioPeer::FK_CARRERA_ID, $carrera_id);
     }
     $criteria->addAscendingOrderByColumn(AnioPeer::DESCRIPCION);
     $criteria->addAscendingOrderByColumn(DivisionPeer::ORDEN);
     $criteria->addAscendingOrderByColumn(DivisionPeer::DESCRIPCION);
     $divisiones = DivisionPeer::doSelectJoinAnio($criteria);
     // divisiones a mostrar
     foreach ($divisiones as $division) {
         $optionsDivision[$division->getId()] = $division->__toString();
     }
     if ($this->getRequestParameter('division_id')) {
         $division_id = $this->getRequestParameter('division_id');
     } else {
         if (count($optionsDivision) > 0) {
             $aTemp = array_keys($optionsDivision);
             $division_id = $aTemp[0];
         } else {
             // Ver si se puede hacer desde el validate
             $this->getRequest()->setError('Division', 'No hay Ninguna División cargada');
             $flag_error = 1;
         }
     }
     $cCarrera = new Criteria();
     $cCarrera->add(CarreraPeer::FK_ESTABLECIMIENTO_ID, $establecimiento_id);
     $carreras = CarreraPeer::doSelect($cCarrera);
     foreach ($carreras as $carrera) {
         $optionsCarrera[$carrera->getId()] = $carrera->getDescripcion();
     }
     if (!checkdate($m, $d, $y)) {
         // Ver si se puede hacer desde el validate
         $this->getRequest()->setError('Fecha', 'La fecha ingresada es erronea');
         $flag_error = 1;
     }
     if ($flag_error == 0) {
         // devuelve un intervalo de dias según vista y fecha seleccionada
         $aIntervalo = diasxintervalo($d, $m, $y, $vista_id);
         // chequeo si el intervalo de fechas generados esta o no dentro de las fechas validas del ciclo lectivo
         foreach ($aIntervalo as $fecha) {
             $fecha_intervalo = strtotime($fecha);
             if ($fecha_intervalo >= $ciclolectivo_fecha_inicio and $fecha_intervalo <= $ciclolectivo_fecha_fin) {
                 $aFechaTemp[] = $fecha;
             }
         }
         $aIntervalo = $aFechaTemp;
     }
     // obteniendo los feriados actuales
     $criteria = new Criteria();
     $feriados = FeriadoPeer::doSelect($criteria);
     foreach ($feriados as $feriado) {
         $aFeriado[$feriado->getFecha()] = $feriado->getNombre();
     }
     // esto deberia estar hecho muy diferente guardar en un /tmp con archivo aleatorio
     if (file_exists(sfConfig::get('sf_upload_dir_name') . '/grafico_asistencias.png')) {
         unlink(sfConfig::get('sf_upload_dir_name') . '/grafico_asistencias.png');
     }
     if (count($aIntervalo) > 0) {
         //Obtener los alumnos de la division y asistencias en el rango de fecha
         //$con = sfContext::getInstance()->getDatabaseConnection($connection='propel');
         $con = Propel::getConnection();
         $s = "SELECT alumno.id, alumno.nombre, alumno.apellido, alumno.apellido_materno,";
         $s .= "tipoasistencia.descripcion, tipoasistencia.nombre AS asistencia, asistencia.fecha,";
         $s .= "asistencia.fk_tipoasistencia_id ";
         $s .= "FROM alumno, rel_alumno_division ";
         $s .= "LEFT JOIN asistencia ON ( rel_alumno_division.FK_ALUMNO_ID = asistencia.FK_ALUMNO_ID ";
         $s .= "AND asistencia.FECHA ";
         $s .= "IN (";
         for ($i = 0, $max = count($aIntervalo); $i < $max; $i++) {
             $s .= "'" . $aIntervalo[$i] . " 00:00:00'";
             if ($i < count($aIntervalo) - 1) {
                 $s .= ",";
             }
         }
         $s .= ") ) ";
         $s .= "LEFT JOIN tipoasistencia ON ( asistencia.FK_TIPOASISTENCIA_ID = tipoasistencia.ID ) ";
         $s .= "WHERE ";
         if ($alumno_id >= 0) {
             $s .= "alumno.ID =" . $alumno_id;
         } else {
             $s .= "rel_alumno_division.FK_DIVISION_ID =" . $division_id;
         }
         $s .= " AND rel_alumno_division.FK_ALUMNO_ID = alumno.ID";
         $s .= " ORDER BY alumno.apellido,alumno.apellido_materno,alumno.nombre,asistencia.FECHA";
         $stmt = $con->prepare($s);
         $alumnos = $stmt->execute();
         $totales = array();
         $tot = 0;
         while ($alumno = $stmt->fetch(PDO::FETCH_ASSOC)) {
             $idxAlumno[$alumno['id']] = $alumno['apellido'] . " " . $alumno['apellido_materno'] . " " . $alumno['nombre'];
             if ($alumno['fecha']) {
                 $datos[$alumno['id']][$alumno['fecha']] = $alumno['asistencia'];
                 @$totales[$alumno['asistencia']]++;
             }
         }
         $aTipoasistencias = $this->getTiposasistencias();
         $aPorcentajeAsistencia = array();
         $flag = 0;
         // cantidad de fechas sin fines de semana
         $cantFechas = 0;
         foreach ($aIntervalo as $fecha) {
             if (!(date("w", strtotime($fecha)) == 6) and !(date("w", strtotime($fecha)) == 0)) {
                 $cantFechas++;
             }
         }
         $dias = $cantFechas * count($idxAlumno);
         foreach ($aTipoasistencias as $idx => $Tipoasistencia) {
             $aPorcentajeAsistencia[$idx] = isset($totales[$idx]) ? number_format($totales[$idx] * 100 / $dias, 2) : number_format(0, 2);
             $tot += isset($totales[$idx]) ? number_format($totales[$idx], 2) : number_format(0, 2);
             if ($aPorcentajeAsistencia[$idx] != 0) {
                 $flag = 1;
             }
         }
         if ($flag == 1) {
             $aTitulo = array_keys($aTipoasistencias);
             $aTitulo[] = "No Cargado";
             if ($bool_gd) {
                 // Si no tiene cargado la GD no muestra el grafico
                 // Genera nombre de archivo único
                 $nombre_archivo = uniqid();
                 $nombre_completo_archivo = $nombre_archivo . '.jpg';
                 // nueva clase para grafico de tortas
                 $graph = new ezcGraphPieChart();
                 // uso driver GD pero podria ser SVG o Ming
                 $graph->driver = new ezcGraphGdDriver();
                 $graph->driver->options->supersampling = 1;
                 $graph->driver->options->jpegQuality = 100;
                 $graph->driver->options->imageFormat = IMG_JPEG;
                 // Color de fondo del grafico
                 $graph->background->color = '#FFFFFF';
                 // De donde sacar la letra
                 $graph->options->font = realpath(sfConfig::get('sf_lib_dir') . "/font/FreeSerifBold.ttf");
                 $graph->options->font->maxFontSize = 9;
                 //     $graph->title = "Asistencia";
                 // Cargo datos de la asistencia
                 $graph->data['Asistencia'] = new ezcGraphArrayDataSet($aPorcentajeAsistencia);
                 // tamaño del symbolo de la lista
                 $graph->legend->symbolSize = 10;
                 // se selecciona las opciones graficas
                 $graph->renderer = new ezcGraphRenderer3d();
                 $graph->renderer->options->moveOut = 0.01;
                 $graph->renderer->options->pieChartShadowSize = 10;
                 // $graph->renderer->options->pieChartGleam = .5;
                 $graph->renderer->options->dataBorder = false;
                 $graph->renderer->options->pieChartHeight = 16;
                 $graph->renderer->options->legendSymbolGleam = 0.5;
                 //graba archivo de imagen
                 $graph->render(400, 250, sfConfig::get('app_alba_tmpdir') . DIRECTORY_SEPARATOR . $nombre_completo_archivo);
             }
         }
     }
     //Asignacion de variables para el template
     $this->bool_tmp = is_writable(sfConfig::get('app_alba_tmpdir'));
     $this->bool_gd = $bool_gd;
     $this->nombre_completo_archivo = $nombre_completo_archivo;
     $this->d = $d;
     $this->m = $m;
     $this->y = $y;
     $this->aTipoasistencias = $aTipoasistencias;
     $this->aAlumnos = $idxAlumno;
     $this->aDatos = $datos;
     $this->optionsDivision = $optionsDivision;
     $this->optionsCarrera = $optionsCarrera;
     $this->aVistas = repeticiones();
     $this->aMeses = Meses();
     $this->aIntervalo = $aIntervalo;
     $this->aPorcentajeAsistencia = $aPorcentajeAsistencia;
     $this->aFeriado = $aFeriado;
     $this->alumno_id = $alumno_id;
     $this->cuenta_id = $cuenta_id;
     $this->vista_id = $vista_id;
     $this->division_id = $division_id;
     $this->carrera_id = $carrera_id;
     $this->anio_desde = $anio_desde;
     $this->anio_hasta = $anio_hasta;
 }
Exemplo n.º 29
0
 public function testRenderPieChartWithGleamAndShadow()
 {
     $filename = $this->tempDir . __FUNCTION__ . '.svg';
     $chart = new ezcGraphPieChart();
     $chart->data['sample'] = new ezcGraphArrayDataSet(array('Mozilla' => 4375, 'IE' => 345, 'Opera' => 1204, 'wget' => 231, 'Safari' => 987));
     $chart->data['sample']->highlight['Opera'] = true;
     $chart->renderer->options->legendSymbolGleam = 0.5;
     $chart->renderer->options->pieChartShadowSize = 5;
     $chart->renderer->options->pieChartGleamBorder = 3;
     $chart->renderer->options->pieChartGleam = 0.5;
     $chart->driver = new ezcGraphSvgDriver();
     $chart->render(500, 200, $filename);
     $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg');
 }
Exemplo n.º 30
0
<?php

require 'Base/src/base.php';
function __autoload($className)
{
    ezcBase::autoload($className);
}
// Create the graph
$graph = new ezcGraphPieChart();
// Add the data and hilight norwegian data set
$graph->data['articles'] = new ezcGraphArrayDataSet(array('English' => 1300000, 'Germany' => 452000, 'Netherlands' => 217000, 'Norway' => 70000));
$graph->data['articles']->highlight['Norway'] = true;
// Set graph title
$graph->title = 'Articles by country';
// Modify pie chart label to only show amount and percent
$graph->options->label = '%2$d (%3$.1f%%)';
// Use 3d renderer, and beautify it
$graph->renderer = new ezcGraphRenderer3d();
$graph->renderer->options->pieChartShadowSize = 12;
$graph->renderer->options->pieChartGleam = 0.5;
$graph->renderer->options->dataBorder = false;
$graph->renderer->options->pieChartHeight = 16;
$graph->renderer->options->legendSymbolGleam = 0.5;
$graph->renderer->options->pieChartOffset = 100;
// Output the graph with std SVG driver
$graph->render(500, 200, 'wiki_graph.svg');