Graphviz: Control node align in a subgraph - orientation

Consider the following subgraph, with 5 Mrecod nodes:
Is there a way to force a vertical orientation, with the nodes above each other? I've tried rankdir=TB in the subgraph, with no effect.
I am running graphviz under Ubuntu with no special parameters:
dot -Tpng graph.dot -o img/graph.png

Adam, just to clear up a couple of potentially confusing points:
I'm pretty sure that the rankdir attribute applies to the entire graph, you cannot isolate that particular subgraph.
rankdir=TB is the default value to begin with, so adding it isn't really going to do anything.
That said, if I am reading your subgraph correctly, it looks like:
You have a collection of 5 record-type nodes in a cluster.
Each of those nodes have inbound edges from one or more nodes outside the cluster.
None of the nodes within the cluster have edges between them.
If that's correct, then the nodes in your subgraph have the same rank (or probably do, depending upon the rank of the nodes that connect to them). Setting rankdir=LR (or rankdir=RL) will change the orientation of that subgraph so the nodes are aligned vertically, but it will also change the alignment of the overall graph.
One way to get just those nodes to be aligned vertically is to add an invisible edge between them. For example, if you have nodes A, B, C, D and E, your cluster definition might look something like this:
digraph G {
// ...skipping stuff outside the cluster...
subgraph clusterFoo {
node [shape=record]
A [label="..."]
B [label="..."]
C [label="..."]
D [label="..."]
E [label="..."]
edge [style=invis]
A -> B -> C -> D -> E
}
}
Adding the edges will force the nodes in the subgraph to have a different rank, so the default rankdir=TB will lay out the nodes from top to bottom rather than from left to right. The style=invis attribute on these "false" edges will make them invisible.
If you want to tweak the spacing or alignment of the nodes within the cluster you might also want to play with edge attributes such as weight or minlen/attrs.html#d:minlen), or consider constraint=false on the inbound edges.
If I've misinterpreted your graph or if this doesn't help you at all, can you update your question to add a minimal example of the DOT file you are working with?
PS: On Ubuntu, you can use:
dot -Txlib graph.dot
to quickly open up a window with a rendering of the graph in graph.dot without first writing it to a file. The rendered image will even automatically update when you modify the source file.

Related

How to get all nodes within an area surrounded by a node type by using Cypher (Neo4j)

I am trying to do the following:
Let's say this is the initial graph: Initial Graph
I want to get all the blue nodes between red nodes and connect them to a new yellow node. I want to do this for every blue node area seperated by red nodes.
What I am trying to tell: The Result I Want
I want to do this without creating redundant yellow nodes and unnecessary traversals. Also, I want to do this in a single query, if it is possible.
Initially I achieved creating yellow nodes and connecting them by getting paths which start with a red node and end with another red node. However, this solution led to creating redundant yellow nodes since there are some areas seperated by 3 or more red nodes. For instance if a blue node area is seperated by 3 red nodes, this solution finds 3 different paths in that area, therefore creates 3 different yellow nodes. So I had to delete redundant yellow nodes in another query which was terrible in terms of efficiency.
After that, I tried using apoc expand functions, however they require minLevel and maxLevel parameters which again leads to finding more than one path in a blue node area.
In short, the real question is how can I achieve getting each blue node area as a single path without compromising efficiency?
Edit: I also tried creating a yellow node for each blue node directly connected to the red node near it and then connected the other blue nodes to the yellow node if they are reachable through blue nodes, however this query also takes too much time.
As far as I am concerned matching paths like the following query affects time efficiency too negatively:
MATCH path = (:YELLOW)-[link*]-(:BLUE)-[:CONNECTION]-(:RED)
WHERE single(x IN nodes(path) WHERE x:RED)
//Then connect nodes in path to the yellow node if there is no connection
Any suggestions?

Cytoscape define edge length

I am creating a manual layout for a network in Cytoscape version 3.8.2. I would like to be able to define the edge lengths, so the network looks more uniform. Is there a way to define the property edge length?
Specifically, I want something like the below subsection of a network to be a perfect circle.
No, the edge length is not a property in Cytoscape. You would need to calculate it based on the source and target node positions. One way to achieve what you want would be select all of the outer nodes, then do a degree-sorted circular layout, and then drag your central node back into the center.
-- scooter

JUNG layout for left-to-right placement of nodes

Is there an optimal layout in JUNG for left-to-right placement of nodes in the graph? I'm looking for something that would model a data lineage and need to represent this somewhat linearly (left to right).
If your graph is a tree, then you can use the TreeLayout and do some post-processing to rotate it to have the root on the left instead of the top (see the L2RTreeLayoutDemo for an example of how to do this).
If your graph is only sort of tree-shaped, then you may want to extract a tree from your graph first (see MinimumSpanningTreeDemo for one way to do this automatically) and then follow the procedure above.
If neither of those works for you (for example, this won't work if your graph has multiple "roots"), then you will probably need to create your own layout, perhaps based on TreeLayout.

Cytoscape- Selecting directed edges

In Cytoscape, I have bi-directional edges from a reference node. How do I select only those edges that have a particular directionality. For example selecting all the outward directed edges from the reference node.
Have you tried using this:
cy.$id('yourID').outgoers();
This selects all edges going out of the specified node, which you can get by a click-event e.g.
If you want to get the outgoing nodes behind these edges, you can use this:
cy.$id('yourID').outgoers().targets();
http://js.cytoscape.org/#nodes.outgoers
http://js.cytoscape.org/#edges.targets

How to handle text nodes that contain text that goes below baseline?

I have the following problem with Tikz/Latex:
I have some nodes that contain text. Most text doesn't have letters that reach below the baseline. But for those nodes where it happens, the ratio and placement of node height and text/baseline is off. Have a look at the example image.
Solutions I know of:
make the nodes' minimum height bigger. This results in the nodes being sized the same, but the baseline is still at different heights
use struts. This results in all nodes being laid out like the ones containing the offending text. This results in too much space between the baseline of the text and the surrounding box for most nodes
There's a property for nodes: text depth
One can simply set it to 0pt for the offending (or all) nodes.
Note
Of course this is well documented in the pgfmanual.
This is more of a pointer (can't get TikZ at the moment), but since you are not getting anything else, there are two things to try:
1) There is the $\smash[b]{\text{my text y}}$ (you need amsmath for this).
2) Maybe \raisebox{0pt}[0pt]{my text y} is what you want.

Resources