|
272 | 272 | //! * [DOT language](http://www.graphviz.org/doc/info/lang.html)
|
273 | 273 |
|
274 | 274 | #![doc(
|
275 |
| - html_root_url = "https://doc.rust-lang.org/nightly/", |
| 275 | + html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/", |
276 | 276 | test(attr(allow(unused_variables), deny(warnings)))
|
277 | 277 | )]
|
278 | 278 | #![feature(nll)]
|
@@ -591,14 +591,15 @@ pub trait GraphWalk<'a> {
|
591 | 591 | fn target(&'a self, edge: &Self::Edge) -> Self::Node;
|
592 | 592 | }
|
593 | 593 |
|
594 |
| -#[derive(Copy, Clone, PartialEq, Eq, Debug)] |
| 594 | +#[derive(Clone, PartialEq, Eq, Debug)] |
595 | 595 | pub enum RenderOption {
|
596 | 596 | NoEdgeLabels,
|
597 | 597 | NoNodeLabels,
|
598 | 598 | NoEdgeStyles,
|
599 | 599 | NoNodeStyles,
|
600 | 600 |
|
601 |
| - Monospace, |
| 601 | + Fontname(String), |
| 602 | + DarkTheme, |
602 | 603 | }
|
603 | 604 |
|
604 | 605 | /// Returns vec holding all the default render options.
|
@@ -630,10 +631,26 @@ where
|
630 | 631 | writeln!(w, "digraph {} {{", g.graph_id().as_slice())?;
|
631 | 632 |
|
632 | 633 | // Global graph properties
|
633 |
| - if options.contains(&RenderOption::Monospace) { |
634 |
| - writeln!(w, r#" graph[fontname="monospace"];"#)?; |
635 |
| - writeln!(w, r#" node[fontname="monospace"];"#)?; |
636 |
| - writeln!(w, r#" edge[fontname="monospace"];"#)?; |
| 634 | + let mut graph_attrs = Vec::new(); |
| 635 | + let mut content_attrs = Vec::new(); |
| 636 | + let font; |
| 637 | + if let Some(fontname) = options.iter().find_map(|option| { |
| 638 | + if let RenderOption::Fontname(fontname) = option { Some(fontname) } else { None } |
| 639 | + }) { |
| 640 | + font = format!(r#"fontname="{}""#, fontname); |
| 641 | + graph_attrs.push(&font[..]); |
| 642 | + content_attrs.push(&font[..]); |
| 643 | + } |
| 644 | + if options.contains(&RenderOption::DarkTheme) { |
| 645 | + graph_attrs.push(r#"bgcolor="black""#); |
| 646 | + content_attrs.push(r#"color="white""#); |
| 647 | + content_attrs.push(r#"fontcolor="white""#); |
| 648 | + } |
| 649 | + if !(graph_attrs.is_empty() && content_attrs.is_empty()) { |
| 650 | + writeln!(w, r#" graph[{}];"#, graph_attrs.join(" "))?; |
| 651 | + let content_attrs_str = content_attrs.join(" "); |
| 652 | + writeln!(w, r#" node[{}];"#, content_attrs_str)?; |
| 653 | + writeln!(w, r#" edge[{}];"#, content_attrs_str)?; |
637 | 654 | }
|
638 | 655 |
|
639 | 656 | for n in g.nodes().iter() {
|
|
0 commit comments