Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

fix hover interactive map, remove title

kruzhambusaa55dfa9b492
diff --git a/src/pages/Project/View/InteractiveMap.jsx b/src/pages/Project/View/InteractiveMap.jsx
index 99d0855a1..2f19be372 100644
--- a/src/pages/Project/View/InteractiveMap.jsx
+++ b/src/pages/Project/View/InteractiveMap.jsx
@@ -1,4 +1,4 @@
-import React, { memo } from 'react'
+import React, { memo, useState } from 'react'
import cx from 'clsx'
import _map from 'lodash/map'
import { useTranslation } from 'react-i18next'
@@ -25,38 +25,73 @@ countries.registerLocale(countriesZh)
countries.registerLocale(countriesSv)
const InteractiveMap = ({ data, onClickCountry, total }) => {
+
const { t, i18n: { language } } = useTranslation('common')
+ const [hoverShow, setHoverShow] = useState(false)
+ const [dataHover, setDataHover] = useState(null)
+ const [cursorPosition, setCursorPosition] = useState(null)
+
+ const onMouseMove = (e) => {
+ let rect = e.currentTarget.getBoundingClientRect()
+
+ let x = e.clientX - rect.left
+ let y = e.clientY - rect.top
+
+ setCursorPosition({pageX: x, pageY: y})
+ }
return (
- <svg id='map' viewBox='0 0 1050 650' className='w-full h-full'>
- <g>
- {_map(countriesList, (item, index) => {
- const perc = (data[index] / total * 100) || 0
- const title = `${countries.getName(index, language)}\n${t('project.unique')}: ${data[index] || 0}`
+ <div className='relative'>
+ <svg id='map' viewBox='0 0 1050 650' className='w-full h-full' onMouseMove={(e) => {onMouseMove(e)}}>
+ <g>
+ {_map(countriesList, (item, index) => {
+ const perc = (data[index] / total * 100) || 0
- return (
- <path
- key={index}
- id={index}
- className={cx('cursor-pointer', {
- 'hover:opacity-90': perc > 0,
- 'fill-[#cfd1d4] dark:fill-[#374151]': perc === 0,
- 'fill-[#92b2e7] dark:fill-[#43448c]': perc > 0 && perc < 3,
- 'fill-[#6f9be3] dark:fill-[#4642bf]': perc >= 3 && perc < 10,
- 'fill-[#5689db] dark:fill-[#4a42db]': perc >= 10 && perc < 20,
- 'fill-[#3b82f6] dark:fill-[#4035dc]': perc >= 20,
- })}
- d={item.d}
- onClick={() => perc !== 0 && onClickCountry(index)}
- >
- <title>
- {title}
- </title>
- </path>
- )
- })}
- </g>
- </svg>
+ return (
+ <path
+ key={index}
+ id={index}
+ className={cx('cursor-pointer', {
+ 'hover:opacity-90': perc > 0,
+ 'fill-[#cfd1d4] dark:fill-[#374151]': perc === 0,
+ 'fill-[#92b2e7] dark:fill-[#43448c]': perc > 0 && perc < 3,
+ 'fill-[#6f9be3] dark:fill-[#4642bf]': perc >= 3 && perc < 10,
+ 'fill-[#5689db] dark:fill-[#4a42db]': perc >= 10 && perc < 20,
+ 'fill-[#3b82f6] dark:fill-[#4035dc]': perc >= 20,
+ })}
+ d={item.d}
+ onClick={() => perc !== 0 && onClickCountry(index)}
+ onMouseEnter={(e) => {
+ setHoverShow(true)
+ setDataHover({
+ countries: countries.getName(index, language),
+ data: data[index] || 0
+ })
+ }}
+ onMouseLeave={() => {
+ setHoverShow(false)
+ }}
+ >
+ </path>
+ )
+ })}
+ </g>
+ </svg>
+ <div>
+ {hoverShow && (
+ <div className="border-2 text-xs dark:bg-gray-800 dark:shadow-gray-850 dark:border-gray-850 dark:text-gray-200 p-1 rounded-md" style={{
+ zIndex: 9999,
+ position: 'absolute',
+ top: cursorPosition.pageY+20,
+ left: cursorPosition.pageX
+ }}>
+ <strong>{dataHover.countries}</strong>
+ <br />
+ {t('project.unique')}: <strong className="dark:text-indigo-400">{dataHover.data}</strong>
+ </div>
+ )}
+ </div>
+ </div>
)
}