Added a new config for coloring based on amount or weight

master
Wynd 2024-08-20 00:07:19 +03:00
parent cbb5d07cb4
commit f2e52f3815
4 changed files with 44 additions and 11 deletions

View File

@ -45,13 +45,19 @@ $ git-heatmap -r "/path/to/repo" -b "main" -r "other/repo" -b ""
# by default merges are counted so using --no-merges ensures they won't be counted
$ git-heatmap --no-merges
# by default it colors every day on a per number of commits basis with --counting by-weight
# it will color the days based on the number of commits in that day vs
# the maximum number of commits in a day that is visible
$ git-heatmap --counting by-weight
# filter by one or multiple authors
# without an -a flag all authors will be checked
$ git-heatmap -a "username" -a "other"
# choose from when to start the checking
# if no --since flag is given it will start the search one year from the current date
# if no --until date is given it will check for either 365 days since the start date or until the current day, depending on which one is closer
# if no --until date is given it will check for either 365 days since the start date or
# until the current day, depending on which one is closer
$ git-heatmap --since "2013-08-23"
# or choose a time span, both --since and --until must use a YYYY-MM-DD format

View File

@ -3,7 +3,7 @@ use std::path::PathBuf;
use chrono::{Duration, Local};
use clap::{arg, Parser, ValueHint};
use crate::heatmap::HeatmapColors;
use crate::heatmap::{ColorLogic, HeatmapColors};
#[derive(Clone, Debug, Parser, PartialEq, Eq)]
#[command(version, about, long_about = None)]
@ -31,6 +31,9 @@ pub struct CliArgs {
#[arg(long("no-merges"), default_value_t = false)]
pub no_merges: bool,
#[arg(long("counting"), value_enum, default_value_t = ColorLogic::ByAmount)]
pub counting: ColorLogic,
}
fn get_since_date() -> String {

View File

@ -138,3 +138,10 @@ pub enum HeatmapColors {
Green,
Red,
}
#[derive(Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum ColorLogic {
ByAmount,
ByWeight,
}

View File

@ -8,7 +8,7 @@ use anyhow::{anyhow, Context, Result};
use chrono::{DateTime, Duration, Local, NaiveDate, TimeZone};
use clap::Parser;
use gix::{bstr::ByteSlice, traverse::commit::simple::Sorting, ObjectId};
use heatmap::HeatmapColors;
use heatmap::{ColorLogic, HeatmapColors};
use itertools::Itertools;
use mailmap::Mailmap;
use rgb::Rgb;
@ -24,6 +24,7 @@ pub const ESCAPE: &str = "\x1B";
pub const RESET: &str = "\x1B[0m";
pub const DAYS: [&str; 7] = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
pub static CHAR: OnceLock<char> = OnceLock::new();
static COLOR_LOGIC: OnceLock<ColorLogic> = OnceLock::new();
pub static COLOR_MAP: OnceLock<Vec<String>> = OnceLock::new();
const GREEN_COLOR_MAP: [Rgb; 5] = [
@ -64,6 +65,7 @@ fn main() -> Result<()> {
// dbg!(&args);
CHAR.set(args.char).unwrap();
COLOR_LOGIC.set(args.counting.clone()).unwrap();
let color_map = match args.color_scheme {
HeatmapColors::Green => GREEN_COLOR_MAP,
HeatmapColors::Red => RED_COLOR_MAP,
@ -100,14 +102,29 @@ fn get_default_until(since: NaiveDate) -> String {
}
fn get_color(val: i32, high: i32) -> usize {
let color = val as f32 / high as f32;
match color {
0.0 => 0,
x if x <= 0.2 => 1,
x if x <= 0.4 => 2,
x if x <= 0.8 => 3,
x if x > 0.8 => 4,
_ => 0,
match COLOR_LOGIC.get() {
Some(logic) => match logic {
ColorLogic::ByAmount => match val {
0 => 0,
x if x < 2 => 1,
x if x < 4 => 2,
x if x < 6 => 3,
x if x > 6 => 4,
_ => 0,
},
ColorLogic::ByWeight => {
let color = val as f32 / high as f32;
match color {
0.0 => 0,
x if x <= 0.2 => 1,
x if x <= 0.4 => 2,
x if x <= 0.8 => 3,
x if x > 0.8 => 4,
_ => 0,
}
}
},
None => 0,
}
}