我目前正在尝试在Javascript中实现一个树形映射算法。更具体地说,是Squarified Treemaps中描述的算法。给出的伪代码如下所示:
procedure squarify(list of real children, list of real row, real w)
begin
real c = head(children);
if worst(row, w) <= worst(row++[c], w) then
squarify(tail(children),row++[c], w)
else
layoutrow(row);
squarify(children,[], width());
fi
end然而,我的JavaScript看起来像这样:
var c = children[0];
if (worst(row, w) >= worst(row.concat(c), w)) {
this.squarify(children.splice(1), row.concat(c), w);
} else {
layoutrow(row);
this.squarify(children, [], width());
}据我所知,我的代码工作正常,但不平等是错误的。我假设我在我的实现中忽略了一些东西,或者在伪代码中不等式是错误的吗?谢谢
发布于 2013-06-23 04:47:16
你想要添加c到当前的row,当这样做会改善宽高比,例如,当
worst(row++[c], w) < worst(row, w)我最近在github上提交了一段代码,它用TypeScript实现了算法,并包含了现成的JavaScript:
发布于 2017-06-03 03:53:12
如果您只对布局算法感兴趣,请查看我的squarify npm包。它只返回布局数据,让您可以随心所欲地呈现结果。
https://stackoverflow.com/questions/9880635
复制相似问题