Rev 6039 | Rev 6097 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?php
namespace LeadersLinked\Library;
use Fpdf\Fpdf;
use Amenadiel\JpGraph\Graph;
use Amenadiel\JpGraph\Plot;
class SurveyReport extends FPDF {
/**
* Header PDF
*/
function Header() {
$this->Image($_SERVER['DOCUMENT_ROOT'] . '/pdf/header_background.png', 10, 8, 190);
$this->Image($_SERVER['DOCUMENT_ROOT'] . '/pdf/header_logo.png', 130, 20, 60);
}
/**
* Header custom PDF
* @param string $headerFormName
* @param string $headerUsername
*/
function customHeader($headerFormName, $headerUsername) {
$s = utf8_decode(' Página: ' . $this->PageNo());
$this->SetFont('Arial', '', 10);
$this->SetY(40);
$this->Cell(190, 10, $s, 0, 0, 'R');
$this->SetFont('Arial', 'B', 15);
$this->SetY(50);
$this->Cell(180, 10, $headerFormName, 0, 0, 'C');
$this->setY($this->getY() + 8);
$this->SetFont('Arial', '', 10);
$this->Cell(180, 10, $headerUsername, 0, 0, 'C');
$this->setY($this->getY() + 10);
}
/**
* Footer PDF
*/
function Footer() {
$this->SetY(-30);
$this->Image($_SERVER['DOCUMENT_ROOT'] . '/pdf/footer_background.jpg', 10, $this->getY(), 190);
}
/**
* Create chart PDF
* @param string[] $labels
* @param float[] $values
* @param string $title
* @param string $filename
*/
function pieChart($labels, $values, $title, $filename) {
// We need some data
$datay = $values;
$datax = $labels;
// Setup the graph.
$graph = new Graph\PieGraph(400, 240);
$graph->clearTheme();
$graph->img->SetMargin(60, 20, 35, 75);
$graph->SetScale("textlin");
$graph->SetShadow();
// Set up the title for the graph
$graph->title->Set($title);
$graph->title->SetMargin(8);
$graph->title->SetColor("darkred");
// Show 0 label on Y-axis (default is not to show)
$graph->yscale->ticks->SupressZeroLabel(false);
// Setup X-axis labels
$graph->xaxis->SetTickLabels($datax);
$graph->xaxis->SetLabelAngle(50);
// Create the bar pot
$bplot = new Plot\PiePlot($datay);
// Setup color for gradient fill style
// Set color for the frame of each bar
$bplot->SetColor("white");
$graph->Add($bplot);
$graph->Stroke($filename);
}
function BarDiagram($w, $h, $data, $format, $color=null, $maxVal=0, $nbDiv=4)
{
$this->SetFont('Courier', '', 10);
$this->SetLegends($data,$format);
$XPage = $this->GetX();
$YPage = $this->GetY();
$margin = 2;
$YDiag = $YPage + $margin;
$hDiag = floor($h - $margin * 2);
$XDiag = $XPage + $margin * 2 + $this->wLegend;
$lDiag = floor($w - $margin * 3 - $this->wLegend);
if($color == null)
$color=array(155,155,155);
if ($maxVal == 0) {
$maxVal = max($data);
}
$valIndRepere = ceil($maxVal / $nbDiv);
$maxVal = $valIndRepere * $nbDiv;
$lRepere = floor($lDiag / $nbDiv);
$lDiag = $lRepere * $nbDiv;
$unit = $lDiag / $maxVal;
$hBar = floor($hDiag / ($this->NbVal + 1));
$hDiag = $hBar * ($this->NbVal + 1);
$eBaton = floor($hBar * 80 / 100);
$this->SetLineWidth(0.2);
$this->Rect($XDiag, $YDiag, $lDiag, $hDiag);
$this->SetFont('Courier', '', 10);
$this->SetFillColor($color[0],$color[1],$color[2]);
$i=0;
foreach($data as $val) {
//Bar
$xval = $XDiag;
$lval = (int)($val * $unit);
$yval = $YDiag + ($i + 1) * $hBar - $eBaton / 2;
$hval = $eBaton;
$this->Rect($xval, $yval, $lval, $hval, 'DF');
//Legend
$this->SetXY(0, $yval);
$this->Cell($xval - $margin, $hval, $this->legends[$i],0,0,'R');
$i++;
}
//Scales
for ($i = 0; $i <= $nbDiv; $i++) {
$xpos = $XDiag + $lRepere * $i;
$this->Line($xpos, $YDiag, $xpos, $YDiag + $hDiag);
$val = $i * $valIndRepere;
$xpos = $XDiag + $lRepere * $i - $this->GetStringWidth($val) / 2;
$ypos = $YDiag + $hDiag - $margin;
$this->Text($xpos, $ypos, $val);
}
}
}