Heatmap colors based on the highest visible number of commits instead of commit number for that day
parent
de4143ed81
commit
6aae792912
|
@ -1,16 +1,17 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use chrono::{DateTime, Datelike, Duration, Local, Utc};
|
||||
use chrono::{DateTime, Datelike, Duration, Local};
|
||||
use clap::ValueEnum;
|
||||
|
||||
use crate::{get_char, get_color, get_color_map, Commit, DAYS, RESET};
|
||||
|
||||
pub struct Heatmap {
|
||||
data: [Vec<u32>; 7],
|
||||
data: [Vec<i32>; 7],
|
||||
start_date: DateTime<Local>,
|
||||
end_date: DateTime<Local>,
|
||||
commits: Vec<Commit>,
|
||||
months: Vec<(usize, String)>,
|
||||
highest_count: i32,
|
||||
}
|
||||
|
||||
impl Heatmap {
|
||||
|
@ -25,6 +26,7 @@ impl Heatmap {
|
|||
end_date,
|
||||
commits,
|
||||
months: vec![],
|
||||
highest_count: 0,
|
||||
};
|
||||
|
||||
let mut grouped_commits = BTreeMap::new();
|
||||
|
@ -36,11 +38,11 @@ impl Heatmap {
|
|||
}
|
||||
|
||||
let mut current_day = start_date;
|
||||
let mut day_of_week = (current_day.weekday().num_days_from_monday()) % 7;
|
||||
let mut day_of_week = current_day.weekday().num_days_from_monday() % 7;
|
||||
|
||||
if day_of_week != 0 {
|
||||
for i in 0..day_of_week {
|
||||
heatmap.data[i as usize].push(0);
|
||||
heatmap.data[i as usize].push(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,10 +60,15 @@ impl Heatmap {
|
|||
|
||||
let value = grouped_commits.get(¤t_day.date_naive());
|
||||
match value {
|
||||
Some(val) => heatmap.data[day_of_week as usize].push(*val),
|
||||
Some(val) => {
|
||||
heatmap.data[day_of_week as usize].push(*val);
|
||||
if *val > heatmap.highest_count {
|
||||
heatmap.highest_count = *val;
|
||||
}
|
||||
}
|
||||
None => heatmap.data[day_of_week as usize].push(0),
|
||||
}
|
||||
// println!("{} {value:?}", current_day.date_naive());
|
||||
// println!("{} {value:?} {highest_count}", current_day.date_naive());
|
||||
current_day += Duration::days(1);
|
||||
day_of_week = current_day.weekday().num_days_from_monday() % 7;
|
||||
}
|
||||
|
@ -97,8 +104,16 @@ impl Heatmap {
|
|||
for (day, row) in DAYS.iter().zip(&self.data) {
|
||||
print!("{day} ");
|
||||
for val in row {
|
||||
let color = &get_color_map()[get_color(*val)];
|
||||
print!("{color}{}{RESET} ", get_char());
|
||||
match val {
|
||||
x if *x >= 0 => {
|
||||
let color = &get_color_map()[get_color(*val, self.highest_count)];
|
||||
print!("{color}{}{RESET} ", get_char());
|
||||
}
|
||||
x if *x < 0 => {
|
||||
print!("{RESET} ");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
print!("\n");
|
||||
}
|
||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -5,7 +5,7 @@
|
|||
use std::{cmp::Reverse, sync::OnceLock};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use chrono::{Date, DateTime, Datelike, Duration, Local, NaiveDate, Offset, TimeZone, Utc};
|
||||
use chrono::{DateTime, Duration, Local};
|
||||
use clap::Parser;
|
||||
use gix::{bstr::ByteSlice, ObjectId, Repository};
|
||||
use heatmap::HeatmapColors;
|
||||
|
@ -28,7 +28,7 @@ const GREEN_COLOR_MAP: [Rgb; 5] = [
|
|||
Rgb(14, 68, 41),
|
||||
Rgb(0, 109, 50),
|
||||
Rgb(38, 166, 65),
|
||||
Rgb(57, 211, 83),
|
||||
Rgb(25, 255, 64),
|
||||
];
|
||||
|
||||
const RED_COLOR_MAP: [Rgb; 5] = [
|
||||
|
@ -76,13 +76,14 @@ fn main() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn get_color(val: u32) -> usize {
|
||||
match val {
|
||||
0 => 0,
|
||||
x if x < 2 => 1,
|
||||
x if x < 4 => 2,
|
||||
x if x < 6 => 3,
|
||||
x if x > 8 => 4,
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue