/** * Show a multi-area chart * * @param $raw_datas : an array with : * - key 'datas', ex : array( 'test1' => 15, 'test2' => 25) * - key 'unit', ex : '%', 'Kg' (optionnal) * - key 'spline', curves line (boolean - optionnal) * @param $title : title of the chart * @param $desc : description of the chart (optionnal) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) * @return nothing */ function showGarea($params) { global $LANG; $criterias = PluginMreportingCommon::initGraphParams($params); foreach ($criterias as $key => $val) { ${$key} = $val; } $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); foreach ($configs as $k => $v) { ${$k} = $v; } //if (self::DEBUG_GRAPH && isset($raw_datas)) Toolbox::logdebug($raw_datas); $options = array("title" => $title, "desc" => $desc, "randname" => $randname, "export" => $export, "delay" => $delay, "short_classname" => $opt["short_classname"]); $this->initGraph($options); if (!isset($raw_datas['datas'])) { echo "}</script>"; echo $LANG['plugin_mreporting']["error"][1]; $end['opt']["export"] = false; $end['opt']["randname"] = false; $end['opt']["f_name"] = $opt['f_name']; $end['opt']["class"] = $opt['class']; PluginMreportingCommon::endGraph($end); return false; } $datas = $raw_datas['datas']; $labels2 = $raw_datas['labels2']; $datas = $this->initDatasMultiple($datas, $labels2, $unit); $always = ''; $hover = ''; PluginMreportingConfig::checkVisibility($show_label, $always, $hover); $nb_bar = count($datas); $height = 20 * $nb_bar + 250; if ($height < 450) { $height = 450; } $JS = <<<JAVASCRIPT var width_area = {$this->width}; var height_area = {$height}; var offset = 0; var step = Math.round(m / 20); var x = pv.Scale.linear(0, m-1).range(5, width_area); var y = pv.Scale.linear(0, max).range(0, height_area-(n*14)); var i = -1; //console.log(x.ticks()); /* The root panel. */ vis{$randname} = new pv.Panel() .width(width_area) .height(height_area) .bottom(20) .left(50) .right(15) .top(5); /* Y-ticks. */ vis{$randname}.add(pv.Rule) .data(y.ticks()) .bottom(function(d) Math.round(y(d)) - .5) .strokeStyle(function(d) d ? "#eee" : "black") .anchor("left").add(pv.Label) .text(function(d) d.toFixed(1)); /* X-ticks. */ vis{$randname}.add(pv.Rule) .data(x.ticks(m)) .left(function(d) Math.round(x(d)) - .5) .strokeStyle(function() { if (this.index == 0) return "black"; return (i == this.index) ? "black" : "#eee"; }) .height(height_area - (n*14)) .bottom(-5) .anchor("bottom").add(pv.Label) .text(function(d) labels2[this.index]) .visible(function() { if ((this.index / step) == Math.round(this.index / step)) return true; else return false; }); /* add mini black lines in front of labels tick */ vis{$randname}.add(pv.Rule) .data(x.ticks(m)) .left(function() x(this.index)-1) .bottom(-5) .strokeStyle("black") .height(5) .visible(function() { if ((this.index / step) == Math.round(this.index / step)) return true; else return false; }); /* A panel for each data series. */ var panel{$randname} = vis{$randname}.add(pv.Panel) .data(datas); /* The line. */ var lines{$randname} = panel{$randname}.add(pv.Line) .tension(function () { return ('{$unit}' == '%') ? 0.9 : 0.7; }) .data(function(d) d) .interpolate(function () { //curve line if ({$spline}>0) return "cardinal"; else return "linear"; }) .strokeStyle(function() { return colors(this.parent.index); }) .left(function() x(this.index)) .bottom(function(d) y(d)) .visible(function() {return (this.index < ((offset / 2) * ( m / 12))); }) .lineWidth(2); if ('{$area}'>0) { lines{$randname}.add(pv.Area) .visible(function() { return m < ((offset / 2) * ( m / 12)); }) .lineWidth(0) .bottom(1) .fillStyle(function() { return colors(this.parent.index).alpha(.15); }) .height(function(d) y(d)); } /* The dots*/ var dots{$randname} = lines{$randname}.add(pv.Dot) .left(function() x(this.index)) .bottom(function(d) y(d)) .fillStyle(function () { return (i == this.index) ? colors(this.parent.index) : "white"; }) .lineWidth(2) .size(function () { return (i == this.index) ? 15 : 10;}); /* The legend */ var legend_dots{$randname} = lines{$randname}.add(pv.Dot) .data(function(d) [d[i]]) .left(5) .top(function() this.parent.index * 13 + 10); var legend_labels{$randname} = legend_dots{$randname}.anchor("right").add(pv.Label) .text(function(d) { var text = labels[this.parent.index]; if (i > -1 && {$hover}) text += " : "+d+" {$unit}"; // mouse over labels return text; }); /* An invisible bar to capture events (without flickering). */ vis{$randname}.add(pv.Bar) .fillStyle("rgba(0,0,0,.001)") .event("mouseout", function() { i = -1; return vis{$randname}; }) .event("mousemove", function() { i = Math.round(x.invert(vis{$randname}.mouse().x)); return vis{$randname} ; }); //render in loop to animate var interval = setInterval(function() { offset++; vis{$randname}.render(); if (offset > 100) clearInterval(interval); }, 20); JAVASCRIPT; if ($show_graph) { echo $JS; } $opt['randname'] = $randname; $options = array("opt" => $opt, "export" => $export, "datas" => $datas, "labels2" => $labels2, "flip_data" => $flip_data, "unit" => $unit); PluginMreportingCommon::endGraph($options); }