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) { public function refresh(PHPExcel_Worksheet $worksheet) {
foreach($this->_plotValues as $plotValues) { foreach($this->_plotValues as $plotValues) {
if ($plotValues !== NULL) if ($plotValues !== NULL)
$plotValues->refresh($worksheet); $plotValues->refresh($worksheet, TRUE);
} }
foreach($this->_plotLabel as $plotValues) { foreach($this->_plotLabel as $plotValues) {
if ($plotValues !== NULL) if ($plotValues !== NULL)
$plotValues->refresh($worksheet); $plotValues->refresh($worksheet, TRUE);
} }
foreach($this->_plotCategory as $plotValues) { foreach($this->_plotCategory as $plotValues) {
if ($plotValues !== NULL) 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 * FALSE - don't change the value of _dataSource
* @return PHPExcel_Chart_DataSeriesValues * @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->_dataValues = PHPExcel_Calculation_Functions::flattenArray($dataValues);
$this->_pointCount = count($dataValues); $this->_pointCount = count($dataValues);
@ -277,7 +277,7 @@ class PHPExcel_Chart_DataSeriesValues
return $var !== NULL; return $var !== NULL;
} }
public function refresh(PHPExcel_Worksheet $worksheet) { public function refresh(PHPExcel_Worksheet $worksheet, $flatten = TRUE) {
if ($this->_dataSource !== NULL) { if ($this->_dataSource !== NULL) {
$calcEngine = PHPExcel_Calculation::getInstance(); $calcEngine = PHPExcel_Calculation::getInstance();
$newDataValues = PHPExcel_Calculation::_unwrapResult( $newDataValues = PHPExcel_Calculation::_unwrapResult(
@ -287,9 +287,26 @@ class PHPExcel_Chart_DataSeriesValues
$worksheet->getCell('A1') $worksheet->getCell('A1')
) )
); );
if ($flatten) {
$this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues); $this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues);
} else {
$newArray = array_values(array_shift($newDataValues));
foreach($newArray as $i => $newDataSet) {
$newArray[$i] = array($newDataSet);
} }
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() } // function _formatPointMarker()
private function _formatDataSetLabels($groupID,$datasetLabels,$rotation = '') { private function _formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation = '') {
$datasetLabelFormatCode = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getFormatCode(); $datasetLabelFormatCode = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getFormatCode();
if (!is_null($datasetLabelFormatCode)) { if (!is_null($datasetLabelFormatCode)) {
// Retrieve any label formatting code // Retrieve any label formatting code
@ -107,11 +107,8 @@ class PHPExcel_Chart_Renderer_jpgraph
$testCurrentIndex = 0; $testCurrentIndex = 0;
foreach($datasetLabels as $i => $datasetLabel) { foreach($datasetLabels as $i => $datasetLabel) {
// Fill in any missing values in the $datasetLabels array array_reverse($datasetLabel);
while ($i != $testCurrentIndex) {
$datasetLabels[$testCurrentIndex] = '';
++$testCurrentIndex;
}
if (is_array($datasetLabel)) { if (is_array($datasetLabel)) {
if ($rotation == 'bar') { if ($rotation == 'bar') {
$datasetLabel = array_reverse($datasetLabel); $datasetLabel = array_reverse($datasetLabel);
@ -266,9 +263,10 @@ class PHPExcel_Chart_Renderer_jpgraph
private function _renderPlotLine($groupID, $filled = false, $combination = false, $dimensions = '2d') { private function _renderPlotLine($groupID, $filled = false, $combination = false, $dimensions = '2d') {
$grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping(); $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
$labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
if ($labelCount > 0) {
$datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues(); $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
if (count($datasetLabels) > 0) { $datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount);
$datasetLabels = $this->_formatDataSetLabels($groupID,$datasetLabels);
$this->_graph->xaxis->SetTickLabels($datasetLabels); $this->_graph->xaxis->SetTickLabels($datasetLabels);
} }
@ -333,9 +331,10 @@ class PHPExcel_Chart_Renderer_jpgraph
} }
$grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping(); $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
$labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
if ($labelCount > 0) {
$datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues(); $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
if (count($datasetLabels) > 0) { $datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation);
$datasetLabels = $this->_formatDataSetLabels($groupID,$datasetLabels,$rotation);
// Rotate for bar rather than column chart // Rotate for bar rather than column chart
if ($rotation == 'bar') { if ($rotation == 'bar') {
$datasetLabels = array_reverse($datasetLabels); $datasetLabels = array_reverse($datasetLabels);
@ -599,23 +598,24 @@ class PHPExcel_Chart_Renderer_jpgraph
$this->_renderPiePlotArea($doughnut); $this->_renderPiePlotArea($doughnut);
$iLimit = ($multiplePlots) ? $groupCount : 1; $iLimit = ($multiplePlots) ? $groupCount : 1;
for($i = 0; $i < $iLimit; ++$i) { for($groupID = 0; $groupID < $iLimit; ++$groupID) {
$grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotGrouping(); $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
$exploded = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotStyle(); $exploded = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
if ($i == 0) { if ($groupID == 0) {
$datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotCategoryByIndex(0)->getDataValues(); $labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
if (count($datasetLabels) > 0) { if ($labelCount > 0) {
$datasetLabels = $this->_formatDataSetLabels($i,$datasetLabels); $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(); $seriesPlots = array();
// For pie charts, we only display the first series: doughnut charts generally display all series // For pie charts, we only display the first series: doughnut charts generally display all series
$jLimit = ($multiplePlots) ? $seriesCount : 1; $jLimit = ($multiplePlots) ? $seriesCount : 1;
// Loop through each data series in turn // Loop through each data series in turn
for($j = 0; $j < $jLimit; ++$j) { 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 // Fill in any missing values in the $dataValues array
$testCurrentIndex = 0; $testCurrentIndex = 0;
@ -646,6 +646,7 @@ class PHPExcel_Chart_Renderer_jpgraph
} }
$seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]); $seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);
if (count($datasetLabels) > 0)
$seriesPlot->SetLabels(array_fill(0,count($datasetLabels),'')); $seriesPlot->SetLabels(array_fill(0,count($datasetLabels),''));
if ($dimensions != '3d') { if ($dimensions != '3d') {
$seriesPlot->SetGuideLines(false); $seriesPlot->SetGuideLines(false);
@ -668,8 +669,8 @@ class PHPExcel_Chart_Renderer_jpgraph
$this->_renderRadarPlotArea(); $this->_renderRadarPlotArea();
for($i = 0; $i < $groupCount; ++$i) { for($groupID = 0; $groupID < $groupCount; ++$groupID) {
$this->_renderPlotRadar($i); $this->_renderPlotRadar($groupID);
} }
} // function _renderRadarChart() } // function _renderRadarChart()
@ -679,8 +680,8 @@ class PHPExcel_Chart_Renderer_jpgraph
$this->_renderCartesianPlotArea(); $this->_renderCartesianPlotArea();
for($i = 0; $i < $groupCount; ++$i) { for($groupID = 0; $groupID < $groupCount; ++$i) {
$this->_renderPlotStock($i); $this->_renderPlotStock($groupID);
} }
} // function _renderStockChart() } // function _renderStockChart()

View File

@ -103,9 +103,11 @@ class PHPExcel_Writer_PDF_DomPDF extends PHPExcel_Writer_PDF_Core implements PHP
$paperSize = self::$_paperSizes[$printPaperSize]; $paperSize = self::$_paperSizes[$printPaperSize];
} }
$orientation = ($orientation == 'L') ? 'landscape' : 'portrait';
// Create PDF // Create PDF
$pdf = new DOMPDF(); $pdf = new DOMPDF();
$pdf->set_paper(strtolower($paperSize), strtolower($orientation)); $pdf->set_paper(strtolower($paperSize), $orientation);
$pdf->load_html( $pdf->load_html(
$this->generateHTMLHeader(false) . $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) ? $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT) ?
PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT : $this->getOrientation(); PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT : $this->getOrientation();
} }
$orientation = strtolower($orientation); $orientation = strtoupper($orientation);
// Override Paper Size // Override Paper Size
if (!is_null($this->getPaperSize())) { if (!is_null($this->getPaperSize())) {
@ -109,7 +109,7 @@ class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPEx
// Create PDF // Create PDF
$pdf = new mpdf(); $pdf = new mpdf();
$pdf->_setPageSize(strtoupper($paperSize), $orientation); $pdf->_setPageSize(strtoupper($paperSize), $orientation);
$pdf->DefOrientation = $orientation;
// Document info // Document info
$pdf->SetTitle($this->_phpExcel->getProperties()->getTitle()); $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle());
$pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator()); $pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator());

View File

@ -109,7 +109,7 @@ foreach($inputFileNames as $inputFileName) {
echo ' ' , $chartName , ' - ' , $caption , EOL; echo ' ' , $chartName , ' - ' , $caption , EOL;
echo str_repeat(' ',strlen($chartName)+3); 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)) { if (file_exists($jpegFile)) {
unlink($jpegFile); unlink($jpegFile);
} }