@@ -513,11 +513,29 @@ pub trait GraphWalk<'a, N, E> {
513
513
fn target ( & ' a self , edge : & E ) -> N ;
514
514
}
515
515
516
+ #[ deriving( Copy , PartialEq , Eq , Show ) ]
517
+ pub enum RenderOption {
518
+ NoEdgeLabels ,
519
+ NoNodeLabels ,
520
+ }
521
+
522
+ /// Returns vec holding all the default render options.
523
+ pub fn default_options ( ) -> Vec < RenderOption > { vec ! [ ] }
524
+
516
525
/// Renders directed graph `g` into the writer `w` in DOT syntax.
517
- /// (Main entry point for the library .)
526
+ /// (Simple wrapper around `render_opts` that passes a default set of options .)
518
527
pub fn render < ' a , N : Clone +' a , E : Clone +' a , G : Labeller < ' a , N , E > +GraphWalk < ' a , N , E > , W : Writer > (
519
528
g : & ' a G ,
520
- w : & mut W ) -> io:: IoResult < ( ) >
529
+ w : & mut W ) -> io:: IoResult < ( ) > {
530
+ render_opts ( g, w, & [ ] )
531
+ }
532
+
533
+ /// Renders directed graph `g` into the writer `w` in DOT syntax.
534
+ /// (Main entry point for the library.)
535
+ pub fn render_opts < ' a , N : Clone +' a , E : Clone +' a , G : Labeller < ' a , N , E > +GraphWalk < ' a , N , E > , W : Writer > (
536
+ g : & ' a G ,
537
+ w : & mut W ,
538
+ options : & [ RenderOption ] ) -> io:: IoResult < ( ) >
521
539
{
522
540
fn writeln < W : Writer > ( w : & mut W , arg : & [ & str ] ) -> io:: IoResult < ( ) > {
523
541
for & s in arg. iter ( ) { try!( w. write_str ( s) ) ; }
@@ -532,9 +550,13 @@ pub fn render<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>,
532
550
for n in g. nodes ( ) . iter ( ) {
533
551
try!( indent ( w) ) ;
534
552
let id = g. node_id ( n) ;
535
- let escaped = g. node_label ( n) . escape ( ) ;
536
- try!( writeln ( w, & [ id. as_slice ( ) ,
537
- "[label=\" " , escaped. as_slice ( ) , "\" ];" ] ) ) ;
553
+ if options. contains ( & RenderOption :: NoNodeLabels ) {
554
+ try!( writeln ( w, & [ id. as_slice ( ) , ";" ] ) ) ;
555
+ } else {
556
+ let escaped = g. node_label ( n) . escape ( ) ;
557
+ try!( writeln ( w, & [ id. as_slice ( ) ,
558
+ "[label=\" " , escaped. as_slice ( ) , "\" ];" ] ) ) ;
559
+ }
538
560
}
539
561
540
562
for e in g. edges ( ) . iter ( ) {
@@ -544,8 +566,14 @@ pub fn render<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>,
544
566
let target = g. target ( e) ;
545
567
let source_id = g. node_id ( & source) ;
546
568
let target_id = g. node_id ( & target) ;
547
- try!( writeln ( w, & [ source_id. as_slice ( ) , " -> " , target_id. as_slice ( ) ,
548
- "[label=\" " , escaped_label. as_slice ( ) , "\" ];" ] ) ) ;
569
+ if options. contains ( & RenderOption :: NoEdgeLabels ) {
570
+ try!( writeln ( w, & [ source_id. as_slice ( ) ,
571
+ " -> " , target_id. as_slice ( ) , ";" ] ) ) ;
572
+ } else {
573
+ try!( writeln ( w, & [ source_id. as_slice ( ) ,
574
+ " -> " , target_id. as_slice ( ) ,
575
+ "[label=\" " , escaped_label. as_slice ( ) , "\" ];" ] ) ) ;
576
+ }
549
577
}
550
578
551
579
writeln ( w, & [ "}" ] )
0 commit comments