Inheritance: extends AbstractType, implements PhpOffice\PhpPresentation\ComparableInterface
Ejemplo n.º 1
0
 public function testHashCode()
 {
     $oSeries = new Series();
     $object = new Scatter();
     $object->addSeries($oSeries);
     $this->assertEquals(md5($oSeries->getHashCode() . get_class($object)), $object->getHashCode());
 }
Ejemplo n.º 2
0
 public function testHashIndex()
 {
     $object = new Scatter();
     $value = rand(1, 100);
     $this->assertEmpty($object->getHashIndex());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Scatter', $object->setHashIndex($value));
     $this->assertEquals($value, $object->getHashIndex());
 }
Ejemplo n.º 3
0
 public function testChartScatter()
 {
     $oSeries = new Series('Series', array('Jan' => 1, 'Feb' => 5, 'Mar' => 2));
     $oSeries->setShowSeriesName(true);
     $oScatter = new Scatter();
     $oScatter->addSeries($oSeries);
     $phpPresentation = new PhpPresentation();
     $oSlide = $phpPresentation->getActiveSlide();
     $oChart = $oSlide->createChartShape();
     $oChart->getPlotArea()->setType($oScatter);
     $pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
     $element = '/office:document-content/office:body/office:chart/chart:chart';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $this->assertEquals('chart:scatter', $pres->getElementAttribute($element, 'chart:class', 'Object 1/content.xml'));
 }
Ejemplo n.º 4
0
 public function testTypeScatterSuperScript()
 {
     $oSlide = $this->oPresentation->getActiveSlide();
     $oShape = $oSlide->createChartShape();
     $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
     $oScatter = new Scatter();
     $oSeries = new Series('Downloads', $this->seriesData);
     $oSeries->getFont()->setSuperScript(true);
     $oScatter->addSeries($oSeries);
     $oShape->getPlotArea()->setType($oScatter);
     $oXMLDoc = TestHelperDOCX::getDocument($this->oPresentation, 'PowerPoint2007');
     $element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:dLbls/c:txPr/a:p/a:pPr/a:defRPr';
     $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/' . $oShape->getIndexedFilename()));
     $this->assertEquals('30000', $oXMLDoc->getElementAttribute($element, 'baseline', 'ppt/charts/' . $oShape->getIndexedFilename()));
 }
Ejemplo n.º 5
0
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);
    $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);
}
Ejemplo n.º 6
0
 /**
  * Write Type Scatter
  *
  * @param  \PhpOffice\Common\XMLWriter         $objWriter    XML Writer
  * @param  \PhpOffice\PhpPresentation\Shape\Chart\Type\Scatter $subject
  * @param  boolean                                $includeSheet
  * @throws \Exception
  */
 protected function writeTypeScatter(XMLWriter $objWriter, Scatter $subject, $includeSheet = false)
 {
     // c:scatterChart
     $objWriter->startElement('c:scatterChart');
     // c:scatterStyle
     $objWriter->startElement('c:scatterStyle');
     $objWriter->writeAttribute('val', 'lineMarker');
     $objWriter->endElement();
     // c:varyColors
     $objWriter->startElement('c:varyColors');
     $objWriter->writeAttribute('val', '0');
     $objWriter->endElement();
     // Write series
     $seriesIndex = 0;
     foreach ($subject->getData() as $series) {
         // c:ser
         $objWriter->startElement('c:ser');
         // c:idx
         $objWriter->startElement('c:idx');
         $objWriter->writeAttribute('val', $seriesIndex);
         $objWriter->endElement();
         // c:order
         $objWriter->startElement('c:order');
         $objWriter->writeAttribute('val', $seriesIndex);
         $objWriter->endElement();
         // c:tx
         $objWriter->startElement('c:tx');
         $coords = $includeSheet ? 'Sheet1!$' . \PHPExcel_Cell::stringFromColumnIndex(1 + $seriesIndex) . '$1' : '';
         $this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords);
         $objWriter->endElement();
         // c:marker
         $objWriter->startElement('c:marker');
         // c:marker
         $objWriter->startElement('c:symbol');
         $objWriter->writeAttribute('val', 'none');
         // Marker style
         //$objWriter->writeAttribute('size', '7'); // Marker size
         $objWriter->endElement();
         $objWriter->endElement();
         // c:dLbls
         $objWriter->startElement('c:dLbls');
         // c:txPr
         $objWriter->startElement('c:txPr');
         // a:bodyPr
         $objWriter->writeElement('a:bodyPr', null);
         // a:lstStyle
         $objWriter->writeElement('a:lstStyle', null);
         // a:p
         $objWriter->startElement('a:p');
         // a:pPr
         $objWriter->startElement('a:pPr');
         // a:defRPr
         $objWriter->startElement('a:defRPr');
         $objWriter->writeAttribute('b', $series->getFont()->isBold() ? 'true' : 'false');
         $objWriter->writeAttribute('i', $series->getFont()->isItalic() ? 'true' : 'false');
         $objWriter->writeAttribute('strike', $series->getFont()->isStrikethrough() ? 'sngStrike' : 'noStrike');
         $objWriter->writeAttribute('sz', $series->getFont()->getSize() * 100);
         $objWriter->writeAttribute('u', $series->getFont()->getUnderline());
         if ($series->getFont()->isSuperScript() || $series->getFont()->isSubScript()) {
             if ($series->getFont()->isSuperScript()) {
                 $objWriter->writeAttribute('baseline', '30000');
             } elseif ($series->getFont()->isSubScript()) {
                 $objWriter->writeAttribute('baseline', '-25000');
             }
         }
         // Font - a:solidFill
         $objWriter->startElement('a:solidFill');
         // a:srgbClr
         $objWriter->startElement('a:srgbClr');
         $objWriter->writeAttribute('val', $series->getFont()->getColor()->getRGB());
         $objWriter->endElement();
         $objWriter->endElement();
         // Font - a:latin
         $objWriter->startElement('a:latin');
         $objWriter->writeAttribute('typeface', $series->getFont()->getName());
         $objWriter->endElement();
         $objWriter->endElement();
         $objWriter->endElement();
         // a:endParaRPr
         $objWriter->startElement('a:endParaRPr');
         $objWriter->writeAttribute('lang', 'en-US');
         $objWriter->writeAttribute('dirty', '0');
         $objWriter->endElement();
         $objWriter->endElement();
         $objWriter->endElement();
         // c:showLegendKey
         $this->writeElementWithValAttribute($objWriter, 'c:showLegendKey', '0');
         // c:showVal
         $this->writeElementWithValAttribute($objWriter, 'c:showVal', $series->hasShowValue() ? '1' : '0');
         // c:showCatName
         $this->writeElementWithValAttribute($objWriter, 'c:showCatName', $series->hasShowCategoryName() ? '1' : '0');
         // c:showSerName
         $this->writeElementWithValAttribute($objWriter, 'c:showSerName', $series->hasShowSeriesName() ? '1' : '0');
         // c:showPercent
         $this->writeElementWithValAttribute($objWriter, 'c:showPercent', $series->hasShowPercentage() ? '1' : '0');
         // c:showLeaderLines
         $this->writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->hasShowLeaderLines() ? '1' : '0');
         $objWriter->endElement();
         if ($series->getFill()->getFillType() != Fill::FILL_NONE) {
             // c:spPr
             $objWriter->startElement('c:spPr');
             // Write fill
             $this->writeFill($objWriter, $series->getFill());
             // ## c:spPr
             $objWriter->endElement();
         }
         // Write X axis data
         $axisXData = array_keys($series->getValues());
         // c:xVal
         $objWriter->startElement('c:xVal');
         $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisXData, 'Sheet1!$A$2:$A$' . (1 + count($axisXData)));
         $objWriter->endElement();
         // Write Y axis data
         $axisYData = array_values($series->getValues());
         // c:yVal
         $objWriter->startElement('c:yVal');
         $coords = $includeSheet ? 'Sheet1!$' . \PHPExcel_Cell::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . \PHPExcel_Cell::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : '';
         $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords);
         $objWriter->endElement();
         // c:smooth
         $objWriter->startElement('c:smooth');
         $objWriter->writeAttribute('val', '0');
         $objWriter->endElement();
         $objWriter->endElement();
         ++$seriesIndex;
     }
     // c:axId
     $objWriter->startElement('c:axId');
     $objWriter->writeAttribute('val', '52743552');
     $objWriter->endElement();
     // c:axId
     $objWriter->startElement('c:axId');
     $objWriter->writeAttribute('val', '52749440');
     $objWriter->endElement();
     $objWriter->endElement();
 }
Ejemplo n.º 7
0
 public function testTypeScatterSeriesOutline()
 {
     $expectedWidth = rand(1, 100);
     $expectedWidthCm = number_format(CommonDrawing::pointsToCentimeters($expectedWidth), 3, '.', '') . 'cm';
     $expectedElement = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleSeries0\'][@style:family=\'chart\']/style:graphic-properties';
     $oColor = new Color(Color::COLOR_YELLOW);
     $oOutline = new Outline();
     // Define the color
     $oOutline->getFill()->setFillType(Fill::FILL_SOLID);
     $oOutline->getFill()->setStartColor($oColor);
     // Define the width (in points)
     $oOutline->setWidth($expectedWidth);
     $oPhpPresentation = new PhpPresentation();
     $oSlide = $oPhpPresentation->getActiveSlide();
     $oShape = $oSlide->createChartShape();
     $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
     $oScatter = new Scatter();
     $oSeries = new Series('Downloads', array('A' => 1, 'B' => 2, 'C' => 4, 'D' => 3, 'E' => 2));
     $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->assertTrue($oXMLDoc->attributeElementExists($expectedElement, 'svg:stroke-width', 'Object 1/content.xml'));
     $this->assertEquals('0.079cm', $oXMLDoc->getElementAttribute($expectedElement, 'svg:stroke-width', 'Object 1/content.xml'));
     $this->assertTrue($oXMLDoc->attributeElementExists($expectedElement, 'svg:stroke-color', 'Object 1/content.xml'));
     $this->assertEquals('#4a7ebb', $oXMLDoc->getElementAttribute($expectedElement, 'svg:stroke-color', 'Object 1/content.xml'));
     $oSeries->setOutline($oOutline);
     $oScatter->setSeries(array($oSeries));
     $oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation');
     $this->assertTrue($oXMLDoc->fileExists('Object 1/content.xml'));
     $this->assertTrue($oXMLDoc->elementExists($expectedElement, 'Object 1/content.xml'));
     $this->assertTrue($oXMLDoc->attributeElementExists($expectedElement, 'svg:stroke-width', 'Object 1/content.xml'));
     $this->assertEquals($expectedWidthCm, $oXMLDoc->getElementAttribute($expectedElement, 'svg:stroke-width', 'Object 1/content.xml'));
     $this->assertTrue($oXMLDoc->attributeElementExists($expectedElement, 'svg:stroke-color', 'Object 1/content.xml'));
     $this->assertEquals('#' . $oColor->getRGB(), $oXMLDoc->getElementAttribute($expectedElement, 'svg:stroke-color', 'Object 1/content.xml'));
 }