Normand Briere
2018-07-07 e416acb9b012b17d1efe49ad2199ea7132d874d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package timeflow.vis;
 
import java.awt.*;
import java.util.*;
 
import timeflow.data.db.*;
import timeflow.model.Display;
import timeflow.model.VirtualField;
import timeflow.util.*;
 
public class GroupVisualAct extends VisualAct
{
   private ArrayList<Act> group=new ArrayList<Act>();
   private boolean mixed=false;
   private DoubleBag<Color> colorBag;
   int numActs=0;
   double total=0;
   
   public GroupVisualAct(java.util.List<VisualAct> vacts, boolean mixed, Rectangle bounds)
   {
       super(vacts.get(0).act);
       int n=vacts.size();
       
       VisualAct proto=vacts.get(0);
       
       this.color=proto.color;
       this.trackString=proto.trackString;
       this.visible=proto.visible;
       this.x=proto.x;
       this.y=proto.y;
       
       this.spaceToRight=proto.spaceToRight;
       this.start=proto.start;
       this.group=new ArrayList<Act>();
       this.label="Group of "+n+" events";
       this.mouseOver=this.label;
       this.colorBag=new DoubleBag<Color>();
       Field sizeField=act.getDB().getField(VirtualField.SIZE);
       for (VisualAct v: vacts)
       {
           numActs++;
           if(sizeField!=null)
               total+=v.act.getValue(sizeField);
           this.size+=v.size;
           this.colorBag.add(v.color, v.size);
       }
       this.size=Math.sqrt(this.size);
       this.mixed=mixed;        
   }
 
   public int getNumActs()
   {
       return numActs;
   }
   
   public void add(Act secondAct)
   {
       if (group==null)
       {
           group=new ArrayList<Act>();
           if (act!=null)
               group.add(act);
       }
       group.add(secondAct);
   }
 
   public void draw(Graphics2D g, int ox, int oy, int r, Rectangle maxFill, boolean showDuration)
   {
       if (!mixed)
       {
           g.setColor(color);
           g.fillOval(ox,oy-r,2*r,2*r);
           g.drawOval(ox-2,oy-r-2,2*r+3,2*r+3);
       }
       else
       {
           java.util.List<Color> colors=colorBag.listTop(8, true);
           double total=0;
           for (Color c: colors)
               total+=colorBag.num(c);
                           
           // now draw pie chart thing.
           double angle=0;
           int pieCenterX=ox+r;
           int pieCenterY=oy;
           for (Color c: colors)
           {
               double num=colorBag.num(c);
               double sa=(360*angle)/total;
               int startAngle=(int)(sa);
               int arcAngle=(int)(((360*(angle+num)))/total-sa);
               g.setColor(c);
               g.fillArc(pieCenterX-r,pieCenterY-r,2*r,2*r,startAngle,arcAngle);
               angle+=num;
           }        
       }
   }
}