1 23 24 package de.progra.charting.model; 25 26 import de.progra.charting.CoordSystem; 27 import de.progra.charting.ChartUtilities; 28 import java.util.TreeSet ; 29 import java.util.Set ; 30 import java.util.HashMap ; 31 32 40 public class ObjectChartDataModel extends AbstractChartDataModel { 41 42 43 protected Object [] columns; 44 45 46 protected DataSet[] data; 47 48 49 protected HashMap valuesbyaxis = new HashMap (); 50 51 52 protected ChartDataModelConstraints constraints1, constraints2; 53 54 57 public ObjectChartDataModel() { 58 data = new DefaultDataSet[0]; 59 columns = new Object [0]; 60 61 TreeSet set1 = new TreeSet (); 62 valuesbyaxis.put(new Integer (CoordSystem.FIRST_YAXIS), set1); 63 64 TreeSet set2 = new TreeSet (); 65 valuesbyaxis.put(new Integer (CoordSystem.SECOND_YAXIS), set2); 66 67 constraints1 = new DefaultChartDataModelConstraints(this, CoordSystem.FIRST_YAXIS, false); 68 constraints2 = new DefaultChartDataModelConstraints(this, CoordSystem.SECOND_YAXIS, false); 69 } 70 71 79 public ObjectChartDataModel(Number [][] data, Object [] columns, String rows[]) { 80 this(); 81 82 this.columns = columns; 83 84 this.data = new DefaultDataSet[data.length]; 85 86 TreeSet set = 87 (TreeSet )valuesbyaxis.get(new Integer (CoordSystem.FIRST_YAXIS)); 88 89 ChartUtilities.addDataToSet(set, data); 90 91 for(int i = 0; i < data.length; i++) { 92 this.data[i] = new DefaultDataSet(data[i], 93 columns, 94 CoordSystem.FIRST_YAXIS, 95 rows[i]); 96 } 97 } 98 99 107 public ObjectChartDataModel(int[][] data, Object [] columns, String [] rows) { 108 this(); 109 110 Number [][] numdata = ChartUtilities.transformArray(data); 111 112 this.columns = columns; 113 114 this.data = new DefaultDataSet[data.length]; 115 116 TreeSet set = 117 (TreeSet )valuesbyaxis.get(new Integer (CoordSystem.FIRST_YAXIS)); 118 119 ChartUtilities.addDataToSet(set, numdata); 120 121 for(int i = 0; i < data.length; i++) { 122 this.data[i] = new DefaultDataSet(numdata[i], 123 columns, 124 CoordSystem.FIRST_YAXIS, 125 rows[i]); 126 } 127 } 128 129 130 138 public ObjectChartDataModel(double[][] data, Object [] columns, String [] rows) { 139 this(); 140 141 Number [][] numdata = ChartUtilities.transformArray(data); 142 143 this.columns = columns; 144 145 this.data = new DefaultDataSet[data.length]; 146 147 TreeSet set = 148 (TreeSet )valuesbyaxis.get(new Integer (CoordSystem.FIRST_YAXIS)); 149 150 ChartUtilities.addDataToSet(set, numdata); 151 152 for(int i = 0; i < data.length; i++) { 153 this.data[i] = new DefaultDataSet(numdata[i], 154 columns, 155 CoordSystem.FIRST_YAXIS, 156 rows[i]); 157 } 158 } 159 160 171 public ObjectChartDataModel(DataSet[] ds, Object [] columns) { 172 this(); 173 data = ds; 174 this.columns = columns; 175 176 TreeSet set; 177 178 HashMap map = new HashMap (); 179 180 for(int i = 0; i < ds.length; i++) { 181 map.clear(); 182 Number [] numdata = new Number [columns.length]; 183 184 for(int j = 0; j < columns.length; j++) 185 map.put(columns[j], new Double (Double.NaN)); 186 187 set = (TreeSet )valuesbyaxis.get(new Integer (ds[i].getYAxis())); 188 189 for(int j = 0; j < ds[i].getDataSetLength(); j++) { 190 map.put(ds[i].getColumnValueAt(j), ds[i].getValueAt(j)); 191 set.add(ds[i].getValueAt(j)); 192 } 193 194 for(int j = 0; j < columns.length; j++) { 195 numdata[j] = (Number )map.get(columns[j]); 196 } 197 198 data[i] = new DefaultDataSet(numdata, 199 columns, 200 CoordSystem.FIRST_YAXIS, 201 ds[i].getTitle()); 202 } 203 } 204 205 209 public int getDataSetLength(int set) { 210 return data[set].getDataSetLength(); 211 } 212 213 216 public int getDataSetNumber() { 217 return data.length; 218 } 219 220 221 226 public String getDataSetName(int set) { 227 return data[set].getTitle(); 228 } 229 230 234 public int getAxisBinding(int set) { 235 return data[set].getYAxis(); 236 } 237 238 243 public Number getValueAt(int set, int index) { 244 return (Number )data[set].getValueAt(index); 245 } 246 247 254 public ChartDataModelConstraints getChartDataModelConstraints(final int axis) { 255 if(axis == CoordSystem.FIRST_YAXIS) 256 return constraints1; 257 else 258 return constraints2; 259 } 260 261 267 public void setChartDataModelConstraints(int axis, ChartDataModelConstraints constraints) { 268 if(axis == CoordSystem.FIRST_YAXIS) 269 constraints1 = constraints; 270 else 271 constraints2 = constraints; 272 } 273 274 278 public Object getColumnValueAt(int col) { 279 if(col < columns.length) 280 return columns[col]; 281 else 282 return null; 283 } 284 285 289 public Object getColumnValueAt(int set, int col) { 290 return getColumnValueAt(col); 291 } 292 293 296 protected TreeSet getOrderedValues(int axis) { 297 return (TreeSet )valuesbyaxis.get(new Integer (axis)); 298 } 299 300 303 protected double getFirstColumnValue() { 304 return 0.0; 305 } 306 307 310 protected double getLastColumnValue() { 311 return Math.max((double)columns.length, 1.0); 312 } 313 } 314 | Popular Tags |