Наследование: extends AbstractGraphic, implements PhpOffice\PhpPresentation\ComparableInterface
Пример #1
0
 public function testIncludeSpreadsheet()
 {
     $object = new Chart();
     $this->assertFalse($object->hasIncludedSpreadsheet());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart', $object->setIncludeSpreadsheet());
     $this->assertFalse($object->hasIncludedSpreadsheet());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart', $object->setIncludeSpreadsheet(false));
     $this->assertFalse($object->hasIncludedSpreadsheet());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart', $object->setIncludeSpreadsheet(true));
     $this->assertTrue($object->hasIncludedSpreadsheet());
 }
Пример #2
0
 /**
  * Write chart relationships to XML format
  *
  * @param  \PhpOffice\PhpPresentation\Shape\Chart $pChart
  * @return string                    XML Output
  * @throws \Exception
  */
 public function writeChartRelationships(ShapeChart $pChart)
 {
     // Create XML writer
     $objWriter = $this->getXMLWriter();
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8', 'yes');
     // Relationships
     $objWriter->startElement('Relationships');
     $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
     // Write spreadsheet relationship?
     if ($pChart->hasIncludedSpreadsheet()) {
         $this->writeRelationship($objWriter, 1, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/package', '../embeddings/' . $pChart->getIndexedFilename() . '.xlsx');
     }
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
Пример #3
0
 /**
  * @param Chart $chart
  */
 private function writeWallStyle(Chart $chart)
 {
     $chartType = $chart->getPlotArea()->getType();
     // style:style
     $this->xmlContent->startElement('style:style');
     $this->xmlContent->writeAttribute('style:name', 'styleWall');
     $this->xmlContent->writeAttribute('style:family', 'chart');
     // style:chart-properties
     $this->xmlContent->startElement('style:graphic-properties');
     //@todo : Permit edit color and size border of wall
     if ($chartType instanceof Line || $chartType instanceof Scatter) {
         $this->xmlContent->writeAttribute('draw:fill', 'solid');
         $this->xmlContent->writeAttribute('draw:fill-color', '#FFFFFF');
     } else {
         $this->xmlContent->writeAttribute('draw:fill', 'none');
         $this->xmlContent->writeAttribute('draw:stroke', 'solid');
         $this->xmlContent->writeAttribute('svg:stroke-width', '0.026cm');
         $this->xmlContent->writeAttribute('svg:stroke-color', '#878787');
     }
     // > style:chart-properties
     $this->xmlContent->endElement();
     // > style:style
     $this->xmlContent->endElement();
 }
Пример #4
0
 /**
  * Write chart
  *
  * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer
  * @param \PhpOffice\PhpPresentation\Shape\Chart $shape
  * @param  int $shapeId
  */
 private function writeShapeChart(XMLWriter $objWriter, ShapeChart $shape, $shapeId)
 {
     // p:graphicFrame
     $objWriter->startElement('p:graphicFrame');
     // p:nvGraphicFramePr
     $objWriter->startElement('p:nvGraphicFramePr');
     // p:cNvPr
     $objWriter->startElement('p:cNvPr');
     $objWriter->writeAttribute('id', $shapeId);
     $objWriter->writeAttribute('name', $shape->getName());
     $objWriter->writeAttribute('descr', $shape->getDescription());
     $objWriter->endElement();
     // p:cNvGraphicFramePr
     $objWriter->writeElement('p:cNvGraphicFramePr', null);
     // p:nvPr
     $objWriter->writeElement('p:nvPr', null);
     $objWriter->endElement();
     // p:xfrm
     $objWriter->startElement('p:xfrm');
     $objWriter->writeAttribute('rot', CommonDrawing::degreesToAngle($shape->getRotation()));
     // a:off
     $objWriter->startElement('a:off');
     $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX()));
     $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY()));
     $objWriter->endElement();
     // a:ext
     $objWriter->startElement('a:ext');
     $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($shape->getWidth()));
     $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($shape->getHeight()));
     $objWriter->endElement();
     $objWriter->endElement();
     // a:graphic
     $objWriter->startElement('a:graphic');
     // a:graphicData
     $objWriter->startElement('a:graphicData');
     $objWriter->writeAttribute('uri', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
     // c:chart
     $objWriter->startElement('c:chart');
     $objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
     $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
     $objWriter->writeAttribute('r:id', $shape->relationId);
     $objWriter->endElement();
     $objWriter->endElement();
     $objWriter->endElement();
     $objWriter->endElement();
 }
Пример #5
0
 /**
  * Write table Chart
  * @param XMLWriter $objWriter
  * @param Chart $shape
  */
 public function writeShapeChart(XMLWriter $objWriter, Chart $shape)
 {
     $parentWriter = $this->getParentWriter();
     if (!$parentWriter instanceof ODPresentation) {
         throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPresentation\\Writer\\ODPresentation');
     }
     $parentWriter->chartArray[$this->shapeId] = $shape;
     // draw:frame
     $objWriter->startElement('draw:frame');
     $objWriter->writeAttribute('draw:name', $shape->getTitle()->getText());
     $objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm');
     $objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm');
     $objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm');
     $objWriter->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm');
     // draw:object
     $objWriter->startElement('draw:object');
     $objWriter->writeAttribute('xlink:href', './Object ' . $this->shapeId);
     $objWriter->writeAttribute('xlink:type', 'simple');
     $objWriter->writeAttribute('xlink:show', 'embed');
     // > draw:object
     $objWriter->endElement();
     // > draw:frame
     $objWriter->endElement();
 }
Пример #6
0
 /**
  * Write Plot Area
  *
  * @param  \PhpOffice\Common\XMLWriter     $objWriter XML Writer
  * @param  \PhpOffice\PhpPresentation\Shape\Chart\PlotArea $subject
  * @param  \PhpOffice\PhpPresentation\Shape\Chart          $chart
  * @throws \Exception
  */
 protected function writePlotArea(XMLWriter $objWriter, PlotArea $subject, ShapeChart $chart)
 {
     // c:plotArea
     $objWriter->startElement('c:plotArea');
     // Write layout
     $this->writeLayout($objWriter, $subject);
     // Write chart
     $chartType = $subject->getType();
     if ($chartType instanceof Area) {
         $this->writeTypeArea($objWriter, $chartType, $chart->hasIncludedSpreadsheet());
     } elseif ($chartType instanceof Bar) {
         $this->writeTypeBar($objWriter, $chartType, $chart->hasIncludedSpreadsheet());
     } elseif ($chartType instanceof Bar3D) {
         $this->writeTypeBar3D($objWriter, $chartType, $chart->hasIncludedSpreadsheet());
     } elseif ($chartType instanceof Pie) {
         $this->writeTypePie($objWriter, $chartType, $chart->hasIncludedSpreadsheet());
     } elseif ($chartType instanceof Pie3D) {
         $this->writeTypePie3D($objWriter, $chartType, $chart->hasIncludedSpreadsheet());
     } elseif ($chartType instanceof Line) {
         $this->writeTypeLine($objWriter, $chartType, $chart->hasIncludedSpreadsheet());
     } elseif ($chartType instanceof Scatter) {
         $this->writeTypeScatter($objWriter, $chartType, $chart->hasIncludedSpreadsheet());
     } else {
         throw new \Exception('The chart type provided could not be rendered.');
     }
     // Write X axis?
     if ($chartType->hasAxisX()) {
         // c:catAx (Axis X)
         $objWriter->startElement('c:catAx');
         // c:axId
         $objWriter->startElement('c:axId');
         $objWriter->writeAttribute('val', '52743552');
         $objWriter->endElement();
         // c:scaling
         $objWriter->startElement('c:scaling');
         // c:orientation
         $objWriter->startElement('c:orientation');
         $objWriter->writeAttribute('val', 'minMax');
         $objWriter->endElement();
         $objWriter->endElement();
         // c:axPos
         $objWriter->startElement('c:axPos');
         $objWriter->writeAttribute('val', 'b');
         $objWriter->endElement();
         // c:numFmt
         $objWriter->startElement('c:numFmt');
         $objWriter->writeAttribute('formatCode', $subject->getAxisX()->getFormatCode());
         $objWriter->writeAttribute('sourceLinked', '0');
         $objWriter->endElement();
         // c:majorTickMark
         $objWriter->startElement('c:majorTickMark');
         $objWriter->writeAttribute('val', 'none');
         $objWriter->endElement();
         // c:tickLblPos
         $objWriter->startElement('c:tickLblPos');
         $objWriter->writeAttribute('val', 'nextTo');
         $objWriter->endElement();
         // 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->writeElement('a:defRPr', null);
         $objWriter->endElement();
         // a:r
         $objWriter->startElement('a:r');
         // a:rPr
         $objWriter->startElement('a:rPr');
         $objWriter->writeAttribute('lang', 'en-US');
         $objWriter->writeAttribute('dirty', '0');
         $objWriter->endElement();
         // a:t
         $objWriter->writeElement('a:t', $subject->getAxisX()->getTitle());
         $objWriter->endElement();
         // a:endParaRPr
         $objWriter->startElement('a:endParaRPr');
         $objWriter->writeAttribute('lang', 'en-US');
         $objWriter->writeAttribute('dirty', '0');
         $objWriter->endElement();
         $objWriter->endElement();
         $objWriter->endElement();
         // c:crossAx
         $objWriter->startElement('c:crossAx');
         $objWriter->writeAttribute('val', '52749440');
         $objWriter->endElement();
         // c:crosses
         $objWriter->startElement('c:crosses');
         $objWriter->writeAttribute('val', 'autoZero');
         $objWriter->endElement();
         // c:lblAlgn
         $objWriter->startElement('c:lblAlgn');
         $objWriter->writeAttribute('val', 'ctr');
         $objWriter->endElement();
         // c:lblOffset
         $objWriter->startElement('c:lblOffset');
         $objWriter->writeAttribute('val', '100');
         $objWriter->endElement();
         $objWriter->endElement();
     }
     // Write Y axis?
     if ($chartType->hasAxisY()) {
         // c:valAx (Axis Y)
         $objWriter->startElement('c:valAx');
         // c:axId
         $objWriter->startElement('c:axId');
         $objWriter->writeAttribute('val', '52749440');
         $objWriter->endElement();
         // c:scaling
         $objWriter->startElement('c:scaling');
         // c:orientation
         $objWriter->startElement('c:orientation');
         $objWriter->writeAttribute('val', 'minMax');
         $objWriter->endElement();
         // ## c:scaling
         $objWriter->endElement();
         // c:axPos
         $objWriter->startElement('c:axPos');
         $objWriter->writeAttribute('val', 'l');
         $objWriter->endElement();
         // c:numFmt
         $objWriter->startElement('c:numFmt');
         $objWriter->writeAttribute('formatCode', $subject->getAxisY()->getFormatCode());
         $objWriter->writeAttribute('sourceLinked', '0');
         $objWriter->endElement();
         // c:majorTickMark
         $objWriter->startElement('c:majorTickMark');
         $objWriter->writeAttribute('val', 'none');
         $objWriter->endElement();
         // c:tickLblPos
         $objWriter->startElement('c:tickLblPos');
         $objWriter->writeAttribute('val', 'nextTo');
         $objWriter->endElement();
         // 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->writeElement('a:defRPr', null);
         // ## a:pPr
         $objWriter->endElement();
         // a:r
         $objWriter->startElement('a:r');
         // a:rPr
         $objWriter->startElement('a:rPr');
         $objWriter->writeAttribute('lang', 'en-US');
         $objWriter->writeAttribute('dirty', '0');
         $objWriter->endElement();
         // a:t
         $objWriter->writeElement('a:t', $subject->getAxisY()->getTitle());
         // ## a:r
         $objWriter->endElement();
         // a:endParaRPr
         $objWriter->startElement('a:endParaRPr');
         $objWriter->writeAttribute('lang', 'en-US');
         $objWriter->writeAttribute('dirty', '0');
         $objWriter->endElement();
         // ## a:p
         $objWriter->endElement();
         // ## c:txPr
         $objWriter->endElement();
         // c:crossAx
         $objWriter->startElement('c:crossAx');
         $objWriter->writeAttribute('val', '52743552');
         $objWriter->endElement();
         // c:crosses
         $objWriter->startElement('c:crosses');
         $objWriter->writeAttribute('val', 'autoZero');
         $objWriter->endElement();
         // c:crossBetween
         $objWriter->startElement('c:crossBetween');
         $objWriter->writeAttribute('val', 'between');
         $objWriter->endElement();
         $objWriter->endElement();
     }
     $objWriter->endElement();
 }
Пример #7
0
 /**
  * Write table Chart
  * @param XMLWriter $objWriter
  * @param Chart $shape
  * @throws \Exception
  */
 public function writeShapeChart(XMLWriter $objWriter, Chart $shape)
 {
     $arrayChart = $this->getArrayChart();
     $arrayChart[$this->shapeId] = $shape;
     $this->setArrayChart($arrayChart);
     // draw:frame
     $objWriter->startElement('draw:frame');
     $objWriter->writeAttribute('draw:name', $shape->getTitle()->getText());
     $objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm');
     $objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm');
     $objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm');
     $objWriter->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm');
     // draw:object
     $objWriter->startElement('draw:object');
     $objWriter->writeAttribute('xlink:href', './Object ' . $this->shapeId);
     $objWriter->writeAttribute('xlink:type', 'simple');
     $objWriter->writeAttribute('xlink:show', 'embed');
     // > draw:object
     $objWriter->endElement();
     // > draw:frame
     $objWriter->endElement();
 }