chrisrzhou / react-wordcloud

☁️ Simple React + D3 wordcloud component with powerful features.

Home Page:https://react-wordcloud.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to keep the original size of font after mouse out?

Socvest opened this issue · comments

Following the example from this Codesandbox, it seems whenever I hover the mouse over a text and out of it, the size of the text drastically reduces from its original size. Is there a way to avoid this behaviour because it pretty much reduces the intended effect of demonstrating the important of that word based on the value parameter in the original text data.

So after a work around, I found a solution. Just get the original font-size, multiply it by a factor then divide it by the same factor to get back to the original size.

Inside the callback function:

const currentFontSize = element.getAttribute("font-size").match(/\d+/)[0]
...
.attr("font-size", isActive ? `${currentFontSize * 1.5}px` : currentFontSize/1.5 + "px")