diff --git a/src/main.rs b/src/main.rs index 66c1369..6911170 100644 --- a/src/main.rs +++ b/src/main.rs @@ -98,7 +98,8 @@ pub struct CommitActivityData { pub authors_by_count: Vec, pub oldest: DateTime, pub now: DateTime, - pub max_count: f64, + pub max_total_count: f64, + pub max_author_count: f64, } pub fn process( @@ -118,13 +119,15 @@ pub fn process( 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() { let bin = (*t - oldest).num_weeks() as usize; let author = crate::author_display(c); + timeline[bin].1 += 1.; - if timeline[bin].1 > max_count { - max_count = timeline[bin].1; + if timeline[bin].1 > max_total_count { + max_total_count = timeline[bin].1; } let author_count = count_per_author @@ -135,12 +138,17 @@ pub fn process( let author_timeline = timeline_per_author .get_mut(&author) .expect("unknown author, but we checked them all before?"); + // TODO ugly trick 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 < 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! + 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() { @@ -175,7 +183,8 @@ pub fn process( count_per_author, authors_by_count, oldest, - max_count, + max_total_count, + max_author_count, }) } diff --git a/src/tui.rs b/src/tui.rs index 81cc062..68ea0d6 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -20,6 +20,7 @@ pub fn display(data: crate::CommitActivityData, total: bool, max_authors: usize) // prepare chart widget let mut datasets = Vec::new(); let authors : Vec = 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() { 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(), ]; let y_labels = [ - "0".into(), format!("{}", data.max_count) + "0".into(), format!("{}", y_max) ]; 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() .title(Span::styled("Y Axis", Style::default().fg(Color::Cyan))) .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()) );