Exemplo n.º 1
0
<?php

session_start();
require_once 'phplot.php';
echo $_GET[countKeywords];
$data = array(array('新增文件', intval($_GET[countnew])), array('删除文件', intval($_GET[countdel])), array('修改文件', intval($_GET[countmodify])));
$plot = new PHPlot(350, 280);
$plot->SetTTFPath('./public');
$plot->SetDefaultTTFont('SIMHEI.TTF');
$plot->SetUseTTF(True);
$plot->SetImageBorderType('plain');
$plot->SetPlotType('bars');
$plot->SetDataType('text-data');
$plot->SetPlotBorderType('full');
$plot->SetBackgroundColor('#ffffcc');
$plot->SetDrawPlotAreaBackground(True);
$plot->SetPlotBgColor('#ffffff');
$plot->SetDataValues($data);
$plot->SetTitle("新增文件数:{$_GET['countnew']} 删除文件数:{$_GET['countdel']} 修改文件数:{$_GET['countmodify']}");
$plot->SetTitleColor('#D9773A');
foreach ($data as $row) {
    $plot->Setshading(10);
}
$plot->SetDataBorderColors('black');
$plot->DrawGraph();
Exemplo n.º 2
0
for ($len = 5; $len <= $tp['MaxLen']; $len += 5) {
    $data[] = array(str_repeat('Label', $len / 5), $len);
}
$p = new PHPlot(800, 600);
$p->SetTitle($tp['title'] . $tp['suffix']);
$p->SetDataType('text-data');
$p->SetDataValues($data);
# Fix Y ticks
$p->SetPlotAreaWorld(NULL, 0, NULL, NULL);
$p->SetYTickIncrement(5);
# Font:
if ($tp['TTF']) {
    # Using TrueType fonts: Set path and default font.
    $p->SetTTFPath($phplot_test_ttfdir);
    $font = $phplot_test_ttfonts[$tp['FontName']];
    $p->SetDefaultTTFont($font);
    # Now select label font with size (if supplied):
    if (empty($tp['FontSize'])) {
        $p->SetFont('x_label', $font);
    } else {
        $p->SetFont('x_label', $font, $tp['FontSize']);
    }
} else {
    # Using GD fonts:
    if (isset($tp['FontSize'])) {
        $p->SetFont('x_label', $tp['FontSize']);
    }
}
# Label angle:
if (isset($tp['angle'])) {
    $p->SetXLabelAngle($tp['angle']);
Exemplo n.º 3
0
require_once 'config.php';
# This is a parameterized test. Other scripts can set $tp and then include
# this script. The parameters are shown in the defaults array below:
if (!isset($tp)) {
    $tp = array();
}
$tp = array_merge(array('title' => 'Legend Test', 'suffix' => ' (baseline)', 'use_ttf' => False, 'textalign' => NULL, 'colorboxalign' => NULL, 'legendfont' => NULL, 'line_spacing' => NULL, 'text' => NULL, 'px' => NULL, 'py' => NULL, 'wx' => NULL, 'wy' => NULL, 'ttfont' => $phplot_test_ttfonts['sans'], 'ttfdir' => $phplot_test_ttfdir, 'ttfsize' => 14, 'cbwa' => NULL), $tp);
require_once 'phplot.php';
$data = array(array('', 0, 0, 0, 0), array('', 1, 1, 2, 3), array('', 2, 2, 4, 6), array('', 3, 3, 6, 9));
if (!isset($tp['text'])) {
    $tp['text'] = array('Plot Line 1', 'Longer label for Plot Line 2', 'line 3');
}
$p = new PHPlot(800, 600);
if ($tp['use_ttf']) {
    $p->SetTTFPath($tp['ttfdir']);
    $p->SetDefaultTTFont($tp['ttfont']);
}
# Set line spacing:
if (isset($tp['line_spacing'])) {
    $p->SetLineSpacing($tp['line_spacing']);
}
$p->SetTitle($tp['title'] . $tp['suffix']);
# Need to set the font for TTF even if legendfont isn't given, to get the size.
if ($tp['use_ttf']) {
    if (isset($tp['legendfont'])) {
        $p->SetFont('legend', $tp['legendfont'], $tp['ttfsize']);
    } else {
        $p->SetFont('legend', $tp['ttfont'], $tp['ttfsize']);
    }
} elseif (isset($tp['legendfont'])) {
    $p->SetFont('legend', $tp['legendfont']);
Exemplo n.º 4
0
<?php

# $Id$
# Testing phplot - Default TT font (5): Default path and default font
require_once 'phplot.php';
require_once 'config.php';
// TTF setup
$data = array(array('A', 3, 6), array('B', 2, 4), array('C', 1, 2));
$p = new PHPlot(800, 800);
$p->SetDataType('text-data');
$p->SetDataValues($data);
$p->SetPlotType('bars');
$p->SetTitle("SetTTFPath and SetDefaultTTFont");
$p->SetTTFPath($phplot_test_ttfdir);
$p->SetDefaultTTFont($phplot_test_ttfonts['sansitalic']);
$p->SetXTitle('X Axis Title');
$p->SetYTitle('Y Axis Title');
$p->DrawGraph();
fwrite(STDERR, "OK defaultfont5: title font=" . $p->fonts['title']['font'] . "\n");
Exemplo n.º 5
0
if (isset($format)) {
    if ($format == 1) {
        $mode = '';
    } elseif ($format == 2) {
        $mode = 'Data';
    }
    // E.g. SetXDataLabelType()
    $subtitle[] = "Format (Set{$mode}LabelType) '{$formattype}, {$formatarg}'";
}
if (empty($subtitle)) {
    $title .= "\nDefaults (baseline)";
} else {
    $title .= "\n" . implode(", ", $subtitle);
}
$plot = new PHPlot(800, 600);
$plot->SetDefaultTTFont($phplot_test_ttfdir . $phplot_test_ttfonts['sans']);
$plot->SetPlotType('stackedbars');
$plot->SetDataType($horiz ? 'text-data-yx' : 'text-data');
$plot->SetDataValues($data);
$plot->SetTitle($title);
if (isset($textheight)) {
    $plot->SetFont($horiz ? 'x_label' : 'y_label', NULL, $textheight);
}
if (isset($textangle)) {
    call_user_func(array($plot, "Set{$dep_var}DataLabelAngle"), $textangle);
}
if (isset($shading)) {
    $plot->SetShading($shading);
}
call_user_func(array($plot, "Set{$ind_var}TickPos"), 'none');
call_user_func(array($plot, "Set{$dep_var}DataLabelPos"), 'plotstack');
	/**
	 * Adds raw image data of the graph to the output.
	 * @param $opts FormOptions
	 */
	public function draw( FormOptions $opts ) {
		global $wgTranslatePHPlotFont, $wgLang;

		$width = $opts->getValue( 'width' );
		$height = $opts->getValue( 'height' );
		// Define the object
		$plot = new PHPlot( $width, $height );

		list( $legend, $resData ) = $this->getData( $opts );
		$count = count( $resData );
		$skip = intval( $count / ( $width / 60 ) - 1 );
		$i = $count;

		foreach ( $resData as $date => $edits ) {
			if ( $skip > 0 ) {
				if ( ( $count - $i ) % $skip !== 0 ) $date = '';
			}

			if ( strpos( $date, ';' ) !== false ) {
				list( , $date ) = explode( ';', $date, 2 );
			}

			array_unshift( $edits, $date );
			$data[] = $edits;
			$i--;
		}

		$font = FCFontFinder::find( $wgLang->getCode() );

		if ( $font ) {
			$plot->SetDefaultTTFont( $font );
		} else {
			$plot->SetDefaultTTFont( $wgTranslatePHPlotFont );
		}
		$plot->SetDataValues( $data );

		if ( $legend !== null ) {
			$plot->SetLegend( $legend );
		}

		$numberFont = FCFontFinder::find( 'en' );

		$plot->setFont( 'x_label', $numberFont, 8 );
		$plot->setFont( 'y_label', $numberFont, 8 );

		$yTitle = wfMsg( 'translate-stats-' . $opts['count'] );

		// Turn off X axis ticks and labels because they get in the way:
		$plot->SetYTitle( $yTitle );
		$plot->SetXTickLabelPos( 'none' );
		$plot->SetXTickPos( 'none' );
		$plot->SetXLabelAngle( 45 );


		$max = max( array_map( 'max', $resData ) );
		$max = self::roundToSignificant( $max, 1 );
		$max = round( $max, intval( -log( $max, 10 ) ) );

		$yTick = 10;
		while ( $max / $yTick > $height / 20 ) {
			$yTick *= 2;
		}

		// If we have very small case, ensure that there is at least one tick
		$yTick = min( $max, $yTick );
		$yTick = self::roundToSignificant( $yTick );
		$plot->SetYTickIncrement( $yTick );
		$plot->SetPlotAreaWorld( null, 0, null, $max );


		$plot->SetTransparentColor( 'white' );
		$plot->SetBackgroundColor( 'white' );

		// Draw it
		$plot->DrawGraph();
	}
	public function execute( $par ) {
		global $wgRequest, $wgOut, $wgLang, $wgAutoloadClasses;

		$this->setHeaders();
		$this->outputHeader();

		if ( !class_exists( 'PHPlot' ) && !isset($wgAutoloadClasses['PHPlot'] ) ) {
			$wgOut->addWikiMsg( 'uos-warn' );
			return;
		}

		$par = trim(strtolower($par));

		foreach ( $this->blacklist as $b ) {
			if ( $b === $par ) {
				$par = false;
				break;
			}
		}

		if ( !$par ) {
			$opts = array();
			$hiddenoptions = $this->getHiddenOptions();
			$name = SpecialPage::getTitleFor( 'UserOptionStats' )->getPrefixedText();
			foreach ( $this->getOptions() as $k ) {
				if( in_array( $k, $hiddenoptions ) ) {
					continue; # List hidden options separately (see below)
				}
				$opts[] = "[[$name/$k|$k]]";
			}
			$wgOut->addWikiMsg( 'uos-choose', $wgLang->commaList( $opts ) );
			if ( count( $hiddenoptions ) > 0 ) {
				$hiddenopts = array();
				foreach ( $hiddenoptions as $hk ) {
					$hiddenopts[] = "[[$name/$hk|$hk]]";
				}
				$wgOut->addWikiMsg( 'uos-choose-hidden', $wgLang->commaList( $hiddenopts ) );
			}
			return;
		}

		$dbr = wfGetDB( DB_SLAVE );

		$users = $dbr->select( 'user', '*', '', __METHOD__ );
		$data = array();
		$optionName = $par;
		foreach ( $users as $u ) {
			// New from row doesn't load user_properties, hence this is slow!
			$obj = User::newFromRow( $u );
			$opt = $obj->getOption( $optionName, wfMsg( 'uos-unknown' ) );

			if ( !isset($data[$opt]) ) $data[$opt] = 0;
			$data[$opt]++;
		}

		$realdata = array();
		$labels = array();

		// Most popular first, barring other
		arsort( $data );

		// After more than 7 the default colors start to loop :(
		// So use the last free color for "other" which includes the rest
		$max = 7;
		$rest = array_slice( $data, $max );
		$data = array_slice( $data, 0, $max );
		foreach ( $data as $k => $d ) {
			$labels[] = "$k ($d)";
			$realdata[] = array( $k, $d );
		}
		if ( count($rest) ) {
			$other = 0;
			foreach ( $rest as $v ) $other += $v;
			$labels[] = wfMsg( 'uos-other' ) . " ($other)";
			$realdata[] = array( 'other', $other );
		}

		$title = $wgRequest->getText( 'pietitle', wfMsg( 'uos-title', $optionName ) );
		$width = $wgRequest->getInt( 'width', 700 );
		$height = $wgRequest->getInt( 'height', 500 );
		$width = max( 200, min( 1000, $width ) );
		$height = max( 200, min( 1000, $height ) );
		$shading = $wgRequest->getInt( 'shading', 10 );
		$height = max( 0, min( 1000, $height ) );

		// Define the object
		$plot = new PHPlot( $width, $height );
		$plot->SetDataType('text-data-single');
		$plot->setDataValues( $realdata );
		$plot->SetPlotType('pie');
		$plot->SetLegend($labels);
		$plot->SetShading( $shading );
		$plot->SetLabelScalePosition(0.3);
		$plot->SetTitle( $title );

		// Better fonts
		$realFunction = array( 'FCFontFinder', 'find' );
		if ( is_callable( $realFunction ) ) {
			$font = FCFontFinder::find( $wgLang->getCode() );
			if ( $font ) {
				$plot->SetDefaultTTFont( $font );
			}
		}

		global $wgOut;
		$wgOut->disable();
		$plot->DrawGraph();
	}
Exemplo n.º 8
0
require_once 'config.php';
$data = array(array('A', 1, 4), array('B', 2, 6), array('C', 3, 0));
$p = new PHPlot(400, 300);
$p->SetTitle('Error test');
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetXDataLabelPos('none');
# Errors:
switch ($case) {
    case 1:
        # Test: Turn on TTF without path setup
        $p->SetUseTTF(True);
        break;
    case 2:
        # Test: Bad default font with path
        $p->SetDefaultTTFont("/no/such/path/to/font.ttf");
        break;
    case 3:
        # Test: Bad default font without path
        $p->SetDefaultTTFont("nosuchfont.ttf");
        break;
    case 4:
        # Test: Bad font path
        $p->SetTTFPath("/no/such/font/dir");
        break;
    case 5:
        # Test: Good font path and default, bad font selected
        $p->SetTTFPath($phplot_test_ttfdir);
        $p->SetDefaultTTFont($phplot_test_ttfonts['sans']);
        $p->SetFont('title', 'nosuchfont.ttf', 14);
        break;
Exemplo n.º 9
0
# PHPlot Demo
# 2008-01-09 ljb
# For more information see http://sourceforge.net/projects/phplot/
# Load the PHPlot class library:
require_once 'phplot/phplot.php';
# Define the data array: Label, the 3 data sets.
# Year,  Features, Bugs, Happy Users:
$data = array();
$total = $_GET['total'] + 1;
for ($i = 1; $i < $total; $i++) {
    $data[] = array('版本' . $i . '-非Pass' . $_GET[$i] . "个", $_GET[$i]);
}
# Create a PHPlot object which will make a 600x400 pixel image:
$p = new PHPlot(850, 300);
# Use TrueType fonts:
$p->SetDefaultTTFont('phplot/simsun.ttc');
# Set the main plot title:
$p->SetTitle('版本非PASS测试例数量直方图');
# Select the data array representation and store the data:
$p->SetDataType('text-data');
$p->SetDataValues($data);
# Select the plot type - bar chart:
$p->SetPlotType('bars');
# Define the data range. PHPlot can do this automatically, but not as well.
//$p->SetPlotAreaWorld(0, 0, 7, 100);
# Select an overall image background color and another color under the plot:
$p->SetBackgroundColor('#CCDDED');
$p->SetDrawPlotAreaBackground(True);
$p->SetPlotBgColor('#CCDDED');
# Draw lines on all 4 sides of the plot:
$p->SetPlotBorderType('full');
Exemplo n.º 10
0
 if (count($stat['data']) == 0) {
     $stat['data'] = array(array(NULL, NULL));
 } elseif (count($stat['data'][0]) == 1) {
     $stat['data'][0][] = 0;
 }
 foreach ($plot_defaults as $key => $value) {
     if (!isset($stat[$key])) {
         $stat[$key] = $value;
     }
 }
 //Define the object
 $graph = new PHPlot($stat['xsize'], $stat['ysize']);
 $graph->SetDataType($stat['data_type']);
 $graph->SetFileFormat($stat['file_format']);
 $graph->SetPlotType($stat['graphtype']);
 $graph->SetDefaultTTFont('../tagsets/fonts/FreeSerif.ttf');
 $graph->SetPlotBorderType('none');
 // plotleft, plotright, both, full, none
 $graph->SetBackgroundColor($stat['background_color']);
 if ($stat['graphtype'] == 'bars') {
     $graph->SetShading(0);
     $graph->SetPlotAreaWorld(NULL, 0);
 }
 if (count($stat['legend']) > 0) {
     foreach ($stat['legend'] as $key => $val) {
         if (strlen($val) > 23) {
             $stat['legend'][$key] = substr($val, 0, 20) . '...';
         }
     }
     $graph->SetLegend($stat['legend']);
 }
Exemplo n.º 11
0
<?php

# $Id$
# Testing phplot - Default TT font (3a): Default font with file basename only
require_once 'phplot.php';
require_once 'config.php';
// TTF setup
$data = array(array('A', 3, 6), array('B', 2, 4), array('C', 1, 2));
$p = new PHPlot(800, 800);
$p->SetDataType('text-data');
$p->SetDataValues($data);
$p->SetPlotType('bars');
$p->SetTitle("SetDefaultTTFont() with file basename only");
$p->SetDefaultTTFont($phplot_test_ttfonts['serif']);
$p->SetXTitle('X Axis Title');
$p->SetYTitle('Y Axis Title');
$p->DrawGraph();
fwrite(STDERR, "OK defaultfont3a: title font=" . $p->fonts['title']['font'] . "\n");
Exemplo n.º 12
0
<?php

# $Id$
# Testing phplot - Default TT font (4): Default font with full path
require_once 'phplot.php';
require_once 'config.php';
// TTF setup
$data = array(array('A', 3, 6), array('B', 2, 4), array('C', 1, 2));
$p = new PHPlot(800, 800);
$p->SetDataType('text-data');
$p->SetDataValues($data);
$p->SetPlotType('bars');
$p->SetTitle("SetDefaultTTFont() with full path");
$p->SetDefaultTTFont($phplot_test_ttfdir . $phplot_test_ttfonts['mono']);
$p->SetXTitle('X Axis Title');
$p->SetYTitle('Y Axis Title');
$p->DrawGraph();
fwrite(STDERR, "OK defaultfont4: title font=" . $p->fonts['title']['font'] . "\n");