Code covered by the BSD License  

Highlights from
Matgraph

from Matgraph by Ed Scheinerman
Toolbox for working with simple, undirected graphs

Description of draw_labels
Home > matgraph > @graph > draw_labels.m

draw_labels

PURPOSE ^

draw_labels(g) --- add labels to a drawing of g

SYNOPSIS ^

function draw_labels(g,offset)

DESCRIPTION ^

 draw_labels(g) --- add labels to a drawing of g
 assuming g has already been drawn in a figure window (with draw or cdraw)
 add labels to the drawing. 
 Note: draw(g); add_labels(g) is tantamount to ldraw(g)
 If the drawing already has vertex numbers, this might make a mess.

 An optional second argument gives an offset of the label away from the
 vertex: draw_labels(g, [dx, dy]) moves the label dx to the right and dy
 up. Suggested offset: [0.1, -0.1]

CROSS-REFERENCE INFORMATION ^

This function calls:
  • get_label get_label(g) or get_label(g,v) --- get vertex label(s)
  • getxy getxy(g) --- give g's embedding (or [] if g doesn't have one)
  • is_labeled is_labeled(g) --- determine if there are labels on vertices.
  • label Assign labels to vertices of g
  • nv nv(g) --- number of vertices in g
This function is called by:
  • ldraw ldraw(g,line_style) --- draw a graph with vertices marked with their labels

SOURCE CODE ^

0001 function draw_labels(g,offset)
0002 % draw_labels(g) --- add labels to a drawing of g
0003 % assuming g has already been drawn in a figure window (with draw or cdraw)
0004 % add labels to the drawing.
0005 % Note: draw(g); add_labels(g) is tantamount to ldraw(g)
0006 % If the drawing already has vertex numbers, this might make a mess.
0007 %
0008 % An optional second argument gives an offset of the label away from the
0009 % vertex: draw_labels(g, [dx, dy]) moves the label dx to the right and dy
0010 % up. Suggested offset: [0.1, -0.1]
0011 
0012 if (~is_labeled(g))
0013     label(g)
0014 end
0015 
0016 if nargin == 1
0017     offset = [0 0];
0018 end
0019 
0020 xy = getxy(g);
0021 n = nv(g);
0022 
0023 for v=1:n
0024     x = xy(v,1) + offset(1);
0025     y = xy(v,2) + offset(2);
0026     text(x,y,get_label(g,v)); 
0027 end

Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003

Contact us at files@mathworks.com