Exemplo n.º 1
0
function draw_odometer_chart($WIDTH, $HEIGHT, $DATA, $CONFIG, $LEGEND, $FONT, $PALETTE = 'default')
{
    $palettename = return_palette_name($PALETTE);
    require dirname(__FILE__) . '/lib/ezc/Graph/mahara/palettes/' . $palettename . '.php';
    $graph = new ezcGraphOdometerChart();
    $paletteclass = generate_palette_class_name($palettename);
    $graph->palette = new $paletteclass();
    $graph->title = $CONFIG['title'];
    $graph->subtitle = 'Created: ' . $CONFIG['ctime'] . ', modified: ' . $CONFIG['mtime'];
    $graph->subtitle->position = ezcGraph::BOTTOM;
    $graph->legend = false;
    $graph->background->padding = 10;
    $graph->driver = new ezcGraphGdDriver();
    $graph->driver->options->imageFormat = IMG_PNG;
    switch ($FONT['type']) {
        case 'serif':
            $fontname = 'lib/ezc/Graph/mahara/fonts/LiberationSerif-Regular.ttf';
            break;
        case 'sans':
            $fontname = 'lib/ezc/Graph/mahara/fonts/LiberationSans-Regular.ttf';
            break;
    }
    $graph->options->font = $fontname;
    // Set the maximum font size for all chart elements
    $graph->options->font->maxFontSize = $FONT['size'];
    // Set the font size for the title independently to 14
    $graph->title->font->maxFontSize = $FONT['titlesize'];
    // Set colors for the background gradient
    //$graph->options->startColor = '#808080';
    //$graph->options->endColor = '#C0C0C0';
    /*
    $graph->options->startColor = '#2E3436';
    $graph->options->endColor = '#EEEEEC';
    */
    // Set marker width
    $graph->options->markerWidth = 3;
    // Set axis span
    $graph->axis->min = 0;
    $graph->axis->max = 100;
    $graph->axis->label = $DATA['label'];
    /*
    $graph->yAxis->majorStep = 20;
    $graph->yAxis->minorStep = 10;
    if ($CONFIG['type'] == 'percent') {
    	$graph->yAxis->formatString = '%d%%';
    }
    */
    if ($CONFIG['type'] == 'percent') {
        $EZCDATA = array($DATA['percent']);
    } else {
        $EZCDATA = array($DATA['value']);
    }
    $graph->data[$CONFIG['title']] = new ezcGraphArrayDataSet($EZCDATA);
    /* Build the PNG file and send it to the web browser */
    $graph->renderToOutput($WIDTH, $HEIGHT);
}
Exemplo n.º 2
0
 public function testRenderCompleteOdometerToOutput()
 {
     $filename = $this->tempDir . __FUNCTION__ . '.svg';
     $chart = new ezcGraphOdometerChart();
     $chart->data['data'] = new ezcGraphArrayDataSet(array(1, 7, 18));
     ob_start();
     // Suppress header already sent warning
     @$chart->renderToOutput(500, 200);
     file_put_contents($filename, ob_get_clean());
     $this->compare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg');
 }