fix: max total and max author

This commit is contained in:
əlemi 2024-02-09 19:51:45 +01:00
parent 070e3428f7
commit 1ad66a9ff1
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 17 additions and 7 deletions

View file

@ -98,7 +98,8 @@ pub struct CommitActivityData {
pub authors_by_count: Vec<String>, pub authors_by_count: Vec<String>,
pub oldest: DateTime<Utc>, pub oldest: DateTime<Utc>,
pub now: DateTime<Utc>, pub now: DateTime<Utc>,
pub max_count: f64, pub max_total_count: f64,
pub max_author_count: f64,
} }
pub fn process( pub fn process(
@ -118,13 +119,15 @@ pub fn process(
count_per_author.insert(author, 0); count_per_author.insert(author, 0);
} }
let mut max_count = 0.; let mut max_total_count = 0.;
let mut max_author_count = 0.;
for (t, c) in commits.values() { for (t, c) in commits.values() {
let bin = (*t - oldest).num_weeks() as usize; let bin = (*t - oldest).num_weeks() as usize;
let author = crate::author_display(c); let author = crate::author_display(c);
timeline[bin].1 += 1.; timeline[bin].1 += 1.;
if timeline[bin].1 > max_count { if timeline[bin].1 > max_total_count {
max_count = timeline[bin].1; max_total_count = timeline[bin].1;
} }
let author_count = count_per_author let author_count = count_per_author
@ -135,12 +138,17 @@ pub fn process(
let author_timeline = timeline_per_author let author_timeline = timeline_per_author
.get_mut(&author) .get_mut(&author)
.expect("unknown author, but we checked them all before?"); .expect("unknown author, but we checked them all before?");
// TODO ugly trick // TODO ugly trick
if author_timeline[bin].1 < 0. { author_timeline[bin].1 = 0. }; if author_timeline[bin].1 < 0. { author_timeline[bin].1 = 0. };
if bin > 0 && author_timeline[bin-1].1 < 0. { author_timeline[bin-1].1 = 0. }; if bin > 0 && author_timeline[bin-1].1 < 0. { author_timeline[bin-1].1 = 0. };
if bin < author_timeline.len() - 1 && author_timeline[bin+1].1 < 0. { author_timeline[bin+1].1 = 0. }; if bin < author_timeline.len() - 1 && author_timeline[bin+1].1 < 0. { author_timeline[bin+1].1 = 0. };
// TODO these are needed to "hide" zero lines in TUI and avoid overlaps, ew! // TODO these are needed to "hide" zero lines in TUI and avoid overlaps, ew!
author_timeline[bin].1 += 1.; author_timeline[bin].1 += 1.;
if author_timeline[bin].1 > max_author_count {
max_author_count = author_timeline[bin].1;
}
} }
for (_name, author_d) in timeline_per_author.iter_mut() { for (_name, author_d) in timeline_per_author.iter_mut() {
@ -175,7 +183,8 @@ pub fn process(
count_per_author, count_per_author,
authors_by_count, authors_by_count,
oldest, oldest,
max_count, max_total_count,
max_author_count,
}) })
} }

View file

@ -20,6 +20,7 @@ pub fn display(data: crate::CommitActivityData, total: bool, max_authors: usize)
// prepare chart widget // prepare chart widget
let mut datasets = Vec::new(); let mut datasets = Vec::new();
let authors : Vec<String> = data.authors_by_count.iter().take(max_authors).cloned().collect(); let authors : Vec<String> = data.authors_by_count.iter().take(max_authors).cloned().collect();
let y_max = if total { data.max_total_count } else { data.max_author_count };
for name in data.authors_by_count.iter() { for name in data.authors_by_count.iter() {
let author_d = data.timeline_per_author.get(name).expect("author in list has no data"); let author_d = data.timeline_per_author.get(name).expect("author in list has no data");
@ -52,7 +53,7 @@ pub fn display(data: crate::CommitActivityData, total: bool, max_authors: usize)
Utc::now().date_naive().format("%Y/%m/%d").to_string(), Utc::now().date_naive().format("%Y/%m/%d").to_string(),
]; ];
let y_labels = [ let y_labels = [
"0".into(), format!("{}", data.max_count) "0".into(), format!("{}", y_max)
]; ];
let x_max = Utc::now().timestamp() as f64; let x_max = Utc::now().timestamp() as f64;
@ -69,7 +70,7 @@ pub fn display(data: crate::CommitActivityData, total: bool, max_authors: usize)
.y_axis(Axis::default() .y_axis(Axis::default()
.title(Span::styled("Y Axis", Style::default().fg(Color::Cyan))) .title(Span::styled("Y Axis", Style::default().fg(Color::Cyan)))
.style(Style::default().fg(Color::White)) .style(Style::default().fg(Color::White))
.bounds([-0.0, data.max_count + 1.]) .bounds([-0.0, y_max + 1.])
.labels(y_labels.iter().map(Span::from).collect()) .labels(y_labels.iter().map(Span::from).collect())
); );