public function testTypeScatterMarker() { do { $expectedSymbol = array_rand(Marker::$arraySymbol); } while ($expectedSymbol == Marker::SYMBOL_NONE); $expectedSize = rand(2, 72); $expectedEltSymbol = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:marker/c:symbol'; $expectedElementSize = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:marker/c:size'; $oSlide = $this->oPresentation->getActiveSlide(); $oShape = $oSlide->createChartShape(); $oScatter = new Scatter(); $oSeries = new Series('Downloads', $this->seriesData); $oSeries->getMarker()->setSymbol($expectedSymbol)->setSize($expectedSize); $oScatter->addSeries($oSeries); $oShape->getPlotArea()->setType($oScatter); $oXMLDoc = TestHelperDOCX::getDocument($this->oPresentation, 'PowerPoint2007'); $this->assertTrue($oXMLDoc->elementExists($expectedEltSymbol, 'ppt/charts/' . $oShape->getIndexedFilename())); $this->assertTrue($oXMLDoc->elementExists($expectedElementSize, 'ppt/charts/' . $oShape->getIndexedFilename())); $this->assertEquals($expectedSymbol, $oXMLDoc->getElementAttribute($expectedEltSymbol, 'val', 'ppt/charts/' . $oShape->getIndexedFilename())); $this->assertEquals($expectedSize, $oXMLDoc->getElementAttribute($expectedElementSize, 'val', 'ppt/charts/' . $oShape->getIndexedFilename())); $oSeries->getMarker()->setSize(1); $oScatter->setSeries(array($oSeries)); $oXMLDoc = TestHelperDOCX::getDocument($this->oPresentation, 'PowerPoint2007'); $this->assertTrue($oXMLDoc->elementExists($expectedElementSize, 'ppt/charts/' . $oShape->getIndexedFilename())); $this->assertEquals(2, $oXMLDoc->getElementAttribute($expectedElementSize, 'val', 'ppt/charts/' . $oShape->getIndexedFilename())); $oSeries->getMarker()->setSize(73); $oScatter->setSeries(array($oSeries)); $oXMLDoc = TestHelperDOCX::getDocument($this->oPresentation, 'PowerPoint2007'); $this->assertTrue($oXMLDoc->elementExists($expectedElementSize, 'ppt/charts/' . $oShape->getIndexedFilename())); $this->assertEquals(72, $oXMLDoc->getElementAttribute($expectedElementSize, 'val', 'ppt/charts/' . $oShape->getIndexedFilename())); $oSeries->getMarker()->setSymbol(Marker::SYMBOL_NONE); $oScatter->setSeries(array($oSeries)); $oXMLDoc = TestHelperDOCX::getDocument($this->oPresentation, 'PowerPoint2007'); $this->assertFalse($oXMLDoc->elementExists($expectedEltSymbol, 'ppt/charts/' . $oShape->getIndexedFilename())); $this->assertFalse($oXMLDoc->elementExists($expectedElementSize, 'ppt/charts/' . $oShape->getIndexedFilename())); }
function fnSlide_Scatter(PhpPresentation $objPHPPresentation) { global $oFill; global $oShadow; // Create templated slide echo EOL . date('H:i:s') . ' Create templated slide' . EOL; $currentSlide = createTemplatedSlide($objPHPPresentation); // local function // Generate sample data for fourth chart echo date('H:i:s') . ' Generate sample data for chart' . EOL; $seriesData = array('Monday' => 0.1, 'Tuesday' => 0.33333, 'Wednesday' => 0.4444, 'Thursday' => 0.5, 'Friday' => 0.4666, 'Saturday' => 0.3666, 'Sunday' => 0.1666); // Create a scatter chart (that should be inserted in a shape) echo date('H:i:s') . ' Create a scatter chart (that should be inserted in a chart shape)' . EOL; $lineChart = new Scatter(); $series = new Series('Downloads', $seriesData); $series->setShowSeriesName(true); $series->getMarker()->setSymbol(\PhpOffice\PhpPresentation\Shape\Chart\Marker::SYMBOL_DASH); $series->getMarker()->setSize(10); $lineChart->addSeries($series); // Create a shape (chart) echo date('H:i:s') . ' Create a shape (chart)' . EOL; $shape = $currentSlide->createChartShape(); $shape->setName('PHPPresentation Daily Download Distribution')->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('PHPPresentation Daily Downloads'); $shape->getTitle()->getFont()->setItalic(true); $shape->getPlotArea()->setType($lineChart); $shape->getView3D()->setRotationX(30); $shape->getView3D()->setPerspective(30); $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE); $shape->getLegend()->getFont()->setItalic(true); }
public function testTypeScatterMarker() { $expectedSymbol1 = Marker::SYMBOL_PLUS; $expectedSymbol2 = Marker::SYMBOL_DASH; $expectedSymbol3 = Marker::SYMBOL_DOT; $expectedSymbol4 = Marker::SYMBOL_TRIANGLE; $expectedSymbol5 = Marker::SYMBOL_NONE; $expectedElement = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleSeries0\'][@style:family=\'chart\']/style:chart-properties'; $expectedSize = rand(1, 100); $expectedSizeCm = number_format(CommonDrawing::pointsToCentimeters($expectedSize), 2, '.', '') . 'cm'; $oPhpPresentation = new PhpPresentation(); $oSlide = $oPhpPresentation->getActiveSlide(); $oShape = $oSlide->createChartShape(); $oScatter = new Scatter(); $oSeries = new Series('Downloads', array('A' => 1, 'B' => 2, 'C' => 4, 'D' => 3, 'E' => 2)); $oSeries->getMarker()->setSymbol($expectedSymbol1)->setSize($expectedSize); $oScatter->addSeries($oSeries); $oShape->getPlotArea()->setType($oScatter); $oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation'); $this->assertTrue($oXMLDoc->fileExists('Object 1/content.xml')); $this->assertTrue($oXMLDoc->elementExists($expectedElement, 'Object 1/content.xml')); $this->assertEquals($expectedSymbol1, $oXMLDoc->getElementAttribute($expectedElement, 'chart:symbol-name', 'Object 1/content.xml')); $this->assertEquals($expectedSizeCm, $oXMLDoc->getElementAttribute($expectedElement, 'chart:symbol-width', 'Object 1/content.xml')); $this->assertEquals($expectedSizeCm, $oXMLDoc->getElementAttribute($expectedElement, 'chart:symbol-height', 'Object 1/content.xml')); $oSeries->getMarker()->setSymbol($expectedSymbol2); $oScatter->setSeries(array($oSeries)); $oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation'); $this->assertEquals('horizontal-bar', $oXMLDoc->getElementAttribute($expectedElement, 'chart:symbol-name', 'Object 1/content.xml')); $oSeries->getMarker()->setSymbol($expectedSymbol3); $oScatter->setSeries(array($oSeries)); $oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation'); $this->assertEquals('circle', $oXMLDoc->getElementAttribute($expectedElement, 'chart:symbol-name', 'Object 1/content.xml')); $oSeries->getMarker()->setSymbol($expectedSymbol4); $oScatter->setSeries(array($oSeries)); $oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation'); $this->assertEquals('arrow-up', $oXMLDoc->getElementAttribute($expectedElement, 'chart:symbol-name', 'Object 1/content.xml')); $oSeries->getMarker()->setSymbol($expectedSymbol5); $oScatter->setSeries(array($oSeries)); $oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation'); $this->assertFalse($oXMLDoc->attributeElementExists($expectedElement, 'chart:symbol-name', 'Object 1/content.xml')); $this->assertFalse($oXMLDoc->attributeElementExists($expectedElement, 'chart:symbol-width', 'Object 1/content.xml')); $this->assertFalse($oXMLDoc->attributeElementExists($expectedElement, 'chart:symbol-height', 'Object 1/content.xml')); }
/** * @param Chart $chart * @param Chart\Series $series */ private function writeSeriesStyle(Chart $chart, Chart\Series $series) { $chartType = $chart->getPlotArea()->getType(); // style:style $this->xmlContent->startElement('style:style'); $this->xmlContent->writeAttribute('style:name', 'styleSeries' . $this->numSeries); $this->xmlContent->writeAttribute('style:family', 'chart'); // style:chart-properties $this->xmlContent->startElement('style:chart-properties'); $this->xmlContent->writeAttribute('chart:data-label-number', 'value'); $this->xmlContent->writeAttribute('chart:label-position', 'center'); if ($chartType instanceof AbstractTypePie) { $this->xmlContent->writeAttribute('chart:pie-offset', $chartType->getExplosion()); } if ($chartType instanceof Line || $chartType instanceof Scatter) { $oMarker = $series->getMarker(); /** * @link : http://www.datypic.com/sc/odf/a-chart_symbol-type.html */ $this->xmlContent->writeAttributeIf($oMarker->getSymbol() == Chart\Marker::SYMBOL_NONE, 'chart:symbol-type', 'none'); /** * @link : http://www.datypic.com/sc/odf/a-chart_symbol-name.html */ $this->xmlContent->writeAttributeIf($oMarker->getSymbol() != Chart\Marker::SYMBOL_NONE, 'chart:symbol-type', 'named-symbol'); if ($oMarker->getSymbol() != Chart\Marker::SYMBOL_NONE) { switch ($oMarker->getSymbol()) { case Chart\Marker::SYMBOL_DASH: $symbolName = 'horizontal-bar'; break; case Chart\Marker::SYMBOL_DOT: $symbolName = 'circle'; break; case Chart\Marker::SYMBOL_TRIANGLE: $symbolName = 'arrow-up'; break; default: $symbolName = $oMarker->getSymbol(); break; } $this->xmlContent->writeAttribute('chart:symbol-name', $symbolName); $symbolSize = number_format(CommonDrawing::pointsToCentimeters($oMarker->getSize()), 2, '.', ''); $this->xmlContent->writeAttribute('chart:symbol-width', $symbolSize . 'cm'); $this->xmlContent->writeAttribute('chart:symbol-height', $symbolSize . 'cm'); } } // > style:chart-properties $this->xmlContent->endElement(); // style:graphic-properties $this->xmlContent->startElement('style:graphic-properties'); if ($chartType instanceof Line || $chartType instanceof Scatter) { $outlineWidth = ''; $outlineColor = ''; $oOutline = $series->getOutline(); if ($oOutline instanceof Outline) { $outlineWidth = $oOutline->getWidth(); if (!empty($outlineWidth)) { $outlineWidth = number_format(CommonDrawing::pointsToCentimeters($outlineWidth), 3, '.', ''); } $outlineColor = $oOutline->getFill()->getStartColor()->getRGB(); } if (empty($outlineWidth)) { $outlineWidth = '0.079'; } if (empty($outlineColor)) { $outlineColor = '4a7ebb'; } $this->xmlContent->writeAttribute('svg:stroke-width', $outlineWidth . 'cm'); $this->xmlContent->writeAttribute('svg:stroke-color', '#' . $outlineColor); } else { $this->xmlContent->writeAttribute('draw:stroke', 'none'); if (!$chartType instanceof Area) { $this->xmlContent->writeAttribute('draw:fill', $series->getFill()->getFillType()); } } $this->xmlContent->writeAttribute('draw:fill-color', '#' . $series->getFill()->getStartColor()->getRGB()); // > style:graphic-properties $this->xmlContent->endElement(); // style:text-properties $this->xmlContent->startElement('style:text-properties'); $this->xmlContent->writeAttribute('fo:color', '#' . $series->getFont()->getColor()->getRGB()); $this->xmlContent->writeAttribute('fo:font-family', $series->getFont()->getName()); $this->xmlContent->writeAttribute('fo:font-size', $series->getFont()->getSize() . 'pt'); // > style:text-properties $this->xmlContent->endElement(); // > style:style $this->xmlContent->endElement(); foreach ($series->getDataPointFills() as $idx => $oFill) { // style:style $this->xmlContent->startElement('style:style'); $this->xmlContent->writeAttribute('style:name', 'styleSeries' . $this->numSeries . '_' . $idx); $this->xmlContent->writeAttribute('style:family', 'chart'); // style:graphic-properties $this->xmlContent->startElement('style:graphic-properties'); $this->xmlContent->writeAttribute('draw:fill', $oFill->getFillType()); $this->xmlContent->writeAttribute('draw:fill-color', '#' . $oFill->getStartColor()->getRGB()); // > style:graphic-properties $this->xmlContent->endElement(); // > style:style $this->xmlContent->endElement(); } }
public function testMarker() { $object = new Series(); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Series', $object->setMarker(new Marker())); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Marker', $object->getMarker()); }