001: package org.krysalis.jcharts.chartData;
002:
003: import java.awt.Paint;
004:
005: import org.krysalis.jcharts.chartData.interfaces.IRadarChartDataSet;
006: import org.krysalis.jcharts.properties.RadarChartProperties;
007: import org.krysalis.jcharts.test.HTMLGenerator;
008:
009: /**
010: * The chart dataset of a radar chart
011: *
012: * @author Rami Hansenne
013: */
014: final public class RadarChartDataSet extends DataSet implements
015: IRadarChartDataSet {
016: private String chartTitle;
017: private String[] axisLabels;
018:
019: /******************************************************************************************
020: * Constructor
021: *
022: * @param chartTitle if the title is NULL, no title will be drawn
023: * @param data the data sets to be displayed in the chart.
024: * @param legendLabels if this is: NULL there will be no Legend. Otherwise, there must be an
025: * one to one mapping of labels to data sets.
026: * @param paints paints to use for the data sets. There must be an one to one mapping of
027: * labels to data sets.
028: * @param axisLabels
029: * @param chartTypeProperties properties Object specific to the type of chart you are rendering.
030: * @throws ChartDataException if data is not in correct form.
031: *******************************************************************************************/
032: public RadarChartDataSet(String chartTitle, double[][] data,
033: String[] legendLabels, Paint[] paints, String[] axisLabels,
034: RadarChartProperties chartTypeProperties)
035: throws ChartDataException {
036: super (data, legendLabels, paints, chartTypeProperties);
037: validateData(data, legendLabels, axisLabels, paints);
038: this .chartTitle = chartTitle;
039: this .axisLabels = axisLabels;
040: }
041:
042: /*******************************************************************************************
043: * Perform some limited validation of the structure of the passed data. This is useful for
044: * development.
045: *
046: * @param data
047: * @param legendLabels
048: * @param axisLabels
049: * @param paints
050: * @throws ChartDataException
051: *******************************************************************************************/
052: private void validateData(double[][] data, String[] legendLabels,
053: String[] axisLabels, Paint[] paints)
054: throws ChartDataException {
055: if (legendLabels != null
056: && (data.length != legendLabels.length)) {
057: throw new ChartDataException(
058: "There is not an one to one mapping of 'legend labels' to 'data items'.");
059: }
060:
061: if (data.length != paints.length) {
062: throw new ChartDataException(
063: "There is not an one to one mapping of 'Paint' Implementations to 'data items'.");
064: }
065:
066: for (int i = 1; i < data.length; i++)
067: if (data[i].length != data[0].length)
068: throw new ChartDataException(
069: "All data items should contain an equal number of values.");
070:
071: if (data.length > 0 && axisLabels.length != data[0].length)
072: throw new ChartDataException(
073: "There is not a one to one mapping of axis labels to values per 'data item'.");
074:
075: }
076:
077: /******************************************************************************************
078: * Returns the chart title.
079: *
080: * @return String the chart title. If this returns NULL, no title will be displayed.
081: ******************************************************************************************/
082: public String getChartTitle() {
083: return this .chartTitle;
084: }
085:
086: /******************************************************************************************
087: * Returns the value in the data set at the specified position.
088: *
089: * @param dataset
090: * @param index
091: * @return double
092: * @throws ArrayIndexOutOfBoundsException
093: *******************************************************************************************/
094: public final double getValue(int dataset, int index)
095: throws ArrayIndexOutOfBoundsException {
096: return super .data[dataset][index];
097: }
098:
099: /******************************************************************************************
100: * Returns the number of data sets
101: *
102: * @return int
103: ******************************************************************************************/
104: public final int getNumberOfDataSets() {
105: return this .data.length;
106: }
107:
108: /******************************************************************************************
109: * Returns the number of values per data set
110: *
111: * @return int
112: ******************************************************************************************/
113: public final int getDataSetSize() {
114: if (data.length == 0)
115: return 0;
116: else
117: return data[0].length;
118: }
119:
120: /******************************************************************************************
121: * Returns the x-axis label corresponding to the passed index
122: *
123: * @param index
124: * @return String
125: *******************************************************************************************/
126: public String getAxisLabel(int index) {
127: return this .axisLabels[index];
128: }
129:
130: /******************************************************************************************
131: * Returns the number of labels on the x-axis
132: *
133: * @return int
134: ******************************************************************************************/
135: public int getNumberOfAxisLabels() {
136: if (this .axisLabels != null) {
137: return this .axisLabels.length;
138: } else {
139: return 0;
140: }
141: }
142:
143: /*********************************************************************************************
144: * Enables the testing routines to display the contents of this Object.
145: *
146: * @param htmlGenerator
147: **********************************************************************************************/
148: public void toHTML(HTMLGenerator htmlGenerator) {
149: super.toHTML(htmlGenerator);
150: }
151:
152: }
|