#contents

[[PHPlot Information:http://tec-tech.org/phplot5/]]

*PHPlot Tips [#rd85df66]

:&size(20){''CAUTION'' };|
&size(20){''The licenece of PHPlot is LGPL. '' };~
&size(20){''So the patches on this page are distributed ''};~
&size(20){''also under LGPL Licence.''};~
&size(20){''  merlin<merlin AT tec-tech.org>''};~


** Change Pie-Chart start angle and drawing direction. [#r188d86d]

Two public variables are added.

+ $pie_startpoint : a start angle of pie chart ; unit: degree ; clockwise angle. 
+ $pie_direction   : pie drawing direction ; 0:counterclockwise 1:clockwise 


// # phplot-5.1.2 pie-chart modification
// # phplot512-MD01_01 2010/06/30 merlin<merlin@tec-tech.org>
 # 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 [#j45ff13f]
+ [[(k3m の日記)PHPlotの円グラフの描き方を修正(2009年04月09日):http://slashdot.jp/~k3m/journal/472567]]
+ [[(plasmasphere.net)PHPlotで円グラフの開始地点を変更する(2006年11月02日):http://www.plasmasphere.net/diary/article281.html]]

** Automatic color setting of pie-chart label[#ic69de09]
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 [#pcbafb7e]

 <?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~
&ref(./pie_mode0-2.png,50%,"default");
&ref(./pie_mode0.png,50%,"default");

mode 1 : Complementary color mode~
&ref(./pie_mode1-2.png,50%,"Complementary color mod");
&ref(./pie_mode1.png,50%,"Complementary color mod");

mode 2 : Automatic black/white mode~
&ref(./pie_mode2-2.png,50%,"Automatic black/white mode");
&ref(./pie_mode2.png,50%,"Automatic black/white mode");

*** reference [#w1185ab2]
-[[(W3C)Techniques For Accessibility Evaluation And Repair Tools - W3C Working Draft, 26 April 2000:http://www.w3.org/TR/AERT]]
-[[(Web Kanzaki)色の組み合わせをチェックしてみる:http://www.kanzaki.com/docs/html/color-check#calc-contrast]]

*** Dynamic Examples (5.5.0) [#lc47f221]
|tilted|flat|h
|[[Mode0:http://tec-tech.org/phplot5/example550/piechartex01.php]]|[[Mode0:http://tec-tech.org/phplot5/example550/piechartex00.php]]|
|[[Mode1:http://tec-tech.org/phplot5/example550/piechartex11.php]]|[[Mode1:http://tec-tech.org/phplot5/example550/piechartex10.php]]|
|[[Mode2:http://tec-tech.org/phplot5/example550/piechartex21.php]]|[[Mode2:http://tec-tech.org/phplot5/example550/piechartex20.php]]|

 
*** patches [#h36e27df]
-&ref(./piechart_540.patch,patch to 5.4.0);
-&ref(./piechart_550.patch,patch to 5.5.0);

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS