D3 Tree Graph Modified Data Model - d3.js

I'm hoping to get opinions on what would be a good data model to drawing something like d3 tree graph. Tree graph won't work for me as is because I have scenarios where a child node could be linked with two parent nodes, sometimes, the parent nodes from different levels of hierarchy. I'm planning to modify d3 tree graph to use a different data model, and here's where I'd really appreciate expert opinions. Following is a simple representation of what I think the data model could be. One is hierarchical model and the other is flat. Has anyone actually meddled with d3 tree data model? Any help/opinions are greatly appreciated! Thanks in advance for the help!
var hierarchicalData = [
{
"id": "n1",
"children": [
{
"id": "n1-a",
"children":[
{
"id": "n1-a-1"
}
]
},
{
"id": "n1-b",
"children":[
{
"id": "n1-b-1"
}
]
}
]
},
{
"id": "n2",
"children": [
{
"id": "n2-a",
"children":[
{
"id": "n2-a-1"
}
]
}
]
}
];
The following is a flat representation of the exact same hierarchical model but contains "level" that represents hierarchy.
{
"n1":{
"level": 0,
"children": ["n1-a", "n1-b"],
},
"n1-a":{
"level": 1,
"children":["n1-a-1"]
},
"n1-a-1":{
"level": 2,
"children":[]
},
"n1-b":{
"level": 1,
"children":["n1-b-1"]
},
"n1-b-1":{
"level": 2,
"children":[]
},
"n2":{
"level": 0,
"children": ["n2-a"]
},
"n2-a":{
"level": 1,
"children": ["n2-a-1"]
},
"n2-a-1":{
"level": 2,
"children":[]
}
}

If a child node can have more than one parent, then it's not a tree graph by definition.
There are several UI approaches you may take if you want to have a tree but it really depends on what you're trying to accomplish.
I worked with d3 tree to present a company Org-chart.
Several companies have employees with a direct manager and secondary manager.
What we did is showing the connection only to the direct manager.
But we presented the link to the other manager on mouse-over on the employee node.
This is more of a UI solution than a data model solution and there are many other possibilities.
Another option is to do what My-heritage did with family tree. They're showing both parents of each node, but only one of them is connected to the rest of the tree presented.

Related

Querying geoshape results from different indexes

I have the following scenario: I have an index with all possible ads of my platform. These ads contain an object with coordinates (latitude/longitude).
{
"id": "123",
"slug": "my-ad-slug",
"location": {
"coordinates": {
"latitude": 1.123456,
"longitude": 1.987654
}
}
I also have another index with some locations and their polygons and shapes for geolocation searches.
{
"id": "456",
"name": "my location",
"geo_location": {
"type": "Polygon",
"coordinates": [...]
}
}
My question is: how can I query all ads that are within a certain polygon, since I have two different indexes in this case? Do you see an easy way on doing so?
Thanks y'all!

Receive JSON data from Neo4j to Spring Boot API

I'm trying to send data from Neo4J to Spring boot and I want to receive a JSON like this:
{
"name": "Alex Statham",
"people": [
{
"name": "Jason Statham",
"people": [
{
"name": "Lyna Statham"
},
{
"name": "John Statham"
}
]
},
{
"name": "Will Statham",
"people": [
{
"name": "Michael Statham"
}
]
}
]
}
I try many query and this one maybe the best query which returns a correct family tree for all cases, but it only return nodes with no relationship so I can't put that data to the Library I use:
MATCH (p1:Person {maBN:3})
CALL apoc.path.subgraphNodes(p1, {
sequence: '>Person,FCHILD,>Person,FCHILD,>Person',
maxLevel: 6
}) YIELD node
RETURN node, p1
Here is that Library: https://www.npmjs.com/package/react-tree-graph
What should I do? I don't know too much about Cypher and Neo4j.
You could use apoc.convert.toTree which takes a list of paths and creates a structure like yours.

Can D3 or CrossFilter be used to aggregate totals from multidimensional datasets?

Question: When provided a multidimensional json structure that lacks key:values for some nodes, is it possible to reduce the structure in D3 or CrossFilter to aggregate totals accross each node that has a unique identifier?
Using plain object notation, I'm able to filter on just on subset of data: data.map.exe.Program_Files. I would like to calculate and group from Class and Type located 3 nodes down from the map notation regardless of the parent node value. The Donut Chart would be used to filter on (ps1, exe, dll, etc..)
Example Script:
Plunker Example
Note: I have no control over the dataset and required to maintain the structure of the current data consumed by other D3 controls. So flattening into a new Object Array would lose binding with other controls.
Sample Subset of dataset, see data.json on plunker:
{
"map": {
"ps1": {
"User": [],
"Program_Files": [],
"System_Files": [
{
"class": "dir",
"type": "ps1",
"total": 10,
"handled": 5,
"nothandled": 5,
"percentHandled": 0.0,
"id": 1,
"directory": "c:\\windows\\system32\\"
}
],
"Temp": [],
"Public": []
},
"dll": {
"User": [],
"Program_Files": [],
"System_Files": [
{
"class": "dir",
"type": "dll",
"total": 1000,
"handled": 685,
"nothandled": 315,
"percentHandled": 0.0,
"id": 1,
"directory": "c:\\windows\\system32\\"
}
],
"Temp": [],
"Public": []
}....
After further research and guidance, the final solution was to flatten the structure into a single object array. One can still process multi-deminsional json structures when a key:value element exists, this was not my case, so the format condition forced me to flatten the structure.

Accessing custom attribute array in d3js tree node

I am pretty new to the D3JS library but is it possible to add a custom attribute to the json file for the tree layout to process and retrieve the data while building the tree if the particular attribute is not empty?
For example:
{
"name": "Josphen",
"id": "1",
"children": [
{
"name": "Ronald",
"id": "3"
},
{
"name": "Coxy",
"id": "4",
"spouse": [
{
"name": "baby",
"id": "5"
}
]
}
]
}
Would later allow me to retrieve attribute with id=5 while generating the node of id=4.
Any insight into this is appreciated.

Dendrogram from hierarchical clustering in D3

I'm quite new to D3 so I apologize if this is a very basic question. I wish to implement a dendrogram that shows the result of a hierarchical clustering algorithm. This layout differs in a major point from the examples I have been able to find: Except for the leaves of the tree, the nodes does not have any identity, but merely joins subtrees at specific heights relative to their like-ness.
As an example look at:
http://r.789695.n4.nabble.com/file/n2293207/Dendrogram.jpeg
Compared to http://bl.ocks.org/mbostock/4063570 this dendrogram does not have the 'n-partite nature' (defined layers for each level of nodes).
The question is thus how to define a dendrogram with arbitrary join positions of subtrees?
Thanks
Thomas
edit:
It seems it was not as difficult as anticipated and it did not require development of a new layout. In my input data I included an additional parameter with the calculated height of the join. An example json file would be something like this:
{
"height": "1",
"children": [
{
"height": "0.8",
"children": [
{
"name": "leaf 1",
"height": "0"
},
{
"height": "0.35",
"children": [
{
"name": "leaf 2",
"height": "0"
},
{
"name": "leaf 3",
"height": "0"
}
]
]
},
{
"name": "leaf 4",
"height": "0"
}
]
}
and then, when calculating the node object, transform the y value using map:
var nodes = cluster.nodes(root).map(function(d) {d.y = scale(d.height); return d});
where cluster is your cluster layout object and scale is a suitable scale for the dendrogram height.

Resources