Collapse a jung node based on node selection - graph

I am trying to collapse all the children of a vertex when a user clicks on it. But the problem is that, every time I tried to do so, I got the following error:
Tree must not contain edu.ics.jung.graph.DelegateForest#17510d96
The code is given below:
public void graphClicked(MyNode v, MouseEvent me)
{
Collection<MyNode> childrens = graph.getChildren(v);
Collection picked = new Hashset(childrens);
if(picked.size>1)
{
Graph ingraph = this.radialLayout.getGraph();
Graph clusterGraph = collapser.getClusterGraph(graph,childrens);
Graph g = collapser.collapse(ingraph,clustergraph); //The error report points on this line
.
.
.
}
}
I am using a Forest with RadialLayout.
Can anyone help me? How can I solve the problem?

Check out the tree node collapse and vertex collapse demos here:
http://jung.sourceforge.net/applet/index.html
The source for each of these is included in the distribution files.

Related

How to get visible nodes with Visjs

I have this large network created with vis-network:
When clicking on the nodes I create clusters. For example if I click on the 2 green boxes the result is:
In this new view I have two regular nodes ("Program #3289" and "Task #7300") and two clusters ("Project #3415" and "Project #3416") that contain their children.
If I use dataset.get() it returns all my 106 initial nodes.
If I use network.body.nodes it returns all my 106 initial nodes + my two clusters.
What I want: a way to only get the visible nodes in my network. In that case, I should get only 2 regular nodes and 2 clusters.
Did I miss a function that permits to do it?
Thank you
I finally came up with the below solution:
var visibleNodes = [];
for (var nodeId in visNetwork.body.nodes) {
// we check if the node is inside a cluster
if (!visNetwork.clustering.clusteredNodes[nodeId]) {
visibleNodes.push(nodeId)
}
}

Creating edge using vertex ids

I am trying to bulk load data into janusgraph.
I am trying to follow bulk load recommendations
I am strugling with point (d) which is "Add all the edges using the map to look-up JanusGraph’s vertex id and retrieving the vertices using that id"
My current code(scala) looks like
val key = Key[String]("Key")
val sLabel : StepLabel[Vertex] = StepLabel("target")
case (src, edgeType, dest) =>
graph.V().has(key, dest).as(sLabel).traversal.V().has(key, src).addE(edgeType).to(sLabel).traversal
.property("propertyKey", "propertyValue")
I have vertexId of source and dest vertex but I am unable to figureout how to change this code to create edge using vertexIds.
I am quite new to gremlin, any help would be appreciated.
case (idSrc, edgeType, idDest) =>
g.V(idSrc).as("a").V(idDest).addE(edgeType).from("a")

sunburst.R total frequency count is incorrect

I am plotting a sunburst donut and I cannot figure out why the total is incorrect.
library(sunburstR)
reports <- data.frame(
sequence = c("SVP-VP-Dir-end","SVP-VP-Dir-end","SVP-VP-Dir-end","SVP-VP-Dir-end","SVP-No VP-Dir-end","SVP-No VP-Dir-end","SVP-No VP-Dir-end"),
freq = as.numeric(c("167","60","51","32","5","1","1")))
sunburst(reports, count = TRUE)
It is supposed to be 100% 317 of 317 . Anyone know how to fix this? There is not much documentation on this great package.
Also, I would like it to have a default value in the center of donut.
If there is another way to create an interactive donut using R, please let me know.
Thanks you in advance.
It looks like the default function generating the message in the center of the donut rounds the total value to the nearest ten.
But you can customize this function using the explanation argument of sunburst. Oddly, the customized function (in javascript) must be provided as a string.
Try the following function:
custom.message = "function (d) {
root = d;
while (root.parent) {
root = root.parent
}
p = (100*d.value/root.value).toPrecision(3);
msg = p+' %<br/>'+d.value+' of '+root.value;
return msg;
}"
Now:
sunburst(reports, explanation = custom.message )
will generate the donut displaying exact total values. The count argument is no longer needed, as it is used by the default explanation function.
The value returned by custom.message is html code. As you can see, I've just inserted a line break (<br/>). You can modify the msg return value to further customize the look and feel.

Alternative to Recursive Function

I have been working on MLM (multi level marketing) application.
Below is the code snippet (not entire code) of recursive function which I had written in initial phase and was working properly. But now the MLM tree is too deep and recursive function stops. It says maximum nesting level exceeded. I increased nesting function call levels few times but now I dont want to increase it further as I know that's not right solution.
Can anyone suggest a alternative code (may be iterative) to me for this?
<?php
function findallpairs($username, $totalusers= 0)
{
$sql = "select username,package_id from tbl_user where
parent_id = '".$username."' order by username";
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result))
{
$username = $row["username"];
$totalusers++;
$arrtmp = findallpairs($username, $totalusers);
$totalusers = $arrtmp["totalusers"];
}
}
$arrpoints["totalusers"] = $totalusers;
return $arrpoints;
}
?>
Note : Please remember my original code is too big but I have been pasting just the important aspect of the logic here.
It would be a great help for me if I find the alternative solution to this.
Thanks in advance!
How deep are you going?
The day makes a mutliway tree within your sql database. Trees are recursive structures, and recursive code is what naturally fits.
You may be able use use what i'm calling quasi-memiozation.
This should be easy if you have the children listed in the DB structure. Take a result for all users with no childrin, memioize their value into a hash or tree with the key being the user ID and the value 1. Then just mass iterate over each user (or just the parents of memiozed entries) and if it has values memiozed for all its children, add them together and memoioze that value. Repeat the iteration until you find the root (a user with no parent)
If you don't have a record of children it's likely terribly inefficient.

OrientDB GraphDatabase: OSQLSynchQuery for #RID to get graph.getVertex(rid) ... the fastest way to load a vertex from index key?

Given a basic Blueprints-compatible OrientGraph with Index 'name' (unique or notunique), any suggestions for how the following could be improved, if needs be?
Note: I can't find a definitive guide to load a [blueprints] vertex using index. I have a large graph and using has('name','bob') (in console) takes 2 minutes! On the other hand, an index-based search returns in milliseconds.
The best I've come up with so far:
OrientGraph graph = new OrientGraph("local:/graph1/databases/test", "admin", "admin");
List<ODocument> resultlist = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>("SELECT FROM INDEX:name WHERE KEY = 'bob'"));
ODocument resultodoc = resultlist.get(0).field("rid");
String rid = resultodoc.getIdentity().toString(); // would return something like #6:1500000
Vertex v1 = graph.getVertex(rid);
System.out.println(v1.getProperty("name"));
OrientDB supports the IndexableGraph interface. To use it take a look at:
https://github.com/tinkerpop/blueprints/wiki/Graph-Indices

Resources