Skip to content

Commit

Permalink
避免除0
Browse files Browse the repository at this point in the history
  • Loading branch information
vnt-dev committed Jul 7, 2024
1 parent a70b4f3 commit 8ae2049
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common/src/console_out/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ pub fn console_chart_a(chart_a: ChartA) {
let up_max_value = *chart_a.up_map.values().max().unwrap_or(&0);
let down_max_value = *chart_a.down_map.values().max().unwrap_or(&0);
let max_value = up_max_value.max(down_max_value);
let max_value = max_value.max(1);
let max_height = 50;
// 打印条形图
for key in &keys {
Expand Down Expand Up @@ -342,6 +343,7 @@ pub fn console_chart_b(chart_b: ChartB) {
}
fn console_chart_b_list(list: Vec<usize>) {
let max_value = *list.iter().max().unwrap_or(&0);
let max_value = max_value.max(1);
let max_height = max_value.min(20);
// 遍历从最大高度到0
for i in (0..=max_height).rev() {
Expand Down

0 comments on commit 8ae2049

Please sign in to comment.