aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlain Béarez <abearez@apache.org>2018-02-12 12:59:38 +0000
committerAlain Béarez <abearez@apache.org>2018-02-12 12:59:38 +0000
commitb964cffa2cfb09e7eea87443c1f73ad4fcf76b8e (patch)
tree0f0aa085f907808de765e5905be3e5bbe56b362e /src
parent6e6707369206533118a7f65c0ba219b0e9a09291 (diff)
downloadpoi-b964cffa2cfb09e7eea87443c1f73ad4fcf76b8e.tar.gz
poi-b964cffa2cfb09e7eea87443c1f73ad4fcf76b8e.zip
[bug-57369] support for major and minor unit on XDDFChart axes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1823963 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java30
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java32
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartAxis.java75
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDateAxis.java58
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSeriesAxis.java190
-rw-r--r--src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java58
6 files changed, 426 insertions, 17 deletions
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java
index 4a673f7d33..52fe4223f3 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java
@@ -80,6 +80,36 @@ public class XDDFCategoryAxis extends XDDFChartAxis {
}
@Override
+ public boolean isSetMinorUnit() {
+ return false;
+ }
+
+ @Override
+ public void setMinorUnit(double minor) {
+ // nothing
+ }
+
+ @Override
+ public double getMinorUnit() {
+ return Double.NaN;
+ }
+
+ @Override
+ public boolean isSetMajorUnit() {
+ return false;
+ }
+
+ @Override
+ public void setMajorUnit(double major) {
+ // nothing
+ }
+
+ @Override
+ public double getMajorUnit() {
+ return Double.NaN;
+ }
+
+ @Override
public void crossAxis(XDDFChartAxis axis) {
ctCatAx.getCrossAx().setVal(axis.getId());
}
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 f86d217470..99a117fd36 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
@@ -62,6 +62,7 @@ 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.CTValAx;
import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument;
@@ -359,19 +360,48 @@ public abstract class XDDFChart extends POIXMLDocumentPart {
}
private void parseAxes() {
- // TODO: add other axis types
for (CTCatAx catAx : chart.getPlotArea().getCatAxArray()) {
axes.add(new XDDFCategoryAxis(catAx));
}
for (CTDateAx dateAx : chart.getPlotArea().getDateAxArray()) {
axes.add(new XDDFDateAxis(dateAx));
}
+ for (CTSerAx serAx : chart.getPlotArea().getSerAxArray()) {
+ axes.add(new XDDFSeriesAxis(serAx));
+ }
for (CTValAx valAx : chart.getPlotArea().getValAxArray()) {
axes.add(new XDDFValueAxis(valAx));
}
}
/**
+ * Set value range (basic Axis Options)
+ * @param axisIndex 0 - primary axis, 1 - secondary axis
+ * @param minimum minimum value; Double.NaN - automatic; null - no change
+ * @param maximum maximum value; Double.NaN - automatic; null - no change
+ * @param majorUnit major unit value; Double.NaN - automatic; null - no change
+ * @param minorUnit minor unit value; Double.NaN - automatic; null - no change
+ */
+ public void setValueRange(int axisIndex, Double minimum, Double maximum, Double majorUnit, Double minorUnit) {
+ XDDFChartAxis axis = getAxes().get(axisIndex);
+ if (axis == null) {
+ return;
+ }
+ if (minimum != null) {
+ axis.setMinimum(minimum);
+ }
+ if (maximum != null) {
+ axis.setMaximum(maximum);
+ }
+ if (majorUnit != null) {
+ axis.setMajorUnit(majorUnit);
+ }
+ if (minorUnit != null) {
+ axis.setMinorUnit(minorUnit);
+ }
+ }
+
+ /**
* method to create relationship with embedded part
* for example writing xlsx file stream into output stream
*
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartAxis.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartAxis.java
index cd1c6f01ab..b08b2fb47a 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartAxis.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartAxis.java
@@ -24,7 +24,6 @@ import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBoolean;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartLines;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTLogBase;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
@@ -58,6 +57,38 @@ public abstract class XDDFChartAxis implements HasShapeProperties {
public abstract XDDFShapeProperties getOrAddMinorGridProperties();
/**
+ * @return true if minor unit value is defined, false otherwise
+ */
+ public abstract boolean isSetMinorUnit();
+
+ /**
+ * @param minor
+ * axis minor unit
+ */
+ public abstract void setMinorUnit(double minor);
+
+ /**
+ * @return axis minor unit or NaN if not set
+ */
+ public abstract double getMinorUnit();
+
+ /**
+ * @return true if major unit value is defined, false otherwise
+ */
+ public abstract boolean isSetMajorUnit();
+
+ /**
+ * @param major
+ * axis major unit
+ */
+ public abstract void setMajorUnit(double major);
+
+ /**
+ * @return axis major unit or NaN if not set
+ */
+ public abstract double getMajorUnit();
+
+ /**
* @return axis id
*/
public long getId() {
@@ -132,14 +163,14 @@ public abstract class XDDFChartAxis implements HasShapeProperties {
}
/**
- * @return axis log base or 0.0 if not set
+ * @return axis log base or NaN if not set
*/
public double getLogBase() {
- CTLogBase logBase = getCTScaling().getLogBase();
- if (logBase != null) {
- return logBase.getVal();
+ CTScaling scaling = getCTScaling();
+ if (scaling.isSetLogBase()) {
+ return scaling.getLogBase().getVal();
}
- return 0.0;
+ return Double.NaN;
}
/**
@@ -155,22 +186,28 @@ public abstract class XDDFChartAxis implements HasShapeProperties {
*/
public void setMinimum(double min) {
CTScaling scaling = getCTScaling();
- if (scaling.isSetMin()) {
- scaling.getMin().setVal(min);
+ if (Double.isNaN(min)) {
+ if (scaling.isSetMin()) {
+ scaling.unsetMin();
+ }
} else {
- scaling.addNewMin().setVal(min);
+ if (scaling.isSetMin()) {
+ scaling.getMin().setVal(min);
+ } else {
+ scaling.addNewMin().setVal(min);
+ }
}
}
/**
- * @return axis minimum or 0.0 if not set
+ * @return axis minimum or NaN if not set
*/
public double getMinimum() {
CTScaling scaling = getCTScaling();
if (scaling.isSetMin()) {
return scaling.getMin().getVal();
} else {
- return 0.0;
+ return Double.NaN;
}
}
@@ -187,22 +224,28 @@ public abstract class XDDFChartAxis implements HasShapeProperties {
*/
public void setMaximum(double max) {
CTScaling scaling = getCTScaling();
- if (scaling.isSetMax()) {
- scaling.getMax().setVal(max);
+ if (Double.isNaN(max)) {
+ if (scaling.isSetMax()) {
+ scaling.unsetMax();
+ }
} else {
- scaling.addNewMax().setVal(max);
+ if (scaling.isSetMax()) {
+ scaling.getMax().setVal(max);
+ } else {
+ scaling.addNewMax().setVal(max);
+ }
}
}
/**
- * @return axis maximum or 0.0 if not set
+ * @return axis maximum or NaN if not set
*/
public double getMaximum() {
CTScaling scaling = getCTScaling();
if (scaling.isSetMax()) {
return scaling.getMax().getVal();
} else {
- return 0.0;
+ return Double.NaN;
}
}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDateAxis.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDateAxis.java
index 95f7d74f4c..bde26ffb7e 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDateAxis.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFDateAxis.java
@@ -83,6 +83,64 @@ public class XDDFDateAxis extends XDDFChartAxis {
}
@Override
+ public boolean isSetMinorUnit() {
+ return ctDateAx.isSetMinorUnit();
+ }
+
+ @Override
+ public void setMinorUnit(double minor) {
+ if (Double.isNaN(minor)) {
+ if (ctDateAx.isSetMinorUnit()) {
+ ctDateAx.unsetMinorUnit();
+ }
+ } else {
+ if (ctDateAx.isSetMinorUnit()) {
+ ctDateAx.getMinorUnit().setVal(minor);
+ } else {
+ ctDateAx.addNewMinorUnit().setVal(minor);
+ }
+ }
+ }
+
+ @Override
+ public double getMinorUnit() {
+ if (ctDateAx.isSetMinorUnit()) {
+ return ctDateAx.getMinorUnit().getVal();
+ } else {
+ return Double.NaN;
+ }
+ }
+
+ @Override
+ public boolean isSetMajorUnit() {
+ return ctDateAx.isSetMajorUnit();
+ }
+
+ @Override
+ public void setMajorUnit(double major) {
+ if (Double.isNaN(major)) {
+ if (ctDateAx.isSetMajorUnit()) {
+ ctDateAx.unsetMajorUnit();
+ }
+ } else {
+ if (ctDateAx.isSetMajorUnit()) {
+ ctDateAx.getMajorUnit().setVal(major);
+ } else {
+ ctDateAx.addNewMajorUnit().setVal(major);
+ }
+ }
+ }
+
+ @Override
+ public double getMajorUnit() {
+ if (ctDateAx.isSetMajorUnit()) {
+ return ctDateAx.getMajorUnit().getVal();
+ } else {
+ return Double.NaN;
+ }
+ }
+
+ @Override
public void crossAxis(XDDFChartAxis axis) {
ctDateAx.getCrossAx().setVal(axis.getId());
}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSeriesAxis.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSeriesAxis.java
new file mode 100644
index 0000000000..37ec0ddab3
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFSeriesAxis.java
@@ -0,0 +1,190 @@
+/* ====================================================================
+ 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.CTAxPos;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTBoolean;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartLines;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerAx;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTTickMark;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTUnsignedInt;
+import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
+
+@Beta
+public class XDDFSeriesAxis extends XDDFChartAxis {
+
+ private CTSerAx ctSerAx;
+
+ public XDDFSeriesAxis(CTPlotArea plotArea, AxisPosition position) {
+ initializeAxis(plotArea, position);
+ }
+
+ public XDDFSeriesAxis(CTSerAx ctSerAx) {
+ this.ctSerAx = ctSerAx;
+ }
+
+ @Override
+ public XDDFShapeProperties getOrAddMajorGridProperties() {
+ CTChartLines majorGridlines;
+ if (ctSerAx.isSetMajorGridlines()) {
+ majorGridlines = ctSerAx.getMajorGridlines();
+ } else {
+ majorGridlines = ctSerAx.addNewMajorGridlines();
+ }
+ return new XDDFShapeProperties(getOrAddLinesProperties(majorGridlines));
+ }
+
+ @Override
+ public XDDFShapeProperties getOrAddMinorGridProperties() {
+ CTChartLines minorGridlines;
+ if (ctSerAx.isSetMinorGridlines()) {
+ minorGridlines = ctSerAx.getMinorGridlines();
+ } else {
+ minorGridlines = ctSerAx.addNewMinorGridlines();
+ }
+ return new XDDFShapeProperties(getOrAddLinesProperties(minorGridlines));
+ }
+
+ @Override
+ public XDDFShapeProperties getOrAddShapeProperties() {
+ CTShapeProperties properties;
+ if (ctSerAx.isSetSpPr()) {
+ properties = ctSerAx.getSpPr();
+ } else {
+ properties = ctSerAx.addNewSpPr();
+ }
+
+ return new XDDFShapeProperties(properties);
+ }
+
+ @Override
+ public boolean isSetMinorUnit() {
+ return false;
+ }
+
+ @Override
+ public void setMinorUnit(double minor) {
+ // nothing
+ }
+
+ @Override
+ public double getMinorUnit() {
+ return Double.NaN;
+ }
+
+ @Override
+ public boolean isSetMajorUnit() {
+ return false;
+ }
+
+ @Override
+ public void setMajorUnit(double major) {
+ // nothing
+ }
+
+ @Override
+ public double getMajorUnit() {
+ return Double.NaN;
+ }
+
+ @Override
+ public void crossAxis(XDDFChartAxis axis) {
+ ctSerAx.getCrossAx().setVal(axis.getId());
+ }
+
+ @Override
+ protected CTUnsignedInt getCTAxId() {
+ return ctSerAx.getAxId();
+ }
+
+ @Override
+ protected CTAxPos getCTAxPos() {
+ return ctSerAx.getAxPos();
+ }
+
+ @Override
+ public boolean hasNumberFormat() {
+ return ctSerAx.isSetNumFmt();
+ }
+
+ @Override
+ protected CTNumFmt getCTNumFmt() {
+ if (ctSerAx.isSetNumFmt()) {
+ return ctSerAx.getNumFmt();
+ }
+ return ctSerAx.addNewNumFmt();
+ }
+
+ @Override
+ protected CTScaling getCTScaling() {
+ return ctSerAx.getScaling();
+ }
+
+ @Override
+ protected CTCrosses getCTCrosses() {
+ CTCrosses crosses = ctSerAx.getCrosses();
+ if (crosses == null) {
+ return ctSerAx.addNewCrosses();
+ } else {
+ return crosses;
+ }
+ }
+
+ @Override
+ protected CTBoolean getDelete() {
+ return ctSerAx.getDelete();
+ }
+
+ @Override
+ protected CTTickMark getMajorCTTickMark() {
+ return ctSerAx.getMajorTickMark();
+ }
+
+ @Override
+ protected CTTickMark getMinorCTTickMark() {
+ return ctSerAx.getMinorTickMark();
+ }
+
+ private void initializeAxis(CTPlotArea plotArea, AxisPosition position) {
+ final long id = getNextAxId(plotArea);
+ ctSerAx = plotArea.addNewSerAx();
+ ctSerAx.addNewAxId().setVal(id);
+ ctSerAx.addNewAxPos();
+ ctSerAx.addNewScaling();
+ ctSerAx.addNewCrosses();
+ ctSerAx.addNewCrossAx();
+ ctSerAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
+ ctSerAx.addNewDelete();
+ ctSerAx.addNewMajorTickMark();
+ ctSerAx.addNewMinorTickMark();
+
+ setPosition(position);
+ setOrientation(AxisOrientation.MIN_MAX);
+ setCrosses(AxisCrosses.AUTO_ZERO);
+ setVisible(true);
+ setMajorTickMark(AxisTickMark.CROSS);
+ setMinorTickMark(AxisTickMark.NONE);
+ }
+}
diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java
index 9720000d16..d25f8550b6 100644
--- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java
+++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java
@@ -79,6 +79,64 @@ public class XDDFValueAxis extends XDDFChartAxis {
}
@Override
+ public boolean isSetMinorUnit() {
+ return ctValAx.isSetMinorUnit();
+ }
+
+ @Override
+ public void setMinorUnit(double minor) {
+ if (Double.isNaN(minor)) {
+ if (ctValAx.isSetMinorUnit()) {
+ ctValAx.unsetMinorUnit();
+ }
+ } else {
+ if (ctValAx.isSetMinorUnit()) {
+ ctValAx.getMinorUnit().setVal(minor);
+ } else {
+ ctValAx.addNewMinorUnit().setVal(minor);
+ }
+ }
+ }
+
+ @Override
+ public double getMinorUnit() {
+ if (ctValAx.isSetMinorUnit()) {
+ return ctValAx.getMinorUnit().getVal();
+ } else {
+ return Double.NaN;
+ }
+ }
+
+ @Override
+ public boolean isSetMajorUnit() {
+ return ctValAx.isSetMajorUnit();
+ }
+
+ @Override
+ public void setMajorUnit(double major) {
+ if (Double.isNaN(major)) {
+ if (ctValAx.isSetMajorUnit()) {
+ ctValAx.unsetMajorUnit();
+ }
+ } else {
+ if (ctValAx.isSetMajorUnit()) {
+ ctValAx.getMajorUnit().setVal(major);
+ } else {
+ ctValAx.addNewMajorUnit().setVal(major);
+ }
+ }
+ }
+
+ @Override
+ public double getMajorUnit() {
+ if (ctValAx.isSetMajorUnit()) {
+ return ctValAx.getMajorUnit().getVal();
+ } else {
+ return Double.NaN;
+ }
+ }
+
+ @Override
public void crossAxis(XDDFChartAxis axis) {
ctValAx.getCrossAx().setVal(axis.getId());
}