How to connect nodes with TikZ chain like this example? - chain

After reading How to connect nodes with TikZ?,I am thinking about how to convert below simple example to use TiKz chain.
Current MWE:
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,positioning,calc}
\tikzset{
block/.style={draw,text width=2em,minimum height=1em,align=center},
arrow/.style={->}
}
\newcommand\connect[2]{\path[draw,arrow] (#1) |- ($(#1)!1/2!(#2)$) -| (#2)}
\begin{document}
\begin{tikzpicture}[>=stealth']
\node[block] (N1) {N1};
\node[block,below=1cm of N1,xshift=-1cm] (N2) {N2};
\connect{N1}{N2};
\end{tikzpicture}
\end{document}
Current output:
I wish to use chain library to do it but still not find right way. The node position should not change and the connection line style should the same.

From this example, it use chain for straight line node connection but use \draw command to draw no-straight line path.
So I think it's not proper to use chain for current tasks. Or you can just create two invisible coordinate then connect it with chain (too complicated, right?).
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,chains,positioning,scopes,quotes}
\tikzset{
block/.style={draw,text width=2em,minimum height=1em,align=center},
arrow/.style={->}
}
\begin{document}
\begin{tikzpicture}[>=stealth']
{[start chain]
\node[block,on chain] (N1) {N1};
\node[block,on chain,join=by {arrow},below=1cm of N1,xshift=-1cm] (N2) {N2};
}
\end{tikzpicture}
\end{document}

Related

evenly distribute pygraphviz nodes

I have a graphviz code like this:
import pygraphviz as pgv
A = pgv.AGraph(strict=False, directed=True,
overlap=False, sep="+10,10")
[A.add_node(k) for k, v in S] # adding all nodes
A.add_edge(S.created, S.packaged_unassigned)
A.add_edge(S.packaged_unassigned, S.packaged_assigned)
A.add_edge(S.packaged_assigned, S.packaged_unassigned, style="dotted")
A.add_edge(S.packaged_assigned, S.shipped_to_distributor)
A.add_edge(S.shipped_to_distributor, S.on_distributor_side_out)
A.add_edge(S.on_distributor_side_out, S.shipped_to_deployer)
A.add_edge(S.shipped_to_deployer, S.on_distributor_side_in)
A.add_edge(S.on_distributor_side_in, S.shipped_to_lab)
A.add_edge(S.shipped_to_lab, S.on_lab_side)
A.add_edge(S.on_lab_side, S.analysis_completed)
A.add_edge(S.analysis_completed, S.completed)
A.layout()
A.draw("status_chart.png")
which produces this output:
https://i.ibb.co/7pJQ8rd/Screenshot-2020-12-20-at-22-23-10.png
My concern here is that the nodes seem to not utilize the available space properly. Instead they just span the diagonal of the image.
How can i make graphviz utilize the space better to create a smaller image while keeping the constraint of no overlaps?
One constraint is that you have specified a chained graph. and thus, the plot is somewhat constrained by that.
See the documentation for some possible alternative options to specify:
https://pygraphviz.github.io/documentation/latest/reference/agraph.html
For example, you can try specifying a landscape view
AGraph(landscape='true'...)
You can also try experimenting with different layout directives:
Optional prog=[‘neato’|’dot’|’twopi’|’circo’|’fdp’|’nop’] will use specified graphviz layout method.
Also see:
unflatten(args='')
To adjust directed graphs to improve layout aspect ratio.
Another technique you could use is to break-up parts of the graph, such that it might look like this (adding a text label to the nodes, with the numbering scheme):
(1) -> (2) ->(3)
(4) -> (5) ->(6)
...
NOTE: The Python documentation for that library specifically suggests that you also refer to the Graphviz documentation...for additional options.
http://www.graphviz.org/doc/info/lang.html
http://www.graphviz.org/doc/info/attrs.html
For example:
http://www.graphviz.org/doc/info/attrs.html#d:ratio
http://www.graphviz.org/doc/info/attrs.html#a:layout
http://www.graphviz.org/doc/info/attrs.html#d:scale
The Gallery also has some great examples, illustrating the use of different parameters
http://www.graphviz.org/gallery/

Multiple graphs inside Graphviz DOT file

I have this Graphviz DOT graph:
digraph unit_test {
label="Unit test"
edge [fillcolor="#a6cee3" color="#1f78b4"]
node[shape="ellipse" style="filled" fillcolor="#1f77b4"]
start
end
node[shape="box" style="filled" fillcolor="#ff7f0e"]
process
subgraph cluster_process {
label = "Major logic"
process
}
start -> process
process -> end
}
The above renders as:
I have this second graph:
digraph details {
label = "Process details"
edge [fillcolor="#a6cee3" color="#1f78b4"]
node[shape="ellipse" style="filled" fillcolor="#1f77b4"]
start
end
node[shape="box" style="filled" fillcolor="#ff7f0e"]
details
subgraph cluster_details {
label = "Details"
details
}
start -> details
details -> end
}
Which renders to:
Problem
When I put the above two graphs inside the same DOT file named supporting.dot and I run dot -Tpng -o supporting.png supporting.dot command, terminal prints out some jiberish and the output image file won't contain both graphs, it just contains the first one. Is it possible to use multiple graphs inside a single DOT file? If so, what am I missing?
Question is unclear about what is to be accomplished, but maybe the following is a starting point
digraph G{
subgraph unit_test {
label="Unit test"
edge [fillcolor="#a6cee3" color="#1f78b4"]
node[shape="ellipse" style="filled" fillcolor="#1f77b4"]
start
end
node[shape="box" style="filled" fillcolor="#ff7f0e"]
process
subgraph cluster_process {
label = "Major logic"
process
}
start -> process
process -> end
}
subgraph details {
label = "Process details"
edge [fillcolor="#a6cee3" color="#1f78b4"]
node[shape="ellipse" style="filled" fillcolor="#1f77b4"]
start1 [label="start"]
end1 [label="end"]
node[shape="box" style="filled" fillcolor="#ff7f0e"]
details
subgraph cluster_details {
label = "Details"
details
}
start1 -> details
details -> end1
}
}
Note the naming / labels in the second subgraph.
Dot can't render 2 graphs into a single file, the output you see is probably the content of one of the graphs as a png.
In order to prevent that, you may run your graphs first through gvpack - something similar to:
gvpack -u supporting.dot | dot -Tpng -o supporting.png
This combines all graphs in supporting.dot into a single graph, which then is rendered with dot.
The layout of the graphs can be influenced by some more options of gvpack.
It is legal to have multiple graphs defined in one input file. You can then produce multiple output files using the -O option, like this:
dot -Tpng -O multi.gv
This will produce multi.gv.png and multi.gv.2.png
I got a better answer
http://www.bound-t.com/manuals/ref-manual.pdf
The -dot_dir option and the names of drawing files
The -dot option creates a single file that contains all drawings from one Bound-T run. If you
then use the dot tool to create a PostScript file, each drawing will go on its own page in the
PostScript file. However, dot can also generate graphical formats that do not have a concept of
"page" and then it may happen that only the first drawing is visible. If you want to use such
non-paged graphical formats it is better to create a directory (folder) to hold the drawing files
and use the Bound-T option -dot_dir instead of the option -dot. The -dot_dir option creates a
separate file for each drawing, named as follows:
• The call-graph of a root subprogram is put in a file called cg_R_nnn.dot, where R is the
link-name of the root subprogram, edited to replace most non-alphanumeric characters
with underscores '_', and nnn is a sequential number to distinguish root subprograms that
have the same name after this editing.
• If the call-graph of some root subrogram is recursive, Bound-T draws the joint call-graph of
all roots and puts it in a file called jcg_all_roots_001.dot.
• The flow-graph of a subprogram is put in a file called fg_S_nnn.dot, where S is the linkname of the subprogram, edited as above, and nnn is a sequential number to distinguish
subprograms that have the same name after this editing and also to distinguish drawings
that show different flow-graphs (execution bounds) for the same subprogram.
The sequential numbers nnn start from 1 and increment by 1 for each drawing file; the same
number sequence is shared by all types of drawings and all subprograms. For example, if we
analyse the root subprogram main?func that calls the two subprograms start$sense and
start$actuate, with the -dot_dir option and -draw options that ask for one flow-graph drawing
of each subprogram, the following drawing files are created:
• cg_main_func_001.dot for the call-graph of main?func
• fg_main_func_002.dot for the flow-graph of main?func
• fg_start_sense_003.dot for the flow-graph of start$sense
• fg_start_actuate_004.dot for the flow-graph of start$actuate.

! Missing number, treated as zero error in latex when using for loop

\begin{algorithm}
\caption{AlgorithmCH election algorithm}
\label{algorithm}
\begin{algorithmic}[1]
\Procedure{CHElection}
\For{each node i }
\EndFor
\EndProcedure
\end{algorithmic}
\end{algorithm}
I have this code used to write an algorithm in LATEX but I received this error (! Missing number, treated as zero error) when I point to the error, I saw it at \End for. Can anyone tell me why I am getting this error please?
This are the packages I added for writing an algorithm
\usepackage[noend]{algpseudocode}
\usepackage[ruled,noresetcount,noend]{algorithm2e}
Don't load algorithm2e when you're using algpseudocode. The former creates an algorithm floating environment, but in order to use algorithmic from algpseudocode, you should load algorithm instead (from the algorithms bundle).
\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\begin{document}
\begin{algorithm}
\caption{AlgorithmCH election algorithm}
\label{algorithm}
\begin{algorithmic}[1]
\Procedure{CHElection}{}
\For{each node~$i$}
\EndFor
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
Note also the second (mandatory) argument for \Procedure, which designates the arguments passed to the procedure. It can also be left blank, but you need to explicitly include this.
I just removed that error by placing the packages in the folloing order
\usepackage{algopseudocode}
%\usepackage{algorithmic} not required
\usepackage{algorithm}

SPSS: Can I generate graphs for multiple variables using a single syntax input with the GRAPH command?

I was wondering if it was possible to create graphs for multiple variables in a single syntax command in SPSS:
GRAPH
/HISTOGRAM(NORMAL)=
As it is, I'm creating multiple graphs as such:
GRAPH
/HISTOGRAM(NORMAL)=CO
GRAPH
/HISTOGRAM(NORMAL)=Min_last
GRAPH
/HISTOGRAM(NORMAL)=Day_abs
etc etc.
If I would do something along the lines of:
GRAPH
/HISTOGRAM(NORMAL)=CO Min_last Day_abs
and it would generate a graph for each variable, I'd be pretty happy.
Anyways, let me know if you think it's possible or if I need to provide more info. Thanks for reading!
If you just to save typing and want an independent set of graphs, you can define a macro like this.
define !H (!positional !cmdend)
!do !i !in (!1)
graph /histogram(normal)=!i.
!doend
!enddefine.
and invoke it with a list of variables.
!H salary salbegin.
The way I like to do it is to reshape the data so all three variables are in the same row using VARSTOCASES and then either panel the charts in small multiples (if you want the axes to be the same) or use SPLIT FILES to produce seperate charts. Example of the split file approach below:
*Making fake data.
INPUT PROGRAM.
LOOP #i = 1 TO 100.
COMPUTE CO = RV.NORMAL(0,1).
COMPUTE Min_last = RV.UNIFORM(0,1).
COMPUTE Days_abs = RV.POISSON(5).
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
*Reshaping to long.
VARSTOCASES /MAKE V FROM CO Min_last Days_abs /INDEX VLab (V).
*Split file and build seperate charts.
SORT CASES BY VLab.
SPLIT FILE BY VLab.
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=V
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: V=col(source(s), name("V"))
GUIDE: axis(dim(1), label("Value"))
GUIDE: axis(dim(2), label("Frequency"))
ELEMENT: interval(position(summary.count(bin.rect(V))), shape.interior(shape.square))
END GPL.
SPLIT FILE OFF.

how to establish relation between any two nodes of d3 tree layout

I have a D3 tree layout.There will be relation between any two nodes,based on this relation i want to show some connection between 2 nodes.Till now i was using circles.on onmouse circles of the 2 nodes will be in some specified color.circles were not covering images exaclty.so i applied transform but it disturbing some other functionalities.
my sole purpose is to show some connection between any two nodes using circles or something else.i tried applying circles using CSS3 but it didnt work
is there any way to achieve my requirement
If I am understanding you, there are different ways to achieve this, and this is only one.
Consider this:
function highlight() {
var selectedClass = d3.select(this).attr("class");
d3.selectAll("circle")
.style("fill",function(d) {
if ( selectedClass == d3.select(this).attr("class"))
return "magenta";
});
}
Assuming you have established the relationship between any given number of nodes (two or more) by assigning them the same class (perhaps a big assumption), then code like the one above can display such relationship. If you click on one of the nodes (this function is called by the node .on("click"...), the others will also display the desired change, illustrated here by a change in color. Does this help?

Resources