View | Details | Raw Unified | Return to bug 55768
Collapse All | Expand All

(-)src/java/org/apache/poi/ss/usermodel/charts/AxisTickMark.java (+30 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.ss.usermodel.charts;
19
20
/**
21
 * Enumeration of possible axis tick marks.
22
 *
23
 * @author Martin Andersson
24
 */
25
public enum AxisTickMark {
26
	NONE,
27
	CROSS,
28
	IN,
29
	OUT;
30
}
(-)src/java/org/apache/poi/ss/usermodel/charts/ChartAxis.java (-1 / +31 lines)
Lines 26-32 import org.apache.poi.util.Beta; Link Here
26
 */
26
 */
27
@Beta
27
@Beta
28
public interface ChartAxis {
28
public interface ChartAxis {
29
	
29
30
	/**
30
	/**
31
	 * @return axis id
31
	 * @return axis id
32
	 */
32
	 */
Lines 123-126 public interface ChartAxis { Link Here
123
	 * @param axis that this axis should cross
123
	 * @param axis that this axis should cross
124
	 */
124
	 */
125
	void crossAxis(ChartAxis axis);
125
	void crossAxis(ChartAxis axis);
126
127
	/**
128
	 * @return visibility of the axis.
129
	 */
130
	boolean isVisible();
131
132
	/**
133
	 * @param value visibility of the axis.
134
	 */
135
	void setVisible(boolean value);
136
137
	/**
138
	 * @return major tick mark.
139
	 */
140
	AxisTickMark getMajorTickMark();
141
142
	/**
143
	 * @param tickMark major tick mark type.
144
	 */
145
	void setMajorTickMark(AxisTickMark tickMark);
146
147
	/**
148
	 * @return minor tick mark.
149
	 */
150
	AxisTickMark getMinorTickMark();
151
152
	/**
153
	 * @param tickMark minor tick mark type.
154
	 */
155
	void setMinorTickMark(AxisTickMark tickMark);
126
}
156
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFCategoryAxis.java (+25 lines)
Lines 20-34 package org.apache.poi.xssf.usermodel.charts; Link Here
20
import org.apache.poi.ss.usermodel.charts.AxisCrosses;
20
import org.apache.poi.ss.usermodel.charts.AxisCrosses;
21
import org.apache.poi.ss.usermodel.charts.AxisOrientation;
21
import org.apache.poi.ss.usermodel.charts.AxisOrientation;
22
import org.apache.poi.ss.usermodel.charts.AxisPosition;
22
import org.apache.poi.ss.usermodel.charts.AxisPosition;
23
import org.apache.poi.ss.usermodel.charts.AxisTickMark;
23
import org.apache.poi.ss.usermodel.charts.ChartAxis;
24
import org.apache.poi.ss.usermodel.charts.ChartAxis;
24
import org.apache.poi.util.Beta;
25
import org.apache.poi.util.Beta;
25
import org.apache.poi.xssf.usermodel.XSSFChart;
26
import org.apache.poi.xssf.usermodel.XSSFChart;
26
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
27
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
28
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBoolean;
27
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCatAx;
29
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCatAx;
28
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
30
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
29
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
31
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
30
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
32
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
33
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTickMark;
31
import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
34
import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
35
import org.openxmlformats.schemas.drawingml.x2006.chart.STTickMark;
32
36
33
/**
37
/**
34
 * Category axis type.
38
 * Category axis type.
Lines 73-78 public class XSSFCategoryAxis extends XSSFChartAxis { Link Here
73
		return ctCatAx.getCrosses();
77
		return ctCatAx.getCrosses();
74
	}
78
	}
75
79
80
	@Override
81
	protected CTBoolean getDelete() {
82
		return ctCatAx.getDelete();
83
	}
84
85
	@Override
86
	protected CTTickMark getMajorCTTickMark() {
87
		return ctCatAx.getMajorTickMark();
88
	}
89
90
	@Override
91
	protected CTTickMark getMinorCTTickMark() {
92
		return ctCatAx.getMinorTickMark();
93
	}
94
76
	public void crossAxis(ChartAxis axis) {
95
	public void crossAxis(ChartAxis axis) {
77
		ctCatAx.getCrossAx().setVal(axis.getId());
96
		ctCatAx.getCrossAx().setVal(axis.getId());
78
	}
97
	}
Lines 85-93 public class XSSFCategoryAxis extends XSSFChartAxis { Link Here
85
		ctCatAx.addNewCrosses();
104
		ctCatAx.addNewCrosses();
86
		ctCatAx.addNewCrossAx();
105
		ctCatAx.addNewCrossAx();
87
		ctCatAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
106
		ctCatAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
107
		ctCatAx.addNewDelete();
108
		ctCatAx.addNewMajorTickMark();
109
		ctCatAx.addNewMinorTickMark();
88
110
89
		setPosition(pos);
111
		setPosition(pos);
90
		setOrientation(AxisOrientation.MIN_MAX);
112
		setOrientation(AxisOrientation.MIN_MAX);
91
		setCrosses(AxisCrosses.AUTO_ZERO);
113
		setCrosses(AxisCrosses.AUTO_ZERO);
114
		setVisible(true);
115
		setMajorTickMark(AxisTickMark.CROSS);
116
		setMinorTickMark(AxisTickMark.NONE);
92
	}
117
	}
93
}
118
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartAxis.java (+52 lines)
Lines 21-37 import org.apache.poi.ss.usermodel.charts.ChartAxis; Link Here
21
import org.apache.poi.ss.usermodel.charts.AxisPosition;
21
import org.apache.poi.ss.usermodel.charts.AxisPosition;
22
import org.apache.poi.ss.usermodel.charts.AxisOrientation;
22
import org.apache.poi.ss.usermodel.charts.AxisOrientation;
23
import org.apache.poi.ss.usermodel.charts.AxisCrosses;
23
import org.apache.poi.ss.usermodel.charts.AxisCrosses;
24
import org.apache.poi.ss.usermodel.charts.AxisTickMark;
24
import org.apache.poi.util.Beta;
25
import org.apache.poi.util.Beta;
25
import org.apache.poi.xssf.usermodel.XSSFChart;
26
import org.apache.poi.xssf.usermodel.XSSFChart;
26
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
27
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
28
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBoolean;
27
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
29
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
28
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
30
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
29
import org.openxmlformats.schemas.drawingml.x2006.chart.CTOrientation;
31
import org.openxmlformats.schemas.drawingml.x2006.chart.CTOrientation;
30
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLogBase;
32
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLogBase;
31
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
33
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
34
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTickMark;
32
import org.openxmlformats.schemas.drawingml.x2006.chart.STOrientation;
35
import org.openxmlformats.schemas.drawingml.x2006.chart.STOrientation;
33
import org.openxmlformats.schemas.drawingml.x2006.chart.STAxPos;
36
import org.openxmlformats.schemas.drawingml.x2006.chart.STAxPos;
34
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrosses;
37
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrosses;
38
import org.openxmlformats.schemas.drawingml.x2006.chart.STTickMark;
35
39
36
/**
40
/**
37
 * Base class for all axis types.
41
 * Base class for all axis types.
Lines 158-167 public abstract class XSSFChartAxis implements ChartAxis { Link Here
158
		getCTCrosses().setVal(fromAxisCrosses(crosses));
162
		getCTCrosses().setVal(fromAxisCrosses(crosses));
159
	}
163
	}
160
164
165
	public boolean isVisible() {
166
		return !getDelete().getVal();
167
	}
168
169
	public void setVisible(boolean value) {
170
		getDelete().setVal(!value);
171
	}
172
173
	public AxisTickMark getMajorTickMark() {
174
		return toAxisTickMark(getMajorCTTickMark());
175
	}
176
177
	public void setMajorTickMark(AxisTickMark tickMark) {
178
		getMajorCTTickMark().setVal(fromAxisTickMark(tickMark));
179
	}
180
181
	public AxisTickMark getMinorTickMark() {
182
		return toAxisTickMark(getMinorCTTickMark());
183
	}
184
185
	public void setMinorTickMark(AxisTickMark tickMark) {
186
		getMinorCTTickMark().setVal(fromAxisTickMark(tickMark));
187
	}
188
161
	protected abstract CTAxPos getCTAxPos();
189
	protected abstract CTAxPos getCTAxPos();
162
	protected abstract CTNumFmt getCTNumFmt();
190
	protected abstract CTNumFmt getCTNumFmt();
163
	protected abstract CTScaling getCTScaling();
191
	protected abstract CTScaling getCTScaling();
164
	protected abstract CTCrosses getCTCrosses();
192
	protected abstract CTCrosses getCTCrosses();
193
	protected abstract CTBoolean getDelete();
194
	protected abstract CTTickMark getMajorCTTickMark();
195
	protected abstract CTTickMark getMinorCTTickMark();
165
196
166
	private static STOrientation.Enum fromAxisOrientation(AxisOrientation orientation) {
197
	private static STOrientation.Enum fromAxisOrientation(AxisOrientation orientation) {
167
		switch (orientation) {
198
		switch (orientation) {
Lines 221-224 public abstract class XSSFChartAxis implements ChartAxis { Link Here
221
			default: return AxisPosition.BOTTOM;
252
			default: return AxisPosition.BOTTOM;
222
		}
253
		}
223
	}
254
	}
255
256
	private static STTickMark.Enum fromAxisTickMark(AxisTickMark tickMark) {
257
		switch (tickMark) {
258
			case NONE: return STTickMark.NONE;
259
			case IN: return STTickMark.IN;
260
			case OUT: return STTickMark.OUT;
261
			case CROSS: return STTickMark.CROSS;
262
			default:
263
				throw new IllegalArgumentException("Unknown AxisTickMark: " + tickMark);
264
		}
265
	}
266
267
	private static AxisTickMark toAxisTickMark(CTTickMark ctTickMark) {
268
		switch (ctTickMark.getVal().intValue()) {
269
			case STTickMark.INT_NONE: return AxisTickMark.NONE;
270
			case STTickMark.INT_IN: return AxisTickMark.IN;
271
			case STTickMark.INT_OUT: return AxisTickMark.OUT;
272
			case STTickMark.INT_CROSS: return AxisTickMark.CROSS;
273
			default: return AxisTickMark.CROSS;
274
		}
275
	}
224
}
276
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFValueAxis.java (+25 lines)
Lines 23-38 import org.apache.poi.ss.usermodel.charts.AxisPosition; Link Here
23
import org.apache.poi.ss.usermodel.charts.AxisOrientation;
23
import org.apache.poi.ss.usermodel.charts.AxisOrientation;
24
import org.apache.poi.ss.usermodel.charts.AxisCrossBetween;
24
import org.apache.poi.ss.usermodel.charts.AxisCrossBetween;
25
import org.apache.poi.ss.usermodel.charts.AxisCrosses;
25
import org.apache.poi.ss.usermodel.charts.AxisCrosses;
26
import org.apache.poi.ss.usermodel.charts.AxisTickMark;
26
27
27
import org.apache.poi.util.Beta;
28
import org.apache.poi.util.Beta;
28
import org.apache.poi.xssf.usermodel.XSSFChart;
29
import org.apache.poi.xssf.usermodel.XSSFChart;
29
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
30
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
30
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
31
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
32
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBoolean;
31
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
33
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
32
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
34
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
33
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
35
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
36
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTickMark;
34
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrossBetween;
37
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrossBetween;
35
import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
38
import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
39
import org.openxmlformats.schemas.drawingml.x2006.chart.STTickMark;
36
40
37
/**
41
/**
38
 * Value axis type.
42
 * Value axis type.
Lines 89-94 public class XSSFValueAxis extends XSSFChartAxis implements ValueAxis { Link Here
89
		return ctValAx.getCrosses();
93
		return ctValAx.getCrosses();
90
	}
94
	}
91
95
96
	@Override
97
	protected CTBoolean getDelete() {
98
		return ctValAx.getDelete();
99
	}
100
101
	@Override
102
	protected CTTickMark getMajorCTTickMark() {
103
		return ctValAx.getMajorTickMark();
104
	}
105
106
	@Override
107
	protected CTTickMark getMinorCTTickMark() {
108
		return ctValAx.getMinorTickMark();
109
	}
110
92
	public void crossAxis(ChartAxis axis) {
111
	public void crossAxis(ChartAxis axis) {
93
		ctValAx.getCrossAx().setVal(axis.getId());
112
		ctValAx.getCrossAx().setVal(axis.getId());
94
	}
113
	}
Lines 102-112 public class XSSFValueAxis extends XSSFChartAxis implements ValueAxis { Link Here
102
		ctValAx.addNewCrosses();
121
		ctValAx.addNewCrosses();
103
		ctValAx.addNewCrossAx();
122
		ctValAx.addNewCrossAx();
104
		ctValAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
123
		ctValAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
124
		ctValAx.addNewDelete();
125
		ctValAx.addNewMajorTickMark();
126
		ctValAx.addNewMinorTickMark();
105
127
106
		setPosition(pos);
128
		setPosition(pos);
107
		setOrientation(AxisOrientation.MIN_MAX);
129
		setOrientation(AxisOrientation.MIN_MAX);
108
		setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
130
		setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
109
		setCrosses(AxisCrosses.AUTO_ZERO);
131
		setCrosses(AxisCrosses.AUTO_ZERO);
132
		setVisible(true);
133
		setMajorTickMark(AxisTickMark.CROSS);
134
		setMinorTickMark(AxisTickMark.NONE);
110
	}
135
	}
111
136
112
	private static STCrossBetween.Enum fromCrossBetween(AxisCrossBetween crossBetween) {
137
	private static STCrossBetween.Enum fromCrossBetween(AxisCrossBetween crossBetween) {
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java (-1 / +36 lines)
Lines 36-42 public final class TestXSSFChartAxis extends TestCase { Link Here
36
		XSSFChart chart = drawing.createChart(anchor);
36
		XSSFChart chart = drawing.createChart(anchor);
37
		axis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
37
		axis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
38
	}
38
	}
39
 
39
40
	public void testLogBaseIllegalArgument() throws Exception {
40
	public void testLogBaseIllegalArgument() throws Exception {
41
		IllegalArgumentException iae = null;
41
		IllegalArgumentException iae = null;
42
		try {
42
		try {
Lines 76-79 public final class TestXSSFChartAxis extends TestCase { Link Here
76
		assertTrue(Math.abs(axis.getMaximum() - newValue) < EPSILON);
76
		assertTrue(Math.abs(axis.getMaximum() - newValue) < EPSILON);
77
	}
77
	}
78
78
79
	public void testVisibleAccessMethods() {
80
		axis.setVisible(true);
81
		assertTrue(axis.isVisible());
82
83
		axis.setVisible(false);
84
		assertFalse(axis.isVisible());
85
	}
86
87
	public void testMajorTickMarkAccessMethods() {
88
		axis.setMajorTickMark(AxisTickMark.NONE);
89
		assertEquals(AxisTickMark.NONE, axis.getMajorTickMark());
90
91
		axis.setMajorTickMark(AxisTickMark.IN);
92
		assertEquals(AxisTickMark.IN, axis.getMajorTickMark());
93
94
		axis.setMajorTickMark(AxisTickMark.OUT);
95
		assertEquals(AxisTickMark.OUT, axis.getMajorTickMark());
96
97
		axis.setMajorTickMark(AxisTickMark.CROSS);
98
		assertEquals(AxisTickMark.CROSS, axis.getMajorTickMark());
99
	}
100
101
	public void testMinorTickMarkAccessMethods() {
102
		axis.setMinorTickMark(AxisTickMark.NONE);
103
		assertEquals(AxisTickMark.NONE, axis.getMinorTickMark());
104
105
		axis.setMinorTickMark(AxisTickMark.IN);
106
		assertEquals(AxisTickMark.IN, axis.getMinorTickMark());
107
108
		axis.setMinorTickMark(AxisTickMark.OUT);
109
		assertEquals(AxisTickMark.OUT, axis.getMinorTickMark());
110
111
		axis.setMinorTickMark(AxisTickMark.CROSS);
112
		assertEquals(AxisTickMark.CROSS, axis.getMinorTickMark());
113
	}
79
}
114
}

Return to bug 55768