What is the logic behind d3.js nice() ticks

2019-07-15 05:04发布

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.

var s = d3.scale.linear().domain([minValue, maxValue]);
var ticks = s.nice().ticks(numberOfPoints);

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

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?

1条回答
Juvenile、少年°
2楼-- · 2019-07-15 05:50

D3 is open source, so you can look up the implementation. It basically boils down to rounding the extreme values:

domain[i0] = nice.floor(x0);
domain[i1] = nice.ceil(x1);
查看更多
登录 后发表回答