{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "geo-markers",
  "type": "registry:component",
  "title": "Geo Markers",
  "description": "A geo-map layer of places: points in their group's colour and shape with optional names, or bubbles whose area is a number; each read by arrow keys and listed in a table.",
  "categories": [
    "viz"
  ],
  "dependencies": [
    "d3-scale"
  ],
  "devDependencies": [
    "@types/d3-scale"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/chart",
    "@rivier-ui/cn",
    "@rivier-ui/geo-map"
  ],
  "files": [
    {
      "path": "registry/viz/geo-markers.tsx",
      "type": "registry:component",
      "target": "components/viz/geo-markers.tsx",
      "content": "\"use client\";\n/**\n * @name geo-markers\n * @category viz\n * @description A geo-map layer of places: points in their group's colour and shape with optional names, or bubbles whose area is a number; each read by arrow keys and listed in a table.\n * @when Marking sites, cities or events on a map, or comparing counts by place (bubbles: area, never radius, carries the number). For values that belong to whole regions use choropleth; for thousands of points use geo-hexbin. Goes inside geo-map.\n * @example\n * <GeoMap label=\"Our stores\" fit={country}>\n *   <GeoFeatures data={country} />\n *   <GeoMarkers\n *     label=\"Stores\"\n *     points={[\n *       { id: \"a\", name: \"Harbour\", lon: 5.32, lat: 60.39, value: 120 },\n *       { id: \"b\", name: \"Station\", lon: 10.75, lat: 59.91, value: 340 },\n *     ]}\n *     variant=\"bubble\"\n *     valueLabel=\"Visits\"\n *   />\n * </GeoMap>\n */\nimport { scaleSqrt } from \"d3-scale\";\nimport type { ComponentProps } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { ChartMark, chartSeries, formatNumber } from \"@/components/viz/chart\";\nimport { GeoLayer, GeoTable, useGeoMap } from \"@/components/viz/geo-map\";\n\nexport type GeoPoint = {\n  id: string;\n  name: string;\n  lon: number;\n  lat: number;\n  /** A number: the bubble's area, and a row in the tooltip and the table. */\n  value?: number;\n  /** A group: one colour and shape per group, in order of first appearance (or `groups`). */\n  group?: string;\n};\n\nexport type GeoMarkersProps = Omit<ComponentProps<\"g\">, \"children\" | \"points\"> & {\n  /** The layer's name, for screen readers and the table. */\n  label: string;\n  points: readonly GeoPoint[];\n  /** \"point\" marks each place; \"bubble\" sizes it by `value`. */\n  variant?: \"point\" | \"bubble\";\n  groups?: readonly string[];\n  /** Write each place's name beside its mark. Default: when there are 12 or fewer. */\n  showLabels?: boolean;\n  /** The largest bubble's radius in pixels at zoom 1. Default 24. */\n  maxRadius?: number;\n  valueLabel?: string;\n  /** Words for the table's column heads. */\n  labels?: { place: string; group: string; latitude: string; longitude: string };\n  formatValue?: (value: number) => string;\n};\n\nconst LABELS = { place: \"Place\", group: \"Group\", latitude: \"Latitude\", longitude: \"Longitude\" };\n\nexport function GeoMarkers({ label, points, variant = \"point\", groups, showLabels, maxRadius = 24, valueLabel = \"Value\", labels = LABELS, formatValue, className, ...props }: GeoMarkersProps) {\n  const { projection, locale, view } = useGeoMap(\"GeoMarkers\");\n  const number = formatValue ?? ((amount: number) => formatNumber(amount, locale));\n  const order = groups ? [...groups] : [...new Set(points.map((p) => p.group ?? \"\"))];\n  const grouped = order.length > 1 || (order[0] ?? \"\") !== \"\";\n  const radius = scaleSqrt()\n    .domain([0, Math.max(1e-9, ...points.map((p) => Math.max(0, p.value ?? 0)))])\n    .range([0, maxRadius * Math.sqrt(view.k)]);\n  const placed = points.flatMap((point) => {\n    const at = projection([point.lon, point.lat]);\n    return at ? [{ point, x: at[0], y: at[1], group: Math.max(0, order.indexOf(point.group ?? \"\")) }] : [];\n  });\n  // Big bubbles first, so small ones are drawn over them and stay visible.\n  const drawOrder = variant === \"bubble\" ? [...placed.keys()].sort((a, b) => (placed[b]?.point.value ?? 0) - (placed[a]?.point.value ?? 0)) : [...placed.keys()];\n  const labelled = showLabels ?? placed.length <= 12;\n  const coordinate = (value: number): string => formatNumber(value, locale, { maximumFractionDigits: 3 });\n  const items = placed.map((item) => ({\n    x: item.x,\n    y: item.y,\n    title: item.point.name,\n    rows: [\n      ...(grouped ? [{ label: \"\", value: item.point.group ?? \"\", index: item.group < 5 ? item.group : -1, mark: \"rect\" as const }] : []),\n      ...(item.point.value !== undefined ? [{ label: valueLabel, value: number(item.point.value) }] : []),\n    ],\n  }));\n  return (\n    <>\n      <GeoLayer label={label} items={items} className={className} {...props}>\n        {(active, point) => (\n          <g data-slot=\"geo-markers\" aria-hidden=\"true\">\n            {drawOrder.map((index) => {\n              const item = placed[index];\n              if (!item) return null;\n              const colour = grouped ? (item.group < 5 ? item.group : -1) : 0;\n              const dim = active !== null && active !== index;\n              return (\n                <g key={item.point.id} onPointerEnter={() => point(index)} className={cn(\"transition-opacity duration-instant motion-reduce:transition-none\", dim && \"opacity-50\")}>\n                  <circle cx={item.x} cy={item.y} r={Math.max(12, variant === \"bubble\" ? radius(Math.max(0, item.point.value ?? 0)) : 0)} fill=\"transparent\" />\n                  {variant === \"bubble\" ? (\n                    <circle\n                      cx={item.x}\n                      cy={item.y}\n                      r={Math.max(2, radius(Math.max(0, item.point.value ?? 0)))}\n                      className={cn(chartSeries(colour).fill, \"stroke-background\")}\n                      fillOpacity={0.7}\n                      strokeWidth={1.25}\n                    />\n                  ) : (\n                    <ChartMark index={colour} x={item.x} y={item.y} radius={5} />\n                  )}\n                  {labelled ? (\n                    <text x={item.x + 8} y={item.y} dy=\"0.32em\" className=\"fill-foreground stroke-background text-xs\" paintOrder=\"stroke\" strokeWidth={3} strokeLinejoin=\"round\">\n                      {item.point.name}\n                    </text>\n                  ) : null}\n                </g>\n              );\n            })}\n            {active !== null && placed[active] ? (\n              <circle\n                cx={placed[active]?.x}\n                cy={placed[active]?.y}\n                r={(variant === \"bubble\" ? Math.max(2, radius(Math.max(0, placed[active]?.point.value ?? 0))) : 5) + 4}\n                fill=\"none\"\n                className=\"pointer-events-none stroke-foreground\"\n                strokeWidth={2}\n              />\n            ) : null}\n          </g>\n        )}\n      </GeoLayer>\n      <GeoTable\n        caption={label}\n        columns={[labels.place, ...(grouped ? [labels.group] : []), ...(points.some((p) => p.value !== undefined) ? [valueLabel] : []), labels.latitude, labels.longitude]}\n        rows={points.map((p) => [\n          p.name,\n          ...(grouped ? [p.group ?? \"\"] : []),\n          ...(points.some((q) => q.value !== undefined) ? [p.value === undefined ? \"\" : number(p.value)] : []),\n          coordinate(p.lat),\n          coordinate(p.lon),\n        ])}\n      />\n    </>\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "viz",
    "when": "Marking sites, cities or events on a map, or comparing counts by place (bubbles: area, never radius, carries the number). For values that belong to whole regions use choropleth; for thousands of points use geo-hexbin. Goes inside geo-map.",
    "example": "<GeoMap label=\"Our stores\" fit={country}>\n  <GeoFeatures data={country} />\n  <GeoMarkers\n    label=\"Stores\"\n    points={[\n      { id: \"a\", name: \"Harbour\", lon: 5.32, lat: 60.39, value: 120 },\n      { id: \"b\", name: \"Station\", lon: 10.75, lat: 59.91, value: 340 },\n    ]}\n    variant=\"bubble\"\n    valueLabel=\"Visits\"\n  />\n</GeoMap>",
    "client": true
  }
}
