Skip to content

Commit

Permalink
Update #2 issue bar rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
luukverhoeven committed May 11, 2024
1 parent 9928608 commit bfe6976
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
47 changes: 34 additions & 13 deletions components/plot/bar/graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@
}

if ($g['id'] == $id) {
include($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pDraw.class.php");
include($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pData.class.php");
include($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pImage.class.php");
//
require_once($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pDraw.php");
require_once($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pData.php");
require_once($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pColor.php");
require_once($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pException.php");
require_once($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pCharts.php");

// Dataset definition.
$dataset = new pData();

$dataset = new \pChart\pData();
$labels = array_shift($series);

// Invert/Reverse Hebrew labels so it can be rendered using PHP imagettftext()
Expand All @@ -94,6 +98,7 @@
(preg_match("/[\xE0-\xFA]/", iconv("UTF-8", "ISO-8859-8", $value))) ? $reportclass->utf8_strrev($value) : $value
);
}

$dataset->addPoints($invertedlabels, "Labels");
$dataset->setAbscissa("Labels");

Expand All @@ -106,9 +111,11 @@

$width = property_exists($g['formdata'], "width") ? $g['formdata']->width : 900;
$height = property_exists($g['formdata'], "height") ? $g['formdata']->height : 500;

$colorr = property_exists($g['formdata'], "color_r") ? $g['formdata']->color_r : 170;
$colorg = property_exists($g['formdata'], "color_g") ? $g['formdata']->color_g : 183;
$colorb = property_exists($g['formdata'], "color_b") ? $g['formdata']->color_b : 87;

$padding = 30;
$fontsize = 8;
$fontpath = $CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/fonts";
Expand All @@ -126,8 +133,15 @@
$legendoffset = $maxlegendoffset;
}

$mypicture = new pImage($width, $height, $dataset);
$mypicture->setFontProperties(["FontName" => "$fontpath/calibri.ttf", "FontSize" => $fontsize]);
$mypicture = new \pChart\pDraw($width, $height);
$mypicture->myData = $dataset;

$mypicture->setFontProperties([
"FontName" => "$fontpath/Cairo-Regular.ttf",
"FontSize" => $fontsize,
"Color" => new \pChart\pColor(0 , 0 , 0),
]);

[$legendwidth, $legendheight] = array_values($mypicture->getLegendSize());
$legendx = $width - $legendwidth - $padding;
$legendy = $padding;
Expand All @@ -137,9 +151,6 @@
$graphy = $padding;
$graphwidth = $legendx - $padding;
$graphheight = $height - $labeloffset;

$bgsettings = ['R' => 225, 'G' => 225, 'B' => 225];
$mypicture->drawFilledRectangle(0, 0, $width + 2, $height + 2, $bgsettings);
$mypicture->setGraphArea($graphx, $graphy, $graphwidth, $graphheight);

$scalesettings = [
Expand All @@ -150,7 +161,14 @@
"DrawSubTicks" => true,
];
$mypicture->drawScale($scalesettings);
$mypicture->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
$mypicture->setShadow(true, [
"X" => 1,
"Y" => 1,
"R" => 0,
"G" => 0,
"B" => 0,
"Alpha" => 10,
]);

$chartsettings = [
"DisplayValues" => true,
Expand All @@ -160,13 +178,16 @@
"DisplayG" => 0,
"DisplayB" => 0,
"DisplayOffset" => 5,
"DrawSubTicks" => true,
];
$mypicture->drawBarChart($chartsettings);
/* Draw the chart */
$pCharts = new \pChart\pCharts($mypicture);
$pCharts->drawBarChart($chartsettings);

$mypicture->setShadow(false);
$mypicture->drawLegend($legendx, $legendy);
$mypicture->stroke();

// Hack to clear output and send only IMAGE data to browser.
ob_clean();
$mypicture->autoOutput();
}
}
6 changes: 3 additions & 3 deletions components/plot/line/graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

require_login();

error_reporting(0);
ini_set('display_erros', false);
// error_reporting(E_ALL);
// ini_set('display_erros', true);

$id = required_param('id', PARAM_ALPHANUM);
$reportid = required_param('reportid', PARAM_INT);
Expand Down Expand Up @@ -152,4 +152,4 @@
ob_clean(); // Hack to clear output and send only IMAGE data to browser.
$test->Stroke();
}
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"license": "GPL-3.0+",
"require": {
"composer/installers": "*",
"ext-json": "*"
"ext-json": "*",
"ext-iconv": "*"
},
"extra": {
"installer-name": "configurable_reports"
Expand Down
2 changes: 1 addition & 1 deletion lib/pChart2/class/pDraw.php
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ private function drawAlphaPixel($X, $Y, array $ColorA) # FAST
}

/* Allocate a color with transparency */
private function allocateColor(array $ColorA) # FAST
public function allocateColor(array $ColorA) # FAST
{
($ColorA[3] < 0) AND $ColorA[3] = 0;
($ColorA[3] > 100) AND $ColorA[3] = 100;
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2024050700;
$plugin->version = 2024051100;
$plugin->requires = 2017111300;
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '4.1.0';
Expand Down

0 comments on commit bfe6976

Please sign in to comment.