You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2013/11/22 18:45:00 UTC
svn commit: r1544612 - in /poi/trunk/src:
java/org/apache/poi/ss/usermodel/charts/
ooxml/java/org/apache/poi/xssf/usermodel/
ooxml/java/org/apache/poi/xssf/usermodel/charts/
ooxml/testcases/org/apache/poi/xssf/usermodel/charts/
Author: cedricwalter
Date: Fri Nov 22 17:45:00 2013
New Revision: 1544612
URL: http://svn.apache.org/r1544612
Log:
Bug 54676: added new chart axis type: Category axis
Added:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFCategoryAxis.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java
Modified:
poi/trunk/src/java/org/apache/poi/ss/usermodel/charts/ChartAxisFactory.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java
Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/charts/ChartAxisFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/charts/ChartAxisFactory.java?rev=1544612&r1=1544611&r2=1544612&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/charts/ChartAxisFactory.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/charts/ChartAxisFactory.java Fri Nov 22 17:45:00 2013
@@ -23,13 +23,19 @@ import org.apache.poi.util.Beta;
* A factory for different chart axis.
*
* @author Roman Kashitsyn
+ * @author Martin Andersson
*/
@Beta
public interface ChartAxisFactory {
-
+
/**
* @return new value axis
*/
ValueAxis createValueAxis(AxisPosition pos);
+ /**
+ * @return new category axis.
+ */
+ ChartAxis createCategoryAxis(AxisPosition pos);
+
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java?rev=1544612&r1=1544611&r2=1544612&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java Fri Nov 22 17:45:00 2013
@@ -33,6 +33,7 @@ import org.apache.poi.util.Internal;
import org.apache.poi.ss.usermodel.Chart;
import org.apache.poi.ss.usermodel.charts.ChartAxis;
import org.apache.poi.ss.usermodel.charts.ChartAxisFactory;
+import org.apache.poi.xssf.usermodel.charts.XSSFCategoryAxis;
import org.apache.poi.xssf.usermodel.charts.XSSFChartDataFactory;
import org.apache.poi.xssf.usermodel.charts.XSSFChartAxis;
import org.apache.poi.xssf.usermodel.charts.XSSFValueAxis;
@@ -43,6 +44,7 @@ import org.apache.poi.ss.usermodel.chart
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTCatAx;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
@@ -59,6 +61,7 @@ import org.w3c.dom.Text;
* Represents a SpreadsheetML Chart
* @author Nick Burch
* @author Roman Kashitsyn
+ * @author Martin Andersson
*/
public final class XSSFChart extends POIXMLDocumentPart implements Chart, ChartAxisFactory {
@@ -212,6 +215,18 @@ public final class XSSFChart extends POI
return valueAxis;
}
+ public XSSFCategoryAxis createCategoryAxis(AxisPosition pos) {
+ long id = axis.size() + 1;
+ XSSFCategoryAxis categoryAxis = new XSSFCategoryAxis(this, id, pos);
+ if (axis.size() == 1) {
+ ChartAxis ax = axis.get(0);
+ ax.crossAxis(categoryAxis);
+ categoryAxis.crossAxis(ax);
+ }
+ axis.add(categoryAxis);
+ return categoryAxis;
+ }
+
public List<? extends XSSFChartAxis> getAxis() {
if (axis.isEmpty() && hasAxis()) {
parseAxis();
@@ -287,9 +302,16 @@ public final class XSSFChart extends POI
private void parseAxis() {
// TODO: add other axis types
+ parseCategoryAxis();
parseValueAxis();
}
+ private void parseCategoryAxis() {
+ for (CTCatAx catAx : chart.getPlotArea().getCatAxList()) {
+ axis.add(new XSSFCategoryAxis(this, catAx));
+ }
+ }
+
private void parseValueAxis() {
for (CTValAx valAx : chart.getPlotArea().getValAxList()) {
axis.add(new XSSFValueAxis(this, valAx));
Added: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFCategoryAxis.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFCategoryAxis.java?rev=1544612&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFCategoryAxis.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFCategoryAxis.java Fri Nov 22 17:45:00 2013
@@ -0,0 +1,93 @@
+/* ====================================================================
+ 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.xssf.usermodel.charts;
+
+import org.apache.poi.ss.usermodel.charts.AxisCrosses;
+import org.apache.poi.ss.usermodel.charts.AxisOrientation;
+import org.apache.poi.ss.usermodel.charts.AxisPosition;
+import org.apache.poi.ss.usermodel.charts.ChartAxis;
+import org.apache.poi.util.Beta;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTCatAx;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
+import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
+
+/**
+ * Category axis type.
+ *
+ * @author Martin Andersson
+ */
+@Beta
+public class XSSFCategoryAxis extends XSSFChartAxis {
+
+ private CTCatAx ctCatAx;
+
+ public XSSFCategoryAxis(XSSFChart chart, long id, AxisPosition pos) {
+ super(chart);
+ createAxis(id, pos);
+ }
+
+ public XSSFCategoryAxis(XSSFChart chart, CTCatAx ctCatAx) {
+ super(chart);
+ this.ctCatAx = ctCatAx;
+ }
+
+ public long getId() {
+ return ctCatAx.getAxId().getVal();
+ }
+
+ protected CTAxPos getCTAxPos() {
+ return ctCatAx.getAxPos();
+ }
+
+ protected CTNumFmt getCTNumFmt() {
+ if (ctCatAx.isSetNumFmt()) {
+ return ctCatAx.getNumFmt();
+ }
+ return ctCatAx.addNewNumFmt();
+ }
+
+ protected CTScaling getCTScaling() {
+ return ctCatAx.getScaling();
+ }
+
+ protected CTCrosses getCTCrosses() {
+ return ctCatAx.getCrosses();
+ }
+
+ public void crossAxis(ChartAxis axis) {
+ ctCatAx.getCrossAx().setVal(axis.getId());
+ }
+
+ private void createAxis(long id, AxisPosition pos) {
+ ctCatAx = chart.getCTChart().getPlotArea().addNewCatAx();
+ ctCatAx.addNewAxId().setVal(id);
+ ctCatAx.addNewAxPos();
+ ctCatAx.addNewScaling();
+ ctCatAx.addNewCrosses();
+ ctCatAx.addNewCrossAx();
+ ctCatAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
+
+ setPosition(pos);
+ setOrientation(AxisOrientation.MIN_MAX);
+ setCrosses(AxisCrosses.AUTO_ZERO);
+ }
+}
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java?rev=1544612&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFCategoryAxis.java Fri Nov 22 17:45:00 2013
@@ -0,0 +1,40 @@
+/* ====================================================================
+ 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.xssf.usermodel.charts;
+
+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);
+
+ axis.setCrosses(AxisCrosses.AUTO_ZERO);
+ assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO);
+
+ assertEquals(chart.getAxis().size(), 1);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org