From: Alain BĂ©arez Date: Mon, 13 Jan 2020 00:27:06 +0000 (+0000) Subject: Error bar minus and plus as numerical data sources X-Git-Tag: REL_4_1_2~23 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1bcaa30bed3c5d1bb592d36353fdbe0ccbac8a9e;p=poi.git Error bar minus and plus as numerical data sources git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872692 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java index 0034862eeb..1066e6da81 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java @@ -33,11 +33,9 @@ import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumData; import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumRef; -import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumVal; import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx; import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrData; import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrRef; -import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrVal; import org.openxmlformats.schemas.drawingml.x2006.chart.CTUnsignedInt; /** @@ -211,16 +209,15 @@ public abstract class XDDFChartData { } public void plot() { - int numOfPoints = categoryData.getPointCount(); if (categoryData.isNumeric()) { CTNumData cache = retrieveNumCache(getAxDS(), categoryData); - fillNumCache(cache, numOfPoints, (XDDFNumericalDataSource) categoryData); + ((XDDFNumericalDataSource) categoryData).fillNumericalCache(cache); } else { CTStrData cache = retrieveStrCache(getAxDS(), categoryData); - fillStringCache(cache, numOfPoints, categoryData); + categoryData.fillStringCache(cache); } CTNumData cache = retrieveNumCache(getNumDS(), valuesData); - fillNumCache(cache, numOfPoints, valuesData); + valuesData.fillNumericalCache(cache); } /** @@ -343,61 +340,5 @@ public abstract class XDDFChartData { } return numCache; } - - private void fillStringCache(CTStrData cache, int numOfPoints, XDDFDataSource data) { - cache.setPtArray(null); // unset old values - int effectiveNumOfPoints = 0; - for (int i = 0; i < numOfPoints; ++i) { - Object value = data.getPointAt(i); - if (value != null) { - CTStrVal ctStrVal = cache.addNewPt(); - ctStrVal.setIdx(i); - ctStrVal.setV(value.toString()); - effectiveNumOfPoints++; - } - } - if (effectiveNumOfPoints == 0) { - if (cache.isSetPtCount()) { - cache.unsetPtCount(); - } - } else { - if (cache.isSetPtCount()) { - cache.getPtCount().setVal(numOfPoints); - } else { - cache.addNewPtCount().setVal(numOfPoints); - } - } - } - - private void fillNumCache(CTNumData cache, int numOfPoints, XDDFNumericalDataSource data) { - String formatCode = data.getFormatCode(); - if (formatCode == null) { - if (cache.isSetFormatCode()) { - cache.unsetFormatCode(); - } - } else { - cache.setFormatCode(formatCode); - } - cache.setPtArray(null); // unset old values - int effectiveNumOfPoints = 0; - for (int i = 0; i < numOfPoints; ++i) { - Object value = data.getPointAt(i); - if (value != null) { - CTNumVal ctNumVal = cache.addNewPt(); - ctNumVal.setIdx(i); - ctNumVal.setV(value.toString()); - effectiveNumOfPoints++; - } - } - if (effectiveNumOfPoints == 0) { - cache.unsetPtCount(); - } else { - if (cache.isSetPtCount()) { - cache.getPtCount().setVal(numOfPoints); - } else { - cache.addNewPtCount().setVal(numOfPoints); - } - } - } } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSource.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSource.java index 8d941bf11c..2a51f32bd3 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSource.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSource.java @@ -20,6 +20,9 @@ package org.apache.poi.xddf.usermodel.chart; import org.apache.poi.util.Beta; +import org.apache.poi.util.Internal; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrData; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrVal; @Beta public interface XDDFDataSource { @@ -46,4 +49,34 @@ public interface XDDFDataSource { String getDataRangeReference(); String getFormula(); + + /** + * @since POI 4.1.2 + */ + @Internal + default void fillStringCache(CTStrData cache) { + cache.setPtArray(null); // unset old values + final int numOfPoints = getPointCount(); + int effectiveNumOfPoints = 0; + for (int i = 0; i < numOfPoints; ++i) { + Object value = getPointAt(i); + if (value != null) { + CTStrVal ctStrVal = cache.addNewPt(); + ctStrVal.setIdx(i); + ctStrVal.setV(value.toString()); + effectiveNumOfPoints++; + } + } + if (effectiveNumOfPoints == 0) { + if (cache.isSetPtCount()) { + cache.unsetPtCount(); + } + } else { + if (cache.isSetPtCount()) { + cache.getPtCount().setVal(numOfPoints); + } else { + cache.addNewPtCount().setVal(numOfPoints); + } + } + } } 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 index e3c70a6757..807afc080a 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFErrorBars.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFErrorBars.java @@ -22,6 +22,9 @@ 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; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumData; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumRef; /** * @since POI 4.1.2 @@ -166,5 +169,61 @@ public class XDDFErrorBars { } } - // TODO handle minus and plus as numerical data sources + public XDDFNumericalDataSource getMinus() { + if (bars.isSetMinus()) { + return XDDFDataSourcesFactory.fromDataSource(bars.getMinus()); + } else { + return null; + } + } + + public void setMinus(XDDFNumericalDataSource ds) { + if (ds == null) { + if (bars.isSetMinus()) { + bars.unsetMinus(); + } + } else { + if (bars.isSetMinus()) { + ds.fillNumericalCache(retrieveCache(bars.getMinus(), ds.getDataRangeReference())); + } else { + CTNumDataSource ctDS = bars.addNewMinus(); + ctDS.addNewNumLit(); + ds.fillNumericalCache(retrieveCache(ctDS, ds.getDataRangeReference())); + } + } + } + + public XDDFNumericalDataSource getPlus() { + if (bars.isSetPlus()) { + return XDDFDataSourcesFactory.fromDataSource(bars.getPlus()); + } else { + return null; + } + } + + public void setPlus(XDDFNumericalDataSource ds) { + if (ds == null) { + if (bars.isSetPlus()) { + bars.unsetPlus(); + } + } else { + if (bars.isSetPlus()) { + ds.fillNumericalCache(retrieveCache(bars.getPlus(), ds.getDataRangeReference())); + } else { + CTNumDataSource ctDS = bars.addNewPlus(); + ctDS.addNewNumLit(); + ds.fillNumericalCache(retrieveCache(ctDS, ds.getDataRangeReference())); + } + } + } + + private CTNumData retrieveCache(CTNumDataSource ds, String dataRangeReference) { + if (ds.isSetNumRef()) { + CTNumRef numRef = ds.getNumRef(); + numRef.setF(dataRangeReference); + return numRef.getNumCache(); + } else { + return ds.getNumLit(); + } + } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFNumericalDataSource.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFNumericalDataSource.java index add2f3ccbf..74e1fb3364 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFNumericalDataSource.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFNumericalDataSource.java @@ -20,6 +20,9 @@ package org.apache.poi.xddf.usermodel.chart; import org.apache.poi.util.Beta; +import org.apache.poi.util.Internal; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumData; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumVal; @Beta public interface XDDFNumericalDataSource extends XDDFDataSource { @@ -31,4 +34,40 @@ public interface XDDFNumericalDataSource extends XDDFDataSourc default boolean isLiteral() { return false; } + + /** + * @since POI 4.1.2 + */ + @Internal + default void fillNumericalCache(CTNumData cache) { + String formatCode = getFormatCode(); + if (formatCode == null) { + if (cache.isSetFormatCode()) { + cache.unsetFormatCode(); + } + } else { + cache.setFormatCode(formatCode); + } + cache.setPtArray(null); // unset old values + final int numOfPoints = getPointCount(); + int effectiveNumOfPoints = 0; + for (int i = 0; i < numOfPoints; ++i) { + Object value = getPointAt(i); + if (value != null) { + CTNumVal ctNumVal = cache.addNewPt(); + ctNumVal.setIdx(i); + ctNumVal.setV(value.toString()); + effectiveNumOfPoints++; + } + } + if (effectiveNumOfPoints == 0) { + cache.unsetPtCount(); + } else { + if (cache.isSetPtCount()) { + cache.getPtCount().setVal(numOfPoints); + } else { + cache.addNewPtCount().setVal(numOfPoints); + } + } + } }