Clean-up code for more recent chart types

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1870603 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alain Béarez 2019-11-30 01:20:20 +00:00
parent bb90cfccf0
commit 1a99d1d58e
9 changed files with 55 additions and 43 deletions

View File

@ -126,7 +126,7 @@ public class XDDFArea3DChartData extends XDDFChartData {
@Override
public XDDFChartData.Series addSeries(XDDFDataSource<?> category,
XDDFNumericalDataSource<? extends Number> values) {
final int index = this.series.size();
final long index = this.parent.incrementSeriesCount();
final CTAreaSer ctSer = this.chart.addNewSer();
ctSer.addNewCat();
ctSer.addNewVal();

View File

@ -104,7 +104,7 @@ public class XDDFAreaChartData extends XDDFChartData {
@Override
public XDDFChartData.Series addSeries(XDDFDataSource<?> category,
XDDFNumericalDataSource<? extends Number> values) {
final int index = this.series.size();
final long index = this.parent.incrementSeriesCount();
final CTAreaSer ctSer = this.chart.addNewSer();
ctSer.addNewCat();
ctSer.addNewVal();

View File

@ -181,7 +181,7 @@ public class XDDFBar3DChartData extends XDDFChartData {
@Override
public XDDFChartData.Series addSeries(XDDFDataSource<?> category,
XDDFNumericalDataSource<? extends Number> values) {
final int index = this.series.size();
final long index = this.parent.incrementSeriesCount();
final CTBarSer ctSer = this.chart.addNewSer();
ctSer.addNewTx();
ctSer.addNewCat();

View File

@ -380,7 +380,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
}
public XDDFManualLayout getOrAddManualLayout() {
return new XDDFManualLayout(chart.getPlotArea());
return new XDDFManualLayout(getCTPlotArea());
}
private long seriesCount = 0;
@ -390,7 +390,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
public void plot(XDDFChartData data) {
XSSFSheet sheet = getSheet();
for (XDDFChartData.Series series : data.getSeries()) {
for (int idx = 0; idx < data.getSeriesCount(); idx++) {
XDDFChartData.Series series = data.getSeries(idx);
series.plot();
XDDFDataSource<?> categoryDS = series.getCategoryData();
XDDFNumericalDataSource<? extends Number> valuesDS = series.getValuesData();
@ -468,7 +469,6 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
CTSurface3DChart surfaceChart = plotArea.getSurface3DChartArray(i);
series.add(new XDDFSurface3DChartData(this, surfaceChart, categories, values));
}
// TODO repeat above code for missing charts: Bubble, Doughnut, OfPie and Stock
return series;
}
@ -496,7 +496,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
}
public XDDFValueAxis createValueAxis(AxisPosition pos) {
XDDFValueAxis valueAxis = new XDDFValueAxis(chart.getPlotArea(), pos);
XDDFValueAxis valueAxis = new XDDFValueAxis(getCTPlotArea(), pos);
if (axes.size() == 1) {
XDDFChartAxis axis = axes.get(0);
axis.crossAxis(valueAxis);
@ -513,7 +513,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
* @return series axis with specified position
*/
public XDDFSeriesAxis createSeriesAxis(AxisPosition pos) {
XDDFSeriesAxis seriesAxis = new XDDFSeriesAxis(chart.getPlotArea(), pos);
XDDFSeriesAxis seriesAxis = new XDDFSeriesAxis(getCTPlotArea(), pos);
if (axes.size() == 1) {
XDDFChartAxis axis = axes.get(0);
axis.crossAxis(seriesAxis);
@ -524,7 +524,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
}
public XDDFCategoryAxis createCategoryAxis(AxisPosition pos) {
XDDFCategoryAxis categoryAxis = new XDDFCategoryAxis(chart.getPlotArea(), pos);
XDDFCategoryAxis categoryAxis = new XDDFCategoryAxis(getCTPlotArea(), pos);
if (axes.size() == 1) {
XDDFChartAxis axis = axes.get(0);
axis.crossAxis(categoryAxis);
@ -535,7 +535,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
}
public XDDFDateAxis createDateAxis(AxisPosition pos) {
XDDFDateAxis dateAxis = new XDDFDateAxis(chart.getPlotArea(), pos);
XDDFDateAxis dateAxis = new XDDFDateAxis(getCTPlotArea(), pos);
if (axes.size() == 1) {
XDDFChartAxis axis = axes.get(0);
axis.crossAxis(dateAxis);
@ -602,23 +602,23 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
}
private boolean hasAxes() {
CTPlotArea ctPlotArea = chart.getPlotArea();
CTPlotArea ctPlotArea = getCTPlotArea();
int totalAxisCount = ctPlotArea.sizeOfValAxArray() + ctPlotArea.sizeOfCatAxArray() + ctPlotArea
.sizeOfDateAxArray() + ctPlotArea.sizeOfSerAxArray();
return totalAxisCount > 0;
}
private void parseAxes() {
for (CTCatAx catAx : chart.getPlotArea().getCatAxArray()) {
for (CTCatAx catAx : getCTPlotArea().getCatAxArray()) {
axes.add(new XDDFCategoryAxis(catAx));
}
for (CTDateAx dateAx : chart.getPlotArea().getDateAxArray()) {
for (CTDateAx dateAx : getCTPlotArea().getDateAxArray()) {
axes.add(new XDDFDateAxis(dateAx));
}
for (CTSerAx serAx : chart.getPlotArea().getSerAxArray()) {
for (CTSerAx serAx : getCTPlotArea().getSerAxArray()) {
axes.add(new XDDFSeriesAxis(serAx));
}
for (CTValAx valAx : chart.getPlotArea().getValAxArray()) {
for (CTValAx valAx : getCTPlotArea().getValAxArray()) {
axes.add(new XDDFValueAxis(valAx));
}
}
@ -775,10 +775,11 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
* @since POI 4.0.0
*/
private XSSFRow getRow(XSSFSheet sheet, int index) {
if (sheet.getRow(index) != null) {
return sheet.getRow(index);
} else {
XSSFRow row = sheet.getRow(index);
if (row == null) {
return sheet.createRow(index);
} else {
return row;
}
}
@ -794,10 +795,11 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
* @since POI 4.0.0
*/
private XSSFCell getCell(XSSFRow row, int index) {
if (row.getCell(index) != null) {
return row.getCell(index);
} else {
XSSFCell cell = row.getCell(index);
if (cell == null) {
return row.createCell(index);
} else {
return cell;
}
}

View File

@ -346,20 +346,26 @@ public abstract class XDDFChartData {
private void fillStringCache(CTStrData cache, int numOfPoints, XDDFDataSource<?> data) {
cache.setPtArray(null); // unset old values
if (data.getPointAt(0) != null) { // assuming no value for first is no values at all
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);
}
for (int i = 0; i < numOfPoints; ++i) {
String value = data.getPointAt(i).toString();
if (value != null) {
CTStrVal ctStrVal = cache.addNewPt();
ctStrVal.setIdx(i);
ctStrVal.setV(value);
}
}
}
}
@ -373,20 +379,24 @@ public abstract class XDDFChartData {
cache.setFormatCode(formatCode);
}
cache.setPtArray(null); // unset old values
if (data.getPointAt(0) != null) { // assuming no value for first is no values at all
if (cache.isSetPtCount()) {
cache.getPtCount().setVal(numOfPoints);
} else {
cache.addNewPtCount().setVal(numOfPoints);
}
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);
}
}
}
}

View File

@ -117,7 +117,7 @@ public class XDDFLine3DChartData extends XDDFChartData {
@Override
public XDDFChartData.Series addSeries(XDDFDataSource<?> category,
XDDFNumericalDataSource<? extends Number> values) {
final int index = this.series.size();
final long index = this.parent.incrementSeriesCount();
final CTLineSer ctSer = this.chart.addNewSer();
ctSer.addNewCat();
ctSer.addNewVal();

View File

@ -63,7 +63,7 @@ public class XDDFPie3DChartData extends XDDFChartData {
@Override
public XDDFChartData.Series addSeries(XDDFDataSource<?> category,
XDDFNumericalDataSource<? extends Number> values) {
final int index = this.series.size();
final long index = this.parent.incrementSeriesCount();
final CTPieSer ctSer = this.chart.addNewSer();
ctSer.addNewCat();
ctSer.addNewVal();

View File

@ -101,7 +101,7 @@ public class XDDFSurface3DChartData extends XDDFChartData {
@Override
public XDDFChartData.Series addSeries(XDDFDataSource<?> category,
XDDFNumericalDataSource<? extends Number> values) {
final int index = this.series.size();
final long index = this.parent.incrementSeriesCount();
final CTSurfaceSer ctSer = this.chart.addNewSer();
ctSer.addNewCat();
ctSer.addNewVal();

View File

@ -101,7 +101,7 @@ public class XDDFSurfaceChartData extends XDDFChartData {
@Override
public XDDFChartData.Series addSeries(XDDFDataSource<?> category,
XDDFNumericalDataSource<? extends Number> values) {
final int index = this.series.size();
final long index = this.parent.incrementSeriesCount();
final CTSurfaceSer ctSer = this.chart.addNewSer();
ctSer.addNewCat();
ctSer.addNewVal();