diff --git a/src/graphviz.rs b/src/graphviz.rs index c0ce9cf..7e62ed5 100644 --- a/src/graphviz.rs +++ b/src/graphviz.rs @@ -34,8 +34,8 @@ impl EGraph { } fn to_graphviz(&self) -> Graph { - // 1. Group nodes by typ and class - let mut class_nodes = std::collections::HashMap::new(); + // 1. Group nodes by type and class (use BTreeMap to keep sorted so colors are consistent) + let mut class_nodes = std::collections::BTreeMap::new(); // and create mapping from each node ID to its class let mut node_to_class = std::collections::HashMap::new(); for (node_id, node) in &self.nodes { @@ -81,7 +81,7 @@ impl EGraph { let mut typ_colors = std::collections::HashMap::new(); for (typ, class_to_node) in class_nodes { - let next_color = typ_colors.len() % N_COLORS + INITIAL_COLOR; + let next_color = (typ_colors.len() + INITIAL_COLOR) % N_COLORS; let color = typ_colors.entry(typ).or_insert(next_color); stmts.push(stmt!(attr!("fillcolor", color))); for (class_id, nodes) in class_to_node {