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

(-)src/java/org/apache/poi/ss/usermodel/charts/ChartSerie.java (+57 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.util.CellReference;
21
22
/**
23
 * Basic settings for all chart series.
24
 *
25
 * @author Martin Andersson
26
 */
27
public interface ChartSerie {
28
29
	/**
30
	 * Sets the title of the series as a string literal.
31
	 *
32
	 * @param title
33
	 */
34
	void setTitle(String title);
35
36
	/**
37
	 * Sets the title of the series as a cell reference.
38
	 *
39
	 * @param titleReference
40
	 */
41
	void setTitle(CellReference titleReference);
42
43
	/**
44
	 * @return title as string literal.
45
	 */
46
	String getTitleString();
47
48
	/**
49
	 * @return title as cell reference.
50
	 */
51
	CellReference getTitleCellReference();
52
53
	/**
54
	 * @return title type.
55
	 */
56
	TitleType getTitleType();
57
}
(-)src/java/org/apache/poi/ss/usermodel/charts/LineChartSerie.java (-1 / +1 lines)
Lines 26-32 import org.apache.poi.util.Beta; Link Here
26
 * @author Martin Andersson
26
 * @author Martin Andersson
27
 */
27
 */
28
@Beta
28
@Beta
29
public interface LineChartSerie {
29
public interface LineChartSerie extends ChartSerie {
30
30
31
	/**
31
	/**
32
	 * @return data source used for category axis data.
32
	 * @return data source used for category axis data.
(-)src/java/org/apache/poi/ss/usermodel/charts/ScatterChartSerie.java (-1 / +1 lines)
Lines 25-31 import org.apache.poi.util.Beta; Link Here
25
 * @author Roman Kashitsyn
25
 * @author Roman Kashitsyn
26
 */
26
 */
27
@Beta
27
@Beta
28
public interface ScatterChartSerie {
28
public interface ScatterChartSerie extends ChartSerie {
29
29
30
    /**
30
    /**
31
     * @return data source used for X axis values
31
     * @return data source used for X axis values
(-)src/java/org/apache/poi/ss/usermodel/charts/TitleType.java (+28 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
 * Title types for charts.
22
 *
23
 * @author Martin Andersson
24
 */
25
public enum TitleType {
26
	STRING,
27
	CELL_REFERENCE;
28
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/charts/AbstractXSSFChartSerie.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 org.apache.poi.ss.usermodel.charts.ChartSerie;
21
import org.apache.poi.ss.usermodel.charts.TitleType;
22
import org.apache.poi.ss.util.CellReference;
23
import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx;
24
25
/**
26
 *
27
 * @author Martin Andersson
28
 */
29
public abstract class AbstractXSSFChartSerie implements ChartSerie {
30
31
	private String titleValue;
32
	private CellReference titleRef;
33
	private TitleType titleType;
34
35
	public void setTitle(CellReference titleReference) {
36
		titleType = TitleType.CELL_REFERENCE;
37
		titleRef = titleReference;
38
	}
39
40
	public void setTitle(String title) {
41
		titleType = TitleType.STRING;
42
		titleValue = title;
43
	}
44
45
	public CellReference getTitleCellReference() {
46
		if (TitleType.CELL_REFERENCE.equals(titleType)) {
47
			return titleRef;
48
		}
49
		throw new IllegalStateException("Title type is not CellReference.");
50
	}
51
52
	public String getTitleString() {
53
		if (TitleType.STRING.equals(titleType)) {
54
			return titleValue;
55
		}
56
		throw new IllegalStateException("Title type is not String.");
57
	}
58
59
	public TitleType getTitleType() {
60
		return titleType;
61
	}
62
63
	protected boolean isTitleSet() {
64
		return titleType != null;
65
	}
66
67
	protected CTSerTx getCTSerTx() {
68
		CTSerTx tx = CTSerTx.Factory.newInstance();
69
		switch (titleType) {
70
			case CELL_REFERENCE:
71
				tx.addNewStrRef().setF(titleRef.formatAsString());
72
				return tx;
73
			case STRING:
74
				tx.setV(titleValue);
75
				return tx;
76
			default:
77
				throw new IllegalStateException("Unkown title type: " + titleType);
78
		}
79
	}
80
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFLineChartData.java (-1 / +5 lines)
Lines 50-56 public class XSSFLineChartData implements LineChartData { Link Here
50
		series = new ArrayList<Serie>();
50
		series = new ArrayList<Serie>();
51
	}
51
	}
52
52
53
	static class Serie implements LineChartSerie {
53
	static class Serie extends AbstractXSSFChartSerie implements LineChartSerie {
54
        private int id;
54
        private int id;
55
        private int order;
55
        private int order;
56
        private ChartDataSource<?> categories;
56
        private ChartDataSource<?> categories;
Lines 85-90 public class XSSFLineChartData implements LineChartData { Link Here
85
			XSSFChartUtil.buildAxDataSource(catDS, categories);
85
			XSSFChartUtil.buildAxDataSource(catDS, categories);
86
			CTNumDataSource valueDS = ctLineSer.addNewVal();
86
			CTNumDataSource valueDS = ctLineSer.addNewVal();
87
			XSSFChartUtil.buildNumDataSource(valueDS, values);
87
			XSSFChartUtil.buildNumDataSource(valueDS, values);
88
89
			if (isTitleSet()) {
90
				ctLineSer.setTx(getCTSerTx());
91
			}
88
		}
92
		}
89
	}
93
	}
90
94
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFScatterChartData.java (-1 / +5 lines)
Lines 50-56 public class XSSFScatterChartData implements ScatterChartData { Link Here
50
    /**
50
    /**
51
     * Package private ScatterChartSerie implementation.
51
     * Package private ScatterChartSerie implementation.
52
     */
52
     */
53
    static class Serie implements ScatterChartSerie {
53
    static class Serie extends AbstractXSSFChartSerie implements ScatterChartSerie {
54
        private int id;
54
        private int id;
55
        private int order;
55
        private int order;
56
        private ChartDataSource<?> xs;
56
        private ChartDataSource<?> xs;
Lines 92-97 public class XSSFScatterChartData implements ScatterChartData { Link Here
92
92
93
            CTNumDataSource yVal = scatterSer.addNewYVal();
93
            CTNumDataSource yVal = scatterSer.addNewYVal();
94
            XSSFChartUtil.buildNumDataSource(yVal, ys);
94
            XSSFChartUtil.buildNumDataSource(yVal, ys);
95
96
			if (isTitleSet()) {
97
				scatterSer.setTx(getCTSerTx());
98
			}
95
        }
99
        }
96
    }
100
    }
97
101
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestAbstractXSSFChartSerie.java (+49 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.TitleType;
23
import org.apache.poi.ss.util.CellReference;
24
25
/**
26
 *
27
 * @author Martin Andersson
28
 */
29
public class TestAbstractXSSFChartSerie extends TestCase {
30
31
	public void testTitleAccessorMethods() {
32
		AbstractXSSFChartSerie serie = new AbstractXSSFChartSerie() {};
33
34
		assertFalse(serie.isTitleSet());
35
36
		serie.setTitle("title");
37
		assertTrue(serie.isTitleSet());
38
		assertNotNull(serie.getCTSerTx());
39
		assertEquals(TitleType.STRING, serie.getTitleType());
40
		assertEquals("title", serie.getTitleString());
41
42
		CellReference cellRef = new CellReference("Sheet1!A1");
43
		serie.setTitle(cellRef);
44
		assertTrue(serie.isTitleSet());
45
		assertNotNull(serie.getCTSerTx());
46
		assertEquals(TitleType.CELL_REFERENCE, serie.getTitleType());
47
		assertEquals(cellRef, serie.getTitleCellReference());
48
	}
49
}

Return to bug 55768