|
1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
4
|
|
|
|
5
|
|
|
|
6
|
|
|
|
7
|
|
package org.ejtools.graph.renderer;
|
|
8
|
|
|
|
9
|
|
import java.awt.Color;
|
|
10
|
|
import java.awt.FontMetrics;
|
|
11
|
|
import java.awt.Graphics;
|
|
12
|
|
import java.awt.Insets;
|
|
13
|
|
import java.awt.geom.Rectangle2D;
|
|
14
|
|
import java.text.Format;
|
|
15
|
|
|
|
16
|
|
import org.ejtools.graph.Axis;
|
|
17
|
|
import org.ejtools.graph.GraphRenderer;
|
|
18
|
|
|
|
19
|
|
|
|
20
|
|
|
|
21
|
|
|
|
22
|
|
|
|
23
|
|
|
|
24
|
|
public class HorizontalAxis extends Axis
|
|
25
|
|
{
|
|
26
|
|
|
|
27
|
|
|
|
28
|
|
|
|
29
|
|
|
|
30
|
|
|
|
31
|
|
|
|
32
|
0
|
public HorizontalAxis(Format format, int position)
|
|
33
|
|
{
|
|
34
|
0
|
this.format = format;
|
|
35
|
0
|
this.orientation = HORIZONTAL;
|
|
36
|
0
|
this.position = position;
|
|
37
|
|
}
|
|
38
|
|
|
|
39
|
|
|
|
40
|
|
|
|
41
|
|
|
|
42
|
|
|
|
43
|
|
|
|
44
|
|
|
|
45
|
0
|
public void paintComponent(Graphics graphics)
|
|
46
|
|
{
|
|
47
|
0
|
String display;
|
|
48
|
0
|
double multiplier = 0.0d;
|
|
49
|
|
|
|
50
|
0
|
graphics.setFont(FONT);
|
|
51
|
0
|
FontMetrics metrics = graphics.getFontMetrics();
|
|
52
|
|
|
|
53
|
0
|
Insets insets = this.getInsets();
|
|
54
|
0
|
int x = insets.left;
|
|
55
|
|
|
|
56
|
0
|
double width = (double) this.getWidth() - 1 - insets.left - insets.right;
|
|
57
|
0
|
double height = (double) this.getHeight() - 1 - insets.top - insets.bottom;
|
|
58
|
|
|
|
59
|
0
|
double min = element.getXRange().getMin();
|
|
60
|
0
|
double max = element.getXRange().getMax();
|
|
61
|
|
|
|
62
|
0
|
double scaleX = width / (max - min);
|
|
63
|
0
|
double offsetX = x - scaleX * min;
|
|
64
|
|
|
|
65
|
0
|
if (this.horizontalScaling == GraphRenderer.ALIGN_LEFT)
|
|
66
|
|
{
|
|
67
|
0
|
scaleX = 1.0d;
|
|
68
|
0
|
offsetX = -min;
|
|
69
|
|
}
|
|
70
|
0
|
if (this.horizontalScaling == GraphRenderer.ALIGN_RIGHT)
|
|
71
|
|
{
|
|
72
|
0
|
scaleX = 1.0d * this.horizontalScale;
|
|
73
|
0
|
offsetX = width - max * this.horizontalScale;
|
|
74
|
|
}
|
|
75
|
|
|
|
76
|
0
|
min = (x - offsetX) / scaleX;
|
|
77
|
|
|
|
78
|
0
|
String minText = this.getFormated(min);
|
|
79
|
0
|
Rectangle2D minBounds = metrics.getStringBounds(minText, graphics);
|
|
80
|
0
|
String maxText = this.getFormated(max);
|
|
81
|
0
|
Rectangle2D maxBounds = metrics.getStringBounds(maxText, graphics);
|
|
82
|
|
|
|
83
|
|
|
|
84
|
0
|
double bound = Math.max(minBounds.getWidth() * 4.0d, maxBounds.getWidth() * 4.0d);
|
|
85
|
|
|
|
86
|
|
|
|
87
|
0
|
int ticks = 1;
|
|
88
|
0
|
while ((width / ticks) > bound)
|
|
89
|
|
{
|
|
90
|
0
|
ticks = ticks * 2;
|
|
91
|
|
}
|
|
92
|
|
|
|
93
|
|
|
|
94
|
0
|
graphics.drawLine(0, 0, (int) width, 0);
|
|
95
|
|
|
|
96
|
|
|
|
97
|
0
|
multiplier = width / ticks / 2;
|
|
98
|
0
|
graphics.setColor(Color.black);
|
|
99
|
0
|
for (int i = 0; i <= (2 * ticks); i++)
|
|
100
|
|
{
|
|
101
|
0
|
int j = (int) (i * multiplier);
|
|
102
|
0
|
graphics.drawLine(j, 0, j, FONT.getSize() / 2);
|
|
103
|
|
}
|
|
104
|
|
|
|
105
|
|
|
|
106
|
0
|
multiplier = width / ticks;
|
|
107
|
|
|
|
108
|
|
|
|
109
|
0
|
graphics.drawLine(0, 0, 0, FONT.getSize() - metrics.getDescent());
|
|
110
|
0
|
graphics.drawString(minText, 0, (int) (height - metrics.getDescent()));
|
|
111
|
|
|
|
112
|
|
|
|
113
|
0
|
for (int i = 1; i < ticks; i++)
|
|
114
|
|
{
|
|
115
|
0
|
int j = (int) (i * multiplier);
|
|
116
|
0
|
graphics.drawLine(j, 0, j, FONT.getSize() - metrics.getDescent());
|
|
117
|
|
|
|
118
|
0
|
display = this.getFormated(min + i * (max - min) / ticks);
|
|
119
|
0
|
Rectangle2D middleBounds = metrics.getStringBounds(display, graphics);
|
|
120
|
|
|
|
121
|
0
|
j = j - (int) (middleBounds.getWidth() / 2);
|
|
122
|
|
|
|
123
|
0
|
graphics.drawString(display, j, (int) (height - metrics.getDescent()));
|
|
124
|
|
}
|
|
125
|
|
|
|
126
|
|
|
|
127
|
0
|
graphics.drawLine((int) width, 0, (int) width, FONT.getSize() - metrics.getDescent());
|
|
128
|
0
|
graphics.drawString(maxText, (int) (width - maxBounds.getWidth()), (int) (height - metrics.getDescent()));
|
|
129
|
|
}
|
|
130
|
|
}
|
|
131
|
|
|