| .. | .. |
|---|
| 9 | 9 | import timeflow.vis.Mouseover; |
|---|
| 10 | 10 | import timeflow.vis.TimeScale; |
|---|
| 11 | 11 | |
|---|
| 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; |
|---|
| 45 | 15 | |
|---|
| 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 | + } |
|---|
| 60 | 20 | |
|---|
| 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 | + TimeflowModel 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 | + TimeflowModel model = visuals.getModel(); |
|---|
| 45 | + |
|---|
| 46 | + int n = t.tics.size(); |
|---|
| 47 | + for (int i = 0; i < n - 1; i++) |
|---|
| 48 | + { |
|---|
| 49 | + long start = t.tics.get(i); |
|---|
| 50 | + long end = t.tics.get(i + 1); |
|---|
| 51 | + |
|---|
| 52 | + int x0 = Math.max(x, visuals.getTimeScale().toInt(start)); |
|---|
| 53 | + int x1 = visuals.getTimeScale().toInt(end); |
|---|
| 54 | + |
|---|
| 55 | + int dayOfWeek = TimeUtils.cal(start).get(Calendar.DAY_OF_WEEK); |
|---|
| 56 | + |
|---|
| 57 | + g.setColor(t.unit.isDayOrLess() && (dayOfWeek == 1 || dayOfWeek == 7) |
|---|
| 58 | + ? new Color(245, 245, 245) : new Color(240, 240, 240)); |
|---|
| 59 | + |
|---|
| 60 | + g.fillRect(x0, y, x1 - x0, h); |
|---|
| 61 | + g.setColor(Color.white); |
|---|
| 62 | + g.drawLine(x1, y, x1, y + h); |
|---|
| 63 | + g.drawLine(x0, y + h, x1, y + h); |
|---|
| 64 | + objectLocations.add(new Mouseover(new Interval(start, end), x0, y, x1 - x0, h)); |
|---|
| 65 | + |
|---|
| 66 | + g.setFont(model.getDisplay().timeLabel()); |
|---|
| 67 | + String label = full ? t.unit.formatFull(start) : t.unit.format(new Date(start)); |
|---|
| 68 | + |
|---|
| 69 | + if (!full) |
|---|
| 70 | + full = false; |
|---|
| 71 | + |
|---|
| 72 | + int tx = x0; |
|---|
| 73 | + int ty = y + h; |
|---|
| 74 | + g.setColor(full ? Color.darkGray : Color.gray); |
|---|
| 75 | + int sw = model.getDisplay().timeLabelFontMetrics().stringWidth(label); |
|---|
| 76 | + if (true) // sw < x1 - tx) |
|---|
| 77 | + { |
|---|
| 78 | + g.drawString(label, tx, ty); |
|---|
| 79 | + } else |
|---|
| 80 | + { |
|---|
| 81 | + int c = label.indexOf(':'); |
|---|
| 82 | + if (c > 0) |
|---|
| 83 | + { |
|---|
| 84 | + label = label.substring(0, c); |
|---|
| 85 | + sw = model.getDisplay().timeLabelFontMetrics().stringWidth(label); |
|---|
| 86 | + //if (sw < x1 - tx) |
|---|
| 87 | + { |
|---|
| 88 | + g.drawString(label, tx, ty); |
|---|
| 89 | + } |
|---|
| 90 | + } |
|---|
| 91 | + } |
|---|
| 92 | + } |
|---|
| 93 | + } |
|---|
| 88 | 94 | } |
|---|