diff options
Diffstat (limited to 'server/tools/src/diagram_dot.rs')
-rw-r--r-- | server/tools/src/diagram_dot.rs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/server/tools/src/diagram_dot.rs b/server/tools/src/diagram_dot.rs index b3e54881..f86a2d4e 100644 --- a/server/tools/src/diagram_dot.rs +++ b/server/tools/src/diagram_dot.rs @@ -19,7 +19,7 @@ use anyhow::{Result, bail}; use hurrycurry_protocol::{ Gamedata, Message, - book::{Diagram, NodeStyle}, + book::{Diagram, DiagramNode, NodeStyle}, }; use std::{ fmt::Write, @@ -27,6 +27,8 @@ use std::{ process::{Command, Stdio}, }; +use crate::diagram_svg::{edge_color, node_color}; + pub fn diagram_dot_svg(data: &Gamedata, diagram: &Diagram) -> Result<String> { let mut child = Command::new("dot") .arg("-Tsvg") @@ -52,7 +54,7 @@ pub fn diagram_dot(data: &Gamedata, diagram: &Diagram, use_position: bool) -> Re if use_position { attrs.push(format!("pos=\"{},{}!\"", n.position.x, n.position.y)); } - node_style(&mut attrs, &n.style); + node_style(&mut attrs, &n); match &n.label { Message::Text(text) => { attrs.push(format!("label=\"{text}\"")); @@ -84,20 +86,22 @@ pub fn diagram_dot(data: &Gamedata, diagram: &Diagram, use_position: bool) -> Re writeln!(out, "k{i} [{}]", attrs.join(" "))?; } for edge in &diagram.edges { - writeln!(out, "k{} -> k{}", edge.src, edge.dst)?; + let color = edge_color(edge); + writeln!(out, "k{} -> k{} [color=\"{color}\"]", edge.src, edge.dst)?; } writeln!(out, "}}")?; Ok(out) } -fn node_style(attrs: &mut Vec<String>, style: &NodeStyle) { - let (shape, color) = match style { - NodeStyle::FinalProduct => ("circle", "#555"), - NodeStyle::IntermediateProduct => ("circle", "#333"), - NodeStyle::ProcessActive => ("box", "#47c42b"), - NodeStyle::ProcessPassive => ("box", "#c4a32b"), - NodeStyle::ProcessInstant => ("box", "#5452d8"), +fn node_style(attrs: &mut Vec<String>, node: &DiagramNode) { + let shape = match node.style { + NodeStyle::FinalProduct => "circle", + NodeStyle::IntermediateProduct => "circle", + NodeStyle::ProcessActive => "box", + NodeStyle::ProcessPassive => "box", + NodeStyle::ProcessInstant => "box", }; + let color = node_color(node); attrs.push(format!("shape={shape}")); attrs.push("style=filled".to_owned()); attrs.push(format!("fillcolor=\"{color}\"")); |