# Heatmap_svg
a simple crate for creating heatmaps based on a list of dates
## instalation
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
``` shell
cargo add heatmap_svg
```
## usage
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
``` rust
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
``` rust
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)
# planned features
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
- [ ] allow for better formating
- [ ] make a wrapper function that takes in string instead of NaiveDate when
creating an image so that the user doesnt need to worry about using chrono
- [x] allow for limiting how many days should be displayed
- [x] allow a different day-1 when creating the view
- [x] allow ofr a month or week view
- [ ] implement standard features like Copy()