Skip to content

Commit 71c52b9

Browse files
committed
fix(dotted-map): apply dotColor prop to map dots
1 parent 00cf49c commit 71c52b9

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

apps/www/public/llms-full.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5915,6 +5915,7 @@ export function DottedMap<M extends Marker = Marker>({
59155915
height = 75,
59165916
mapSamples = 5000,
59175917
markers = [],
5918+
dotColor = "currentColor",
59185919
markerColor = "#FF6900",
59195920
dotRadius = 0.2,
59205921
stagger = true,
@@ -5971,7 +5972,7 @@ export function DottedMap<M extends Marker = Marker>({
59715972
cx={point.x + offsetX}
59725973
cy={point.y}
59735974
r={dotRadius}
5974-
fill="currentColor"
5975+
fill={dotColor}
59755976
key={`${point.x}-${point.y}-${index}`}
59765977
/>
59775978
)

apps/www/public/r/dotted-map.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"files": [
1111
{
1212
"path": "registry/magicui/dotted-map.tsx",
13-
"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 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=\"currentColor\"\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",
13+
"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",
1414
"type": "registry:ui"
1515
}
1616
]

apps/www/registry/magicui/dotted-map.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function DottedMap<M extends Marker = Marker>({
4343
height = 75,
4444
mapSamples = 5000,
4545
markers = [],
46+
dotColor = "currentColor",
4647
markerColor = "#FF6900",
4748
dotRadius = 0.2,
4849
stagger = true,
@@ -99,7 +100,7 @@ export function DottedMap<M extends Marker = Marker>({
99100
cx={point.x + offsetX}
100101
cy={point.y}
101102
r={dotRadius}
102-
fill="currentColor"
103+
fill={dotColor}
103104
key={`${point.x}-${point.y}-${index}`}
104105
/>
105106
)

0 commit comments

Comments
 (0)