import { defineChart } from "@tanstack/charts"
import { geoShape } from "@tanstack/charts/geo"
type ExtendedFeatureCollection,
import { scaleThreshold } from "d3-scale"
import { useEffect, useMemo, useState } from "react"
import { Chart, chartColors } from "@/components/ui/tanstack-chart"
type Country = ExtendedFeature<GeoGeometryObjects, { name: string }>
const projection = { type: geoEqualEarth, fit: "sphere" as const }
export function LearningPovertyMap({ rates }: { rates: Map<string, number> }) {
const [countries, setCountries] =
useState<ExtendedFeatureCollection<Country> | null>(null)
// Your own copy of the countries GeoJSON.
fetch("/maps/world-countries-110m.json")
.then((response) => response.json())
const definition = useMemo(() => {
if (!countries) return null
const measured = countries.features.flatMap((country) => {
const rate = rates.get(country.properties.name)
return rate === undefined
: [{ ...country, properties: { ...country.properties, rate } }]
color: (country) => country.properties.rate,
stroke: chartColors.surface,
scales: { x: null, y: null },
scale: scaleThreshold<number, string>,
domain: [20, 40, 60, 80],
ariaLabel="World map of the share of children who cannot read by age 10"