function circle($arr)
 {
     $pos = 100;
     // choose a color for the ellipse
     $col_ellipse = imagecolorallocate($this->im, 200, 200, 200);
     $col_ellipse_top = imagecolorallocate($this->im, 180, 180, 180);
     // draw the ellipse
     imagefilledellipse($this->im, 150, $pos + 10, 200, 100, $col_ellipse);
     imagefilledellipse($this->im, 150, $pos, 200, 100, $col_ellipse_top);
     $arrCount = count($arr);
     $start = 0;
     $gesamt = 0;
     $textline = 20;
     for ($x = 0; $arrCount > $x; $x++) {
         $move = $arr[$x]['size'] * 3.6 + $gesamt;
         $add = $arr[$x]['size'] * 3.6;
         $fillcolor = ImageColorAllocate($this->im, rand(0, 255), rand(0, 255), rand(0, 255));
         $black = ImageColorAllocate($this->im, 0, 0, 0);
         // Startpunkte / mitte des Kuchens
         $point[] = 150;
         $point[] = $pos;
         $radius = 100;
         for ($i = $start; $i <= $move; $i++) {
             $point[] = 150 + $radius * sin(deg2rad($i));
             $point[] = $pos - $radius * cos(deg2rad($i)) * 0.5;
         }
         $start = $i;
         ImageFilledPolygon($this->im, $point, sizeof($point) / 2, $fillcolor);
         unset($point);
         $textline = $textline + 15;
         imagefilledrectangle($this->im, 300 - 15, $textline + 2, 300 - 5, $textline + 13, $fillcolor);
         imagerectangle($this->im, 300 - 5, $textline + 2, 300 - 15, $textline + 13, $black);
         ImageString($this->im, 2, 300, $textline, $arr[$x]['name'], $this->text_color);
         $gesamt = $gesamt + $add;
     }
 }
Example #2
0
	//=================================

	//=================================
	// Polygone 5/20
	unset($tab5);
	$tab5=array();
	for($i=0;$i<$nbMat;$i++){
		$angle=round($i*360/$nbMat);
		//writinfo('/tmp/infos_graphe.txt','a+',"\$angle=$angle\n");
		$tab=coordcirc(5,$angle);

		$tab5[]=$tab[0];
		$tab5[]=$tab[1];
	}

	ImageFilledPolygon($img,$tab5,count($tab5)/2,$bande1);
	//=================================


	//=================================
	// Axes
	for($i=0;$i<count($tab20)/2;$i++){
		imageline ($img,$x0,$y0,$tab20[2*$i],$tab20[2*$i+1],$axes);
		if($i>0){
			imageline ($img,$tab20[2*($i-1)],$tab20[2*($i-1)+1],$tab20[2*$i],$tab20[2*$i+1],$axes);
		}
		else{
			//imageline ($img,$tab20[2*count($tab20)/2],$tab20[2*count($tab20)/2+1],$tab20[2*$i],$tab20[2*$i+1],$axes);
		}
	}
	imageline ($img,$tab20[0],$tab20[1],$tab20[2*($i-1)],$tab20[2*($i-1)+1],$axes);
Example #3
0
 /**
  * Draws a squaredarea or stackedsquaredarea plot (Squared Area)
  *
  * This is the main function for drawing squaredarea and stackedsquaredarea plots,
  * which area a blend of 'squared' plus either 'area' or 'stackedarea'. Supported
  * data types are data-data and text-data.  Missing points are not allowed,
  * and all data sets must have the same number of points.
  *
  * @param bool $do_stacked  True for cumulative (stacked), false or omit for unstacked.
  * @return bool  True (False on error if an error handler returns True)
  */
 protected function DrawSquaredArea($do_stacked = FALSE)
 {
     if (!$this->CheckDataType('text-data, data-data')) {
         return FALSE;
     }
     // Validation: Need at least 2 rows; all rows must have same number of columns.
     if (($n_rows = $this->num_data_rows) < 2) {
         return TRUE;
     }
     if ($this->records_per_group != min($this->num_recs)) {
         return $this->PrintError("DrawSquaredArea(): Data array must contain the same number" . " of Y values for each X");
     }
     // Calculate and store device coordinates xd[] and yd[][], and draw the data labels.
     $n_columns = $this->SetupAreaPlot($do_stacked, $xd, $yd);
     // Draw a filled polygon for each Y column
     $prev_col = 0;
     for ($col = 1; $col < $n_columns; $col++) {
         // 1 extra for X axis artificial column
         // Current data set forms the top. For each point after the first, add 2 points.
         $x_prev = $xd[0];
         $y_prev = $yd[0][$col];
         $pts = array($x_prev, $y_prev);
         // Bottom left point
         for ($row = 1; $row < $n_rows; $row++) {
             $x = $xd[$row];
             $y = $yd[$row][$col];
             array_push($pts, $x, $y_prev, $x, $y);
             $x_prev = $x;
             $y_prev = $y;
         }
         // Previous data set forms the bottom. Process right to left.
         // Note $row is now $n_rows, and it will be stepped back to 0.
         $row--;
         $x_prev = $xd[$row];
         $y_prev = $yd[$row][$prev_col];
         array_push($pts, $x_prev, $y_prev);
         // Bottom right point
         while (--$row >= 0) {
             $x = $xd[$row];
             $y = $yd[$row][$prev_col];
             array_push($pts, $x_prev, $y, $x, $y);
             $x_prev = $x;
             $y_prev = $y;
         }
         // Draw the resulting polygon, which has (2 * (1 + 2*(n_rows-1))) points:
         ImageFilledPolygon($this->img, $pts, 4 * $n_rows - 2, $this->ndx_data_colors[$prev_col]);
         $prev_col = $col;
     }
     // Draw the data borders, if enabled. (After, else the area fills cover parts of it.)
     if (!empty($this->draw_data_borders)) {
         $this->DrawAreaFillBorders($n_columns, $xd, $yd, $do_stacked, TRUE);
     }
     return TRUE;
 }
Example #4
0
    /**
     * Output the plot
     * @access private
     */
    function _done()
    {
        parent::_done();

        $totalY = 0;
        $this->_dataset->_reset();
        while ($point = $this->_dataset->_next()) {
            $totalY += $point['Y'];
        }

        $centerX = (int) (($this->_left + $this->_right) / 2);
        $centerY = (int) (($this->_top + $this->_bottom) / 2);
        $diameter = min($this->height(), $this->width()) * 0.75;
        $currentY = 0; //rand(0, 100)*$totalY/100;
        $this->_dataset->_reset();

        while ($point = $this->_dataset->_next()) {
            $angle1 = 360 * ($currentY / $totalY);
            $currentY += $point['Y'];
            $angle2 = 360 * ($currentY / $totalY);
            $dX = $diameter * ($this->_radius / 100) * cos(deg2rad(($angle1 + $angle2) / 2));
            $dY = $diameter * ($this->_radius / 100) * sin(deg2rad(($angle1 + $angle2) / 2));
            $dD = sqrt($dX * $dX + $dY * $dY);

            $polygon[] = $centerX;
            $polygon[] = $centerY;

            $angle = min($angle1, $angle2);
            $dA = 360 / (pi() * $diameter);
            while ($angle <= max($angle1, $angle2)) {
                $polygon[] = ($centerX + ($diameter / 2) * cos(deg2rad($angle % 360)));
                $polygon[] = ($centerY + ($diameter / 2) * sin(deg2rad($angle % 360)));
                $angle += $dA;
            }
            if ($angle != max($angle1, $angle2)) {
                $polygon[] = ($centerX + ($diameter / 2) * cos(deg2rad($angle2 % 360)));
                $polygon[] = ($centerY + ($diameter / 2) * sin(deg2rad($angle2 % 360)));
            }
            //ImageFilledArc($this->_canvas(), $centerX+$dX, $centerY+$dY, $diameter-$dD, $diameter-$dD, $angle1 % 360, $angle2 % 360, $this->_getFillStyle(), IMG_ARC_PIE);
            //ImageFilledArc($this->_canvas(), $centerX+$dX, $centerY+$dY, $diameter-$dD, $diameter-$dD, $angle1 % 360, $angle2 % 360, $this->_getLineStyle(), IMG_ARC_NOFILL+IMG_ARC_EDGED);
            ImageFilledPolygon($this->_canvas(), $polygon, count($polygon) / 2, $this->_getFillStyle());
            //echo $this->_getFillStyle();
            // Modified: Don't draw border
            //ImagePolygon($this->_canvas(), $polygon, count($polygon) / 2, $this->_getLineStyle());

            unset ($polygon);
        }
        //ImageEllipse($this->_canvas(), $centerX, $centerY, $diameter, $diameter, 0);
        $this->_drawMarker();
    }
Example #5
0
 function drawArrow($X1, $Y1, $X2, $Y2, $Format = "")
 {
     $FillR = isset($Format["FillR"]) ? $Format["FillR"] : 0;
     $FillG = isset($Format["FillG"]) ? $Format["FillG"] : 0;
     $FillB = isset($Format["FillB"]) ? $Format["FillB"] : 0;
     $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $FillR;
     $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $FillG;
     $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $FillB;
     $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
     $Size = isset($Format["Size"]) ? $Format["Size"] : 10;
     $Ratio = isset($Format["Ratio"]) ? $Format["Ratio"] : 0.5;
     $TwoHeads = isset($Format["TwoHeads"]) ? $Format["TwoHeads"] : FALSE;
     $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : FALSE;
     /* Calculate the line angle */
     $Angle = $this->getAngle($X1, $Y1, $X2, $Y2);
     /* Override Shadow support, this will be managed internally */
     $RestoreShadow = $this->Shadow;
     if ($this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0) {
         $this->Shadow = FALSE;
         $this->drawArrow($X1 + $this->ShadowX, $Y1 + $this->ShadowY, $X2 + $this->ShadowX, $Y2 + $this->ShadowY, array("FillR" => $this->ShadowR, "FillG" => $this->ShadowG, "FillB" => $this->ShadowB, "Alpha" => $this->Shadowa, "Size" => $Size, "Ratio" => $Ratio, "TwoHeads" => $TwoHeads, "Ticks" => $Ticks));
     }
     /* Draw the 1st Head */
     $TailX = cos(($Angle - 180) * PI / 180) * $Size + $X2;
     $TailY = sin(($Angle - 180) * PI / 180) * $Size + $Y2;
     $Points = "";
     $Points[] = $X2;
     $Points[] = $Y2;
     $Points[] = cos(($Angle - 90) * PI / 180) * $Size * $Ratio + $TailX;
     $Points[] = sin(($Angle - 90) * PI / 180) * $Size * $Ratio + $TailY;
     $Points[] = cos(($Angle - 270) * PI / 180) * $Size * $Ratio + $TailX;
     $Points[] = sin(($Angle - 270) * PI / 180) * $Size * $Ratio + $TailY;
     $Points[] = $X2;
     $Points[] = $Y2;
     /* Visual correction */
     if ($Angle == 180 || $Angle == 360) {
         $Points[4] = $Points[2];
     }
     if ($Angle == 90 || $Angle == 270) {
         $Points[5] = $Points[3];
     }
     $ArrowColor = $this->allocateColor($this->Picture, $FillR, $FillG, $FillB, $Alpha);
     ImageFilledPolygon($this->Picture, $Points, 4, $ArrowColor);
     $this->drawLine($Points[0], $Points[1], $Points[2], $Points[3], array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha));
     $this->drawLine($Points[2], $Points[3], $Points[4], $Points[5], array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha));
     $this->drawLine($Points[0], $Points[1], $Points[4], $Points[5], array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha));
     /* Draw the second head */
     if ($TwoHeads) {
         $Angle = $this->getAngle($X2, $Y2, $X1, $Y1);
         $TailX2 = cos(($Angle - 180) * PI / 180) * $Size + $X1;
         $TailY2 = sin(($Angle - 180) * PI / 180) * $Size + $Y1;
         $Points = "";
         $Points[] = $X1;
         $Points[] = $Y1;
         $Points[] = cos(($Angle - 90) * PI / 180) * $Size * $Ratio + $TailX2;
         $Points[] = sin(($Angle - 90) * PI / 180) * $Size * $Ratio + $TailY2;
         $Points[] = cos(($Angle - 270) * PI / 180) * $Size * $Ratio + $TailX2;
         $Points[] = sin(($Angle - 270) * PI / 180) * $Size * $Ratio + $TailY2;
         $Points[] = $X1;
         $Points[] = $Y1;
         /* Visual correction */
         if ($Angle == 180 || $Angle == 360) {
             $Points[4] = $Points[2];
         }
         if ($Angle == 90 || $Angle == 270) {
             $Points[5] = $Points[3];
         }
         $ArrowColor = $this->allocateColor($this->Picture, $FillR, $FillG, $FillB, $Alpha);
         ImageFilledPolygon($this->Picture, $Points, 4, $ArrowColor);
         $this->drawLine($Points[0], $Points[1], $Points[2], $Points[3], array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha));
         $this->drawLine($Points[2], $Points[3], $Points[4], $Points[5], array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha));
         $this->drawLine($Points[0], $Points[1], $Points[4], $Points[5], array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha));
         $this->drawLine($TailX, $TailY, $TailX2, $TailY2, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha, "Ticks" => $Ticks));
     } else {
         $this->drawLine($X1, $Y1, $TailX, $TailY, array("R" => $BorderR, "G" => $BorderG, "B" => $BorderB, "Alpha" => $Alpha, "Ticks" => $Ticks));
     }
     /* Re-enable shadows */
     $this->Shadow = $RestoreShadow;
 }
Example #6
0
 function DrawArea()
 {
     $width = $this->chart_area[2] - $this->chart_area[0];
     $height = $this->chart_area[3] - $this->chart_area[1];
     $step = $width / $this->record_count_group;
     $corr = $step / 2;
     $xpos = $step;
     $init = $this->chart_area[0];
     for ($i = 0; $i < $this->record_group; $i++) {
         $x = $this->chart_area[0] + $corr;
         $x = round($x, 0);
         $y = $this->chart_area[3];
         $posarr[$i][] = $x;
         $posarr[$i][] = $y;
     }
     foreach ($this->data_values as $row) {
         $arrcounter = 0;
         foreach ($row as $v) {
             if ($v != $row[0]) {
                 $x = $xpos + $init - $corr;
                 $y = $this->chart_area[3] - $v / $this->record_max * $height;
                 $x = round($x, 0);
                 $y = round($y, 0);
                 $posarr[$arrcounter][] = $x;
                 $posarr[$arrcounter][] = $y;
                 $arrcounter++;
             }
         }
         $xpos += $step;
     }
     for ($i = 0; $i < $this->record_group; $i++) {
         $x = $this->chart_area[2] - $corr;
         $y = $this->chart_area[3];
         $posarr[$i][] = $x;
         $posarr[$i][] = $y;
     }
     $colcount = 0;
     foreach ($posarr as $row) {
         if ($colcount >= count($this->bar_color)) {
             $colcount = 0;
         }
         $barcol = $this->col_bar_color[$colcount];
         ImageFilledPolygon($this->img, $row, count($row) / 2, $barcol);
         $colcount++;
     }
 }
Example #7
0
 function draw_brush($x, $y, $size, $type, $colour)
 {
     $x = round($x);
     $y = round($y);
     $half = round($size / 2);
     switch ($type) {
         case 'circle':
             ImageArc($this->image, $x, $y, $size, $size, 0, 360, $this->colour[$colour]);
             ImageFillToBorder($this->image, $x, $y, $this->colour[$colour], $this->colour[$colour]);
             break;
         case 'square':
             ImageFilledRectangle($this->image, $x - $half, $y - $half, $x + $half, $y + $half, $this->colour[$colour]);
             break;
         case 'vertical':
             ImageFilledRectangle($this->image, $x, $y - $half, $x + 1, $y + $half, $this->colour[$colour]);
             break;
         case 'horizontal':
             ImageFilledRectangle($this->image, $x - $half, $y, $x + $half, $y + 1, $this->colour[$colour]);
             break;
         case 'slash':
             ImageFilledPolygon($this->image, array($x + $half, $y - $half, $x + $half + 1, $y - $half, $x - $half + 1, $y + $half, $x - $half, $y + $half), 4, $this->colour[$colour]);
             break;
         case 'backslash':
             ImageFilledPolygon($this->image, array($x - $half, $y - $half, $x - $half + 1, $y - $half, $x + $half + 1, $y + $half, $x + $half, $y + $half), 4, $this->colour[$colour]);
             break;
         default:
             @eval($type);
             // user can create own brush script.
     }
 }
Example #8
0
 /**
  * Draw a pie slice
  *
  * Parameter array:
  * 
  * 'x': int X center point
  * 
  * 'y': int Y center point
  * 
  * 'rx': int X radius
  * 
  * 'ry': int Y radius
  * 
  * 'v1': int The starting angle (in degrees)
  * 
  * 'v2': int The end angle (in degrees)
  * 
  * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut)
  * 
  * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut)
  * 
  * 'fill': mixed [optional] The fill color
  * 
  * 'line': mixed [optional] The line color
  * 
  * @param array $params Parameter array
  */
 function pieslice($params)
 {
     $x = $this->_getX($params['x']);
     $y = $this->_getY($params['y']);
     $rx = $params['rx'];
     $ry = $params['ry'];
     $v1 = $params['v1'];
     $v2 = $params['v2'];
     $srx = isset($params['srx']) ? $params['srx'] : 0;
     $sry = isset($params['sry']) ? $params['sry'] : 0;
     $fillColor = isset($params['fill']) ? $params['fill'] : false;
     $lineColor = isset($params['line']) ? $params['line'] : false;
     $dA = 0.1;
     if ($srx !== false && $sry !== false) {
         $angle = max($v1, $v2);
         while ($angle >= min($v1, $v2)) {
             $polygon[] = $x + $srx * cos(deg2rad($angle % 360));
             $polygon[] = $y + $sry * sin(deg2rad($angle % 360));
             $angle -= $dA;
         }
         if ($angle + $dA > min($v1, $v2)) {
             $polygon[] = $x + $srx * cos(deg2rad(min($v1, $v2) % 360));
             $polygon[] = $y + $sry * sin(deg2rad(min($v1, $v2) % 360));
         }
     } else {
         $polygon[] = $x;
         $polygon[] = $y;
     }
     $angle = min($v1, $v2);
     while ($angle <= max($v1, $v2)) {
         $polygon[] = $x + $rx * cos(deg2rad($angle % 360));
         $polygon[] = $y + $ry * sin(deg2rad($angle % 360));
         $angle += $dA;
     }
     if ($angle - $dA < max($v1, $v2)) {
         $polygon[] = $x + $rx * cos(deg2rad(max($v1, $v2) % 360));
         $polygon[] = $y + $ry * sin(deg2rad(max($v1, $v2) % 360));
     }
     if (($fill = $this->_getFillStyle($fillColor, $x - $rx - 1, $y - $ry - 1, $x + $rx + 1, $y + $ry + 1)) !== false && count($polygon) > 2) {
         ImageFilledPolygon($this->_canvas, $polygon, count($polygon) / 2, $fill);
     }
     if (($line = $this->_getLineStyle($lineColor)) !== false) {
         ImagePolygon($this->_canvas, $polygon, count($polygon) / 2, $line);
     }
     parent::pieSlice($params);
 }
Example #9
0
 function DrawStackedBars()
 {
     if ($this->data_type != 'text-data') {
         $this->DrawError('DrawStackedBars(): Bar plots must be text-data: use SetDataType("text-data")');
         return FALSE;
     }
     for ($row = 0; $row < $this->num_data_rows; $row++) {
         $record = 1;
         // Skip record #0 (data label)
         $x_now_pixels = $this->xtr(0.5 + $row);
         // Place text-data at X = 0.5, 1.5, 2.5, etc...
         if ($this->x_data_label_pos != 'none') {
             // Draw X Data labels?
             $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels);
         }
         // Draw the bars
         $oldv = 0;
         for ($idx = 0; $record < $this->num_recs[$row]; $record++, $idx++) {
             if (is_numeric($this->data[$row][$record])) {
                 // Allow for missing Y data
                 $x1 = $x_now_pixels - $this->data_group_space;
                 $x2 = $x_now_pixels + $this->data_group_space;
                 $y1 = $this->ytr(abs($this->data[$row][$record]) + $oldv);
                 $y2 = $this->ytr($this->x_axis_position + $oldv);
                 $oldv += abs($this->data[$row][$record]);
                 if ($this->shading) {
                     // Draw the shade?
                     ImageFilledPolygon($this->img, array($x1, $y1, $x1 + $this->shading, $y1 - $this->shading, $x2 + $this->shading, $y1 - $this->shading, $x2 + $this->shading, $y2 - $this->shading, $x2, $y2, $x2, $y1), 6, $this->ndx_data_dark_colors[$idx]);
                 } else {
                     ImageRectangle($this->img, $x1, $y1, $x2, $y2, $this->ndx_data_border_colors[$idx]);
                 }
                 // Draw the bar
                 ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $this->ndx_data_colors[$idx]);
             }
         }
         // end for
     }
     // end for
 }
Example #10
0
 function DrawBullet($image, $x, $y, $type, $color)
 {
     switch ($type) {
         case 0:
         case 5:
             for ($i = 0; $i < 8; $i++) {
                 ImageArc($image, $x, $y, $i, $i, 0, 359, $color);
             }
             break;
         case 1:
         case 6:
             ImageFilledRectangle($image, $x - 3, $y - 3, $x + 3, $y + 3, $color);
             break;
         case 2:
         case 7:
             ImageFilledRectangle($image, $x - 1, $y - 4, $x + 1, $y + 4, $color);
             ImageFilledRectangle($image, $x - 4, $y - 1, $x + 4, $y + 1, $color);
             break;
         case 3:
         case 8:
             $points[0] = $x;
             $points[1] = $y - 4;
             $points[2] = $x + 4;
             $points[3] = $y;
             $points[4] = $x;
             $points[5] = $y + 4;
             $points[6] = $x - 4;
             $points[7] = $y;
             ImageFilledPolygon($image, $points, 4, $color);
             break;
         case 4:
         case 9:
             $points[0] = $x;
             $points[1] = $y - 4;
             $points[2] = $x + 4;
             $points[3] = $y + 4;
             $points[4] = $x - 4;
             $points[5] = $y + 4;
             ImageFilledPolygon($image, $points, 3, $color);
             break;
         default:
     }
     return;
 }
Example #11
0
function draw_plage_spher($im, $results, $flg, $l0, $b0, $p0, $sx, $r, $col)
{
    $lon = $results['LON'];
    $lat = $results['LAT'];
    /*if ($flg == 0)
    		$col=ImageColorAllocate($im, 255, 255-$results['INTENSITY'], 255-$results['INTENSITY']);
    	else
    		$col=ImageColorAllocate($im, 255, 255-$results['INTENSITY'], 255);*/
    $cBlack = ImageColorAllocate($im, 0, 0, 0);
    $nb = count($lon);
    for ($i = 0; $i < $nb; $i++) {
        $lon[$i] = $lon[$i] + 360 * $flg - rad2deg($l0);
        //if ( ($lon[$i] <= 90) && ($lon[$i] >= -90) ) {
        $coord = ToHelio($lon[$i], $lat[$i], $b0, $p0, $r, $sx);
        $points[] = $coord['lon'];
        $points[] = $coord['lat'];
        //}
    }
    if (count($points) > 0) {
        ImageFilledPolygon($im, $points, count($points) / 2, $col);
        imagepolygon($im, $points, count($points) / 2, $cBlack);
    }
    unset($points);
}
Example #12
0
function draw_feat_pix($im, $tab_xpix, $tab_ypix, $c_x, $c_y, $intensity, $feat_id, $filled, $zoom)
{
    global $global;
    $font_ttf = $global['FONT_PATH'];
    $sizey = imagesy($im);
    $nb = count($tab_xpix);
    $points = array();
    if ($filled) {
        $col = ImageColorAllocate($im, 255, 255 - $intensity, 255 - $intensity);
    } else {
        $col = ImageColorAllocate($im, 255, 255, 255);
    }
    if ($filled) {
        $gc_col = ImageColorAllocate($im, 0, 0, 0);
    } else {
        $gc_col = ImageColorAllocate($im, 0, 0, 255);
    }
    for ($i = 0; $i < $nb; $i++) {
        $points[] = $tab_xpix[$i] * $zoom;
        $points[] = $sizey - $tab_ypix[$i] * $zoom;
        // en PHP, l'origine de l'image est coin gauche haut
    }
    if (count($points) > 0) {
        if ($filled) {
            ImageFilledPolygon($im, $points, $nb, $col);
        }
        ImagePolygon($im, $points, $nb, $col);
    }
    imagefilledellipse($im, $c_x * $zoom, $sizey - $c_y * $zoom, 2, 2, $gc_col);
    //ImageString ($im, 3, $c_x*$zoom-strlen($feat_id), $sizey-$c_y*$zoom+5, $feat_id, $gc_col);
    $textArray = explode(' ', $feat_id);
    $y = $sizey - $c_y * $zoom + 15;
    foreach ($textArray as $txt) {
        ImageTTFText($im, 8, 0, $c_x * $zoom - strlen($feat_id) + 10, $y, $gc_col, $font_ttf, $txt);
        $y += 15;
    }
    //ImageTTFText($im, 8, 0, $c_x*$zoom-strlen($feat_id)+10, $sizey-$c_y*$zoom+15, $gc_col, $font_ttf, $feat_id);
}
Example #13
0
function _drawxaxis() {

        $maxlabwid = $this->_maxlab();
        $x0 = $this->lm;
        $y0 = $this->tm + $this->cheight;
        $x1 = $x0 + $this->cwidth;
        $y1 = $y0;
        $div = $this->xgridint;
        imageline($this->image,$x0,$y0,$x1,$y1,$this->gridcol);
        $gry = $this->xgrid ? $this->tm : $this->tm + $this->cheight + 3 ;
        $ii=0;
        for ($x=$x1,$i=$this->xcount-1; $x>$x0+3; $x -= $div, $i--, $ii++) {
                if ($this->xdashed) {
                        for ($xd=$gry;$xd<=$y0; $xd=$xd+4) {
                                imagesetpixel($this->image,$x,$xd,$this->gridcol);
                        }
                } else {
                        imageline($this->image,$x,$gry,$x,$y0,$this->gridcol);
                }
                imageline($this->image,$x,$y0-4,$x,$y0+3,$this->txtcol);
                $v = $this->xlabels[$i];
                $tw = strlen("$v")*imagefontwidth(2);
                $th = imagefontheight(2);

                if (!($ii%$this->xstep)) {
                        if ($this->xdelta) { if (!$delta) { $delta=12; } else { $delta=0; } } else { $delta=0; }

                        $this->_writestring($this->image,2,$x - ($div+$tw)/2, $y0 + 5 + $delta, $v, $this->txtcol,0,0);
                }
        }
        $y = $this->height - 30;
        $tw = strlen($this->xtitle)*imagefontwidth(3);
        $x = ($this->lm + $this->cwidth + $this->lm - $tw)/2;
        $this->_writestring($this->image,3,$this->lm + $this->cwidth+2,$y0-20,$this->xtitle,$this->txtcol,1,0);

        if ($this->xstr) {
                $points[0] = $this->lm + $this->cwidth+10;
                $points[1] = $y0-3;
                $points[2] = $points[0]+15;
                $points[3] = $points[1]+3;
                $points[4] = $points[2]-15;
                $points[5] = $points[3]+3;
                $points[6] = $points[4]+3;
                $points[7] = $points[5]-3;
                ImageSetThickness($this->image, $this->xline);
                imageline($this->image,$x0,$y0,$x1+15,$y1,$this->txtcol);
                ImageSetThickness($this->image, 1);
                ImageFilledPolygon($this->image,$points,4,$this->txtcol);
        }
}
Example #14
0
 }
 $text_size = 1;
 //Compute the pic's center and the radius
 $x_center = $width / 2;
 $y_center = $height / 2;
 $radius = $width / 2 - 30;
 $div_length = 10;
 $subdiv_length = 6;
 //Plot the data
 $points = array();
 for ($i = 0; $i < $num_points; $i++) {
     //Compute the point
     $points[$i * 2] = $x_center + $data[$i] * $radius / 10 * cos(deg2rad($angles[$i]));
     $points[$i * 2 + 1] = $y_center - $data[$i] * $radius / 10 * sin(deg2rad($angles[$i]));
 }
 ImageFilledPolygon($im, $points, $num_points, $orange);
 ImagePolygon($im, $points, $num_points, $blue);
 //Plot the sub-areas
 $suba_nb = 4;
 for ($i = 0; $i < $suba_nb; $i++) {
     for ($j = 0; $j < $num_points; $j++) {
         //Compute the point
         $points[$j * 2] = $x_center + $radius / $suba_nb * ($i + 1) * cos(deg2rad($angles[$j]));
         $points[$j * 2 + 1] = $y_center - $radius / $suba_nb * ($i + 1) * sin(deg2rad($angles[$j]));
     }
     ImagePolygon($im, $points, $num_points, $grey);
 }
 //Plot the axis
 for ($i = 0; $i < $num_points; $i++) {
     //Axis
     $x = $x_center + $radius * cos(deg2rad($angles[$i]));
Example #15
0
 private function drawshape($image, $action, $color)
 {
     switch ($action % 7) {
         case 0:
             ImageFilledRectangle($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color);
             break;
         case 1:
         case 2:
             ImageFilledEllipse($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color);
             break;
         case 3:
             $points = array($this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY());
             ImageFilledPolygon($image, $points, 4, $color);
             break;
         case 4:
         case 5:
         case 6:
             $start = $this->getInt() * 360 / 256;
             $end = $start + $this->getInt() * 180 / 256;
             ImageFilledArc($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $start, $end, $color, IMG_ARC_PIE);
             break;
     }
 }
Example #16
0
}
$points2[2 * $i + 2] = 100;
$points2[2 * $i + 3] = $ycenter;
ImageFilledPolygon($image, $points2, $the3 - $ths3 + 2, $line3);
ImagePolygon($image, $points2, $the3 - $ths3 + 2, $black);
// Calculate the slice for Admin
$points2[0] = 100;
$points2[1] = $ycenter;
for ($i = 0; $i <= $the4 - $ths4; $i += 1) {
    $theta = ($i + $ths4) / 100;
    $points2[2 * $i + 2] = round(100 + 80 * sin($theta));
    $points2[2 * $i + 3] = round($ycenter + 80 * cos($theta));
}
$points2[2 * $i + 2] = 100;
$points2[2 * $i + 3] = $ycenter;
ImageFilledPolygon($image, $points2, $the4 - $ths4 + 2, $line4);
ImagePolygon($image, $points2, $the4 - $ths4 + 2, $black);
// Label the graph
ImageString($image, 5, 110, 3, 'Effort by Category', $black);
ImageString($image, 3, 60, 200, 'All Periods', $black);
ImageString($image, 3, 230, 200, 'Latest Period', $black);
// Outline the image
ImageLine($image, 0, 0, 379, 0, $dark);
ImageLine($image, 379, 0, 379, 219, $dark);
ImageLine($image, 379, 219, 0, 219, $dark);
ImageLine($image, 0, 219, 0, 0, $dark);
// Expose the graph
header('Content-type: image/png');
ImagePNG($image);
// echo "</p>\n";
//echo "</table>\n";
Example #17
0
        $endx = $width;
        $endy = round($height / 2);
        $points = array($endx, $endy, $endx - 9, $endy + 5, $endx - 9, $endy - 5);
        break;
    case 'bottom':
        $endx = round($width / 2);
        $endy = $height;
        $points = array($endx, $endy, $endx + 5, $endy - 9, $endx - 5, $endy - 9);
        break;
    default:
        die('end must be top, left, right or bottom!');
        break;
}
// end preparations
header("Content-type: image/png");
$arrow = ImageCreate($width + 1, $height + 1);
$white = ImageColorAllocate($arrow, 255, 255, 255);
$black = ImageColorAllocate($arrow, 0, 0, 0);
ImageLine($arrow, $startx, $starty, round($width / 2), round($height / 2), $black);
ImageLine($arrow, round($width / 2), round($height / 2), $endx, $endy, $black);
ImageFilledPolygon($arrow, $points, 3, $black);
if ($text != '_-NONE') {
    while (list($numl, $line) = each($lines)) {
        // centralize the text horizontally
        $offsetx = round(($textareax - strlen($line) * $fontwidth) / 2);
        ImageString($arrow, $font, $x + $offsetx - $fontwidth, $y + $offsety - $fontheight / 2, $line, $black);
        $offsety += $fontheight;
    }
}
ImagePNG($arrow);
ImageDestroy($arrow);
Example #18
0
 protected function DrawArea($do_stacked = FALSE)
 {
     if (!$this->CheckDataType('text-data, data-data')) {
         return FALSE;
     }
     $n = $this->num_data_rows;
     // Number of X values
     if ($n < 2) {
         return TRUE;
     }
     // Require at least 2 rows, for imagefilledpolygon().
     // These arrays store the device X and Y coordinates for all lines:
     $xd = array();
     $yd = array();
     // Make sure each row has the same number of values. Note records_per_group is max(num_recs).
     if ($this->records_per_group != min($this->num_recs)) {
         return $this->PrintError("DrawArea(): Data array must contain the same number" . " of Y values for each X");
     }
     // Calculate the Y value for each X, and store the device
     // coordinates into the xd and yd arrays.
     // For stacked area plots, the Y values accumulate.
     for ($row = 0; $row < $n; $row++) {
         $rec = 1;
         // Skip record #0 (data label)
         if ($this->datatype_implied) {
             // Implied X values?
             $x_now = 0.5 + $row;
         } else {
             $x_now = $this->data[$row][$rec++];
         }
         // Read it, advance record index
         $x_now_pixels = $this->xtr($x_now);
         if ($this->x_data_label_pos != 'none') {
             // Draw X Data labels?
             $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels, $row);
         }
         // Store the X value.
         // There is an artificial Y value at the axis. For 'area' it goes
         // at the end; for stackedarea it goes before the start.
         $xd[$row] = $x_now_pixels;
         $yd[$row] = array();
         if ($do_stacked) {
             $yd[$row][] = $this->x_axis_y_pixels;
         }
         // Store the Y values for this X.
         // All Y values are clipped to the x axis which should be zero but can be moved.
         $y = 0;
         while ($rec < $this->records_per_group) {
             if (is_numeric($y_now = $this->data[$row][$rec++])) {
                 // Treat missing values as 0.
                 $y += abs($y_now);
             }
             $yd[$row][] = $this->ytr(max($this->x_axis_position, $y));
             if (!$do_stacked) {
                 $y = 0;
             }
         }
         if (!$do_stacked) {
             $yd[$row][] = $this->x_axis_y_pixels;
         }
     }
     // Now draw the filled polygons.
     // Note data_columns is the number of Y points (columns excluding label and X), and the
     // number of entries in the yd[] arrays is data_columns+1.
     $prev_row = 0;
     for ($row = 1; $row <= $this->data_columns; $row++) {
         // 1 extra for X axis artificial row
         $pts = array();
         // Previous data set forms top (for area) or bottom (for stackedarea):
         for ($j = 0; $j < $n; $j++) {
             $pts[] = $xd[$j];
             $pts[] = $yd[$j][$prev_row];
         }
         // Current data set forms bottom (for area) or top (for stackedarea):
         for ($j = $n - 1; $j >= 0; $j--) {
             $pts[] = $xd[$j];
             $pts[] = $yd[$j][$row];
         }
         // Draw it:
         ImageFilledPolygon($this->img, $pts, $n * 2, $this->ndx_data_colors[$prev_row]);
         $prev_row = $row;
     }
     return TRUE;
 }
Example #19
0
    /**
     * Output the axis
     * @access private
     */
    function _done()
    {
        parent::_done();

        if (!$this->_font) {
            $this->_font = $GLOBALS['_Image_Graph_font'];
        }

        $value = $this->_getNextLabel();
        
        $lastPosition = false;

        $this->_debug("Enumerating values from $value to ".$this->_getMaximum());
        while ($value <= $this->_getMaximum()) {
            if ((((abs($value) > 0.0001) or ($this->_showLabelZero)) and (($value > $this->_getMinimum()) or ($this->_showLabelMinimum)) and (($value < $this->_getMaximum()) or ($this->_showLabelMaximum))) and ($value>= $this->_getMinimum()) and ($value<= $this->_getMaximum())) {
                $labelPosition = $this->_point($value);

                if (is_object($this->_dataPreProcessor)) {
                    $labelText = $this->_dataPreProcessor->_process($value);
                } else {
                    $labelText = $value;
                }

                $doOutput = false;
                if ($this->_type == IMAGE_GRAPH_AXIS_Y) {
                    $text = new Image_Graph_Text($this->_right - 3, $labelPosition, $labelText, $this->_font);
                    $text->setAlignment(IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_RIGHT);
                    
                    if (($text->_fillBottom() < $lastPosition) or ($lastPosition === false)) {
                        $lastPosition = $text->_fillTop();
                        $doOutput = true;
                    }
                } else {
                    $text = new Image_Graph_Text($labelPosition, $this->_top + 3, $labelText, $this->_font);
                    $text->setAlignment(IMAGE_GRAPH_ALIGN_CENTER_X | IMAGE_GRAPH_ALIGN_TOP);

                    if (($text->_fillLeft() > $lastPosition) or ($lastPosition === false)) {
                        $lastPosition = $text->_fillRight();
                        $doOutput = true;
                    }
                }

                if ($doOutput) {
                    $this->add($text);
                    $text->_done();
                }

                if ($this->_type == IMAGE_GRAPH_AXIS_Y) {
                    ImageLine($this->_canvas(), $this->_right, $labelPosition, $this->_right + 6, $labelPosition, $this->_getLineStyle());
                } else {
                    ImageLine($this->_canvas(), $labelPosition, $this->_top, $labelPosition, $this->_top - 6, $this->_getLineStyle());
                }
            }

            $nextValue = $this->_getNextLabel($value);
/*            if ($minorLabelInterval = $this->_minorLabelInterval()) {
                $minorValue = $value + $minorLabelInterval;
                while (($minorValue < $nextValue) and ($minorValue < $this->_getMaximum() - $minorLabelInterval)) {
                    if ($minorValue >= $this->_getMinimum()) {
                        $position = $this->_point($minorValue);
                        if ($this->_type == IMAGE_GRAPH_AXIS_Y) {
                            ImageLine($this->_canvas(), $this->_right, $position, $this->_right + 3, $position, $this->_getLineStyle());
                        } else {
                            ImageLine($this->_canvas(), $position, $this->_top, $position, $this->_top - 3, $this->_getLineStyle());
                        }
                    }

                    $minorValue += $minorLabelInterval;
                }
            }*/

            $value = $nextValue;
        }

        if ($this->_type == IMAGE_GRAPH_AXIS_Y) {
            ImageLine($this->_canvas(), $this->_right, $this->_top, $this->_right, $this->_bottom, $this->_getLineStyle());
            if ($this->_showArrow) {
                $arrow[] = $this->_right - 5;
                $arrow[] = $this->_top + 8;
                $arrow[] = $this->_right;
                $arrow[] = $this->_top;
                $arrow[] = $this->_right + 5;
                $arrow[] = $this->_top + 8;
                ImageFilledPolygon($this->_canvas(), $arrow, count($arrow) / 2, $this->_getFillStyle());
                ImagePolygon($this->_canvas(), $arrow, count($arrow) / 2, $this->_getLineStyle());
            }
        } else {
            ImageLine($this->_canvas(), $this->_left, $this->_top, $this->_right, $this->_top, $this->_getLineStyle());
            if ($this->_showArrow) {
                $arrow[] = $this->_right - 8;
                $arrow[] = $this->_top + 5;
                $arrow[] = $this->_right;
                $arrow[] = $this->_top;
                $arrow[] = $this->_right - 8;
                $arrow[] = $this->_top - 5;
                ImageFilledPolygon($this->_canvas(), $arrow, count($arrow) / 2, $this->_getFillStyle());
                ImagePolygon($this->_canvas(), $arrow, count($arrow) / 2, $this->_getLineStyle());
            }
        }
    }
Example #20
0
 protected function DrawStackedBars()
 {
     if (!$this->CheckDataType('text-data')) {
         return False;
     }
     // This is the X offset from the bar's label center point to the left side of the bar.
     $x_first_bar = $this->record_bar_width / 2 - $this->bar_adjust_gap;
     // Copy shading value to local variable
     $shade = $this->shading;
     // Determine if any data labels are on:
     if ($this->y_data_label_pos == 'plotin') {
         $data_labels_above = True;
         $data_labels_within = False;
     } elseif ($this->y_data_label_pos == 'plotstack') {
         $data_labels_above = True;
         $data_labels_within = True;
         // Get the text label height, plus a little bit, so we can omit labels in
         // segments that are too short for the label to fit.
         $data_labels_min_height = $this->fonts['y_label']['height'] + 2;
     } else {
         $data_labels_above = False;
         $data_labels_within = False;
     }
     if ($data_labels_above || $data_labels_within) {
         $data_label_y_offset = -5 - $shade;
     }
     for ($row = 0; $row < $this->num_data_rows; $row++) {
         $record = 1;
         // Skip record #0 (data label)
         $x_now_pixels = $this->xtr(0.5 + $row);
         // Place text-data at X = 0.5, 1.5, 2.5, etc...
         if ($this->x_data_label_pos != 'none') {
             // Draw X Data labels?
             $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels);
         }
         // Lower left and lower right X of the bars in this stack:
         $x1 = $x_now_pixels - $x_first_bar;
         $x2 = $x1 + $this->actual_bar_width;
         // Draw the bar segments in this stack. The first segment is drawn from the X axis to Y1.
         // Each additional segment is drawn from the top of the previous segment to the new
         // cumulative Y. Skip over any segment of 0 size or part below the X axis.
         $wy1 = 0;
         // World coordinates Y1, upper value
         $wy2 = $this->x_axis_position;
         // World coordinates Y2, lower value
         for ($idx = 0; $record < $this->num_recs[$row]; $record++, $idx++) {
             // Skip missing Y values, and ignore Y=0 values.
             if (is_numeric($this->data[$row][$record]) && ($this_y = abs($this->data[$row][$record])) > 0) {
                 $wy1 += $this_y;
                 // Accumulate Y value in world coordinates - top of current segment.
                 // Draw nothing if top of segment is below X axis.
                 // Bottom (wy2) will not go below X axis, so we will get a partial
                 // segment from X axis up if the segment would cross the X axis.
                 if ($wy1 > $this->x_axis_position) {
                     $y1 = $this->ytr($wy1);
                     $y2 = $this->ytr($wy2);
                     // Draw the bar
                     ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $this->ndx_data_colors[$idx]);
                     if ($shade > 0) {
                         // Draw the shade?
                         ImageFilledPolygon($this->img, array($x1, $y1, $x1 + $shade, $y1 - $shade, $x2 + $shade, $y1 - $shade, $x2 + $shade, $y2 - $shade, $x2, $y2, $x2, $y1), 6, $this->ndx_data_dark_colors[$idx]);
                     } else {
                         // Or draw a border?
                         ImageRectangle($this->img, $x1, $y1, $x2, $y2, $this->ndx_data_border_colors[$idx]);
                     }
                     // Draw optional data label for this bar segment just below the line.
                     // Text value is the current Y, but position is the cumulative Y.
                     // Skip the label if the segment is too short for the label to fit.
                     if ($data_labels_within && $y2 - $y1 >= $data_labels_min_height) {
                         $this->DrawDataLabel($this->fonts['y_label'], $this->y_data_label_angle, $row + 0.5, $wy1, $this->ndx_title_color, $this_y, 'center', 'top', 0, 3);
                     }
                 }
                 // Make the top of this segment become the bottom of the next segment, but not if
                 // it is still below the X axis.
                 $wy2 = max($this->x_axis_position, $wy1);
             }
         }
         // end for
         // Draw optional data label above the bar with the total value.
         // Value is wy1, but position is wy2. This only makes a difference when
         // the stacked bar ends completely below the X axis. Then we see the actual
         // cumulative value (wy1), positioned above the axis, with no bar at all.
         if ($data_labels_above) {
             $this->DrawDataLabel($this->fonts['y_label'], $this->y_data_label_angle, $row + 0.5, $wy2, $this->ndx_title_color, $wy1, 'center', 'bottom', 0, $data_label_y_offset);
         }
     }
     // end for
     return TRUE;
 }
Example #21
0
$image = ImageCreate(1920, 1080);
# Make an image
$blue = ImageColorAllocate($image, 0, 0, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
for ($index = 0; $index < 255; $index++) {
    $color[] = ImageColorAllocate($image, rand(), rand(), 100);
}
$resultCode = mysqli_query($db, 'select Code from nations');
while ($nations = mysqli_fetch_array($resultCode)) {
    // if($nations == 'us'){
    //print $nations.'<br>';
    $resultPoly = mysqli_query($db, "select Polygon from polygons where Code='" . $nations['Code'] . "'");
    while ($poly = mysqli_fetch_array($resultPoly)) {
        unset($points);
        unset($x);
        unset($y);
        $resultLong = mysqli_query($db, "select * from edges where Polygon='" . $poly['Polygon'] . "'");
        while ($row = mysqli_fetch_array($resultLong)) {
            $x[] = (180 + $row['Longitude']) / 360 * 1920;
            $y[] = (90 - $row['Latitude']) / 180 * 1080;
            $points[] = (180 + $row['Longitude']) / 360 * 1920;
            $points[] = (90 - $row['Latitude']) / 180 * 1080;
        }
        ImageFilledPolygon($image, $points, $resultLong->num_rows, $color[rand(0, 254)]);
        for ($i = 0; $i < count($x) - 1; $i += 1) {
            ImageLine($image, $x[$i], $y[$i], $x[$i + 1], $y[$i + 1], $black);
        }
        imagesetthickness($image, 2);
    }
}
ImagePNG($image);
 function DrawAreaSeries()
 {
     //Set first and last datapoints of area
     $i = 0;
     while ($i < $this->records_per_group) {
         $posarr[$i][] = $this->xtr(0.5);
         //x initial
         $posarr[$i][] = $this->ytr($this->x_axis_position);
         //y initial
         $i++;
     }
     reset($this->data_values);
     while (list($j, $row) = each($this->data_values)) {
         $color_index = 0;
         //foreach ($row as $v)
         while (list($k, $v) = each($row)) {
             if ($k == 0) {
                 //Draw Data Labels
                 $xlab = SubStr($v, 0, $this->x_datalabel_maxlength);
                 $this->DrawXDataLabel($xlab, $this->xtr($j + 0.5));
             } else {
                 // Create Array of points for later
                 $x = round($this->xtr($j + 0.5));
                 $y = round($this->ytr($v));
                 $posarr[$color_index][] = $x;
                 $posarr[$color_index][] = $y;
                 $color_index++;
             }
         }
     }
     //Final_points
     for ($i = 0; $i < $this->records_per_group; $i++) {
         $posarr[$i][] = round($this->xtr($this->max_x + 0.5));
         //x final
         $posarr[$i][] = $this->ytr($this->x_axis_position);
         //y final
     }
     $color_index = 0;
     //foreach($posarr as $row)
     reset($posarr);
     while (list(, $row) = each($posarr)) {
         if ($color_index >= count($this->ndx_data_color)) {
             $color_index = 0;
         }
         $barcol = $this->ndx_data_color[$color_index];
         //echo "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11],$row[12], $barcol<br />";
         ImageFilledPolygon($this->img, $row, count($row) / 2, $barcol);
         $color_index++;
     }
 }
Example #23
0
    /**
     * Image_Graph_GradientFill [Constructor]
     * @param int $direction The direction of the gradient
     * @param int $startColor The RGB value of the starting color
     * @param int $endColor The RGB value of the ending color
     * @param int $count The number of steps to be made between the 2 colors (the more the more smooth, but more ressources are required). 100 is default.
     * @param int $alpha The alpha-blend (not supported yet)
     */
    function &Image_Graph_Fill_Gradient($direction, $startColor, $endColor, $count = 100, $alpha = 0)
    {
        parent::__construct();
        $this->_direction = $direction;
        $this->_startColor['RED'] = ($startColor >> 16) & 0xff;
        $this->_startColor['GREEN'] = ($startColor >> 8) & 0xff;
        $this->_startColor['BLUE'] = $startColor & 0xff;

        $this->_endColor['RED'] = ($endColor >> 16) & 0xff;
        $this->_endColor['GREEN'] = ($endColor >> 8) & 0xff;
        $this->_endColor['BLUE'] = $endColor & 0xff;

        $this->_count = $count;

        switch ($this->_direction) {
            case IMAGE_GRAPH_GRAD_HORIZONTAL :
                $width = $this->_count;
                $height = 1;
                break;

            case IMAGE_GRAPH_GRAD_VERTICAL :
                $width = 1;
                $height = $this->_count;
                break;

            case IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED :
                $width = 2 * $this->_count;
                $height = 1;
                break;

            case IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED :
                $width = 1;
                $height = 2 * $this->_count;
                break;

            case IMAGE_GRAPH_GRAD_DIAGONALLY_TL_BR :
            case IMAGE_GRAPH_GRAD_DIAGONALLY_BL_TR :
                $width = $height = $this->_count / 2;
                break;

            case IMAGE_GRAPH_GRAD_RADIAL :
                $width = $height = sqrt($this->_count * $this->_count / 2);
                break;
        }

        if (isset($GLOBALS['_Image_Graph_gd2'])) {
            $this->_image = ImageCreateTrueColor($width, $height);
        } else {
            $this->_image = ImageCreate($width, $height);
        }

        $redIncrement = ($this->_endColor['RED'] - $this->_startColor['RED']) / $this->_count;
        $greenIncrement = ($this->_endColor['GREEN'] - $this->_startColor['GREEN']) / $this->_count;
        $blueIncrement = ($this->_endColor['BLUE'] - $this->_startColor['BLUE']) / $this->_count;

        for ($i = 0; $i <= $this->_count; $i ++) {
            if ($i == 0) {
                $red = $this->_startColor['RED'];
                $green = $this->_startColor['GREEN'];
                $blue = $this->_startColor['BLUE'];
            } else {
                $red = round(($redIncrement * $i) + $redIncrement + $this->_startColor['RED']);
                $green = round(($greenIncrement * $i) + $greenIncrement + $this->_startColor['GREEN']);
                $blue = round(($blueIncrement * $i) + $blueIncrement + $this->_startColor['BLUE']);
            }
            $color = ImageColorAllocate($this->_image, $red, $green, $blue);

            switch ($this->_direction) {
                case IMAGE_GRAPH_GRAD_HORIZONTAL :
                    ImageSetPixel($this->_image, $i, 0, $color);
                    break;

                case IMAGE_GRAPH_GRAD_VERTICAL :
                    ImageSetPixel($this->_image, 0, $height - $i, $color);
                    break;

                case IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED :
                    ImageSetPixel($this->_image, $i, 0, $color);
                    ImageSetPixel($this->_image, $width - $i, 0, $color);
                    break;

                case IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED :
                    ImageSetPixel($this->_image, 0, $i, $color);
                    ImageSetPixel($this->_image, 0, $height - $i, $color);
                    break;

                case IMAGE_GRAPH_GRAD_DIAGONALLY_TL_BR :
                    if ($i > $width) {
                        $polygon = array ($width, $i - $width, $width, $height, $i - $width, $height);
                    } else {
                        $polygon = array (0, $i, 0, $height, $width, $height, $width, 0, $i, 0);
                    }
                    ImageFilledPolygon($this->_image, $polygon, count($polygon) / 2, $color);
                    break;

                case IMAGE_GRAPH_GRAD_DIAGONALLY_BL_TR :
                    if ($i > $height) {
                        $polygon = array ($i - $height, 0, $width, 0, $width, 2 * $height - $i);
                    } else {
                        $polygon = array (0, $height - $i, 0, 0, $width, 0, $width, $height, $i, $height);
                    }
                    ImageFilledPolygon($this->_image, $polygon, count($polygon) / 2, $color);
                    break;

                case IMAGE_GRAPH_GRAD_RADIAL :
                    if (($GLOBALS['_Image_Graph_gd2']) and ($i < $this->_count)) {
                        ImageFilledEllipse($this->_image, $width / 2, $height / 2, $this->_count - $i, $this->_count - $i, $color);
                    }
                    break;
            }
        }
    }
Example #24
0
 function DrawStackedBars()
 {
     if ($this->data_type != 'text-data') {
         $this->DrawError('DrawStackedBars(): Bar plots must be text-data: use SetDataType("text-data")');
         return FALSE;
     }
     // This is the X offset from the bar's label center point to the left side of the bar.
     $x_first_bar = $this->record_bar_width / 2 - $this->bar_adjust_gap;
     for ($row = 0; $row < $this->num_data_rows; $row++) {
         $record = 1;
         // Skip record #0 (data label)
         $x_now_pixels = $this->xtr(0.5 + $row);
         // Place text-data at X = 0.5, 1.5, 2.5, etc...
         if ($this->x_data_label_pos != 'none') {
             // Draw X Data labels?
             $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels);
         }
         // Lower left and lower right X of the bars in this group:
         $x1 = $x_now_pixels - $x_first_bar;
         $x2 = $x1 + $this->actual_bar_width;
         // Draw the bars
         $oldv = 0;
         for ($idx = 0; $record < $this->num_recs[$row]; $record++, $idx++) {
             if (is_numeric($this->data[$row][$record])) {
                 // Allow for missing Y data
                 $y1 = $this->ytr(abs($this->data[$row][$record]) + $oldv);
                 $y2 = $this->ytr($this->x_axis_position + $oldv);
                 $oldv += abs($this->data[$row][$record]);
                 // Draw the bar
                 ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $this->ndx_data_colors[$idx]);
                 if ($this->shading) {
                     // Draw the shade?
                     ImageFilledPolygon($this->img, array($x1, $y1, $x1 + $this->shading, $y1 - $this->shading, $x2 + $this->shading, $y1 - $this->shading, $x2 + $this->shading, $y2 - $this->shading, $x2, $y2, $x2, $y1), 6, $this->ndx_data_dark_colors[$idx]);
                 } else {
                     ImageRectangle($this->img, $x1, $y1, $x2, $y2, $this->ndx_data_border_colors[$idx]);
                 }
             }
         }
         // end for
     }
     // end for
 }
Example #25
0
<?php

$points = array($x1, $y1, $x2, $y2, $x3, $y3);
ImageFilledPolygon($image, $points, count($points) / 2, $color);