From: Alain BĂ©arez Date: Tue, 21 May 2019 00:13:28 +0000 (+0000) Subject: Added more chart supports. X-Git-Tag: REL_4_1_1~99 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=af1dacfe2c5ccfb8bee0c1e7517cce5d698f6833;p=poi.git Added more chart supports. fixed bug while creating chart with bar and line series. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1859589 13f79535-47bb-0310-9956-ffa450edef68 --- 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 1de43cb974..f674a37a38 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 @@ -134,17 +134,26 @@ public class BarAndLineChart { lineCategories.crossAxis(rightValues); // the bar chart - XDDFBarChartData bar = (XDDFBarChartData) chart.createData(ChartTypes.BAR, lineCategories, rightValues); + XDDFBarChartData bar = (XDDFBarChartData) chart.createData(ChartTypes.BAR, barCategories, leftValues); XDDFBarChartData.Series series1 = (XDDFBarChartData.Series) bar.addSeries(xs, ys1); series1.setTitle("Bars", new CellReference("Sheet1!$B$1")); bar.setVaryColors(true); bar.setBarDirection(BarDirection.COL); chart.plot(bar); - // the line chart + // 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 + // 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.setTitle("Lines", new CellReference("Sheet1!$C$1")); lines.setVaryColors(true); chart.plot(lines); diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ChartTypes.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ChartTypes.java index 7ecaab0699..fcec761933 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ChartTypes.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/ChartTypes.java @@ -17,9 +17,16 @@ package org.apache.poi.xddf.usermodel.chart; public enum ChartTypes { + AREA, + AREA3D, BAR, + BAR3D, LINE, + LINE3D, PIE, + PIE3D, RADAR, - SCATTER + SCATTER, + SURFACE, + SURFACE3D } 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 new file mode 100644 index 0000000000..28ccea3355 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFArea3DChartData.java @@ -0,0 +1,169 @@ +/* ==================================================================== + 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.Map; + +import org.apache.poi.util.Beta; +import org.apache.poi.xddf.usermodel.XDDFShapeProperties; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTArea3DChart; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTAreaSer; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx; + +@Beta +public class XDDFArea3DChartData extends XDDFChartData { + private CTArea3DChart chart; + + public XDDFArea3DChartData(CTArea3DChart chart, Map categories, + Map values) { + this.chart = chart; + for (CTAreaSer series : chart.getSerList()) { + this.series.add(new Series(series, series.getCat(), series.getVal())); + } + defineAxes(categories, values); + } + + private void defineAxes(Map categories, Map values) { + if (chart.sizeOfAxIdArray() == 0) { + for (Long id : categories.keySet()) { + chart.addNewAxId().setVal(id); + } + for (Long id : values.keySet()) { + chart.addNewAxId().setVal(id); + } + } + defineAxes(chart.getAxIdArray(), categories, values); + } + + @Override + public void setVaryColors(boolean varyColors) { + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } + } + + public Grouping getGrouping() { + return Grouping.valueOf(chart.getGrouping().getVal()); + } + + public void setGrouping(Grouping grouping) { + if (chart.getGrouping() != null) { + chart.getGrouping().setVal(grouping.underlying); + } else { + chart.addNewGrouping().setVal(grouping.underlying); + } + } + + @Override + public XDDFChartData.Series addSeries(XDDFDataSource category, + XDDFNumericalDataSource values) { + final int index = this.series.size(); + final CTAreaSer ctSer = this.chart.addNewSer(); + ctSer.addNewCat(); + ctSer.addNewVal(); + ctSer.addNewIdx().setVal(index); + ctSer.addNewOrder().setVal(index); + final Series added = new Series(ctSer, category, values); + this.series.add(added); + return added; + } + + public class Series extends XDDFChartData.Series { + private CTAreaSer series; + + protected Series(CTAreaSer series, XDDFDataSource category, + XDDFNumericalDataSource values) { + super(category, values); + this.series = series; + } + + protected Series(CTAreaSer series, CTAxDataSource category, CTNumDataSource values) { + super(XDDFDataSourcesFactory.fromDataSource(category), XDDFDataSourcesFactory.fromDataSource(values)); + this.series = series; + } + + @Override + protected CTSerTx getSeriesText() { + if (series.isSetTx()) { + return series.getTx(); + } else { + return series.addNewTx(); + } + } + + @Override + public void setShowLeaderLines(boolean showLeaderLines) { + if (!series.isSetDLbls()) { + series.addNewDLbls(); + } + if (series.getDLbls().isSetShowLeaderLines()) { + series.getDLbls().getShowLeaderLines().setVal(showLeaderLines); + } else { + series.getDLbls().addNewShowLeaderLines().setVal(showLeaderLines); + } + } + + @Override + public XDDFShapeProperties getShapeProperties() { + if (series.isSetSpPr()) { + return new XDDFShapeProperties(series.getSpPr()); + } else { + return null; + } + } + + @Override + public void setShapeProperties(XDDFShapeProperties properties) { + if (properties == null) { + if (series.isSetSpPr()) { + series.unsetSpPr(); + } + } else { + if (series.isSetSpPr()) { + series.setSpPr(properties.getXmlObject()); + } else { + series.addNewSpPr().set(properties.getXmlObject()); + } + } + } + + @Override + protected CTAxDataSource getAxDS() { + return series.getCat(); + } + + @Override + 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); + } + } +} 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 new file mode 100644 index 0000000000..e04d1e4d8b --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFAreaChartData.java @@ -0,0 +1,172 @@ +/* ==================================================================== + 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.Map; + +import org.apache.poi.util.Beta; +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; + +@Beta +public class XDDFAreaChartData extends XDDFChartData { + private CTAreaChart chart; + + public XDDFAreaChartData(CTAreaChart chart, Map categories, + Map values) { + this.chart = chart; + for (CTAreaSer series : chart.getSerList()) { + this.series.add(new Series(series, series.getCat(), series.getVal())); + } + defineAxes(categories, values); + } + + private void defineAxes(Map categories, Map values) { + if (chart.sizeOfAxIdArray() == 0) { + for (Long id : categories.keySet()) { + chart.addNewAxId().setVal(id); + } + for (Long id : values.keySet()) { + chart.addNewAxId().setVal(id); + } + } + defineAxes(chart.getAxIdArray(), categories, values); + } + + @Override + public void setVaryColors(boolean varyColors) { + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } + } + + public Grouping getGrouping() { + return Grouping.valueOf(chart.getGrouping().getVal()); + } + + public void setGrouping(Grouping grouping) { + if (chart.getGrouping() != null) { + chart.getGrouping().setVal(grouping.underlying); + } else { + chart.addNewGrouping().setVal(grouping.underlying); + } + } + + @Override + public XDDFChartData.Series addSeries(XDDFDataSource category, + XDDFNumericalDataSource values) { + final int index = this.series.size(); + final CTAreaSer ctSer = this.chart.addNewSer(); + ctSer.addNewCat(); + ctSer.addNewVal(); + ctSer.addNewIdx().setVal(index); + ctSer.addNewOrder().setVal(index); + final Series added = new Series(ctSer, category, values); + this.series.add(added); + return added; + } + + public class Series extends XDDFChartData.Series { + private CTAreaSer series; + + protected Series(CTAreaSer series, XDDFDataSource category, + XDDFNumericalDataSource values) { + super(category, values); + this.series = series; + } + + protected Series(CTAreaSer series, CTAxDataSource category, CTNumDataSource values) { + super(XDDFDataSourcesFactory.fromDataSource(category), XDDFDataSourcesFactory.fromDataSource(values)); + this.series = series; + } + + @Override + protected CTSerTx getSeriesText() { + if (series.isSetTx()) { + return series.getTx(); + } else { + return series.addNewTx(); + } + } + + @Override + public void setShowLeaderLines(boolean showLeaderLines) { + if (!series.isSetDLbls()) { + series.addNewDLbls(); + } + if (series.getDLbls().isSetShowLeaderLines()) { + series.getDLbls().getShowLeaderLines().setVal(showLeaderLines); + } else { + series.getDLbls().addNewShowLeaderLines().setVal(showLeaderLines); + } + } + + @Override + public XDDFShapeProperties getShapeProperties() { + if (series.isSetSpPr()) { + return new XDDFShapeProperties(series.getSpPr()); + } else { + return null; + } + } + + @Override + public void setShapeProperties(XDDFShapeProperties properties) { + if (properties == null) { + if (series.isSetSpPr()) { + series.unsetSpPr(); + } + } else { + if (series.isSetSpPr()) { + series.setSpPr(properties.getXmlObject()); + } else { + series.addNewSpPr().set(properties.getXmlObject()); + } + } + } + + @Override + protected CTAxDataSource getAxDS() { + return series.getCat(); + } + + @Override + 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); + } + } +} 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 new file mode 100644 index 0000000000..12543846f1 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFBar3DChartData.java @@ -0,0 +1,201 @@ +/* ==================================================================== + 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.Map; + +import org.apache.poi.util.Beta; +import org.apache.poi.xddf.usermodel.XDDFShapeProperties; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTBar3DChart; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTBarSer; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx; + +@Beta +public class XDDFBar3DChartData extends XDDFChartData { + private CTBar3DChart chart; + + public XDDFBar3DChartData(CTBar3DChart chart, Map categories, + Map values) { + this.chart = chart; + if (chart.getBarDir() == null) { + chart.addNewBarDir().setVal(BarDirection.BAR.underlying); + } + for (CTBarSer series : chart.getSerList()) { + this.series.add(new Series(series, series.getCat(), series.getVal())); + } + defineAxes(categories, values); + } + + private void defineAxes(Map categories, Map values) { + if (chart.sizeOfAxIdArray() == 0) { + for (Long id : categories.keySet()) { + chart.addNewAxId().setVal(id); + } + for (Long id : values.keySet()) { + chart.addNewAxId().setVal(id); + } + } + defineAxes(chart.getAxIdArray(), categories, values); + } + + @Override + public void setVaryColors(boolean varyColors) { + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } + } + + public BarDirection getBarDirection() { + return BarDirection.valueOf(chart.getBarDir().getVal()); + } + + public void setBarDirection(BarDirection direction) { + chart.getBarDir().setVal(direction.underlying); + } + + public BarGrouping getBarGrouping() { + if (chart.isSetGrouping()) { + return BarGrouping.valueOf(chart.getGrouping().getVal()); + } else { + return BarGrouping.STANDARD; + } + } + + public void setBarGrouping(BarGrouping grouping) { + if (chart.isSetGrouping()) { + chart.getGrouping().setVal(grouping.underlying); + } else { + chart.addNewGrouping().setVal(grouping.underlying); + } + } + + public int getGapWidth() { + if (chart.isSetGapWidth()) { + return chart.getGapWidth().getVal(); + } else { + return 0; + } + } + + public void setGapWidth(int width) { + if (chart.isSetGapWidth()) { + chart.getGapWidth().setVal(width); + } else { + chart.addNewGapWidth().setVal(width); + } + } + + @Override + public XDDFChartData.Series addSeries(XDDFDataSource category, + XDDFNumericalDataSource values) { + final int index = this.series.size(); + final CTBarSer ctSer = this.chart.addNewSer(); + ctSer.addNewTx(); + ctSer.addNewCat(); + ctSer.addNewVal(); + ctSer.addNewIdx().setVal(index); + ctSer.addNewOrder().setVal(index); + final Series added = new Series(ctSer, category, values); + this.series.add(added); + return added; + } + + public class Series extends XDDFChartData.Series { + private CTBarSer series; + + protected Series(CTBarSer series, XDDFDataSource category, + XDDFNumericalDataSource values) { + super(category, values); + this.series = series; + } + + protected Series(CTBarSer series, CTAxDataSource category, CTNumDataSource values) { + super(XDDFDataSourcesFactory.fromDataSource(category), XDDFDataSourcesFactory.fromDataSource(values)); + this.series = series; + } + + @Override + protected CTSerTx getSeriesText() { + if (series.isSetTx()) { + return series.getTx(); + } else { + return series.addNewTx(); + } + } + + @Override + public void setShowLeaderLines(boolean showLeaderLines) { + if (!series.isSetDLbls()) { + series.addNewDLbls(); + } + if (series.getDLbls().isSetShowLeaderLines()) { + series.getDLbls().getShowLeaderLines().setVal(showLeaderLines); + } else { + series.getDLbls().addNewShowLeaderLines().setVal(showLeaderLines); + } + } + + @Override + public XDDFShapeProperties getShapeProperties() { + if (series.isSetSpPr()) { + return new XDDFShapeProperties(series.getSpPr()); + } else { + return null; + } + } + + @Override + public void setShapeProperties(XDDFShapeProperties properties) { + if (properties == null) { + if (series.isSetSpPr()) { + series.unsetSpPr(); + } + } else { + if (series.isSetSpPr()) { + series.setSpPr(properties.getXmlObject()); + } else { + series.addNewSpPr().set(properties.getXmlObject()); + } + } + } + + @Override + protected CTAxDataSource getAxDS() { + return series.getCat(); + } + + @Override + 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); + } + } +} 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 ce79733aa8..ee8c225265 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 @@ -187,5 +187,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); + } } } 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 e1a7b2e9d3..65140ebbb1 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 @@ -72,6 +72,7 @@ import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerAx; import org.openxmlformats.schemas.drawingml.x2006.chart.CTSurface; import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle; import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTView3D; import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument; import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties; @@ -301,6 +302,21 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai } } + /** + * Get or Add chart 3D view into chart + * + * @return this method will add 3D view + */ + public XDDFView3D getOrAddView3D() { + CTView3D view3D; + if (chart.isSetView3D()) { + view3D = chart.getView3D(); + } else { + view3D = chart.addNewView3D(); + } + return new XDDFView3D(view3D); + } + /** * Get the chart title body if there is one, i.e. title is set and is not a * formula. @@ -436,6 +452,23 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai return valueAxis; } + /** + * this method will return series axis with specified position + * + * @param pos axis position Left, Right, Top, Bottom + * @return series axis with specified position + */ + public XDDFSeriesAxis createSeriesAxis(AxisPosition pos) { + XDDFSeriesAxis seriesAxis = new XDDFSeriesAxis(chart.getPlotArea(), pos); + if (axes.size() == 1) { + XDDFChartAxis axis = axes.get(0); + axis.crossAxis(seriesAxis); + seriesAxis.crossAxis(axis); + } + axes.add(seriesAxis); + return seriesAxis; + } + public XDDFCategoryAxis createCategoryAxis(AxisPosition pos) { XDDFCategoryAxis categoryAxis = new XDDFCategoryAxis(chart.getPlotArea(), pos); if (axes.size() == 1) { @@ -458,21 +491,50 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai return dateAxis; } + /** + * this method will return specified chart data with category and series values + * + * @param type chart type + * @param category category values of chart + * @param values series values of chart + * @return specified chart data. + */ public XDDFChartData createData(ChartTypes type, XDDFChartAxis category, XDDFValueAxis values) { - Map categories = Collections.singletonMap(category.getId(), category); - Map mapValues = Collections.singletonMap(values.getId(), values); + Map categories = null; + Map mapValues = null; + + 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: + return new XDDFAreaChartData(plotArea.addNewAreaChart(), categories, mapValues); + case AREA3D: + return new XDDFArea3DChartData(plotArea.addNewArea3DChart(), categories, mapValues); case BAR: return new XDDFBarChartData(plotArea.addNewBarChart(), categories, mapValues); + case BAR3D: + return new XDDFBar3DChartData(plotArea.addNewBar3DChart(), categories, mapValues); case LINE: return new XDDFLineChartData(plotArea.addNewLineChart(), categories, mapValues); + case LINE3D: + return new XDDFLine3DChartData(plotArea.addNewLine3DChart(), categories, mapValues); case PIE: return new XDDFPieChartData(plotArea.addNewPieChart()); + case PIE3D: + return new XDDFPie3DChartData(plotArea.addNewPie3DChart()); case RADAR: return new XDDFRadarChartData(plotArea.addNewRadarChart(), categories, mapValues); case SCATTER: return new XDDFScatterChartData(plotArea.addNewScatterChart(), categories, mapValues); + case SURFACE: + return new XDDFSurfaceChartData(plotArea.addNewSurfaceChart(), categories, mapValues); + case SURFACE3D: + return new XDDFSurface3DChartData(plotArea.addNewSurface3DChart(), categories, mapValues); default: return null; } 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 e23b51a46c..66753f0aa5 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 @@ -98,6 +98,20 @@ 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 Series(XDDFDataSource category, XDDFNumericalDataSource 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 new file mode 100644 index 0000000000..6b95566377 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java @@ -0,0 +1,231 @@ +/* ==================================================================== + 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.Map; + +import org.apache.poi.util.Beta; +import org.apache.poi.xddf.usermodel.XDDFShapeProperties; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTLine3DChart; +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; + +@Beta +public class XDDFLine3DChartData extends XDDFChartData { + private CTLine3DChart chart; + + public XDDFLine3DChartData(CTLine3DChart chart, Map categories, + Map values) { + this.chart = chart; + for (CTLineSer series : chart.getSerList()) { + this.series.add(new Series(series, series.getCat(), series.getVal())); + } + defineAxes(categories, values); + } + + private void defineAxes(Map categories, Map values) { + if (chart.sizeOfAxIdArray() == 0) { + for (Long id : categories.keySet()) { + chart.addNewAxId().setVal(id); + } + for (Long id : values.keySet()) { + chart.addNewAxId().setVal(id); + } + } + defineAxes(chart.getAxIdArray(), categories, values); + } + + @Override + public void setVaryColors(boolean varyColors) { + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } + } + + public Grouping getGrouping() { + return Grouping.valueOf(chart.getGrouping().getVal()); + } + + public void setGrouping(Grouping grouping) { + if (chart.getGrouping() != null) { + chart.getGrouping().setVal(grouping.underlying); + } else { + chart.addNewGrouping().setVal(grouping.underlying); + } + } + + @Override + public XDDFChartData.Series addSeries(XDDFDataSource category, + XDDFNumericalDataSource values) { + final int index = this.series.size(); + final CTLineSer ctSer = this.chart.addNewSer(); + ctSer.addNewCat(); + ctSer.addNewVal(); + ctSer.addNewIdx().setVal(index); + ctSer.addNewOrder().setVal(index); + final Series added = new Series(ctSer, category, values); + this.series.add(added); + return added; + } + + public class Series extends XDDFChartData.Series { + private CTLineSer series; + + protected Series(CTLineSer series, XDDFDataSource category, + XDDFNumericalDataSource values) { + super(category, values); + this.series = series; + } + + protected Series(CTLineSer series, CTAxDataSource category, CTNumDataSource values) { + super(XDDFDataSourcesFactory.fromDataSource(category), XDDFDataSourcesFactory.fromDataSource(values)); + this.series = series; + } + + @Override + protected CTSerTx getSeriesText() { + if (series.isSetTx()) { + return series.getTx(); + } else { + return series.addNewTx(); + } + } + + @Override + public void setShowLeaderLines(boolean showLeaderLines) { + if (!series.isSetDLbls()) { + series.addNewDLbls(); + } + if (series.getDLbls().isSetShowLeaderLines()) { + series.getDLbls().getShowLeaderLines().setVal(showLeaderLines); + } else { + series.getDLbls().addNewShowLeaderLines().setVal(showLeaderLines); + } + } + + @Override + public XDDFShapeProperties getShapeProperties() { + if (series.isSetSpPr()) { + return new XDDFShapeProperties(series.getSpPr()); + } else { + return null; + } + } + + @Override + public void setShapeProperties(XDDFShapeProperties properties) { + if (properties == null) { + if (series.isSetSpPr()) { + series.unsetSpPr(); + } + } else { + if (series.isSetSpPr()) { + series.setSpPr(properties.getXmlObject()); + } else { + series.addNewSpPr().set(properties.getXmlObject()); + } + } + } + + + public Boolean getSmooth() { + if (series.isSetSmooth()) { + return series.getSmooth().getVal(); + } else { + return null; + } + } + + /** + * @param smooth + * whether or not to smooth lines, if null then reverts to default. + * + */ + public void setSmooth(Boolean smooth) { + if (smooth == null) { + if (series.isSetSmooth()) { + series.unsetSmooth(); + } + } else { + if (series.isSetSmooth()) { + series.getSmooth().setVal(smooth); + } else { + series.addNewSmooth().setVal(smooth); + } + } + } + + /** + * @param size + *
Minimum inclusive:
2
Maximum inclusive:
72
+ */ + public void setMarkerSize(short size) { + if (size < 2 || 72 < size) { + throw new IllegalArgumentException("Minimum inclusive: 2; Maximum inclusive: 72"); + } + CTMarker marker = getMarker(); + if (marker.isSetSize()) { + marker.getSize().setVal(size); + } else { + marker.addNewSize().setVal(size); + } + } + + public void setMarkerStyle(MarkerStyle style) { + CTMarker marker = getMarker(); + if (marker.isSetSymbol()) { + marker.getSymbol().setVal(style.underlying); + } else { + marker.addNewSymbol().setVal(style.underlying); + } + } + + private CTMarker getMarker() { + if (series.isSetMarker()) { + return series.getMarker(); + } else { + return series.addNewMarker(); + } + } + + @Override + protected CTAxDataSource getAxDS() { + return series.getCat(); + } + + @Override + 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); + } + } +} 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 4d4f00ce9a..32bd022592 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 @@ -66,9 +66,13 @@ public class XDDFLineChartData extends XDDFChartData { return Grouping.valueOf(chart.getGrouping().getVal()); } - public void setGrouping(Grouping grouping) { - chart.getGrouping().setVal(grouping.underlying); - } + public void setGrouping(Grouping grouping) { + if (chart.getGrouping() != null) { + chart.getGrouping().setVal(grouping.underlying); + } else { + chart.addNewGrouping().setVal(grouping.underlying); + } + } @Override public XDDFChartData.Series addSeries(XDDFDataSource category, @@ -215,5 +219,15 @@ public class XDDFLineChartData 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); + } } } 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 new file mode 100644 index 0000000000..7f7ce539f4 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFPie3DChartData.java @@ -0,0 +1,157 @@ +/* ==================================================================== + 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.xddf.usermodel.XDDFShapeProperties; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTPie3DChart; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieSer; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx; + +@Beta +public class XDDFPie3DChartData extends XDDFChartData { + private CTPie3DChart chart; + + public XDDFPie3DChartData(CTPie3DChart chart) { + this.chart = chart; + for (CTPieSer series : chart.getSerList()) { + this.series.add(new Series(series, series.getCat(), series.getVal())); + } + } + + @Override + public void setVaryColors(boolean varyColors) { + if (chart.isSetVaryColors()) { + chart.getVaryColors().setVal(varyColors); + } else { + chart.addNewVaryColors().setVal(varyColors); + } + } + + @Override + public XDDFChartData.Series addSeries(XDDFDataSource category, + XDDFNumericalDataSource values) { + final int index = this.series.size(); + final CTPieSer ctSer = this.chart.addNewSer(); + ctSer.addNewCat(); + ctSer.addNewVal(); + ctSer.addNewIdx().setVal(index); + ctSer.addNewOrder().setVal(index); + final Series added = new Series(ctSer, category, values); + this.series.add(added); + return added; + } + + public class Series extends XDDFChartData.Series { + private CTPieSer series; + + protected Series(CTPieSer series, XDDFDataSource category, + XDDFNumericalDataSource values) { + super(category, values); + this.series = series; + } + + protected Series(CTPieSer series, CTAxDataSource category, CTNumDataSource values) { + super(XDDFDataSourcesFactory.fromDataSource(category), XDDFDataSourcesFactory.fromDataSource(values)); + this.series = series; + } + + @Override + protected CTSerTx getSeriesText() { + if (series.isSetTx()) { + return series.getTx(); + } else { + return series.addNewTx(); + } + } + + @Override + public void setShowLeaderLines(boolean showLeaderLines) { + if (!series.isSetDLbls()) { + series.addNewDLbls(); + } + if (series.getDLbls().isSetShowLeaderLines()) { + series.getDLbls().getShowLeaderLines().setVal(showLeaderLines); + } else { + series.getDLbls().addNewShowLeaderLines().setVal(showLeaderLines); + } + } + + @Override + public XDDFShapeProperties getShapeProperties() { + if (series.isSetSpPr()) { + return new XDDFShapeProperties(series.getSpPr()); + } else { + return null; + } + } + + @Override + public void setShapeProperties(XDDFShapeProperties properties) { + if (properties == null) { + if (series.isSetSpPr()) { + series.unsetSpPr(); + } + } else { + if (series.isSetSpPr()) { + series.setSpPr(properties.getXmlObject()); + } else { + series.addNewSpPr().set(properties.getXmlObject()); + } + } + } + + public long getExplosion() { + if (series.isSetExplosion()) { + return series.getExplosion().getVal(); + } else { + return 0; + } + } + + public void setExplosion(long explosion) { + if (series.isSetExplosion()) { + series.getExplosion().setVal(explosion); + } else { + series.addNewExplosion().setVal(explosion); + } + } + + @Override + protected CTAxDataSource getAxDS() { + return series.getCat(); + } + + @Override + 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); + } + } +} 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 988b48e84c..d31210da7f 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 @@ -143,5 +143,15 @@ public class XDDFPieChartData 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); + } } } 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 a7917c30f9..4f494b6f2c 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 @@ -156,5 +156,15 @@ public class XDDFRadarChartData 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); + } } } 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 eec3a3730d..162833b85d 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 @@ -228,5 +228,15 @@ public class XDDFScatterChartData extends XDDFChartData { protected CTNumDataSource getNumDS() { return series.getYVal(); } + + @Override + public void updateIdXVal(long val) { + series.getIdx().setVal(val); + } + + @Override + public void updateOrderVal(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 new file mode 100644 index 0000000000..273a77c814 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSurface3DChartData.java @@ -0,0 +1,173 @@ +/* ==================================================================== + 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.Map; + +import org.apache.poi.util.Beta; +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; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTSurfaceSer; + +@Beta +public class XDDFSurface3DChartData extends XDDFChartData { + private CTSurface3DChart chart; + + public XDDFSurface3DChartData(CTSurface3DChart chart, Map categories, + Map values) { + this.chart = chart; + for (CTSurfaceSer series : chart.getSerList()) { + this.series.add(new Series(series, series.getCat(), series.getVal())); + } + defineAxes(categories, values); + } + + private void defineAxes(Map categories, Map values) { + if (chart.sizeOfAxIdArray() == 0) { + for (Long id : categories.keySet()) { + chart.addNewAxId().setVal(id); + } + for (Long id : values.keySet()) { + chart.addNewAxId().setVal(id); + } + } + defineAxes(chart.getAxIdArray(), categories, values); + } + + public void setSeriesAxisId(XDDFSeriesAxis seriesAxis) { + chart.addNewAxId().setVal(seriesAxis.getId()); + } + + public CTBoolean getWireframe() { + if (chart.isSetWireframe()) { + return chart.getWireframe(); + } else { + return chart.addNewWireframe(); + } + } + + public void setWireframe(boolean val) { + if (chart.isSetWireframe()) { + chart.getWireframe().setVal(val); + } else { + chart.addNewWireframe().setVal(val); + } + } + + /** + * Surface chart is not supporting vary color property + */ + @Override + public void setVaryColors(boolean varyColors) { + + } + + @Override + public XDDFChartData.Series addSeries(XDDFDataSource category, + XDDFNumericalDataSource values) { + final int index = this.series.size(); + final CTSurfaceSer ctSer = this.chart.addNewSer(); + ctSer.addNewCat(); + ctSer.addNewVal(); + ctSer.addNewIdx().setVal(index); + ctSer.addNewOrder().setVal(index); + final Series added = new Series(ctSer, category, values); + this.series.add(added); + return added; + } + + public class Series extends XDDFChartData.Series { + private CTSurfaceSer series; + + protected Series(CTSurfaceSer series, XDDFDataSource category, + XDDFNumericalDataSource values) { + super(category, values); + this.series = series; + } + + protected Series(CTSurfaceSer series, CTAxDataSource category, CTNumDataSource values) { + super(XDDFDataSourcesFactory.fromDataSource(category), XDDFDataSourcesFactory.fromDataSource(values)); + this.series = series; + } + + @Override + protected CTSerTx getSeriesText() { + if (series.isSetTx()) { + return series.getTx(); + } else { + return series.addNewTx(); + } + } + + /** + * Surface chart is not supporting vary show leader lines property + */ + @Override + public void setShowLeaderLines(boolean showLeaderLines) { + + } + + @Override + public XDDFShapeProperties getShapeProperties() { + if (series.isSetSpPr()) { + return new XDDFShapeProperties(series.getSpPr()); + } else { + return null; + } + } + + @Override + public void setShapeProperties(XDDFShapeProperties properties) { + if (properties == null) { + if (series.isSetSpPr()) { + series.unsetSpPr(); + } + } else { + if (series.isSetSpPr()) { + series.setSpPr(properties.getXmlObject()); + } else { + series.addNewSpPr().set(properties.getXmlObject()); + } + } + } + + @Override + protected CTAxDataSource getAxDS() { + return series.getCat(); + } + + @Override + 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); + } + } +} 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 new file mode 100644 index 0000000000..64545229bc --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSurfaceChartData.java @@ -0,0 +1,172 @@ +/* ==================================================================== + 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.Map; + +import org.apache.poi.util.Beta; +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; +import org.openxmlformats.schemas.drawingml.x2006.chart.CTSurfaceSer; + +@Beta +public class XDDFSurfaceChartData extends XDDFChartData { + private CTSurfaceChart chart; + + public XDDFSurfaceChartData(CTSurfaceChart chart, Map categories, + Map values) { + this.chart = chart; + for (CTSurfaceSer series : chart.getSerList()) { + this.series.add(new Series(series, series.getCat(), series.getVal())); + } + defineAxes(categories, values); + } + private void defineAxes(Map categories, Map values) { + if (chart.sizeOfAxIdArray() == 0) { + for (Long id : categories.keySet()) { + chart.addNewAxId().setVal(id); + } + for (Long id : values.keySet()) { + chart.addNewAxId().setVal(id); + } + } + defineAxes(chart.getAxIdArray(), categories, values); + } + + public void setSeriesAxisId(XDDFSeriesAxis seriesAxis) { + chart.addNewAxId().setVal(seriesAxis.getId()); + } + + public CTBoolean getWireframe() { + if (chart.isSetWireframe()) { + return chart.getWireframe(); + } else { + return chart.addNewWireframe(); + } + } + + public void setWireframe(boolean val) { + if (chart.isSetWireframe()) { + chart.getWireframe().setVal(val); + } else { + chart.addNewWireframe().setVal(val); + } + } + + /** + * Surface chart is not supporting vary color property + */ + @Override + public void setVaryColors(boolean varyColors) { + + } + + @Override + public XDDFChartData.Series addSeries(XDDFDataSource category, + XDDFNumericalDataSource values) { + final int index = this.series.size(); + final CTSurfaceSer ctSer = this.chart.addNewSer(); + ctSer.addNewCat(); + ctSer.addNewVal(); + ctSer.addNewIdx().setVal(index); + ctSer.addNewOrder().setVal(index); + final Series added = new Series(ctSer, category, values); + this.series.add(added); + return added; + } + + public class Series extends XDDFChartData.Series { + private CTSurfaceSer series; + + protected Series(CTSurfaceSer series, XDDFDataSource category, + XDDFNumericalDataSource values) { + super(category, values); + this.series = series; + } + + protected Series(CTSurfaceSer series, CTAxDataSource category, CTNumDataSource values) { + super(XDDFDataSourcesFactory.fromDataSource(category), XDDFDataSourcesFactory.fromDataSource(values)); + this.series = series; + } + + @Override + protected CTSerTx getSeriesText() { + if (series.isSetTx()) { + return series.getTx(); + } else { + return series.addNewTx(); + } + } + + /** + * Surface chart is not supporting vary show leader lines property + */ + @Override + public void setShowLeaderLines(boolean showLeaderLines) { + + } + + @Override + public XDDFShapeProperties getShapeProperties() { + if (series.isSetSpPr()) { + return new XDDFShapeProperties(series.getSpPr()); + } else { + return null; + } + } + + @Override + public void setShapeProperties(XDDFShapeProperties properties) { + if (properties == null) { + if (series.isSetSpPr()) { + series.unsetSpPr(); + } + } else { + if (series.isSetSpPr()) { + series.setSpPr(properties.getXmlObject()); + } else { + series.addNewSpPr().set(properties.getXmlObject()); + } + } + } + + @Override + protected CTAxDataSource getAxDS() { + return series.getCat(); + } + + @Override + 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); + } + } +} \ No newline at end of file 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 new file mode 100644 index 0000000000..42ad2cd003 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFView3D.java @@ -0,0 +1,103 @@ +/* + * ==================================================================== + * 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.openxmlformats.schemas.drawingml.x2006.chart.CTView3D; + + +public class XDDFView3D { + private final CTView3D view3D; + + public XDDFView3D(CTView3D view3D) { + this.view3D = view3D; + } + + public int getXRotationAngle() { + return view3D.getRotX().getVal(); + } + + 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 void setYRotationAngle(int val) { + if (view3D.isSetRotY()) { + view3D.getRotY().setVal(val); + } else { + view3D.addNewRotY().setVal(val); + } + } + + public boolean getRightAngleAxes() { + return view3D.getRAngAx().getVal(); + } + + 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 setPerspectiveAngle(short val) { + if (view3D.isSetPerspective()) { + view3D.getPerspective().setVal(val); + } else { + view3D.addNewPerspective().setVal(val); + } + } + + public int getDepthPercentVal() { + return view3D.getDepthPercent().getVal(); + } + + 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 setHeightPercent(int val) { + if (view3D.isSetHPercent()) { + view3D.getHPercent().setVal(val); + } else { + view3D.addNewHPercent().setVal(val); + } + } +}