aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Béarez <abearez@apache.org>2020-01-13 00:26:59 +0000
committerAlain Béarez <abearez@apache.org>2020-01-13 00:26:59 +0000
commit22dd38ef72ca26b790193ef8e44e5b5a957d74d6 (patch)
treef0f33bed4127c6e517f187cfbe2292b5c09b2cc6
parentb211a1362c9d0a067bff9de057e2ae12b3f8d774 (diff)
downloadpoi-22dd38ef72ca26b790193ef8e44e5b5a957d74d6.tar.gz
poi-22dd38ef72ca26b790193ef8e44e5b5a957d74d6.zip
Implement error bars for bar and line charts
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872690 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorBarType.java45
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorDirection.java44
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorValueType.java47
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java35
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java35
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFErrorBars.java170
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java35
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java35
-rw-r--r--src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java9
9 files changed, 455 insertions, 0 deletions
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorBarType.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorBarType.java
new file mode 100644
index 0000000000..3086000c09
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorBarType.java
@@ -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);
+ }
+}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorDirection.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorDirection.java
new file mode 100644
index 0000000000..bcde0a1465
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorDirection.java
@@ -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);
+ }
+}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorValueType.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorValueType.java
new file mode 100644
index 0000000000..8af436bed0
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorValueType.java
@@ -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);
+ }
+}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java
index 4adb94c950..666802b1fa 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java
@@ -216,6 +216,41 @@ public class XDDFBar3DChartData extends XDDFChartData {
}
}
+ /**
+ * @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()) {
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java
index a79d587dce..4261212d33 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java
@@ -206,6 +206,41 @@ public class XDDFBarChartData extends XDDFChartData {
}
}
+ /**
+ * @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()) {
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFErrorBars.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFErrorBars.java
new file mode 100644
index 0000000000..e3c70a6757
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFErrorBars.java
@@ -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
+}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java
index d744d4d2ed..ac47f4d373 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java
@@ -248,6 +248,41 @@ public class XDDFLine3DChartData extends XDDFChartData {
}
}
+ /**
+ * @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();
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java
index 85bb9a40e3..17bf971584 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java
@@ -228,6 +228,41 @@ public class XDDFLineChartData extends XDDFChartData {
}
}
+ /**
+ * @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();
diff --git a/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java
index c6e91add81..aa0bf374f8 100644
--- a/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java
+++ b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java
@@ -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);
}
}