{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dotted-world-map",
  "type": "registry:ui",
  "title": "Dotted World Map",
  "description": "A dependency-free SVG world map drawn with dots, tinted by heat value. Ships with interactive markers, tooltips, and a GitHub-style legend.",
  "author": "Aditya Ojha <https://akoder.xyz>",
  "categories": [
    "visualization",
    "map",
    "chart",
    "svg"
  ],
  "dependencies": [
    "radix-ui",
    "lucide-react"
  ],
  "registryDependencies": [
    "tooltip"
  ],
  "meta": {
    "docs": "https://akoder.xyz/components/dotted-world-map",
    "source": "https://github.com/AdityaKodez/adityaojha/blob/main/components/ui/dotted-world-map.tsx"
  },
  "files": [
    {
      "path": "components/ui/dotted-world-map.tsx",
      "content": "\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport { Globe } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\nimport { Tooltip, TooltipContent, TooltipTrigger } from \"./tooltip\";\n\n/**\n * A heat source on the map. Declared here rather than in `config/` so the\n * component stays self-contained — it ships through the shadcn registry as a\n * single file with no project-specific imports.\n */\nexport type WorldPoint = {\n  name: string;\n  lat: number;\n  lng: number;\n  /** Heat intensity, 0–1. Drives dot color and marker color. */\n  value: number;\n  /** Heat radius in geographic degrees. */\n  radius?: number;\n  /** Hover/focus detail for the point marker. Defaults to name + activity score. */\n  tooltip?: string;\n  /** Optional ISO 3166-1 alpha-2 country code for the tooltip flag. */\n  countryCode?: string;\n};\n\nconst DEFAULT_COLORS = [\n  \"#22c55e\",\n  \"#84cc16\",\n  \"#eab308\",\n  \"#f97316\",\n  \"#ef4444\",\n];\n\n// Natural Earth country geometry, sampled on a 120 × 60 equirectangular grid.\n// Keeping the land mask as ranges lets the map remain dependency-free while the\n// inactive dots follow coastlines instead of filling the SVG rectangle.\nconst LAND_RANGES: ReadonlyArray<ReadonlyArray<readonly [number, number]>> = [\n  [],\n  [],\n  [\n    [31, 39],\n    [44, 53],\n  ],\n  [\n    [28, 35],\n    [38, 54],\n    [64, 66],\n    [67, 68],\n    [91, 93],\n  ],\n  [\n    [19, 21],\n    [23, 24],\n    [26, 27],\n    [28, 34],\n    [37, 53],\n    [82, 83],\n    [94, 97],\n  ],\n  [\n    [19, 21],\n    [24, 25],\n    [26, 31],\n    [32, 34],\n    [41, 53],\n    [78, 79],\n    [87, 100],\n    [101, 102],\n    [107, 108],\n  ],\n  [\n    [6, 10],\n    [22, 26],\n    [28, 29],\n    [30, 37],\n    [42, 51],\n    [68, 70],\n    [82, 84],\n    [85, 113],\n  ],\n  [\n    [0, 1],\n    [5, 33],\n    [34, 35],\n    [36, 39],\n    [42, 49],\n    [65, 74],\n    [76, 84],\n    [85, 120],\n  ],\n  [\n    [6, 33],\n    [34, 38],\n    [43, 46],\n    [53, 55],\n    [64, 67],\n    [68, 119],\n  ],\n  [\n    [5, 29],\n    [34, 36],\n    [44, 46],\n    [62, 66],\n    [67, 112],\n    [113, 114],\n    [115, 118],\n  ],\n  [\n    [8, 9],\n    [14, 29],\n    [34, 37],\n    [38, 39],\n    [58, 59],\n    [62, 63],\n    [64, 66],\n    [68, 107],\n    [113, 114],\n  ],\n  [\n    [16, 31],\n    [34, 40],\n    [58, 59],\n    [64, 65],\n    [67, 105],\n    [112, 114],\n  ],\n  [\n    [17, 33],\n    [34, 41],\n    [57, 58],\n    [59, 108],\n    [112, 113],\n  ],\n  [\n    [19, 38],\n    [59, 108],\n  ],\n  [\n    [19, 38],\n    [59, 70],\n    [71, 72],\n    [73, 77],\n    [78, 106],\n    [107, 108],\n  ],\n  [\n    [19, 37],\n    [57, 58],\n    [59, 62],\n    [63, 69],\n    [73, 76],\n    [77, 105],\n    [107, 108],\n  ],\n  [\n    [19, 35],\n    [57, 60],\n    [65, 68],\n    [70, 77],\n    [78, 100],\n    [101, 103],\n  ],\n  [\n    [19, 35],\n    [57, 60],\n    [64, 65],\n    [67, 68],\n    [69, 77],\n    [78, 101],\n    [102, 103],\n    [106, 107],\n  ],\n  [\n    [20, 34],\n    [58, 63],\n    [72, 100],\n    [104, 106],\n  ],\n  [\n    [21, 33],\n    [57, 65],\n    [67, 69],\n    [72, 101],\n    [103, 104],\n  ],\n  [\n    [23, 28],\n    [32, 33],\n    [56, 71],\n    [72, 76],\n    [77, 101],\n  ],\n  [\n    [24, 28],\n    [55, 77],\n    [80, 100],\n  ],\n  [\n    [25, 27],\n    [33, 34],\n    [55, 72],\n    [73, 80],\n    [83, 90],\n    [91, 98],\n  ],\n  [\n    [25, 28],\n    [30, 31],\n    [36, 37],\n    [55, 72],\n    [74, 79],\n    [84, 88],\n    [91, 95],\n    [96, 97],\n  ],\n  [\n    [27, 31],\n    [54, 73],\n    [74, 78],\n    [84, 87],\n    [91, 96],\n    [100, 101],\n  ],\n  [\n    [30, 32],\n    [54, 76],\n    [85, 87],\n    [93, 96],\n  ],\n  [\n    [31, 32],\n    [35, 38],\n    [39, 40],\n    [55, 77],\n    [85, 87],\n    [95, 96],\n  ],\n  [\n    [34, 40],\n    [56, 77],\n    [101, 102],\n  ],\n  [\n    [34, 43],\n    [57, 58],\n    [62, 76],\n    [92, 93],\n    [98, 100],\n  ],\n  [\n    [34, 43],\n    [63, 75],\n    [93, 95],\n    [96, 99],\n  ],\n  [\n    [33, 45],\n    [63, 74],\n    [94, 95],\n    [97, 99],\n    [100, 101],\n    [104, 105],\n  ],\n  [\n    [33, 47],\n    [64, 73],\n    [94, 95],\n    [105, 108],\n  ],\n  [\n    [33, 48],\n    [64, 73],\n    [96, 98],\n    [106, 109],\n  ],\n  [\n    [34, 48],\n    [64, 73],\n  ],\n  [\n    [35, 47],\n    [64, 74],\n    [76, 77],\n    [103, 105],\n    [107, 108],\n  ],\n  [\n    [36, 47],\n    [64, 73],\n    [75, 77],\n    [101, 106],\n    [107, 109],\n  ],\n  [\n    [37, 47],\n    [64, 72],\n    [75, 76],\n    [100, 109],\n  ],\n  [\n    [37, 46],\n    [65, 72],\n    [74, 76],\n    [98, 110],\n  ],\n  [\n    [36, 44],\n    [65, 71],\n    [98, 111],\n  ],\n  [\n    [36, 44],\n    [65, 71],\n    [98, 111],\n  ],\n  [\n    [36, 43],\n    [66, 70],\n    [99, 111],\n  ],\n  [\n    [36, 42],\n    [66, 67],\n    [99, 100],\n    [106, 110],\n  ],\n  [\n    [35, 41],\n    [107, 110],\n    [118, 119],\n  ],\n  [\n    [35, 39],\n    [118, 119],\n  ],\n  [\n    [36, 38],\n    [117, 118],\n  ],\n  [\n    [35, 38],\n    [116, 117],\n  ],\n  [[35, 37]],\n  [[35, 37]],\n  [],\n  [],\n  [],\n  [[39, 40]],\n  [\n    [37, 38],\n    [76, 80],\n    [87, 109],\n  ],\n  [\n    [36, 39],\n    [62, 63],\n    [64, 67],\n    [68, 83],\n    [84, 114],\n  ],\n  [\n    [19, 20],\n    [26, 27],\n    [28, 32],\n    [33, 34],\n    [36, 40],\n    [55, 116],\n  ],\n  [\n    [11, 37],\n    [51, 115],\n  ],\n  [\n    [6, 7],\n    [10, 34],\n    [43, 46],\n    [50, 114],\n  ],\n  [\n    [9, 40],\n    [42, 115],\n  ],\n  [[10, 11]],\n  [],\n];\nconst ANTARCTICA_START_ROW = 50;\n\nexport type DottedWorldMapPoint = WorldPoint;\n\nexport type DottedWorldMapProps = {\n  /** Heat sources. Higher values make nearby land dots warmer. */\n  points: WorldPoint[];\n  colors?: string[];\n  /** Color of low-intensity land dots. Defaults to the first color in the scale. */\n  baseColor?: string;\n  dotRadius?: number;\n  spacing?: number;\n  /** Width in dots. */\n  cols?: number;\n  /** Height in dots. */\n  rows?: number;\n  /** Opacity of all land dots. */\n  baseOpacity?: number;\n  /** Render an interactive marker with tooltip for every point. */\n  showMarkers?: boolean;\n  /** Show a GitHub-style color legend below the map. */\n  showLegend?: boolean;\n  /** Labels at the low/high ends of the legend. */\n  legendLabels?: { low?: string; high?: string };\n  className?: string;\n};\n\nexport function DottedWorldMap({\n  points,\n  colors = DEFAULT_COLORS,\n  baseColor,\n  dotRadius = 1.7,\n  spacing = 6,\n  cols = 120,\n  rows = 60,\n  baseOpacity = 0.2,\n  showMarkers = true,\n  showLegend = true,\n  legendLabels,\n  className,\n}: DottedWorldMapProps) {\n  const width = cols * spacing;\n  const height = rows * spacing;\n  const colorScale = colors.length > 0 ? colors : DEFAULT_COLORS;\n  const lowColor = baseColor ?? colorScale[0] ?? \"currentColor\";\n\n  const heatPaths = useMemo(\n    () =>\n      computeHeatPaths({\n        cols,\n        rows,\n        spacing,\n        dotRadius,\n        points,\n        colorCount: colorScale.length,\n      }),\n    [cols, rows, spacing, dotRadius, points, colorScale.length],\n  );\n\n  const markers = useMemo(\n    () =>\n      showMarkers\n        ? points\n            .filter((point) => point.value >= 0.02)\n            .map((point) => {\n              const x = ((point.lng + 180) / 360) * width;\n              const y = ((90 - point.lat) / 180) * height;\n              const clamped = Math.min(1, Math.max(0, point.value));\n              const colorIndex = Math.min(\n                colorScale.length - 1,\n                Math.round(clamped * (colorScale.length - 1)),\n              );\n              const markerColor = colorScale[colorIndex] ?? lowColor;\n              const label =\n                point.tooltip ??\n                `${point.name} · activity ${Math.round(clamped * 100)}/100`;\n              return { point, x, y, markerColor, label };\n            })\n        : [],\n    [showMarkers, points, width, height, colorScale, lowColor],\n  );\n\n  return (\n    <div className=\"flex w-full flex-col gap-2\">\n      <svg\n        viewBox={`0 0 ${width} ${height}`}\n        role=\"img\"\n        aria-label=\"World heatmap\"\n        className={cn(\"h-full w-full select-none\", className)}\n        preserveAspectRatio=\"xMidYMid meet\"\n      >\n        {heatPaths.map((path, index) => (\n          <path\n            key={colorScale[index] ?? index}\n            d={path}\n            fill={index === 0 ? lowColor : (colorScale[index] ?? lowColor)}\n            opacity={baseOpacity}\n            aria-hidden=\"true\"\n          />\n        ))}\n        {markers.map(({ point, x, y, markerColor, label }) => (\n          <Tooltip key={point.name}>\n            <TooltipTrigger asChild>\n              <g\n                tabIndex={0}\n                aria-label={label}\n                className=\"cursor-pointer outline-none\"\n              >\n                {/* Invisible hit target for reliable hover/focus. */}\n                <circle\n                  cx={x}\n                  cy={y}\n                  r={Math.max(dotRadius * 3.2, 6)}\n                  fill=\"transparent\"\n                />\n                <circle\n                  cx={x}\n                  cy={y}\n                  r={dotRadius * 2.6}\n                  fill={markerColor}\n                  opacity={0.25}\n                  aria-hidden=\"true\"\n                />\n                <circle\n                  cx={x}\n                  cy={y}\n                  r={dotRadius * 1.4}\n                  fill={markerColor}\n                  aria-hidden=\"true\"\n                />\n              </g>\n            </TooltipTrigger>\n            <TooltipContent>\n              {point.countryCode !== undefined ? (\n                <CountryFlag code={point.countryCode} />\n              ) : null}\n              <p>{label}</p>\n            </TooltipContent>\n          </Tooltip>\n        ))}\n      </svg>\n      {showLegend ? (\n        <div className=\"flex items-center justify-end gap-1.5 text-[10px] text-muted-foreground\">\n          <span>{legendLabels?.low ?? \"Less\"}</span>\n          {colorScale.map((color, index) => (\n            <span\n              key={index}\n              aria-hidden=\"true\"\n              className=\"h-2 w-2 rounded-[2px]\"\n              style={{ backgroundColor: color }}\n            />\n          ))}\n          <span>{legendLabels?.high ?? \"More\"}</span>\n        </div>\n      ) : null}\n    </div>\n  );\n}\n\nfunction CountryFlag({ code }: { code: string }) {\n  const [failedCode, setFailedCode] = useState<string | null>(null);\n\n  if (failedCode === code || !/^[A-Z]{2}$/.test(code)) {\n    return <Globe aria-hidden=\"true\" className=\"size-4 shrink-0\" strokeWidth={1.8} />;\n  }\n\n  return (\n    // The CDN serves SVG flags directly, without the Next.js image optimizer.\n    // eslint-disable-next-line @next/next/no-img-element\n    <img\n      src={`https://flagcdn.com/${code.toLowerCase()}.svg`}\n      alt=\"\"\n      width={20}\n      height={15}\n      className=\"max-h-4 w-5 shrink-0 object-contain\"\n      onError={() => setFailedCode(code)}\n    />\n  );\n}\n\nfunction computeHeatPaths({\n  cols,\n  rows,\n  spacing,\n  dotRadius,\n  points,\n  colorCount,\n}: {\n  cols: number;\n  rows: number;\n  spacing: number;\n  dotRadius: number;\n  points: WorldPoint[];\n  colorCount: number;\n}): string[] {\n  const dots = Array.from({ length: colorCount }, () => [] as string[]);\n\n  for (let row = 0; row < rows; row++) {\n    const sourceRowIndex = Math.floor(\n      ((row + 0.5) / rows) * LAND_RANGES.length,\n    );\n    if (sourceRowIndex >= ANTARCTICA_START_ROW) continue;\n\n    const sourceRow = LAND_RANGES[sourceRowIndex] ?? [];\n    for (let col = 0; col < cols; col++) {\n      const sourceCol = Math.floor(((col + 0.5) / cols) * 120);\n      if (\n        !sourceRow.some(([start, end]) => sourceCol >= start && sourceCol < end)\n      )\n        continue;\n\n      const x = col * spacing + spacing / 2;\n      const y = row * spacing + spacing / 2;\n      const lat = 90 - ((row + 0.5) / rows) * 180;\n      const lng = -180 + ((col + 0.5) / cols) * 360;\n      const intensity = calculateHeatIntensity(lat, lng, points);\n      const colorIndex = Math.min(\n        colorCount - 1,\n        Math.round(intensity * (colorCount - 1)),\n      );\n      dots[colorIndex]?.push(\n        `M${x - dotRadius},${y}a${dotRadius},${dotRadius} 0 1,0 ${dotRadius * 2},0a${dotRadius},${dotRadius} 0 1,0 -${dotRadius * 2},0`,\n      );\n    }\n  }\n\n  return dots.map((group) => group.join(\"\"));\n}\n\nfunction calculateHeatIntensity(\n  lat: number,\n  lng: number,\n  points: WorldPoint[],\n): number {\n  return Math.min(\n    1,\n    points.reduce((total, point) => {\n      const lngDistance = Math.abs(lng - point.lng);\n      const wrappedLngDistance = Math.min(lngDistance, 360 - lngDistance);\n      const x = wrappedLngDistance * Math.cos((lat * Math.PI) / 180);\n      const y = lat - point.lat;\n      const radius = point.radius ?? 18;\n      return total + point.value * Math.exp(-(x * x + y * y) / (2 * radius * radius));\n    }, 0),\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "docs": "## Installation\n\n```bash\nnpx shadcn@latest add @akoder/dotted-world-map\n```\n\n## Usage\n\n```tsx\nimport { DottedWorldMap } from \"@/components/ui/dotted-world-map\";\n\nconst points = [\n  { name: \"London\", countryCode: \"GB\", lat: 51.5074, lng: -0.1278, value: 0.9, radius: 12 },\n  { name: \"Tokyo\", countryCode: \"JP\", lat: 35.6762, lng: 139.6503, value: 0.8, radius: 12 },\n  { name: \"New York\", countryCode: \"US\", lat: 40.7128, lng: -74.006, value: 0.95, radius: 13 },\n];\n\nexport function VisitorsMap() {\n  return <DottedWorldMap points={points} />;\n}\n```\n\n`countryCode` is optional and uses uppercase ISO 3166-1 alpha-2 codes. Invalid codes or failed flag images show a globe. Omit it for text-only tooltips. If your site uses a Content Security Policy, allow https://flagcdn.com in img-src."
}