d3-measure-text

A JavaScript component to measure the the width and height of SVG text.

d3-measure-text

A JavaScript component to measure the the width and height of SVG text.

If you're creating a graph with SVG, it's especially nice to know the size of the axis labels' text so that you can position the graph appropriately.

npm install --save d3-measure-text
component install jprichardson/d3-measure-text
bower install d3-measure-text
<script src="/path/to/d3-measure-text.js"></script>
var d3MeasureText = require('d3-measure-text')
d3MeasureText.d3 = d3 //<--- set d3 if it's not global. 
 
var dim = d3MeasureText("Time (days)")
console.dir(dim) //{width: 33, height: 12} 

This code is modified from Bill's answer on StackOverflow.

(MIT License)

Copyright 2013, JP Richardson jprichardson@gmail.com