4 include_once 
"Services/Chart/classes/class.ilChartData.php";
 
    5 include_once 
"Services/Chart/classes/class.ilChartLegend.php";
 
   35         public function __construct($a_id, $a_width = 500, $a_height = 500, $a_renderer = 
"flot")
 
   38                 $this->data = array();
 
   41                 $this->
setSize($a_width, $a_height);
 
   55                         $this->renderer = (string)$a_value;
 
   77                 $this->width = (int)$a_x;
 
   78                 $this->height = (int)$a_y;
 
   94                 $this->data[$a_idx] = $a_series;
 
  105                 $this->legend = $a_legend;
 
  116             if(preg_match(
"/^#[0-9a-f]{3}$/i", $a_value, $match))
 
  120                 else if(preg_match(
"/^#[0-9a-f]{6}$/i", $a_value, $match))
 
  135                 if(self::isValidColor($a_value))
 
  137                         if(strlen($a_value) == 4)
 
  139                                 return "\"rgba(".hexdec($a_value[1].$a_value[1]).
", ".
 
  140                                         hexdec($a_value[2].$a_value[2]).
", ".
 
  141                                         hexdec($a_value[3].$a_value[3]).
", ".$a_opacity.
")\"";
 
  145                                 return "\"rgba(".hexdec($a_value[1].$a_value[2]).
", ".
 
  146                                         hexdec($a_value[3].$a_value[4]).
", ".
 
  147                                         hexdec($a_value[5].$a_value[6]).
", ".$a_opacity.
")\"";
 
  159                 $this->shadow = (int)$a_value;
 
  179                 foreach($a_values as $color)
 
  181                         if(self::isValidColor($color))
 
  183                                 $this->colors[] = $color;
 
  205         public function setTicks($a_x, $a_y, $a_labeled = 
false)
 
  207                 $this->ticks = array(
"x" => $a_x, 
"y" => $a_y, 
"labeled" => (
bool)$a_labeled);
 
  227                 include_once 
"Services/jQuery/classes/class.iljQueryUtil.php";
 
  230                 $tpl->addJavascript(
"Services/Chart/js/flot/excanvas.min.js");
 
  231                 $tpl->addJavascript(
"Services/Chart/js/flot/jquery.flot.min.js");
 
  232                 $tpl->addJavascript(
"Services/Chart/js/flot/jquery.flot.pie.js");
 
  234                 $chart = 
new ilTemplate(
"tpl.grid.html", 
true, 
true, 
"Services/Chart");
 
  235                 $chart->setVariable(
"ID", $this->
id);
 
  236                 $chart->setVariable(
"WIDTH", $this->width);
 
  237                 $chart->setVariable(
"HEIGHT", $this->height);
 
  239                 $last = array_keys($this->data);
 
  240                 $last = array_pop($last);
 
  242                 foreach($this->data as $idx => $series)
 
  244                         $chart->setCurrentBlock(
"series");
 
  245                         $chart->setVariable(
"SERIES_LABEL", str_replace(
"\"", 
"\\\"", $series->getLabel()));
 
  246                         $chart->setVariable(
"SERIES_TYPE", $series->getType());
 
  248                         $type = $series->getType();
 
  253                                 foreach($series->getData() as $point)
 
  255                                         $points[] = 
"[".$point[0].
",".$point[1].
"]";
 
  257                                 $chart->setVariable(
"SERIES_DATA", 
"[ ".implode(
",", $points).
" ]");
 
  262                                 $chart->setVariable(
"SERIES_DATA", array_pop($series->getData()));
 
  266                                 $chart->setVariable(
"SERIES_END", 
",");
 
  269                         $options = array(
"show: ".($series->isHidden() ? 
"false" : 
"true"));
 
  270                         if($type != 
"points")
 
  272                                 $width = $series->getLineWidth();
 
  275                                         $options[] = 
"lineWidth:".$width;
 
  279                                         $bar_options = $series->getBarOptions();
 
  280                                         if($bar_options[
"width"] !== null)
 
  282                                                 $options[] = 
"barWidth:".str_replace(
",", 
".", $bar_options[
"width"]);
 
  283                                                 $options[] = 
"align: \"".$bar_options[
"align"].
"\"";
 
  284                                                 if($bar_options[
"horizontal"])
 
  286                                                         $options[] = 
"horizontal: true";
 
  290                                 else if($type == 
"lines")
 
  292                                         if($series->getLineSteps())
 
  294                                                 $options[] = 
"steps: true";
 
  300                                 $radius = $series->getPointRadius();
 
  303                                         $options[] = 
"radius:".$radius;
 
  306                         $fill = $series->getFill();
 
  309                                 $options[] = 
"fill: ".$fill[
"fill"];
 
  312                                         $options[] = 
"fillColor: ".self::renderColor($fill[
"color"], $fill[
"fill"]);
 
  315                         $chart->setVariable(
"SERIES_OPTIONS", implode(
", ", $options));
 
  317                         $chart->parseCurrentBlock();
 
  323                 $chart->setVariable(
"SHADOW", (
int)$this->
getShadow());
 
  324                 $chart->setVariable(
"IS_PIE", ($has_pie ? 
"true" : 
"false"));
 
  337                         $chart->setVariable(
"COLORS", implode(
",", $tmp));
 
  343                         $chart->setVariable(
"LEGEND", 
"show: false");
 
  347                         $margin = $this->legend->getMargin();
 
  350                         $legend[] = 
"noColumns: ".$this->legend->getColumns();
 
  351                         $legend[] = 
"position: \"".$this->legend->getPosition().
"\"";
 
  352                         $legend[] = 
"margin: [".$margin[
"x"].
", ".$margin[
"y"].
"]";
 
  353                         $legend[] = 
"backgroundColor: ".self::renderColor($this->legend->getBackground());
 
  354                         $legend[] = 
"backgroundOpacity: ".str_replace(
",",
".",$this->legend->getOpacity());
 
  355                         $legend[] = 
"labelBoxBorderColor: ".self::renderColor($this->legend->getLabelBorder());
 
  357                         $chart->setVariable(
"LEGEND", implode(
", ", 
$legend));
 
  365                         foreach(
$ticks as $axis => $def)
 
  369                                         $tmp[$axis] = $axis.
"axis: { ticks: ".$def.
" }";
 
  371                                 else if(is_array($def))
 
  374                                         foreach($def as $idx => $value)
 
  378                                                         $ttmp[] = 
"[".$idx.
", \"".$value.
"\"]";
 
  385                                         $tmp[$axis] = $axis.
"axis: { ticks: [".implode(
", ", $ttmp).
"] }";
 
  391             if(!isset($tmp[
"x"]) && $this->integer_axis[
"x"])
 
  393                         $tmp[
"x"] = 
"xaxis: { tickDecimals: 0 }";
 
  395                 if(!isset($tmp[
"y"]) && $this->integer_axis[
"y"])
 
  397                         $tmp[
"y"] = 
"yaxis: { tickDecimals: 0 }";
 
  402                         $chart->setVariable(
"AXIS", 
",".implode(
", ", $tmp));
 
  405                 return $chart->get();
 
  410                 $this->integer_axis[
"y"] = (bool)$a_status;
 
  415                 $this->integer_axis[
"x"] = (bool)$a_status;