diff options
author | Alain Béarez <abearez@apache.org> | 2019-05-21 00:13:40 +0000 |
---|---|---|
committer | Alain Béarez <abearez@apache.org> | 2019-05-21 00:13:40 +0000 |
commit | 093cbcfccae37db00b182683df1fc6480047230f (patch) | |
tree | 048b9e247433b5c1607b2b496355bdc2ebff8d54 /src | |
parent | af1dacfe2c5ccfb8bee0c1e7517cce5d698f6833 (diff) | |
download | poi-093cbcfccae37db00b182683df1fc6480047230f.tar.gz poi-093cbcfccae37db00b182683df1fc6480047230f.zip |
code cleanup plus fix for bug 63153
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1859590 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
23 files changed, 871 insertions, 311 deletions
diff --git a/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java b/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java index 3b96eb0bda..bd8ff14c4c 100644 --- a/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java +++ b/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java @@ -108,7 +108,7 @@ public class BarChartDemo { values1[6] = 16.0; // if you ever want to change the underlying data final XDDFNumericalDataSource<? extends Number> valuesData2 = XDDFDataSourcesFactory.fromArray(values2, valuesDataRange2, 2); - XDDFChartData.Series series1 = bar.getSeries().get(0); + XDDFChartData.Series series1 = bar.getSeries(0); series1.replaceData(categoriesData, valuesData); series1.setTitle(series[0], chart.setSheetTitle(series[0], 0)); XDDFChartData.Series series2 = bar.addSeries(categoriesData, valuesData2); diff --git a/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java b/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java index 4f020550db..1cc8aa2b10 100644 --- a/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java +++ b/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java @@ -98,10 +98,10 @@ public class PieChartDemo { final XDDFDataSource<?> categoriesData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange); final XDDFNumericalDataSource<? extends Number> valuesData = XDDFDataSourcesFactory.fromArray(values, valuesDataRange); - XDDFPieChartData.Series firstSeries = (XDDFPieChartData.Series) pie.getSeries().get(0); + XDDFPieChartData.Series firstSeries = (XDDFPieChartData.Series) pie.getSeries(0); firstSeries.replaceData(categoriesData, valuesData); firstSeries.setTitle(chartTitle, chart.setSheetTitle(chartTitle, 0)); - firstSeries.setExplosion(25); + firstSeries.setExplosion(25L); chart.plot(pie); // save the result diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarAndLineChart.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarAndLineChart.java index f674a37a38..b8e36ccbef 100644 --- a/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarAndLineChart.java +++ b/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarAndLineChart.java @@ -144,16 +144,16 @@ public class BarAndLineChart { // the line chart on secondary axis XDDFLineChartData lines = (XDDFLineChartData) chart.createData(ChartTypes.LINE, lineCategories, rightValues); - - //uncomment below line if only primary axis required and comment above line + + //uncomment below line if only primary axis required and comment above line // the line chart on primary axis /*XDDFLineChartData lines = (XDDFLineChartData) chart.createData(ChartTypes.LINE, lineCategories, leftValues);*/ - - + + XDDFLineChartData.Series series2 = (XDDFLineChartData.Series) lines.addSeries(xs, ys2); - series2.updateIdXVal(1); - series2.updateOrderVal(1); + series2.setIndex(1); + series2.setOrder(1); series2.setTitle("Lines", new CellReference("Sheet1!$C$1")); lines.setVaryColors(true); chart.plot(lines); diff --git a/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java b/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java index ebce9410d1..731b732f8d 100644 --- a/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java +++ b/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java @@ -110,7 +110,7 @@ public class BarChartExample { values1[6] = 16.0; // if you ever want to change the underlying data final XDDFNumericalDataSource<? extends Number> valuesData2 = XDDFDataSourcesFactory.fromArray(values2, valuesDataRange2, 2); - XDDFChartData.Series series1 = bar.getSeries().get(0); + XDDFChartData.Series series1 = bar.getSeries(0); series1.replaceData(categoriesData, valuesData); series1.setTitle(series[0], chart.setSheetTitle(series[0], 0)); XDDFChartData.Series series2 = bar.addSeries(categoriesData, valuesData2); diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFLinearShadeProperties.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFLinearShadeProperties.java index c3d4566dc3..54680ba522 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFLinearShadeProperties.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/XDDFLinearShadeProperties.java @@ -52,7 +52,7 @@ public class XDDFLinearShadeProperties { } } - public Boolean getScaled() { + public Boolean isScaled() { if (props.isSetScaled()) { return props.getScaled(); } else { diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/Shape.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/Shape.java new file mode 100644 index 0000000000..2150290b16 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/Shape.java @@ -0,0 +1,48 @@ +/* ==================================================================== + 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.STShape; + +public enum Shape { + BOX(STShape.BOX), + CONE(STShape.CONE), + CONE_TO_MAX(STShape.CONE_TO_MAX), + CYLINDER(STShape.CYLINDER), + PYRAMID(STShape.PYRAMID), + PYRAMID_TO_MAX(STShape.PYRAMID_TO_MAX); + + final STShape.Enum underlying; + + Shape(STShape.Enum grouping) { + this.underlying = grouping; + } + + private final static HashMap<STShape.Enum, Shape> reverse = new HashMap<>(); + static { + for (Shape value : values()) { + reverse.put(value.underlying, value); + } + } + + static Shape valueOf(STShape.Enum grouping) { + return reverse.get(grouping); + } +} diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFArea3DChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFArea3DChartData.java index 28ccea3355..339cbccc26 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFArea3DChartData.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFArea3DChartData.java @@ -20,6 +20,7 @@ package org.apache.poi.xddf.usermodel.chart; import java.util.Map; import org.apache.poi.util.Beta; +import org.apache.poi.util.Internal; import org.apache.poi.xddf.usermodel.XDDFShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.chart.CTArea3DChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTAreaSer; @@ -52,26 +53,70 @@ public class XDDFArea3DChartData extends XDDFChartData { defineAxes(chart.getAxIdArray(), categories, values); } + @Internal @Override - public void setVaryColors(boolean varyColors) { - if (chart.isSetVaryColors()) { - chart.getVaryColors().setVal(varyColors); + protected void removeCTSeries(int n) { + chart.removeSer(n); + } + + @Override + public void setVaryColors(Boolean varyColors) { + if (varyColors == null) { + if (chart.isSetVaryColors()) { + chart.unsetVaryColors(); + } } else { - chart.addNewVaryColors().setVal(varyColors); + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } } } public Grouping getGrouping() { - return Grouping.valueOf(chart.getGrouping().getVal()); + if (chart.isSetGrouping()) { + return Grouping.valueOf(chart.getGrouping().getVal()); + } else { + return null; + } } - public void setGrouping(Grouping grouping) { - if (chart.getGrouping() != null) { - chart.getGrouping().setVal(grouping.underlying); - } else { - chart.addNewGrouping().setVal(grouping.underlying); - } - } + public void setGrouping(Grouping grouping) { + if (grouping == null) { + if (chart.isSetGrouping()) { + chart.unsetGrouping(); + } + } else { + if (chart.isSetGrouping()) { + chart.getGrouping().setVal(grouping.underlying); + } else { + chart.addNewGrouping().setVal(grouping.underlying); + } + } + } + + public Integer getGapDepth() { + if (chart.isSetGapDepth()) { + return chart.getGapDepth().getVal(); + } else { + return null; + } + } + + public void setGapDepth(Integer depth) { + if (depth == null) { + if (chart.isSetGapDepth()) { + chart.unsetGapDepth(); + } + } else { + if (chart.isSetGapDepth()) { + chart.getGapDepth().setVal(depth); + } else { + chart.addNewGapDepth().setVal(depth); + } + } + } @Override public XDDFChartData.Series addSeries(XDDFDataSource<?> category, @@ -155,14 +200,14 @@ public class XDDFArea3DChartData extends XDDFChartData { protected CTNumDataSource getNumDS() { return series.getVal(); } - + @Override - public void updateIdXVal(long val) { + public void setIndex(long val) { series.getIdx().setVal(val); } - + @Override - public void updateOrderVal(long val) { + public void setOrder(long val) { series.getOrder().setVal(val); } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFAreaChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFAreaChartData.java index e04d1e4d8b..04e08b697f 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFAreaChartData.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFAreaChartData.java @@ -20,13 +20,11 @@ package org.apache.poi.xddf.usermodel.chart; import java.util.Map; import org.apache.poi.util.Beta; +import org.apache.poi.util.Internal; import org.apache.poi.xddf.usermodel.XDDFShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.chart.CTAreaChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTAreaSer; import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; -import org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart; -import org.openxmlformats.schemas.drawingml.x2006.chart.CTLineSer; -import org.openxmlformats.schemas.drawingml.x2006.chart.CTMarker; import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx; @@ -55,26 +53,48 @@ public class XDDFAreaChartData extends XDDFChartData { defineAxes(chart.getAxIdArray(), categories, values); } + @Internal @Override - public void setVaryColors(boolean varyColors) { - if (chart.isSetVaryColors()) { - chart.getVaryColors().setVal(varyColors); + protected void removeCTSeries(int n) { + chart.removeSer(n); + } + + @Override + public void setVaryColors(Boolean varyColors) { + if (varyColors == null) { + if (chart.isSetVaryColors()) { + chart.unsetVaryColors(); + } } else { - chart.addNewVaryColors().setVal(varyColors); + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } } } public Grouping getGrouping() { - return Grouping.valueOf(chart.getGrouping().getVal()); + if (chart.isSetGrouping()) { + return Grouping.valueOf(chart.getGrouping().getVal()); + } else { + return null; + } } - public void setGrouping(Grouping grouping) { - if (chart.getGrouping() != null) { - chart.getGrouping().setVal(grouping.underlying); - } else { - chart.addNewGrouping().setVal(grouping.underlying); - } - } + public void setGrouping(Grouping grouping) { + if (grouping == null) { + if (chart.isSetGrouping()) { + chart.unsetGrouping(); + } + } else { + if (chart.isSetGrouping()) { + chart.getGrouping().setVal(grouping.underlying); + } else { + chart.addNewGrouping().setVal(grouping.underlying); + } + } + } @Override public XDDFChartData.Series addSeries(XDDFDataSource<?> category, @@ -158,14 +178,14 @@ public class XDDFAreaChartData extends XDDFChartData { protected CTNumDataSource getNumDS() { return series.getVal(); } - + @Override - public void updateIdXVal(long val) { + public void setIndex(long val) { series.getIdx().setVal(val); } - + @Override - public void updateOrderVal(long val) { + public void setOrder(long val) { series.getOrder().setVal(val); } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java index 12543846f1..17126f7ade 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java @@ -20,6 +20,7 @@ package org.apache.poi.xddf.usermodel.chart; import java.util.Map; import org.apache.poi.util.Beta; +import org.apache.poi.util.Internal; import org.apache.poi.xddf.usermodel.XDDFShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTBar3DChart; @@ -55,12 +56,24 @@ public class XDDFBar3DChartData extends XDDFChartData { defineAxes(chart.getAxIdArray(), categories, values); } + @Internal @Override - public void setVaryColors(boolean varyColors) { - if (chart.isSetVaryColors()) { - chart.getVaryColors().setVal(varyColors); + protected void removeCTSeries(int n) { + chart.removeSer(n); + } + + @Override + public void setVaryColors(Boolean varyColors) { + if (varyColors == null) { + if (chart.isSetVaryColors()) { + chart.unsetVaryColors(); + } } else { - chart.addNewVaryColors().setVal(varyColors); + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } } } @@ -76,31 +89,87 @@ public class XDDFBar3DChartData extends XDDFChartData { if (chart.isSetGrouping()) { return BarGrouping.valueOf(chart.getGrouping().getVal()); } else { - return BarGrouping.STANDARD; + return null; } } public void setBarGrouping(BarGrouping grouping) { - if (chart.isSetGrouping()) { - chart.getGrouping().setVal(grouping.underlying); + if (grouping == null) { + if (chart.isSetGrouping()) { + chart.unsetGrouping(); + } + } else { + if (chart.isSetGrouping()) { + chart.getGrouping().setVal(grouping.underlying); + } else { + chart.addNewGrouping().setVal(grouping.underlying); + } + } + } + + public Integer getGapDepth() { + if (chart.isSetGapDepth()) { + return chart.getGapDepth().getVal(); + } else { + return null; + } + } + + public void setGapDepth(Integer depth) { + if (depth == null) { + if (chart.isSetGapDepth()) { + chart.unsetGapDepth(); + } } else { - chart.addNewGrouping().setVal(grouping.underlying); + if (chart.isSetGapDepth()) { + chart.getGapDepth().setVal(depth); + } else { + chart.addNewGapDepth().setVal(depth); + } } } - public int getGapWidth() { + public Integer getGapWidth() { if (chart.isSetGapWidth()) { return chart.getGapWidth().getVal(); } else { - return 0; + return null; } } - public void setGapWidth(int width) { - if (chart.isSetGapWidth()) { - chart.getGapWidth().setVal(width); + public void setGapWidth(Integer width) { + if (width == null) { + if (chart.isSetGapWidth()) { + chart.unsetGapWidth(); + } + } else { + if (chart.isSetGapWidth()) { + chart.getGapWidth().setVal(width); + } else { + chart.addNewGapWidth().setVal(width); + } + } + } + + public Shape getShape() { + if (chart.isSetShape()) { + return Shape.valueOf(chart.getShape().getVal()); } else { - chart.addNewGapWidth().setVal(width); + return null; + } + } + + public void setShape(Shape shape) { + if (shape == null) { + if (chart.isSetShape()) { + chart.unsetShape(); + } + } else { + if (chart.isSetShape()) { + chart.getShape().setVal(shape.underlying); + } else { + chart.addNewShape().setVal(shape.underlying); + } } } @@ -187,14 +256,14 @@ public class XDDFBar3DChartData extends XDDFChartData { protected CTNumDataSource getNumDS() { return series.getVal(); } - + @Override - public void updateIdXVal(long val) { + public void setIndex(long val) { series.getIdx().setVal(val); } - + @Override - public void updateOrderVal(long val) { + public void setOrder(long val) { series.getOrder().setVal(val); } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java index ee8c225265..3197ccf7e9 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBarChartData.java @@ -20,6 +20,7 @@ package org.apache.poi.xddf.usermodel.chart; import java.util.Map; import org.apache.poi.util.Beta; +import org.apache.poi.util.Internal; import org.apache.poi.xddf.usermodel.XDDFShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTBarChart; @@ -55,12 +56,24 @@ public class XDDFBarChartData extends XDDFChartData { defineAxes(chart.getAxIdArray(), categories, values); } + @Internal @Override - public void setVaryColors(boolean varyColors) { - if (chart.isSetVaryColors()) { - chart.getVaryColors().setVal(varyColors); + protected void removeCTSeries(int n) { + chart.removeSer(n); + } + + @Override + public void setVaryColors(Boolean varyColors) { + if (varyColors == null) { + if (chart.isSetVaryColors()) { + chart.unsetVaryColors(); + } } else { - chart.addNewVaryColors().setVal(varyColors); + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } } } @@ -76,31 +89,74 @@ public class XDDFBarChartData extends XDDFChartData { if (chart.isSetGrouping()) { return BarGrouping.valueOf(chart.getGrouping().getVal()); } else { - return BarGrouping.STANDARD; + return null; } } public void setBarGrouping(BarGrouping grouping) { - if (chart.isSetGrouping()) { - chart.getGrouping().setVal(grouping.underlying); + if (grouping == null) { + if (chart.isSetGrouping()) { + chart.unsetGrouping(); + } } else { - chart.addNewGrouping().setVal(grouping.underlying); + if (chart.isSetGrouping()) { + chart.getGrouping().setVal(grouping.underlying); + } else { + chart.addNewGrouping().setVal(grouping.underlying); + } } } - public int getGapWidth() { + public Integer getGapWidth() { if (chart.isSetGapWidth()) { return chart.getGapWidth().getVal(); } else { - return 0; + return null; } } - public void setGapWidth(int width) { - if (chart.isSetGapWidth()) { - chart.getGapWidth().setVal(width); + public void setGapWidth(Integer width) { + if (width == null) { + if (chart.isSetGapWidth()) { + chart.unsetGapWidth(); + } } else { - chart.addNewGapWidth().setVal(width); + if (chart.isSetGapWidth()) { + chart.getGapWidth().setVal(width); + } else { + chart.addNewGapWidth().setVal(width); + } + } + } + + public Byte getOverlap() { + if (chart.isSetOverlap()) { + return chart.getOverlap().getVal(); + } else { + return null; + } + } + + /** + * Minimum inclusive: -100 + * <br/> + * Maximum inclusive: 100 + * @param overlap + */ + public void setOverlap(Byte overlap) { + if (overlap == null) { + if (chart.isSetOverlap()) { + chart.unsetOverlap(); + } + } else { + if (overlap < -100 || 100 < overlap) { + return; + } + if (chart.isSetOverlap()) { + chart.getOverlap().setVal(overlap); + } else { + chart.addNewOverlap().setVal(overlap); + } } } @@ -187,15 +243,15 @@ public class XDDFBarChartData extends XDDFChartData { protected CTNumDataSource getNumDS() { return series.getVal(); } - + @Override - public void updateIdXVal(long val) { - series.getIdx().setVal(val); - } - - @Override - public void updateOrderVal(long val) { - series.getOrder().setVal(val); - } + protected void setIndex(long index) { + series.getIdx().setVal(index); + } + + @Override + protected void setOrder(long order) { + series.getOrder().setVal(order); + } } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java index 65140ebbb1..5464373bc4 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java @@ -57,19 +57,26 @@ import org.apache.poi.xssf.usermodel.XSSFTable; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlOptions; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTArea3DChart; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTAreaChart; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTBar3DChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTBarChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTBoolean; import org.openxmlformats.schemas.drawingml.x2006.chart.CTCatAx; import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace; import org.openxmlformats.schemas.drawingml.x2006.chart.CTDateAx; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTLine3DChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTPie3DChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea; import org.openxmlformats.schemas.drawingml.x2006.chart.CTRadarChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerAx; import org.openxmlformats.schemas.drawingml.x2006.chart.CTSurface; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTSurface3DChart; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTSurfaceChart; import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle; import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx; import org.openxmlformats.schemas.drawingml.x2006.chart.CTView3D; @@ -83,7 +90,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumns; @Beta public abstract class XDDFChart extends POIXMLDocumentPart implements TextContainer { - + /** * default width of chart in emu */ @@ -93,7 +100,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai * default height of chart in emu */ public static final int DEFAULT_HEIGHT = 500000; - + /** * default x-coordinate of chart in emu */ @@ -103,7 +110,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai * default y-coordinate value of chart in emu */ public static final int DEFAULT_Y = 10; - + /** * Underlying workbook */ @@ -390,21 +397,46 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai Map<Long, XDDFChartAxis> categories = getCategoryAxes(); Map<Long, XDDFValueAxis> values = getValueAxes(); + for (int i = 0; i < plotArea.sizeOfAreaChartArray(); i++) { + CTAreaChart areaChart = plotArea.getAreaChartArray(i); + series.add(new XDDFAreaChartData(areaChart, categories, values)); + } + + for (int i = 0; i < plotArea.sizeOfArea3DChartArray(); i++) { + CTArea3DChart areaChart = plotArea.getArea3DChartArray(i); + series.add(new XDDFArea3DChartData(areaChart, categories, values)); + } + for (int i = 0; i < plotArea.sizeOfBarChartArray(); i++) { CTBarChart barChart = plotArea.getBarChartArray(i); series.add(new XDDFBarChartData(barChart, categories, values)); } + for (int i = 0; i < plotArea.sizeOfBar3DChartArray(); i++) { + CTBar3DChart barChart = plotArea.getBar3DChartArray(i); + series.add(new XDDFBar3DChartData(barChart, categories, values)); + } + for (int i = 0; i < plotArea.sizeOfLineChartArray(); i++) { CTLineChart lineChart = plotArea.getLineChartArray(i); series.add(new XDDFLineChartData(lineChart, categories, values)); } + for (int i = 0; i < plotArea.sizeOfLine3DChartArray(); i++) { + CTLine3DChart lineChart = plotArea.getLine3DChartArray(i); + series.add(new XDDFLine3DChartData(lineChart, categories, values)); + } + for (int i = 0; i < plotArea.sizeOfPieChartArray(); i++) { CTPieChart pieChart = plotArea.getPieChartArray(i); series.add(new XDDFPieChartData(pieChart)); } + for (int i = 0; i < plotArea.sizeOfPie3DChartArray(); i++) { + CTPie3DChart pieChart = plotArea.getPie3DChartArray(i); + series.add(new XDDFPie3DChartData(pieChart)); + } + for (int i = 0; i < plotArea.sizeOfRadarChartArray(); i++) { CTRadarChart radarChart = plotArea.getRadarChartArray(i); series.add(new XDDFRadarChartData(radarChart, categories, values)); @@ -415,7 +447,17 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai series.add(new XDDFScatterChartData(scatterChart, categories, values)); } - // TODO repeat above code for all kind of charts + for (int i = 0; i < plotArea.sizeOfSurfaceChartArray(); i++) { + CTSurfaceChart surfaceChart = plotArea.getSurfaceChartArray(i); + series.add(new XDDFSurfaceChartData(surfaceChart, categories, values)); + } + + for (int i = 0; i < plotArea.sizeOfSurface3DChartArray(); i++) { + CTSurface3DChart surfaceChart = plotArea.getSurface3DChartArray(i); + series.add(new XDDFSurface3DChartData(surfaceChart, categories, values)); + } + + // TODO repeat above code for missing charts: Bubble, Doughnut, OfPie and Stock return series; } @@ -453,7 +495,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai } /** - * this method will return series axis with specified position + * this method will return series axis with specified position * * @param pos axis position Left, Right, Top, Bottom * @return series axis with specified position @@ -502,13 +544,12 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai public XDDFChartData createData(ChartTypes type, XDDFChartAxis category, XDDFValueAxis values) { Map<Long, XDDFChartAxis> categories = null; Map<Long, XDDFValueAxis> mapValues = null; - - if(ChartTypes.PIE != type && ChartTypes.PIE3D != type) - { + + if (ChartTypes.PIE != type && ChartTypes.PIE3D != type) { categories = Collections.singletonMap(category.getId(), category); mapValues = Collections.singletonMap(values.getId(), values); } - + final CTPlotArea plotArea = getCTPlotArea(); switch (type) { case AREA: @@ -796,9 +837,9 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai XSSFRow row = this.getRow(sheet, 0); XSSFCell cell = this.getCell(row, column); cell.setCellValue(title); - + CTTable ctTable = this.getSheetTable(sheet); - + this.updateSheetTable(ctTable, title, column); return new CellReference(sheet.getSheetName(), 0, column, true, true); } 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 66753f0aa5..6ef965c4b8 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 @@ -20,10 +20,12 @@ package org.apache.poi.xddf.usermodel.chart; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Map; import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.Beta; +import org.apache.poi.util.Internal; import org.apache.poi.xddf.usermodel.XDDFShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumData; @@ -75,11 +77,62 @@ public abstract class XDDFChartData { return valueAxes; } + /** + * Calls to <code>getSeries().add(series)</code> or to <code>getSeries().remove(series)</code> + * may corrupt the workbook. + * + * <p> + * Instead, use the following methods: + * <ul> + * <li>{@link #getSeriesCount()}</li> + * <li>{@link #getSeries(int)}</li> + * <li>{@link #addSeries(XDDFDataSource,XDDFNumericalDataSource)}</li> + * <li>{@link #removeSeries(int)}</li> + * </ul> + * + * @deprecated since POI 4.1.1 + * @return + */ + @Deprecated public List<Series> getSeries() { return series; } - public abstract void setVaryColors(boolean varyColors); + public final int getSeriesCount() { + return series.size(); + } + + public final Series getSeries(int n) { + return series.get(n); + } + + public final void removeSeries(int n) { + final String procName = "removeSeries"; + if (n < 0 || series.size() <= n) { + throw new IllegalArgumentException(String.format(Locale.ROOT, "%s(%d): illegal index", procName, n)); + } + series.remove(n); + removeCTSeries(n); + } + + /** + * This method should be implemented in every class that extends <code>XDDFChartData</code>. + * <p> + * A typical implementation would be + * + * <pre><code> + protected void removeCTSeries(int n) { + chart.removeSer(n); + } + + * </code></pre> + * + * @param n + */ + @Internal + protected abstract void removeCTSeries(int n); + + public abstract void setVaryColors(Boolean varyColors); public abstract XDDFChartData.Series addSeries(XDDFDataSource<?> category, XDDFNumericalDataSource<? extends Number> values); @@ -98,19 +151,9 @@ public abstract class XDDFChartData { protected abstract CTNumDataSource getNumDS(); - /** - * This method will update series id value - * - * @param val - */ - public abstract void updateIdXVal(long val); - - /** - * this method will update series order value - * - * @param val - */ - public abstract void updateOrderVal(long val); + protected abstract void setIndex(long index); + + protected abstract void setOrder(long order); protected Series(XDDFDataSource<?> category, XDDFNumericalDataSource<? extends Number> values) { replaceData(category, values); diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java index 6b95566377..28c7cacea9 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java @@ -20,6 +20,7 @@ package org.apache.poi.xddf.usermodel.chart; import java.util.Map; import org.apache.poi.util.Beta; +import org.apache.poi.util.Internal; import org.apache.poi.xddf.usermodel.XDDFShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTLine3DChart; @@ -53,12 +54,24 @@ public class XDDFLine3DChartData extends XDDFChartData { defineAxes(chart.getAxIdArray(), categories, values); } + @Internal @Override - public void setVaryColors(boolean varyColors) { - if (chart.isSetVaryColors()) { - chart.getVaryColors().setVal(varyColors); + protected void removeCTSeries(int n) { + chart.removeSer(n); + } + + @Override + public void setVaryColors(Boolean varyColors) { + if (varyColors == null) { + if (chart.isSetVaryColors()) { + chart.unsetVaryColors(); + } } else { - chart.addNewVaryColors().setVal(varyColors); + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } } } @@ -74,6 +87,28 @@ public class XDDFLine3DChartData extends XDDFChartData { } } + public Integer getGapDepth() { + if (chart.isSetGapDepth()) { + return chart.getGapDepth().getVal(); + } else { + return null; + } + } + + public void setGapDepth(Integer depth) { + if (depth == null) { + if (chart.isSetGapDepth()) { + chart.unsetGapDepth(); + } + } else { + if (chart.isSetGapDepth()) { + chart.getGapDepth().setVal(depth); + } else { + chart.addNewGapDepth().setVal(depth); + } + } + } + @Override public XDDFChartData.Series addSeries(XDDFDataSource<?> category, XDDFNumericalDataSource<? extends Number> values) { @@ -148,7 +183,7 @@ public class XDDFLine3DChartData extends XDDFChartData { } - public Boolean getSmooth() { + public Boolean isSmooth() { if (series.isSetSmooth()) { return series.getSmooth().getVal(); } else { @@ -217,14 +252,14 @@ public class XDDFLine3DChartData extends XDDFChartData { protected CTNumDataSource getNumDS() { return series.getVal(); } - + @Override - public void updateIdXVal(long val) { + public void setIndex(long val) { series.getIdx().setVal(val); } - + @Override - public void updateOrderVal(long val) { + public void setOrder(long val) { series.getOrder().setVal(val); } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java index 32bd022592..0682780764 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java @@ -20,6 +20,7 @@ package org.apache.poi.xddf.usermodel.chart; import java.util.Map; import org.apache.poi.util.Beta; +import org.apache.poi.util.Internal; import org.apache.poi.xddf.usermodel.XDDFShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart; @@ -53,12 +54,24 @@ public class XDDFLineChartData extends XDDFChartData { defineAxes(chart.getAxIdArray(), categories, values); } + @Internal @Override - public void setVaryColors(boolean varyColors) { - if (chart.isSetVaryColors()) { - chart.getVaryColors().setVal(varyColors); + protected void removeCTSeries(int n) { + chart.removeSer(n); + } + + @Override + public void setVaryColors(Boolean varyColors) { + if (varyColors == null) { + if (chart.isSetVaryColors()) { + chart.unsetVaryColors(); + } } else { - chart.addNewVaryColors().setVal(varyColors); + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } } } @@ -150,7 +163,7 @@ public class XDDFLineChartData extends XDDFChartData { /** * @since 4.0.1 */ - public Boolean getSmooth() { + public Boolean isSmooth() { if (series.isSetSmooth()) { return series.getSmooth().getVal(); } else { @@ -219,14 +232,14 @@ public class XDDFLineChartData extends XDDFChartData { protected CTNumDataSource getNumDS() { return series.getVal(); } - + @Override - public void updateIdXVal(long val) { + public void setIndex(long val) { series.getIdx().setVal(val); } - + @Override - public void updateOrderVal(long val) { + public void setOrder(long val) { series.getOrder().setVal(val); } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFPie3DChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFPie3DChartData.java index 7f7ce539f4..44aacb28df 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFPie3DChartData.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFPie3DChartData.java @@ -18,6 +18,7 @@ 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.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource; @@ -36,12 +37,24 @@ public class XDDFPie3DChartData extends XDDFChartData { } } + @Internal @Override - public void setVaryColors(boolean varyColors) { - if (chart.isSetVaryColors()) { - chart.getVaryColors().setVal(varyColors); + protected void removeCTSeries(int n) { + chart.removeSer(n); + } + + @Override + public void setVaryColors(Boolean varyColors) { + if (varyColors == null) { + if (chart.isSetVaryColors()) { + chart.unsetVaryColors(); + } } else { - chart.addNewVaryColors().setVal(varyColors); + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } } } @@ -118,19 +131,25 @@ public class XDDFPie3DChartData extends XDDFChartData { } } - public long getExplosion() { + public Long getExplosion() { if (series.isSetExplosion()) { return series.getExplosion().getVal(); } else { - return 0; + return null; } } - public void setExplosion(long explosion) { - if (series.isSetExplosion()) { - series.getExplosion().setVal(explosion); + public void setExplosion(Long explosion) { + if (explosion == null) { + if (series.isSetExplosion()) { + series.unsetExplosion(); + } } else { - series.addNewExplosion().setVal(explosion); + if (series.isSetExplosion()) { + series.getExplosion().setVal(explosion); + } else { + series.addNewExplosion().setVal(explosion); + } } } @@ -143,14 +162,14 @@ public class XDDFPie3DChartData extends XDDFChartData { protected CTNumDataSource getNumDS() { return series.getVal(); } - + @Override - public void updateIdXVal(long val) { + public void setIndex(long val) { series.getIdx().setVal(val); } - + @Override - public void updateOrderVal(long val) { + public void setOrder(long val) { series.getOrder().setVal(val); } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFPieChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFPieChartData.java index d31210da7f..97bbc6c37d 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFPieChartData.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFPieChartData.java @@ -18,6 +18,7 @@ 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.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource; @@ -36,12 +37,49 @@ public class XDDFPieChartData extends XDDFChartData { } } + @Internal @Override - public void setVaryColors(boolean varyColors) { - if (chart.isSetVaryColors()) { - chart.getVaryColors().setVal(varyColors); + protected void removeCTSeries(int n) { + chart.removeSer(n); + } + + @Override + public void setVaryColors(Boolean varyColors) { + if (varyColors == null) { + if (chart.isSetVaryColors()) { + chart.unsetVaryColors(); + } } else { - chart.addNewVaryColors().setVal(varyColors); + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } + } + } + + public Integer getFirstSliceAngle() { + if (chart.isSetFirstSliceAng()) { + return chart.getFirstSliceAng().getVal(); + } else { + return null; + } + } + + public void setFirstSliceAngle(Integer angle) { + if (angle == null) { + if (chart.isSetFirstSliceAng()) { + chart.unsetFirstSliceAng(); + } + } else { + if (angle < 0 || 360 < angle) { + throw new IllegalArgumentException("angle must be between 0 and 360"); + } + if (chart.isSetFirstSliceAng()) { + chart.getFirstSliceAng().setVal(angle); + } else { + chart.addNewFirstSliceAng().setVal(angle); + } } } @@ -118,19 +156,25 @@ public class XDDFPieChartData extends XDDFChartData { } } - public long getExplosion() { + public Long getExplosion() { if (series.isSetExplosion()) { return series.getExplosion().getVal(); } else { - return 0; + return null; } } - public void setExplosion(long explosion) { - if (series.isSetExplosion()) { - series.getExplosion().setVal(explosion); + public void setExplosion(Long explosion) { + if (explosion == null) { + if (series.isSetExplosion()) { + series.unsetExplosion(); + } } else { - series.addNewExplosion().setVal(explosion); + if (series.isSetExplosion()) { + series.getExplosion().setVal(explosion); + } else { + series.addNewExplosion().setVal(explosion); + } } } @@ -143,14 +187,14 @@ public class XDDFPieChartData extends XDDFChartData { protected CTNumDataSource getNumDS() { return series.getVal(); } - + @Override - public void updateIdXVal(long val) { + public void setIndex(long val) { series.getIdx().setVal(val); } - + @Override - public void updateOrderVal(long val) { + public void setOrder(long val) { series.getOrder().setVal(val); } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFRadarChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFRadarChartData.java index 4f494b6f2c..a9dad76a3c 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFRadarChartData.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFRadarChartData.java @@ -20,6 +20,7 @@ package org.apache.poi.xddf.usermodel.chart; import java.util.Map; import org.apache.poi.util.Beta; +import org.apache.poi.util.Internal; import org.apache.poi.xddf.usermodel.XDDFShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource; @@ -53,12 +54,24 @@ public class XDDFRadarChartData extends XDDFChartData { defineAxes(chart.getAxIdArray(), categories, values); } + @Internal @Override - public void setVaryColors(boolean varyColors) { - if (chart.isSetVaryColors()) { - chart.getVaryColors().setVal(varyColors); + protected void removeCTSeries(int n) { + chart.removeSer(n); + } + + @Override + public void setVaryColors(Boolean varyColors) { + if (varyColors == null) { + if (chart.isSetVaryColors()) { + chart.unsetVaryColors(); + } } else { - chart.addNewVaryColors().setVal(varyColors); + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } } } @@ -156,15 +169,15 @@ public class XDDFRadarChartData extends XDDFChartData { protected CTNumDataSource getNumDS() { return series.getVal(); } - + @Override - public void updateIdXVal(long val) { + public void setIndex(long val) { series.getIdx().setVal(val); } - - @Override - public void updateOrderVal(long val) { - series.getOrder().setVal(val); - } + + @Override + public void setOrder(long val) { + series.getOrder().setVal(val); + } } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java index 162833b85d..a7f45f4d23 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java @@ -20,6 +20,7 @@ package org.apache.poi.xddf.usermodel.chart; import java.util.Map; import org.apache.poi.util.Beta; +import org.apache.poi.util.Internal; import org.apache.poi.xddf.usermodel.XDDFShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTMarker; @@ -54,12 +55,24 @@ public class XDDFScatterChartData extends XDDFChartData { defineAxes(chart.getAxIdArray(), categories, values); } + @Internal @Override - public void setVaryColors(boolean varyColors) { - if (chart.isSetVaryColors()) { - chart.getVaryColors().setVal(varyColors); + protected void removeCTSeries(int n) { + chart.removeSer(n); + } + + @Override + public void setVaryColors(Boolean varyColors) { + if (varyColors == null) { + if (chart.isSetVaryColors()) { + chart.unsetVaryColors(); + } } else { - chart.addNewVaryColors().setVal(varyColors); + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } } } @@ -119,7 +132,7 @@ public class XDDFScatterChartData extends XDDFChartData { /** * @since 4.0.1 */ - public Boolean getSmooth() { + public Boolean isSmooth() { if (series.isSetSmooth()) { return series.getSmooth().getVal(); } else { @@ -228,15 +241,15 @@ public class XDDFScatterChartData extends XDDFChartData { protected CTNumDataSource getNumDS() { return series.getYVal(); } - + @Override - public void updateIdXVal(long val) { + public void setIndex(long val) { series.getIdx().setVal(val); } - - @Override - public void updateOrderVal(long val) { - series.getOrder().setVal(val); - } + + @Override + public void setOrder(long val) { + series.getOrder().setVal(val); + } } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSurface3DChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSurface3DChartData.java index 273a77c814..e565638790 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSurface3DChartData.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSurface3DChartData.java @@ -20,9 +20,9 @@ package org.apache.poi.xddf.usermodel.chart; import java.util.Map; import org.apache.poi.util.Beta; +import org.apache.poi.util.Internal; import org.apache.poi.xddf.usermodel.XDDFShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; -import org.openxmlformats.schemas.drawingml.x2006.chart.CTBoolean; import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx; import org.openxmlformats.schemas.drawingml.x2006.chart.CTSurface3DChart; @@ -52,35 +52,47 @@ public class XDDFSurface3DChartData extends XDDFChartData { } defineAxes(chart.getAxIdArray(), categories, values); } - - public void setSeriesAxisId(XDDFSeriesAxis seriesAxis) { - chart.addNewAxId().setVal(seriesAxis.getId()); + + @Internal + @Override + protected void removeCTSeries(int n) { + chart.removeSer(n); + } + + /** + * Surface chart is not supporting vary color property. + */ + @Override + public void setVaryColors(Boolean varyColors) { + // nothing to do } - - public CTBoolean getWireframe() { + + public void defineSeriesAxis(XDDFSeriesAxis seriesAxis) { + chart.addNewAxId().setVal(seriesAxis.getId()); + } + + public Boolean isWireframe() { if (chart.isSetWireframe()) { - return chart.getWireframe(); + return chart.getWireframe().getVal(); } else { - return chart.addNewWireframe(); + return null; } } - public void setWireframe(boolean val) { - if (chart.isSetWireframe()) { - chart.getWireframe().setVal(val); + public void setWireframe(Boolean show) { + if (show == null) { + if (chart.isSetWireframe()) { + chart.unsetWireframe(); + } } else { - chart.addNewWireframe().setVal(val); + if (chart.isSetWireframe()) { + chart.getWireframe().setVal(show); + } else { + chart.addNewWireframe().setVal(show); + } } } - /** - * Surface chart is not supporting vary color property - */ - @Override - public void setVaryColors(boolean varyColors) { - - } - @Override public XDDFChartData.Series addSeries(XDDFDataSource<?> category, XDDFNumericalDataSource<? extends Number> values) { @@ -119,11 +131,11 @@ public class XDDFSurface3DChartData extends XDDFChartData { } /** - * Surface chart is not supporting vary show leader lines property + * Surface chart is not supporting show leader lines property */ @Override public void setShowLeaderLines(boolean showLeaderLines) { - + // nothing to do } @Override @@ -159,14 +171,14 @@ public class XDDFSurface3DChartData extends XDDFChartData { protected CTNumDataSource getNumDS() { return series.getVal(); } - + @Override - public void updateIdXVal(long val) { + public void setIndex(long val) { series.getIdx().setVal(val); } - + @Override - public void updateOrderVal(long val) { + public void setOrder(long val) { series.getOrder().setVal(val); } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSurfaceChartData.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSurfaceChartData.java index 64545229bc..7c95a575b2 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSurfaceChartData.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSurfaceChartData.java @@ -20,9 +20,9 @@ package org.apache.poi.xddf.usermodel.chart; import java.util.Map; import org.apache.poi.util.Beta; +import org.apache.poi.util.Internal; import org.apache.poi.xddf.usermodel.XDDFShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; -import org.openxmlformats.schemas.drawingml.x2006.chart.CTBoolean; import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource; import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx; import org.openxmlformats.schemas.drawingml.x2006.chart.CTSurfaceChart; @@ -31,7 +31,6 @@ import org.openxmlformats.schemas.drawingml.x2006.chart.CTSurfaceSer; @Beta public class XDDFSurfaceChartData extends XDDFChartData { private CTSurfaceChart chart; - public XDDFSurfaceChartData(CTSurfaceChart chart, Map<Long, XDDFChartAxis> categories, Map<Long, XDDFValueAxis> values) { this.chart = chart; @@ -40,6 +39,7 @@ public class XDDFSurfaceChartData extends XDDFChartData { } defineAxes(categories, values); } + private void defineAxes(Map<Long, XDDFChartAxis> categories, Map<Long, XDDFValueAxis> values) { if (chart.sizeOfAxIdArray() == 0) { for (Long id : categories.keySet()) { @@ -52,34 +52,46 @@ public class XDDFSurfaceChartData extends XDDFChartData { defineAxes(chart.getAxIdArray(), categories, values); } - public void setSeriesAxisId(XDDFSeriesAxis seriesAxis) { - chart.addNewAxId().setVal(seriesAxis.getId()); + @Internal + @Override + protected void removeCTSeries(int n) { + chart.removeSer(n); + } + + /** + * Surface chart is not supporting vary color property. + */ + @Override + public void setVaryColors(Boolean varyColors) { + // nothing to do + } + + public void defineSeriesAxis(XDDFSeriesAxis seriesAxis) { + chart.addNewAxId().setVal(seriesAxis.getId()); } - - public CTBoolean getWireframe() { + + public Boolean isWireframe() { if (chart.isSetWireframe()) { - return chart.getWireframe(); + return chart.getWireframe().getVal(); } else { - return chart.addNewWireframe(); + return null; } } - public void setWireframe(boolean val) { - if (chart.isSetWireframe()) { - chart.getWireframe().setVal(val); + public void setWireframe(Boolean show) { + if (show == null) { + if (chart.isSetWireframe()) { + chart.unsetWireframe(); + } } else { - chart.addNewWireframe().setVal(val); + if (chart.isSetWireframe()) { + chart.getWireframe().setVal(show); + } else { + chart.addNewWireframe().setVal(show); + } } } - /** - * Surface chart is not supporting vary color property - */ - @Override - public void setVaryColors(boolean varyColors) { - - } - @Override public XDDFChartData.Series addSeries(XDDFDataSource<?> category, XDDFNumericalDataSource<? extends Number> values) { @@ -118,11 +130,11 @@ public class XDDFSurfaceChartData extends XDDFChartData { } /** - * Surface chart is not supporting vary show leader lines property + * Surface chart is not supporting show leader lines property */ @Override public void setShowLeaderLines(boolean showLeaderLines) { - + // nothing to do } @Override @@ -158,14 +170,14 @@ public class XDDFSurfaceChartData extends XDDFChartData { protected CTNumDataSource getNumDS() { return series.getVal(); } - + @Override - public void updateIdXVal(long val) { + public void setIndex(long val) { series.getIdx().setVal(val); } - + @Override - public void updateOrderVal(long val) { + public void setOrder(long val) { series.getOrder().setVal(val); } } diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFView3D.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFView3D.java index 42ad2cd003..5d9d10f614 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFView3D.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFView3D.java @@ -19,85 +19,162 @@ package org.apache.poi.xddf.usermodel.chart; +import org.apache.poi.util.Internal; import org.openxmlformats.schemas.drawingml.x2006.chart.CTView3D; - public class XDDFView3D { private final CTView3D view3D; - public XDDFView3D(CTView3D view3D) { + @Internal + protected XDDFView3D(CTView3D view3D) { this.view3D = view3D; } - - public int getXRotationAngle() { - return view3D.getRotX().getVal(); + + public Byte getXRotationAngle() { + if (view3D.isSetRotX()) { + return view3D.getRotX().getVal(); + } else { + return null; + } + } + + public void setXRotationAngle(Byte rotation) { + if (rotation == null) { + if (view3D.isSetRotX()) { + view3D.unsetRotX(); + } + } else { + if (rotation < -90 || 90 < rotation) { + throw new IllegalArgumentException("rotation must be between -90 and 90"); + } + if (view3D.isSetRotX()) { + view3D.getRotX().setVal(rotation); + } else { + view3D.addNewRotX().setVal(rotation); + } + } + } + + public Integer getYRotationAngle() { + if (view3D.isSetRotY()) { + return view3D.getRotY().getVal(); + } else { + return null; + } + } + + public void setYRotationAngle(Integer rotation) { + if (rotation == null) { + if (view3D.isSetRotY()) { + view3D.unsetRotY(); + } + } else { + if (rotation < 0 || 360 < rotation) { + throw new IllegalArgumentException("rotation must be between 0 and 360"); + } + if (view3D.isSetRotY()) { + view3D.getRotY().setVal(rotation); + } else { + view3D.addNewRotY().setVal(rotation); + } + } + } + + public Boolean hasRightAngleAxes() { + if (view3D.isSetRAngAx()) { + return view3D.getRAngAx().getVal(); + } else { + return null; + } + } + + public void setRightAngleAxes(Boolean rightAngles) { + if (rightAngles == null) { + if (view3D.isSetRAngAx()) { + view3D.unsetRAngAx(); + } + } else { + if (view3D.isSetRAngAx()) { + view3D.getRAngAx().setVal(rightAngles); + } else { + view3D.addNewRAngAx().setVal(rightAngles); + } + } } - - public void setXRotationAngle(int val) { - if (view3D.isSetRotY()) { - view3D.getRotY().setVal(val); - } else { - view3D.addNewRotY().setVal(val); - } - } - - public int getYRotationAngle() { - return view3D.getRotY().getVal(); + + public Short getPerspectiveAngle() { + if (view3D.isSetPerspective()) { + return view3D.getPerspective().getVal(); + } else { + return null; + } + } + + public void setPerspectiveAngle(Short perspective) { + if (perspective == null) { + if (view3D.isSetPerspective()) { + view3D.unsetPerspective(); + } + } else { + if (perspective < 0 || 240 < perspective) { + throw new IllegalArgumentException("perspective must be between 0 and 240"); + } + if (view3D.isSetPerspective()) { + view3D.getPerspective().setVal(perspective); + } else { + view3D.addNewPerspective().setVal(perspective); + } + } } - - public void setYRotationAngle(int val) { - if (view3D.isSetRotY()) { - view3D.getRotY().setVal(val); - } else { - view3D.addNewRotY().setVal(val); - } - } - - public boolean getRightAngleAxes() { - return view3D.getRAngAx().getVal(); + + public Integer getDepthPercent() { + if (view3D.isSetDepthPercent()) { + return view3D.getDepthPercent().getVal(); + } else { + return null; + } } - - public void setRightAngleAxes(boolean val) { - if (view3D.isSetRAngAx()) { - view3D.getRAngAx().setVal(val); - } else { - view3D.addNewRAngAx().setVal(val); - } - } - - public short getPerspectiveAngle() { - return view3D.getPerspective().getVal(); + + public void setDepthPercent(Integer percent) { + if (percent == null) { + if (view3D.isSetDepthPercent()) { + view3D.unsetDepthPercent(); + } + } else { + if (percent < 20 || 2000 < percent) { + throw new IllegalArgumentException("percent must be between 20 and 2000"); + } + if (view3D.isSetDepthPercent()) { + view3D.getDepthPercent().setVal(percent); + } else { + view3D.addNewDepthPercent().setVal(percent); + } + } } - - public void setPerspectiveAngle(short val) { - if (view3D.isSetPerspective()) { - view3D.getPerspective().setVal(val); - } else { - view3D.addNewPerspective().setVal(val); - } - } - - public int getDepthPercentVal() { - return view3D.getDepthPercent().getVal(); + + public Integer getHPercent() { + if (view3D.isSetHPercent()) { + return view3D.getHPercent().getVal(); + } else { + return null; + } } - - public void setDepthPercent(int val) { - if (view3D.isSetDepthPercent()) { - view3D.getDepthPercent().setVal(val); - } else { - view3D.addNewDepthPercent().setVal(val); - } - } - - public int getHeightPercent() { - return view3D.getHPercent().getVal(); + + public void setHPercent(Integer percent) { + if (percent == null) { + if (view3D.isSetHPercent()) { + view3D.unsetHPercent(); + } + } else { + if (percent < 5 || 500 < percent) { + throw new IllegalArgumentException("percent must be between 5 and 500"); + } + if (view3D.isSetHPercent()) { + view3D.getHPercent().setVal(percent); + } else { + view3D.addNewHPercent().setVal(percent); + } + } } - - public void setHeightPercent(int val) { - if (view3D.isSetHPercent()) { - view3D.getHPercent().setVal(val); - } else { - view3D.addNewHPercent().setVal(val); - } - } + } diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java index 27775fadee..412520aede 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java @@ -67,9 +67,9 @@ public class TestXSLFChart { List<XDDFChartData> data = findChartData(chart); XDDFPieChartData pie = (XDDFPieChartData) data.get(0); - XDDFPieChartData.Series firstSeries = (XDDFPieChartData.Series) pie.getSeries().get(0); - firstSeries.setExplosion(25); - assertEquals(25, firstSeries.getExplosion()); + XDDFPieChartData.Series firstSeries = (XDDFPieChartData.Series) pie.getSeries(0); + firstSeries.setExplosion(25L); + assertEquals(Long.valueOf(25), firstSeries.getExplosion()); fillChartData(chart, pie); pptx.close(); @@ -87,7 +87,7 @@ public class TestXSLFChart { XDDFBarChartData bar = (XDDFBarChartData) data.get(0); assertEquals(BarDirection.BAR, bar.getBarDirection()); assertEquals(BarGrouping.CLUSTERED, bar.getBarGrouping()); - assertEquals(100, bar.getGapWidth()); + assertEquals(Integer.valueOf(100), bar.getGapWidth()); fillChartData(chart, bar); XDDFBarChartData column = (XDDFBarChartData) findChartData(chart2).get(0); @@ -153,7 +153,7 @@ public class TestXSLFChart { final String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0)); final String valuesDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 1, 1)); - final XDDFChartData.Series series = data.getSeries().get(0); + final XDDFChartData.Series series = data.getSeries(0); final XDDFDataSource<?> categoryData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange); final XDDFNumericalDataSource<Integer> valuesData = XDDFDataSourcesFactory.fromArray(values, valuesDataRange); series.replaceData(categoryData, valuesData); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java index c7f1b17b9c..652644b7ca 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java @@ -713,7 +713,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook { assertNotNull(read); assertSheetOrder(read, "Sheet1-Renamed", "Sheet2", "Sheet3"); XSSFSheet sheet = (XSSFSheet) read.getSheet("Sheet1-Renamed"); - XDDFChartData.Series series = sheet.getDrawingPatriarch().getCharts().get(0).getChartSeries().get(0).getSeries().get(0); + XDDFChartData.Series series = sheet.getDrawingPatriarch().getCharts().get(0).getChartSeries().get(0).getSeries(0); assertTrue("should be a bar chart data series", series instanceof XDDFBarChartData.Series); String formula = ((XDDFBarChartData.Series) series).getCategoryData().getFormula(); assertTrue("should contain new sheet name", formula.startsWith("'Sheet1-Renamed'!")); @@ -1142,7 +1142,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook { wb.close(); } - + /** * See bug #61700 * @throws Exception @@ -1152,14 +1152,14 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook { Workbook workbook = _testDataProvider.createWorkbook(); workbook.createSheet().createRow(0).createCell(0).setCellFormula("B1+C1"); workbook.getCreationHelper().createFormulaEvaluator().evaluateAll(); - + assertFalse(workbook.getForceFormulaRecalculation()); workbook.setForceFormulaRecalculation(true); assertTrue(workbook.getForceFormulaRecalculation()); - + Workbook wbBack = _testDataProvider.writeOutAndReadBack(workbook); assertTrue(wbBack.getForceFormulaRecalculation()); - + workbook.close(); wbBack.close(); } |