NAME

VcsTools::GraphMgr - Perl class to draw VCS revision in a GraphWidget

SYNOPSIS

use Tk ;
use VcsTools::GraphMgr;
use Tk::Multi::Manager ;

use strict ;

my $mw = MainWindow-> new ;

my $wmgr = $mw -> MultiManager ( 'title' => 'log test' ,
                            'menu' => $w_menu ) -> pack ();

my $mgr = new VcsTools::GraphMgr('name' => 'test', multiMgr => $wmgr ) ;

$mgr -> addLabel ('big test on-going');

my $ref = [1000..1005];
my ($ox,$oy) = (100,100);

$mgr -> addNode ('1.0',$ref,\$ox,\$oy) ;

my ($x,$y)= ($ox,$oy) ;
$mgr -> addDirectArrow('1.0','1.1',\$x,\$y) ;
$mgr -> addNode ('1.1',$ref,\$x,\$y) ;

my ($bx,$by)=($ox,$oy) ;
my $dx ;
$mgr -> addBranchArrow('1.0','1.0.1.1',\$bx,\$by,\$dx) ;
$mgr -> addNode ('1.0.1.1',$ref,\$bx,\$by) ;
$mgr->arrowBind('<1>','orange',
               sub {print "clicked arrow ",shift," -> ",shift,"\n";});
$mgr->nodeBind('<2>','red',
               sub {print "clicked 2 on node ",shift,"\n";});

$mgr->command(-label => 'unselect all', -command => 
              sub {$mgr->unselectAllNodes}) ;

MainLoop ; # Tk's

DESCRIPTION

GraphMgr is a class designed to help to draw revision graph on the VcsTools::GraphWidget.

GraphMgr is able to draw the following items:

  • node: some text for each revision of your VCS file.

  • direct arrow: an arrow to represent a regular new version (e.g. from revision 1.1 to revision 1.2)

  • branch arrow: an arrow to represent a new branch (e.g. from revision 1.1 to revision 1.1.1.1)

  • merges arrow: an arrow to represent a merge between 2 revisions from different branches.

GraphMgr also provides :

  • a binding on nodes on button 1 to 'select' them.

  • Methods to bind nodes and arrows on user's call-back.

  • a command method to easily add menu command.

Constructor

new('name'=> '...', 'multiMgr' => 'object_ref', ['help' => ...])

multiMgr is the Tk::Multi::Manager object. The help parameter value is forwarded as is to the newSlave() method of Tk::Multi::Manager(3).

Drawing Methods

In each drawing methods, passing a reference (here x_ref, y_ref and delta_x_ref) means that the value refered to will be modified by the method.

Note that all revision parameters as treated as string.

addDirectArrow(revision,next_revision, x_ref, y_ref)

Add a new staight (i.e. vertical) revision arrow from coordinate (x,y).

x and y are modified so that their new value is the coordinate of the tip of the arrow.

addBranchArrow(revision,branch_revision, x_ref, y_ref, delta_x_ref)

Add a new branch to revision 'revision'. The first revision of this new branch being 'branch_revision'.

The arrow will be drawn from (x,y) to (x+delta_x, y).

x and y are modified so that their new value is the coordinate of the tip of the arrow.

delta_x is modified so that the next branch drawn using this delta_x value will not overlap the first branch.

addLabel(text)

Put some text on the top of the graph.

addMergeInfo(revsion, merge_from_revision)

Declare that node 'revision' is a merge between the staight upper node (whose revision number does not need to be passed to this function) and the node 'merge_from_revision'.

addAllMerges()

This method is to be called once all nodes, direct arrow and branch arrow are drawn and all relevant calls to addAllMerges are done. It will add merge arrows between the revision declared with the addMergeInfo method.

addNode(revision,text_array_ref, x_ref, y_ref)

Will add a new node (made of a rectangle with the text inside). The node will be drawn at coordinate (x,y)

x and y are modified so that their new value is the coordinate of the tip of the arrow.

Note that this method will add 'vx.y' (i.e. the revision number) on top of the text.

clear()

Clear the graph.

Management methods

command(-label => 'some text', -command => sub {...} )

Delegated to the menu entry managed by Multi::Manager. Calling this method will add a new command to the aforementionned menu.

graphSlave()

Returns the ref of the graph widget.

nodeBind(button, color, sub{my $rev = shift; ... })

Bind the 'button' on nodes. When 'button' is clicked, the node text color will change to 'color' and the callback sub will be called with the revision number as parameter.

arrowBind(button, color, sub{ ...})

Bind the 'button' on arrows. When 'button' is clicked, the arrow color will change to 'color' and the callback sub will be called with the revision number attached to the start of the arrow as first parameter and the revision number attached to the tip of the arrow as second parameter.

The callback should be in this form :

sub 
  {
    my $rev = shift;    # base of the arrow
    my $tiprev = shift; # tip of the arrow
    ...
  }

unselectAllNodes()

Unselect all previously selected nodes (see button <1> binding)

getSelectedNodes()

Return an array containing the version of currently selected nodes.

addRev( revision ,.. )

Add the passed revision in the revision listbox

listBind('<a button>' => sub {...} )

Bind the sub on the <a button> click on the revision list. All parameter of listBinf() are passed as to the Tk bind command.

Private methods

resetColor(canvas_item_id)

Put the color of the canvas item back to black.

setSelArrow(color)

Will set the current arrow to the color.

setSelNode(color)

Will set the current node text to the color.

toggleCurrentNode(color)

Will toggle the current node rectangle to the color or to black.

toggleNode(id,color)

Will toggle the node (with text id) rectangle to the color or to black.

AUTHOR

Dominique Dumont, Dominique_Dumont@grenoble.hp.com

Copyright (c) 1998 Dominique Dumont. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl(1), Tk(3), Tk::Multi::Manager(3), VcsTools::GraphWidget(3)