ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChartDataPie.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "Services/Chart/classes/class.ilChartData.php";
5 
14 {
15  protected $line_width; // [int]
16  protected $label_radius; //mixed
17 
18  protected function getTypeString()
19  {
20  return "pie";
21  }
22 
28  public function setLineWidth($a_value)
29  {
30  $this->line_width = (int)$a_value;
31  }
32 
38  public function getLineWidth()
39  {
40  return $this->line_width;
41  }
42 
51  public function setLabelRadius($a_value)
52  {
53  $this->label_radius = $a_value;
54  }
55 
59  public function getLabelRadius()
60  {
61  return $this->label_radius;
62  }
63 
64  public function addPoint($a_value, $a_caption = null)
65  {
66  $this->data[] = array($a_value, $a_caption);
67  }
68 
69  public function parseData(array &$a_data)
70  {
71  foreach($this->data as $slice)
72  {
73  $series = new stdClass();
74  $series->label = str_replace("\"", "\\\"", $slice[1]);
75 
76  // add percentage to legend
77  if(!$this->getLabelRadius())
78  {
79  $series->label .= " (".$slice[0]."%)";
80  }
81 
82  $series->data = $slice[0];
83 
84  $options = array("show"=>($this->isHidden() ? false : true));
85 
86  $series->{$this->getTypeString()} = $options;
87 
88  $a_data[] = $series;
89  }
90  }
91 
92  public function parseGlobalOptions(stdClass $a_options, ilChart $a_chart)
93  {
94  $a_options->series->pie = new stdClass();
95  $a_options->series->pie->show = true;
96 
97  // fill vs. stroke - trying to normalize data attributes
98 
99  $fill = $this->getFill();
100  $width = $this->getLineWidth();
101  if($fill["fill"] || $width)
102  {
103  $a_options->series->pie->stroke = new stdClass;
104  if($width)
105  {
106  $a_options->series->pie->stroke->width = $width;
107  }
108  if($fill["color"])
109  {
110  $a_options->series->pie->stroke->color = ilChart::renderColor($fill["color"], $fill["fill"]);
111  }
112  }
113 
114  $radius = $this->getLabelRadius();
115  if ($radius)
116  {
117  $a_options->series->pie->label = new stdClass;
118  $a_options->series->pie->label->background = new stdClass;
119  $a_options->series->pie->radius = 1;
120  $a_options->series->pie->label->radius = $radius;
121  $a_options->series->pie->label->show = true;
122  $a_options->series->pie->label->background->color = "#444";
123  $a_options->series->pie->label->background->opacity = 0.8;
124  }
125  }
126 }
127 
128 ?>