【发布时间】:2014-08-14 14:17:45
【问题描述】:
谁能告诉我下面的代码到底发生了什么?我知道它是用于缩放的,但是在这种情况下,二维边界数组有什么作用?
var bounds = path.bounds(d),
dx = bounds[1][0] - bounds[0][0],
dy = bounds[1][1] - bounds[0][1],
x = (bounds[0][0] + bounds[1][0]) / 2,
y = (bounds[0][1] + bounds[1][1]) / 2,
scale = .9 / Math.max(dx / width, dy / height),
translate = [width / 2 - scale * x, height / 2 - scale * y];
提前致谢。
【问题讨论】:
-
这个方法返回边界框(包围物体的最小矩形),它是一种简单的计算中心的方法。
-
所以
path.bounds()输出为[[left,top],[right,bottom]]。不同于geo.path.bounds()输出[[left, bottom], [right, top]]和API。可能需要放到github api中。
标签: d3.js