Author: abearez Date: Mon Jan 13 00:26:59 2020 New Revision: 1872690 URL: http://svn.apache.org/viewvc?rev=1872690&view=rev Log: Implement error bars for bar and line charts
Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorBarType.java poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorDirection.java poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorValueType.java poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFErrorBars.java Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java poi/trunk/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorBarType.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorBarType.java?rev=1872690&view=auto ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorBarType.java (added) +++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorBarType.java Mon Jan 13 00:26:59 2020 @@ -0,0 +1,45 @@ +/* ==================================================================== +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 java.util.HashMap; + +import org.openxmlformats.schemas.drawingml.x2006.chart.STErrBarType;; + +public enum ErrorBarType { + BOTH(STErrBarType.BOTH), + MINUS(STErrBarType.MINUS), + PLUS(STErrBarType.PLUS); + + final STErrBarType.Enum underlying; + + ErrorBarType(STErrBarType.Enum barType) { + this.underlying = barType; + } + + private final static HashMap<STErrBarType.Enum, ErrorBarType> reverse = new HashMap<>(); + static { + for (ErrorBarType value : values()) { + reverse.put(value.underlying, value); + } + } + + static ErrorBarType valueOf(STErrBarType.Enum barType) { + return reverse.get(barType); + } +} Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorDirection.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorDirection.java?rev=1872690&view=auto ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorDirection.java (added) +++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorDirection.java Mon Jan 13 00:26:59 2020 @@ -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.xddf.usermodel.chart; + +import java.util.HashMap; + +import org.openxmlformats.schemas.drawingml.x2006.chart.STErrDir;; + +public enum ErrorDirection { + X(STErrDir.X), + Y(STErrDir.Y); + + final STErrDir.Enum underlying; + + ErrorDirection(STErrDir.Enum direction) { + this.underlying = direction; + } + + private final static HashMap<STErrDir.Enum, ErrorDirection> reverse = new HashMap<>(); + static { + for (ErrorDirection value : values()) { + reverse.put(value.underlying, value); + } + } + + static ErrorDirection valueOf(STErrDir.Enum direction) { + return reverse.get(direction); + } +} Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorValueType.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorValueType.java?rev=1872690&view=auto ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorValueType.java (added) +++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorValueType.java Mon Jan 13 00:26:59 2020 @@ -0,0 +1,47 @@ +/* ==================================================================== +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 java.util.HashMap; + +import org.openxmlformats.schemas.drawingml.x2006.chart.STErrValType;; + +public enum ErrorValueType { + CUSTOM(STErrValType.CUST), + FIXED_VALUE(STErrValType.FIXED_VAL), + PERCENTAGE(STErrValType.PERCENTAGE), + STANDARD_DEVIATION(STErrValType.STD_DEV), + STANDARD_ERROR(STErrValType.STD_ERR); + + final STErrValType.Enum underlying; + + ErrorValueType(STErrValType.Enum valueType) { + this.underlying = valueType; + } + + private final static HashMap<STErrValType.Enum, ErrorValueType> reverse = new HashMap<>(); + static { + for (ErrorValueType value : values()) { + reverse.put(value.underlying, value); + } + } + + static ErrorValueType valueOf(STErrValType.Enum valueType) { + return reverse.get(valueType); + } +} Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java?rev=1872690&r1=1872689&r2=1872690&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java Mon Jan 13 00:26:59 2020 @@ -216,6 +216,41 @@ public class XDDFBar3DChartData extends } } + /** + * @since 4.1.2 + */ + public boolean hasErrorBars() { + return series.isSetErrBars(); + } + + /** + * @since 4.1.2 + */ + public XDDFErrorBars getErrorBars() { + if (series.isSetErrBars()) { + return new XDDFErrorBars(series.getErrBars()); + } else { + return null; + } + } + + /** + * @since 4.1.2 + */ + public void setErrorBars(XDDFErrorBars bars) { + if (bars == null) { + if (series.isSetErrBars()) { + series.unsetErrBars(); + } + } else { + if (series.isSetErrBars()) { + series.getErrBars().set(bars.getXmlObject()); + } else { + series.addNewErrBars().set(bars.getXmlObject()); + } + } + } + @Override public void setShowLeaderLines(boolean showLeaderLines) { if (!series.isSetDLbls()) { Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java?rev=1872690&r1=1872689&r2=1872690&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java Mon Jan 13 00:26:59 2020 @@ -206,6 +206,41 @@ public class XDDFBarChartData extends XD } } + /** + * @since 4.1.2 + */ + public boolean hasErrorBars() { + return series.isSetErrBars(); + } + + /** + * @since 4.1.2 + */ + public XDDFErrorBars getErrorBars() { + if (series.isSetErrBars()) { + return new XDDFErrorBars(series.getErrBars()); + } else { + return null; + } + } + + /** + * @since 4.1.2 + */ + public void setErrorBars(XDDFErrorBars bars) { + if (bars == null) { + if (series.isSetErrBars()) { + series.unsetErrBars(); + } + } else { + if (series.isSetErrBars()) { + series.getErrBars().set(bars.getXmlObject()); + } else { + series.addNewErrBars().set(bars.getXmlObject()); + } + } + } + @Override public void setShowLeaderLines(boolean showLeaderLines) { if (!series.isSetDLbls()) { Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFErrorBars.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFErrorBars.java?rev=1872690&view=auto ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFErrorBars.java (added) +++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFErrorBars.java Mon Jan 13 00:26:59 2020 @@ -0,0 +1,170 @@ +/* ==================================================================== + 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.util.Beta; +import org.apache.poi.util.Internal; +import org.apache.poi.xddf.usermodel.XDDFShapeProperties; +import org.apache.xmlbeans.XmlObject; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTErrBars; + +/** + * @since POI 4.1.2 + */ +@Beta +public class XDDFErrorBars { + private CTErrBars bars; + + public XDDFErrorBars() { + this(CTErrBars.Factory.newInstance()); + } + + @Internal + protected XDDFErrorBars(CTErrBars bars) { + this.bars = bars; + } + + @Internal + protected XmlObject getXmlObject() { + return bars; + } + + public XDDFChartExtensionList getExtensionList() { + if (bars.isSetExtLst()) { + return new XDDFChartExtensionList(bars.getExtLst()); + } else { + return null; + } + } + + public void setExtensionList(XDDFChartExtensionList list) { + if (list == null) { + if (bars.isSetExtLst()) { + bars.unsetExtLst(); + } + } else { + bars.setExtLst(list.getXmlObject()); + } + } + + public XDDFShapeProperties getShapeProperties() { + if (bars.isSetSpPr()) { + return new XDDFShapeProperties(bars.getSpPr()); + } else { + return null; + } + } + + public void setShapeProperties(XDDFShapeProperties properties) { + if (properties == null) { + if (bars.isSetSpPr()) { + bars.unsetSpPr(); + } + } else { + if (bars.isSetSpPr()) { + bars.setSpPr(properties.getXmlObject()); + } else { + bars.addNewSpPr().set(properties.getXmlObject()); + } + } + } + + public ErrorBarType getErrorBarType() { + return ErrorBarType.valueOf(bars.getErrBarType().getVal()); + } + + public void setErrorBarType(ErrorBarType barType) { + bars.getErrBarType().setVal(barType.underlying); + } + + public ErrorValueType getErrorValueType() { + return ErrorValueType.valueOf(bars.getErrValType().getVal()); + } + + public void setErrorValueType(ErrorValueType valueType) { + bars.getErrValType().setVal(valueType.underlying); + } + + public ErrorDirection getErrorDirection() { + if (bars.isSetErrDir()) { + return ErrorDirection.valueOf(bars.getErrDir().getVal()); + } else { + return null; + } + } + + public void setErrorDirection(ErrorDirection direction) { + if (direction == null) { + if (bars.isSetErrDir()) { + bars.unsetErrDir(); + } + } else { + if (bars.isSetErrDir()) { + bars.getErrDir().setVal(direction.underlying); + } else { + bars.addNewErrDir().setVal(direction.underlying); + } + } + } + + public Boolean getNoEndCap() { + if (bars.isSetVal()) { + return bars.getNoEndCap().getVal(); + } else { + return null; + } + } + + public void setNoEndCap(Boolean noEndCap) { + if (noEndCap == null) { + if (bars.isSetNoEndCap()) { + bars.unsetNoEndCap(); + } + } else { + if (bars.isSetNoEndCap()) { + bars.getNoEndCap().setVal(noEndCap); + } else { + bars.addNewNoEndCap().setVal(noEndCap); + } + } + } + + public Double getValue() { + if (bars.isSetVal()) { + return bars.getVal().getVal(); + } else { + return null; + } + } + + public void setValue(Double value) { + if (value == null) { + if (bars.isSetVal()) { + bars.unsetVal(); + } + } else { + if (bars.isSetVal()) { + bars.getVal().setVal(value); + } else { + bars.addNewVal().setVal(value); + } + } + } + + // TODO handle minus and plus as numerical data sources +} Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java?rev=1872690&r1=1872689&r2=1872690&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java Mon Jan 13 00:26:59 2020 @@ -248,6 +248,41 @@ public class XDDFLine3DChartData extends } } + /** + * @since 4.1.2 + */ + public boolean hasErrorBars() { + return series.isSetErrBars(); + } + + /** + * @since 4.1.2 + */ + public XDDFErrorBars getErrorBars() { + if (series.isSetErrBars()) { + return new XDDFErrorBars(series.getErrBars()); + } else { + return null; + } + } + + /** + * @since 4.1.2 + */ + public void setErrorBars(XDDFErrorBars bars) { + if (bars == null) { + if (series.isSetErrBars()) { + series.unsetErrBars(); + } + } else { + if (series.isSetErrBars()) { + series.getErrBars().set(bars.getXmlObject()); + } else { + series.addNewErrBars().set(bars.getXmlObject()); + } + } + } + @Override protected CTAxDataSource getAxDS() { return series.getCat(); Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java?rev=1872690&r1=1872689&r2=1872690&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java Mon Jan 13 00:26:59 2020 @@ -228,6 +228,41 @@ public class XDDFLineChartData extends X } } + /** + * @since 4.1.2 + */ + public boolean hasErrorBars() { + return series.isSetErrBars(); + } + + /** + * @since 4.1.2 + */ + public XDDFErrorBars getErrorBars() { + if (series.isSetErrBars()) { + return new XDDFErrorBars(series.getErrBars()); + } else { + return null; + } + } + + /** + * @since 4.1.2 + */ + public void setErrorBars(XDDFErrorBars bars) { + if (bars == null) { + if (series.isSetErrBars()) { + series.unsetErrBars(); + } + } else { + if (series.isSetErrBars()) { + series.getErrBars().set(bars.getXmlObject()); + } else { + series.addNewErrBars().set(bars.getXmlObject()); + } + } + } + @Override protected CTAxDataSource getAxDS() { return series.getCat(); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java?rev=1872690&r1=1872689&r2=1872690&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java Mon Jan 13 00:26:59 2020 @@ -158,6 +158,15 @@ public class TestNecessaryOOXMLClasses { Assert.assertNotNull(ctOverlap); CTFirstSliceAng ctFirstSliceAng = CTFirstSliceAng.Factory.newInstance(); Assert.assertNotNull(ctFirstSliceAng); + + STErrBarType.Enum e9 = STErrBarType.Enum.forString("both"); + Assert.assertNotNull(e9); + STErrValType.Enum e10 = STErrValType.Enum.forString("percentage"); + Assert.assertNotNull(e10); + STErrDir.Enum e11 = STErrDir.Enum.forString("x"); + Assert.assertNotNull(e11); + CTErrBars bars = CTErrBars.Factory.newInstance(); + Assert.assertNotNull(bars); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org