]> source.dussan.org Git - poi.git/commitdiff
Implement error bars for bar and line charts
authorAlain Béarez <abearez@apache.org>
Mon, 13 Jan 2020 00:26:59 +0000 (00:26 +0000)
committerAlain Béarez <abearez@apache.org>
Mon, 13 Jan 2020 00:26:59 +0000 (00:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872690 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorBarType.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorDirection.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorValueType.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFErrorBars.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java
src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java

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 (file)
index 0000000..3086000
--- /dev/null
@@ -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 (file)
index 0000000..bcde0a1
--- /dev/null
@@ -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 (file)
index 0000000..8af436b
--- /dev/null
@@ -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);
+    }
+}
index 4adb94c950ba7225a153190c4a3cca7b7b87b688..666802b1fa21db0c5c5a66d90ce7490dc2131efa 100644 (file)
@@ -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()) {
index a79d587dce7d8537eee500581069e58d2891dc38..4261212d333f4cc0938b71717fc1453cf9fb1314 100644 (file)
@@ -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 (file)
index 0000000..e3c70a6
--- /dev/null
@@ -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
+}
index d744d4d2ed36a176ce44c646ac5e5f7100edb16e..ac47f4d3735db72a19c7c71266ab1b30270bad18 100644 (file)
@@ -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();
index 85bb9a40e3498292f30a5e1a338f3a2d8e975657..17bf9715845f712391c3a7fd938dab33d11622ac 100644 (file)
@@ -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();
index c6e91add8176fb8e29d25d68238a721cd996defe..aa0bf374f891298129c196863ff0df8a89143d97 100644 (file)
@@ -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);
     }
 
 }