You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2011/05/20 10:22:54 UTC

svn commit: r1125275 [2/2] - in /poi/trunk/src: documentation/content/xdocs/ examples/src/org/apache/poi/xssf/usermodel/examples/ java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/usermodel/ java/org/apache/poi/ss/usermodel/charts/ java/org/ap...

Added: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFValueAxis.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFValueAxis.java?rev=1125275&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFValueAxis.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFValueAxis.java Fri May 20 08:22:53 2011
@@ -0,0 +1,123 @@
+/* ====================================================================
+   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.ChartAxis;
+import org.apache.poi.ss.usermodel.charts.ValueAxis;
+import org.apache.poi.ss.usermodel.charts.AxisPosition;
+import org.apache.poi.ss.usermodel.charts.AxisOrientation;
+import org.apache.poi.ss.usermodel.charts.AxisCrossBetween;
+import org.apache.poi.ss.usermodel.charts.AxisCrosses;
+
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
+import org.openxmlformats.schemas.drawingml.x2006.chart.STAxPos;
+import org.openxmlformats.schemas.drawingml.x2006.chart.STCrossBetween;
+import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
+
+/**
+ * Value axis type.
+ *
+ * @author Roman Kashitsyn
+ */
+public class XSSFValueAxis extends XSSFChartAxis implements ValueAxis {
+
+	private CTValAx ctValAx;
+
+	public XSSFValueAxis(XSSFChart chart, long id, AxisPosition pos) {
+		super(chart);
+		createAxis(id, pos);
+	}
+
+	public long getId() {
+		return ctValAx.getAxId().getVal();
+	}
+
+	public void setCrossBetween(AxisCrossBetween crossBetween) {
+		ctValAx.getCrossBetween().setVal(fromCrossBetween(crossBetween));
+	}
+
+	public AxisCrossBetween getCrossBetween() {
+		return toCrossBetween(ctValAx.getCrossBetween().getVal());
+	}
+
+	@Override
+	protected CTAxPos getCTAxPos() {
+		return ctValAx.getAxPos();
+	}
+
+	@Override
+	protected CTNumFmt getCTNumFmt() {
+		if (ctValAx.isSetNumFmt()) {
+			return ctValAx.getNumFmt();
+		}
+		return ctValAx.addNewNumFmt();
+	}
+
+	@Override
+	protected CTScaling getCTScaling() {
+		return ctValAx.getScaling();
+	}
+
+	@Override
+	protected CTCrosses getCTCrosses() {
+		return ctValAx.getCrosses();
+	}
+
+	public void crossAxis(ChartAxis axis) {
+		ctValAx.getCrossAx().setVal(axis.getId());
+	}
+
+	private void createAxis(long id, AxisPosition pos) {
+		ctValAx = chart.getCTChart().getPlotArea().addNewValAx();
+		ctValAx.addNewAxId().setVal(id);
+		ctValAx.addNewAxPos();
+		ctValAx.addNewScaling();
+		ctValAx.addNewCrossBetween();
+		ctValAx.addNewCrosses();
+		ctValAx.addNewCrossAx();
+		ctValAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
+
+		setPosition(pos);
+		setOrientation(AxisOrientation.MIN_MAX);
+		setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
+		setCrosses(AxisCrosses.AUTO_ZERO);
+	}
+
+	private static STCrossBetween.Enum fromCrossBetween(AxisCrossBetween crossBetween) {
+		switch (crossBetween) {
+			case BETWEEN: return STCrossBetween.BETWEEN;
+			case MIDPOINT_CATEGORY: return STCrossBetween.MID_CAT;
+			default:
+				throw new IllegalArgumentException();
+		}
+	}
+
+	private static AxisCrossBetween toCrossBetween(STCrossBetween.Enum ctCrossBetween) {
+		switch (ctCrossBetween.intValue()) {
+			case STCrossBetween.INT_BETWEEN: return AxisCrossBetween.BETWEEN;
+			case STCrossBetween.INT_MID_CAT: return AxisCrossBetween.MIDPOINT_CATEGORY;
+			default:
+				throw new IllegalArgumentException();
+		}
+	}
+}

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFChart.java?rev=1125275&r1=1125274&r2=1125275&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFChart.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFChart.java Fri May 20 08:22:53 2011
@@ -55,4 +55,20 @@ public final class TestXSSFChart extends
        chart = s3.createDrawingPatriarch().getCharts().get(0);
        assertEquals("Sheet 3 Chart with Title", chart.getTitle().getString());
     }
+
+	public void testAddChartsToNewWorkbook() throws Exception {
+		XSSFWorkbook wb = new XSSFWorkbook();
+		XSSFSheet s1 = wb.createSheet();
+		XSSFDrawing d1 = s1.createDrawingPatriarch();
+		XSSFClientAnchor a1 = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30);
+		XSSFChart c1 = d1.createChart(a1);
+
+		assertEquals(1, d1.getCharts().size());
+		assertNotNull(c1.getGraphicFrame());
+		assertNotNull(c1.getOrCreateLegend());
+
+		XSSFClientAnchor a2 = new XSSFClientAnchor(0, 0, 0, 0, 1, 11, 10, 60);
+		XSSFChart c2 = d1.createChart(a2);
+		assertEquals(2, d1.getCharts().size());
+	}
 }

Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java?rev=1125275&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java Fri May 20 08:22:53 2011
@@ -0,0 +1,80 @@
+/* ====================================================================
+   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.*;
+import org.apache.poi.xssf.usermodel.charts.*;
+
+public final class TestXSSFChartAxis extends TestCase {
+
+	private static final double EPSILON = 1E-7;
+	private XSSFChartAxis axis;
+
+	public TestXSSFChartAxis() {
+		super();
+		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);
+		axis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
+	}
+ 
+	public void testLogBaseIllegalArgument() throws Exception {
+		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);
+	}
+
+	public void testLogBaseLegalArgument() throws Exception {
+		axis.setLogBase(Math.E);
+		assertTrue(Math.abs(axis.getLogBase() - Math.E) < EPSILON);
+	}
+
+	public void testNumberFormat() throws Exception {
+		final String numberFormat = "General";
+		axis.setNumberFormat(numberFormat);
+		assertEquals(numberFormat, axis.getNumberFormat());
+	}
+
+	public void testMaxAndMinAccessMethods() {
+		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);
+	}
+
+}

Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java?rev=1125275&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java Fri May 20 08:22:53 2011
@@ -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.*;
+import org.apache.poi.ss.usermodel.charts.ChartLegend;
+import org.apache.poi.ss.usermodel.charts.LegendPosition;
+import org.apache.poi.xssf.usermodel.*;
+
+public final class TestXSSFChartLegend extends TestCase {
+ 
+	public void testLegendPositionAccessMethods() throws Exception {
+		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();
+
+		legend.setPosition(LegendPosition.TOP_RIGHT);
+		assertEquals(LegendPosition.TOP_RIGHT, legend.getPosition());
+	}
+}

Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFScatterChartData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFScatterChartData.java?rev=1125275&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFScatterChartData.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFScatterChartData.java Fri May 20 08:22:53 2011
@@ -0,0 +1,51 @@
+/* ====================================================================
+   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.xssf.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.ss.usermodel.charts.*;
+import org.apache.poi.xssf.usermodel.charts.XSSFChartDataFactory;
+
+public final class TestXSSFScatterChartData  extends TestCase {
+ 
+	public void testOneSeriePlot() 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);
+
+		ChartAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
+		ChartAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
+
+		ScatterChartData scatterChartData =
+				XSSFChartDataFactory.getInstance().createScatterChartData();
+
+		ScatterChartSerie serie = scatterChartData.addSerie();
+		serie.setXValues(sheet, new CellRangeAddress(0,0,1,10));
+		serie.setYValues(sheet, new CellRangeAddress(1,1,1,10));
+
+		assertEquals(scatterChartData.getSeries().size(), 1);
+
+		chart.plot(scatterChartData, bottomAxis, leftAxis);
+	}
+
+}

Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java?rev=1125275&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java Fri May 20 08:22:53 2011
@@ -0,0 +1,44 @@
+/* ====================================================================
+   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.*;
+import org.apache.poi.xssf.usermodel.charts.*;
+
+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);
+
+		axis.setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
+		assertEquals(axis.getCrossBetween(), AxisCrossBetween.MIDPOINT_CATEGORY);
+
+		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