Skip to content

Commit

Permalink
Merge pull request #18 from sn3p/fix-uncaught-error
Browse files Browse the repository at this point in the history
Fix uncaught argument error introduced in PHP7.1
  • Loading branch information
sn3p authored Aug 31, 2018
2 parents 6f04861 + 5554b8a commit 4d21dfc
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions html/includes/renderer-general-output.php
Original file line number Diff line number Diff line change
@@ -1,132 +1,132 @@
<?php
// Fix for UTF-8 required for local use
require_once('encoding.php');
require_once('encoding.php');
use \ForceUTF8\Encoding;

function renderChart($target,$layout,$color,$title,$data,$labels,$categories,$width,$height,$charttype) {

// Add categories if required
if(!empty($categories) && count($categories)>0) {
if(!empty($categories) && count($categories)>0) {
$categoriesString = "categories: ".json_encode($categories).", ";
$categoriesStringPos = strpos($layout,"{",strpos($layout,"xAxis"))+1;
if($categoriesStringPos !== false)
$layout = substr_replace($layout,$categoriesString,$categoriesStringPos,0);
}

// Replace title if required
if(!empty($title) && strlen($title)>0) {
if(!empty($title) && strlen($title)>0) {
$titleStringPosStart = strpos($layout,":",strpos($layout,"text"))+1;
$titleStringPosEnd = strpos($layout,"}",strpos($layout,"text"))-1;

if($categoriesStringPos !== false)
$layout = substr_replace($layout,json_encode($title),$titleStringPosStart,$titleStringPosEnd-$titleStringPosStart);
}

$chart = "
<div id='$target' style='width: ".$width."px; height: ".$height."px; margin: 0em'></div>
<div id='$target' style='width: ".$width."px; height: ".$height."px; margin: 0em'></div>
<script type='text/javascript'>
var chart = new Highcharts.Chart({
chart: {
renderTo: '$target' ";
if($charttype == RENDERER_CHARTTYPE_RADAR)

if($charttype == RENDERER_CHARTTYPE_RADAR)
$chart .= ", polar: true, type: 'area'";

// Encoding::toUTF8() required for $data & $labels in offline use
$chart .= "}, ".Encoding::toUTF8($layout)." ,series: [
".jsonEncodeSeries(Encoding::toUTF8($data),Encoding::toUTF8($labels),$color,$charttype)."
]
});
</script>";

return $chart;
}

function jsonEncodeMultiSeries($data,$labels,$color,$charttype) {
function jsonEncodeMultiSeries($data,$labels,$color,$charttype) {
$countSeries = count($data);

for($i=0;$i<$countSeries;$i++) {

// Reset vars per serie
$layoutSerie = '';
$colorTransparant = false;
$charttypeSingle = $charttype;

// Check if this is the last one
if($i == ($countSeries-1)) {
if($i == ($countSeries-1)) {

if($charttype == RENDERER_CHARTTYPE_LINESTEPCOLUMN)
$charttypeSingle = RENDERER_CHARTTYPE_LINESTEP;

} else {

if($charttype == RENDERER_CHARTTYPE_LINECOLUMN || $charttype == RENDERER_CHARTTYPE_LINESTEPCOLUMN) {
$colorTransparant = true;
$charttypeSingle = RENDERER_CHARTTYPE_COLUMN;


$layoutSerie .= "
showInLegend: false,
yAxis: 1,
";
}
}

}

$jsonData .= jsonEncodeSingleSerie($data[$i],$labels,$color,$charttypeSingle,$layoutSerie,$colorTransparant);

if($i<($countSeries-1))
$jsonData .= ",";

}

return $jsonData;
}



function jsonEncodeSingleSerie($data,$labels,$color,$charttype,$layoutSerie,$colorTransparant=false) {
function jsonEncodeSingleSerie($data,$labels,$color,$charttype,$layoutSerie='',$colorTransparant=false) {
global $renderer_color;
global $renderer_color_transparancy;

$countSeries = count($data);
$jsonData = "";

if($countSeries>0) {
for($i=0;$i<$countSeries;$i++) {
for($i=0;$i<$countSeries;$i++) {

$colorSerie = $renderer_color[$color][$i][0];
if($colorTransparant)
$colorSerie = "rgba(".hex2rgb($colorSerie).",".$renderer_color_transparancy.")";

$jsonData .= " { ";

if($charttype == RENDERER_CHARTTYPE_COLUMN)
$jsonData .= " type: 'column',";
$jsonData .= " type: 'column',";

if($charttype == RENDERER_CHARTTYPE_BAR)
$jsonData .= " type: 'bar',";
$jsonData .= " type: 'bar',";

if($charttype == RENDERER_CHARTTYPE_LINESTEP)
$jsonData .= " step: 'left',";
$jsonData .= " step: 'left',";

$jsonData .= $layoutSerie;

$jsonData .= "
color: '".$colorSerie."',
name: ".json_encode($labels[$i]).",
data: ".json_encode($data[$i])." }";

if($i<($countSeries-1))
$jsonData .= ",";

}

} else if(countSeries==1) {
$jsonData .= "data: { ".$layoutSerie.json_encode($data[0])." }";
}
}

return $jsonData;
}

Expand All @@ -135,13 +135,13 @@ function jsonEncodeRadarSerie($data,$labels,$color,$charttype) {
}


function jsonEncodeSeries($data,$labels,$color,$charttype) {
function jsonEncodeSeries($data,$labels,$color,$charttype) {

if($charttype == RENDERER_CHARTTYPE_LINECOLUMN || $charttype == RENDERER_CHARTTYPE_LINESTEPCOLUMN)
return jsonEncodeMultiSeries($data,$labels,$color,$charttype);
return jsonEncodeMultiSeries($data,$labels,$color,$charttype);

else
return jsonEncodeSingleSerie($data,$labels,$color,$charttype);
return jsonEncodeSingleSerie($data,$labels,$color,$charttype);
}


Expand Down Expand Up @@ -192,4 +192,4 @@ function hex2rgb($hex) {

}

?>
?>

0 comments on commit 4d21dfc

Please sign in to comment.