Author: benm
Date: 2005-03-23 18:41:38 -0500 (Wed, 23 Mar 2005)
New Revision: 42179

Modified:
   trunk/heap-prof/src/viewer/common/ChangeLog
   trunk/heap-prof/src/viewer/common/TypeGraphPlotter.cs
   trunk/heap-prof/src/viewer/gui-gtk/ChangeLog
   trunk/heap-prof/src/viewer/gui-gtk/TypeGraphViewer.cs
Log:
In gui-gtk:
2005-03-23  Ben Maurer  <[EMAIL PROTECTED]>

        * TypeGraphViewer.cs: Create a scale for the x axis.

In common:
2005-02-19  Ben Maurer  <[EMAIL PROTECTED]>

        * TypeGraphPlotter.cs:
            - A new color chooser. Somewhat exparimental. I still think it
              needs to get better
            - Make anti-alias work nicely, by drawing rectangles from the
              bottom of the band to the top of the screen. This prevents
              little white lines. 



Modified: trunk/heap-prof/src/viewer/common/ChangeLog
===================================================================
--- trunk/heap-prof/src/viewer/common/ChangeLog 2005-03-23 23:10:13 UTC (rev 
42178)
+++ trunk/heap-prof/src/viewer/common/ChangeLog 2005-03-23 23:41:38 UTC (rev 
42179)
@@ -1,3 +1,12 @@
+2005-02-19  Ben Maurer  <[EMAIL PROTECTED]>
+
+       * TypeGraphPlotter.cs:
+           - A new color chooser. Somewhat exparimental. I still think it
+             needs to get better
+           - Make anti-alias work nicely, by drawing rectangles from the
+             bottom of the band to the top of the screen. This prevents
+             little white lines. 
+
 2005-02-06  Ben Maurer  <[EMAIL PROTECTED]>
 
        * Profile.cs (MaxSize): new prop.

Modified: trunk/heap-prof/src/viewer/common/TypeGraphPlotter.cs
===================================================================
--- trunk/heap-prof/src/viewer/common/TypeGraphPlotter.cs       2005-03-23 
23:10:13 UTC (rev 42178)
+++ trunk/heap-prof/src/viewer/common/TypeGraphPlotter.cs       2005-03-23 
23:41:38 UTC (rev 42179)
@@ -40,7 +40,7 @@
                int del_t = end_t - start_t;
                
                data = new ArrayList ();
-               int size_threshold = Profile.MaxSize / ysize;
+               int size_threshold = (Profile.MaxSize / ysize) * 3;
                
                foreach (TimeData td in d.Data) {
                        if (td.HeapSize < size_threshold)
@@ -72,22 +72,25 @@
        
        public void Draw (Graphics g)
        {
+               Point [] poly = new Point [data.Count + 2];
                
-               int [] offsets = new int [data.Count];
-               Point [] prev = new Point [data.Count];
+               for (int i = 0; i < poly.Length; i ++)
+                       poly [i].Y = ysize;
                
-               for (int i = 0; i < prev.Length; i ++)
-                       prev [i].Y = ysize;
+               poly [0] = new Point (0, 0);
+               poly [poly.Length - 1] = new Point (xsize, 0);
+               poly [poly.Length - 2] = new Point (xsize, ysize);
                
-               prev [0].X = xsize;
-               
                for (int i = -1; i <  tl.TypeIndexes.Length; i ++) {
-                       Point [] line = new Point [data.Count];
+                       Brush b;
+                       if (i == -1)
+                               b = Brushes.DarkGray;
+                       else
+                               b = tl.TypeBrushes [i];
                        
-                       int j = 0;
+                       g.FillPolygon (b, poly);
+                       int j = 1;
                        foreach (TimePoint tp in data) {
-                               
-                               
                                int psize;
                                
                                if (i == -1)
@@ -95,29 +98,13 @@
                                else
                                        psize = tp.TypeData [i];
                                
-                               line [j].X = tp.X;
-                               line [j].Y = ysize - checked (offsets [j] + 
(int)((long)psize * (long) ysize / (long)Profile.MaxSize));
-                               offsets [j] = ysize - line [j].Y;
+                               poly [j].X = tp.X;
+                               poly [j].Y -= checked ((int)((long)psize * 
(long) ysize / (long)Profile.MaxSize));
                                j ++;
                        }
-                       
-                       GraphicsPath path = new GraphicsPath ();
-                       path.AddLines (line);
-                       path.AddLine (line [line.Length - 1], prev [0]);
-                       path.AddLines (prev);
-                       //path.CloseFigure ();
-                       
-                       Brush b;
-                       if (i == -1)
-                               b = Brushes.DarkGray;
-                       else
-                               b = tl.TypeBrushes [i];
-                       
-                       g.FillPath (b, path);
-                       
-                       prev = line;
-                       Array.Reverse (prev, 0, prev.Length);
                }
+               
+               g.FillPolygon (Brushes.White, poly);
        
                {
                        Point [] line = new Point [data.Count];
@@ -141,17 +128,72 @@
 class RandomBrush {
        int i;
        
-       static Brush [] brushes = {
-               Brushes.IndianRed,
-               Brushes.BurlyWood,
-               Brushes.Chocolate,
-               Brushes.DarkGoldenrod,
-               Brushes.PaleGoldenrod,
-               Brushes.DarkOrange,
-               Brushes.DarkSalmon,
+       static Brush [] brushes;
+       
+       const int N_COLORS = 26;
+       const int MOD = 5;
+
+       static RandomBrush () {
                
-       };
+               Color [] c = Generate (N_COLORS);
+               
+               brushes = new Brush [c.Length];
+               
+               for (int i = 0; i < c.Length; i ++)
+                       brushes [i] = new SolidBrush (c [i]);
+       }
        
+       static Color [] Generate (int range)
+       {
+               
+               float hue_step = 1.0f / range;
+               float hue_base = 0.0f;
+               
+               int mod_check;
+               
+               Color [] ret = new Color [range];
+               for (int i = 0; i < range; i ++) {
+                       
+                       float hue_offset, hue;
+                       
+                       hue = hue_step * ((MOD * i) % N_COLORS);
+                       
+                       
+                       Console.WriteLine (hue);
+                       ret [i] = HSV2RGB (hue, .60f, .80f);
+               }
+               
+               return ret;
+       }
+       
+       public static Color HSV2RGB (float H, float S, float V) {
+               if (S == 0.0)
+                       return new Color ();
+               
+               H *= 6.0f;
+               int i = (int) Math.Floor (H);
+               float f = H - (float)i;
+               float p = V*(1.0f - S);
+               float q = V*(1.0f - S * f);
+               float t = V*(1.0f - (S* (1.0f - f)));
+               
+               
+               int i_v = (int) (V * 255.0f);
+               int i_p = (int) (p * 255.0f);
+               int i_q = (int) (q * 255.0f);
+               int i_t = (int) (t * 255.0f);
+               switch (i) {
+                       case 0: return Color.FromArgb (i_v, i_t, i_p);
+                       case 1: return Color.FromArgb (i_q, i_v, i_p);
+                       case 2: return Color.FromArgb (i_p, i_v, i_t);
+                       case 3: return Color.FromArgb (i_p, i_q, i_v);
+                       case 4: return Color.FromArgb (i_t, i_p, i_v);
+                       case 5: return Color.FromArgb (i_v, i_p, i_q);
+                       default:
+                               return new Color ();
+               }
+       }
+       
        public Brush Next ()
        {
                return brushes [i ++ % brushes.Length];

Modified: trunk/heap-prof/src/viewer/gui-gtk/ChangeLog
===================================================================
--- trunk/heap-prof/src/viewer/gui-gtk/ChangeLog        2005-03-23 23:10:13 UTC 
(rev 42178)
+++ trunk/heap-prof/src/viewer/gui-gtk/ChangeLog        2005-03-23 23:41:38 UTC 
(rev 42179)
@@ -1,3 +1,7 @@
+2005-03-23  Ben Maurer  <[EMAIL PROTECTED]>
+
+       * TypeGraphViewer.cs: Create a scale for the x axis.
+
 2005-02-12  Ben Maurer  <[EMAIL PROTECTED]>
 
        * HeapScroller.cs, ShellPager.cs, Shell.cs: Allow the closing of

Modified: trunk/heap-prof/src/viewer/gui-gtk/TypeGraphViewer.cs
===================================================================
--- trunk/heap-prof/src/viewer/gui-gtk/TypeGraphViewer.cs       2005-03-23 
23:10:13 UTC (rev 42178)
+++ trunk/heap-prof/src/viewer/gui-gtk/TypeGraphViewer.cs       2005-03-23 
23:41:38 UTC (rev 42179)
@@ -185,10 +185,6 @@
 
 }
 
-
-//
-// A sample using inheritance to draw
-//
 class TypeGrpah : DrawingArea {
        TypeList tl;
        
@@ -199,6 +195,8 @@
        Plotter plot;
        TypeGraphComponent parent;
        
+       Gdk.Rectangle graph_area, x_scale, y_scale;
+       
        public TypeGrpah (TypeList tl, TypeGraphComponent parent)
        {
                Events |= Gdk.EventMask.ButtonPressMask;
@@ -207,39 +205,98 @@
                this.parent = parent;
                SetSizeRequest (700, 700);
        }
-                              
+       
        protected override bool OnExposeEvent (Gdk.EventExpose args)
        {
                
                if (bitmap_cache == null) {
-                       bitmap_cache = new Gdk.Pixmap (GdkWindow, 
allocation.Width, allocation.Height, -1);
+                       bitmap_cache = new Gdk.Pixmap (GdkWindow, 
graph_area.Width, graph_area.Height, -1);
                        bitmap_cache.DrawRectangle (Style.WhiteGC, true, 0, 0,
-                               allocation.Width, allocation.Height);
+                               graph_area.Width, graph_area.Height);
                        
                        using (Graphics g = Gtk.DotNet.Graphics.FromDrawable 
(bitmap_cache)) {
-                               plot = new Plotter (allocation.Width, 
allocation.Height, parent.CurrentTabulator, tl);
+                               plot = new Plotter (graph_area.Width, 
graph_area.Height, parent.CurrentTabulator, tl);
                                plot.Draw (g);
                        }
                }
+               Gdk.Rectangle area = args.Area;
                
-               Gdk.Rectangle area = args.Area;
                GdkWindow.DrawDrawable (Style.BlackGC,
                                                bitmap_cache,
-                                               area.X, area.Y,
-                                               area.X, area.Y,
-                                               area.Width, area.Height);
+                                               0, 0,
+                                               graph_area.X, graph_area.Y,
+                                               graph_area.Width, 
graph_area.Height);
+
+               DrawXScale (area);
                
                return true;
        }
        
+       string FormatTime (int ms)
+       {
+               TimeSpan dt = TimeSpan.FromMilliseconds (ms);
+               
+               double seconds = (double) (dt.Ticks % TimeSpan.TicksPerMinute) 
/ (double) TimeSpan.TicksPerSecond;
+               
+               string format;
+               
+               if (dt.TotalDays > 1)
+                       format = "{0}.{1}:{2}:{3}";
+               else if (dt.TotalHours > 1)
+                       format = "{1}:{2}:{3}";
+               else if (dt.TotalMinutes > 1)
+                       format = "{2}:{3}";
+               else
+                       format = "{3}";
+               
+               return String.Format (format, dt.Days, dt.Hours, dt.Minutes, 
seconds);
+       }
+       
+       void DrawXScale (Gdk.Rectangle area)
+       {
+               const int tick_space = 15;
+               const int major_tick_freq = 5;
+               const int minor_tick_height = 5;
+               const int major_tick_height = 10;
+               
+               int t_0 = parent.StartTime;
+               int dt = ((parent.EndTime - parent.StartTime) / x_scale.Width) 
* tick_space;
+               
+               for (int i = 0; i < x_scale.Width / tick_space; i ++) {
+                       if (i % major_tick_freq == 0) {
+                               
+                               Pango.Layout layout = this.CreatePangoLayout 
(FormatTime (t_0 + dt * i));
+                               
+                               int w, h;
+                               
+                               layout.GetPixelSize (out w, out h);
+                               
+                               GdkWindow.DrawLayout (Style.BlackGC,  x_scale.X 
+ i * tick_space - w / 2,  x_scale.Y + major_tick_height, layout);              
        
+                               GdkWindow.DrawLine (Style.BlackGC, x_scale.X + 
i * tick_space , x_scale.Y, x_scale.X + i * tick_space, x_scale.Y + 
major_tick_height);
+                       } else {
+                               GdkWindow.DrawLine (Style.BlackGC, x_scale.X + 
i * tick_space , x_scale.Y, x_scale.X + i * tick_space, x_scale.Y + 
minor_tick_height);
+                       }
+               }
+       }
+       
        protected override void OnSizeAllocated (Gdk.Rectangle allocation)
        {
-               allocated = true;
+               
+               int x_scale_size = 30, y_scale_size = 10;
+               
+               y_scale = new Gdk.Rectangle (0, 0, y_scale_size, 
allocation.Height - x_scale_size);
+               x_scale = new Gdk.Rectangle (y_scale_size, allocation.Height - 
x_scale_size, allocation.Width - y_scale_size, x_scale_size);
+               graph_area = new Gdk.Rectangle (y_scale_size, 0, 
allocation.Width - y_scale_size, allocation.Height - x_scale_size);
+               
+               Console.WriteLine (allocation);
+               Console.WriteLine (x_scale);
+               
                this.allocation = allocation;
+               
                UpdateCache ();
                base.OnSizeAllocated (allocation);
        }
-
+       
        public void UpdateCache ()
        {
                if (bitmap_cache != null)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to