ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilChart Class Reference

Abstract Chart generator base class. More...

+ Inheritance diagram for ilChart:
+ Collaboration diagram for ilChart:

Public Member Functions

 getDataInstance ($a_type=null)
 Get data series instance.
 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.
 setColors ($a_values)
 Set colors.
 getColors ()
 Get colors.
 setShadow ($a_value)
 Set shadow.
 getShadow ()
 Get shadow.
 setAutoResize ($a_value)
 Toggle auto-resizing on window resize/redraw.
 parseGlobalOptions (stdClass $a_options)
 Convert (global) properties to flot config.
 getHTML ()
 Render.

Static Public Member Functions

static getInstanceByType ($a_type, $a_id)
 Get type instance.
static isValidColor ($a_value)
 Validate html color code.
static renderColor ($a_value, $a_opacity=1)
 Render html color code.

Data Fields

const TYPE_GRID = 1
const TYPE_PIE = 2
const TYPE_SPIDER = 3

Protected Member Functions

 __construct ($a_id)
 Constructor.
 isValidDataType (ilChartData $a_series)
 Validate data series.
 isValid ()
 Basic validation.
 initJS ()
 Init JS script files.
 addCustomJS ()
 Add type-specific JS script.

Protected Attributes

 $id
 $width
 $height
 $data
 $legend
 $shadow
 $colors
 $auto_resize

Detailed Description

Abstract Chart generator base class.

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 13 of file class.ilChart.php.

Constructor & Destructor Documentation

ilChart::__construct (   $a_id)
protected

Constructor.

Parameters
string$a_id

Reimplemented in ilChartGrid.

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

References setShadow().

{
$this->id = $a_id;
$this->data = array();
$this->setShadow(2);
}

+ Here is the call graph for this function:

Member Function Documentation

ilChart::addCustomJS ( )
protected

Add type-specific JS script.

Reimplemented in ilChartSpider, and ilChartPie.

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

Referenced by initJS().

{
}

+ Here is the caller graph for this function:

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

Add data series.

Parameters
ilChartData$a_series
mixed$a_id
Returns
mixed index

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

References $data, and isValidDataType().

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

+ Here is the call graph for this function:

ilChart::getColors ( )

Get colors.

Returns
array

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

References $colors.

Referenced by getHTML().

{
return $this->colors;
}

+ Here is the caller graph for this function:

ilChart::getDataInstance (   $a_type = null)
abstract

Get data series instance.

Returns
ilChartData

Reimplemented in ilChartGrid, ilChartSpider, and ilChartPie.

ilChart::getHTML ( )

Render.

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

References $colors, $ret, getColors(), getShadow(), initJS(), isValid(), parseGlobalOptions(), and renderColor().

{
if(!$this->isValid())
{
return;
}
$this->initJS();
$chart = new ilTemplate("tpl.grid.html", true, true, "Services/Chart");
$chart->setVariable("ID", $this->id);
if($this->width)
{
if(is_numeric($this->width))
{
$chart->setVariable("WIDTH", "width:".$this->width."px;");
}
else
{
$chart->setVariable("WIDTH", "width:".$this->width.";");
}
}
if($this->height)
{
if(is_numeric($this->height))
{
$chart->setVariable("HEIGHT", "height:".$this->height."px;");
}
else
{
$chart->setVariable("HEIGHT", "height:".$this->height.";");
}
}
// (series) data
$json_series = array();
foreach($this->data as $series)
{
$series->parseData($json_series);
}
$chart->setVariable("SERIES", json_encode($json_series));
// global options
$json_options = new stdClass();
$json_options->series = new stdClass();
$json_options->series->shadowSize = (int)$this->getShadow();
$json_options->series->lines = new stdClass();
$json_options->series->lines->show = false;
foreach($this->data as $series)
{
$series->parseGlobalOptions($json_options, $this);
}
$this->parseGlobalOptions($json_options);
$colors = $this->getColors();
if($colors)
{
$json_options->colors = array();
foreach($colors as $color)
{
$json_options->colors[] = self::renderColor($color);
}
}
// legend
$json_options->legend = new stdClass();
if(!$this->legend)
{
$json_options->legend->show = false;
}
else
{
$this->legend->parseOptions($json_options->legend);
}
$chart->setVariable("OPTIONS", json_encode($json_options));
$ret = $chart->get();
return $ret;
}

+ Here is the call graph for this function:

static ilChart::getInstanceByType (   $a_type,
  $a_id 
)
static

Get type instance.

Parameters
int$a_type
string$a_id
Returns
ilChart

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

Referenced by ilPollBlockGUI\fillRow(), ilSessionStatisticsGUI\getChart(), ilPersonalSkillsGUI\getGapAnalysisHTML(), ilLPObjectStatisticsDailyTableGUI\getGraph(), ilLPObjectStatisticsTableGUI\getGraph(), ilLPObjectStatisticsTypesTableGUI\getGraph(), ilLPObjectStatisticsLPTableGUI\getGraph(), SurveyMetricQuestionGUI\renderChart(), SurveyQuestionGUI\renderChart(), and ilWikiStatGUI\renderGraph().

{
switch($a_type)
{
case self::TYPE_GRID:
include_once "Services/Chart/classes/class.ilChartGrid.php";
return new ilChartGrid($a_id);
case self::TYPE_PIE:
include_once "Services/Chart/classes/class.ilChartPie.php";
return new ilChartPie($a_id);
case self::TYPE_SPIDER:
include_once "Services/Chart/classes/class.ilChartSpider.php";
return new ilChartSpider($a_id);
}
}

+ Here is the caller graph for this function:

ilChart::getShadow ( )

Get shadow.

Returns
int

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

References $shadow.

Referenced by getHTML().

{
return $this->shadow;
}

+ Here is the caller graph for this function:

ilChart::initJS ( )
protected

Init JS script files.

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

References $tpl, addCustomJS(), and iljQueryUtil\initjQuery().

Referenced by getHTML().

{
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");
if((bool)$this->auto_resize)
{
// #13108
$tpl->addJavascript("Services/Chart/js/flot/jquery.flot.resize.min.js");
}
$this->addCustomJS();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilChart::isValid ( )
protected

Basic validation.

Returns
bool

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

Referenced by getHTML().

{
if(sizeof($this->data))
{
return true;
}
return false;
}

+ 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 168 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:

ilChart::isValidDataType ( ilChartData  $a_series)
abstractprotected

Validate data series.

Returns
bool

Reimplemented in ilChartGrid, ilChartSpider, and ilChartPie.

Referenced by addData().

+ Here is the caller graph for this function:

ilChart::parseGlobalOptions ( stdClass  $a_options)

Convert (global) properties to flot config.

Parameters
object$a_options

Reimplemented in ilChartGrid, ilChartSpider, and ilChartPie.

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

Referenced by getHTML().

{
}

+ Here is the caller graph for this function:

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

Render html color code.

Parameters
string$a_value
float$a_opacity
Returns
string

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

Referenced by getHTML(), ilChartDataSpider\parseData(), ilChartData\parseData(), ilChartDataSpider\parseGlobalOptions(), ilChartSpider\parseGlobalOptions(), ilChartDataPie\parseGlobalOptions(), and ilChartLegend\parseOptions().

{
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::setAutoResize (   $a_value)

Toggle auto-resizing on window resize/redraw.

Parameters
bool$a_value

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

{
$this->auto_resize = (bool)$a_value;
}
ilChart::setColors (   $a_values)

Set colors.

Parameters
array$a_values

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

Referenced by ilChartPie\parseGlobalOptions().

{
$this->legend = $a_legend;
}

+ Here is the caller graph for this function:

ilChart::setShadow (   $a_value)

Set shadow.

Parameters
int$a_value

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

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

Field Documentation

ilChart::$auto_resize
protected

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

ilChart::$colors
protected

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

Referenced by getColors(), and getHTML().

ilChart::$data
protected

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

Referenced by addData().

ilChart::$height
protected

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

ilChart::$id
protected

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

ilChart::$legend
protected

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

Referenced by ilChartPie\parseGlobalOptions().

ilChart::$shadow
protected

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

Referenced by getShadow().

ilChart::$width
protected

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

const ilChart::TYPE_PIE = 2

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

const ilChart::TYPE_SPIDER = 3

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

Referenced by ilPersonalSkillsGUI\getGapAnalysisHTML().


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