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

北战南征 提交于 2019-12-07 21:45:05

问题


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:


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);


来源:https://stackoverflow.com/questions/34930763/what-is-the-logic-behind-d3-js-nice-ticks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!