I'm trying to implement this graph which looks like:
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:
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.
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.