| Crates.io | heatmap_svg |
| lib.rs | heatmap_svg |
| version | 0.1.1 |
| created_at | 2025-06-28 11:29:35.168558+00 |
| updated_at | 2025-06-30 13:52:41.134579+00 |
| description | a package to make svg image heatmaps based on a list of dates |
| homepage | |
| repository | https://codeberg.org/Badacko/heatmap_svg |
| max_upload_size | |
| id | 1729754 |
| size | 45,604 |
a simple crate for creating heatmaps based on a list of dates
like most crates, heatmap_svg is available on crates.io and is thus downloadable via cargo in the cli, u can add it to your project like this
cargo add heatmap_svg
heatmaps are structs with values as fields, u can either specifiy these setting by using the default =Heatmap::new()= method, this generates a default heatmap and is the intended wat of using this package, it contains viable default values for positioning everything and a catppuccin mocha colorscheme, however if u want to it is also possible initialize a Heatmap manually
let mut a = Heatmap {
bg_color: "#1E1E2E",
fg_color: "#CDD6F4",
empty_cell_color: "#45475a",
tier1_cell_color: "#94e2d5",
tier2_cell_color: "#89dceb",
tier3_cell_color: "#74c7ec",
tier4_cell_color: "#b4befe",
tier1_limit: 0,
tier2_limit: 3,
tier3_limit: 6,
tier4_limit: 10,
size: 20,
spacing: 5,
left_offset: 300,
up_offset: 50
};
// is equivalent to the following
let mut b = Heatmap::new();
// and u can edit each field manually
a.bg_color = "#FFFFFF";
b.bg_color = "#FFFFFF";
to create the svg image we need 2 things, a vector of NaiveDates and a path to which we save.
=NaiveDate= is a datatype that is used from the chrono package, and is the date type we use in =heatmap_svg= as well. For more documentation see the [https://docs.rs/chrono/latest/chrono](chrono's docs)
for simplicity sake we will just parse strings to NaiveDates
let a = vec!
["2025-03-11", "2025-03-11",
"2025-03-11", "2025-01-01",
"2025-03-11", "2025-03-30",
"2025-03-11", ]
.iter().map(|x| NaiveDate::parse_from_str(x, "%Y-%m-%d")
.unwrap()).collect();
let hmap = Heatmap::new();
hmap.create_svg(a, "heatmap.svg");
and with that code we have succesfully made an svg image in the root of ur rust project, which u can now view in your browser or whatever tool u prefer!
this examples output is visible in this repo's root dir (note that codeberg doesn't render it correctly, to view right click and open image in new tab)
as of now (28 Jun 2025) the crate is very young and still has quite a decent amount of things that I still need to implement