【发布时间】:2014-07-21 08:55:19
【问题描述】:
我有一个基于force-collapsable example 的可视化,我想加快或跳过初始节点移动以尽快使图表达到平衡。
我遵循了answer 中的建议,并从我的代码中调用了 tick(),但它在 force-collabsable 示例中不起作用,因为 force 对象上没有 tick 或 alpha 方法。
这是我的代码在修改后的样子,我删除了 on tick 调用并在最后添加了 force.tick() 调用:
var force = d3.layout.force() // line 38 in the example
//.on("tick", tick) // commented out as I call tick instead
.charge(function(d) { return d._children ? -d.size / 100 : -30; })
.linkDistance(function(d) { return d.target._children ? 80 : 30; })
.size([w, h - 160]);
function update() { // line 56 in the example
var nodes = flatten(root),
links = d3.layout.tree().links(nodes);
force // line 60 in the example
.nodes(nodes)
.links(links)
.start();
force.tick() // added by me to cause a tick and the point of error
但调用失败并显示“未捕获类型错误:未定义不是函数”,因为该方法不存在。
当我调用 force 对象时(取自 Chrome 调试器),它具有以下值:
charge: function (x) {
distance: function (x) {
drag: function () {
friction: function (x) {
gravity: function (x) {
linkDistance: function (x) {
linkStrength: function (x) {
links: function (x) {
nodes: function (x) {
on: function (type, listener) {
resume: function () {
size: function (x) {
start: function () {
stop: function () {
theta: function (x) {
proto: Object
为什么这个例子中的力对象与其他不使用树形布局的力布局例子不同?如何直接调用tick()?
【问题讨论】:
-
没有答案的链接。
-
能贴出相关代码吗? JS错误的行号也会有帮助,所以我们知道什么是未定义的。
标签: javascript svg d3.js force-layout