();
}
/**
@@ -74,6 +78,7 @@ public class XSSFScatterChartData implements ScatterChartData {
* Returns data source used for X axis values.
* @return data source used for X axis values
*/
+ @Override
public ChartDataSource> getXValues() {
return xs;
}
@@ -82,6 +87,7 @@ public class XSSFScatterChartData implements ScatterChartData {
* Returns data source used for Y axis values.
* @return data source used for Y axis values
*/
+ @Override
public ChartDataSource extends Number> getYValues() {
return ys;
}
@@ -103,6 +109,7 @@ public class XSSFScatterChartData implements ScatterChartData {
}
}
+ @Override
public ScatterChartSeries addSerie(ChartDataSource> xs,
ChartDataSource extends Number> ys) {
if (!ys.isNumeric()) {
@@ -114,6 +121,7 @@ public class XSSFScatterChartData implements ScatterChartData {
return newSerie;
}
+ @Override
public void fillChart(Chart chart, ChartAxis... axis) {
if (!(chart instanceof XSSFChart)) {
throw new IllegalArgumentException("Chart must be instance of XSSFChart");
@@ -133,6 +141,7 @@ public class XSSFScatterChartData implements ScatterChartData {
}
}
+ @Override
public List extends Series> getSeries() {
return series;
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFValueAxis.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFValueAxis.java
index 3dea67ddb4..14f16d4a11 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFValueAxis.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFValueAxis.java
@@ -24,8 +24,9 @@ import org.apache.poi.ss.usermodel.charts.AxisPosition;
import org.apache.poi.ss.usermodel.charts.AxisTickMark;
import org.apache.poi.ss.usermodel.charts.ChartAxis;
import org.apache.poi.ss.usermodel.charts.ValueAxis;
-import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Removal;
+import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
import org.apache.poi.xssf.usermodel.XSSFChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBoolean;
@@ -42,9 +43,10 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
/**
* Value axis type.
*
- * @author Roman Kashitsyn
+ * @deprecated use {@link XDDFValueAxis} instead
*/
-@Beta
+@Deprecated
+@Removal(version="4.2")
public class XSSFValueAxis extends XSSFChartAxis implements ValueAxis {
private CTValAx ctValAx;
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFChart.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFChart.java
index e7df6ec69f..dbc68c2155 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFChart.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFChart.java
@@ -22,39 +22,23 @@ import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.Arrays;
import javax.xml.namespace.QName;
-import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.POIXMLException;
-import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.util.Beta;
import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.Internal;
+import org.apache.poi.xddf.usermodel.chart.XDDFChart;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
-import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument;
/**
* Represents a Chart in a .docx file
*/
@Beta
-public class XWPFChart extends POIXMLDocumentPart {
-
- /**
- * Root element of the Chart part
- */
- private final CTChartSpace chartSpace;
-
- /**
- * The Chart within that
- */
- private final CTChart chart;
+public class XWPFChart extends XDDFChart {
// lazy initialization
private Long checksum;
@@ -64,39 +48,11 @@ public class XWPFChart extends POIXMLDocumentPart {
*
* @param part the package part holding the chart data,
* the content type must be application/vnd.openxmlformats-officedocument.drawingml.chart+xml
- *
+ *
* @since POI 4.0.0
*/
protected XWPFChart(PackagePart part) throws IOException, XmlException {
super(part);
-
- chartSpace = ChartSpaceDocument.Factory.parse(part.getInputStream(), DEFAULT_XML_OPTIONS).getChartSpace();
- chart = chartSpace.getChart();
- }
-
- @Override
- protected void onDocumentRead() throws IOException {
- super.onDocumentRead();
- }
-
- /**
- * Return the underlying CTChartSpace bean, the root element of the Chart part.
- *
- * @return the underlying CTChartSpace bean
- */
- @Internal
- public CTChartSpace getCTChartSpace() {
- return chartSpace;
- }
-
- /**
- * Return the underlying CTChart bean, within the Chart Space
- *
- * @return the underlying CTChart bean
- */
- @Internal
- public CTChart getCTChart() {
- return chart;
}
@Override
@@ -108,7 +64,7 @@ public class XWPFChart extends POIXMLDocumentPart {
chartSpace.save(out, xmlOptions);
}
}
-
+
public Long getChecksum() {
if (this.checksum == null) {
InputStream is = null;
@@ -120,7 +76,9 @@ public class XWPFChart extends POIXMLDocumentPart {
throw new POIXMLException(e);
} finally {
try {
- if (is != null) is.close();
+ if (is != null) {
+ is.close();
+ }
} catch (IOException e) {
throw new POIXMLException(e);
}
@@ -157,7 +115,7 @@ public class XWPFChart extends POIXMLDocumentPart {
}
return false;
}
-
+
@Override
public int hashCode() {
return getChecksum().hashCode();
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
index e63b98995d..2b3c3eda7b 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
@@ -63,7 +63,27 @@ import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTComment;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CommentsDocument;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.EndnotesDocument;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.FootnotesDocument;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.NumberingDocument;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
/**
* High(ish) level class for working with .docx files.
@@ -79,7 +99,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
*/
public class XWPFDocument extends POIXMLDocument implements Document, IBody {
private static final POILogger LOG = POILogFactory.getLogger(XWPFDocument.class);
-
+
protected List footers = new ArrayList<>();
protected List headers = new ArrayList<>();
protected List comments = new ArrayList<>();
@@ -186,8 +206,9 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
}
docCursor.dispose();
// Sort out headers and footers
- if (doc.getDocument().getBody().getSectPr() != null)
+ if (doc.getDocument().getBody().getSectPr() != null) {
headerFooterPolicy = new XWPFHeaderFooterPolicy(this);
+ }
// Create for each XML-part in the Package a PartClass
for (RelationPart rp : getRelationParts()) {
@@ -224,7 +245,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
} else if (relation.equals(XWPFRelation.CHART.getRelation())) {
//now we can use all methods to modify charts in XWPFDocument
XWPFChart chartData = (XWPFChart) p;
- chartData.onDocumentRead();
+// chartData.onDocumentRead(); // ??? there is nothing to be done there!!!
charts.add(chartData);
} else if (relation.equals(XWPFRelation.GLOSSARY_DOCUMENT.getRelation())) {
// We don't currently process the glossary itself
@@ -380,20 +401,25 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
public XWPFHyperlink getHyperlinkByID(String id) {
for (XWPFHyperlink link : hyperlinks) {
- if (link.getId().equals(id))
+ if (link.getId().equals(id)) {
return link;
+ }
}
return null;
}
public XWPFFootnote getFootnoteByID(int id) {
- if (footnotes == null) return null;
+ if (footnotes == null) {
+ return null;
+ }
return footnotes.getFootnoteById(id);
}
public XWPFFootnote getEndnoteByID(int id) {
- if (endnotes == null) return null;
+ if (endnotes == null) {
+ return null;
+ }
return endnotes.get(id);
}
@@ -410,8 +436,9 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
public XWPFComment getCommentByID(String id) {
for (XWPFComment comment : comments) {
- if (comment.getId().equals(id))
+ if (comment.getId().equals(id)) {
return comment;
+ }
}
return null;
@@ -450,7 +477,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
}
return headerFooterPolicy;
}
-
+
/**
* Create a header of the given type
*
@@ -471,8 +498,8 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
}
return hfPolicy.createHeader(STHdrFtr.Enum.forInt(type.toInt()));
}
-
-
+
+
/**
* Create a footer of the given type
*
@@ -619,7 +646,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
String uri = CTP.type.getName().getNamespaceURI();
/*
* TODO DO not use a coded constant, find the constant in the OOXML
- * classes instead, as the child of type CT_Paragraph is defined in the
+ * classes instead, as the child of type CT_Paragraph is defined in the
* OOXML schema as 'p'
*/
String localPart = "p";
@@ -667,8 +694,9 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
cursor.toCursor(newParaPos);
while (cursor.toPrevSibling()) {
o = cursor.getObject();
- if (o instanceof CTP || o instanceof CTTbl)
+ if (o instanceof CTP || o instanceof CTTbl) {
i++;
+ }
}
bodyElements.add(i, newP);
cursor.toCursor(newParaPos);
@@ -706,8 +734,9 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
cursor.toCursor(tableCursor);
while (cursor.toPrevSibling()) {
o = cursor.getObject();
- if (o instanceof CTP || o instanceof CTTbl)
+ if (o instanceof CTP || o instanceof CTTbl) {
i++;
+ }
}
bodyElements.add(i, newT);
cursor.toCursor(tableCursor);
@@ -984,7 +1013,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
tables.set(pos, table);
ctDocument.getBody().setTblArray(pos, table.getCTTbl());
}
-
+
/**
* Verifies that the documentProtection tag in settings.xml file
* specifies that the protection is enforced (w:enforcement="1")
@@ -1288,7 +1317,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
public void setZoomPercent(long zoomPercent) {
settings.setZoomPercent(zoomPercent);
}
-
+
/**
* inserts an existing XWPFTable to the arrays bodyElements and tables
*
@@ -1378,7 +1407,9 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
throw new POIXMLException(e);
} finally {
try {
- if (out != null) out.close();
+ if (out != null) {
+ out.close();
+ }
} catch (IOException e) {
// ignore
}
diff --git a/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFDataSourcesFactory.java b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFDataSourcesFactory.java
new file mode 100644
index 0000000000..f6c547cb15
--- /dev/null
+++ b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFDataSourcesFactory.java
@@ -0,0 +1,134 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.xddf.usermodel.chart;
+
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.ss.util.SheetBuilder;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link XDDFDataSourcesFactory}.
+ */
+public class TestXDDFDataSourcesFactory extends TestCase {
+
+ private static final Object[][] numericCells = {
+ {0.0, 1.0, 2.0, 3.0, 4.0},
+ {0.0, "=B1*2", "=C1*2", "=D1*2", "=E1*2"}
+ };
+
+ private static final Object[][] stringCells = {
+ { 1, 2, 3, 4, 5},
+ {"A", "B", "C", "D", "E"}
+ };
+
+ private static final Object[][] mixedCells = {
+ {1.0, "2.0", 3.0, "4.0", 5.0, "6.0"}
+ };
+
+ public void testNumericArrayDataSource() {
+ Double[] doubles = new Double[]{1.0, 2.0, 3.0, 4.0, 5.0};
+ XDDFDataSource doubleDataSource = XDDFDataSourcesFactory.fromArray(doubles, null);
+ assertTrue(doubleDataSource.isNumeric());
+ assertFalse(doubleDataSource.isReference());
+ assertDataSourceIsEqualToArray(doubleDataSource, doubles);
+ }
+
+ public void testStringArrayDataSource() {
+ String[] strings = new String[]{"one", "two", "three", "four", "five"};
+ XDDFDataSource stringDataSource = XDDFDataSourcesFactory.fromArray(strings, null);
+ assertFalse(stringDataSource.isNumeric());
+ assertFalse(stringDataSource.isReference());
+ assertDataSourceIsEqualToArray(stringDataSource, strings);
+ }
+
+ public void testNumericCellDataSource() {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, numericCells).build();
+ CellRangeAddress numCellRange = CellRangeAddress.valueOf("A2:E2");
+ XDDFDataSource numDataSource = XDDFDataSourcesFactory.fromNumericCellRange(sheet, numCellRange);
+ assertTrue(numDataSource.isReference());
+ assertTrue(numDataSource.isNumeric());
+ assertEquals(numericCells[0].length, numDataSource.getPointCount());
+ for (int i = 0; i < numericCells[0].length; ++i) {
+ assertEquals(((Double) numericCells[0][i]) * 2,
+ numDataSource.getPointAt(i), 0.00001);
+ }
+ }
+
+ public void testStringCellDataSource() {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, stringCells).build();
+ CellRangeAddress numCellRange = CellRangeAddress.valueOf("A2:E2");
+ XDDFDataSource numDataSource = XDDFDataSourcesFactory.fromStringCellRange(sheet, numCellRange);
+ assertTrue(numDataSource.isReference());
+ assertFalse(numDataSource.isNumeric());
+ assertEquals(numericCells[0].length, numDataSource.getPointCount());
+ for (int i = 0; i < stringCells[1].length; ++i) {
+ assertEquals(stringCells[1][i], numDataSource.getPointAt(i));
+ }
+ }
+
+ public void testMixedCellDataSource() {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, mixedCells).build();
+ CellRangeAddress mixedCellRange = CellRangeAddress.valueOf("A1:F1");
+ XDDFDataSource strDataSource = XDDFDataSourcesFactory.fromStringCellRange(sheet, mixedCellRange);
+ XDDFDataSource numDataSource = XDDFDataSourcesFactory.fromNumericCellRange(sheet, mixedCellRange);
+ for (int i = 0; i < mixedCells[0].length; ++i) {
+ if (i % 2 == 0) {
+ assertNull(strDataSource.getPointAt(i));
+ assertEquals(((Double) mixedCells[0][i]),
+ numDataSource.getPointAt(i), 0.00001);
+ } else {
+ assertNull(numDataSource.getPointAt(i));
+ assertEquals(mixedCells[0][i], strDataSource.getPointAt(i));
+ }
+ }
+ }
+
+ public void testIOBExceptionOnInvalidIndex() {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, numericCells).build();
+ CellRangeAddress rangeAddress = CellRangeAddress.valueOf("A2:E2");
+ XDDFDataSource numDataSource = XDDFDataSourcesFactory.fromNumericCellRange(sheet, rangeAddress);
+ IndexOutOfBoundsException exception = null;
+ try {
+ numDataSource.getPointAt(-1);
+ } catch (IndexOutOfBoundsException e) {
+ exception = e;
+ }
+ assertNotNull(exception);
+
+ exception = null;
+ try {
+ numDataSource.getPointAt(numDataSource.getPointCount());
+ } catch (IndexOutOfBoundsException e) {
+ exception = e;
+ }
+ assertNotNull(exception);
+ }
+
+ private void assertDataSourceIsEqualToArray(XDDFDataSource ds, T[] array) {
+ assertEquals(ds.getPointCount(), array.length);
+ for (int i = 0; i < array.length; ++i) {
+ assertEquals(ds.getPointAt(i), array[i]);
+ }
+ }
+}
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java
index e5f531dd38..5a66e41f8d 100644
--- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java
+++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java
@@ -18,44 +18,151 @@
*/
package org.apache.poi.xslf.usermodel;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
-import java.io.OutputStream;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import java.util.List;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.xddf.usermodel.chart.AxisCrossBetween;
+import org.apache.poi.xddf.usermodel.chart.AxisCrosses;
+import org.apache.poi.xddf.usermodel.chart.AxisOrientation;
+import org.apache.poi.xddf.usermodel.chart.AxisPosition;
+import org.apache.poi.xddf.usermodel.chart.AxisTickMark;
+import org.apache.poi.xddf.usermodel.chart.BarDirection;
+import org.apache.poi.xddf.usermodel.chart.BarGrouping;
+import org.apache.poi.xddf.usermodel.chart.Grouping;
+import org.apache.poi.xddf.usermodel.chart.LayoutMode;
+import org.apache.poi.xddf.usermodel.chart.LayoutTarget;
+import org.apache.poi.xddf.usermodel.chart.LegendPosition;
+import org.apache.poi.xddf.usermodel.chart.RadarStyle;
+import org.apache.poi.xddf.usermodel.chart.ScatterStyle;
+import org.apache.poi.xddf.usermodel.chart.XDDFBarChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartLegend;
+import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
+import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory;
+import org.apache.poi.xddf.usermodel.chart.XDDFLineChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFManualLayout;
+import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
+import org.apache.poi.xddf.usermodel.chart.XDDFPieChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFRadarChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFScatterChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
import org.apache.poi.xslf.XSLFTestDataSamples;
-import org.apache.poi.xssf.usermodel.XSSFRow;
-import org.apache.poi.xssf.usermodel.XSSFSheet;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumData;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumVal;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieChart;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieSer;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrData;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrVal;
+/**
+ * a modified version from POI-examples
+ */
public class TestXSLFChart {
-
- /**
- * a modified version from POI-examples
- */
@Test
- public void testFillChartTemplate() throws IOException {
-
- String chartTitle = "Apache POI"; // first line is chart title
-
+ public void testFillPieChartTemplate() throws IOException {
XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument("pie-chart.pptx");
- XSLFSlide slide = pptx.getSlides().get(0);
+ XSLFChart chart = findChart(pptx.getSlides().get(0));
+ List data = findChartData(chart);
+ XDDFPieChartData pie = (XDDFPieChartData) data.get(0);
+ XDDFPieChartData.Series firstSeries = (XDDFPieChartData.Series) pie.getSeries().get(0);
+ firstSeries.setExplosion(25);
+ assertEquals(25, firstSeries.getExplosion());
+
+ fillChartData(chart, pie);
+ pptx.close();
+ }
+
+ @Test
+ public void testFillBarChartTemplate() throws IOException {
+ XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument("bar-chart.pptx");
+ XSLFSlide slide = pptx.getSlides().get(0);
+ // duplicate slide and chart before applying "destructive" tests to it
+ XSLFChart chart2 = findChart(pptx.createSlide().importContent(slide));
+ XSLFChart chart = findChart(slide);
+
+ List data = findChartData(chart);
+ XDDFBarChartData bar = (XDDFBarChartData) data.get(0);
+ assertEquals(BarDirection.BAR, bar.getBarDirection());
+ assertEquals(BarGrouping.CLUSTERED, bar.getBarGrouping());
+ assertEquals(100, bar.getGapWidth());
+ fillChartData(chart, bar);
+
+ XDDFBarChartData column = (XDDFBarChartData) findChartData(chart2).get(0);
+ column.setBarDirection(BarDirection.COL);
+ assertEquals(BarDirection.COL, column.getBarDirection());
+ column.getCategoryAxis().setOrientation(AxisOrientation.MIN_MAX);
+ column.getValueAxes().get(0).setPosition(AxisPosition.BOTTOM);
+ fillChartData(chart2, column);
+
+ pptx.close();
+ }
+
+ @Test
+ public void testFillLineChartTemplate() throws IOException {
+ XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument("line-chart.pptx");
+ XSLFChart chart = findChart(pptx.getSlides().get(0));
+ List data = findChartData(chart);
+
+ XDDFLineChartData line = (XDDFLineChartData) data.get(0);
+ assertEquals(Grouping.STANDARD, line.getGrouping());
+ line.setGrouping(Grouping.PERCENT_STACKED);
+ assertEquals(Grouping.PERCENT_STACKED, line.getGrouping());
+
+ fillChartData(chart, line);
+ pptx.close();
+ }
+
+ @Test
+ public void testFillRadarChartTemplate() throws IOException {
+ XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument("radar-chart.pptx");
+ XSLFChart chart = findChart(pptx.getSlides().get(0));
+ List data = findChartData(chart);
+
+ XDDFRadarChartData radar = (XDDFRadarChartData) data.get(0);
+ assertEquals(RadarStyle.MARKER, radar.getStyle());
+ radar.setStyle(RadarStyle.FILLED);
+ assertEquals(RadarStyle.FILLED, radar.getStyle());
+
+ fillChartData(chart, radar);
+ pptx.close();
+ }
+
+ @Test
+ public void testFillScatterChartTemplate() throws IOException {
+ XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument("scatter-chart.pptx");
+ XSLFChart chart = findChart(pptx.getSlides().get(0));
+ List data = findChartData(chart);
+
+ XDDFScatterChartData scatter = (XDDFScatterChartData) data.get(0);
+ assertEquals(ScatterStyle.LINE_MARKER, scatter.getStyle());
+ scatter.setStyle(ScatterStyle.SMOOTH);
+ assertEquals(ScatterStyle.SMOOTH, scatter.getStyle());
+
+ fillChartData(chart, scatter);
+ pptx.close();
+ }
+
+ private void fillChartData(XSLFChart chart, XDDFChartData data) {
+ final int numOfPoints = 3;
+ final String[] categories = {"First", "Second", "Third"};
+ final Integer[] values = {1, 3, 4};
+
+ final String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));
+ final String valuesDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 1, 1));
+
+ final XDDFChartData.Series series = data.getSeries().get(0);
+ final XDDFDataSource> categoryData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange);
+ final XDDFNumericalDataSource valuesData = XDDFDataSourcesFactory.fromArray(values, valuesDataRange);
+ series.replaceData(categoryData, valuesData);
+ final String title = "Apache POI";
+ series.setTitle(title, chart.setSheetTitle(title));
+ chart.plot(data);
+ }
+
+ private XSLFChart findChart(XSLFSlide slide) {
// find chart in the slide
XSLFChart chart = null;
for(POIXMLDocumentPart part : slide.getRelations()){
@@ -65,76 +172,161 @@ public class TestXSLFChart {
}
}
- if(chart == null) throw new IllegalStateException("chart not found in the template");
-
- // embedded Excel workbook that holds the chart data
- POIXMLDocumentPart xlsPart = chart.getRelations().get(0);
- XSSFWorkbook wb = new XSSFWorkbook();
- XSSFSheet sheet = wb.createSheet();
-
- CTChart ctChart = chart.getCTChart();
- CTPlotArea plotArea = ctChart.getPlotArea();
-
- CTPieChart pieChart = plotArea.getPieChartArray(0);
- //Pie Chart Series
- CTPieSer ser = pieChart.getSerArray(0);
-
- // Series Text
- CTSerTx tx = ser.getTx();
- tx.getStrRef().getStrCache().getPtArray(0).setV(chartTitle);
- sheet.createRow(0).createCell(1).setCellValue(chartTitle);
- String titleRef = new CellReference(sheet.getSheetName(), 0, 1, true, true).formatAsString();
- tx.getStrRef().setF(titleRef);
-
-
- // Category Axis Data
- CTAxDataSource cat = ser.getCat();
- CTStrData strData = cat.getStrRef().getStrCache();
-
- // Values
- CTNumDataSource valSrc = ser.getVal();
- CTNumData numData = valSrc.getNumRef().getNumCache();
-
- strData.setPtArray(null); // unset old axis text
- numData.setPtArray(null); // unset old values
-
- Map pieModel = new LinkedHashMap<>();
- pieModel.put("First", 1.0);
- pieModel.put("Second", 3.0);
- pieModel.put("Third", 4.0);
-
- // set model
- int idx = 0;
- int rownum = 1;
- for(String key : pieModel.keySet()){
- double val = pieModel.get(key);
-
- CTNumVal numVal = numData.addNewPt();
- numVal.setIdx(idx);
- numVal.setV("" + val);
-
- CTStrVal sVal = strData.addNewPt();
- sVal.setIdx(idx);
- sVal.setV(key);
-
- idx++;
- XSSFRow row = sheet.createRow(rownum++);
- row.createCell(0).setCellValue(key);
- row.createCell(1).setCellValue(val);
+ if(chart == null) {
+ throw new IllegalStateException("chart not found in the template");
}
- numData.getPtCount().setVal(idx);
- strData.getPtCount().setVal(idx);
- String numDataRange = new CellRangeAddress(1, rownum-1, 1, 1).formatAsString(sheet.getSheetName(), true);
- valSrc.getNumRef().setF(numDataRange);
- String axisDataRange = new CellRangeAddress(1, rownum-1, 0, 0).formatAsString(sheet.getSheetName(), true);
- cat.getStrRef().setF(axisDataRange);
-
- // updated the embedded workbook with the data
- OutputStream xlsOut = xlsPart.getPackagePart().getOutputStream();
- wb.write(xlsOut);
- xlsOut.close();
- wb.close();
+ checkLegendOperations(chart);
+ return chart;
}
-}
\ No newline at end of file
+ private List findChartData(XSLFChart chart) {
+ List data = chart.getChartSeries();
+ assertNotNull(data);
+ assertEquals(1, data.size());
+
+ XDDFChartData firstSeries = data.get(0);
+ assertNotNull(firstSeries);
+ if (firstSeries instanceof XDDFScatterChartData) {
+ assertEquals(null, firstSeries.getCategoryAxis());
+ assertEquals(2, firstSeries.getValueAxes().size());
+ checkAxisOperations(firstSeries.getValueAxes().get(0));
+ checkAxisOperations(firstSeries.getValueAxes().get(1));
+ } else if (!(firstSeries instanceof XDDFPieChartData)) {
+ assertNotNull(firstSeries.getCategoryAxis());
+ assertEquals(1, firstSeries.getValueAxes().size());
+ checkAxisOperations(firstSeries.getValueAxes().get(0));
+ }
+
+ return data;
+ }
+
+ private void checkLegendOperations(XSLFChart chart) {
+ XDDFChartLegend legend = chart.getOrAddLegend();
+ assertFalse(legend.isOverlay());
+ legend.setOverlay(true);
+ assertTrue(legend.isOverlay());
+ legend.setPosition(LegendPosition.TOP_RIGHT);
+ assertEquals(LegendPosition.TOP_RIGHT, legend.getPosition());
+
+ XDDFManualLayout layout = legend.getOrAddManualLayout();
+ assertNotNull(layout.getTarget());
+ assertNotNull(layout.getXMode());
+ assertNotNull(layout.getYMode());
+ assertNotNull(layout.getHeightMode());
+ assertNotNull(layout.getWidthMode());
+ /*
+ * According to interface, 0.0 should be returned for
+ * uninitialized double properties.
+ */
+ assertTrue(layout.getX() == 0.0);
+ assertTrue(layout.getY() == 0.0);
+ assertTrue(layout.getWidthRatio() == 0.0);
+ assertTrue(layout.getHeightRatio() == 0.0);
+
+ final double newRatio = 1.1;
+ final double newCoordinate = 0.3;
+ final LayoutMode nonDefaultMode = LayoutMode.FACTOR;
+ final LayoutTarget nonDefaultTarget = LayoutTarget.OUTER;
+
+ layout.setWidthRatio(newRatio);
+ assertTrue(layout.getWidthRatio() == newRatio);
+
+ layout.setHeightRatio(newRatio);
+ assertTrue(layout.getHeightRatio() == newRatio);
+
+ layout.setX(newCoordinate);
+ assertTrue(layout.getX() == newCoordinate);
+
+ layout.setY(newCoordinate);
+ assertTrue(layout.getY() == newCoordinate);
+
+ layout.setXMode(nonDefaultMode);
+ assertTrue(layout.getXMode() == nonDefaultMode);
+
+ layout.setYMode(nonDefaultMode);
+ assertTrue(layout.getYMode() == nonDefaultMode);
+
+ layout.setWidthMode(nonDefaultMode);
+ assertTrue(layout.getWidthMode() == nonDefaultMode);
+
+ layout.setHeightMode(nonDefaultMode);
+ assertTrue(layout.getHeightMode() == nonDefaultMode);
+
+ layout.setTarget(nonDefaultTarget);
+ assertTrue(layout.getTarget() == nonDefaultTarget);
+ }
+
+ private void checkAxisOperations(XDDFValueAxis axis) {
+ axis.setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
+ assertEquals(AxisCrossBetween.MIDPOINT_CATEGORY, axis.getCrossBetween());
+
+ axis.setCrosses(AxisCrosses.AUTO_ZERO);
+ assertEquals(AxisCrosses.AUTO_ZERO, axis.getCrosses());
+
+ final String numberFormat = "General";
+ axis.setNumberFormat(numberFormat);
+ assertEquals(numberFormat, axis.getNumberFormat());
+
+ axis.setPosition(AxisPosition.BOTTOM);
+ assertEquals(AxisPosition.BOTTOM, axis.getPosition());
+
+ axis.setMajorTickMark(AxisTickMark.NONE);
+ assertEquals(AxisTickMark.NONE, axis.getMajorTickMark());
+
+ axis.setMajorTickMark(AxisTickMark.IN);
+ assertEquals(AxisTickMark.IN, axis.getMajorTickMark());
+
+ axis.setMajorTickMark(AxisTickMark.OUT);
+ assertEquals(AxisTickMark.OUT, axis.getMajorTickMark());
+
+ axis.setMajorTickMark(AxisTickMark.CROSS);
+ assertEquals(AxisTickMark.CROSS, axis.getMajorTickMark());
+
+ axis.setMinorTickMark(AxisTickMark.NONE);
+ assertEquals(AxisTickMark.NONE, axis.getMinorTickMark());
+
+ axis.setMinorTickMark(AxisTickMark.IN);
+ assertEquals(AxisTickMark.IN, axis.getMinorTickMark());
+
+ axis.setMinorTickMark(AxisTickMark.OUT);
+ assertEquals(AxisTickMark.OUT, axis.getMinorTickMark());
+
+ axis.setMinorTickMark(AxisTickMark.CROSS);
+ assertEquals(AxisTickMark.CROSS, axis.getMinorTickMark());
+
+ axis.setVisible(true);
+ assertTrue(axis.isVisible());
+
+ axis.setVisible(false);
+ assertFalse(axis.isVisible());
+
+ final double EPSILON = 1E-7;
+ axis.setLogBase(Math.E);
+ assertTrue(Math.abs(axis.getLogBase() - Math.E) < EPSILON);
+
+ final double newValue = 10.0;
+
+ axis.setMinimum(newValue);
+ assertTrue(Math.abs(axis.getMinimum() - newValue) < EPSILON);
+
+ axis.setMaximum(newValue);
+ assertTrue(Math.abs(axis.getMaximum() - newValue) < EPSILON);
+
+ IllegalArgumentException iae = null;
+ try {
+ axis.setLogBase(0.0);
+ } catch (IllegalArgumentException e) {
+ iae = e;
+ }
+ assertNotNull(iae);
+
+ iae = null;
+ try {
+ axis.setLogBase(30000.0);
+ } catch (IllegalArgumentException e) {
+ iae = e;
+ }
+ assertNotNull(iae);
+ }
+}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFChart.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFChart.java
index f033e8ed4e..bdaacb8993 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFChart.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFChart.java
@@ -17,46 +17,46 @@
package org.apache.poi.xssf.usermodel;
-import junit.framework.TestCase;
-
import org.apache.poi.xssf.XSSFTestDataSamples;
+import junit.framework.TestCase;
+
public final class TestXSSFChart extends TestCase {
-
+
public void testGetAccessors() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithThreeCharts.xlsx");
XSSFSheet s1 = wb.getSheetAt(0);
XSSFSheet s2 = wb.getSheetAt(1);
XSSFSheet s3 = wb.getSheetAt(2);
-
+
assertEquals(0, s1.getRelations().size());
assertEquals(1, s2.getRelations().size());
assertEquals(1, s3.getRelations().size());
-
+
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
}
-
+
public void testGetCharts() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithThreeCharts.xlsx");
-
+
XSSFSheet s1 = wb.getSheetAt(0);
XSSFSheet s2 = wb.getSheetAt(1);
XSSFSheet s3 = wb.getSheetAt(2);
-
+
assertEquals(0, s1.createDrawingPatriarch().getCharts().size());
assertEquals(2, s2.createDrawingPatriarch().getCharts().size());
assertEquals(1, s3.createDrawingPatriarch().getCharts().size());
-
+
// Check the titles
XSSFChart chart = s2.createDrawingPatriarch().getCharts().get(0);
assertEquals(null, chart.getTitleText());
-
+
chart = s2.createDrawingPatriarch().getCharts().get(1);
assertEquals("Pie Chart Title Thingy", chart.getTitleText().getString());
-
+
chart = s3.createDrawingPatriarch().getCharts().get(0);
assertEquals("Sheet 3 Chart with Title", chart.getTitleText().getString());
-
+
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
}
@@ -68,14 +68,15 @@ public final class TestXSSFChart extends TestCase {
XSSFChart c1 = d1.createChart(a1);
assertEquals(1, d1.getCharts().size());
+
assertNotNull(c1.getGraphicFrame());
- assertNotNull(c1.getOrCreateLegend());
+ assertNotNull(c1.getOrAddLegend());
XSSFClientAnchor a2 = new XSSFClientAnchor(0, 0, 0, 0, 1, 11, 10, 60);
XSSFChart c2 = d1.createChart(a2);
assertNotNull(c2);
assertEquals(2, d1.getCharts().size());
-
+
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java
index 64ce92b570..a7f9098e39 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java
@@ -17,24 +17,32 @@
package org.apache.poi.xssf.usermodel.charts;
+import org.apache.poi.xddf.usermodel.chart.AxisCrosses;
+import org.apache.poi.xddf.usermodel.chart.AxisPosition;
+import org.apache.poi.xddf.usermodel.chart.XDDFCategoryAxis;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
import junit.framework.TestCase;
-import org.apache.poi.ss.usermodel.charts.*;
-import org.apache.poi.xssf.usermodel.*;
-
public final class TestXSSFCategoryAxis extends TestCase {
-
+
public void testAccessMethods() throws Exception {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet();
XSSFDrawing drawing = sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
XSSFChart chart = drawing.createChart(anchor);
- XSSFCategoryAxis axis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
+ XDDFCategoryAxis axis = chart.createCategoryAxis(AxisPosition.BOTTOM);
axis.setCrosses(AxisCrosses.AUTO_ZERO);
assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO);
- assertEquals(chart.getAxis().size(), 1);
+ assertEquals(chart.getAxes().size(), 1);
+
+ wb.close();
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java
index 41e02b12ff..1578755ab1 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java
@@ -19,18 +19,22 @@ package org.apache.poi.xssf.usermodel.charts;
import java.util.List;
-import junit.framework.TestCase;
-
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.charts.*;
+import org.apache.poi.xddf.usermodel.chart.AxisPosition;
+import org.apache.poi.xddf.usermodel.chart.AxisTickMark;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartAxis;
import org.apache.poi.xssf.XSSFTestDataSamples;
-import org.apache.poi.xssf.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import junit.framework.TestCase;
public final class TestXSSFChartAxis extends TestCase {
private static final double EPSILON = 1E-7;
- private final XSSFChartAxis axis;
+ private final XDDFChartAxis axis;
public TestXSSFChartAxis() {
super();
@@ -39,9 +43,9 @@ public final class TestXSSFChartAxis extends TestCase {
XSSFDrawing drawing = sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
XSSFChart chart = drawing.createChart(anchor);
- axis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
+ axis = chart.createValueAxis(AxisPosition.BOTTOM);
}
-
+
public void testLogBaseIllegalArgument() throws Exception {
IllegalArgumentException iae = null;
try {
@@ -119,13 +123,12 @@ public final class TestXSSFChartAxis extends TestCase {
public void testGetChartAxisBug57362() {
//Load existing excel with some chart on it having primary and secondary axis.
- final Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("57362.xlsx");
- final Sheet sh = workbook.getSheetAt(0);
- final XSSFSheet xsh = (XSSFSheet) sh;
- final XSSFDrawing drawing = xsh.createDrawingPatriarch();
+ final XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("57362.xlsx");
+ final XSSFSheet sh = workbook.getSheetAt(0);
+ final XSSFDrawing drawing = sh.createDrawingPatriarch();
final XSSFChart chart = drawing.getCharts().get(0);
- final List extends XSSFChartAxis> axisList = chart.getAxis();
+ final List extends XDDFChartAxis> axisList = chart.getAxes();
assertEquals(4, axisList.size());
assertNotNull(axisList.get(0));
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java
index 524b421da9..2a464067c1 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java
@@ -23,13 +23,12 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import org.apache.poi.ss.usermodel.Chart;
-import org.apache.poi.ss.usermodel.ClientAnchor;
-import org.apache.poi.ss.usermodel.Drawing;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.charts.ChartLegend;
-import org.apache.poi.ss.usermodel.charts.LegendPosition;
+import org.apache.poi.xddf.usermodel.chart.LegendPosition;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartLegend;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
@@ -39,28 +38,28 @@ import org.junit.Test;
public final class TestXSSFChartLegend {
@Test
public void testLegendPositionAccessMethods() throws IOException {
- Workbook wb = new XSSFWorkbook();
- Sheet sheet = wb.createSheet();
- Drawing> drawing = sheet.createDrawingPatriarch();
- ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
- Chart chart = drawing.createChart(anchor);
- ChartLegend legend = chart.getOrCreateLegend();
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+ XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
+ XSSFChart chart = drawing.createChart(anchor);
+ XDDFChartLegend legend = chart.getOrAddLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
assertEquals(LegendPosition.TOP_RIGHT, legend.getPosition());
-
+
wb.close();
}
@Test
public void test_setOverlay_defaultChartLegend_expectOverlayInitialValueSetToFalse() throws IOException {
// Arrange
- Workbook wb = new XSSFWorkbook();
- Sheet sheet = wb.createSheet();
- Drawing> drawing = sheet.createDrawingPatriarch();
- ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
- Chart chart = drawing.createChart(anchor);
- ChartLegend legend = chart.getOrCreateLegend();
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+ XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
+ XSSFChart chart = drawing.createChart(anchor);
+ XDDFChartLegend legend = chart.getOrAddLegend();
// Act
@@ -73,12 +72,12 @@ public final class TestXSSFChartLegend {
@Test
public void test_setOverlay_chartLegendSetToTrue_expectOverlayInitialValueSetToTrue() throws IOException {
// Arrange
- Workbook wb = new XSSFWorkbook();
- Sheet sheet = wb.createSheet();
- Drawing> drawing = sheet.createDrawingPatriarch();
- ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
- Chart chart = drawing.createChart(anchor);
- ChartLegend legend = chart.getOrCreateLegend();
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+ XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
+ XSSFChart chart = drawing.createChart(anchor);
+ XDDFChartLegend legend = chart.getOrAddLegend();
// Act
legend.setOverlay(true);
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartTitle.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartTitle.java
index 7282aa0f41..14f467a37f 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartTitle.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartTitle.java
@@ -26,24 +26,22 @@ import java.io.IOException;
import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Chart;
-import org.apache.poi.ss.usermodel.ClientAnchor;
-import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.charts.AxisCrosses;
-import org.apache.poi.ss.usermodel.charts.AxisPosition;
-import org.apache.poi.ss.usermodel.charts.ChartAxis;
-import org.apache.poi.ss.usermodel.charts.ChartDataSource;
-import org.apache.poi.ss.usermodel.charts.ChartLegend;
-import org.apache.poi.ss.usermodel.charts.DataSources;
-import org.apache.poi.ss.usermodel.charts.LegendPosition;
-import org.apache.poi.ss.usermodel.charts.LineChartData;
-import org.apache.poi.ss.usermodel.charts.ValueAxis;
import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xddf.usermodel.chart.AxisCrosses;
+import org.apache.poi.xddf.usermodel.chart.AxisPosition;
+import org.apache.poi.xddf.usermodel.chart.ChartTypes;
+import org.apache.poi.xddf.usermodel.chart.LegendPosition;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartAxis;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartLegend;
+import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
+import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory;
+import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
+import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFDrawing;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -54,9 +52,9 @@ import org.junit.Test;
* Test get/set chart title.
*/
public class TestXSSFChartTitle {
- private Workbook createWorkbookWithChart() {
- Workbook wb = new XSSFWorkbook();
- Sheet sheet = wb.createSheet("linechart");
+ private XSSFWorkbook createWorkbookWithChart() {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet("linechart");
final int NUM_OF_ROWS = 3;
final int NUM_OF_COLUMNS = 10;
@@ -71,28 +69,26 @@ public class TestXSSFChartTitle {
}
}
- Drawing> drawing = sheet.createDrawingPatriarch();
- ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+ XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);
- Chart chart = drawing.createChart(anchor);
- ChartLegend legend = chart.getOrCreateLegend();
+ XSSFChart chart = drawing.createChart(anchor);
+ XDDFChartLegend legend = chart.getOrAddLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
- LineChartData data = chart.getChartDataFactory().createLineChartData();
-
// Use a category axis for the bottom axis.
- ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
- ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
+ XDDFChartAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
+ XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
- ChartDataSource xs = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
- ChartDataSource ys1 = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));
- ChartDataSource ys2 = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1));
+ XDDFDataSource xs = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
+ XDDFNumericalDataSource ys1 = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));
+ XDDFNumericalDataSource ys2 = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1));
+ XDDFChartData data = chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);
data.addSeries(xs, ys1);
data.addSeries(xs, ys2);
-
- chart.plot(data, bottomAxis, leftAxis);
+ chart.plot(data);
return wb;
}
@@ -100,16 +96,14 @@ public class TestXSSFChartTitle {
/**
* Gets the first chart from the named sheet in the workbook.
*/
- private XSSFChart getChartFromWorkbook(Workbook wb, String sheetName) {
- Sheet sheet = wb.getSheet(sheetName);
- if (sheet instanceof XSSFSheet) {
- XSSFSheet xsheet = (XSSFSheet) sheet;
- XSSFDrawing drawing = xsheet.getDrawingPatriarch();
- if (drawing != null) {
- List charts = drawing.getCharts();
- if (charts != null && charts.size() > 0) {
- return charts.get(0);
- }
+ private XSSFChart getChartFromWorkbook(XSSFWorkbook wb, String sheetName) {
+ XSSFSheet sheet = wb.getSheet(sheetName);
+ XSSFSheet xsheet = sheet;
+ XSSFDrawing drawing = xsheet.getDrawingPatriarch();
+ if (drawing != null) {
+ List charts = drawing.getCharts();
+ if (charts != null && charts.size() > 0) {
+ return charts.get(0);
}
}
return null;
@@ -117,7 +111,7 @@ public class TestXSSFChartTitle {
@Test
public void testNewChart() throws IOException {
- Workbook wb = createWorkbookWithChart();
+ XSSFWorkbook wb = createWorkbookWithChart();
XSSFChart chart = getChartFromWorkbook(wb, "linechart");
assertNotNull(chart);
assertNull(chart.getTitleText());
@@ -126,7 +120,7 @@ public class TestXSSFChartTitle {
XSSFRichTextString queryTitle = chart.getTitleText();
assertNotNull(queryTitle);
assertEquals(myTitle, queryTitle.toString());
-
+
final String myTitleFormula = "1 & \" and \" & 2";
chart.setTitleFormula(myTitleFormula);
// setting formula should unset text, but since there is a formula, returns an empty string
@@ -139,7 +133,7 @@ public class TestXSSFChartTitle {
@Test
public void testExistingChartWithTitle() throws IOException {
- Workbook wb = XSSFTestDataSamples.openSampleWorkbook("chartTitle_withTitle.xlsx");
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("chartTitle_withTitle.xlsx");
XSSFChart chart = getChartFromWorkbook(wb, "Sheet1");
assertNotNull(chart);
XSSFRichTextString originalTitle = chart.getTitleText();
@@ -155,7 +149,7 @@ public class TestXSSFChartTitle {
@Test
public void testExistingChartNoTitle() throws IOException {
- Workbook wb = XSSFTestDataSamples.openSampleWorkbook("chartTitle_noTitle.xlsx");
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("chartTitle_noTitle.xlsx");
XSSFChart chart = getChartFromWorkbook(wb, "Sheet1");
assertNotNull(chart);
assertNull(chart.getTitleText());
@@ -169,7 +163,7 @@ public class TestXSSFChartTitle {
@Test
public void testExistingChartWithFormulaTitle() throws IOException {
- Workbook wb = XSSFTestDataSamples.openSampleWorkbook("chartTitle_withTitleFormula.xlsx");
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("chartTitle_withTitleFormula.xlsx");
XSSFChart chart = getChartFromWorkbook(wb, "Sheet1");
assertNotNull(chart);
XSSFRichTextString originalTitle = chart.getTitleText();
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFDateAxis.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFDateAxis.java
index 81a474f502..5664488185 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFDateAxis.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFDateAxis.java
@@ -17,24 +17,32 @@
package org.apache.poi.xssf.usermodel.charts;
+import org.apache.poi.xddf.usermodel.chart.AxisCrosses;
+import org.apache.poi.xddf.usermodel.chart.AxisPosition;
+import org.apache.poi.xddf.usermodel.chart.XDDFDateAxis;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
import junit.framework.TestCase;
-import org.apache.poi.ss.usermodel.charts.*;
-import org.apache.poi.xssf.usermodel.*;
-
public final class TestXSSFDateAxis extends TestCase {
-
+
public void testAccessMethods() throws Exception {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet();
XSSFDrawing drawing = sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
XSSFChart chart = drawing.createChart(anchor);
- XSSFDateAxis axis = chart.getChartAxisFactory().createDateAxis(AxisPosition.BOTTOM);
+ XDDFDateAxis axis = chart.createDateAxis(AxisPosition.BOTTOM);
axis.setCrosses(AxisCrosses.AUTO_ZERO);
assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO);
- assertEquals(chart.getAxis().size(), 1);
+ assertEquals(chart.getAxes().size(), 1);
+
+ wb.close();
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFLineChartData.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFLineChartData.java
index e5ee56b504..83a25dff64 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFLineChartData.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFLineChartData.java
@@ -22,19 +22,20 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import org.apache.poi.ss.usermodel.Chart;
-import org.apache.poi.ss.usermodel.ClientAnchor;
-import org.apache.poi.ss.usermodel.Drawing;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.charts.AxisPosition;
-import org.apache.poi.ss.usermodel.charts.ChartAxis;
-import org.apache.poi.ss.usermodel.charts.ChartDataSource;
-import org.apache.poi.ss.usermodel.charts.DataSources;
-import org.apache.poi.ss.usermodel.charts.LineChartData;
-import org.apache.poi.ss.usermodel.charts.LineChartSeries;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.SheetBuilder;
+import org.apache.poi.xddf.usermodel.chart.AxisPosition;
+import org.apache.poi.xddf.usermodel.chart.ChartTypes;
+import org.apache.poi.xddf.usermodel.chart.XDDFCategoryAxis;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
+import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory;
+import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
+import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
@@ -50,27 +51,26 @@ public class TestXSSFLineChartData {
@Test
public void testOneSeriePlot() throws IOException {
- Workbook wb = new XSSFWorkbook();
- Sheet sheet = new SheetBuilder(wb, plotData).build();
- Drawing> drawing = sheet.createDrawingPatriarch();
- ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
- Chart chart = drawing.createChart(anchor);
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, plotData).build();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+ XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
+ XSSFChart chart = drawing.createChart(anchor);
- ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
- ChartAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
+ XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
+ XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
- LineChartData lineChartData =
- chart.getChartDataFactory().createLineChartData();
+ XDDFDataSource xs = XDDFDataSourcesFactory.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1"));
+ XDDFNumericalDataSource ys = XDDFDataSourcesFactory.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2"));
- ChartDataSource xs = DataSources.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1"));
- ChartDataSource ys = DataSources.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2"));
- LineChartSeries series = lineChartData.addSeries(xs, ys);
+ XDDFChartData lineChartData = chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);
+ XDDFChartData.Series series = lineChartData.addSeries(xs, ys);
assertNotNull(series);
assertEquals(1, lineChartData.getSeries().size());
assertTrue(lineChartData.getSeries().contains(series));
- chart.plot(lineChartData, bottomAxis, leftAxis);
+ chart.plot(lineChartData);
wb.close();
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFManualLayout.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFManualLayout.java
index 73df559144..85ac30f30f 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFManualLayout.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFManualLayout.java
@@ -22,15 +22,14 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import org.apache.poi.ss.usermodel.Chart;
-import org.apache.poi.ss.usermodel.ClientAnchor;
-import org.apache.poi.ss.usermodel.Drawing;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.charts.ChartLegend;
-import org.apache.poi.ss.usermodel.charts.LayoutMode;
-import org.apache.poi.ss.usermodel.charts.LayoutTarget;
-import org.apache.poi.ss.usermodel.charts.ManualLayout;
+import org.apache.poi.xddf.usermodel.chart.LayoutMode;
+import org.apache.poi.xddf.usermodel.chart.LayoutTarget;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartLegend;
+import org.apache.poi.xddf.usermodel.chart.XDDFManualLayout;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.After;
import org.junit.Before;
@@ -38,25 +37,25 @@ import org.junit.Test;
public final class TestXSSFManualLayout {
- private Workbook wb;
- private ManualLayout layout;
-
+ private XSSFWorkbook wb;
+ private XDDFManualLayout layout;
+
@Before
public void createEmptyLayout() {
wb = new XSSFWorkbook();
- Sheet sheet = wb.createSheet();
- Drawing> drawing = sheet.createDrawingPatriarch();
- ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
- Chart chart = drawing.createChart(anchor);
- ChartLegend legend = chart.getOrCreateLegend();
- layout = legend.getManualLayout();
+ XSSFSheet sheet = wb.createSheet();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+ XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
+ XSSFChart chart = drawing.createChart(anchor);
+ XDDFChartLegend legend = chart.getOrAddLegend();
+ layout = legend.getOrAddManualLayout();
}
@After
public void closeWB() throws IOException {
wb.close();
}
-
+
/*
* Accessor methods are not trivial. They use lazy underlying bean
* initialization so there can be some errors (NPE, for example).
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFScatterChartData.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFScatterChartData.java
index 79dc71c8d2..5683bc4052 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFScatterChartData.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFScatterChartData.java
@@ -23,19 +23,21 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import org.apache.poi.ss.usermodel.Chart;
-import org.apache.poi.ss.usermodel.ClientAnchor;
-import org.apache.poi.ss.usermodel.Drawing;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.charts.AxisPosition;
-import org.apache.poi.ss.usermodel.charts.ChartAxis;
-import org.apache.poi.ss.usermodel.charts.ChartDataSource;
-import org.apache.poi.ss.usermodel.charts.DataSources;
-import org.apache.poi.ss.usermodel.charts.ScatterChartData;
-import org.apache.poi.ss.usermodel.charts.ScatterChartSeries;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.SheetBuilder;
+import org.apache.poi.xddf.usermodel.chart.AxisPosition;
+import org.apache.poi.xddf.usermodel.chart.ChartTypes;
+import org.apache.poi.xddf.usermodel.chart.ScatterStyle;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
+import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory;
+import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
+import org.apache.poi.xddf.usermodel.chart.XDDFScatterChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
@@ -51,27 +53,27 @@ public final class TestXSSFScatterChartData {
@Test
public void testOneSeriePlot() throws IOException {
- Workbook wb = new XSSFWorkbook();
- Sheet sheet = new SheetBuilder(wb, plotData).build();
- Drawing> drawing = sheet.createDrawingPatriarch();
- ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
- Chart chart = drawing.createChart(anchor);
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, plotData).build();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+ XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
+ XSSFChart chart = drawing.createChart(anchor);
- ChartAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
- ChartAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
+ XDDFValueAxis bottomAxis = chart.createValueAxis(AxisPosition.BOTTOM);
+ XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
- ScatterChartData scatterChartData =
- chart.getChartDataFactory().createScatterChartData();
+ XDDFDataSource xs = XDDFDataSourcesFactory.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1"));
+ XDDFNumericalDataSource ys = XDDFDataSourcesFactory.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2"));
- ChartDataSource xs = DataSources.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1"));
- ChartDataSource ys = DataSources.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2"));
- ScatterChartSeries series = scatterChartData.addSerie(xs, ys);
+ XDDFScatterChartData scatterChartData = (XDDFScatterChartData) chart.createData(ChartTypes.SCATTER, bottomAxis, leftAxis);
+ XDDFChartData.Series series = scatterChartData.addSeries(xs, ys);
+ assertEquals(ScatterStyle.LINE_MARKER, scatterChartData.getStyle());
assertNotNull(series);
assertEquals(1, scatterChartData.getSeries().size());
assertTrue(scatterChartData.getSeries().contains(series));
- chart.plot(scatterChartData, bottomAxis, leftAxis);
+ chart.plot(scatterChartData);
wb.close();
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java
index db8ded3707..3f8ef06db4 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java
@@ -17,20 +17,27 @@
package org.apache.poi.xssf.usermodel.charts;
+import org.apache.poi.xddf.usermodel.chart.AxisCrossBetween;
+import org.apache.poi.xddf.usermodel.chart.AxisCrosses;
+import org.apache.poi.xddf.usermodel.chart.AxisPosition;
+import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
import junit.framework.TestCase;
-import org.apache.poi.ss.usermodel.charts.*;
-import org.apache.poi.xssf.usermodel.*;
-
public final class TestXSSFValueAxis extends TestCase {
-
+
public void testAccessMethods() throws Exception {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet();
XSSFDrawing drawing = sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
XSSFChart chart = drawing.createChart(anchor);
- XSSFValueAxis axis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
+ XDDFValueAxis axis = chart.createValueAxis(AxisPosition.BOTTOM);
axis.setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
assertEquals(axis.getCrossBetween(), AxisCrossBetween.MIDPOINT_CATEGORY);
@@ -38,6 +45,8 @@ public final class TestXSSFValueAxis extends TestCase {
axis.setCrosses(AxisCrosses.AUTO_ZERO);
assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO);
- assertEquals(chart.getAxis().size(), 1);
+ assertEquals(chart.getAxes().size(), 1);
+
+ wb.close();
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFChart.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFChart.java
index 1cb233dade..cb55371160 100644
--- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFChart.java
+++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFChart.java
@@ -20,6 +20,8 @@ package org.apache.poi.xwpf.usermodel;
import java.io.IOException;
import java.util.List;
+import org.apache.poi.xddf.usermodel.chart.XDDFBarChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
@@ -33,7 +35,7 @@ import junit.framework.TestCase;
public class TestXWPFChart extends TestCase {
/**
- * test method to check charts are null
+ * test method to check charts are not null
*/
public void testRead() throws IOException
{
@@ -41,10 +43,18 @@ public class TestXWPFChart extends TestCase {
List charts = sampleDoc.getCharts();
assertNotNull(charts);
assertEquals(2, charts.size());
- assertNotNull(charts.get(0));
- assertNotNull(charts.get(1));
+ checkData(charts.get(0));
+ checkData(charts.get(1));
}
-
+
+ private void checkData(XWPFChart chart) {
+ assertNotNull(chart);
+ assertEquals(1, chart.getChartSeries().size());
+ XDDFChartData data = chart.getChartSeries().get(0);
+ assertEquals(XDDFBarChartData.class, data.getClass());
+ assertEquals(3, data.getSeries().size());
+ }
+
/**
* test method to add chart title and check whether it's set
*/
diff --git a/test-data/slideshow/bar-chart.pptx b/test-data/slideshow/bar-chart.pptx
new file mode 100644
index 0000000000..e4d2613046
Binary files /dev/null and b/test-data/slideshow/bar-chart.pptx differ
diff --git a/test-data/slideshow/line-chart.pptx b/test-data/slideshow/line-chart.pptx
new file mode 100644
index 0000000000..7fd9f4d0f8
Binary files /dev/null and b/test-data/slideshow/line-chart.pptx differ
diff --git a/test-data/slideshow/radar-chart.pptx b/test-data/slideshow/radar-chart.pptx
new file mode 100644
index 0000000000..f569d7f3a1
Binary files /dev/null and b/test-data/slideshow/radar-chart.pptx differ
diff --git a/test-data/slideshow/scatter-chart.pptx b/test-data/slideshow/scatter-chart.pptx
new file mode 100644
index 0000000000..a4f2431b97
Binary files /dev/null and b/test-data/slideshow/scatter-chart.pptx differ