From 134bc27e30f246e8813743a598b17c5bc1cf144b Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Wed, 28 Aug 2024 12:00:56 +0300 Subject: [PATCH 1/4] feat: Improve choropleth map to include configurable geometry border colors --- packages/hurumap-next/src/Map/utils.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/hurumap-next/src/Map/utils.js b/packages/hurumap-next/src/Map/utils.js index 21d347907..0ab31231a 100644 --- a/packages/hurumap-next/src/Map/utils.js +++ b/packages/hurumap-next/src/Map/utils.js @@ -62,7 +62,7 @@ const generateLegend = ( return legend; }; -export const generateChoropleth = (colors, locations, mapType) => { +export const generateChoropleth = (choroplethProps, locations, mapType) => { if (mapType !== "choropleth") return null; const filteredLocations = locations.filter(({ count }) => count !== null); @@ -75,13 +75,14 @@ export const generateChoropleth = (colors, locations, mapType) => { const roundedMaxCount = Math.ceil(maxCount); const negativeColorRange = - colors?.negative_color_range || + choroplethProps?.negative_color_range || defaultChoroplethStyles.negative_color_range; const positiveColorRange = - colors?.positive_color_range || + choroplethProps?.positive_color_range || defaultChoroplethStyles.positive_color_range; - const zeroColor = colors?.zero_color || defaultChoroplethStyles.zero_color; - const opacity = colors?.opacity || defaultChoroplethStyles.opacity; + const zeroColor = + choroplethProps?.zero_color || defaultChoroplethStyles.zero_color; + const opacity = choroplethProps?.opacity || defaultChoroplethStyles.opacity; const positiveThresholds = hasPositiveValues ? calculateThresholds( @@ -125,6 +126,7 @@ export const generateChoropleth = (colors, locations, mapType) => { code, count, fillColor: color, + color: choroplethProps.border_color, opacity, }; }); From c228e0a9b45acb6cf19d1eacd1c6089c2bf702dc Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Wed, 28 Aug 2024 12:56:58 +0300 Subject: [PATCH 2/4] fix: Set default borderColor to color --- packages/hurumap-next/src/Map/utils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/hurumap-next/src/Map/utils.js b/packages/hurumap-next/src/Map/utils.js index 0ab31231a..0930fb51f 100644 --- a/packages/hurumap-next/src/Map/utils.js +++ b/packages/hurumap-next/src/Map/utils.js @@ -83,6 +83,8 @@ export const generateChoropleth = (choroplethProps, locations, mapType) => { const zeroColor = choroplethProps?.zero_color || defaultChoroplethStyles.zero_color; const opacity = choroplethProps?.opacity || defaultChoroplethStyles.opacity; + const borderColor = + choroplethProps.border_color || defaultChoroplethStyles.color; const positiveThresholds = hasPositiveValues ? calculateThresholds( @@ -126,7 +128,7 @@ export const generateChoropleth = (choroplethProps, locations, mapType) => { code, count, fillColor: color, - color: choroplethProps.border_color, + color: borderColor, opacity, }; }); From 917a2c1bace040dd4dbc3e960735b7a98d795a27 Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Wed, 28 Aug 2024 13:33:23 +0300 Subject: [PATCH 3/4] fix: Use configured colors in inactive layers --- packages/hurumap-next/src/Map/Layers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/hurumap-next/src/Map/Layers.js b/packages/hurumap-next/src/Map/Layers.js index 9d9a01f40..0cf39e485 100644 --- a/packages/hurumap-next/src/Map/Layers.js +++ b/packages/hurumap-next/src/Map/Layers.js @@ -75,6 +75,7 @@ function Layers({ const locationCodes = locationCodesProp?.map((c) => c.toUpperCase()) || []; if (!locationCodes?.includes(feature.properties.code.toUpperCase())) { + geoStyles.inactive.color = choropleth[0].color; layer.setStyle(geoStyles.inactive); } else { const popUpContent = (level, name) => From fb1a2bb1c161900102cb278330db24a5467c1ab3 Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Wed, 28 Aug 2024 13:39:09 +0300 Subject: [PATCH 4/4] chore: Use optional chaining (?.) for safe property access --- packages/hurumap-next/src/Map/Layers.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/hurumap-next/src/Map/Layers.js b/packages/hurumap-next/src/Map/Layers.js index 0cf39e485..dd9ba7175 100644 --- a/packages/hurumap-next/src/Map/Layers.js +++ b/packages/hurumap-next/src/Map/Layers.js @@ -75,7 +75,8 @@ function Layers({ const locationCodes = locationCodesProp?.map((c) => c.toUpperCase()) || []; if (!locationCodes?.includes(feature.properties.code.toUpperCase())) { - geoStyles.inactive.color = choropleth[0].color; + geoStyles.inactive.color = + choropleth?.[0]?.color ?? geoStyles.inactive.color; layer.setStyle(geoStyles.inactive); } else { const popUpContent = (level, name) =>