最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the logic behind d3.js nice() ticks - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question asked Jan 21, 2016 at 17:46 RazzildinhoRazzildinho 2,5841 gold badge21 silver badges33 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 14

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);
发布评论

评论列表(0)

  1. 暂无评论