Fix to x-axis labels for chart rendering

Fix to page orientation for DomPDF renderer
This commit is contained in:
Mark Baker 2012-10-10 12:31:05 +01:00
parent 49b0549885
commit 364f581ee4
6 changed files with 56 additions and 36 deletions

View File

@ -339,15 +339,15 @@ class PHPExcel_Chart_DataSeries
public function refresh(PHPExcel_Worksheet $worksheet) {
foreach($this->_plotValues as $plotValues) {
if ($plotValues !== NULL)
$plotValues->refresh($worksheet);
$plotValues->refresh($worksheet, TRUE);
}
foreach($this->_plotLabel as $plotValues) {
if ($plotValues !== NULL)
$plotValues->refresh($worksheet);
$plotValues->refresh($worksheet, TRUE);
}
foreach($this->_plotCategory as $plotValues) {
if ($plotValues !== NULL)
$plotValues->refresh($worksheet);
$plotValues->refresh($worksheet, FALSE);
}
}

View File

@ -262,7 +262,7 @@ class PHPExcel_Chart_DataSeriesValues
* FALSE - don't change the value of _dataSource
* @return PHPExcel_Chart_DataSeriesValues
*/
public function setDataValues($dataValues = array(), $refreshDataSource = true) {
public function setDataValues($dataValues = array(), $refreshDataSource = TRUE) {
$this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($dataValues);
$this->_pointCount = count($dataValues);
@ -277,7 +277,7 @@ class PHPExcel_Chart_DataSeriesValues
return $var !== NULL;
}
public function refresh(PHPExcel_Worksheet $worksheet) {
public function refresh(PHPExcel_Worksheet $worksheet, $flatten = TRUE) {
if ($this->_dataSource !== NULL) {
$calcEngine = PHPExcel_Calculation::getInstance();
$newDataValues = PHPExcel_Calculation::_unwrapResult(
@ -287,9 +287,26 @@ class PHPExcel_Chart_DataSeriesValues
$worksheet->getCell('A1')
)
);
if ($flatten) {
$this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues);
} else {
$newArray = array_values(array_shift($newDataValues));
foreach($newArray as $i => $newDataSet) {
$newArray[$i] = array($newDataSet);
}
$this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues);
foreach($newDataValues as $newDataSet) {
$i = 0;
foreach($newDataSet as $newDataVal) {
array_unshift($newArray[$i++],$newDataVal);
}
}
$this->_dataValues = $newArray;
}
$this->_pointCount = count($this->_dataValues);
}
}
}

View File

@ -98,7 +98,7 @@ class PHPExcel_Chart_Renderer_jpgraph
} // function _formatPointMarker()
private function _formatDataSetLabels($groupID,$datasetLabels,$rotation = '') {
private function _formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation = '') {
$datasetLabelFormatCode = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getFormatCode();
if (!is_null($datasetLabelFormatCode)) {
// Retrieve any label formatting code
@ -107,11 +107,8 @@ class PHPExcel_Chart_Renderer_jpgraph
$testCurrentIndex = 0;
foreach($datasetLabels as $i => $datasetLabel) {
// Fill in any missing values in the $datasetLabels array
while ($i != $testCurrentIndex) {
$datasetLabels[$testCurrentIndex] = '';
++$testCurrentIndex;
}
array_reverse($datasetLabel);
if (is_array($datasetLabel)) {
if ($rotation == 'bar') {
$datasetLabel = array_reverse($datasetLabel);
@ -266,9 +263,10 @@ class PHPExcel_Chart_Renderer_jpgraph
private function _renderPlotLine($groupID, $filled = false, $combination = false, $dimensions = '2d') {
$grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
$datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
if (count($datasetLabels) > 0) {
$datasetLabels = $this->_formatDataSetLabels($groupID,$datasetLabels);
$labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
if ($labelCount > 0) {
$datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
$datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount);
$this->_graph->xaxis->SetTickLabels($datasetLabels);
}
@ -333,9 +331,10 @@ class PHPExcel_Chart_Renderer_jpgraph
}
$grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
$datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
if (count($datasetLabels) > 0) {
$datasetLabels = $this->_formatDataSetLabels($groupID,$datasetLabels,$rotation);
$labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
if ($labelCount > 0) {
$datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
$datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation);
// Rotate for bar rather than column chart
if ($rotation == 'bar') {
$datasetLabels = array_reverse($datasetLabels);
@ -599,23 +598,24 @@ class PHPExcel_Chart_Renderer_jpgraph
$this->_renderPiePlotArea($doughnut);
$iLimit = ($multiplePlots) ? $groupCount : 1;
for($i = 0; $i < $iLimit; ++$i) {
$grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotGrouping();
$exploded = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotStyle();
if ($i == 0) {
$datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotCategoryByIndex(0)->getDataValues();
if (count($datasetLabels) > 0) {
$datasetLabels = $this->_formatDataSetLabels($i,$datasetLabels);
for($groupID = 0; $groupID < $iLimit; ++$groupID) {
$grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
$exploded = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
if ($groupID == 0) {
$labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
if ($labelCount > 0) {
$datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
$datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount);
}
}
$seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotSeriesCount();
$seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
$seriesPlots = array();
// For pie charts, we only display the first series: doughnut charts generally display all series
$jLimit = ($multiplePlots) ? $seriesCount : 1;
// Loop through each data series in turn
for($j = 0; $j < $jLimit; ++$j) {
$dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotValuesByIndex($j)->getDataValues();
$dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($j)->getDataValues();
// Fill in any missing values in the $dataValues array
$testCurrentIndex = 0;
@ -646,7 +646,8 @@ class PHPExcel_Chart_Renderer_jpgraph
}
$seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);
$seriesPlot->SetLabels(array_fill(0,count($datasetLabels),''));
if (count($datasetLabels) > 0)
$seriesPlot->SetLabels(array_fill(0,count($datasetLabels),''));
if ($dimensions != '3d') {
$seriesPlot->SetGuideLines(false);
}
@ -668,8 +669,8 @@ class PHPExcel_Chart_Renderer_jpgraph
$this->_renderRadarPlotArea();
for($i = 0; $i < $groupCount; ++$i) {
$this->_renderPlotRadar($i);
for($groupID = 0; $groupID < $groupCount; ++$groupID) {
$this->_renderPlotRadar($groupID);
}
} // function _renderRadarChart()
@ -679,8 +680,8 @@ class PHPExcel_Chart_Renderer_jpgraph
$this->_renderCartesianPlotArea();
for($i = 0; $i < $groupCount; ++$i) {
$this->_renderPlotStock($i);
for($groupID = 0; $groupID < $groupCount; ++$i) {
$this->_renderPlotStock($groupID);
}
} // function _renderStockChart()

View File

@ -103,9 +103,11 @@ class PHPExcel_Writer_PDF_DomPDF extends PHPExcel_Writer_PDF_Core implements PHP
$paperSize = self::$_paperSizes[$printPaperSize];
}
$orientation = ($orientation == 'L') ? 'landscape' : 'portrait';
// Create PDF
$pdf = new DOMPDF();
$pdf->set_paper(strtolower($paperSize), strtolower($orientation));
$pdf->set_paper(strtolower($paperSize), $orientation);
$pdf->load_html(
$this->generateHTMLHeader(false) .

View File

@ -95,7 +95,7 @@ class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPEx
$orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT) ?
PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT : $this->getOrientation();
}
$orientation = strtolower($orientation);
$orientation = strtoupper($orientation);
// Override Paper Size
if (!is_null($this->getPaperSize())) {
@ -109,7 +109,7 @@ class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPEx
// Create PDF
$pdf = new mpdf();
$pdf->_setPageSize(strtoupper($paperSize), $orientation);
$pdf->DefOrientation = $orientation;
// Document info
$pdf->SetTitle($this->_phpExcel->getProperties()->getTitle());
$pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator());

View File

@ -109,7 +109,7 @@ foreach($inputFileNames as $inputFileName) {
echo ' ' , $chartName , ' - ' , $caption , EOL;
echo str_repeat(' ',strlen($chartName)+3);
$jpegFile = str_replace('.xlsx', '.jpg', $inputFileNameShort);
$jpegFile = '35'.str_replace('.xlsx', '.jpg', substr($inputFileNameShort,2));
if (file_exists($jpegFile)) {
unlink($jpegFile);
}