Normand Briere
2018-07-11 1e74123cfed4374b403574b6cd16bd8d4e73bf45
timeflow/vis/timeline/AxisRenderer.java
....@@ -9,80 +9,83 @@
99 import timeflow.vis.Mouseover;
1010 import timeflow.vis.TimeScale;
1111
12
-public class AxisRenderer {
13
-
14
- TimelineVisuals visuals;
15
-
16
- public AxisRenderer(TimelineVisuals visuals)
17
- {
18
- this.visuals=visuals;
19
- }
20
-
21
- public void render(Graphics2D g, Collection<Mouseover> objectLocations)
22
- {
23
- TFModel model=visuals.getModel();
24
- g.setColor(model.getDisplay().getColor("chart.background"));
25
- Rectangle bounds=visuals.getBounds();
26
-
27
- TimeScale scale=visuals.getTimeScale();
28
- java.util.List<AxisTicMarks> t=AxisTicMarks.allRelevant(scale.getInterval());
29
-
30
- int dateLabelH=model.getDisplay().getInt("timeline.datelabel.height");
31
- int y=bounds.y+bounds.height-dateLabelH;
32
-
33
- // draw in reverse order so bigger granularity at top.
34
- int n=t.size();
35
- for (int i=0; i<n; i++)
36
- {
37
- render(t.get(i), g, bounds.x, y, dateLabelH-1, bounds.y, i==0, objectLocations);
38
- y-=dateLabelH;
39
- }
40
- }
41
-
42
- void render(AxisTicMarks t, Graphics2D g, int x, int y, int h, int top, boolean full, Collection<Mouseover> objectLocations)
43
- {
44
- TFModel model=visuals.getModel();
12
+public class AxisRenderer
13
+{
14
+ TimelineVisuals visuals;
4515
46
- int n=t.tics.size();
47
- for (int i=0; i<n-1; i++)
48
- {
49
-
50
- long start=t.tics.get(i);
51
- long end=t.tics.get(i+1);
52
-
53
- int x0=Math.max(x,visuals.getTimeScale().toInt(start));
54
- int x1=visuals.getTimeScale().toInt(end);
55
-
56
- int dayOfWeek=TimeUtils.cal(start).get(Calendar.DAY_OF_WEEK);
57
-
58
- g.setColor(t.unit.isDayOrLess() && (dayOfWeek==1 || dayOfWeek==7) ?
59
- new Color(245,245,245) : new Color(240,240,240));
16
+ public AxisRenderer(TimelineVisuals visuals)
17
+ {
18
+ this.visuals = visuals;
19
+ }
6020
61
- g.fillRect(x0, y, x1-x0-1, h);
62
- g.setColor(Color.white);
63
- g.drawLine(x1-1, y, x1-1, y+h);
64
- g.drawLine(x0,y+h,x1,y+h);
65
- objectLocations.add(new Mouseover(new Interval(start,end), x0, y, x1-x0-1, h));
66
-
67
- g.setFont(model.getDisplay().timeLabel());
68
- String label=full? t.unit.formatFull(start) : t.unit.format(new Date(start));
69
- int tx=x0+3;
70
- int ty=y+h-5;
71
- g.setColor(full ? Color.darkGray : Color.gray);
72
- int sw=model.getDisplay().timeLabelFontMetrics().stringWidth(label);
73
- if (sw<x1-tx-3)
74
- g.drawString(label, tx,ty);
75
- else
76
- {
77
- int c=label.indexOf(':');
78
- if (c>0)
79
- {
80
- label=label.substring(0,c);
81
- sw=model.getDisplay().timeLabelFontMetrics().stringWidth(label);
82
- if (sw<x1-tx-3)
83
- g.drawString(label, tx,ty);
84
- }
85
- }
86
- }
87
- }
21
+ public void render(Graphics2D g, Collection<Mouseover> objectLocations)
22
+ {
23
+ TFModel model = visuals.getModel();
24
+ g.setColor(model.getDisplay().getColor("chart.background"));
25
+ Rectangle bounds = visuals.getBounds();
26
+
27
+ TimeScale scale = visuals.getTimeScale();
28
+ java.util.List<AxisTicMarks> t = AxisTicMarks.allRelevant(scale.getInterval());
29
+
30
+ int dateLabelH = model.getDisplay().getInt("timeline.datelabel.height");
31
+ int y = bounds.y + bounds.height - dateLabelH;
32
+
33
+ // draw in reverse order so bigger granularity at top.
34
+ int n = t.size();
35
+ for (int i = 0; i < n; i++)
36
+ {
37
+ render(t.get(i), g, bounds.x, y, dateLabelH - 1, bounds.y, i == 0, objectLocations);
38
+ y -= dateLabelH;
39
+ }
40
+ }
41
+
42
+ void render(AxisTicMarks t, Graphics2D g, int x, int y, int h, int top, boolean full, Collection<Mouseover> objectLocations)
43
+ {
44
+ TFModel model = visuals.getModel();
45
+
46
+ int n = t.tics.size();
47
+ for (int i = 0; i < n - 1; i++)
48
+ {
49
+
50
+ long start = t.tics.get(i);
51
+ long end = t.tics.get(i + 1);
52
+
53
+ int x0 = Math.max(x, visuals.getTimeScale().toInt(start));
54
+ int x1 = visuals.getTimeScale().toInt(end);
55
+
56
+ int dayOfWeek = TimeUtils.cal(start).get(Calendar.DAY_OF_WEEK);
57
+
58
+ g.setColor(t.unit.isDayOrLess() && (dayOfWeek == 1 || dayOfWeek == 7)
59
+ ? new Color(245, 245, 245) : new Color(240, 240, 240));
60
+
61
+ g.fillRect(x0, y, x1 - x0 - 1, h);
62
+ g.setColor(Color.white);
63
+ g.drawLine(x1 - 1, y, x1 - 1, y + h);
64
+ g.drawLine(x0, y + h, x1, y + h);
65
+ objectLocations.add(new Mouseover(new Interval(start, end), x0, y, x1 - x0 - 1, h));
66
+
67
+ g.setFont(model.getDisplay().timeLabel());
68
+ String label = full ? t.unit.formatFull(start) : t.unit.format(new Date(start));
69
+ int tx = x0 + 3;
70
+ int ty = y + h - 5;
71
+ g.setColor(full ? Color.darkGray : Color.gray);
72
+ int sw = model.getDisplay().timeLabelFontMetrics().stringWidth(label);
73
+ if (sw < x1 - tx - 3)
74
+ {
75
+ g.drawString(label, tx, ty);
76
+ } else
77
+ {
78
+ int c = label.indexOf(':');
79
+ if (c > 0)
80
+ {
81
+ label = label.substring(0, c);
82
+ sw = model.getDisplay().timeLabelFontMetrics().stringWidth(label);
83
+ if (sw < x1 - tx - 3)
84
+ {
85
+ g.drawString(label, tx, ty);
86
+ }
87
+ }
88
+ }
89
+ }
90
+ }
8891 }