diff options
Diffstat (limited to 'server/tools/src/diagram_svg.rs')
-rw-r--r-- | server/tools/src/diagram_svg.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/server/tools/src/diagram_svg.rs b/server/tools/src/diagram_svg.rs index 0fc75668..fe3d9de4 100644 --- a/server/tools/src/diagram_svg.rs +++ b/server/tools/src/diagram_svg.rs @@ -19,7 +19,7 @@ use anyhow::Result; use hurrycurry_protocol::{ Gamedata, Message, - book::{Diagram, DiagramNode, NodeStyle}, + book::{Diagram, DiagramEdge, DiagramNode, EdgeStyle, NodeStyle}, glam::Vec2, }; use std::fmt::Write; @@ -80,16 +80,18 @@ pub fn diagram_svg(data: &Gamedata, diagram: &Diagram) -> Result<String> { let tip2 = dst + (dir + dir.perp() * -0.5) * 10.; dst += dir * 5.; // prevent miter line cap from peeking out + let color = edge_color(edge); + // line path writeln!( out, - r#"<path fill="none" stroke="black" stroke-width="2" d="M{} {} L{} {}" />"#, + r#"<path fill="none" stroke="{color}" stroke-width="2" d="M{} {} L{} {}" />"#, src.x, src.y, dst.x, dst.y, )?; // tip path writeln!( out, - r#"<path fill="black" stroke="none" d="M{} {} L{} {} L{} {} Z" />"#, + r#"<path fill="{color}" stroke="none" d="M{} {} L{} {} L{} {} Z" />"#, tip0.x, tip0.y, tip1.x, tip1.y, tip2.x, tip2.y )?; } @@ -110,7 +112,7 @@ fn node_edge_connect_pos(src: &DiagramNode, dst: &DiagramNode) -> Vec2 { } } -fn node_color(node: &DiagramNode) -> &'static str { +pub(crate) fn node_color(node: &DiagramNode) -> &'static str { match node.style { NodeStyle::FinalProduct => "#555", NodeStyle::IntermediateProduct => "#333", @@ -119,6 +121,12 @@ fn node_color(node: &DiagramNode) -> &'static str { NodeStyle::ProcessInstant => "#5452d8", } } +pub(crate) fn edge_color(edge: &DiagramEdge) -> &'static str { + match edge.style { + EdgeStyle::Regular => "#000000", + EdgeStyle::ProcessPassive => "#c4a32b", + } +} fn image_node(out: &mut String, node: &DiagramNode, path: String) -> Result<()> { if matches!( |