4 include_once
"Services/Chart/classes/class.ilChartData.php";
5 include_once
"Services/Chart/classes/class.ilChartLegend.php";
37 public function __construct($a_id, $a_width = 500, $a_height = 500, $a_renderer =
"flot")
40 $this->data = array();
43 $this->
setSize($a_width, $a_height);
57 $this->renderer = (string)$a_value;
79 $this->width = (int)$a_x;
80 $this->height = (int)$a_y;
96 $this->data[$a_idx] = $a_series;
107 $this->legend = $a_legend;
118 if(preg_match(
"/^#[0-9a-f]{3}$/i", $a_value, $match))
122 else if(preg_match(
"/^#[0-9a-f]{6}$/i", $a_value, $match))
137 if(self::isValidColor($a_value))
139 if(strlen($a_value) == 4)
141 return "\"rgba(".hexdec($a_value[1].$a_value[1]).
", ".
142 hexdec($a_value[2].$a_value[2]).
", ".
143 hexdec($a_value[3].$a_value[3]).
", ".$a_opacity.
")\"";
147 return "\"rgba(".hexdec($a_value[1].$a_value[2]).
", ".
148 hexdec($a_value[3].$a_value[4]).
", ".
149 hexdec($a_value[5].$a_value[6]).
", ".$a_opacity.
")\"";
161 $this->shadow = (int)$a_value;
181 foreach($a_values as $color)
183 if(self::isValidColor($color))
185 $this->colors[] = $color;
207 public function setTicks($a_x, $a_y, $a_labeled =
false)
209 $this->ticks = array(
"x" => $a_x,
"y" => $a_y,
"labeled" => (
bool)$a_labeled);
229 $this->leg_labels = $a_val;
249 include_once
"Services/jQuery/classes/class.iljQueryUtil.php";
252 $tpl->addJavascript(
"Services/Chart/js/flot/excanvas.min.js");
253 $tpl->addJavascript(
"Services/Chart/js/flot/jquery.flot.min.js");
254 $tpl->addJavascript(
"Services/Chart/js/flot/jquery.flot.pie.js");
255 $tpl->addJavascript(
"Services/Chart/js/flot/jquery.flot.highlighter.js");
256 $tpl->addJavascript(
"Services/Chart/js/flot/jquery.flot.spider.js");
258 $chart =
new ilTemplate(
"tpl.grid.html",
true,
true,
"Services/Chart");
259 $chart->setVariable(
"ID", $this->
id);
260 $chart->setVariable(
"WIDTH", $this->width);
261 $chart->setVariable(
"HEIGHT", $this->height);
263 $last = array_keys($this->data);
264 $last = array_pop($last);
267 foreach($this->data as $idx => $series)
269 $fill = $series->getFill();
271 if ($series->getType() ==
"spider")
275 if ($fill[
"color"] !=
"")
277 $chart->setCurrentBlock(
"series_property");
278 $chart->setVariable(
"SPROP",
"color");
279 $chart->setVariable(
"SPROP_VAL", self::renderColor($fill[
"color"] ,
"0.5"));
280 $chart->parseCurrentBlock();
284 $chart->setCurrentBlock(
"series");
285 $chart->setVariable(
"SERIES_LABEL", str_replace(
"\"",
"\\\"", $series->getLabel()));
286 $chart->setVariable(
"SERIES_TYPE", $series->getType());
288 $type = $series->getType();
293 foreach($series->getData() as $point)
295 $points[] =
"[".$point[0].
",".$point[1].
"]";
297 $chart->setVariable(
"SERIES_DATA",
"[ ".implode(
",", $points).
" ]");
302 $chart->setVariable(
"SERIES_DATA", array_pop($series->getData()));
306 $chart->setVariable(
"SERIES_END",
",");
309 $options = array(
"show: ".($series->isHidden() ?
"false" :
"true"));
310 if($type !=
"points")
312 $width = $series->getLineWidth();
319 $bar_options = $series->getBarOptions();
320 if($bar_options[
"width"] !== null)
322 $options[] =
"barWidth:".str_replace(
",",
".", $bar_options[
"width"]);
323 $options[] =
"align: \"".$bar_options[
"align"].
"\"";
324 if($bar_options[
"horizontal"])
330 else if($type ==
"lines")
332 if($series->getLineSteps())
340 $radius = $series->getPointRadius();
349 $options[] =
"fill: ".$fill[
"fill"];
352 $options[] =
"fillColor: ".self::renderColor($fill[
"color"], $fill[
"fill"]);
355 $chart->setVariable(
"SERIES_OPTIONS", implode(
", ",
$options));
357 $chart->parseCurrentBlock();
362 $chart->setCurrentBlock(
"spider");
363 $lab_strings = array();
368 $lab_strings[] =
"{label: \"".$l.
"\"}";
369 $max_str_len = max($max_str_len, strlen($l));
371 $chart->setVariable(
"LEG_LABELS", implode($lab_strings,
","));
372 $chart->setVariable(
"LEG_MAX", $this->
getYAxisMax());
377 $chart->setVariable(
"LEG_START_ANGLE",
"10");
381 $chart->setVariable(
"LEG_START_ANGLE",
"0");
384 if ($max_str_len > 60)
386 $chart->setVariable(
"FONT_SIZE",
"10");
388 else if ($max_str_len > 30)
390 $chart->setVariable(
"FONT_SIZE",
"12");
394 $chart->setVariable(
"FONT_SIZE",
"15");
396 $chart->parseCurrentBlock();
398 $chart->setCurrentBlock(
"spider_grid_options");
399 $chart->setVariable(
"NR_TICKS", $this->
getYAxisMax());
400 $chart->parseCurrentBlock();
405 $chart->setVariable(
"SHADOW", (
int)$this->
getShadow());
406 $chart->setVariable(
"IS_PIE", ($has_pie ?
"true" :
"false"));
419 $chart->setVariable(
"COLORS", implode(
",", $tmp));
425 $chart->setVariable(
"LEGEND",
"show: false");
429 $margin = $this->legend->getMargin();
432 $legend[] =
"noColumns: ".$this->legend->getColumns();
433 $legend[] =
"position: \"".$this->legend->getPosition().
"\"";
434 $legend[] =
"margin: [".$margin[
"x"].
", ".$margin[
"y"].
"]";
435 $legend[] =
"backgroundColor: ".self::renderColor($this->legend->getBackground());
436 $legend[] =
"backgroundOpacity: ".str_replace(
",",
".",$this->legend->getOpacity());
437 $legend[] =
"labelBoxBorderColor: ".self::renderColor($this->legend->getLabelBorder());
439 $chart->setVariable(
"LEGEND", implode(
", ",
$legend));
447 foreach(
$ticks as $axis => $def)
451 $tmp[$axis] = $axis.
"axis: { ticks: ".$def.
" }";
453 else if(is_array($def))
456 foreach($def as $idx => $value)
460 $ttmp[] =
"[".$idx.
", \"".$value.
"\"]";
467 $tmp[$axis] = $axis.
"axis: { ticks: [".implode(
", ", $ttmp).
"] }";
473 if(!isset($tmp[
"x"]) && $this->integer_axis[
"x"])
475 $tmp[
"x"] =
"xaxis: { tickDecimals: 0 }";
477 if(!isset($tmp[
"y"]) && $this->integer_axis[
"y"])
479 $tmp[
"y"] =
"yaxis: { tickDecimals: 0 }";
484 $chart->setVariable(
"AXIS",
",".implode(
", ", $tmp));
487 $ret = $chart->get();
494 $this->integer_axis[
"y"] = (bool)$a_status;
499 $this->integer_axis[
"x"] = (bool)$a_status;
509 $this->y_max = $a_val;