What is the logic behind d3.js nice() ticks
<p>I have generated some charts in d3.js. I use the following code to calculate the values to put in my y axis which works like a charm.</p>

<pre><code>var s = d3.scale.linear().domain([minValue, maxValue]);
var ticks = s.nice().ticks(numberOfPoints);
</code></pre>

<p>However I now have to write python code using pycairo which generates clones of the d3.js charts on the server side.</p>

<p>My question is does anybody know the logic used in the above code, or something that can give similar results, so that I can replicate it in python to get nice values to use in my y axis?</p>