1 | use crate::graph::*; |
2 | use std::io::{self, Write}; |
3 | use serde::{Deserialize, Serialize}; |
4 | |
5 | /// A collection of graphs. |
6 | #[derive (Deserialize, Serialize)] |
7 | pub struct MultiGraph { |
8 | name: String, |
9 | graphs: Vec<Graph>, |
10 | } |
11 | |
12 | impl MultiGraph { |
13 | pub fn new(name: String, graphs: Vec<Graph>) -> MultiGraph { |
14 | MultiGraph { name, graphs } |
15 | } |
16 | |
17 | pub fn to_dot<W: Write>(&self, w: &mut W, settings: &GraphvizSettings) -> io::Result<()> { |
18 | let subgraphs: bool = self.graphs.len() > 1; |
19 | if subgraphs { |
20 | writeln!(w, "digraph {} {{" , self.name)?; |
21 | } |
22 | |
23 | for graph: &Graph in &self.graphs { |
24 | graph.to_dot(w, settings, as_subgraph:subgraphs)?; |
25 | } |
26 | |
27 | if subgraphs { |
28 | writeln!(w, " }}" )?; |
29 | } |
30 | |
31 | Ok(()) |
32 | } |
33 | } |
34 | |