From a09bcc1ec86c748cf89e5ba8dfe0c67c71e4489e Mon Sep 17 00:00:00 2001 From: Saif Khan <2001559@sit.singaporetech.edu.sg> Date: Tue, 27 May 2025 10:01:20 +0800 Subject: [PATCH 1/3] Change to color all uncolored regions to gray if only some have colors --- .../belgium_population_by_region_2022.csv | 4 ++-- src/inset_state/auto_color.cpp | 23 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/sample_data/belgium_by_region_since_1995/belgium_population_by_region_2022.csv b/sample_data/belgium_by_region_since_1995/belgium_population_by_region_2022.csv index bb275034..5b876339 100644 --- a/sample_data/belgium_by_region_since_1995/belgium_population_by_region_2022.csv +++ b/sample_data/belgium_by_region_since_1995/belgium_population_by_region_2022.csv @@ -1,4 +1,4 @@ shapeName,Population (people),Color,Inset,Label -Brussels-Capital,1222637,#fbb4ae,, -Flanders,6698876,#b3cde3,, +Brussels-Capital,1222637,,, +Flanders,6698876,,, Wallonia,3662495,#ccebc5,, diff --git a/src/inset_state/auto_color.cpp b/src/inset_state/auto_color.cpp index 6a9558d5..4a559c15 100644 --- a/src/inset_state/auto_color.cpp +++ b/src/inset_state/auto_color.cpp @@ -11,18 +11,12 @@ void InsetState::auto_color() std::vector palette; if (colors_.size() > 0) { - // If some colors are already provided, use a different palette - // From https://colorbrewer2.org/#type=qualitative&scheme=Dark2&n=8 - std::cerr << "Some but not all colors provided, using Dark color palette." + // If some but not all of the GeoDivs are colored, use only #f2f2f2 (light + // gray) to color the rest + std::cerr << "Some but not all colors provided, assigning #f2f2f2 (light " + "grey) to uncolored GeoDivs." << std::endl; - palette.emplace_back("#1b9e77"); // aqua green - palette.emplace_back("#d95f02"); // dark orange - palette.emplace_back("#7570b3"); // purple - palette.emplace_back("#e7298a"); // dark pink - palette.emplace_back("#66a61e"); // olive green - palette.emplace_back("#e6ab02"); // dark yellow - palette.emplace_back("#a6761d"); // brown - palette.emplace_back("#666666"); // dark grey + palette.emplace_back("#f2f2f2"); // light gray } else { // Using default palette for now // TODO: Accept palette from user @@ -48,6 +42,13 @@ void InsetState::auto_color() if (color_found(gd.id())) continue; + // If there's only one color in palette, color the div with it without + // checking for color adjacency + if (palette.size() == 1) { + insert_color(gd.id(), palette[0]); + continue; + } + for (unsigned int i = 0; i < palette.size(); ++i) { const Color c = palette[i]; bool shared_color = false; From e95d26b2a729b8f44850e3ca4c15f700a9711f6b Mon Sep 17 00:00:00 2001 From: Saif Khan <2001559@sit.singaporetech.edu.sg> Date: Tue, 27 May 2025 10:49:35 +0800 Subject: [PATCH 2/3] Fix to _C file postfix when there's only one inset --- src/cartogram_info/cartogram_info.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cartogram_info/cartogram_info.cpp b/src/cartogram_info/cartogram_info.cpp index 08762d12..e6f12824 100644 --- a/src/cartogram_info/cartogram_info.cpp +++ b/src/cartogram_info/cartogram_info.cpp @@ -448,7 +448,12 @@ void CartogramInfo::write_svg(const std::string &suffix) for (const InsetState &inset_state : inset_states_) { inset_names += inset_state.pos(); } - insets_combined.write_map( - map_name_ + "_" + inset_names + "_" + suffix, - false); + // Only attach inset names to filename if there's more than inset + if (n_insets() > 1) { + insets_combined.write_map( + map_name_ + "_" + inset_names + "_" + suffix, + false); + } else { + insets_combined.write_map(map_name_ + "_" + suffix, false); + } } \ No newline at end of file From b9f62044cacfdb3ede2f4d6e773c84d893a90c8a Mon Sep 17 00:00:00 2001 From: adisidev <64905594+adisidev@users.noreply.github.com> Date: Thu, 29 May 2025 13:15:08 +0800 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/cartogram_info/cartogram_info.cpp | 2 +- src/inset_state/auto_color.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cartogram_info/cartogram_info.cpp b/src/cartogram_info/cartogram_info.cpp index e6f12824..c95c11ff 100644 --- a/src/cartogram_info/cartogram_info.cpp +++ b/src/cartogram_info/cartogram_info.cpp @@ -448,7 +448,7 @@ void CartogramInfo::write_svg(const std::string &suffix) for (const InsetState &inset_state : inset_states_) { inset_names += inset_state.pos(); } - // Only attach inset names to filename if there's more than inset + // Only attach inset names to filename if there's more than one inset if (n_insets() > 1) { insets_combined.write_map( map_name_ + "_" + inset_names + "_" + suffix, diff --git a/src/inset_state/auto_color.cpp b/src/inset_state/auto_color.cpp index 4a559c15..87ec5e64 100644 --- a/src/inset_state/auto_color.cpp +++ b/src/inset_state/auto_color.cpp @@ -14,7 +14,7 @@ void InsetState::auto_color() // If some but not all of the GeoDivs are colored, use only #f2f2f2 (light // gray) to color the rest std::cerr << "Some but not all colors provided, assigning #f2f2f2 (light " - "grey) to uncolored GeoDivs." + "gray) to uncolored GeoDivs." << std::endl; palette.emplace_back("#f2f2f2"); // light gray } else {