PHPlot Information

PHPlot Tips

CAUTION
The licenece of PHPlot is LGPL.
So the patches on this page are distributed
also under LGPL Licence.
merlin<merlin AT tec-tech.org>

Change Pie-Chart start angle and drawing direction.

Two public variables are added.

  1. $pie_startpoint : a start angle of pie chart ; unit: degree ; clockwise angle.
  2. $pie_direction : pie drawing direction ; 0:counterclockwise 1:clockwise
# phplot-5.3.0 pie-chart modification
# phplot530-MD01_01 2010/12/06 merlin<merlin@tec-tech.org>

--- phplot.php.orig     2010-12-06 16:59:48.000000000 +0900
+++ phplot.php  2010-12-06 17:11:19.000000000 +0900
@@ -82,6 +82,9 @@
     public $bar_extra_space = 0.5;         // Number of extra bar's worth of space in a group
     public $bar_width_adjust = 1;          // 1 = bars of normal width, must be > 0

+    public $pie_startpoint = 0;           // Start Angle of Pie Chart 0:Top  Clockwise angle
+    public $pie_direction = 1;             // Pie drawing direction 0: Original(CounterClockwise) 1: Clockwise
+
 // Titles
     public $title_txt = '';

@@ -5139,11 +5142,21 @@
                 $end_angle += $val;
                 // This method of conversion to integer - truncate after reversing it - was
                 // chosen to match the implicit method of PHPlot<=5.0.4 to get the same slices.
-                $arc_start_angle = (int)(360 - $start_angle);
-                $arc_end_angle = (int)(360 - $end_angle);
+
+                if ($this->pie_direction==0){
+                   $arc_start_angle = (int)($this->pie_startpoint-90-$start_angle);
+                   $arc_end_angle = (int)($this->pie_startpoint-90-$end_angle);
+                }else{
+                   $arc_start_angle = (int)($this->pie_startpoint-90+$end_angle);
+                   $arc_end_angle = (int)($this->pie_startpoint-90+$start_angle);
+                }

                 if ($arc_start_angle > $arc_end_angle) {
-                    $mid_angle = deg2rad($end_angle - ($val / 2));
+                    if ($this->pie_direction==0){
+                         $mid_angle = deg2rad(90-$this->pie_startpoint+($end_angle - ($val / 2)));
+                    }else{
+                         $mid_angle = deg2rad(90-$this->pie_startpoint-($end_angle - ($val / 2)));
+                    }

                     // Draw the slice
                     ImageFilledArc($this->img, $xpos, $ypos+$h, $diameter, $diam2,

reference

  1. (k3m の日記)PHPlotの円グラフの描き方を修正(2009年04月09日)
  2. (plasmasphere.net)PHPlotで円グラフの開始地点を変更する(2006年11月02日)

Automatic color setting of pie-chart label

A public variable is added.

$pie_label_color_mode
  • 0:default
  • 1:Complementary color mode
  • 2:Automatic Black/White mode
--- phplot.php.orig     2010-12-06 16:59:48.000000000 +0900
+++ phplot.php  2010-12-06 17:12:06.000000000 +0900
@@ -120,6 +120,7 @@
     // to set it. Use the 'suffix' argument to Set[XY]LabelType instead.
     public $data_units_text = '';              // Units text for 'data' labels (i.e: '、', '$', etc.)

+    public $pie_label_color_mode =2;          // Label color mode 0:default 1:Complementary color mode  2:Automatic Black/White mode
 // Legend
     public $legend = '';                       // An array with legend titles
     // These variables are unset to take default values:
@@ -5163,7 +5164,28 @@
                         $label_x = $xpos + ($diameter * 1.2 * cos($mid_angle)) * $this->label_scale_position;
                         $label_y = $ypos+$h - ($diam2 * 1.2 * sin($mid_angle)) * $this->label_scale_position;

-                        $this->DrawText($this->fonts['generic'], 0, $label_x, $label_y, $this->ndx_grid_color,
+                        // Set label colors of the pie chart
+                        switch($this->pie_label_color_mode){
+                          case 1:       // Complementary color mode
+                            $color_pie = imagecolorsforindex($this->img, $slicecol);
+                            $color_label_pie=imagecolorallocate($this->img,     abs($color_pie[red]-255),
+                                                                                abs($color_pie[green]-255),
+                                                                                abs($color_pie[blue]-255));
+                            break;
+                          case 2:       // Automatic black/white mode
+                            $color_pie = imagecolorsforindex($this->img, $slicecol);
+                            if ($color_pie[red]*299+$color_pie[green]*587+$color_pie[blue]*144>128000)
+                                $color_label_pie=imagecolorallocate($this->img,0,0,0);
+                            else
+                                $color_label_pie=imagecolorallocate($this->img,255,255,255);
+                            break;
+                           default:     // Default color mode
+                            $color_label_pie = $this->ndx_grid_color;
+                            break;
+                        }
+                        if ($this->label_scale_position >= 0.5)  $color_label_pie = $this->ndx_grid_color;
+
+                         $this->DrawText($this->fonts['generic'], 0, $label_x, $label_y, $color_label_pie,
                                         $label_txt, 'center', 'center');
                     }
                 }

Example

<?php
# PHPlot Example: Pie/text-data
require_once 'phplot.php';

$data = array(
  array('', 100, 100, 200, 100,100,100,100),
  array('', 150, 100, 150, 100,10,100,100),
); 

$plot = new PHPlot(800,600);
$plot->SetImageBorderType('raised');
$plot->SetDataType('text-data');
$plot->SetDataValues($data);
$plot->SetPlotType('pie');
$plot->pie_startpoint=0;
$plot->pie_label_color_mode=0;
$plot->SetShading(100);
$plot->SetUseTTF('True');
$plot->SetFont('generic','benjamingothic.ttf',20);
$plot->SetLabelScalePosition(0.25);
$plot->DrawGraph();
?>

mode 0 : Default mode
default default

mode 1 : Complementary color mode
Complementary color mod Complementary color mod

mode 2 : Automatic black/white mode
Automatic black/white mode Automatic black/white mode

reference

Dynamic Examples (5.5.0)

patches


添付ファイル: filepiechart_550.patch 819件 [詳細] filepiechart_540.patch 712件 [詳細] filepie_mode2-2.png 829件 [詳細] filepie_mode1-2.png 873件 [詳細] filepie_mode0-2.png 883件 [詳細] filepie_mode2.png 881件 [詳細] filepie_mode1.png 1039件 [詳細] filepie_mode0.png 918件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2011-08-02 (火) 18:04:01 (2689d)