ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilChartGrid.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.ilChart.php";
5 
13 class ilChartGrid extends ilChart
14 {
15  protected $ticks; // [array]
16  protected $integer_axis; // [array]
17 
18  const DATA_LINES = 1;
19  const DATA_BARS = 2;
20  const DATA_POINTS = 3;
21 
22  protected function __construct($a_id)
23  {
24  parent::__construct($a_id);
25 
26  $this->setXAxisToInteger(false);
27  $this->setYAxisToInteger(false);
28  }
29 
30  public function getDataInstance($a_type = null)
31  {
32  switch ($a_type) {
33  case self::DATA_BARS:
34  include_once "Services/Chart/classes/class.ilChartDataBars.php";
35  return new ilChartDataBars();
36 
37  case self::DATA_POINTS:
38  include_once "Services/Chart/classes/class.ilChartDataPoints.php";
39  return new ilChartDataPoints();
40 
41  default:
42  case self::DATA_LINES:
43  include_once "Services/Chart/classes/class.ilChartDataLines.php";
44  return new ilChartDataLines();
45  }
46  }
47 
48  protected function isValidDataType(ilChartData $a_series)
49  {
50  if ($a_series instanceof ilChartDataLines
51  || $a_series instanceof ilChartDataBars
52  || $a_series instanceof ilChartDataPoints) {
53  return true;
54  }
55  return false;
56  }
57 
65  public function setTicks($a_x, $a_y, $a_labeled = false)
66  {
67  $this->ticks = array("x" => $a_x, "y" => $a_y, "labeled" => (bool) $a_labeled);
68  }
69 
75  public function getTicks()
76  {
77  return $this->ticks;
78  }
79 
85  public function setYAxisToInteger($a_status)
86  {
87  $this->integer_axis["y"] = (bool) $a_status;
88  }
89 
95  public function setXAxisToInteger($a_status)
96  {
97  $this->integer_axis["x"] = (bool) $a_status;
98  }
99 
100  public function parseGlobalOptions(stdClass $a_options)
101  {
102  // axis/ticks
103  $tmp = array();
104  $ticks = $this->getTicks();
105  if ($ticks) {
106  $labeled = (bool) $ticks["labeled"];
107  unset($ticks["labeled"]);
108  foreach ($ticks as $axis => $def) {
109  if (is_numeric($def) || is_array($def)) {
110  $a_options->{$axis . "axis"} = new stdClass();
111  }
112  if (is_numeric($def)) {
113  $a_options->{$axis . "axis"}->ticks = $def;
114  } elseif (is_array($def)) {
115  $a_options->{$axis . "axis"}->ticks = array();
116  foreach ($def as $idx => $value) {
117  if ($labeled) {
118  $a_options->{$axis . "axis"}->ticks[] = array($idx, $value);
119  } else {
120  $a_options->{$axis . "axis"}->ticks[] = $value;
121  }
122  }
123  }
124  }
125  }
126 
127  // optional: remove decimals
128  if ($this->integer_axis["x"] && !isset($a_options->xaxis)) {
129  $a_options->{"xaxis"} = new stdClass();
130  $a_options->{"xaxis"}->tickDecimals = 0;
131  }
132  if ($this->integer_axis["y"] && !isset($a_options->yaxis)) {
133  $a_options->{"yaxis"} = new stdClass();
134  $a_options->{"yaxis"}->tickDecimals = 0;
135  }
136  }
137 }
parseGlobalOptions(stdClass $a_options)
Chart data points series.
setXAxisToInteger($a_status)
Restrict x-axis to integer values.
getDataInstance($a_type=null)
Abstract Chart generator base class.
setTicks($a_x, $a_y, $a_labeled=false)
Set ticks.
getTicks()
Get ticks.
$a_type
Definition: workflow.php:92
setYAxisToInteger($a_status)
Restrict y-axis to integer values.
Chart data bars series.
Create styles array
The data for the language used.
isValidDataType(ilChartData $a_series)
Chart data lines series.
Generator for grid-based charts.
$def
Definition: croninfo.php:21
Abstract chart data series base class.
$axis
Definition: showstats.php:64