Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/inset_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class InsetState
nlohmann::json inset_to_geojson(bool, bool = false) const;

// Function to go from equal area to cartogram
void integrate(ProgressTracker &);
void integrate(ProgressTracker &, size_t n_insets);

std::vector<Segment> intersecting_segments(unsigned int) const;
std::vector<std::vector<intersection>> intersec_with_parallel_to(
Expand Down
Original file line number Diff line number Diff line change
@@ -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,,
25 changes: 15 additions & 10 deletions src/cartogram_info/cartogram_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ void CartogramInfo::preprocess()
}

if (args_.export_preprocessed) {

// Output rescaled GeoJSON
write_geojson("input_processed");

// processed = simplified + rescaled
// and potentially projected + small polygons removed

Expand Down Expand Up @@ -196,7 +198,7 @@ void CartogramInfo::replace_missing_and_zero_target_areas()
double total_start_area_with_data = 0.0;
double total_target_area_with_data = 0.0;
for (const InsetState &inset_state : inset_states_) {
for (const auto &gd : inset_state.geo_divs()) {
for (const GeoDiv &gd : inset_state.geo_divs()) {
if (!inset_state.target_area_is_missing(gd.id())) {
total_start_area_with_data += gd.area();
total_target_area_with_data += inset_state.target_area_at(gd.id());
Expand All @@ -221,7 +223,7 @@ void CartogramInfo::replace_missing_and_zero_target_areas()
bool small_target_area_exists = false;
bool missing_target_area_exists = false;
for (InsetState &inset_state : inset_states_) {
for (const auto &gd : inset_state.geo_divs()) {
for (const GeoDiv &gd : inset_state.geo_divs()) {
const double target_area = inset_state.target_area_at(gd.id());
inset_state.insert_whether_input_target_area_is_missing(
gd.id(),
Expand Down Expand Up @@ -253,7 +255,7 @@ void CartogramInfo::replace_missing_and_zero_target_areas()
<< std::endl;
double min_positive_area = dbl_inf;
for (const InsetState &inset_state : inset_states_) {
for (const auto &gd : inset_state.geo_divs()) {
for (const GeoDiv &gd : inset_state.geo_divs()) {
min_positive_area = std::min(min_positive_area, gd.area());
}
}
Expand All @@ -262,7 +264,7 @@ void CartogramInfo::replace_missing_and_zero_target_areas()

// Replace the small target areas
for (InsetState &inset_state : inset_states_) {
for (const auto &gd : inset_state.geo_divs()) {
for (const GeoDiv &gd : inset_state.geo_divs()) {

// Current target area
const double target_area = inset_state.target_area_at(gd.id());
Expand Down Expand Up @@ -295,7 +297,7 @@ void CartogramInfo::replace_missing_and_zero_target_areas()

// Assign new target areas to GeoDivs
for (InsetState &inset_state : inset_states_) {
for (const auto &gd : inset_state.geo_divs()) {
for (const GeoDiv &gd : inset_state.geo_divs()) {
if (inset_state.target_area_is_missing(gd.id())) {
double new_target_area;

Expand Down Expand Up @@ -403,7 +405,7 @@ InsetState CartogramInfo::convert_to_inset_state()
InsetState new_inset_state("", args_);

for (const InsetState &inset_state : inset_states_) {
for (const auto &geo_div : inset_state.geo_divs()) {
for (const GeoDiv &geo_div : inset_state.geo_divs()) {
new_inset_state.push_back(geo_div);
new_inset_state.insert_color(
geo_div.id(),
Expand Down Expand Up @@ -448,7 +450,10 @@ 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 generate inset-named map if there's more than one inset
if (n_insets() > 1) {
insets_combined.write_map(
map_name_ + "_" + inset_names + "_" + suffix,
false);
}
}
25 changes: 12 additions & 13 deletions src/inset_state/auto_color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ void InsetState::auto_color()
std::vector<Color> 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 "
"gray) 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
for (GeoDiv &gd : geo_divs_) {
if (!color_found(gd.id())) {
insert_color(gd.id(), Color("#f2f2f2"));
}
}
return;
} else {
// Using default palette for now
// TODO: Accept palette from user
Expand All @@ -43,7 +42,7 @@ void InsetState::auto_color()
create_contiguity_graph();

// Iterate until we are able to color the entire map
for (const auto &gd : geo_divs_) {
for (const GeoDiv &gd : geo_divs_) {
// If div already has a provided color, move to the next div
if (color_found(gd.id()))
continue;
Expand All @@ -53,7 +52,7 @@ void InsetState::auto_color()
bool shared_color = false;

// Check whether adjacent GeoDivs have the same color
for (const auto &gd_id : gd.adjacent_geodivs()) {
for (const std::string &gd_id : gd.adjacent_geodivs()) {
if (color_found(gd_id)) {
if (color_at(gd_id) == c) {
shared_color = true;
Expand Down
8 changes: 6 additions & 2 deletions src/inset_state/integrate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void InsetState::cleanup_after_integration()
ref_to_fluxy_init().free();
}

void InsetState::integrate(ProgressTracker &progress_tracker)
void InsetState::integrate(ProgressTracker &progress_tracker, size_t n_insets)
{

timer.start(inset_name_);
Expand Down Expand Up @@ -135,7 +135,11 @@ void InsetState::integrate(ProgressTracker &progress_tracker)

// Write SVG for this inset, if requested
if (args_.plot_polygons) {
write_map(inset_name() + "_output", args_.plot_grid, false);
if (n_insets > 1) {
write_map(inset_name() + "_output", args_.plot_grid, false);
} else {
write_map(inset_name() + "_cartogram", args_.plot_grid, false);
}
}

// Project original map with cumulative projection
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(const int argc, const char *argv[])

// Iterate over insets and integrate each one
for (InsetState &inset_state : cart_info.ref_to_inset_states()) {
inset_state.integrate(progress_tracker);
inset_state.integrate(progress_tracker, cart_info.n_insets());
}

// Rescale insets in correct proportion to each other
Expand Down