Changeset 10504 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-06-30T20:43:22+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapScaler.java
r10079 r10504 114 114 private final double spacingMeter; 115 115 private final int steps; 116 private final int m ajorStepEvery;116 private final int minorStepsPerMajor; 117 117 118 118 /** … … 127 127 double log10 = Math.log(lineDistance) / Math.log(10); 128 128 double spacingLog10 = Math.pow(10, Math.floor(log10)); 129 int minorStepsPerMajor; 130 double distanceBetweenMinor; 129 131 if (log10 - Math.floor(log10) < .75) { 130 spacingMeter = spacingLog10 / 4; 131 majorStepEvery = 4; 132 // Add 2 ticks for every full unit 133 distanceBetweenMinor = spacingLog10 / 2; 134 minorStepsPerMajor = 2; 132 135 } else { 133 spacingMeter = spacingLog10; 134 majorStepEvery = 5; 136 // Add 10 ticks for every full unit 137 distanceBetweenMinor = spacingLog10; 138 minorStepsPerMajor = 5; 135 139 } 136 steps = (int) Math.floor(lineDistance / spacingMeter); 140 // round down to the last major step. 141 int majorSteps = (int) Math.floor(lineDistance / distanceBetweenMinor / minorStepsPerMajor); 142 if (majorSteps >= 4) { 143 // we have many major steps, do not paint the minor now. 144 this.spacingMeter = distanceBetweenMinor * minorStepsPerMajor; 145 this.minorStepsPerMajor = 1; 146 } else { 147 this.minorStepsPerMajor = minorStepsPerMajor; 148 this.spacingMeter = distanceBetweenMinor; 149 } 150 steps = majorSteps * this.minorStepsPerMajor; 137 151 } 138 152 153 /** 154 * Paint the ticks to the graphics. 155 * @param g The graphics to paint on. 156 */ 139 157 public void paintTicks(Graphics g) { 140 158 double spacingPixel = spacingMeter / (dist100Pixel / 100); … … 142 160 for (int step = 0; step <= steps; step++) { 143 161 int x = (int) (PADDING_LEFT + spacingPixel * step); 144 boolean isMajor = step % m ajorStepEvery== 0;162 boolean isMajor = step % minorStepsPerMajor == 0; 145 163 int paddingY = isMajor ? 0 : 3; 146 164 g.drawLine(x, paddingY, x, 10 - paddingY); 147 165 148 if ( isMajor || (step == steps && textBlockedUntil < 0)) {166 if (step == 0 || step == steps) { 149 167 String text; 150 168 if (step == 0) { … … 155 173 Rectangle2D bound = g.getFontMetrics().getStringBounds(text, g); 156 174 int left = (int) (x - bound.getWidth() / 2); 157 if (textBlockedUntil < left) { 158 g.drawString(text, left, 23); 159 textBlockedUntil = left + bound.getWidth() + 2; 175 if (textBlockedUntil > left) { 176 left = (int) (textBlockedUntil + 5); 160 177 } 178 g.drawString(text, left, 23); 179 textBlockedUntil = left + bound.getWidth() + 2; 161 180 } 162 181 }
Note:
See TracChangeset
for help on using the changeset viewer.