(ref: MutableRefObject<HTMLElement | null>)
| 450 | }; |
| 451 | |
| 452 | export const getLabelSizeWeb = (ref: MutableRefObject<HTMLElement | null>) => { |
| 453 | if (Platform.OS !== 'web' || ref.current === null) { |
| 454 | return null; |
| 455 | } |
| 456 | |
| 457 | const canvasContext = getCanvasContext(); |
| 458 | |
| 459 | if (!canvasContext) { |
| 460 | return null; |
| 461 | } |
| 462 | |
| 463 | const elementStyles = window.getComputedStyle(ref.current); |
| 464 | canvasContext.font = elementStyles.font; |
| 465 | |
| 466 | const metrics = canvasContext.measureText(ref.current.innerText); |
| 467 | |
| 468 | return { |
| 469 | width: metrics.width, |
| 470 | height: |
| 471 | (metrics.fontBoundingBoxAscent ?? 0) + |
| 472 | (metrics.fontBoundingBoxDescent ?? 0), |
| 473 | }; |
| 474 | }; |
no test coverage detected
searching dependent graphs…