From 55ea09f872ef67da0016ee127ee7094db3ed1cd8 Mon Sep 17 00:00:00 2001 From: Lucas Westermann Date: Tue, 17 Dec 2024 09:58:41 -0500 Subject: [PATCH 1/2] fix: don't set round_count to a fixed value Instead, use maximum theoretical value, or 5 (as fallback) --- asset/radar_chart/basic_json.svg | 5 +++ chart-test-output.svg | 69 ++++++++++++++++++++++++++++++++ src/charts/radar_chart.rs | 3 +- 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 chart-test-output.svg diff --git a/asset/radar_chart/basic_json.svg b/asset/radar_chart/basic_json.svg index f6699c7..f917b66 100644 --- a/asset/radar_chart/basic_json.svg +++ b/asset/radar_chart/basic_json.svg @@ -14,10 +14,15 @@ Allocated Budget Actual Spending + + + + + Sales diff --git a/chart-test-output.svg b/chart-test-output.svg new file mode 100644 index 0000000..f917b66 --- /dev/null +++ b/chart-test-output.svg @@ -0,0 +1,69 @@ + + + + + + +Allocated Budget + + + + + + +Actual Spending + + + + + + + + + + + + + +Sales + + + +Administration + + + +Information Technology + + + +Customer Support + + + +Development + + + +Marketing + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/charts/radar_chart.rs b/src/charts/radar_chart.rs index f4f9953..83a698e 100644 --- a/src/charts/radar_chart.rs +++ b/src/charts/radar_chart.rs @@ -198,7 +198,8 @@ impl RadarChart { let angle = 360.0 / indicators.len() as f32; let cx = c.width() / 2.0; let cy = c.height() / 2.0; - let round_count = 5; + let max_value = indicators.iter().map(|indicator| indicator.max as i32).max().unwrap_or(5); + let round_count = (2..=10).filter(|round_option| max_value % round_option == 0).max().unwrap_or(5); for i in 1..=round_count { let ir = r / round_count as f32 * i as f32; let mut points = vec![]; From 14e01afcbaff24c731ba04c7d3d511398a053ff8 Mon Sep 17 00:00:00 2001 From: Lucas Westermann Date: Tue, 17 Dec 2024 15:00:32 -0500 Subject: [PATCH 2/2] chore: fixed example data for tests Fixes change of grids after new round_count calculation --- asset/multi_chart/basic.svg | 5 +++++ asset/radar_chart/basic.svg | 5 +++++ asset/radar_chart/five_points.svg | 5 +++++ asset/radar_chart/four_points.svg | 5 +++++ asset/radar_chart/seven_points.svg | 5 +++++ asset/radar_chart/three_points.svg | 5 +++++ 6 files changed, 30 insertions(+) diff --git a/asset/multi_chart/basic.svg b/asset/multi_chart/basic.svg index d652760..863966a 100644 --- a/asset/multi_chart/basic.svg +++ b/asset/multi_chart/basic.svg @@ -457,10 +457,15 @@ Allocated Budget Actual Spending + + + + + Sales diff --git a/asset/radar_chart/basic.svg b/asset/radar_chart/basic.svg index f6699c7..f917b66 100644 --- a/asset/radar_chart/basic.svg +++ b/asset/radar_chart/basic.svg @@ -14,10 +14,15 @@ Allocated Budget Actual Spending + + + + + Sales diff --git a/asset/radar_chart/five_points.svg b/asset/radar_chart/five_points.svg index b520f51..0977a1c 100644 --- a/asset/radar_chart/five_points.svg +++ b/asset/radar_chart/five_points.svg @@ -14,10 +14,15 @@ Allocated Budget Actual Spending + + + + + Sales diff --git a/asset/radar_chart/four_points.svg b/asset/radar_chart/four_points.svg index 5a36916..f7a499a 100644 --- a/asset/radar_chart/four_points.svg +++ b/asset/radar_chart/four_points.svg @@ -14,10 +14,15 @@ Allocated Budget Actual Spending + + + + + Sales diff --git a/asset/radar_chart/seven_points.svg b/asset/radar_chart/seven_points.svg index 3e642dc..4347c7d 100644 --- a/asset/radar_chart/seven_points.svg +++ b/asset/radar_chart/seven_points.svg @@ -14,10 +14,15 @@ Allocated Budget Actual Spending + + + + + Sales diff --git a/asset/radar_chart/three_points.svg b/asset/radar_chart/three_points.svg index 150c7d1..decbcc8 100644 --- a/asset/radar_chart/three_points.svg +++ b/asset/radar_chart/three_points.svg @@ -14,10 +14,15 @@ Allocated Budget Actual Spending + + + + + Sales