1 23 24 package de.progra.charting.model; 25 26 import de.progra.charting.ChartUtilities; 27 import de.progra.charting.CoordSystem; 28 import java.util.TreeSet ; 29 30 36 public class StackedChartDataModelConstraints implements ChartDataModelConstraints { 37 38 39 protected AbstractChartDataModel model; 40 41 42 protected int axis; 43 44 45 protected boolean allowManualColScale = true; 46 47 48 public StackedChartDataModelConstraints(AbstractChartDataModel model, int axis) { 49 this.model = model; 50 this.axis = axis; 51 } 52 53 59 public StackedChartDataModelConstraints(AbstractChartDataModel model, int axis, boolean allowManualColScale) { 60 this(model, axis); 61 this.allowManualColScale = allowManualColScale; 62 } 63 64 65 public Number getMaximumValue() { 66 int minimumDataSetLength = Integer.MAX_VALUE; 67 double maxvalue = 0.0; 68 double minvalue = 0.0; 69 70 double columnminvalue = Double.MAX_VALUE; 71 double columnmaxvalue = Double.MIN_VALUE; 72 73 for(int i = 0; i < model.getDataSetNumber(); i++) { 74 minimumDataSetLength = Math.min(minimumDataSetLength, model.getDataSetLength(i)); 75 } 76 77 double value = 0.0; 78 79 for(int i = 0; i < minimumDataSetLength; i++) { 80 for(int j = 0; j < model.getDataSetNumber(); j++) { 81 value = model.getValueAt(j, i).doubleValue(); 82 if(value < 0) 83 columnminvalue += value; 84 else 85 columnmaxvalue += value; 86 } 87 minvalue = Math.min(columnminvalue, minvalue); 88 columnminvalue = 0.0; 89 maxvalue = Math.max(columnmaxvalue, maxvalue); 90 columnmaxvalue = 0.0; 91 } 92 93 if(model.getOrderedValues(CoordSystem.FIRST_YAXIS).size() == 0 94 || (maxvalue == 0.0 && minvalue == 0.0)) 95 return new Integer (1); 96 else if(model.isManualScale()) { 97 return new Double (Math.max(model.getManualMaximumValue().doubleValue(), maxvalue)); 98 } 99 else if(model.isAutoScale()) { 100 if(minvalue / maxvalue > 0.95) { 101 return new Double (ChartUtilities.performAutoScale(minvalue/2, 103 2 * maxvalue)[1]); 104 } 105 else { 106 return new Double (ChartUtilities.performAutoScale(minvalue, 108 maxvalue)[1]); 109 } 110 } else 111 return new Double (maxvalue); 112 } 113 114 115 public Number getMinimumValue() { 116 int minimumDataSetLength = Integer.MAX_VALUE; 117 double maxvalue = 0.0; 118 double minvalue = 0.0; 119 double columnmaxvalue = 0.0; 120 double columnminvalue = 0.0; 121 122 for(int i = 0; i < model.getDataSetNumber(); i++) { 123 minimumDataSetLength = Math.min(minimumDataSetLength, model.getDataSetLength(i)); 124 } 125 126 double value = 0.0; 127 128 for(int i = 0; i < minimumDataSetLength; i++) { 129 for(int j = 0; j < model.getDataSetNumber(); j++) { 130 value = model.getValueAt(j, i).doubleValue(); 131 if(value < 0) 132 columnminvalue += value; 133 else 134 columnmaxvalue += value; 135 } 136 minvalue = Math.min(columnminvalue, minvalue); 137 columnminvalue = 0.0; 138 maxvalue = Math.max(columnmaxvalue, maxvalue); 139 columnmaxvalue = 0.0; 140 } 141 142 if(model.getOrderedValues(CoordSystem.FIRST_YAXIS).size() == 0 143 || (maxvalue == 0.0 && minvalue == 0.0)) 144 return new Integer (0); 145 else if(model.isManualScale()) { 146 return new Double (Math.min(model.getManualMinimumValue().doubleValue(), minvalue)); 148 } 149 else if(model.isAutoScale()) { 150 152 if(minvalue / maxvalue > 0.95) { 153 return new Double (ChartUtilities.performAutoScale(minvalue/2, 155 2 * maxvalue)[0]); 156 } 157 else { 158 return new Double (ChartUtilities.performAutoScale(minvalue, 160 maxvalue)[0]); 161 } 162 } else 163 return new Double (minvalue); 164 } 165 166 169 public double getMinimumColumnValue() { 170 if(model.isManualScale() && allowManualColScale) { 171 return model.getManualMinimumColumnValue(); 172 } 173 if(model.isAutoScale()) 174 return ChartUtilities.performAutoScale(model.getFirstColumnValue(), 175 model.getLastColumnValue())[0]; 176 else 177 return model.getFirstColumnValue(); 178 } 179 180 183 public double getMaximumColumnValue() { 184 if(model.isManualScale() && allowManualColScale) { 185 return model.getManualMaximumColumnValue(); 186 } 187 if(model.isAutoScale()) 188 return ChartUtilities.performAutoScale(model.getFirstColumnValue(), 189 model.getLastColumnValue())[1]; 190 else 191 return model.getLastColumnValue(); 192 } 193 } 194 | Popular Tags |