heatmap_svg 0.1.0

a package to make svg image heatmaps based on a list of dates
Documentation
  • Coverage
  • 94.74%
    18 out of 19 items documented0 out of 3 items with examples
  • Size
  • Source code size: 50.15 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.46 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 22s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • LunaKITPI
  • 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

#+begin_src shell cargo add heatmap_svg #+end_src

** usage

heatmaps are structs with values as fields, u can either specifiy these settings 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

#+begin_src 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"; #+end_src

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

#+begin_src 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");

#+end_src

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
    • allow for limiting how many days should be displayed
    • allow a different day-1 when creating the view
    • allow ofr a month or week view
    • implement standard features like Copy()