Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

feat(dotted-map) : Add marker overlay support to DottedMap (#862)

Yeom-JinHo60a956dbaaea
diff --git a/apps/www/content/docs/components/dotted-map.mdx b/apps/www/content/docs/components/dotted-map.mdx
index 0fff0995..d8b5698b 100644
--- a/apps/www/content/docs/components/dotted-map.mdx
+++ b/apps/www/content/docs/components/dotted-map.mdx
@@ -1,8 +1,8 @@
---
title: Dotted Map
-date: 2025-09-25
+date: 2025-12-31
description: A component with a svg dotted map.
-author: dillionverma
+author: dillionverma, Yeom-JinHo
published: true
---
@@ -46,10 +46,14 @@ npx shadcn@latest add @magicui/dotted-map
<ComponentPreview name="dotted-map-demo-2" />
+### PulseMarker
+
+<ComponentPreview name="dotted-map-demo-3" />
+
## Usage
```tsx showLineNumbers
-import { DottedMap } from "@/components/ui/dotted-map"
+import { DottedMap, type Marker } from "@/components/ui/dotted-map"
```
```tsx showLineNumbers
@@ -58,16 +62,83 @@ import { DottedMap } from "@/components/ui/dotted-map"
</div>
```
+### With Custom Markers
+
+```tsx showLineNumbers
+import { DottedMap, type Marker } from "@/components/ui/dotted-map"
+import type { TCountryCode } from "countries-list"
+
+type CountryCode = Lowercase<TCountryCode>
+
+type MyMarker = Marker & {
+ overlay: {
+ countryCode: CountryCode
+ label: string
+ }
+}
+
+const markers: MyMarker[] = [
+ {
+ lat: 37.5665,
+ lng: 126.978,
+ size: 2.8,
+ overlay: { countryCode: "kr", label: "Seoul" },
+ },
+]
+
+<DottedMap<MyMarker>
+ markers={markers}
+ renderMarkerOverlay={({ marker, x, y, r }) => {
+ // Custom overlay rendering
+ return <text x={x} y={y}>{marker.overlay.label}</text>
+ }}
+/>
+```
+
## Props
-| Prop | Type | Default | Description |
-| ------------- | --------------------- | ----------- | ----------------------------------------------------- |
-| `width` | `number` | `150` | Width of the SVG map. |
-| `height` | `number` | `75` | Height of the SVG map. |
-| `mapSamples` | `number` | `5500` | Number of sample points for map generation. |
-| `markers` | `Marker[]` | `[]` | Array of markers to display on the map. |
-| `dotColor` | `string` | `undefined` | Color of the map dots (uses currentColor if not set). |
-| `markerColor` | `string` | `"#FF6900"` | Color of the markers. |
-| `dotRadius` | `number` | `0.22` | Radius of the map dots. |
-| `className` | `string` | `undefined` | Additional class names applied to the SVG. |
-| `style` | `React.CSSProperties` | `undefined` | Inline styles merged into the SVG. |
+| Prop | Type | Default | Description |
+| --------------------- | --------------------- | ----------- | -------------------------------------------------------------- |
+| `width` | `number` | `150` | Width of the SVG map. |
+| `height` | `number` | `75` | Height of the SVG map. |
+| `mapSamples` | `number` | `5000` | Number of sample points for map generation. |
+| `markers` | `Marker[]` | `[]` | Array of markers to display on the map. |
+| `dotColor` | `string` | `undefined` | Color of the map dots (uses currentColor if not set). |
+| `markerColor` | `string` | `"#FF6900"` | Color of the markers. |
+| `dotRadius` | `number` | `0.2` | Radius of the map dots. |
+| `stagger` | `boolean` | `true` | Whether to stagger dots in alternating rows for visual effect. |
+| `pulse` | `boolean` | `false` | Enables built-in pulse animation for markers. |
+| `renderMarkerOverlay` | `(args) => ReactNode` | `undefined` | Custom render function for marker overlays. |
+| `className` | `string` | `undefined` | Additional class names applied to the SVG. |
+| `style` | `React.CSSProperties` | `undefined` | Inline styles merged into the SVG. |
+
+## Types
+
+### Marker
+
+```tsx
+export interface Marker {
+ lat: number
+ lng: number
+ size?: number
+ pulse?: boolean
+}
+```
+
+Set `pulse` on `DottedMap` to animate all markers (and use `marker.pulse = false` to opt out per marker). Without the `pulse` prop, only markers with `marker.pulse = true` will pulse.
+
+The `DottedMap` component supports generic types, allowing you to extend the `Marker` interface with custom properties:
+
+```tsx
+import type { TCountryCode } from "countries-list"
+
+type CountryCode = Lowercase<TCountryCode>
+
+type MyMarker = Marker & {
+ overlay: {
+ countryCode: CountryCode
+ label: string
+ }
+}
+;<DottedMap<MyMarker> markers={markers} />
+```
diff --git a/apps/www/package.json b/apps/www/package.json
index bb7e8bbb..efc7c6e9 100644
--- a/apps/www/package.json
+++ b/apps/www/package.json
@@ -48,6 +48,7 @@
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
"cobe": "^0.6.4",
+ "countries-list": "^3.2.2",
"fumadocs-core": "^15.8.2",
"fumadocs-mdx": "^12.0.1",
"fumadocs-ui": "^15.7.12",
diff --git a/apps/www/public/llms-full.txt b/apps/www/public/llms-full.txt
index 272fb778..a0f339e2 100644
--- a/apps/www/public/llms-full.txt
+++ b/apps/www/public/llms-full.txt
@@ -6293,40 +6293,61 @@ import { createMap } from "svg-dotted-map"
import { cn } from "@/lib/utils"
-interface Marker {
+export interface Marker {
lat: number
lng: number
size?: number
+ pulse?: boolean
}
-export interface DottedMapProps extends React.SVGProps<SVGSVGElement> {
+/** addMarkers returns markers with lat/lng removed; only x, y and other props (e.g. size) remain */
+type MapMarker<M extends Marker> = Omit<M, "lat" | "lng"> & {
+ x: number
+ y: number
+}
+
+export interface DottedMapProps<
+ M extends Marker = Marker,
+> extends React.SVGProps<SVGSVGElement> {
width?: number
height?: number
mapSamples?: number
- markers?: Marker[]
+ markers?: M[]
dotColor?: string
markerColor?: string
dotRadius?: number
stagger?: boolean
+ pulse?: boolean
+
+ renderMarkerOverlay?: (args: {
+ marker: MapMarker<M>
+ index: number
+ x: number
+ y: number
+ r: number
+ }) => React.ReactNode
}
-export function DottedMap({
+export function DottedMap<M extends Marker = Marker>({
width = 150,
height = 75,
mapSamples = 5000,
markers = [],
+ dotColor = "currentColor",
markerColor = "#FF6900",
dotRadius = 0.2,
stagger = true,
+ pulse = false,
+ renderMarkerOverlay,
className,
style,
-}: DottedMapProps) {
+ ...svgProps
+}: DottedMapProps<M>) {
const { points, addMarkers } = createMap({
width,
height,
mapSamples,
})
-
const processedMarkers = addMarkers(markers)
// Compute stagger helpers in a single, simple pass
@@ -6359,6 +6380,7 @@ export function DottedMap({
viewBox={`0 0 ${width} ${height}`}
className={cn("text-gray-500 dark:text-gray-500", className)}
style={{ width: "100%", height: "100%", ...style }}
+ {...svgProps}
>
{points.map((point, index) => {
const rowIndex = yToRowIndex.get(point.y) ?? 0
@@ -6368,22 +6390,87 @@ export function DottedMap({
cx={point.x + offsetX}
cy={point.y}
r={dotRadius}
- fill="currentColor"
+ fill={dotColor}
key={`${point.x}-${point.y}-${index}`}
/>
)
})}
+
{processedMarkers.map((marker, index) => {
const rowIndex = yToRowIndex.get(marker.y) ?? 0
const offsetX = stagger && rowIndex % 2 === 1 ? xStep / 2 : 0
+
+ const x = marker.x + offsetX
+ const y = marker.y
+ const r = marker.size ?? dotRadius
+ const shouldPulse = pulse
+ ? marker.pulse !== false
+ : marker.pulse === true
+ const pulseTo = r * 2.8
+
return (
- <circle
- cx={marker.x + offsetX}
- cy={marker.y}
- r={marker.size ?? dotRadius}
- fill={markerColor}
- key={`${marker.x}-${marker.y}-${index}`}
- />
+ <g key={`${marker.x}-${marker.y}-${index}`}>
+ <circle cx={x} cy={y} r={r} fill={markerColor} />
+
+ {shouldPulse ? (
+ <g pointerEvents="none">
+ <circle
+ cx={x}
+ cy={y}
+ r={r}
+ fill="none"
+ stroke={markerColor}
+ strokeOpacity={1}
+ strokeWidth={0.35}
+ >
+ <animate
+ attributeName="r"
+ values={`${r};${pulseTo}`}
+ dur="1.4s"
+ repeatCount="indefinite"
+ />
+ <animate
+ attributeName="opacity"
+ values="1;0"
+ dur="1.4s"
+ repeatCount="indefinite"
+ />
+ </circle>
+ <circle
+ cx={x}
+ cy={y}
+ r={r}
+ fill="none"
+ stroke={markerColor}
+ strokeOpacity={0.9}
+ strokeWidth={0.3}
+ >
+ <animate
+ attributeName="r"
+ values={`${r};${pulseTo}`}
+ dur="1.4s"
+ begin="0.7s"
+ repeatCount="indefinite"
+ />
+ <animate
+ attributeName="opacity"
+ values="0.9;0"
+ dur="1.4s"
+ begin="0.7s"
+ repeatCount="indefinite"
+ />
+ </circle>
+ </g>
+ ) : null}
+
+ {renderMarkerOverlay?.({
+ marker: { ...marker, x, y },
+ index,
+ x,
+ y,
+ r,
+ })}
+ </g>
)
})}
</svg>
@@ -6395,91 +6482,92 @@ export function DottedMap({
Title: Dotted Map Demo
--- file: example/dotted-map-demo.tsx ---
+import * as React from "react"
+import type { TCountryCode } from "countries-list"
+
import { DottedMap } from "@/registry/magicui/dotted-map"
+import type { Marker } from "@/registry/magicui/dotted-map"
+
+type CountryCode = Lowercase<TCountryCode>
-const markers = [
+type MyMarker = Marker & {
+ overlay: {
+ countryCode: CountryCode
+ label: string
+ }
+}
+
+const markers: MyMarker[] = [
+ {
+ lat: 37.5665,
+ lng: 126.978,
+ size: 2.8,
+ overlay: { countryCode: "kr", label: "Seoul" },
+ },
{
lat: 40.7128,
lng: -74.006,
- size: 0.3,
- }, // New York
- {
- lat: 34.0522,
- lng: -118.2437,
- size: 0.3,
- }, // Los Angeles
- {
- lat: 51.5074,
- lng: -0.1278,
- size: 0.3,
- }, // London
- {
- lat: -33.8688,
- lng: 151.2093,
- size: 0.3,
- }, // Sydney
- {
- lat: 48.8566,
- lng: 2.3522,
- size: 0.3,
- }, // Paris
- {
- lat: 35.6762,
- lng: 139.6503,
- size: 0.3,
- }, // Tokyo
- {
- lat: 55.7558,
- lng: 37.6176,
- size: 0.3,
- }, // Moscow
- {
- lat: 39.9042,
- lng: 116.4074,
- size: 0.3,
- }, // Beijing
- {
- lat: 28.6139,
- lng: 77.209,
- size: 0.3,
- }, // New Delhi
- {
- lat: -23.5505,
- lng: -46.6333,
- size: 0.3,
- }, // São Paulo
- {
- lat: 1.3521,
- lng: 103.8198,
- size: 0.3,
- }, // Singapore
- {
- lat: 25.2048,
- lng: 55.2708,
- size: 0.3,
- }, // Dubai
- {
- lat: 52.52,
- lng: 13.405,
- size: 0.3,
- }, // Berlin
- {
- lat: 19.4326,
- lng: -99.1332,
- size: 0.3,
- }, // Mexico City
- {
- lat: -26.2041,
- lng: 28.0473,
- size: 0.3,
- }, // Johannesburg
+ size: 2.8,
+ overlay: { countryCode: "us", label: "NYC" },
+ },
]
export default function Component() {
+ const id = React.useId()
return (
<div className="relative h-[500px] w-full overflow-hidden rounded-lg border">
- <div className="to-background absolute inset-0 bg-radial from-transparent to-70%" />
- <DottedMap markers={markers} />
+ <div className="to-background absolute inset-0 bg-radial from-transparent to-200%" />
+ <DottedMap<MyMarker>
+ markers={markers}
+ renderMarkerOverlay={({ marker, x, y, r, index }) => {
+ const { countryCode, label } = marker.overlay
+ const href = `https://flagcdn.com/w80/${countryCode}.webp` // FlagCDN [oai_citation:7‡Flagpedia](https://flagpedia.net/download/api)
+
+ const clipId = `${id}-flag-clip-${index}`.replace(/:/g, "-")
+ const imgR = r * 0.75
+
+ const fontSize = r * 0.9
+ const pillH = r * 1.5
+ const pillW = label.length * (fontSize * 0.62) + r * 1.4
+ const pillX = x + r + r * 0.6
+ const pillY = y - pillH / 2
+
+ return (
+ <g style={{ pointerEvents: "none" }}>
+ <clipPath id={clipId}>
+ <circle cx={x} cy={y} r={imgR} />
+ </clipPath>
+
+ <image
+ href={href}
+ x={x - imgR}
+ y={y - imgR}
+ width={imgR * 2}
+ height={imgR * 2}
+ preserveAspectRatio="xMidYMid slice"
+ clipPath={`url(#${clipId})`}
+ />
+
+ <rect
+ x={pillX}
+ y={pillY}
+ width={pillW}
+ height={pillH}
+ rx={pillH / 2}
+ fill="rgba(0,0,0,0.55)"
+ />
+ <text
+ x={pillX + r * 0.7}
+ y={y + fontSize * 0.35}
+ fontSize={fontSize}
+ fill="white"
+ >
+ {label}
+ </text>
+ </g>
+ )
+ }}
+ />
</div>
)
}
@@ -6500,6 +6588,37 @@ export default function Component() {
}
+===== EXAMPLE: dotted-map-demo-3 =====
+Title: Dotted Map Demo 3
+
+--- file: example/dotted-map-demo-3.tsx ---
+import { DottedMap } from "@/registry/magicui/dotted-map"
+import type { Marker } from "@/registry/magicui/dotted-map"
+
+const markers: Marker[] = [
+ {
+ lat: 37.5665,
+ lng: 126.978,
+ size: 0.3,
+ },
+ {
+ lat: 40.7128,
+ lng: -74.006,
+ size: 0.3,
+ pulse: false,
+ },
+]
+
+export default function Component() {
+ return (
+ <div className="relative h-[500px] w-full overflow-hidden rounded-lg border">
+ <div className="to-background absolute inset-0 bg-radial from-transparent to-200%" />
+ <DottedMap markers={markers} pulse />
+ </div>
+ )
+}
+
+
===== COMPONENT: file-tree =====
Title: File Tree
diff --git a/apps/www/public/llms.txt b/apps/www/public/llms.txt
index 7eba6fc9..6257d84c 100644
--- a/apps/www/public/llms.txt
+++ b/apps/www/public/llms.txt
@@ -215,6 +215,7 @@ This file provides LLM-friendly entry points to documentation and examples.
- [light-rays-demo](https://github.com/magicuidesign/magicui/blob/main/example/light-rays-demo.tsx): Example usage
- [Dotted Map Demo](https://github.com/magicuidesign/magicui/blob/main/example/dotted-map-demo.tsx): Example usage
- [Dotted Map Demo 2](https://github.com/magicuidesign/magicui/blob/main/example/dotted-map-demo-2.tsx): Example usage
+- [Dotted Map Demo 3](https://github.com/magicuidesign/magicui/blob/main/example/dotted-map-demo-3.tsx): Example usage
## Optional
diff --git a/apps/www/public/r/dotted-map-demo-3.json b/apps/www/public/r/dotted-map-demo-3.json
new file mode 100644
index 00000000..989b3783
--- /dev/null
+++ b/apps/www/public/r/dotted-map-demo-3.json
@@ -0,0 +1,17 @@
+{
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "dotted-map-demo-3",
+ "type": "registry:example",
+ "title": "Dotted Map Demo 3",
+ "description": "Example showing a dotted map with pulse animation.",
+ "registryDependencies": [
+ "@magicui/dotted-map"
+ ],
+ "files": [
+ {
+ "path": "registry/example/dotted-map-demo-3.tsx",
+ "content": "import { DottedMap } from \"@/registry/magicui/dotted-map\"\nimport type { Marker } from \"@/registry/magicui/dotted-map\"\n\nconst markers: Marker[] = [\n {\n lat: 37.5665,\n lng: 126.978,\n size: 0.3,\n },\n {\n lat: 40.7128,\n lng: -74.006,\n size: 0.3,\n pulse: false,\n },\n]\n\nexport default function Component() {\n return (\n <div className=\"relative h-[500px] w-full overflow-hidden rounded-lg border\">\n <div className=\"to-background absolute inset-0 bg-radial from-transparent to-200%\" />\n <DottedMap markers={markers} pulse />\n </div>\n )\n}\n",
+ "type": "registry:example"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/apps/www/public/r/dotted-map-demo.json b/apps/www/public/r/dotted-map-demo.json
index 6f0c8af4..bb7b9f76 100644
--- a/apps/www/public/r/dotted-map-demo.json
+++ b/apps/www/public/r/dotted-map-demo.json
@@ -4,13 +4,16 @@
"type": "registry:example",
"title": "Dotted Map Demo",
"description": "Example showing a dotted map.",
+ "dependencies": [
+ "countries-list"
+ ],
"registryDependencies": [
"@magicui/dotted-map"
],
"files": [
{
"path": "registry/example/dotted-map-demo.tsx",
- "content": "import { DottedMap } from \"@/registry/magicui/dotted-map\"\n\nconst markers = [\n {\n lat: 40.7128,\n lng: -74.006,\n size: 0.3,\n }, // New York\n {\n lat: 34.0522,\n lng: -118.2437,\n size: 0.3,\n }, // Los Angeles\n {\n lat: 51.5074,\n lng: -0.1278,\n size: 0.3,\n }, // London\n {\n lat: -33.8688,\n lng: 151.2093,\n size: 0.3,\n }, // Sydney\n {\n lat: 48.8566,\n lng: 2.3522,\n size: 0.3,\n }, // Paris\n {\n lat: 35.6762,\n lng: 139.6503,\n size: 0.3,\n }, // Tokyo\n {\n lat: 55.7558,\n lng: 37.6176,\n size: 0.3,\n }, // Moscow\n {\n lat: 39.9042,\n lng: 116.4074,\n size: 0.3,\n }, // Beijing\n {\n lat: 28.6139,\n lng: 77.209,\n size: 0.3,\n }, // New Delhi\n {\n lat: -23.5505,\n lng: -46.6333,\n size: 0.3,\n }, // São Paulo\n {\n lat: 1.3521,\n lng: 103.8198,\n size: 0.3,\n }, // Singapore\n {\n lat: 25.2048,\n lng: 55.2708,\n size: 0.3,\n }, // Dubai\n {\n lat: 52.52,\n lng: 13.405,\n size: 0.3,\n }, // Berlin\n {\n lat: 19.4326,\n lng: -99.1332,\n size: 0.3,\n }, // Mexico City\n {\n lat: -26.2041,\n lng: 28.0473,\n size: 0.3,\n }, // Johannesburg\n]\n\nexport default function Component() {\n return (\n <div className=\"relative h-[500px] w-full overflow-hidden rounded-lg border\">\n <div className=\"to-background absolute inset-0 bg-radial from-transparent to-70%\" />\n <DottedMap markers={markers} />\n </div>\n )\n}\n",
+ "content": "import * as React from \"react\"\nimport type { TCountryCode } from \"countries-list\"\n\nimport { DottedMap } from \"@/registry/magicui/dotted-map\"\nimport type { Marker } from \"@/registry/magicui/dotted-map\"\n\ntype CountryCode = Lowercase<TCountryCode>\n\ntype MyMarker = Marker & {\n overlay: {\n countryCode: CountryCode\n label: string\n }\n}\n\nconst markers: MyMarker[] = [\n {\n lat: 37.5665,\n lng: 126.978,\n size: 2.8,\n overlay: { countryCode: \"kr\", label: \"Seoul\" },\n },\n {\n lat: 40.7128,\n lng: -74.006,\n size: 2.8,\n overlay: { countryCode: \"us\", label: \"NYC\" },\n },\n]\n\nexport default function Component() {\n const id = React.useId()\n return (\n <div className=\"relative h-[500px] w-full overflow-hidden rounded-lg border\">\n <div className=\"to-background absolute inset-0 bg-radial from-transparent to-200%\" />\n <DottedMap<MyMarker>\n markers={markers}\n renderMarkerOverlay={({ marker, x, y, r, index }) => {\n const { countryCode, label } = marker.overlay\n const href = `https://flagcdn.com/w80/${countryCode}.webp` // FlagCDN [oai_citation:7‡Flagpedia](https://flagpedia.net/download/api)\n\n const clipId = `${id}-flag-clip-${index}`.replace(/:/g, \"-\")\n const imgR = r * 0.75\n\n const fontSize = r * 0.9\n const pillH = r * 1.5\n const pillW = label.length * (fontSize * 0.62) + r * 1.4\n const pillX = x + r + r * 0.6\n const pillY = y - pillH / 2\n\n return (\n <g style={{ pointerEvents: \"none\" }}>\n <clipPath id={clipId}>\n <circle cx={x} cy={y} r={imgR} />\n </clipPath>\n\n <image\n href={href}\n x={x - imgR}\n y={y - imgR}\n width={imgR * 2}\n height={imgR * 2}\n preserveAspectRatio=\"xMidYMid slice\"\n clipPath={`url(#${clipId})`}\n />\n\n <rect\n x={pillX}\n y={pillY}\n width={pillW}\n height={pillH}\n rx={pillH / 2}\n fill=\"rgba(0,0,0,0.55)\"\n />\n <text\n x={pillX + r * 0.7}\n y={y + fontSize * 0.35}\n fontSize={fontSize}\n fill=\"white\"\n >\n {label}\n </text>\n </g>\n )\n }}\n />\n </div>\n )\n}\n",
"type": "registry:example"
}
]
diff --git a/apps/www/public/r/dotted-map.json b/apps/www/public/r/dotted-map.json
index 81d83dae..2608d7a3 100644
--- a/apps/www/public/r/dotted-map.json
+++ b/apps/www/public/r/dotted-map.json
@@ -10,7 +10,7 @@
"files": [
{
"path": "registry/magicui/dotted-map.tsx",
- "content": "import * as React from \"react\"\nimport { createMap } from \"svg-dotted-map\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface Marker {\n lat: number\n lng: number\n size?: number\n}\n\nexport interface DottedMapProps extends React.SVGProps<SVGSVGElement> {\n width?: number\n height?: number\n mapSamples?: number\n markers?: Marker[]\n dotColor?: string\n markerColor?: string\n dotRadius?: number\n stagger?: boolean\n}\n\nexport function DottedMap({\n width = 150,\n height = 75,\n mapSamples = 5000,\n markers = [],\n markerColor = \"#FF6900\",\n dotRadius = 0.2,\n stagger = true,\n className,\n style,\n}: DottedMapProps) {\n const { points, addMarkers } = createMap({\n width,\n height,\n mapSamples,\n })\n\n const processedMarkers = addMarkers(markers)\n\n // Compute stagger helpers in a single, simple pass\n const { xStep, yToRowIndex } = React.useMemo(() => {\n const sorted = [...points].sort((a, b) => a.y - b.y || a.x - b.x)\n const rowMap = new Map<number, number>()\n let step = 0\n let prevY = Number.NaN\n let prevXInRow = Number.NaN\n\n for (const p of sorted) {\n if (p.y !== prevY) {\n // new row\n prevY = p.y\n prevXInRow = Number.NaN\n if (!rowMap.has(p.y)) rowMap.set(p.y, rowMap.size)\n }\n if (!Number.isNaN(prevXInRow)) {\n const delta = p.x - prevXInRow\n if (delta > 0) step = step === 0 ? delta : Math.min(step, delta)\n }\n prevXInRow = p.x\n }\n\n return { xStep: step || 1, yToRowIndex: rowMap }\n }, [points])\n\n return (\n <svg\n viewBox={`0 0 ${width} ${height}`}\n className={cn(\"text-gray-500 dark:text-gray-500\", className)}\n style={{ width: \"100%\", height: \"100%\", ...style }}\n >\n {points.map((point, index) => {\n const rowIndex = yToRowIndex.get(point.y) ?? 0\n const offsetX = stagger && rowIndex % 2 === 1 ? xStep / 2 : 0\n return (\n <circle\n cx={point.x + offsetX}\n cy={point.y}\n r={dotRadius}\n fill=\"currentColor\"\n key={`${point.x}-${point.y}-${index}`}\n />\n )\n })}\n {processedMarkers.map((marker, index) => {\n const rowIndex = yToRowIndex.get(marker.y) ?? 0\n const offsetX = stagger && rowIndex % 2 === 1 ? xStep / 2 : 0\n return (\n <circle\n cx={marker.x + offsetX}\n cy={marker.y}\n r={marker.size ?? dotRadius}\n fill={markerColor}\n key={`${marker.x}-${marker.y}-${index}`}\n />\n )\n })}\n </svg>\n )\n}\n",
+ "content": "import * as React from \"react\"\nimport { createMap } from \"svg-dotted-map\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface Marker {\n lat: number\n lng: number\n size?: number\n pulse?: boolean\n}\n\n/** addMarkers returns markers with lat/lng removed; only x, y and other props (e.g. size) remain */\ntype MapMarker<M extends Marker> = Omit<M, \"lat\" | \"lng\"> & {\n x: number\n y: number\n}\n\nexport interface DottedMapProps<\n M extends Marker = Marker,\n> extends React.SVGProps<SVGSVGElement> {\n width?: number\n height?: number\n mapSamples?: number\n markers?: M[]\n dotColor?: string\n markerColor?: string\n dotRadius?: number\n stagger?: boolean\n pulse?: boolean\n\n renderMarkerOverlay?: (args: {\n marker: MapMarker<M>\n index: number\n x: number\n y: number\n r: number\n }) => React.ReactNode\n}\n\nexport function DottedMap<M extends Marker = Marker>({\n width = 150,\n height = 75,\n mapSamples = 5000,\n markers = [],\n dotColor = \"currentColor\",\n markerColor = \"#FF6900\",\n dotRadius = 0.2,\n stagger = true,\n pulse = false,\n renderMarkerOverlay,\n className,\n style,\n ...svgProps\n}: DottedMapProps<M>) {\n const { points, addMarkers } = createMap({\n width,\n height,\n mapSamples,\n })\n const processedMarkers = addMarkers(markers)\n\n // Compute stagger helpers in a single, simple pass\n const { xStep, yToRowIndex } = React.useMemo(() => {\n const sorted = [...points].sort((a, b) => a.y - b.y || a.x - b.x)\n const rowMap = new Map<number, number>()\n let step = 0\n let prevY = Number.NaN\n let prevXInRow = Number.NaN\n\n for (const p of sorted) {\n if (p.y !== prevY) {\n // new row\n prevY = p.y\n prevXInRow = Number.NaN\n if (!rowMap.has(p.y)) rowMap.set(p.y, rowMap.size)\n }\n if (!Number.isNaN(prevXInRow)) {\n const delta = p.x - prevXInRow\n if (delta > 0) step = step === 0 ? delta : Math.min(step, delta)\n }\n prevXInRow = p.x\n }\n\n return { xStep: step || 1, yToRowIndex: rowMap }\n }, [points])\n\n return (\n <svg\n viewBox={`0 0 ${width} ${height}`}\n className={cn(\"text-gray-500 dark:text-gray-500\", className)}\n style={{ width: \"100%\", height: \"100%\", ...style }}\n {...svgProps}\n >\n {points.map((point, index) => {\n const rowIndex = yToRowIndex.get(point.y) ?? 0\n const offsetX = stagger && rowIndex % 2 === 1 ? xStep / 2 : 0\n return (\n <circle\n cx={point.x + offsetX}\n cy={point.y}\n r={dotRadius}\n fill={dotColor}\n key={`${point.x}-${point.y}-${index}`}\n />\n )\n })}\n\n {processedMarkers.map((marker, index) => {\n const rowIndex = yToRowIndex.get(marker.y) ?? 0\n const offsetX = stagger && rowIndex % 2 === 1 ? xStep / 2 : 0\n\n const x = marker.x + offsetX\n const y = marker.y\n const r = marker.size ?? dotRadius\n const shouldPulse = pulse\n ? marker.pulse !== false\n : marker.pulse === true\n const pulseTo = r * 2.8\n\n return (\n <g key={`${marker.x}-${marker.y}-${index}`}>\n <circle cx={x} cy={y} r={r} fill={markerColor} />\n\n {shouldPulse ? (\n <g pointerEvents=\"none\">\n <circle\n cx={x}\n cy={y}\n r={r}\n fill=\"none\"\n stroke={markerColor}\n strokeOpacity={1}\n strokeWidth={0.35}\n >\n <animate\n attributeName=\"r\"\n values={`${r};${pulseTo}`}\n dur=\"1.4s\"\n repeatCount=\"indefinite\"\n />\n <animate\n attributeName=\"opacity\"\n values=\"1;0\"\n dur=\"1.4s\"\n repeatCount=\"indefinite\"\n />\n </circle>\n <circle\n cx={x}\n cy={y}\n r={r}\n fill=\"none\"\n stroke={markerColor}\n strokeOpacity={0.9}\n strokeWidth={0.3}\n >\n <animate\n attributeName=\"r\"\n values={`${r};${pulseTo}`}\n dur=\"1.4s\"\n begin=\"0.7s\"\n repeatCount=\"indefinite\"\n />\n <animate\n attributeName=\"opacity\"\n values=\"0.9;0\"\n dur=\"1.4s\"\n begin=\"0.7s\"\n repeatCount=\"indefinite\"\n />\n </circle>\n </g>\n ) : null}\n\n {renderMarkerOverlay?.({\n marker: { ...marker, x, y },\n index,\n x,\n y,\n r,\n })}\n </g>\n )\n })}\n </svg>\n )\n}\n",
"type": "registry:ui"
}
]
diff --git a/apps/www/public/r/registry.json b/apps/www/public/r/registry.json
index 955a61f6..724c9df2 100644
--- a/apps/www/public/r/registry.json
+++ b/apps/www/public/r/registry.json
@@ -3348,6 +3348,9 @@
"type": "registry:example",
"title": "Dotted Map Demo",
"description": "Example showing a dotted map.",
+ "dependencies": [
+ "countries-list"
+ ],
"registryDependencies": [
"@magicui/dotted-map"
],
@@ -3373,6 +3376,21 @@
}
]
},
+ {
+ "name": "dotted-map-demo-3",
+ "type": "registry:example",
+ "title": "Dotted Map Demo 3",
+ "description": "Example showing a dotted map with pulse animation.",
+ "registryDependencies": [
+ "@magicui/dotted-map"
+ ],
+ "files": [
+ {
+ "path": "registry/example/dotted-map-demo-3.tsx",
+ "type": "registry:example"
+ }
+ ]
+ },
{
"name": "utils",
"type": "registry:lib",
diff --git a/apps/www/public/registry.json b/apps/www/public/registry.json
index 955a61f6..724c9df2 100644
--- a/apps/www/public/registry.json
+++ b/apps/www/public/registry.json
@@ -3348,6 +3348,9 @@
"type": "registry:example",
"title": "Dotted Map Demo",
"description": "Example showing a dotted map.",
+ "dependencies": [
+ "countries-list"
+ ],
"registryDependencies": [
"@magicui/dotted-map"
],
@@ -3373,6 +3376,21 @@
}
]
},
+ {
+ "name": "dotted-map-demo-3",
+ "type": "registry:example",
+ "title": "Dotted Map Demo 3",
+ "description": "Example showing a dotted map with pulse animation.",
+ "registryDependencies": [
+ "@magicui/dotted-map"
+ ],
+ "files": [
+ {
+ "path": "registry/example/dotted-map-demo-3.tsx",
+ "type": "registry:example"
+ }
+ ]
+ },
{
"name": "utils",
"type": "registry:lib",
diff --git a/apps/www/registry.json b/apps/www/registry.json
index 955a61f6..724c9df2 100644
--- a/apps/www/registry.json
+++ b/apps/www/registry.json
@@ -3348,6 +3348,9 @@
"type": "registry:example",
"title": "Dotted Map Demo",
"description": "Example showing a dotted map.",
+ "dependencies": [
+ "countries-list"
+ ],
"registryDependencies": [
"@magicui/dotted-map"
],
@@ -3373,6 +3376,21 @@
}
]
},
+ {
+ "name": "dotted-map-demo-3",
+ "type": "registry:example",
+ "title": "Dotted Map Demo 3",
+ "description": "Example showing a dotted map with pulse animation.",
+ "registryDependencies": [
+ "@magicui/dotted-map"
+ ],
+ "files": [
+ {
+ "path": "registry/example/dotted-map-demo-3.tsx",
+ "type": "registry:example"
+ }
+ ]
+ },
{
"name": "utils",
"type": "registry:lib",
diff --git a/apps/www/registry/__index__.tsx b/apps/www/registry/__index__.tsx
index 333165ef..a573d7e6 100644
--- a/apps/www/registry/__index__.tsx
+++ b/apps/www/registry/__index__.tsx
@@ -3521,6 +3521,23 @@ export const Index: Record<string, any> = {
}),
meta: undefined,
},
+ "dotted-map-demo-3": {
+ name: "dotted-map-demo-3",
+ description: "Example showing a dotted map with pulse animation.",
+ type: "registry:example",
+ registryDependencies: ["@magicui/dotted-map"],
+ files: [{
+ path: "registry/example/dotted-map-demo-3.tsx",
+ type: "registry:example",
+ target: ""
+ }],
+ component: React.lazy(async () => {
+ const mod = await import("@/registry/example/dotted-map-demo-3.tsx")
+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') ?? item.name
+ return { default: mod.default ?? mod[exportName] }
+ }),
+ meta: undefined,
+ },
"utils": {
name: "utils",
description: "",
diff --git a/apps/www/registry/example/dotted-map-demo-3.tsx b/apps/www/registry/example/dotted-map-demo-3.tsx
new file mode 100644
index 00000000..90472f16
--- /dev/null
+++ b/apps/www/registry/example/dotted-map-demo-3.tsx
@@ -0,0 +1,25 @@
+import { DottedMap } from "@/registry/magicui/dotted-map"
+import type { Marker } from "@/registry/magicui/dotted-map"
+
+const markers: Marker[] = [
+ {
+ lat: 37.5665,
+ lng: 126.978,
+ size: 0.3,
+ },
+ {
+ lat: 40.7128,
+ lng: -74.006,
+ size: 0.3,
+ pulse: false,
+ },
+]
+
+export default function Component() {
+ return (
+ <div className="relative h-[500px] w-full overflow-hidden rounded-lg border">
+ <div className="to-background absolute inset-0 bg-radial from-transparent to-200%" />
+ <DottedMap markers={markers} pulse />
+ </div>
+ )
+}
diff --git a/apps/www/registry/example/dotted-map-demo.tsx b/apps/www/registry/example/dotted-map-demo.tsx
index f7836f03..acc4eaa1 100644
--- a/apps/www/registry/example/dotted-map-demo.tsx
+++ b/apps/www/registry/example/dotted-map-demo.tsx
@@ -1,88 +1,89 @@
+import * as React from "react"
+import type { TCountryCode } from "countries-list"
+
import { DottedMap } from "@/registry/magicui/dotted-map"
+import type { Marker } from "@/registry/magicui/dotted-map"
+
+type CountryCode = Lowercase<TCountryCode>
+
+type MyMarker = Marker & {
+ overlay: {
+ countryCode: CountryCode
+ label: string
+ }
+}
-const markers = [
+const markers: MyMarker[] = [
+ {
+ lat: 37.5665,
+ lng: 126.978,
+ size: 2.8,
+ overlay: { countryCode: "kr", label: "Seoul" },
+ },
{
lat: 40.7128,
lng: -74.006,
- size: 0.3,
- }, // New York
- {
- lat: 34.0522,
- lng: -118.2437,
- size: 0.3,
- }, // Los Angeles
- {
- lat: 51.5074,
- lng: -0.1278,
- size: 0.3,
- }, // London
- {
- lat: -33.8688,
- lng: 151.2093,
- size: 0.3,
- }, // Sydney
- {
- lat: 48.8566,
- lng: 2.3522,
- size: 0.3,
- }, // Paris
- {
- lat: 35.6762,
- lng: 139.6503,
- size: 0.3,
- }, // Tokyo
- {
- lat: 55.7558,
- lng: 37.6176,
- size: 0.3,
- }, // Moscow
- {
- lat: 39.9042,
- lng: 116.4074,
- size: 0.3,
- }, // Beijing
- {
- lat: 28.6139,
- lng: 77.209,
- size: 0.3,
- }, // New Delhi
- {
- lat: -23.5505,
- lng: -46.6333,
- size: 0.3,
- }, // São Paulo
- {
- lat: 1.3521,
- lng: 103.8198,
- size: 0.3,
- }, // Singapore
- {
- lat: 25.2048,
- lng: 55.2708,
- size: 0.3,
- }, // Dubai
- {
- lat: 52.52,
- lng: 13.405,
- size: 0.3,
- }, // Berlin
- {
- lat: 19.4326,
- lng: -99.1332,
- size: 0.3,
- }, // Mexico City
- {
- lat: -26.2041,
- lng: 28.0473,
- size: 0.3,
- }, // Johannesburg
+ size: 2.8,
+ overlay: { countryCode: "us", label: "NYC" },
+ },
]
export default function Component() {
+ const id = React.useId()
return (
<div className="relative h-[500px] w-full overflow-hidden rounded-lg border">
- <div className="to-background absolute inset-0 bg-radial from-transparent to-70%" />
- <DottedMap markers={markers} />
+ <div className="to-background absolute inset-0 bg-radial from-transparent to-200%" />
+ <DottedMap<MyMarker>
+ markers={markers}
+ renderMarkerOverlay={({ marker, x, y, r, index }) => {
+ const { countryCode, label } = marker.overlay
+ const href = `https://flagcdn.com/w80/${countryCode}.webp` // FlagCDN [oai_citation:7‡Flagpedia](https://flagpedia.net/download/api)
+
+ const clipId = `${id}-flag-clip-${index}`.replace(/:/g, "-")
+ const imgR = r * 0.75
+
+ const fontSize = r * 0.9
+ const pillH = r * 1.5
+ const pillW = label.length * (fontSize * 0.62) + r * 1.4
+ const pillX = x + r + r * 0.6
+ const pillY = y - pillH / 2
+
+ return (
+ <g style={{ pointerEvents: "none" }}>
+ <clipPath id={clipId}>
+ <circle cx={x} cy={y} r={imgR} />
+ </clipPath>
+
+ <image
+ href={href}
+ x={x - imgR}
+ y={y - imgR}
+ width={imgR * 2}
+ height={imgR * 2}
+ preserveAspectRatio="xMidYMid slice"
+ clipPath={`url(#${clipId})`}
+ />
+
+ <rect
+ x={pillX}
+ y={pillY}
+ width={pillW}
+ height={pillH}
+ rx={pillH / 2}
+ fill="rgba(0,0,0,0.55)"
+ />
+ <text
+ x={pillX + r * 0.7}
+ y={y + fontSize * 0.35}
+ fontSize={fontSize}
+ fill="white"
+ >
+ {label}
+ </text>
+ </g>
+ )
+ }}
+ />
</div>
)
}
diff --git a/apps/www/registry/magicui/dotted-map.tsx b/apps/www/registry/magicui/dotted-map.tsx
index c8e1339e..fbb85928 100644
--- a/apps/www/registry/magicui/dotted-map.tsx
+++ b/apps/www/registry/magicui/dotted-map.tsx
@@ -3,40 +3,61 @@ import { createMap } from "svg-dotted-map"
import { cn } from "@/lib/utils"
-interface Marker {
+export interface Marker {
lat: number
lng: number
size?: number
+ pulse?: boolean
}
-export interface DottedMapProps extends React.SVGProps<SVGSVGElement> {
+/** addMarkers returns markers with lat/lng removed; only x, y and other props (e.g. size) remain */
+type MapMarker<M extends Marker> = Omit<M, "lat" | "lng"> & {
+ x: number
+ y: number
+}
+
+export interface DottedMapProps<
+ M extends Marker = Marker,
+> extends React.SVGProps<SVGSVGElement> {
width?: number
height?: number
mapSamples?: number
- markers?: Marker[]
+ markers?: M[]
dotColor?: string
markerColor?: string
dotRadius?: number
stagger?: boolean
+ pulse?: boolean
+
+ renderMarkerOverlay?: (args: {
+ marker: MapMarker<M>
+ index: number
+ x: number
+ y: number
+ r: number
+ }) => React.ReactNode
}
-export function DottedMap({
+export function DottedMap<M extends Marker = Marker>({
width = 150,
height = 75,
mapSamples = 5000,
markers = [],
+ dotColor = "currentColor",
markerColor = "#FF6900",
dotRadius = 0.2,
stagger = true,
+ pulse = false,
+ renderMarkerOverlay,
className,
style,
-}: DottedMapProps) {
+ ...svgProps
+}: DottedMapProps<M>) {
const { points, addMarkers } = createMap({
width,
height,
mapSamples,
})
-
const processedMarkers = addMarkers(markers)
// Compute stagger helpers in a single, simple pass
@@ -69,6 +90,7 @@ export function DottedMap({
viewBox={`0 0 ${width} ${height}`}
className={cn("text-gray-500 dark:text-gray-500", className)}
style={{ width: "100%", height: "100%", ...style }}
+ {...svgProps}
>
{points.map((point, index) => {
const rowIndex = yToRowIndex.get(point.y) ?? 0
@@ -78,22 +100,87 @@ export function DottedMap({
cx={point.x + offsetX}
cy={point.y}
r={dotRadius}
- fill="currentColor"
+ fill={dotColor}
key={`${point.x}-${point.y}-${index}`}
/>
)
})}
+
{processedMarkers.map((marker, index) => {
const rowIndex = yToRowIndex.get(marker.y) ?? 0
const offsetX = stagger && rowIndex % 2 === 1 ? xStep / 2 : 0
+
+ const x = marker.x + offsetX
+ const y = marker.y
+ const r = marker.size ?? dotRadius
+ const shouldPulse = pulse
+ ? marker.pulse !== false
+ : marker.pulse === true
+ const pulseTo = r * 2.8
+
return (
- <circle
- cx={marker.x + offsetX}
- cy={marker.y}
- r={marker.size ?? dotRadius}
- fill={markerColor}
- key={`${marker.x}-${marker.y}-${index}`}
- />
+ <g key={`${marker.x}-${marker.y}-${index}`}>
+ <circle cx={x} cy={y} r={r} fill={markerColor} />
+
+ {shouldPulse ? (
+ <g pointerEvents="none">
+ <circle
+ cx={x}
+ cy={y}
+ r={r}
+ fill="none"
+ stroke={markerColor}
+ strokeOpacity={1}
+ strokeWidth={0.35}
+ >
+ <animate
+ attributeName="r"
+ values={`${r};${pulseTo}`}
+ dur="1.4s"
+ repeatCount="indefinite"
+ />
+ <animate
+ attributeName="opacity"
+ values="1;0"
+ dur="1.4s"
+ repeatCount="indefinite"
+ />
+ </circle>
+ <circle
+ cx={x}
+ cy={y}
+ r={r}
+ fill="none"
+ stroke={markerColor}
+ strokeOpacity={0.9}
+ strokeWidth={0.3}
+ >
+ <animate
+ attributeName="r"
+ values={`${r};${pulseTo}`}
+ dur="1.4s"
+ begin="0.7s"
+ repeatCount="indefinite"
+ />
+ <animate
+ attributeName="opacity"
+ values="0.9;0"
+ dur="1.4s"
+ begin="0.7s"
+ repeatCount="indefinite"
+ />
+ </circle>
+ </g>
+ ) : null}
+
+ {renderMarkerOverlay?.({
+ marker: { ...marker, x, y },
+ index,
+ x,
+ y,
+ r,
+ })}
+ </g>
)
})}
</svg>
diff --git a/apps/www/registry/registry-examples.ts b/apps/www/registry/registry-examples.ts
index 5dd95b72..c91afdea 100644
--- a/apps/www/registry/registry-examples.ts
+++ b/apps/www/registry/registry-examples.ts
@@ -1806,6 +1806,7 @@ export const examples: Registry["items"] = [
title: "Dotted Map Demo",
description: "Example showing a dotted map.",
registryDependencies: ["@magicui/dotted-map"],
+ dependencies: ["countries-list"],
files: [
{
path: "example/dotted-map-demo.tsx",
@@ -1826,4 +1827,17 @@ export const examples: Registry["items"] = [
},
],
},
+ {
+ name: "dotted-map-demo-3",
+ type: "registry:example",
+ title: "Dotted Map Demo 3",
+ description: "Example showing a dotted map with pulse animation.",
+ registryDependencies: ["@magicui/dotted-map"],
+ files: [
+ {
+ path: "example/dotted-map-demo-3.tsx",
+ type: "registry:example",
+ },
+ ],
+ },
]
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8c58cb5a..a301acf1 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -107,6 +107,9 @@ importers:
cobe:
specifier: ^0.6.4
version: 0.6.5
+ countries-list:
+ specifier: ^3.2.2
+ version: 3.2.2
fumadocs-core:
specifier: ^15.8.2
@@ -2779,6 +2782,9 @@ packages:
typescript:
optional: true
+ resolution: {integrity: sha512-ABJ/RWQBrPWy+hRuZoW+0ooK8p65Eo3WmUZwHm6v4wmfSPznNAKzjy3+UUYrJK2v3182BVsgWxdB6ROidj39kw==}
+
resolution: {integrity: sha512-VqCUuhcd1iB+dsv8gxPttb5iZh/D0iubSP21g36KXdEuf6I5JiioesUVjpCdHV9MZRUfVFlvwtIUyPfxo5trtw==}
engines: {node: '>=4.8'}
@@ -8334,6 +8340,8 @@ snapshots:
optionalDependencies:
typescript: 5.9.3
+
dependencies:
nice-try: 1.0.5
@@ -8671,7 +8679,7 @@ snapshots:
'@typescript-eslint/parser': 8.50.1([email protected]([email protected]))([email protected])
eslint: 9.39.2([email protected])
eslint-import-resolver-node: 0.3.9
+ eslint-import-resolver-typescript: 3.10.1([email protected])([email protected]([email protected]))
eslint-plugin-jsx-a11y: 6.10.2([email protected]([email protected]))
eslint-plugin-react: 7.37.5([email protected]([email protected]))
@@ -8695,7 +8703,7 @@ snapshots:
transitivePeerDependencies:
- supports-color
dependencies:
'@nolyfill/is-core-module': 1.0.39
debug: 4.4.3
@@ -8710,14 +8718,14 @@ snapshots:
transitivePeerDependencies:
- supports-color
dependencies:
debug: 3.2.7
optionalDependencies:
'@typescript-eslint/parser': 8.50.1([email protected]([email protected]))([email protected])
eslint: 9.39.2([email protected])
eslint-import-resolver-node: 0.3.9
+ eslint-import-resolver-typescript: 3.10.1([email protected])([email protected]([email protected]))
transitivePeerDependencies:
- supports-color
@@ -8732,7 +8740,7 @@ snapshots:
doctrine: 2.1.0
eslint: 9.39.2([email protected])
eslint-import-resolver-node: 0.3.9
hasown: 2.0.2
is-core-module: 2.16.1
is-glob: 4.0.3