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;
/**
}
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);
}
/**
}
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);
- }
- }
- }
}
}
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<T> {
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);
+ }
+ }
+ }
}
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
}
}
- // TODO handle minus and plus as numerical data sources
+ public XDDFNumericalDataSource<Double> getMinus() {
+ if (bars.isSetMinus()) {
+ return XDDFDataSourcesFactory.fromDataSource(bars.getMinus());
+ } else {
+ return null;
+ }
+ }
+
+ public void setMinus(XDDFNumericalDataSource<Double> 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<Double> getPlus() {
+ if (bars.isSetPlus()) {
+ return XDDFDataSourcesFactory.fromDataSource(bars.getPlus());
+ } else {
+ return null;
+ }
+ }
+
+ public void setPlus(XDDFNumericalDataSource<Double> 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();
+ }
+ }
}
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<T extends Number> extends XDDFDataSource<T> {
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);
+ }
+ }
+ }
}