Exemple #1
0
 function render($y)
 {
     # $y is height of box plot
     $h = imagefontheight(FONT_1) + 2;
     # Gap at bottom and top
     $w = imagefontwidth(FONT_1);
     $yy = $y + 2 * $h;
     # $yy is height of image
     if (!parent::Init($this->width + 10, $yy)) {
         return false;
     }
     $this->DrawBackground();
     $this->DrawLine(2, $h, 2, $yy - $h - 1, 'black');
     $this->DrawLine(2, floor($y / 2) + $h, 2 + $this->width, floor($y / 2) + $h, 'black');
     $this->DrawLine(2 + $this->width, $h, 2 + $this->width, $yy - $h - 1, 'black');
     $this->DrawTextRelative('0', 0, 0, 'black', TEXT_RIGHT, 0);
     $this->DrawTextRelative('100', $this->width + 10, 0, 'black', TEXT_LEFT, 0);
     $this->DrawRectangle(2 + $this->low * $this->width, $h, 2 + $this->high * $this->width, $yy - $h - 1, 'grey');
     $this->DrawLine(2 + $this->mean * $this->width, $h, 2 + $this->mean * $this->width, $yy - $h - 1, 'red');
     $mean = round($this->mean * 100, 1) . '%';
     $this->DrawTextRelative($mean, 2 + $this->mean * $this->width, $yy - 1, 'red', TEXT_TOP, 0);
 }
 function Render($y)
 {
     $this->Debug("Sparkline_Bar :: Render({$y})", DEBUG_CALLS);
     // calculate size based on sets for init
     //
     if (!parent::Init($this->CalculateImageWidth(), $y)) {
         return false;
     }
     // convert based on actual canvas size
     //
     $this->ConvertDataSeries(1, $this->GetGraphWidth(), $this->GetGraphHeight());
     // stats debugging
     //
     $this->Debug('Sparkline_Bar :: Draw' . ' series: 1 min: ' . $this->dataSeriesStats[1]['min'] . ' max: ' . $this->dataSeriesStats[1]['max'] . ' height: ' . $this->GetGraphHeight() . ' yfactor: ' . $this->GetGraphHeight() / (abs($this->dataSeriesStats[1]['max']) + abs($this->dataSeriesStats[1]['min'])));
     $this->DrawBackground();
     $yAxis = abs(min($this->dataSeriesStats[1]['min_converted'], 0));
     for ($i = 0; $i < sizeof($this->dataSeriesConverted[1]); $i++) {
         $this->DrawRectangleFilled($i * ($this->barWidth + $this->barSpacing), $yAxis, $i * ($this->barWidth + $this->barSpacing) + $this->barWidth - 1, $yAxis + $this->dataSeriesConverted[1][$i]['value'], $this->dataSeriesConverted[1][$i]['color']);
         if ($this->dataSeriesConverted[1][$i]['underscore']) {
             $this->DrawLine(max(0, $i * ($this->barWidth + $this->barSpacing) - $this->barSpacing / 2), $yAxis, min($this->GetGraphWidth(), $i * ($this->barWidth + $this->barSpacing) + $this->barSpacing / 2), $yAxis, $this->barColorUnderscoreDefault);
         }
     }
 }
<?php

/*
 * Sparkline PHP Graphing Library
 * Copyright 2004 James Byers <*****@*****.**>
 * http://sparkline.org
 *
 * Sparkline is distributed under a BSD License.  See LICENSE for details.
 *
 * $Id: primitives.php,v 1.1 2005/03/31 22:58:55 frabcus Exp $
 *
 * primitives doesn't draw a sparkline, only exercises the drawing primitives
 *
 */
require_once '../lib/Sparkline.php';
$sparkline = new Sparkline();
$sparkline->SetDebugLevel(DEBUG_NONE);
//$sparkline->SetDebugLevel(DEBUG_ERROR | DEBUG_WARNING | DEBUG_STATS | DEBUG_CALLS, '../log.txt');
// with any Sparkline subclass, Render would be called instead of Init
//
$sparkline->Init(100, 20);
$sparkline->DrawFill(9, 9, 'white');
$sparkline->DrawRectangleFilled(1, 9, 98, 18, 'grey');
$sparkline->DrawLine(0, 0, 19, 19, 'red');
$sparkline->DrawCircleFilled(49, 9, 10, 'black');
$sparkline->DrawPoint(96, 17, 'black');
$sparkline->DrawRectangle(0, 0, 99, 19, 'blue');
$sparkline->DrawText('test1', 0, 0, 'red', 1);
$sparkline->DrawText('test2', 25, 0, 'olive', 2);
$sparkline->DrawText('test3', 50, 0, 'blue', 3);
$sparkline->Output();
 function RenderResampled($x, $y)
 {
     $this->Debug("Sparkline_Line :: RenderResampled({$x}, {$y})", DEBUG_CALLS);
     if (!parent::Init($x, $y)) {
         return FALSE;
     }
     // draw background on standard image in case of resample blit miss
     //
     $this->DrawBackground($this->imageHandle);
     // convert based on virtual canvas: x based on size of dataset, y scaled proportionately
     // if size of data set is small, default to 4X target canvas size
     //
     $xVC = max(sizeof($this->dataSeries[1]), 4 * $x);
     $yVC = floor($xVC * ($this->GetGraphHeight() / $this->GetGraphWidth()));
     $this->ConvertDataSeries(1, $xVC, $yVC);
     // stats debugging
     //
     $this->Debug('Sparkline_Line :: DrawResampled' . ' series: 1 min: ' . $this->dataSeriesStats[1]['yMin'] . ' max: ' . $this->dataSeriesStats[1]['yMax'] . ' offset: ' . $this->dataSeriesStats[1]['yMin'] * -1 . ' height: ' . $this->GetGraphHeight() . ' yfactor: ' . $this->GetGraphHeight() / ($this->dataSeriesStats[1]['yMax'] + $this->dataSeriesStats[1]['yMin'] * -1), DEBUG_STATS);
     $this->Debug('Sparkline_Line :: DrawResampled' . ' drawing area:' . ' (' . $this->graphAreaPx[0][0] . ',' . $this->graphAreaPx[0][1] . '), ' . ' (' . $this->graphAreaPx[1][0] . ',' . $this->graphAreaPx[1][1] . ')');
     // create virtual image
     // allocate colors
     // draw background, graph
     // resample and blit onto original graph
     //
     $imageVCHandle = $this->CreateImageHandle($xVC, $yVC);
     while (list($k, $v) = each($this->colorList)) {
         $this->SetColorHandle($k, $this->DrawColorAllocate($k, $imageVCHandle));
     }
     reset($this->colorList);
     $this->DrawBackground($imageVCHandle);
     for ($i = 0; $i < sizeof($this->dataSeriesConverted[1]) - 1; $i++) {
         $this->DrawLine($this->dataSeriesConverted[1][$i][0], $this->dataSeriesConverted[1][$i][1], $this->dataSeriesConverted[1][$i + 1][0], $this->dataSeriesConverted[1][$i + 1][1], 'black', $this->GetLineSize(), $imageVCHandle);
     }
     $this->DrawImageCopyResampled($this->imageHandle, $imageVCHandle, $this->graphAreaPx[0][0], $this->GetImageHeight() - $this->graphAreaPx[1][1], 0, 0, $this->GetGraphWidth(), $this->GetGraphHeight(), $xVC, $yVC);
     // src  height
     // draw features
     //
     while (list(, $v) = each($this->featurePoint)) {
         $pxY = round(($v['ptY'] + $this->yMin * -1) * ($this->GetGraphHeight() / $this->yMax));
         $pxX = round($v['ptX'] * $this->GetGraphWidth() / $this->dataSeriesStats[1]['xMax']);
         $this->DrawCircleFilled($pxX + $this->graphAreaPx[0][0], $pxY + $this->graphAreaPx[0][1], $v['diameter'], $v['color'], $this->imageHandle);
         $this->DrawTextRelative($v['text'], $pxX + $this->graphAreaPx[0][0], $pxY + $this->graphAreaPx[0][1], $v['color'], $v['textpos'], round($v['diameter'] / 2), $v['font'], $this->imageHandle);
     }
 }
 function RenderResampled($x, $y)
 {
     $this->Debug("Sparkline_Line :: RenderResampled({$x}, {$y})", DEBUG_CALLS);
     if (!parent::Init($x, $y)) {
         return false;
     }
     // draw background on standard image in case of resample blit miss
     //
     $this->DrawBackground($this->imageHandle);
     // convert based on virtual canvas: x based on size of dataset, y scaled proportionately
     //
     $xVC = sizeof($this->dataSeries[1]);
     $yVC = floor($xVC * ($this->GetGraphHeight() / $this->GetGraphWidth()));
     $this->ConvertDataSeries(1, $xVC, $yVC);
     // stats debugging
     //
     $this->Debug('Sparkline_Line :: DrawResampled' . ' series: 1 min: ' . $this->dataSeriesStats[1]['min'] . ' max: ' . $this->dataSeriesStats[1]['max'] . ' offset: ' . $this->dataSeriesStats[1]['min'] * -1 . ' height: ' . $this->GetGraphHeight() . ' yfactor: ' . $this->GetGraphHeight() / ($this->dataSeriesStats[1]['max'] + $this->dataSeriesStats[1]['min'] * -1), DEBUG_STATS);
     // create virtual image
     // allocate colors
     // draw background, graph
     // resample and blit onto original graph
     //
     $imageVCHandle = $this->CreateImageHandle($xVC, $yVC);
     while (list($k, $v) = each($this->colorList)) {
         $this->SetColorHandle($k, $this->DrawColorAllocate($k, $imageVCHandle));
     }
     reset($this->colorList);
     $this->DrawBackground($imageVCHandle);
     for ($i = 0; $i < sizeof($this->dataSeriesConverted[1]) - 1; $i++) {
         $this->DrawLine($i, $this->dataSeriesConverted[1][$i], $i + 1, $this->dataSeriesConverted[1][$i + 1], 'black', $this->GetLineSize(), $imageVCHandle);
     }
     $this->DrawImageCopyResampled($this->imageHandle, $imageVCHandle, 0, 0, 0, 0, $this->GetGraphWidth(), $this->GetGraphHeight(), $xVC, $yVC);
     // src  height
 }