d3.js nice()滴答声背后的逻辑是什么 [英] What is the logic behind d3.js nice() ticks

查看:130
本文介绍了d3.js nice()滴答声背后的逻辑是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在d3.js中生成了一些图表.我使用以下代码计算要放入我的y轴的值,该值的工作方式类似于超级按钮.

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

但是我现在必须使用pycairo编写python代码,该代码会在服务器端生成d3.js图表​​的克隆.

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

我的问题是,是否有人知道上面代码中使用的逻辑,或者可以提供类似结果的东西,以便我可以在python中复制它以获得在我的y轴上使用的漂亮值?

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?

推荐答案

D3是开源的,因此您可以

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

这篇关于d3.js nice()滴答声背后的逻辑是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆