ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilChart Class Reference

Chart generator. More...

+ Collaboration diagram for ilChart:

Public Member Functions

 __construct ($a_id, $a_width=500, $a_height=500, $a_renderer="flot")
 Constructor.
 setRenderer ($a_value)
 Set renderer.
 getAllRenderers ()
 Get all available renderers.
 setSize ($a_x, $a_y)
 Set chart size.
 addData (ilChartData $a_series, $a_idx=null)
 Add data series.
 setLegend (ilChartLegend $a_legend)
 Set chart legend.
 setShadow ($a_value)
 Set shadow.
 getShadow ()
 Get shadow.
 setColors ($a_values)
 Set colors.
 getColors ()
 Get colors.
 setTicks ($a_x, $a_y, $a_labeled=false)
 Set ticks.
 getTicks ()
 Get ticks.
 getHTML ()
 Render (flot only currently)
 setYAxisToInteger ($a_status)
 setXAxisToInteger ($a_status)

Static Public Member Functions

static isValidColor ($a_value)
 Validate html color code.

Static Protected Member Functions

static renderColor ($a_value, $a_opacity=1)
 Render html color code.

Protected Attributes

 $id
 $renderer
 $width
 $height
 $data
 $legend
 $shadow
 $colors
 $ticks
 $integer_axis

Detailed Description

Chart generator.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 14 of file class.ilChart.php.

Constructor & Destructor Documentation

ilChart::__construct (   $a_id,
  $a_width = 500,
  $a_height = 500,
  $a_renderer = "flot" 
)

Constructor.

@param string $a_id
@param int $a_width
@param int $a_height
Parameters
string$a_renderer

Definition at line 35 of file class.ilChart.php.

References setRenderer(), setShadow(), setSize(), setXAxisToInteger(), and setYAxisToInteger().

{
$this->id = $a_id;
$this->data = array();
$this->setXAxisToInteger(false);
$this->setYAxisToInteger(false);
$this->setSize($a_width, $a_height);
$this->setRenderer($a_renderer);
$this->setShadow(2);
}

+ Here is the call graph for this function:

Member Function Documentation

ilChart::addData ( ilChartData  $a_series,
  $a_idx = null 
)

Add data series.

Parameters
ilChartData$a_series
mixed$a_id
Returns
mixed index

Definition at line 88 of file class.ilChart.php.

References $data.

{
if($a_idx === null)
{
$a_idx = sizeof($this->data);
}
$this->data[$a_idx] = $a_series;
return $a_idx;
}
ilChart::getAllRenderers ( )

Get all available renderers.

Returns
array

Definition at line 64 of file class.ilChart.php.

Referenced by setRenderer().

{
return array("flot");
}

+ Here is the caller graph for this function:

ilChart::getColors ( )

Get colors.

Returns
array

Definition at line 193 of file class.ilChart.php.

References $colors.

Referenced by getHTML().

{
return $this->colors;
}

+ Here is the caller graph for this function:

ilChart::getHTML ( )

Render (flot only currently)

Definition at line 223 of file class.ilChart.php.

References $colors, $legend, $ticks, $tpl, $width, getColors(), getShadow(), getTicks(), iljQueryUtil\initjQuery(), and renderColor().

{
global $tpl;
include_once "Services/jQuery/classes/class.iljQueryUtil.php";
// $tpl->addJavascript("Services/Chart/js/flot/jquery.min.js");
$tpl->addJavascript("Services/Chart/js/flot/excanvas.min.js");
$tpl->addJavascript("Services/Chart/js/flot/jquery.flot.min.js");
$tpl->addJavascript("Services/Chart/js/flot/jquery.flot.pie.js");
$chart = new ilTemplate("tpl.grid.html", true, true, "Services/Chart");
$chart->setVariable("ID", $this->id);
$chart->setVariable("WIDTH", $this->width);
$chart->setVariable("HEIGHT", $this->height);
$last = array_keys($this->data);
$last = array_pop($last);
$has_pie = false;
foreach($this->data as $idx => $series)
{
$chart->setCurrentBlock("series");
$chart->setVariable("SERIES_LABEL", str_replace("\"", "\\\"", $series->getLabel()));
$chart->setVariable("SERIES_TYPE", $series->getType());
$type = $series->getType();
$points = array();
if($type != "pie")
{
foreach($series->getData() as $point)
{
$points[] = "[".$point[0].",".$point[1]."]";
}
$chart->setVariable("SERIES_DATA", "[ ".implode(",", $points)." ]");
}
else
{
$has_pie = true;
$chart->setVariable("SERIES_DATA", array_pop($series->getData()));
}
if($idx != $last)
{
$chart->setVariable("SERIES_END", ",");
}
$options = array("show: ".($series->isHidden() ? "false" : "true"));
if($type != "points")
{
$width = $series->getLineWidth();
if($width !== null)
{
$options[] = "lineWidth:".$width;
}
if($type == "bars")
{
$bar_options = $series->getBarOptions();
if($bar_options["width"] !== null)
{
$options[] = "barWidth:".str_replace(",", ".", $bar_options["width"]);
$options[] = "align: \"".$bar_options["align"]."\"";
if($bar_options["horizontal"])
{
$options[] = "horizontal: true";
}
}
}
else if($type == "lines")
{
if($series->getLineSteps())
{
$options[] = "steps: true";
}
}
}
else
{
$radius = $series->getPointRadius();
if($radius !== null)
{
$options[] = "radius:".$radius;
}
}
$fill = $series->getFill();
if($fill["fill"])
{
$options[] = "fill: ".$fill["fill"];
if($fill["color"])
{
$options[] = "fillColor: ".self::renderColor($fill["color"], $fill["fill"]);
}
}
$chart->setVariable("SERIES_OPTIONS", implode(", ", $options));
$chart->parseCurrentBlock();
}
// global options
$chart->setVariable("SHADOW", (int)$this->getShadow());
$chart->setVariable("IS_PIE", ($has_pie ? "true" : "false"));
$colors = $this->getColors();
if($colors)
{
$tmp = array();
foreach($colors as $color)
{
$tmp[] = self::renderColor($color);
}
}
if(sizeof($tmp))
{
$chart->setVariable("COLORS", implode(",", $tmp));
}
// legend
if(!$this->legend)
{
$chart->setVariable("LEGEND", "show: false");
}
else
{
$margin = $this->legend->getMargin();
$legend = array();
$legend[] = "show: true";
$legend[] = "noColumns: ".$this->legend->getColumns();
$legend[] = "position: \"".$this->legend->getPosition()."\"";
$legend[] = "margin: [".$margin["x"].", ".$margin["y"]."]";
$legend[] = "backgroundColor: ".self::renderColor($this->legend->getBackground());
$legend[] = "backgroundOpacity: ".str_replace(",",".",$this->legend->getOpacity());
$legend[] = "labelBoxBorderColor: ".self::renderColor($this->legend->getLabelBorder());
$chart->setVariable("LEGEND", implode(", ", $legend));
}
// axis/ticks
$tmp = array();
$ticks = $this->getTicks();
if($ticks)
{
foreach($ticks as $axis => $def)
{
if(is_numeric($def))
{
$tmp[$axis] = $axis."axis: { ticks: ".$def." }";
}
else if(is_array($def))
{
$ttmp = array();
foreach($def as $idx => $value)
{
if($ticks["labeled"])
{
$ttmp[] = "[".$idx.", \"".$value."\"]";
}
else
{
$ttmp[] = $value;
}
}
$tmp[$axis] = $axis."axis: { ticks: [".implode(", ", $ttmp)."] }";
}
}
}
// optional: remove decimals
if(!isset($tmp["x"]) && $this->integer_axis["x"])
{
$tmp["x"] = "xaxis: { tickDecimals: 0 }";
}
if(!isset($tmp["y"]) && $this->integer_axis["y"])
{
$tmp["y"] = "yaxis: { tickDecimals: 0 }";
}
if(sizeof($tmp))
{
$chart->setVariable("AXIS", ",".implode(", ", $tmp));
}
return $chart->get();
}

+ Here is the call graph for this function:

ilChart::getShadow ( )

Get shadow.

Returns
int

Definition at line 167 of file class.ilChart.php.

References $shadow.

Referenced by getHTML().

{
return $this->shadow;
}

+ Here is the caller graph for this function:

ilChart::getTicks ( )

Get ticks.

Returns
array (x, y)

Definition at line 215 of file class.ilChart.php.

References $ticks.

Referenced by getHTML().

{
return $this->ticks;
}

+ Here is the caller graph for this function:

static ilChart::isValidColor (   $a_value)
static

Validate html color code.

Parameters
string$a_value
Returns
bool

Definition at line 114 of file class.ilChart.php.

Referenced by ilChartLegend\setBackground(), ilChartData\setFill(), and ilChartLegend\setLabelBorder().

{
if(preg_match("/^#[0-9a-f]{3}$/i", $a_value, $match))
{
return true;
}
else if(preg_match("/^#[0-9a-f]{6}$/i", $a_value, $match))
{
return true;
}
}

+ Here is the caller graph for this function:

static ilChart::renderColor (   $a_value,
  $a_opacity = 1 
)
staticprotected

Render html color code.

Parameters
string$a_value
float$a_opacity
Returns
string

Definition at line 133 of file class.ilChart.php.

Referenced by getHTML().

{
if(self::isValidColor($a_value))
{
if(strlen($a_value) == 4)
{
return "\"rgba(".hexdec($a_value[1].$a_value[1]).", ".
hexdec($a_value[2].$a_value[2]).", ".
hexdec($a_value[3].$a_value[3]).", ".$a_opacity.")\"";
}
else
{
return "\"rgba(".hexdec($a_value[1].$a_value[2]).", ".
hexdec($a_value[3].$a_value[4]).", ".
hexdec($a_value[5].$a_value[6]).", ".$a_opacity.")\"";
}
}
}

+ Here is the caller graph for this function:

ilChart::setColors (   $a_values)

Set colors.

Parameters
array$a_values

Definition at line 177 of file class.ilChart.php.

{
foreach($a_values as $color)
{
if(self::isValidColor($color))
{
$this->colors[] = $color;
}
}
}
ilChart::setLegend ( ilChartLegend  $a_legend)

Set chart legend.

Parameters
ilChartLegend$a_legend

Definition at line 103 of file class.ilChart.php.

{
$this->legend = $a_legend;
}
ilChart::setRenderer (   $a_value)

Set renderer.

Parameters
string$a_value

Definition at line 51 of file class.ilChart.php.

References getAllRenderers().

Referenced by __construct().

{
if(in_array((string)$a_value, $this->getAllRenderers()))
{
$this->renderer = (string)$a_value;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilChart::setShadow (   $a_value)

Set shadow.

Parameters
int$a_value

Definition at line 157 of file class.ilChart.php.

Referenced by __construct().

{
$this->shadow = (int)$a_value;
}

+ Here is the caller graph for this function:

ilChart::setSize (   $a_x,
  $a_y 
)

Set chart size.

Parameters
int$a_x
int$a_y

Definition at line 75 of file class.ilChart.php.

Referenced by __construct().

{
$this->width = (int)$a_x;
$this->height = (int)$a_y;
}

+ Here is the caller graph for this function:

ilChart::setTicks (   $a_x,
  $a_y,
  $a_labeled = false 
)

Set ticks.

Parameters
int | array$a_x
int | array$a_y
bool$a_labeled

Definition at line 205 of file class.ilChart.php.

{
$this->ticks = array("x" => $a_x, "y" => $a_y, "labeled" => (bool)$a_labeled);
}
ilChart::setXAxisToInteger (   $a_status)

Definition at line 414 of file class.ilChart.php.

Referenced by __construct().

{
$this->integer_axis["x"] = (bool)$a_status;
}

+ Here is the caller graph for this function:

ilChart::setYAxisToInteger (   $a_status)

Definition at line 409 of file class.ilChart.php.

Referenced by __construct().

{
$this->integer_axis["y"] = (bool)$a_status;
}

+ Here is the caller graph for this function:

Field Documentation

ilChart::$colors
protected

Definition at line 23 of file class.ilChart.php.

Referenced by getColors(), and getHTML().

ilChart::$data
protected

Definition at line 20 of file class.ilChart.php.

Referenced by addData().

ilChart::$height
protected

Definition at line 19 of file class.ilChart.php.

ilChart::$id
protected

Definition at line 16 of file class.ilChart.php.

ilChart::$integer_axis
protected

Definition at line 25 of file class.ilChart.php.

ilChart::$legend
protected

Definition at line 21 of file class.ilChart.php.

Referenced by getHTML().

ilChart::$renderer
protected

Definition at line 17 of file class.ilChart.php.

ilChart::$shadow
protected

Definition at line 22 of file class.ilChart.php.

Referenced by getShadow().

ilChart::$ticks
protected

Definition at line 24 of file class.ilChart.php.

Referenced by getHTML(), and getTicks().

ilChart::$width
protected

Definition at line 18 of file class.ilChart.php.

Referenced by getHTML().


The documentation for this class was generated from the following file: