Beispiel #1
0
 public function testHashCode()
 {
     $oSeries = new Series();
     $object = new Pie();
     $object->addSeries($oSeries);
     $this->assertEquals(md5($oSeries->getHashCode() . get_class($object)), $object->getHashCode());
 }
 public function testTypePie()
 {
     $seriesData = array('A' => 1, 'B' => 2, 'C' => 4, 'D' => 3, 'E' => 2);
     $oPHPPowerPoint = new PhpPowerpoint();
     $oSlide = $oPHPPowerPoint->getActiveSlide();
     $oShape = $oSlide->createChartShape();
     $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
     $oPie = new Pie();
     $oSeries = new Series('Downloads', $seriesData);
     $oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
     $oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKBLUE));
     $oSeries->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKGREEN));
     $oSeries->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKRED));
     $oSeries->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKYELLOW));
     $oPie->addSeries($oSeries);
     $oShape->getPlotArea()->setType($oPie);
     $oXMLDoc = TestHelperDOCX::getDocument($oPHPPowerPoint, 'PowerPoint2007');
     $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData';
     $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/slides/slide1.xml'));
     $element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart';
     $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/' . $oShape->getIndexedFilename()));
     $element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser';
     $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/' . $oShape->getIndexedFilename()));
     $element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dPt/c:spPr';
     $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/' . $oShape->getIndexedFilename()));
     $element = '/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:tx/c:v';
     $this->assertEquals($oSeries->getTitle(), $oXMLDoc->getElement($element, 'ppt/charts/' . $oShape->getIndexedFilename())->nodeValue);
 }
function fnSlide_Pie(PhpPowerpoint $objPHPPowerPoint)
{
    global $oFill;
    global $oShadow;
    // Create templated slide
    echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
    $currentSlide = createTemplatedSlide($objPHPPowerPoint);
    // Generate sample data for second chart
    echo date('H:i:s') . ' Generate sample data for chart' . EOL;
    $seriesData = array('Monday' => 18, 'Tuesday' => 23, 'Wednesday' => 14, 'Thursday' => 12, 'Friday' => 20, 'Saturday' => 8, 'Sunday' => 10);
    // Create a pie chart (that should be inserted in a shape)
    echo date('H:i:s') . ' Create a non-3D pie chart (that should be inserted in a chart shape)' . EOL;
    $pieChart = new Pie();
    $pieChart->setExplosion(15);
    $series = new Series('Downloads', $seriesData);
    $series->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF7CB5EC'));
    $series->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF434348'));
    $series->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF90ED7D'));
    $series->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFF7A35C'));
    $series->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF8085E9'));
    $series->getDataPointFill(5)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFF15C80'));
    $series->getDataPointFill(6)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE4D354'));
    $series->setShowPercentage(true);
    $series->setShowValue(false);
    $series->setShowSeriesName(false);
    $series->setShowCategoryName(true);
    $pieChart->addSeries($series);
    // Create a shape (chart)
    echo date('H:i:s') . ' Create a shape (chart)' . EOL;
    $shape = $currentSlide->createChartShape();
    $shape->setName('PHPPowerPoint Daily Downloads')->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
    $shape->setShadow($oShadow);
    $shape->setFill($oFill);
    $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
    $shape->getTitle()->setText('PHPPowerPoint Daily Downloads');
    $shape->getTitle()->getFont()->setItalic(true);
    $shape->getPlotArea()->setType($pieChart);
    $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
    $shape->getLegend()->getFont()->setItalic(true);
}
 public function testChartPie()
 {
     $oSeries = new Series('Series', array('Jan' => 1, 'Feb' => 5, 'Mar' => 2));
     $oSeries->setShowSeriesName(true);
     $oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4672A8'));
     $oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFAB4744'));
     $oSeries->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF8AA64F'));
     $oPie = new Pie();
     $oPie->addSeries($oSeries);
     $phpPowerPoint = new PhpPowerpoint();
     $oSlide = $phpPowerPoint->getActiveSlide();
     $oChart = $oSlide->createChartShape();
     $oChart->getPlotArea()->setType($oPie);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
     $element = '/office:document-content/office:body/office:chart/chart:chart';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $this->assertEquals('chart:circle', $pres->getElementAttribute($element, 'chart:class', 'Object 1/content.xml'));
     $element = '/office:document-content/office:body/office:chart/chart:chart/chart:plot-area/chart:series/chart:data-point';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleAxisX\']/style:chart-properties';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $this->assertEquals('true', $pres->getElementAttribute($element, 'chart:reverse-direction', 'Object 1/content.xml'));
     $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleAxisY\']/style:chart-properties';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $this->assertEquals('true', $pres->getElementAttribute($element, 'chart:reverse-direction', 'Object 1/content.xml'));
 }