From 2a035a23f63720f01425b1d6026d082fa782d699 Mon Sep 17 00:00:00 2001 From: Shachar Date: Fri, 23 May 2025 19:00:42 +0300 Subject: [PATCH] Added commit hash to svg --- src/print/svg.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/print/svg.rs b/src/print/svg.rs index 35cba5a..3c1af97 100644 --- a/src/print/svg.rs +++ b/src/print/svg.rs @@ -3,7 +3,8 @@ use crate::graph::GitGraph; use crate::settings::Settings; use svg::node::element::path::Data; -use svg::node::element::{Circle, Line, Path}; +use svg::node::element::{Circle, Line, Path, Text}; +use svg::node::Text as TextNode; use svg::Document; /// Creates a SVG visual representation of a graph. @@ -33,7 +34,7 @@ pub fn print_svg(graph: &GitGraph, settings: &Settings) -> Result max_column { - max_column = branch.visual.column.unwrap(); + max_column = branch.visual.column.unwrap() + 5; // +5 for commit hash } for p in 0..2 { @@ -77,6 +78,7 @@ pub fn print_svg(graph: &GitGraph, settings: &Settings) -> Result Result Text { + let (x, y) = commit_coord(index, 2); + Text::new() + .set("x", x) + .set("y", y) + .set("stroke", "goldenrod") + .set("font-size", 12) + .set("font-family", "open sans") + .set("letter-spacing", 0.75) + .add(TextNode::new(if shorten { &hash[..7] } else { hash })) +} + fn commit_dot(index: usize, column: usize, color: &str, filled: bool) -> Circle { let (x, y) = commit_coord(index, column); Circle::new()