1 39 40 41 package org.krysalis.jcharts.axisChart.axis.scale; 42 43 44 51 public abstract class ScaleCalculator 52 { 53 private double minValue; 54 private double maxValue; 55 private int roundingPowerOfTen; 56 private int numberOfScaleItems; 57 58 protected double increment; 59 60 61 62 66 protected abstract void computeIncrement(); 67 68 69 77 public final void computeScaleValues() 78 { 79 this.computeIncrement(); 80 81 } 84 85 86 public final void setMinValue( double minValue ) 87 { 88 this.minValue = minValue; 89 } 90 91 92 public final double getMinValue() 93 { 94 return this.minValue; 95 } 96 97 98 public final void setMaxValue( double maxValue ) 99 { 100 this.maxValue = maxValue; 101 } 102 103 104 public final double getMaxValue() 105 { 106 return this.maxValue; 107 } 108 109 110 public final double getIncrement() 111 { 112 return increment; 113 } 114 115 116 public int getNumberOfScaleItems() 117 { 118 return numberOfScaleItems; 119 } 120 121 122 public void setNumberOfScaleItems( int numberOfScaleItems ) 123 { 124 this.numberOfScaleItems = numberOfScaleItems; 125 } 126 127 128 133 public final void setRoundingPowerOfTen( int powerOfTen ) 134 { 135 this.roundingPowerOfTen = powerOfTen; 136 } 137 138 139 public final int getRoundingPowerOfTen() 140 { 141 return this.roundingPowerOfTen; 142 } 143 144 145 152 protected double round( double value, double powerOfTen ) 153 { 154 if( this.roundingPowerOfTen > 0 ) 155 { 156 return ( Math.round( value / powerOfTen ) * powerOfTen ); 157 } 158 else if( this.roundingPowerOfTen < 0 ) 159 { 160 return ( Math.round( value * powerOfTen ) / powerOfTen ); 161 } 162 else 163 { 164 return ( Math.round( value ) ); 165 } 166 } 167 168 169 174 protected void roundTheIncrement( double powerOfTen ) 175 { 176 this.increment = this.round( this.increment, powerOfTen ); 177 178 if( this.roundingPowerOfTen > 0 ) 180 { 181 this.increment += powerOfTen; 182 } 183 else 184 { 185 this.increment += ( 1 / powerOfTen ); 186 } 187 } 188 189 190 194 public String toString() 195 { 196 StringBuffer s= new StringBuffer ( 90 ); 197 s.append( "ScaleCalculator-> min= " ); 198 s.append( this.minValue ); 199 s.append( " max= " ); 200 s.append( this.maxValue ); 201 s.append( " increment= " ); 202 s.append( this.increment ); 203 return s.toString(); 204 } 205 } 206 | Popular Tags |