9.0
top
← prev up next →

Circular-Layout ReferenceπŸ”— i

Thomas A. Houpt <houpt@bio.fsu.edu>

Light-weight drawing of nodes and edges in a circular layout

1OverviewπŸ”— i

A lightweight Racket module which draws a graph of nodes and edges in a circular layout, as an alternative to more powerful graph-rendering e.g. graphviz.

Nodes are defined using make-cl-node (which sets a name, size, a label and color), and edges are defined using make-cl-edge (which defines the source and target nodes, the weight of the edge, a label, and whether the edge is directed, i.e. has an arrow). A list of these nodes and edges are passed to draw-circular-layout along with a destination drawing context ( dc<%> ); scale factor and center of the graph within the drawing context also specified.

2Example outputπŸ”— i

3Example usageπŸ”— i

 
(requirecircular-layout)
(requireracket/gui/base)
 
;;asimplegraphwith5nodesandsomeedges
(definenodes(list
(clnode "a"23"a(23)""white")
(clnode "b"17"b(17)""red")
(clnode "c"11"c(11)""lightblue")
(clnode "d"15"d(15)""green")
(clnode "e"10"e(10)""violet")))
 
 
(defineedges(list
(cledge "a""a"1"10"#t)
(cledge "a""b"1"5"#t)
(cledge "a""c"1"3"#t)
(cledge "a""d"1"5"#t)
 
(cledge "b""a"1"7"#t)
(cledge "b""c"1"5"#t)
(cledge "b""b"1"5"#t)
 
(cledge "c""c"1"5"#t)
(cledge "c""b"1"3"#t)
(cledge "c""d"1"3"#t)
 
(cledge "d""d"1"5"#t)
(cledge "d""a"1"5"#t)
(cledge "d""e"1"5"#t)
 
(cledge "e""e"1"5"#t)
(cledge "e""d"1"5"#t)))
 
;;setupadrawingcanvaswithabitmap,andanimage-snip%todisplayinREPL
(definetarget(make-bitmap 400400))
(definedc(newbitmap-dc% [bitmaptarget]))
(make-objectimage-snip% target)
 
;;callthecircular-layoutfunctiontodrawthegraph
#:nodesnodes
#:edgesedges
#:center'(200.200)
#:scale10)
 

4ReferenceπŸ”— i

Added in version 1.0 of package circular-layout.

struct

(struct clnode(namesizelabelcolor))

name:string?
size:number?
label:string?
color:string?
Description of a node for circular-layout.
  • name is the identifier of the node.

  • size determines the area of the node’s circle – in dc pixels, if scale = 1 – which is conserved in the area of the node’s circle.

  • label is the string drawn at the center of the node.

  • color is the string representation of the color used to fill the node.

It is recommended to use the convenience constructor make-cl-node, which sets some reasonable defaults with minimal specification.

struct

(struct cledge(sourcetargetwidthlabeldirected))

source:string?
target:string?
width:number?
label:string?
directed:boolean?
Description of an edge between two nodes for circular layout.
  • source is the identifier of the source node, i.e, matches name of one of the clnodes in accompanying list of nodes.

  • target is the identifier of the target node, i.e., matches name of one of the clnodes in accompanying list of nodes. If source and target are the same name of a single node, then the edge is a self-edge from that node back to that same node.

  • width determines the pen-width of the edge line in pixels (regardless of scale).

  • label is the string drawn at the control point of the edge curve.

  • directed is a boolean flag that determines if an arrow is drawn pointing at target node (optional: defaults to #t).

It is recommended to use the convenience constructor make-cl-edge, which sets some reasonable defaults with minimal specification.

procedure

( make-cl-node #:namename
[ #:sizesize
#:labellabel
#:colorcolor])clnode?
name:string?
size:number? =1
label:(or/c #fstring? )=#f
color:string? ="white"
A convenience constructor for a clnode with default size 1, using name as default label and white as default color.

procedure

( make-cl-edge #:sourcesource
#:targettarget
[ #:labellabel
#:widthwidth
#:directeddirected])cledge?
source:string?
target:string?
label:string? =""
width:number? =1
directed:boolean? =#t
A convenience constructor for a cledge, with default width of 1, no label, and ’directed’ by default (i.e., an arrow is drawn at the target end).

procedure

( draw-circular-layout #:dcdc
#:nodesnodes
#:edgesedges
#:centercenter
#:scalescale)void?
dc:(is-a?/c dc<%> )
nodes:(listof clnode?)
edges:(listof cledge?)
scale:number?
Nodes are drawn with first node at 12 o’clock, with subsequent nodes arranged clockwise, in the same order as they appear in the nodes list.
Nodes are spaced at vertices of a polygon with side length (* kScaleSideLength(max noderadius)). (The default sidelength is 4 x the radius of the largest node.)
Edges can be listed in any order, as they reference members of the nodes list.

5To DoπŸ”— i

  • Function to return bounds of rendered layout (so we can appropriately size bitmap to fit).

  • Needs improvements to labeling of nodes.

  • Parameterize some of the drawing constants to allow customization.

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /