1 22 package info.monitorenter.gui.chart.labelformatters; 23 24 import info.monitorenter.gui.chart.IAxis; 25 import info.monitorenter.gui.chart.ILabelFormatter; 26 import info.monitorenter.util.Range; 27 import info.monitorenter.util.units.AUnit; 28 import info.monitorenter.util.units.UnitUnchanged; 29 30 42 public abstract class ALabelFormatter implements ILabelFormatter { 43 44 48 public static final AUnit UNIT_UNCHANGED = new UnitUnchanged(); 49 50 51 private IAxis m_axis; 52 53 57 protected ALabelFormatter() { 58 } 60 61 67 public IAxis getAxis() { 68 return this.m_axis; 69 } 70 71 79 public int getMaxAmountChars() { 80 int fractionDigits = 0; 82 Range range = this.m_axis.getRange(); 83 double dRange = range.getExtent(); 84 if (dRange < 1) { 85 if (dRange == 0) { 86 fractionDigits = 1; 87 } else { 88 while (dRange < 1) { 90 dRange *= 10; 91 fractionDigits++; 92 } 93 } 94 } else { 95 if (dRange == 0) { 96 dRange = 1; 97 } 98 if (dRange < 10) { 99 fractionDigits = 2; 100 } else if (dRange < 100) { 101 fractionDigits = 1; 102 } else { 103 fractionDigits = 0; 104 } 105 } 106 107 int integerDigits = 0; 109 double max = range.getMax(); 110 double min = Math.abs(range.getMin()); 111 if (max == 0 && min == 0) { 112 integerDigits = 1; 113 } else if (max < min) { 114 while (min > 1) { 115 min /= 10; 116 integerDigits++; 117 } 118 } else { 119 while (max > 1) { 120 max /= 10; 121 integerDigits++; 122 } 123 } 124 125 return 1 + integerDigits + 1 + fractionDigits; 127 } 128 129 137 public AUnit getUnit() { 138 139 return ALabelFormatter.UNIT_UNCHANGED; 140 } 141 142 148 public void initPaintIteration() { 149 } 151 152 162 public void setAxis(final IAxis axis) { 163 this.m_axis = axis; 164 } 165 166 } 167 | Popular Tags |