palantir/plottable — pull request #589 by bmalehorn (2014-06-24 23:26:35+00:00)
Title: Axis.Category._requestSpace caches character sizes

![cat-cash-1](https://cloud.githubusercontent.com/assets/3344958/3379540/75d128fc-fbf3-11e3-8b79-6f9f3f44b7eb.jpg)

`catAxis._requestedSpace` decides how to fit ticks into their bounding boxes by inserting them into the DOM and then measuring them, letter-by-letter. This means a hundred or so touches to the DOM each time you call `_requestedSpace`, which makes it rather slow.

This branch changes `_requestedSpace` to measure and cache the dimensions of each character, and compute their sizes by adding up individual characters. This means you only touch the DOM as many times as you have letters, and caching means that further resizes will be much faster.

Adding up individual characters is only an approximation, but it's fairly accurate, always within `0.05` px of the actual measurement in my tests.

## Before

![screen shot 2014-06-24 at 4 23 19 pm](https://cloud.githubusercontent.com/assets/3344958/3379726/a177812e-fbf6-11e3-866f-8f2db5c03d7a.png)

## After
![screen shot 2014-06-24 at 4 22 06 pm](https://cloud.githubusercontent.com/assets/3344958/3379729/b3ca9366-fbf6-11e3-9394-ea941dc7377b.png)

Close #572.