dpvomqeu396484 2017-05-13 06:01
浏览 55
已采纳

如何制作随机坐标编号?

I'm trying to implement this graph which looks like:

enter image description here

My graph has only those yellow nodes. Apparently yellow nodes have a random position. How can I make such position?

Here is my current code:

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,
    ];
}

As you see I've set $key*2 for nodes. This is the output:

enter image description here

All nodes are upon each other which doesn't seem good. Anyway, is there any idea how can I make a cheesy coordinate number for nodes?

Noted that it would be great if you have any suggestion about nodes-relations and their coordinate spot. I mean I can change the query and get any needed number related to nodes' relations.

  • 写回答

1条回答 默认 最新

  • dongxun3424 2017-05-13 09:17
    关注

    You can use some energy based methods, like Force-Directed Graph Drawing. There are different implementations of this renown method in PHP such as this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败