doxa-maps/library/colors/adoption.js
swift-river542 daa32d4c58
Some checks are pending
Deploy to GitHub Pages / build (push) Waiting to run
Deploy to GitHub Pages / deploy (push) Blocked by required conditions
Research tabs read at 15px; the status red is a step brighter
2026-09-17 02:38:38 -05:00

58 lines
1.5 KiB
JavaScript

/**
* Adoption Color Strategy
*
* Binary: Red (not adopted) / Neon green (has adoption).
* Reads `adoptionStatus` (boolean) normalized from `adopted_by_churches > 0`.
* Transparent circles — overlap accumulates darker.
*
* Sourced from doxa-research-mfe (research wins on drift).
*/
export const PROPERTY_KEY = 'adoptionStatus'
export const PALETTE = {
notAdopted: '#f03b2d', // Red — unified with PRAYER_COLORS.noPrayer
hasAdoption: '#22c55e' // Bright green — easier to see on the adoption map
}
export const ADOPTION_COLORS = PALETTE
export const LABELS = {
notAdopted: 'Needs Adoption',
hasAdopted: 'Has Adoption'
}
export const ADOPTION_LABELS = LABELS
export function getColor(properties) {
const val = properties.adoptionStatus ?? properties._raw?.adopted_by_churches
const adopted = val === true || val === 1 || (typeof val === 'number' && val > 0)
|| (typeof val === 'object' && val?.value)
return adopted ? PALETTE.hasAdoption : PALETTE.notAdopted
}
export function applyColor({ colorSource = 'properties' } = {}) {
const valueExpr = colorSource === 'feature-state'
? ['feature-state', 'adoptionStatus']
: ['get', 'adoptionStatus']
return [
'case',
['==', valueExpr, true], PALETTE.hasAdoption,
['==', valueExpr, 1], PALETTE.hasAdoption,
PALETTE.notAdopted
]
}
export const buildColorExpression = applyColor
export default {
name: 'Adoption Progress',
propertyKey: PROPERTY_KEY,
palette: PALETTE,
colors: PALETTE,
labels: LABELS,
getColor,
applyColor,
buildColorExpression
}