Version 1.0. Highlights parents and children in drawing area.
authorRichard Jones <rjones@redhat.com>
Fri, 27 Mar 2009 16:40:34 +0000 (16:40 +0000)
committerRichard Jones <rjones@redhat.com>
Fri, 27 Mar 2009 16:40:34 +0000 (16:40 +0000)
configure.ac
rpmdepsize.ml

index 48b6a06..977bddc 100644 (file)
@@ -17,7 +17,7 @@ dnl Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 dnl
 dnl Written by Richard W.M. Jones <rjones@redhat.com>
 
-AC_INIT(rpmdepsize,0.9)
+AC_INIT(rpmdepsize,1.0)
 AM_INIT_AUTOMAKE
 
 AC_CONFIG_MACRO_DIR([m4])
index 3de9065..d0489bb 100644 (file)
@@ -401,6 +401,24 @@ let open_window pkgstr =
    *)
   let opened = ref None in
 
+  (* If we are moused-over a particular package, then this is != None. *)
+  let current = ref None in
+  let set_current new_current =
+    let old_current = !current in
+    current := new_current;
+    (* Because this structure contains loops, we can't use
+     * structural comparisons like: = <> compare.
+     *)
+    let do_repaint =
+      match old_current, new_current with
+      | None, Some _ -> true
+      | Some _, None -> true
+      | Some { pkg = { nevra = n1 } }, Some { pkg = { nevra = n2 } } ->
+         n1 <> n2
+      | _ -> false in
+    if do_repaint then drawing_area_repaint ()
+  in
+
   (* Called from the "Open package" menu entry and other places. *)
   let open_package pkgstr =
     debug "open_package %s\n%!" pkgstr;
@@ -437,6 +455,7 @@ let open_window pkgstr =
 
        opened :=
          Some (root, pkgs, depsmap, totalsmap, tree, depth, top_total);
+       set_current None;
 
        (* Update the window title. *)
        window#set_title (pkgstr ^ " - " ^ base_title);
@@ -486,24 +505,6 @@ let open_window pkgstr =
 
   let tooltips = ref None in
 
-  (* If we are moused-over a particular package, then this is != None. *)
-  let current = ref None in
-  let set_current new_current =
-    let old_current = !current in
-    current := new_current;
-    (* Because this structure contains loops, we can't use
-     * structural comparisons like: = <> compare.
-     *)
-    let do_repaint =
-      match old_current, new_current with
-      | None, Some _ -> true
-      | Some _, None -> true
-      | Some { pkg = { nevra = n1 } }, Some { pkg = { nevra = n2 } } ->
-         n1 <> n2
-      | _ -> false in
-    if do_repaint then drawing_area_repaint ()
-  in
-
   (* To track tooltips, the 'repaint' function records the location of
    * each box (ie. package) in the drawing area in this private data
    * structure, and the 'motion' function looks them up in order to
@@ -585,32 +586,33 @@ let open_window pkgstr =
       let height = int_of_float height in
 
       if width > 8 then (
-       draw_pkg_outline x y width pkgsizewidth height colour;
+       draw_pkg_outline x y width pkgsizewidth height colour pkg;
        draw_pkg_label x y width height colour pkg total increm
       )
       else if width >= 4 then
-       draw_pkg_narrow x y width height colour
+       draw_pkg_narrow x y width height colour pkg
          (* else
             XXX This doesn't work.  We need to coalesce small packages
             in the tree.
             draw_pkg_narrow x y 1 height colour *)
 
-    and draw_pkg_outline x y width pkgsizewidth height colour =
-      draw#set_foreground colour;
+    and draw_pkg_outline x y width pkgsizewidth height colour pkg =
+      let body_colour = choose_colour colour pkg in
+      draw#set_foreground body_colour;
       draw#rectangle ~x:(x+2) ~y:(y+2)
        ~width:(width-4) ~height:(height-4)
        ~filled:true ();
       if pkgsizewidth > 2 then (
-       draw#set_foreground (darken colour);
+       draw#set_foreground (darken body_colour);
        draw#rectangle ~x:(x+2) ~y:(y+2)
          ~width:(pkgsizewidth-2) ~height:(height-4)
          ~filled:true ();
-       draw#set_foreground (choose_contrasting_colour colour);
+       draw#set_foreground (choose_contrasting_colour body_colour);
        draw#set_line_attributes ~style:`ON_OFF_DASH ();
        draw#line (x+pkgsizewidth) (y+2) (x+pkgsizewidth) (y+height-2);
        draw#set_line_attributes ~style:`SOLID ()
       );
-      draw#set_foreground (`BLACK);
+      draw#set_foreground `BLACK;
       draw#rectangle ~x:(x+2) ~y:(y+2)
        ~width:(width-4) ~height:(height-4)
        ~filled:false ()
@@ -729,8 +731,8 @@ Tot: %.1f%% %s" pkg.name
       in
       loop txts
 
-    and draw_pkg_narrow x y width height colour =
-      draw#set_foreground colour;
+    and draw_pkg_narrow x y width height colour pkg =
+      draw#set_foreground (choose_colour colour pkg);
       draw#rectangle ~x:(x+2) ~y:(y+2)
        ~width:(width-4) ~height:(height-4) ~filled:true ()
 
@@ -739,6 +741,22 @@ Tot: %.1f%% %s" pkg.name
          if r + g + b > 98304 then `BLACK else `WHITE
       | _ -> `WHITE
 
+    and choose_colour colour pkg =
+      match !current with
+      | None -> colour
+      | Some current ->
+         let nevra = pkg.nevra in
+         let is_parent =
+           List.exists
+             (fun { pkg = { nevra = n } } -> n = nevra) current.parents in
+         let is_child =
+           List.exists
+             (fun { pkg = { nevra = n } } -> n = nevra) current.children in
+         if is_parent && is_child then `RGB (63000, 63000, 0) (* yellow *)
+         else if is_parent then `RGB (0, 63000, 63000) (* cyan *)
+         else if is_child then `RGB (0, 63000, 0) (* green *)
+         else colour
+
     and darken = function
       | `RGB (r, g, b) ->
          `RGB (r * 9 / 10, g * 9 / 10, b * 9 / 10)
@@ -799,11 +817,11 @@ Total: %.1f%% %s (%Ld bytes)" pkg.nevra
            (display_percent increm top_total) (display_size increm) increm
            (display_percent total top_total) (display_size total) total in
         let text = if dep.parents = [] then text else text ^ sprintf "
-Required by:
+Required by (blue):
   %s"
            (deps_of_string dep.parents) in
         let text = if dep.children = [] then text else text ^ sprintf "
-Requires:
+Requires (green):
   %s"
            (deps_of_string dep.children) in
         tt#set_tip ~text (da :> GObj.widget);