如何制作随机坐标编号?

时间:2017-05-13 06:01:05

标签: php graph

我试图实现this graph,如下所示:

enter image description here

我的图表只有那些黄色节点。显然黄色节点具有随机位置。我怎么能做出这样的立场?

这是我目前的代码:

foreach ($subjects as $key => $subject){

    $nodes[] = [   "data" => [ "id" => "$subject->id",
        "Strength" => 5,
        "selected" => false,
        "cytoscape_alias_list" => ["Aarauer Bierdeckel"],
        "canonicalName" => "Aarauer Bierdeckel",
        "Milk" => "$subject->body",
        "Synonym" => "Kuentener",
        "Quality" => 290,
        "Type" => "Semi-soft",
        "SUID" => $subject->id,
        "NodeType" => "Cheese",
        "name" => "$subject->title",
        "Country" => "Switzerland",
        "shared_name" => "$subject->title"
    ],
        "position" => ["x"=>$key*2,"y"=>$key*2],    // please focus on this line
        "selected" => false,
    ];
}

如您所见,我为节点设置了$key*2。这是输出:

enter image description here

所有节点彼此相连,看起来并不好。无论如何,有什么想法如何为节点制作一个俗气的坐标数?

注意到如果你对节点关系及其坐标点有任何建议会很棒。我的意思是我可以更改查询并获得与节点相关的任何所需数量。关系。

1 个答案:

答案 0 :(得分:0)

您可以使用一些基于能量的方法,例如Force-Directed Graph Drawing。 PHP中这种着名方法有不同的实现,例如this