ILIAS  Release_4_4_x_branch Revision 61816
 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.
 setLegLabels ($a_val)
 Set leg labels.
 getLegLabels ()
 Get leg labels.
 getHTML ()
 Render (flot only currently)
 setYAxisToInteger ($a_status)
 setXAxisToInteger ($a_status)
 setYAxisMax ($a_val)
 Set y axis max value.
 getYAxisMax ()
 Get y axis max value.

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
 $leg_labels = array()
 $y_max = 0

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 37 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 90 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 66 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 195 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 245 of file class.ilChart.php.

References $colors, $legend, $options, $ret, $ticks, $tpl, $width, getColors(), getLegLabels(), getShadow(), getTicks(), getYAxisMax(), iljQueryUtil\initjQuery(), renderColor(), and ilUtil\shortenText().

{
global $tpl;
include_once "Services/jQuery/classes/class.iljQueryUtil.php";
$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");
$tpl->addJavascript("Services/Chart/js/flot/jquery.flot.highlighter.js");
$tpl->addJavascript("Services/Chart/js/flot/jquery.flot.spider.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;
$has_spider = false;
foreach($this->data as $idx => $series)
{
$fill = $series->getFill();
if ($series->getType() == "spider")
{
$has_spider = true;
if ($fill["color"] != "")
{
$chart->setCurrentBlock("series_property");
$chart->setVariable("SPROP", "color");
$chart->setVariable("SPROP_VAL", self::renderColor($fill["color"] , "0.5"));
$chart->parseCurrentBlock();
}
}
$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;
}
}
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();
}
if ($has_spider)
{
$chart->setCurrentBlock("spider");
$lab_strings = array();
$max_str_len = 0;
foreach ($this->getLegLabels() as $l)
{
$l = ilUtil::shortenText ($l, 80, true);
$lab_strings[] = "{label: \"".$l."\"}";
$max_str_len = max($max_str_len, strlen($l));
}
$chart->setVariable("LEG_LABELS", implode($lab_strings, ","));
$chart->setVariable("LEG_MAX", $this->getYAxisMax());
switch (count($this->getLegLabels()))
{
case 4:
case 6:
$chart->setVariable("LEG_START_ANGLE", "10");
break;
default:
$chart->setVariable("LEG_START_ANGLE", "0");
break;
}
if ($max_str_len > 60)
{
$chart->setVariable("FONT_SIZE", "10");
}
else if ($max_str_len > 30)
{
$chart->setVariable("FONT_SIZE", "12");
}
else
{
$chart->setVariable("FONT_SIZE", "15");
}
$chart->parseCurrentBlock();
$chart->setCurrentBlock("spider_grid_options");
$chart->setVariable("NR_TICKS", $this->getYAxisMax());
$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));
}
$ret = $chart->get();
//echo htmlentities($ret);
return $ret;
}

+ Here is the call graph for this function:

ilChart::getLegLabels ( )

Get leg labels.

Returns
array leg labels (array of strings)

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

References $leg_labels.

Referenced by getHTML().

{
}

+ Here is the caller graph for this function:

ilChart::getShadow ( )

Get shadow.

Returns
int

Definition at line 169 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 217 of file class.ilChart.php.

References $ticks.

Referenced by getHTML().

{
return $this->ticks;
}

+ Here is the caller graph for this function:

ilChart::getYAxisMax ( )

Get y axis max value.

Returns
float y axis max value

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

References $y_max.

Referenced by getHTML().

{
return $this->y_max;
}

+ 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 116 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 135 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 179 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 105 of file class.ilChart.php.

{
$this->legend = $a_legend;
}
ilChart::setLegLabels (   $a_val)

Set leg labels.

Parameters
array$a_valleg labels (array of strings)

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

{
$this->leg_labels = $a_val;
}
ilChart::setRenderer (   $a_value)

Set renderer.

Parameters
string$a_value

Definition at line 53 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 159 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 77 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 207 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 497 of file class.ilChart.php.

Referenced by __construct().

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

+ Here is the caller graph for this function:

ilChart::setYAxisMax (   $a_val)

Set y axis max value.

Parameters
float$a_valy axis max value

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

{
$this->y_max = $a_val;
}
ilChart::setYAxisToInteger (   $a_status)

Definition at line 492 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::$leg_labels = array()
protected

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

Referenced by getLegLabels().

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().

ilChart::$y_max = 0
protected

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

Referenced by getYAxisMax().


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