Browse Source

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
tags/REL_4_1_2
Alain Béarez 4 years ago
parent
commit
22dd38ef72

+ 45
- 0
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorBarType.java View File

@@ -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);
}
}

+ 44
- 0
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorDirection.java View File

@@ -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);
}
}

+ 47
- 0
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ErrorValueType.java View File

@@ -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);
}
}

+ 35
- 0
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java View 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()) {

+ 35
- 0
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java View 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()) {

+ 170
- 0
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFErrorBars.java View File

@@ -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
}

+ 35
- 0
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java View 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();

+ 35
- 0
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java View 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();

+ 9
- 0
src/ooxml/testcases/org/apache/poi/xddf/usermodel/TestNecessaryOOXMLClasses.java View 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);
}

}

Loading…
Cancel
Save