diff --git a/Cargo.toml b/Cargo.toml index d279d5a..66a3ab5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,10 +24,10 @@ fontdue = "0.8.0" image = { version = "0.24.8", features = ["webp-encoder", "avif-encoder"], optional = true } once_cell = "1.19.0" regex = "1.10.3" -resvg = { version = "0.38.0", default-features = false, features = [ "text", "system-fonts" ], optional = true } -serde = { version = "1.0.196", features = ["derive"] } -serde_json = "1.0.113" -snafu = "0.8.0" +resvg = { version = "0.40.0", default-features = false, features = [ "text", "system-fonts" ], optional = true } +serde = { version = "1.0.197", features = ["derive"] } +serde_json = "1.0.114" +snafu = "0.8.1" substring = "1.4.5" [features] diff --git a/asset/table_chart/basic.svg b/asset/table_chart/basic.svg index e509aa0..7f02caf 100644 --- a/asset/table_chart/basic.svg +++ b/asset/table_chart/basic.svg @@ -48,4 +48,5 @@ Gitlab Inc +4.32% + \ No newline at end of file diff --git a/src/charts/component.rs b/src/charts/component.rs index 4242f29..ca6c1cb 100644 --- a/src/charts/component.rs +++ b/src/charts/component.rs @@ -243,8 +243,12 @@ impl Rect { attrs.push((ATTR_STROKE_OPACITY, convert_opacity(&color))); } if let Some(color) = self.fill { - attrs.push((ATTR_FILL, color.hex())); - attrs.push((ATTR_FILL_OPACITY, convert_opacity(&color))); + if color.is_transparent() { + attrs.push((ATTR_FILL, "none".to_string())); + } else { + attrs.push((ATTR_FILL, color.hex())); + attrs.push((ATTR_FILL_OPACITY, convert_opacity(&color))); + } } SVGTag { diff --git a/src/charts/encoder.rs b/src/charts/encoder.rs index 11d3284..e38e1d7 100644 --- a/src/charts/encoder.rs +++ b/src/charts/encoder.rs @@ -2,7 +2,7 @@ use once_cell::sync::OnceCell; use resvg::{tiny_skia, usvg}; use snafu::{ResultExt, Snafu}; use std::io::Cursor; -use usvg::{fontdb, TreeParsing, TreePostProc}; +use usvg::fontdb; #[derive(Debug, Snafu)] pub enum Error { @@ -39,9 +39,9 @@ pub(crate) fn get_or_init_fontdb(fonts: Option>) -> &fontdb::Database fn save_image(svg: &str, format: image::ImageOutputFormat) -> Result> { let fontdb = get_or_init_fontdb(None); - let mut tree = usvg::Tree::from_str(svg, &usvg::Options::default()).context(ParseSnafu {})?; - tree.postprocess(usvg::PostProcessingSteps::default(), fontdb); - let pixmap_size = tree.size.to_int_size(); + let tree = + usvg::Tree::from_str(svg, &usvg::Options::default(), fontdb).context(ParseSnafu {})?; + let pixmap_size = tree.size().to_int_size(); let mut pixmap = tiny_skia::Pixmap::new(pixmap_size.width(), pixmap_size.height()).ok_or(Error::Size { width: pixmap_size.width(), diff --git a/src/charts/table_chart.rs b/src/charts/table_chart.rs index ac17c56..5c46058 100644 --- a/src/charts/table_chart.rs +++ b/src/charts/table_chart.rs @@ -48,6 +48,7 @@ pub struct TableChart { pub spans: Vec, pub text_aligns: Vec, pub border_color: Color, + pub outlined: bool, pub header_row_padding: Box, pub header_row_height: f32, @@ -217,6 +218,9 @@ impl TableChart { if let Some(border_color) = get_color_from_value(&data, "border_color") { self.border_color = border_color; } + if let Some(outlined) = get_bool_from_value(&data, "outlined") { + self.outlined = outlined; + } Ok(data) } /// Creates a table chart from json. @@ -557,7 +561,17 @@ impl TableChart { } top += row_height; } - + if self.outlined { + c.rect(Rect { + color: Some(self.border_color), + fill: Some(Color::transparent()), + left: 1.0, + top: 0.0, + width: c.width() - 1.0, + height: top - 1.0, + ..Default::default() + }); + } c.height = c.margin.top + top; self.height = c.height; @@ -602,6 +616,7 @@ mod tests { background_color: Some("#3bb357".into()), font_color: Some(("#fff").into()), }]; + table_chart.outlined = true; assert_eq!( include_str!("../../asset/table_chart/basic.svg"), table_chart.svg().unwrap()