Last active
January 11, 2019 12:56
-
-
Save MaxXxiMast/61f1df0a4c4d37a3cf2714fddcf0e283 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function textSize(text) { | |
if (!d3) return; | |
var container = d3.select('body').append('svg'); | |
container.append('text').attr('x', -99999).attr('y',-99999).text(text); | |
var size = container.node().getBBox(); | |
container.remove(); | |
return { width: size.width, height: size.height }; | |
} | |
// Usage: textSize("This is a very long text"); | |
// => Return: Object {width: 140, height: 15.453125} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment