|
@@ -137,8 +137,8 @@ function A1home() {
|
|
|
}
|
|
|
}, [])
|
|
|
|
|
|
- // 添加tooltip到指定城市下方
|
|
|
- const addTooltip = useCallback((cityId: string, tooltipText: string) => {
|
|
|
+ // 添加tooltip和’(数量)’到指定城市下方
|
|
|
+ const addTooltip = useCallback((cityId: string, tooltipText: string, count: number) => {
|
|
|
if (svgRef.current) {
|
|
|
const city = svgRef.current.querySelector(`#${cityId}`)?.querySelector('ellipse')!
|
|
|
|
|
@@ -148,6 +148,10 @@ function A1home() {
|
|
|
const rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect')
|
|
|
const text = document.createElementNS('http://www.w3.org/2000/svg', 'text')
|
|
|
|
|
|
+ const countText = document.createElementNS('http://www.w3.org/2000/svg', 'text')
|
|
|
+ const countElement = document.createElementNS('http://www.w3.org/2000/svg', 'g')
|
|
|
+ countElement.id = `${cityId}Count`
|
|
|
+
|
|
|
// 设置初始属性(修改以下部分)
|
|
|
rect.setAttribute('fill', 'url(#jinanGradient)') // 使用渐变引用
|
|
|
// rect.setAttribute('stroke', '#6d330fff')
|
|
@@ -161,6 +165,13 @@ function A1home() {
|
|
|
text.setAttribute('font-weight', '600')
|
|
|
text.textContent = tooltipText
|
|
|
|
|
|
+ countText.setAttribute('fill', '#ec5038ff')
|
|
|
+ countText.setAttribute('font-size', '10px')
|
|
|
+ countText.setAttribute('font-weight', '600')
|
|
|
+ countText.setAttribute('text-anchor', 'start')
|
|
|
+ countText.setAttribute('dominant-baseline', 'middle')
|
|
|
+ countText.textContent = `(${count})`
|
|
|
+
|
|
|
// 坐标
|
|
|
const cityCX = city?.cx.baseVal.value
|
|
|
const cityCY = city?.cy.baseVal.value
|
|
@@ -170,13 +181,17 @@ function A1home() {
|
|
|
rect.setAttribute('y', (cityCY + 20).toString()) // 下移20px
|
|
|
text.setAttribute('x', cityCX.toString())
|
|
|
text.setAttribute('y', (cityCY + 30).toString()) // 文字在矩形内居中
|
|
|
+ countText.setAttribute('x', (cityCX + 14).toString()) // 矩形中心
|
|
|
+ countText.setAttribute('y', (cityCY + 10).toString()) // 文字垂直居中
|
|
|
|
|
|
tooltip.appendChild(rect)
|
|
|
tooltip.appendChild(text)
|
|
|
+ countElement.appendChild(countText)
|
|
|
|
|
|
// 添加到 SVG 的 viewport 中
|
|
|
const viewport = svgRef.current.querySelector('.svg-pan-zoom_viewport')
|
|
|
viewport?.appendChild(tooltip)
|
|
|
+ viewport?.appendChild(countElement)
|
|
|
|
|
|
// 隐藏tooltip,待mouseEnter再显示
|
|
|
tooltip.style.opacity = '0'
|
|
@@ -185,8 +200,7 @@ function A1home() {
|
|
|
}
|
|
|
}, [])
|
|
|
|
|
|
- // 添加“(数量)”到城市末尾
|
|
|
-
|
|
|
+ // ... 已有代码 ...
|
|
|
// 更改tooltip文本内容
|
|
|
const changeTooltipText = useCallback((cityId: string, text: string) => {
|
|
|
if (svgRef.current) {
|
|
@@ -229,7 +243,8 @@ function A1home() {
|
|
|
`${martyrListByCity[item][0].cityId}`,
|
|
|
`烈士 ${martyrListByCity[item].length} | 亲属 ${
|
|
|
relativeList[item]?.length || 0
|
|
|
- } | 线索 ${clueList[item]?.length || 0}`
|
|
|
+ } | 线索 ${clueList[item]?.length || 0}`,
|
|
|
+ martyrListByCity[item].length
|
|
|
)
|
|
|
})
|
|
|
}
|