Files
2026-09-03 11:24:19 +02:00

151 lines
5.5 KiB
PHP

<?php
// Load the least-square regression class.
require_once('./polynomial/XY_Plot.php' );
//-----------------------------------------------------------
$imageWidth = 420;
$imageHeight = 330;
$leftMargin = 25;
$rightMargin = 50;
$topMargin = 25;
$bottomMargin = 40;
// Verticle scale
$Y_MajorScale = 0.1;
$Y_MinorScale = $Y_MajorScale / 5;
$X_MajorScale = 0.1;
$X_MinorScale = $X_MajorScale / 5;
//-----------------------------------------------------------
// Create image
$image1 = @imageCreate( $imageWidth , $imageHeight )
or die( "Cannot Initialize new GD image stream" );
//---------------------------------
// Create basic color map
//---------------------------------
$colorMap = array();
//$colorMap[ "Background" ] = image1ColorAllocate( $image1 , 0xDB , 0xB3 , 0xE6 );
$colorMap[ "Background" ] = imageColorAllocate( $image1 , 255, 255, 255 );
// Create a standard color palette
$colorMap[ "Black" ] = imagecolorallocate( $image1, 0, 0, 0 );
$colorMap[ "Red" ] = imagecolorallocate( $image1, 192, 0, 0 );
$colorMap[ "Green" ] = imagecolorallocate( $image1, 0, 192, 0 );
$colorMap[ "Blue" ] = imagecolorallocate( $image1, 0, 0, 192 );
$colorMap[ "Brown" ] = imagecolorallocate( $image1, 48, 48, 0 );
$colorMap[ "Cyan" ] = imagecolorallocate( $image1, 0, 192, 192 );
$colorMap[ "Purple" ] = imagecolorallocate( $image1, 192, 0, 192 );
$colorMap[ "LightGray" ] = imagecolorallocate( $image1, 192, 192, 192 );
$colorMap[ "DarkGray" ] = imagecolorallocate( $image1, 48, 48, 48 );
$colorMap[ "LightRed" ] = imagecolorallocate( $image1, 255, 0, 0 );
$colorMap[ "LightGreen" ] = imagecolorallocate( $image1, 0, 255, 0 );
$colorMap[ "LightBlue" ] = imagecolorallocate( $image1, 0, 0, 255 );
$colorMap[ "Yellow" ] = imagecolorallocate( $image1, 255, 255, 0 );
$colorMap[ "LightCyan" ] = imagecolorallocate( $image1, 0, 255, 255 );
$colorMap[ "LightPurple" ] = imagecolorallocate( $image1, 255, 0, 255 );
$colorMap[ "White" ] = imagecolorallocate( $image1, 255, 255, 255 );
$colorMap[ "DarkYellow" ] = imagecolorallocate( $image1, 255, 214, 0 );
$colorMap[ "Gray10" ] = imagecolorallocate( $image1 , 26 , 26 , 26 );
$colorMap[ "Gray20" ] = imagecolorallocate( $image1 , 51 , 51 , 51 );
$colorMap[ "Gray30" ] = imagecolorallocate( $image1 , 77 , 77 , 77 );
$colorMap[ "Gray40" ] = imagecolorallocate( $image1 , 102 , 102 , 102 );
$colorMap[ "Gray50" ] = imagecolorallocate( $image1 , 128 , 128 , 128 );
$colorMap[ "Gray60" ] = imagecolorallocate( $image1 , 154 , 154 , 154 );
$colorMap[ "Gray70" ] = imagecolorallocate( $image1 , 180 , 180 , 180 );
$colorMap[ "Gray80" ] = imagecolorallocate( $image1 , 205 , 205 , 205 );
$colorMap[ "Gray90" ] = imagecolorallocate( $image1 , 230 , 230 , 230 );
// New plot
$plot = new XY_PlotClass( $image1 );
// Setup boundaries
$plot->sizeWindow
(
$leftMargin,
$topMargin,
$imageWidth - $rightMargin,
$imageHeight - $bottomMargin
);
// Draw border around graph area.
//---------------------------------------------------------------------------
//
//---------------------------------------------------------------------------
function plotRectangleRange1($scaleFrom,$scaleTo,$xFrom,$xTo, $color)
{
global $plot;
global $imageWidth;
global $leftMargin;
global $rightMargin;
global $imageHeight;
global $topMargin;
global $bottomMargin;
global $image1;
$plot->resetData();
$frameWidth = $imageWidth - $leftMargin - $rightMargin;
$scaleCounter = $frameWidth/($scaleTo-$scaleFrom);
if ($color == 'green_value')
$rgb = imagecolorallocatealpha($image1, 0, 255, 0, 100);
else if ($color == 'yellow_value')
$rgb = imagecolorallocatealpha($image1, 255, 255, 0, 100);
else if ($color == 'red_value')
$rgb = imagecolorallocatealpha($image1, 255, 0, 0, 100);
if ($leftMargin+$xTo*$scaleCounter > $imageWidth-$rightMargin) $val=$imageWidth-$rightMargin;
else $val=$leftMargin+$xTo*$scaleCounter;
imagefilledrectangle($image1, $leftMargin+$xFrom*$scaleCounter, $topMargin, $val, $imageHeight-$bottomMargin, $rgb);
}
function plotCircleRange1($scaleXFrom,$scaleXTo,$scaleYFrom,$scaleYTo,$xParam,$yParam)
{
global $plot;
global $imageWidth;
global $leftMargin;
global $rightMargin;
global $imageHeight;
global $topMargin;
global $bottomMargin;
global $image1;
$plot->resetData();
$frameWidth = $imageWidth - $leftMargin - $rightMargin;
$frameHeight = $imageHeight - $topMargin - $bottomMargin;
$scaleXCounter = $frameWidth/($scaleXTo-$scaleXFrom);
$scaleYCounter = $frameHeight/($scaleYTo-$scaleYFrom);
if ($leftMargin+$xParam*$scaleXCounter > $imageWidth-$rightMargin) $valX=$imageWidth-$rightMargin;
else $valX=$leftMargin+$xParam*$scaleXCounter;
$valY=($imageHeight-$bottomMargin)-$yParam*$scaleYCounter;
$grey = imagecolorallocate( $image1 , 154 , 154 , 154 );
imagefilledellipse($image1, $valX, $valY, 10, 10, $grey);
}
//---------------------------------------------------------------------------
// Custom vertical text-- just return value with dolor sign in front
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//
//---------------------------------------------------------------------------
?>