block by guilhermesimoes fb859eac7ff387321d36e9c56f5cb020

D3.js: Automatic text sizing using em units

Full Screen

em are scalable units which are translated by the browser into pixel values. For a base font size of 10px, a value of 1em is translated into 10px. 2em into 20px. And so on. By computing the ratio between the width taken by a label and the available width, we can use that value as an em unit and resize the label to fit the available space.

index.html

data.json