Skip to content

Commit 201f657

Browse files
committed
v5.5.7
1 parent 5bf5cdc commit 201f657

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netdata/charts",
3-
"version": "5.5.6",
3+
"version": "5.5.7",
44
"description": "Netdata frontend SDK and chart utilities",
55
"main": "dist/index.js",
66
"module": "dist/es6/index.js",

src/components/helpers/fontSizer.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,40 @@ const FontSizer = ({
55
Component = "div",
66
maxHeight = 100,
77
maxWidth = 100,
8-
maxFontSize = 500,
8+
maxFontSize = 50,
99
minFontSize = 10,
1010
cacheKey,
1111
...rest
1212
}) => {
1313
const [ref, setRef] = useState()
14+
const cancelRef = useRef(false)
1415

1516
useEffect(() => {
1617
if (!ref) return
1718

18-
requestAnimationFrame(() => {
19+
const timeoutId = setTimeout(() => {
20+
cancelRef.current = false
1921
let fontSize = maxFontSize
2022

2123
ref.style.animation = "font-size 02s"
2224
ref.style.fontSize = fontSize + "px"
2325

24-
const widthScale = maxWidth / ref.offsetWidth
25-
const heightScale = maxHeight / ref.offsetHeight
26-
27-
const scaleFactor = Math.min(widthScale, heightScale)
28-
fontSize = Math.floor(maxFontSize * scaleFactor) || 1
29-
30-
ref.style.fontSize = fontSize + "px"
26+
while (
27+
!cancelRef.current &&
28+
fontSize > minFontSize &&
29+
(ref.offsetWidth > maxWidth || ref.offsetHeight > maxHeight)
30+
) {
31+
const delta = Math.ceil(fontSize / 100)
32+
fontSize = fontSize - delta
33+
ref.style.fontSize = fontSize + "px"
34+
}
3135
})
32-
}, [children, maxHeight, maxWidth, ref, cacheKey])
36+
37+
return () => {
38+
cancelRef.current = true
39+
clearTimeout(timeoutId)
40+
}
41+
}, [children, maxHeight, maxWidth, ref])
3342

3443
return (
3544
<Component truncate ref={setRef} {...rest}>

0 commit comments

Comments
 (0)