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

(-)a/src/examples/src/org/apache/poi/xssf/usermodel/examples/ScatterChart.java (+80 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.xssf.usermodel.examples;
19
20
import java.io.FileOutputStream;
21
import java.util.Date;
22
23
import org.apache.poi.ss.usermodel.*;
24
import org.apache.poi.ss.util.*;
25
import org.apache.poi.ss.usermodel.charts.*;
26
import org.apache.poi.xssf.usermodel.*;
27
import org.apache.poi.xssf.usermodel.charts.*;
28
import org.apache.poi.xssf.usermodel.XSSFWorkbook; 
29
30
/**
31
 * Illustrates how to create a simple scatter chart.
32
 */
33
public class ScatterChart {
34
35
	public static void main(String[]args) throws Exception {
36
		Workbook wb = new XSSFWorkbook();
37
		CreationHelper creationHelper = wb.getCreationHelper();
38
		Sheet sheet = wb.createSheet("new sheet");
39
		final int NUM_OF_ROWS = 3;
40
		final int NUM_OF_COLUMNS = 10;
41
42
		// Create a row and put some cells in it. Rows are 0 based.
43
		Row row;
44
		Cell cell;
45
		for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++) {
46
			row = sheet.createRow((short)rowIndex);
47
			for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) {
48
				cell = row.createCell((short)colIndex);
49
				cell.setCellValue(colIndex * (rowIndex + 1));
50
			}
51
		}
52
53
		Drawing drawing = sheet.createDrawingPatriarch();
54
		ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);
55
56
		Chart chart = drawing.createChart(anchor);
57
		ChartLegend legend = chart.getOrCreateLegend();
58
		legend.setPosition(LegendPosition.RIGHT);
59
60
		ScatterChartData data = chart.getChartDataFactory().createScatterChartData();
61
62
		ValueAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
63
		ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
64
65
		ScatterChartSerie firstSerie = data.addSerie();
66
		firstSerie.setXValues(sheet, new CellRangeAddress(0, 0, NUM_OF_COLUMNS + 1, NUM_OF_COLUMNS + 1));
67
		firstSerie.setXValues(sheet, new CellRangeAddress(1, 1, NUM_OF_COLUMNS + 1, NUM_OF_COLUMNS + 1));
68
69
		ScatterChartSerie secondSerie = data.addSerie();
70
		secondSerie.setXValues(sheet, new CellRangeAddress(0, 0, NUM_OF_COLUMNS + 1, NUM_OF_COLUMNS + 1));
71
		secondSerie.setYValues(sheet, new CellRangeAddress(2, 2, NUM_OF_COLUMNS + 1, NUM_OF_COLUMNS + 1));
72
73
		chart.plot(data, bottomAxis, leftAxis);
74
75
		// Write the output to a file
76
		FileOutputStream fileOut = new FileOutputStream("ooxml-scatter-chart.xlsx");
77
		wb.write(fileOut);
78
		fileOut.close();
79
	}
80
}
(-)a/src/java/org/apache/poi/ss/usermodel/Chart.java (+66 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;
19
20
import java.util.List;
21
22
import org.apache.poi.ss.usermodel.charts.ChartData;
23
import org.apache.poi.ss.usermodel.charts.ChartAxis;
24
import org.apache.poi.ss.usermodel.charts.ChartLegend;
25
import org.apache.poi.ss.usermodel.charts.ChartDataFactory;
26
import org.apache.poi.ss.usermodel.charts.ChartAxisFactory;
27
28
/**
29
 * High level representation of a chart.
30
 *
31
 * @author Roman Kashitsyn
32
 */
33
public interface Chart {
34
	
35
	/**
36
	 * @return an appropriate ChartDataFactory implementation
37
	 */
38
	ChartDataFactory getChartDataFactory();
39
40
	/**
41
	 * @return an appropriate ChartAxisFactory implementation
42
	 */
43
	ChartAxisFactory getChartAxisFactory();
44
45
	/**
46
	 * @return chart legend instance
47
	 */
48
	ChartLegend getOrCreateLegend();
49
50
	/**
51
	 * Delete current chart legend.
52
	 */
53
	void deleteLegend();
54
55
	/**
56
	 * @return list of all chart axis
57
	 */
58
	List<? extends ChartAxis> getAxis();
59
60
	/**
61
	 * Plots specified data on the chart.
62
	 *
63
	 * @param data a data to plot
64
	 */
65
	void plot(ChartData data, ChartAxis... axis);
66
}
(-)a/src/java/org/apache/poi/ss/usermodel/Drawing.java (-2 / +43 lines)
Lines 17-26 Link Here
17
package org.apache.poi.ss.usermodel;
17
package org.apache.poi.ss.usermodel;
18
18
19
/**
19
/**
20
 * High level representation of spreadsheet drawing.
20
 * @author Yegor Kozlov
21
 * @author Yegor Kozlov
22
 * @author Roman Kashitsyn
21
 */
23
 */
22
public interface Drawing {
24
public interface Drawing {
23
    Picture createPicture(ClientAnchor anchor, int pictureIndex);
25
	/**
26
	 * Creates a picture.
27
	 * @param anchor       the client anchor describes how this picture is
28
	 *                     attached to the sheet.
29
	 * @param pictureIndex the index of the picture in the workbook collection
30
	 *                     of pictures.
31
	 *
32
	 * @return the newly created picture.
33
	 */
34
	Picture createPicture(ClientAnchor anchor, int pictureIndex);
24
35
25
    Comment createCellComment(ClientAnchor anchor);
36
	/**
37
	 * Creates a comment.
38
	 * @param anchor the client anchor describes how this comment is attached
39
	 *               to the sheet.
40
	 * @return the newly created comment.
41
	 */
42
	Comment createCellComment(ClientAnchor anchor);
43
44
	/**
45
	 * Creates a chart.
46
	 * @param anchor the client anchor describes how this chart is attached to
47
	 *               the sheet.
48
	 * @return the newly created chart
49
	 */
50
	Chart createChart(ClientAnchor anchor);
51
52
	/**
53
	 * Creates a new client anchor and sets the top-left and bottom-right
54
	 * coordinates of the anchor.
55
	 *
56
	 * @param dx1  the x coordinate in EMU within the first cell.
57
	 * @param dy1  the y coordinate in EMU within the first cell.
58
	 * @param dx2  the x coordinate in EMU within the second cell.
59
	 * @param dy2  the y coordinate in EMU within the second cell.
60
	 * @param col1 the column (0 based) of the first cell.
61
	 * @param row1 the row (0 based) of the first cell.
62
	 * @param col2 the column (0 based) of the second cell.
63
	 * @param row2 the row (0 based) of the second cell.
64
	 * @return the newly created client anchor
65
	 */
66
	ClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2);
26
}
67
}
(-)a/src/java/org/apache/poi/ss/usermodel/charts/AxisCrossBetween.java (+36 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
 *  Specifies the possible crossing states of an axis.
22
 *
23
 * @author Roman Kashitsyn
24
 */
25
public enum AxisCrossBetween {
26
	/**
27
	 * Specifies the value axis shall cross the category axis
28
	 * between data markers.
29
	 */
30
	BETWEEN,
31
	/**
32
	 * Specifies the value axis shall cross the category axis at
33
	 * the midpoint of a category.
34
	 */
35
	MIDPOINT_CATEGORY
36
}
(-)a/src/java/org/apache/poi/ss/usermodel/charts/AxisCrosses.java (+40 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
 * Specifies the possible crossing points for an axis.
22
 *
23
 * @author Roman Kashitsyn
24
 */
25
public enum AxisCrosses {
26
	/**
27
	 * The category axis crosses at the zero point of the value axis (if
28
	 * possible), or the minimum value (if the minimum is greater than zero) or
29
	 * the maximum (if the maximum is less than zero).
30
	 */
31
	AUTO_ZERO,
32
	/**
33
	 * The axis crosses at the maximum value.
34
	 */
35
	MIN,
36
	/**
37
	 * Axis crosses at the minimum value of the chart.
38
	 */
39
	MAX
40
}
(-)a/src/java/org/apache/poi/ss/usermodel/charts/AxisOrientation.java (+36 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
 * Specifies the possible ways to place a picture on a data point, series, wall, or floor.
22
 *
23
 * @author Roman Kashitsyn
24
 */
25
public enum AxisOrientation {
26
	/**
27
	 * Specifies that the values on the axis shall be reversed
28
	 * so they go from maximum to minimum.
29
	 */
30
	MAX_MIN,
31
	/**
32
	 * Specifies that the axis values shall be in the usual
33
	 * order, minimum to maximum.
34
	 */
35
	MIN_MAX
36
}
(-)a/src/java/org/apache/poi/ss/usermodel/charts/AxisPosition.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 all possible axis positions.
22
 *
23
 * @author Roman Kashitsyn
24
 */
25
public enum AxisPosition {
26
	BOTTOM,
27
	LEFT,
28
	RIGHT,
29
	TOP
30
}
(-)a/src/java/org/apache/poi/ss/usermodel/charts/ChartAxis.java (+123 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
 * High level representation of chart axis.
22
 *
23
 * @author Roman Kashitsyn
24
 */
25
public interface ChartAxis {
26
	
27
	/**
28
	 * @return axis id
29
	 */
30
	long getId();
31
32
	/**
33
	 * @return axis position
34
	 */
35
	AxisPosition getPosition();
36
37
	/**
38
	 * @param position new axis position
39
	 */
40
	void setPosition(AxisPosition position);
41
42
	/**
43
	 * @return axis number format
44
	 */
45
	String getNumberFormat();
46
47
	/**
48
	 * @param format axis number format
49
	 */
50
	void setNumberFormat(String format);
51
52
	/**
53
	 * @return true if log base is defined, false otherwise
54
	 */
55
	boolean isSetLogBase();
56
57
	/**
58
	 * @param logBase a number between 2 and 1000 (inclusive)
59
	 * @throws IllegalArgumentException if log base not within allowed range
60
	 */
61
	void setLogBase(double logBase);
62
63
	/**
64
	 * @return axis log base or 0.0 if not set
65
	 */
66
	double getLogBase();
67
68
	/**
69
	 * @return true if minimum value is defined, false otherwise
70
	 */
71
	boolean isSetMinimum();
72
73
	/**
74
	 * @return axis minimum or 0.0 if not set
75
	 */
76
	double getMinimum();
77
78
	/**
79
	 * @param min axis minimum
80
	 */
81
	void setMinimum(double min);
82
83
	/**
84
	 * @return true if maximum value is defined, false otherwise
85
	 */
86
	boolean isSetMaximum();
87
88
	/**
89
	 * @return axis maximum or 0.0 if not set
90
	 */
91
	double getMaximum();
92
93
	/**
94
	 * @param max axis maximum
95
	 */
96
	void setMaximum(double max);
97
98
	/**
99
	 * @return axis orientation
100
	 */
101
	AxisOrientation getOrientation();
102
103
	/**
104
	 * @param axis orientation
105
	 */
106
	void setOrientation(AxisOrientation orientation);
107
108
	/**
109
	 * @param crosses axis cross type
110
	 */
111
	void setCrosses(AxisCrosses crosses);
112
113
	/**
114
	 * @return axis cross type
115
	 */
116
	AxisCrosses getCrosses();
117
118
	/**
119
	 * Declare this axis cross another axis.
120
	 * @param axis that this axis should cross
121
	 */
122
	void crossAxis(ChartAxis axis);
123
}
(-)a/src/java/org/apache/poi/ss/usermodel/charts/ChartAxisFactory.java (+34 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
import org.apache.poi.ss.usermodel.Chart;
21
22
/**
23
 * A factory for different chart axis.
24
 *
25
 * @author Roman Kashitsyn
26
 */
27
public interface ChartAxisFactory {
28
	
29
	/**
30
	 * @return new value axis
31
	 */
32
	ValueAxis createValueAxis(AxisPosition pos);
33
34
}
(-)a/src/java/org/apache/poi/ss/usermodel/charts/ChartData.java (+36 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
import org.apache.poi.ss.usermodel.Chart;
21
22
/**
23
 * A base for all chart data types.
24
 *
25
 * @author Roman Kashitsyn
26
 */
27
public interface ChartData {
28
29
	/**
30
	 * Fills a chart with data specified by implementation.
31
	 *
32
	 * @param chart a chart to fill in
33
	 * @param axis chart axis to use
34
	 */
35
	void fillChart(Chart chart, ChartAxis... axis);
36
}
(-)a/src/java/org/apache/poi/ss/usermodel/charts/ChartDataFactory.java (+32 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
 * A factory for different chart data types.
22
 *
23
 * @author Roman Kashitsyn
24
 */
25
public interface ChartDataFactory {
26
	
27
	/**
28
	 * @return an appropriate ScatterChartData instance
29
	 */
30
	ScatterChartData createScatterChartData();
31
32
}
(-)a/src/java/org/apache/poi/ss/usermodel/charts/ChartLegend.java (+37 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
 * High level representation of chart legend.
22
 *
23
 * @author Roman Kashitsyn
24
 */
25
public interface ChartLegend {
26
	
27
	/**
28
	 * @return legend position
29
	 */
30
	LegendPosition getPosition();
31
32
	/**
33
	 * @param position new legend position
34
	 */
35
	void setPosition(LegendPosition position);
36
37
}
(-)a/src/java/org/apache/poi/ss/usermodel/charts/LegendPosition.java (+31 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 all possible chart legend positions.
22
 *
23
 * @author Roman Kashitsyn
24
 */
25
public enum LegendPosition {
26
	BOTTOM,
27
	LEFT,
28
	RIGHT,
29
	TOP,
30
	TOP_RIGHT
31
}
(-)a/src/java/org/apache/poi/ss/usermodel/charts/ScatterChartData.java (+35 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
import java.util.List;
21
22
/**
23
 * @author Roman Kashitsyn
24
 */
25
public interface ScatterChartData extends ChartData {
26
	/**
27
	 * @return a new scatter chart serie
28
	 */
29
	ScatterChartSerie addSerie();
30
31
	/**
32
	 * @return list of all series
33
	 */
34
	List<? extends ScatterChartSerie> getSeries();
35
}
(-)a/src/java/org/apache/poi/ss/usermodel/charts/ScatterChartSerie.java (+41 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
import org.apache.poi.ss.usermodel.Sheet;
21
import org.apache.poi.ss.util.CellRangeAddress;
22
import org.apache.poi.ss.usermodel.charts.ChartDataFactory;
23
24
/**
25
 * @author Roman Kashitsyn
26
 */
27
public interface ScatterChartSerie {
28
29
	/**
30
	 * @param sheet a sheet to take range from
31
	 * @param address a column or a row with values
32
	 */
33
	void setXValues(Sheet sheet, CellRangeAddress address);
34
	
35
	/**'
36
	 * @param sheet a sheet to take range from
37
	 * @param address a column or a row with values
38
	 */
39
	void setYValues(Sheet sheet, CellRangeAddress address);
40
41
}
(-)a/src/java/org/apache/poi/ss/usermodel/charts/ValueAxis.java (+34 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
 * @author Roman Kashitsyn
22
 */
23
public interface ValueAxis extends ChartAxis {
24
25
	/**
26
	 * @return cross between type
27
	 */
28
	AxisCrossBetween getCrossBetween();
29
30
	/**
31
	 * @param crossBetween cross between type
32
	 */
33
	void setCrossBetween(AxisCrossBetween crossBetween);
34
}
(-)a/src/java/org/apache/poi/ss/util/CellRangeAddress.java (-2 / +16 lines)
Lines 80-89 public class CellRangeAddress extends CellRangeAddressBase { Link Here
80
     *         like single cell references (e.g. 'A1' instead of 'A1:A1').
80
     *         like single cell references (e.g. 'A1' instead of 'A1:A1').
81
     */
81
     */
82
    public String formatAsString() {
82
    public String formatAsString() {
83
        return formatAsString(null, false);
84
    }
85
86
    /**
87
     * @return the text format of this range using specified sheet name.
88
     */
89
    public String formatAsString(String sheetName, boolean useAbsoluteAddress) {
83
        StringBuffer sb = new StringBuffer();
90
        StringBuffer sb = new StringBuffer();
84
        CellReference cellRefFrom = new CellReference(getFirstRow(), getFirstColumn());
91
        if (sheetName != null) {
85
        CellReference cellRefTo = new CellReference(getLastRow(), getLastColumn());
92
            sb.append(sheetName);
93
            sb.append("!");
94
        }
95
        CellReference cellRefFrom = new CellReference(getFirstRow(), getFirstColumn(),
96
                useAbsoluteAddress, useAbsoluteAddress);
97
        CellReference cellRefTo = new CellReference(getLastRow(), getLastColumn(),
98
                useAbsoluteAddress, useAbsoluteAddress);
86
        sb.append(cellRefFrom.formatAsString());
99
        sb.append(cellRefFrom.formatAsString());
100
87
        //for a single-cell reference return A1 instead of A1:A1
101
        //for a single-cell reference return A1 instead of A1:A1
88
        if(!cellRefFrom.equals(cellRefTo)){
102
        if(!cellRefFrom.equals(cellRefTo)){
89
            sb.append(':');
103
            sb.append(':');
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java (-103 / +266 lines)
Lines 21-31 import java.io.IOException; Link Here
21
import java.io.OutputStream;
21
import java.io.OutputStream;
22
import java.util.HashMap;
22
import java.util.HashMap;
23
import java.util.Map;
23
import java.util.Map;
24
import java.util.List;
25
import java.util.ArrayList;
26
27
import javax.xml.namespace.QName;
24
28
25
import org.apache.poi.POIXMLDocumentPart;
29
import org.apache.poi.POIXMLDocumentPart;
26
import org.apache.poi.openxml4j.opc.PackagePart;
30
import org.apache.poi.openxml4j.opc.PackagePart;
27
import org.apache.poi.openxml4j.opc.PackageRelationship;
31
import org.apache.poi.openxml4j.opc.PackageRelationship;
28
import org.apache.poi.util.Internal;
32
import org.apache.poi.util.Internal;
33
import org.apache.poi.ss.usermodel.Chart;
34
import org.apache.poi.ss.usermodel.charts.ChartAxis;
35
import org.apache.poi.ss.usermodel.charts.ChartAxisFactory;
36
import org.apache.poi.xssf.usermodel.charts.XSSFChartDataFactory;
37
import org.apache.poi.xssf.usermodel.charts.XSSFChartAxis;
38
import org.apache.poi.xssf.usermodel.charts.XSSFValueAxis;
39
import org.apache.poi.xssf.usermodel.charts.XSSFChartLegend;
40
import org.apache.poi.ss.usermodel.charts.ChartData;
41
import org.apache.poi.ss.usermodel.charts.AxisPosition;
29
import org.apache.xmlbeans.XmlException;
42
import org.apache.xmlbeans.XmlException;
30
import org.apache.xmlbeans.XmlObject;
43
import org.apache.xmlbeans.XmlObject;
31
import org.apache.xmlbeans.XmlOptions;
44
import org.apache.xmlbeans.XmlOptions;
Lines 33-147 import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart; Link Here
33
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
46
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
34
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
47
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
35
import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument;
48
import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument;
49
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLayout;
50
import org.openxmlformats.schemas.drawingml.x2006.chart.CTManualLayout;
51
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
52
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPrintSettings;
53
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPageMargins;
54
import org.openxmlformats.schemas.drawingml.x2006.chart.STLayoutTarget;
55
import org.openxmlformats.schemas.drawingml.x2006.chart.STLayoutMode;
36
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
56
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
37
import org.w3c.dom.NodeList;
57
import org.w3c.dom.NodeList;
38
import org.w3c.dom.Text;
58
import org.w3c.dom.Text;
39
59
40
/**
60
/**
41
 * Represents a SpreadsheetML Chart
61
 * Represents a SpreadsheetML Chart
62
 * @author Nick Burch
63
 * @author Roman Kashitsyn
42
 */
64
 */
43
public final class XSSFChart extends POIXMLDocumentPart {
65
public final class XSSFChart extends POIXMLDocumentPart implements Chart, ChartAxisFactory {
44
    /**
66
45
     * Root element of the SpreadsheetML Chart part
67
	/**
46
     */
68
	 * Parent graphic frame.
47
    private CTChartSpace chartSpace;
69
	 */
48
    /**
70
	private XSSFGraphicFrame frame;
49
     * The Chart within that
71
50
     */
72
	/**
51
    private CTChart chart;
73
	 * Root element of the SpreadsheetML Chart part
52
74
	 */
53
    /**
75
	private CTChartSpace chartSpace;
54
     * Create a new SpreadsheetML chart
76
	/**
55
     */
77
	 * The Chart within that
56
    protected XSSFChart() {
78
	 */
57
        super();
79
	private CTChart chart;
58
        createChart();
80
59
    }
81
	List<XSSFChartAxis> axis;
60
82
61
    /**
83
	/**
62
     * Construct a SpreadsheetML chart from a package part
84
	 * Create a new SpreadsheetML chart
63
     *
85
	 */
64
     * @param part the package part holding the chart data,
86
	protected XSSFChart() {
65
     * the content type must be <code>application/vnd.openxmlformats-officedocument.drawingml.chart+xml</code>
87
		super();
66
     * @param rel  the package relationship holding this chart,
88
		axis = new ArrayList<XSSFChartAxis>();
67
     * the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart
89
		createChart();
68
     */
90
	}
69
    protected XSSFChart(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
91
70
        super(part, rel);
92
	/**
71
        
93
	 * Construct a SpreadsheetML chart from a package part
72
        chartSpace = ChartSpaceDocument.Factory.parse(part.getInputStream()).getChartSpace(); 
94
	 *
73
        chart = chartSpace.getChart();
95
	 * @param part the package part holding the chart data,
74
    }
96
	 * the content type must be <code>application/vnd.openxmlformats-officedocument.drawingml.chart+xml</code>
75
97
	 * @param rel  the package relationship holding this chart,
76
    /**
98
	 * the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart
77
     * Construct a new CTChartSpace bean. By default, it's just an empty placeholder for chart objects
99
	 */
78
     *
100
	protected XSSFChart(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
79
     * @return a new CTChartSpace bean
101
		super(part, rel);
80
     */
102
81
    private void createChart() {
103
		chartSpace = ChartSpaceDocument.Factory.parse(part.getInputStream()).getChartSpace(); 
82
        chartSpace = CTChartSpace.Factory.newInstance();
104
		chart = chartSpace.getChart();
83
        chart = chartSpace.addNewChart();
105
	}
84
    }
106
85
107
	/**
86
    /**
108
	 * Construct a new CTChartSpace bean. By default, it's just an empty placeholder for chart objects
87
     * Return the underlying CTChartSpace bean, the root element of the SpreadsheetML Chart part.
109
	 *
88
     *
110
	 * @return a new CTChartSpace bean
89
     * @return the underlying CTChartSpace bean
111
	 */
90
     */
112
	private void createChart() {
91
    @Internal
113
		chartSpace = CTChartSpace.Factory.newInstance();
92
    public CTChartSpace getCTChartSpace(){
114
		chart = chartSpace.addNewChart();
93
        return chartSpace;
115
		CTPlotArea plotArea = chart.addNewPlotArea();
94
    }
116
		CTLayout layout = plotArea.addNewLayout();
95
117
		CTManualLayout manualLayout = layout.addNewManualLayout();
96
    /**
118
		manualLayout.addNewLayoutTarget().setVal(STLayoutTarget.INNER);
97
     * Return the underlying CTChart bean, within the Chart Space
119
		manualLayout.addNewXMode().setVal(STLayoutMode.EDGE);
98
     *
120
		manualLayout.addNewYMode().setVal(STLayoutMode.EDGE);
99
     * @return the underlying CTChart bean
121
		manualLayout.addNewX().setVal(0);
100
     */
122
		manualLayout.addNewY().setVal(0);
101
    @Internal
123
		manualLayout.addNewW().setVal(0.65);
102
    public CTChart getCTChart(){
124
		manualLayout.addNewH().setVal(0.8);
103
        return chart;
125
		chart.addNewPlotVisOnly().setVal(true);
104
    }
126
		CTPrintSettings printSettings = chartSpace.addNewPrintSettings();
105
127
		printSettings.addNewHeaderFooter();
106
    @Override
128
107
    protected void commit() throws IOException {
129
		CTPageMargins pageMargins = printSettings.addNewPageMargins();
108
        XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
130
		pageMargins.setB(0.75);
109
131
		pageMargins.setL(0.70);
110
        Map<String, String> map = new HashMap<String, String>();
132
		pageMargins.setR(0.70);
111
        map.put(XSSFDrawing.NAMESPACE_A, "a");
133
		pageMargins.setT(0.75);
112
        map.put(STRelationshipId.type.getName().getNamespaceURI(), "r");
134
		pageMargins.setHeader(0.30);
113
        xmlOptions.setSaveSuggestedPrefixes(map);
135
		pageMargins.setFooter(0.30);
114
136
		printSettings.addNewPageSetup();
115
        PackagePart part = getPackagePart();
137
	}
116
        OutputStream out = part.getOutputStream();
138
117
        chartSpace.save(out, xmlOptions);
139
	/**
118
        out.close();
140
	 * Return the underlying CTChartSpace bean, the root element of the SpreadsheetML Chart part.
119
    }
141
	 *
120
    
142
	 * @return the underlying CTChartSpace bean
121
    /**
143
	 */
122
     * Returns the title, or null if none is set
144
	@Internal
123
     */
145
	public CTChartSpace getCTChartSpace(){
124
    public XSSFRichTextString getTitle() {
146
		return chartSpace;
125
       if(! chart.isSetTitle()) {
147
	}
126
          return null;
148
127
       }
149
	/**
128
       
150
	 * Return the underlying CTChart bean, within the Chart Space
129
       // TODO Do properly
151
	 *
130
       CTTitle title = chart.getTitle();
152
	 * @return the underlying CTChart bean
131
       
153
	 */
132
       StringBuffer text = new StringBuffer();
154
	@Internal
133
       XmlObject[] t = title
155
	public CTChart getCTChart(){
134
           .selectPath("declare namespace a='"+XSSFDrawing.NAMESPACE_A+"' .//a:t");
156
		return chart;
135
       for (int m = 0; m < t.length; m++) {
157
	}
136
          NodeList kids = t[m].getDomNode().getChildNodes();
158
137
          for (int n = 0; n < kids.getLength(); n++) {
159
	@Override
138
             if (kids.item(n) instanceof Text) {
160
	protected void commit() throws IOException {
139
                text.append(kids.item(n).getNodeValue());
161
		XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
140
             }
162
141
          }
163
		/*
142
       }
164
		   Saved chart space must have the following namespaces set:
143
       
165
		   <c:chartSpace
144
       return new XSSFRichTextString(text.toString());
166
		      xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"
145
    }
167
		      xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
168
		      xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
169
		 */
170
		xmlOptions.setSaveSyntheticDocumentElement(new QName(CTChartSpace.type.getName().getNamespaceURI(), "chartSpace", "c"));
171
		Map<String, String> map = new HashMap<String, String>();
172
		map.put(XSSFDrawing.NAMESPACE_A, "a");
173
		map.put(XSSFDrawing.NAMESPACE_C, "c");
174
		map.put(STRelationshipId.type.getName().getNamespaceURI(), "r");
175
		xmlOptions.setSaveSuggestedPrefixes(map);
176
177
		PackagePart part = getPackagePart();
178
		OutputStream out = part.getOutputStream();
179
		chartSpace.save(out, xmlOptions);
180
		out.close();
181
	}
182
183
	/**
184
	 * Returns the parent graphic frame.
185
	 * @return the graphic frame this chart belongs to
186
	 */
187
	public XSSFGraphicFrame getGraphicFrame() {
188
		return frame;
189
	}
190
191
	/**
192
	 * Sets the parent graphic frame.
193
	 */
194
	protected void setGraphicFrame(XSSFGraphicFrame frame) {
195
		this.frame = frame;
196
	}
197
198
	public XSSFChartDataFactory getChartDataFactory() {
199
		return XSSFChartDataFactory.getInstance();
200
	}
201
202
	public XSSFChart getChartAxisFactory() {
203
		return this;
204
	}
205
206
	public void plot(ChartData data, ChartAxis... axis) {
207
		data.fillChart(this, axis);
208
	}
209
210
	public XSSFValueAxis createValueAxis(AxisPosition pos) {
211
		long id = axis.size() + 1;
212
		XSSFValueAxis valueAxis = new XSSFValueAxis(this, id, pos);
213
		if (axis.size() == 1) {
214
			ChartAxis ax = axis.get(0);
215
			ax.crossAxis(valueAxis);
216
			valueAxis.crossAxis(ax);
217
		}
218
		axis.add(valueAxis);
219
		return valueAxis;
220
	}
221
222
	public List<? extends XSSFChartAxis> getAxis() {
223
		return axis;
224
	}
225
226
	/**
227
	 * Sets the width ratio of the chart.
228
	 * Chart width is ratio multiplied by parent frame width.
229
	 * @param ratio a number between 0 and 1.
230
	 */
231
	public void setWidthRatio(double ratio) {
232
		chart.getPlotArea().getLayout().getManualLayout().getW().setVal(ratio);
233
	}
234
235
	/**
236
	 * @return relative chart width
237
	 */
238
	public double getWidthRatio() {
239
		return chart.getPlotArea().getLayout().getManualLayout().getW().getVal();
240
	}
241
242
	/**
243
	 * Sets the height ratio of the chart.
244
	 * Chart height is ratio multiplied by parent frame height.
245
	 * @param ratio a number between 0 and 1.
246
	 */
247
	public void setHeightRatio(double ratio) {
248
		chart.getPlotArea().getLayout().getManualLayout().getH().setVal(ratio);
249
	}
250
251
	/**
252
	 * @return relative chart height
253
	 */
254
	public double getHeightRatio() {
255
		return chart.getPlotArea().getLayout().getManualLayout().getH().getVal();
256
	}
257
258
	/**
259
	 * @return true if only visible cells will be present on the chart,
260
	 *         false otherwise
261
	 */
262
	public boolean isPlotOnlyVisibleCells() {
263
		return chart.getPlotVisOnly().getVal();
264
	}
265
266
	/**
267
	 * @param plotVisOnly a flag specifying if only visible cells should be
268
	 *        present on the chart
269
	 */
270
	public void setPlotOnlyVisibleCells(boolean plotVisOnly) {
271
		chart.getPlotVisOnly().setVal(plotVisOnly);
272
	}
273
274
	/**
275
	 * Returns the title, or null if none is set
276
	 */
277
	public XSSFRichTextString getTitle() {
278
		if(! chart.isSetTitle()) {
279
			return null;
280
		}
281
282
		// TODO Do properly
283
		CTTitle title = chart.getTitle();
284
285
		StringBuffer text = new StringBuffer();
286
		XmlObject[] t = title
287
			.selectPath("declare namespace a='"+XSSFDrawing.NAMESPACE_A+"' .//a:t");
288
		for (int m = 0; m < t.length; m++) {
289
			NodeList kids = t[m].getDomNode().getChildNodes();
290
			for (int n = 0; n < kids.getLength(); n++) {
291
				if (kids.item(n) instanceof Text) {
292
					text.append(kids.item(n).getNodeValue());
293
				}
294
			}
295
		}
296
297
		return new XSSFRichTextString(text.toString());
298
	}
299
300
	public XSSFChartLegend getOrCreateLegend() {
301
		return new XSSFChartLegend(this);
302
	}
303
304
	public void deleteLegend() {
305
		if (chart.isSetLegend()) {
306
			chart.unsetLegend();
307
		}
308
	}
146
309
147
}
310
}
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java (-7 / +59 lines)
Lines 44-49 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture; Link Here
44
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
44
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
45
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
45
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
46
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs;
46
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs;
47
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame;
47
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
48
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
48
49
49
/**
50
/**
Lines 57-64 public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing { Link Here
57
     */
58
     */
58
    private CTDrawing drawing;
59
    private CTDrawing drawing;
59
    private boolean isNew;
60
    private boolean isNew;
61
    private long numOfGraphicFrames = 0L;
60
    
62
    
61
    protected static final String NAMESPACE_A = "http://schemas.openxmlformats.org/drawingml/2006/main";
63
    protected static final String NAMESPACE_A = "http://schemas.openxmlformats.org/drawingml/2006/main";
64
    protected static final String NAMESPACE_C = "http://schemas.openxmlformats.org/drawingml/2006/chart";
62
65
63
    /**
66
    /**
64
     * Create a new SpreadsheetML drawing
67
     * Create a new SpreadsheetML drawing
Lines 125-130 public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing { Link Here
125
        out.close();
128
        out.close();
126
    }
129
    }
127
130
131
	public XSSFClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2,
132
			int col1, int row1, int col2, int row2) {
133
		return new XSSFClientAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2);
134
	}
135
128
    /**
136
    /**
129
     * Constructs a textbox under the drawing.
137
     * Constructs a textbox under the drawing.
130
     *
138
     *
Lines 169-174 public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing { Link Here
169
        return createPicture((XSSFClientAnchor)anchor, pictureIndex);
177
        return createPicture((XSSFClientAnchor)anchor, pictureIndex);
170
    }
178
    }
171
179
180
	/**
181
	 * Creates a chart.
182
	 * @param anchor the client anchor describes how this chart is attached to
183
	 *               the sheet.
184
	 * @return the newly created chart
185
	 * @see org.apache.poi.xssf.usermodel.XSSFDrawing#createChart(ClientAnchor)
186
	 */
187
    public XSSFChart createChart(XSSFClientAnchor anchor) {
188
        int chartNumber = getPackagePart().getPackage().
189
            getPartsByContentType(XSSFRelation.CHART.getContentType()).size() + 1;
190
191
        XSSFChart chart = (XSSFChart) createRelationship(
192
                XSSFRelation.CHART, XSSFFactory.getInstance(), chartNumber);
193
        String chartRelId = chart.getPackageRelationship().getId();
194
195
        XSSFGraphicFrame frame = createGraphicFrame(anchor);
196
        frame.setChart(chart, chartRelId);
197
198
        return chart;
199
    }
200
201
	public XSSFChart createChart(ClientAnchor anchor) {
202
		return createChart((XSSFClientAnchor)anchor);
203
	}
204
172
    /**
205
    /**
173
     * Add the indexed picture to this drawing relations
206
     * Add the indexed picture to this drawing relations
174
     *
207
     *
Lines 240-252 public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing { Link Here
240
        return shape;
273
        return shape;
241
    }
274
    }
242
275
243
    /**
276
	/**
244
     * Creates a cell comment.
277
	 * Creates a comment.
245
     *
278
	 * @param anchor the client anchor describes how this comment is attached
246
     * @param anchor    the client anchor describes how this comment is attached
279
	 *               to the sheet.
247
     *                  to the sheet.
280
	 * @return the newly created comment.
248
     * @return  the newly created comment.
281
	 */
249
     */
250
    public XSSFComment createCellComment(ClientAnchor anchor) {
282
    public XSSFComment createCellComment(ClientAnchor anchor) {
251
        XSSFClientAnchor ca = (XSSFClientAnchor)anchor;
283
        XSSFClientAnchor ca = (XSSFClientAnchor)anchor;
252
        XSSFSheet sheet = (XSSFSheet)getParent();
284
        XSSFSheet sheet = (XSSFSheet)getParent();
Lines 266-271 public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing { Link Here
266
        shape.setRow(ca.getRow1());
298
        shape.setRow(ca.getRow1());
267
        return shape;
299
        return shape;
268
    }
300
    }
301
302
    /**
303
     * Creates a new graphic frame.
304
     *
305
     * @param anchor    the client anchor describes how this frame is attached
306
     *                  to the sheet
307
     * @return  the newly created graphic frame
308
     */
309
    private XSSFGraphicFrame createGraphicFrame(XSSFClientAnchor anchor) {
310
        CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
311
        CTGraphicalObjectFrame ctGraphicFrame = ctAnchor.addNewGraphicFrame();
312
        ctGraphicFrame.set(XSSFGraphicFrame.prototype());
313
314
        long frameId = numOfGraphicFrames++;
315
        XSSFGraphicFrame graphicFrame = new XSSFGraphicFrame(this, ctGraphicFrame);
316
        graphicFrame.setAnchor(anchor);
317
        graphicFrame.setId(frameId);
318
        graphicFrame.setName("Diagramm" + frameId);
319
        return graphicFrame;
320
    }
269
    
321
    
270
    /**
322
    /**
271
     * Returns all charts in this drawing.
323
     * Returns all charts in this drawing.
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java (+187 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.xssf.usermodel;
19
20
import javax.xml.namespace.QName;
21
22
import org.apache.poi.openxml4j.opc.PackageRelationship;
23
import org.apache.poi.util.Internal;
24
import org.apache.xmlbeans.XmlObject;
25
import org.apache.xmlbeans.XmlCursor;
26
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame;
27
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrameNonVisual;
28
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject;
29
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData;
30
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
31
import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
32
import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
33
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
34
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
35
36
/**
37
 * Represents DrawingML GraphicalObjectFrame.
38
 *
39
 * @author Roman Kashitsyn
40
 */
41
public final class XSSFGraphicFrame {
42
43
	private static CTGraphicalObjectFrame prototype = null;
44
45
	private CTGraphicalObjectFrame graphicFrame;
46
	private XSSFDrawing drawing;
47
	private XSSFClientAnchor anchor;
48
49
	/**
50
	 * Construct a new XSSFGraphicFrame object.
51
	 *
52
	 * @param drawing the XSSFDrawing that owns this frame
53
	 * @param ctGraphicFrame the XML bean that stores this frame content
54
	 */
55
	protected XSSFGraphicFrame(XSSFDrawing drawing, CTGraphicalObjectFrame ctGraphicFrame) {
56
		this.drawing = drawing;
57
		this.graphicFrame = ctGraphicFrame;
58
	}
59
60
	@Internal
61
	public CTGraphicalObjectFrame getCTGraphicalObjectFrame() {
62
		return graphicFrame;
63
	}
64
65
	/**
66
	 * Initialize default structure of a new graphic frame
67
	 */
68
	protected static CTGraphicalObjectFrame prototype() {
69
		if (prototype == null) {
70
			CTGraphicalObjectFrame graphicFrame = CTGraphicalObjectFrame.Factory.newInstance();
71
72
			CTGraphicalObjectFrameNonVisual nvGraphic = graphicFrame.addNewNvGraphicFramePr();
73
			CTNonVisualDrawingProps props = nvGraphic.addNewCNvPr();
74
			props.setId(0);
75
			props.setName("Diagramm 1");
76
			nvGraphic.addNewCNvGraphicFramePr();
77
78
			CTTransform2D transform = graphicFrame.addNewXfrm();
79
			CTPositiveSize2D extPoint = transform.addNewExt();
80
			CTPoint2D offPoint = transform.addNewOff();
81
82
			extPoint.setCx(0);
83
			extPoint.setCy(0);
84
			offPoint.setX(0);
85
			offPoint.setY(0);
86
87
			CTGraphicalObject graphic = graphicFrame.addNewGraphic();
88
89
			prototype = graphicFrame;
90
		}
91
		return prototype;
92
	}
93
94
	/**
95
	 * Sets the frame macro.
96
	 */
97
	public void setMacro(String macro) {
98
		graphicFrame.setMacro(macro);
99
	}
100
101
	/**
102
	 * Sets the frame name.
103
	 */
104
	public void setName(String name) {
105
		getNonVisualProperties().setName(name);
106
	}
107
108
	/**
109
	 * Returns the frame name.
110
	 * @return name of the frame
111
	 */
112
	public String getName() {
113
		return getNonVisualProperties().getName();
114
	}
115
116
	private CTNonVisualDrawingProps getNonVisualProperties() {
117
		CTGraphicalObjectFrameNonVisual nvGraphic = graphicFrame.getNvGraphicFramePr();
118
		return nvGraphic.getCNvPr();
119
	}
120
121
	/**
122
	 * Attaches frame to an anchor.
123
	 */
124
	protected void setAnchor(XSSFClientAnchor anchor) {
125
		this.anchor = anchor;
126
	}
127
128
	/**
129
	 * Returns the frame anchor.
130
	 * @return the anchor this frame is attached to
131
	 */
132
	public XSSFClientAnchor getAnchor() {
133
		return anchor;
134
	}
135
136
	/**
137
	 * Assign a DrawingML chart to the graphic frame.
138
	 */
139
	protected void setChart(XSSFChart chart, String relId) {
140
		CTGraphicalObjectData data = graphicFrame.getGraphic().addNewGraphicData();
141
		appendChartElement(data, relId);
142
		chart.setGraphicFrame(this);
143
		return;
144
	}
145
146
	/**
147
	 * Gets the frame id.
148
	 */
149
	public long getId() {
150
		return graphicFrame.getNvGraphicFramePr().getCNvPr().getId();
151
	}
152
153
	/**
154
	 * Sets the frame id.
155
	 */
156
	protected void setId(long id) {
157
		graphicFrame.getNvGraphicFramePr().getCNvPr().setId(id);
158
	}
159
160
	/**
161
	 * The low level code to insert {@code <c:chart>} tag into
162
	 * {@code<a:graphicData>}.
163
	 *
164
	 * Here is the schema (ECMA-376):
165
	 * <pre>
166
	 * {@code
167
	 * <complexType name="CT_GraphicalObjectData">
168
	 *   <sequence>
169
	 *     <any minOccurs="0" maxOccurs="unbounded" processContents="strict"/>
170
	 *   </sequence>
171
	 *   <attribute name="uri" type="xsd:token"/>
172
	 * </complexType>
173
	 * }
174
	 * </pre>
175
	 */
176
	private void appendChartElement(CTGraphicalObjectData data, String id) {
177
		String r_namespaceUri = STRelationshipId.type.getName().getNamespaceURI();
178
		String c_namespaceUri = XSSFDrawing.NAMESPACE_C;
179
		XmlCursor cursor = data.newCursor();
180
		cursor.toNextToken();
181
		cursor.beginElement(new QName(c_namespaceUri, "chart", "c"));
182
		cursor.insertAttributeWithValue(new QName(r_namespaceUri, "id", "r"), id);
183
		cursor.dispose();
184
		data.setUri(c_namespaceUri);
185
	}
186
187
}
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java (-6 / +6 lines)
Lines 90-101 public final class XSSFRelation extends POIXMLRelation { Link Here
90
			"/xl/worksheets/sheet#.xml",
90
			"/xl/worksheets/sheet#.xml",
91
			XSSFSheet.class
91
			XSSFSheet.class
92
	);
92
	);
93
   public static final XSSFRelation CHARTSHEET = new XSSFRelation(
93
	public static final XSSFRelation CHARTSHEET = new XSSFRelation(
94
            "application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml",
94
			"application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml",
95
            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet",
95
			"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet",
96
            "/xl/chartsheets/sheet#.xml",
96
			"/xl/chartsheets/sheet#.xml",
97
            XSSFChartSheet.class
97
			XSSFChartSheet.class
98
   );
98
	);
99
	public static final XSSFRelation SHARED_STRINGS = new XSSFRelation(
99
	public static final XSSFRelation SHARED_STRINGS = new XSSFRelation(
100
			"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",
100
			"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",
101
			"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",
101
			"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartAxis.java (+223 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.xssf.usermodel.charts;
19
20
import org.apache.poi.ss.usermodel.charts.ChartAxis;
21
import org.apache.poi.ss.usermodel.charts.AxisPosition;
22
import org.apache.poi.ss.usermodel.charts.AxisOrientation;
23
import org.apache.poi.ss.usermodel.charts.AxisCrosses;
24
import org.apache.poi.xssf.usermodel.XSSFChart;
25
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
26
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
27
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
28
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
29
import org.openxmlformats.schemas.drawingml.x2006.chart.CTOrientation;
30
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLogBase;
31
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
32
import org.openxmlformats.schemas.drawingml.x2006.chart.STOrientation;
33
import org.openxmlformats.schemas.drawingml.x2006.chart.STAxPos;
34
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrosses;
35
36
/**
37
 * Base class for all axis types.
38
 *
39
 * @author Roman Kashitsyn
40
 */
41
public abstract class XSSFChartAxis implements ChartAxis {
42
43
	protected XSSFChart chart;
44
45
	private static final double MIN_LOG_BASE = 2.0;
46
	private static final double MAX_LOG_BASE = 1000.0;
47
48
	protected XSSFChartAxis(XSSFChart chart) {
49
		this.chart = chart;
50
	}
51
52
	public AxisPosition getPosition() {
53
		return toAxisPosition(getCTAxPos());
54
	}
55
56
	public void setPosition(AxisPosition position) {
57
		getCTAxPos().setVal(fromAxisPosition(position));
58
	}
59
60
	public void setNumberFormat(String format) {
61
		getCTNumFmt().setFormatCode(format);
62
		getCTNumFmt().setSourceLinked(true);
63
	}
64
65
	public String getNumberFormat() {
66
		return getCTNumFmt().getFormatCode();
67
	}
68
69
	public boolean isSetLogBase() {
70
		return getCTScaling().isSetLogBase();
71
	}
72
73
	public void setLogBase(double logBase) {
74
		if (logBase < MIN_LOG_BASE ||
75
			MAX_LOG_BASE < logBase) {
76
			throw new IllegalArgumentException("Axis log base must be between 2 and 1000 (inclusive), got: " + logBase);
77
		}
78
		CTScaling scaling = getCTScaling();
79
		if (scaling.isSetLogBase()) {
80
			scaling.getLogBase().setVal(logBase);
81
		} else {
82
			scaling.addNewLogBase().setVal(logBase);
83
		}
84
	}
85
86
	public double getLogBase() {
87
		CTLogBase logBase = getCTScaling().getLogBase();
88
		if (logBase != null) {
89
			return logBase.getVal();
90
		}
91
		return 0.0;
92
	}
93
94
	public boolean isSetMinimum() {
95
		return getCTScaling().isSetMin();
96
	}
97
98
	public void setMinimum(double min) {
99
		CTScaling scaling = getCTScaling();
100
		if (scaling.isSetMin()) {
101
			scaling.getMin().setVal(min);
102
		} else {
103
			scaling.addNewMin().setVal(min);
104
		}
105
	}
106
107
	public double getMinimum() {
108
		CTScaling scaling = getCTScaling();
109
		if (scaling.isSetMin()) {
110
			return scaling.getMin().getVal();
111
		} else {
112
			return 0.0;
113
		}
114
	}
115
116
	public boolean isSetMaximum() {
117
		return getCTScaling().isSetMax();
118
	}
119
120
	public void setMaximum(double max) {
121
		CTScaling scaling = getCTScaling();
122
		if (scaling.isSetMax()) {
123
			scaling.getMax().setVal(max);
124
		} else {
125
			scaling.addNewMax().setVal(max);
126
		}
127
	}
128
129
	public double getMaximum() {
130
		CTScaling scaling = getCTScaling();
131
		if (scaling.isSetMax()) {
132
			return scaling.getMax().getVal();
133
		} else {
134
			return 0.0;
135
		}
136
	}
137
138
	public AxisOrientation getOrientation() {
139
		return toAxisOrientation(getCTScaling().getOrientation());
140
	}
141
142
	public void setOrientation(AxisOrientation orientation) {
143
		CTScaling scaling = getCTScaling();
144
		STOrientation.Enum stOrientation = fromAxisOrientation(orientation);
145
		if (scaling.isSetOrientation()) {
146
			scaling.getOrientation().setVal(stOrientation);
147
		} else {
148
			getCTScaling().addNewOrientation().setVal(stOrientation);
149
		}
150
	}
151
152
	public AxisCrosses getCrosses() {
153
		return toAxisCrosses(getCTCrosses());
154
	}
155
156
	public void setCrosses(AxisCrosses crosses) {
157
		getCTCrosses().setVal(fromAxisCrosses(crosses));
158
	}
159
160
	protected abstract CTAxPos getCTAxPos();
161
	protected abstract CTNumFmt getCTNumFmt();
162
	protected abstract CTScaling getCTScaling();
163
	protected abstract CTCrosses getCTCrosses();
164
165
	private static STOrientation.Enum fromAxisOrientation(AxisOrientation orientation) {
166
		switch (orientation) {
167
			case MIN_MAX: return STOrientation.MIN_MAX;
168
			case MAX_MIN: return STOrientation.MAX_MIN;
169
			default:
170
				throw new IllegalArgumentException();
171
		}
172
	}
173
174
	private static AxisOrientation toAxisOrientation(CTOrientation ctOrientation) {
175
		switch (ctOrientation.getVal().intValue()) {
176
			case STOrientation.INT_MIN_MAX: return AxisOrientation.MIN_MAX;
177
			case STOrientation.INT_MAX_MIN: return AxisOrientation.MAX_MIN;
178
			default:
179
				throw new IllegalArgumentException();
180
		}
181
	}
182
183
	private static STCrosses.Enum fromAxisCrosses(AxisCrosses crosses) {
184
		switch (crosses) {
185
			case AUTO_ZERO: return STCrosses.AUTO_ZERO;
186
			case MIN: return STCrosses.MIN;
187
			case MAX: return STCrosses.MAX;
188
			default:
189
				throw new IllegalArgumentException();
190
		}
191
	}
192
193
	private static AxisCrosses toAxisCrosses(CTCrosses ctCrosses) {
194
		switch (ctCrosses.getVal().intValue()) {
195
			case STCrosses.INT_AUTO_ZERO: return AxisCrosses.AUTO_ZERO;
196
			case STCrosses.INT_MAX: return AxisCrosses.MAX;
197
			case STCrosses.INT_MIN: return AxisCrosses.MIN;
198
			default:
199
				throw new IllegalArgumentException();
200
		}
201
	}
202
203
	private static STAxPos.Enum fromAxisPosition(AxisPosition position) {
204
		switch (position) {
205
			case BOTTOM: return STAxPos.B;
206
			case LEFT: return STAxPos.L;
207
			case RIGHT: return STAxPos.R;
208
			case TOP: return STAxPos.T;
209
			default:
210
				throw new IllegalArgumentException();
211
		}
212
	}
213
214
	private static AxisPosition toAxisPosition(CTAxPos ctAxPos) {
215
		switch (ctAxPos.getVal().intValue()) {
216
			case STAxPos.INT_B: return AxisPosition.BOTTOM;
217
			case STAxPos.INT_L: return AxisPosition.LEFT;
218
			case STAxPos.INT_R: return AxisPosition.RIGHT;
219
			case STAxPos.INT_T: return AxisPosition.TOP;
220
			default: return AxisPosition.BOTTOM;
221
		}
222
	}
223
}
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartDataFactory.java (+50 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.xssf.usermodel.charts;
19
20
import org.apache.poi.ss.usermodel.charts.*;
21
22
/**
23
 * @author Roman Kashitsyn
24
 */
25
public class XSSFChartDataFactory implements ChartDataFactory {
26
27
	private static XSSFChartDataFactory instance;
28
29
	private XSSFChartDataFactory() {
30
		super();
31
	}
32
33
	/**
34
	 * @return new scatter chart data instance
35
	 */
36
	public XSSFScatterChartData createScatterChartData() {
37
		return new XSSFScatterChartData();
38
	}
39
40
	/**
41
	 * @return factory instance
42
	 */
43
	public static XSSFChartDataFactory getInstance() {
44
		if (instance == null) {
45
			instance = new XSSFChartDataFactory();
46
		}
47
		return instance;
48
	}
49
50
}
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartLegend.java (+101 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.xssf.usermodel.charts;
19
20
import org.apache.poi.util.Internal;
21
import org.apache.poi.ss.usermodel.charts.ChartLegend;
22
import org.apache.poi.ss.usermodel.charts.LegendPosition;
23
import org.apache.poi.xssf.usermodel.XSSFChart;
24
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
25
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLegend;
26
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLegendPos;
27
import org.openxmlformats.schemas.drawingml.x2006.chart.STLegendPos;
28
29
/**
30
 * Represents a SpreadsheetML chart legend
31
 * @author Roman Kashitsyn
32
 */
33
public final class XSSFChartLegend implements ChartLegend {
34
35
	/**
36
	 * Underlaying CTLagend bean
37
	 */
38
	private CTLegend legend;
39
40
	/**
41
	 * Create a new SpreadsheetML chart legend
42
	 */
43
	public XSSFChartLegend(XSSFChart chart) {
44
		CTChart ctChart = chart.getCTChart();
45
		this.legend = (ctChart.isSetLegend()) ?
46
			ctChart.getLegend() :
47
			ctChart.addNewLegend();
48
	}
49
50
	/**
51
	 * Return the underlying CTLegend bean.
52
	 *
53
	 * @return the underlying CTLegend bean
54
	 */
55
	@Internal
56
	public CTLegend getCTLegend(){
57
		return legend;
58
	}
59
60
	public void setPosition(LegendPosition position) {
61
		if (!legend.isSetLegendPos()) {
62
			legend.addNewLegendPos();
63
		}
64
		legend.getLegendPos().setVal(fromLegendPosition(position));
65
	}
66
67
	/*
68
	 * According to ECMA-376 default position is RIGHT.
69
	 */
70
	public LegendPosition getPosition() {
71
		if (legend.isSetLegendPos()) {
72
			return toLegendPosition(legend.getLegendPos());
73
		} else {
74
			return LegendPosition.RIGHT;
75
		}
76
	}
77
78
	private STLegendPos.Enum fromLegendPosition(LegendPosition position) {
79
		switch (position) {
80
			case BOTTOM: return STLegendPos.B;
81
			case LEFT: return STLegendPos.L;
82
			case RIGHT: return STLegendPos.R;
83
			case TOP: return STLegendPos.T;
84
			case TOP_RIGHT: return STLegendPos.TR;
85
			default:
86
				throw new IllegalArgumentException();
87
		}
88
	}
89
90
	private LegendPosition toLegendPosition(CTLegendPos ctLegendPos) {
91
		switch (ctLegendPos.getVal().intValue()) {
92
			case STLegendPos.INT_B: return LegendPosition.BOTTOM;
93
			case STLegendPos.INT_L: return LegendPosition.LEFT;
94
			case STLegendPos.INT_R: return LegendPosition.RIGHT;
95
			case STLegendPos.INT_T: return LegendPosition.TOP;
96
			case STLegendPos.INT_TR: return LegendPosition.TOP_RIGHT;
97
			default:
98
				throw new IllegalArgumentException();
99
		}
100
	}
101
}
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFScatterChartData.java (+147 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.xssf.usermodel.charts;
19
20
import java.util.List;
21
import java.util.ArrayList;
22
23
import org.apache.poi.ss.usermodel.Chart;
24
import org.apache.poi.ss.usermodel.Sheet;
25
import org.apache.poi.ss.util.CellRangeAddress;
26
import org.apache.poi.ss.usermodel.charts.ScatterChartData;
27
import org.apache.poi.ss.usermodel.charts.ScatterChartSerie;
28
import org.apache.poi.ss.usermodel.charts.ChartDataFactory;
29
import org.apache.poi.ss.usermodel.charts.ChartAxis;
30
31
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
32
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterChart;
33
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterStyle;
34
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterSer;
35
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource;
36
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumRef;
37
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource;
38
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
39
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
40
import org.openxmlformats.schemas.drawingml.x2006.chart.STScatterStyle;
41
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrosses;
42
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrossBetween;
43
import org.openxmlformats.schemas.drawingml.x2006.chart.STOrientation;
44
import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
45
import org.openxmlformats.schemas.drawingml.x2006.chart.STAxPos;
46
47
import org.apache.poi.xssf.usermodel.XSSFChart;
48
49
/**
50
 * Represents DrawingML scatter chart.
51
 *
52
 * @author Roman Kashitsyn
53
 */
54
public class XSSFScatterChartData implements ScatterChartData {
55
56
	/**
57
	 * List of all data series.
58
	 */
59
	private List<Serie> series;
60
61
	public XSSFScatterChartData() {
62
		series = new ArrayList<Serie>();
63
	}
64
65
	public static class Serie implements ScatterChartSerie {
66
		private int id;
67
		private int order;
68
		private boolean useCache;
69
		private Sheet xSheet;
70
		private Sheet ySheet;
71
		private CellRangeAddress xAddress;
72
		private CellRangeAddress yAddress;
73
74
		public Serie(int id, int order) {
75
			super();
76
			this.id = id;
77
			this.order = order;
78
			this.useCache = false;
79
		}
80
81
		public void setXValues(Sheet sheet, CellRangeAddress address) {
82
			this.xSheet = sheet;
83
			this.xAddress = address;
84
		}
85
86
		public void setYValues(Sheet sheet, CellRangeAddress address) {
87
			this.ySheet = sheet;
88
			this.yAddress = address;
89
		}
90
91
		/**
92
		 * @param useCache if true, cached results will be added on plot
93
		 */
94
		public void setUseCache(boolean useCache) {
95
			this.useCache = useCache;
96
		}
97
98
		protected void addToChart(CTScatterChart ctScatterChart) {
99
			CTScatterSer scatterSer = ctScatterChart.addNewSer();
100
			scatterSer.addNewIdx().setVal(this.id);
101
			scatterSer.addNewOrder().setVal(this.order);
102
103
			CTAxDataSource xVal = scatterSer.addNewXVal();
104
			CTNumRef numRef = xVal.addNewNumRef();
105
			numRef.setF(xAddress.formatAsString(xSheet.getSheetName(), true));
106
107
			CTNumDataSource yVal = scatterSer.addNewYVal();
108
			numRef = yVal.addNewNumRef();
109
			numRef.setF(yAddress.formatAsString(ySheet.getSheetName(), true));
110
		}
111
	}
112
113
	public XSSFScatterChartData.Serie addSerie() {
114
		int numOfSeries = series.size();
115
		Serie newSerie = new Serie(numOfSeries, numOfSeries);
116
		series.add(newSerie);
117
		return newSerie;
118
	}
119
120
	public void fillChart(Chart chart, ChartAxis... axis) {
121
		if (!(chart instanceof XSSFChart)) {
122
			throw new IllegalArgumentException("Chart must be instance of XSSFChart");
123
		}
124
125
		XSSFChart xssfChart = (XSSFChart) chart;
126
		CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
127
		CTScatterChart scatterChart = plotArea.addNewScatterChart();
128
		addStyle(scatterChart);
129
130
		for (Serie s : series) {
131
			s.addToChart(scatterChart);
132
		}
133
134
		for (ChartAxis ax : axis) {
135
			scatterChart.addNewAxId().setVal(ax.getId());
136
		}
137
	}
138
139
	public List<? extends Serie> getSeries() {
140
		return series;
141
	}
142
143
	private void addStyle(CTScatterChart ctScatterChart) {
144
		CTScatterStyle scatterStyle = ctScatterChart.addNewScatterStyle();
145
		scatterStyle.setVal(STScatterStyle.LINE_MARKER);
146
	}
147
}
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFValueAxis.java (+123 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.xssf.usermodel.charts;
19
20
import org.apache.poi.ss.usermodel.charts.ChartAxis;
21
import org.apache.poi.ss.usermodel.charts.ValueAxis;
22
import org.apache.poi.ss.usermodel.charts.AxisPosition;
23
import org.apache.poi.ss.usermodel.charts.AxisOrientation;
24
import org.apache.poi.ss.usermodel.charts.AxisCrossBetween;
25
import org.apache.poi.ss.usermodel.charts.AxisCrosses;
26
27
import org.apache.poi.xssf.usermodel.XSSFChart;
28
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
29
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
30
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
31
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
32
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
33
import org.openxmlformats.schemas.drawingml.x2006.chart.STAxPos;
34
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrossBetween;
35
import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
36
37
/**
38
 * Value axis type.
39
 *
40
 * @author Roman Kashitsyn
41
 */
42
public class XSSFValueAxis extends XSSFChartAxis implements ValueAxis {
43
44
	private CTValAx ctValAx;
45
46
	public XSSFValueAxis(XSSFChart chart, long id, AxisPosition pos) {
47
		super(chart);
48
		createAxis(id, pos);
49
	}
50
51
	public long getId() {
52
		return ctValAx.getAxId().getVal();
53
	}
54
55
	public void setCrossBetween(AxisCrossBetween crossBetween) {
56
		ctValAx.getCrossBetween().setVal(fromCrossBetween(crossBetween));
57
	}
58
59
	public AxisCrossBetween getCrossBetween() {
60
		return toCrossBetween(ctValAx.getCrossBetween().getVal());
61
	}
62
63
	@Override
64
	protected CTAxPos getCTAxPos() {
65
		return ctValAx.getAxPos();
66
	}
67
68
	@Override
69
	protected CTNumFmt getCTNumFmt() {
70
		if (ctValAx.isSetNumFmt()) {
71
			return ctValAx.getNumFmt();
72
		}
73
		return ctValAx.addNewNumFmt();
74
	}
75
76
	@Override
77
	protected CTScaling getCTScaling() {
78
		return ctValAx.getScaling();
79
	}
80
81
	@Override
82
	protected CTCrosses getCTCrosses() {
83
		return ctValAx.getCrosses();
84
	}
85
86
	public void crossAxis(ChartAxis axis) {
87
		ctValAx.getCrossAx().setVal(axis.getId());
88
	}
89
90
	private void createAxis(long id, AxisPosition pos) {
91
		ctValAx = chart.getCTChart().getPlotArea().addNewValAx();
92
		ctValAx.addNewAxId().setVal(id);
93
		ctValAx.addNewAxPos();
94
		ctValAx.addNewScaling();
95
		ctValAx.addNewCrossBetween();
96
		ctValAx.addNewCrosses();
97
		ctValAx.addNewCrossAx();
98
		ctValAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
99
100
		setPosition(pos);
101
		setOrientation(AxisOrientation.MIN_MAX);
102
		setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
103
		setCrosses(AxisCrosses.AUTO_ZERO);
104
	}
105
106
	private static STCrossBetween.Enum fromCrossBetween(AxisCrossBetween crossBetween) {
107
		switch (crossBetween) {
108
			case BETWEEN: return STCrossBetween.BETWEEN;
109
			case MIDPOINT_CATEGORY: return STCrossBetween.MID_CAT;
110
			default:
111
				throw new IllegalArgumentException();
112
		}
113
	}
114
115
	private static AxisCrossBetween toCrossBetween(STCrossBetween.Enum ctCrossBetween) {
116
		switch (ctCrossBetween.intValue()) {
117
			case STCrossBetween.INT_BETWEEN: return AxisCrossBetween.BETWEEN;
118
			case STCrossBetween.INT_MID_CAT: return AxisCrossBetween.MIDPOINT_CATEGORY;
119
			default:
120
				throw new IllegalArgumentException();
121
		}
122
	}
123
}
(-)a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFChart.java (+16 lines)
Lines 55-58 public final class TestXSSFChart extends TestCase { Link Here
55
       chart = s3.createDrawingPatriarch().getCharts().get(0);
55
       chart = s3.createDrawingPatriarch().getCharts().get(0);
56
       assertEquals("Sheet 3 Chart with Title", chart.getTitle().getString());
56
       assertEquals("Sheet 3 Chart with Title", chart.getTitle().getString());
57
    }
57
    }
58
59
	public void testAddChartsToNewWorkbook() throws Exception {
60
		XSSFWorkbook wb = new XSSFWorkbook();
61
		XSSFSheet s1 = wb.createSheet();
62
		XSSFDrawing d1 = s1.createDrawingPatriarch();
63
		XSSFClientAnchor a1 = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30);
64
		XSSFChart c1 = d1.createChart(a1);
65
66
		assertEquals(1, d1.getCharts().size());
67
		assertNotNull(c1.getGraphicFrame());
68
		assertNotNull(c1.getOrCreateLegend());
69
70
		XSSFClientAnchor a2 = new XSSFClientAnchor(0, 0, 0, 0, 1, 11, 10, 60);
71
		XSSFChart c2 = d1.createChart(a2);
72
		assertEquals(2, d1.getCharts().size());
73
	}
58
}
74
}
(-)a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java (+80 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.xssf.usermodel.charts;
19
20
import junit.framework.TestCase;
21
22
import org.apache.poi.ss.usermodel.charts.*;
23
import org.apache.poi.xssf.usermodel.*;
24
import org.apache.poi.xssf.usermodel.charts.*;
25
26
public final class TestXSSFChartAxis extends TestCase {
27
28
	private static final double EPSILON = 1E-7;
29
	private XSSFChartAxis axis;
30
31
	public TestXSSFChartAxis() {
32
		super();
33
		XSSFWorkbook wb = new XSSFWorkbook();
34
		XSSFSheet sheet = wb.createSheet();
35
		XSSFDrawing drawing = sheet.createDrawingPatriarch();
36
		XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
37
		XSSFChart chart = drawing.createChart(anchor);
38
		axis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
39
	}
40
 
41
	public void testLogBaseIllegalArgument() throws Exception {
42
		IllegalArgumentException iae = null;
43
		try {
44
			axis.setLogBase(0.0);
45
		} catch (IllegalArgumentException e) {
46
			iae = e;
47
		}
48
		assertNotNull(iae);
49
50
		iae = null;
51
		try {
52
			axis.setLogBase(30000.0);
53
		} catch (IllegalArgumentException e) {
54
			iae = e;
55
		}
56
		assertNotNull(iae);
57
	}
58
59
	public void testLogBaseLegalArgument() throws Exception {
60
		axis.setLogBase(Math.E);
61
		assertTrue(Math.abs(axis.getLogBase() - Math.E) < EPSILON);
62
	}
63
64
	public void testNumberFormat() throws Exception {
65
		final String numberFormat = "General";
66
		axis.setNumberFormat(numberFormat);
67
		assertEquals(numberFormat, axis.getNumberFormat());
68
	}
69
70
	public void testMaxAndMinAccessMethods() {
71
		final double newValue = 10.0;
72
73
		axis.setMinimum(newValue);
74
		assertTrue(Math.abs(axis.getMinimum() - newValue) < EPSILON);
75
76
		axis.setMaximum(newValue);
77
		assertTrue(Math.abs(axis.getMaximum() - newValue) < EPSILON);
78
	}
79
80
}
(-)a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java (+40 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.xssf.usermodel.charts;
19
20
import junit.framework.TestCase;
21
22
import org.apache.poi.ss.usermodel.*;
23
import org.apache.poi.ss.usermodel.charts.ChartLegend;
24
import org.apache.poi.ss.usermodel.charts.LegendPosition;
25
import org.apache.poi.xssf.usermodel.*;
26
27
public final class TestXSSFChartLegend extends TestCase {
28
 
29
	public void testLegendPositionAccessMethods() throws Exception {
30
		Workbook wb = new XSSFWorkbook();
31
		Sheet sheet = wb.createSheet();
32
		Drawing drawing = sheet.createDrawingPatriarch();
33
		ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
34
		Chart chart = drawing.createChart(anchor);
35
		ChartLegend legend = chart.getOrCreateLegend();
36
37
		legend.setPosition(LegendPosition.TOP_RIGHT);
38
		assertEquals(LegendPosition.TOP_RIGHT, legend.getPosition());
39
	}
40
}
(-)a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFScatterChartData.java (+51 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.xssf.usermodel.charts;
19
20
import junit.framework.TestCase;
21
22
import org.apache.poi.xssf.usermodel.*;
23
import org.apache.poi.ss.util.CellRangeAddress;
24
import org.apache.poi.ss.usermodel.charts.*;
25
import org.apache.poi.xssf.usermodel.charts.XSSFChartDataFactory;
26
27
public final class TestXSSFScatterChartData  extends TestCase {
28
 
29
	public void testOneSeriePlot() throws Exception {
30
		XSSFWorkbook wb = new XSSFWorkbook();
31
		XSSFSheet sheet = wb.createSheet();
32
		XSSFDrawing drawing = sheet.createDrawingPatriarch();
33
		XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
34
		XSSFChart chart = drawing.createChart(anchor);
35
36
		ChartAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
37
		ChartAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
38
39
		ScatterChartData scatterChartData =
40
				XSSFChartDataFactory.getInstance().createScatterChartData();
41
42
		ScatterChartSerie serie = scatterChartData.addSerie();
43
		serie.setXValues(sheet, new CellRangeAddress(0,0,1,10));
44
		serie.setYValues(sheet, new CellRangeAddress(1,1,1,10));
45
46
		assertEquals(scatterChartData.getSeries().size(), 1);
47
48
		chart.plot(scatterChartData, bottomAxis, leftAxis);
49
	}
50
51
}
(-)a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFValueAxis.java (+44 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.xssf.usermodel.charts;
19
20
import junit.framework.TestCase;
21
22
import org.apache.poi.ss.usermodel.charts.*;
23
import org.apache.poi.xssf.usermodel.*;
24
import org.apache.poi.xssf.usermodel.charts.*;
25
26
public final class TestXSSFValueAxis extends TestCase {
27
 
28
	public void testAccessMethods() throws Exception {
29
		XSSFWorkbook wb = new XSSFWorkbook();
30
		XSSFSheet sheet = wb.createSheet();
31
		XSSFDrawing drawing = sheet.createDrawingPatriarch();
32
		XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
33
		XSSFChart chart = drawing.createChart(anchor);
34
		XSSFValueAxis axis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
35
36
		axis.setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
37
		assertEquals(axis.getCrossBetween(), AxisCrossBetween.MIDPOINT_CATEGORY);
38
39
		axis.setCrosses(AxisCrosses.AUTO_ZERO);
40
		assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO);
41
42
		assertEquals(chart.getAxis().size(), 1);
43
	}
44
}

Return to bug 51196