Insert arrows using graphdrawing library - graph

I would like to link numbers 6 -> 5 and 5 -> 4 but I have no clue on how to do it.
My code is as follows
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}[>=stealth, every node/.style={rectangle, rounded corners, draw, minimum size=0.75cm}]
\graph [tree layout, grow=down, fresh nodes, level distance=0.5in, sibling distance=0.5in]
{
Flight 0 -> {
Flight 1 -> { 4 -> , 5},
Flight 2 -> { 6 },
Flight 3 -> { 7,8 }
}
};
\end{tikzpicture}
\end{document}
This is the output:

The nodes can be accessed by their name so you can simply draw arrows between them:
% !TeX TS-program = lualatex
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}[>=stealth, every node/.style={rectangle, rounded corners, draw, minimum size=0.75cm}]
\graph [tree layout, grow=down, fresh nodes, level distance=0.5in, sibling distance=0.5in]
{
Flight 0 -> {
Flight 1 -> { 4 , 5},
Flight 2 -> { 6 },
Flight 3 -> { 7,8 }
}
};
\draw[->] (6) -- (5);
\draw[->] (5) -- (4);
\end{tikzpicture}
\end{document}

Related

How to print custom attributes in xdot

I have some custom attributes in a .dot file, but running the command xdot file_name.dot does not print those attributes along with the nodes and edges.
How to do so?
I have attached the contents of .dot file for reference.
digraph toy11 {
0 [label1="", label2="<l0>", label3="(process2)"]
1 [label1="", label2="<l1>", label3="(process1)"]
2 [label1="I", label2="<l2>", label3="(process2)"]
0 -> 0 [edge_type="prior1", vedge="<a>"]
0 -> 0 [edge_type="prior2", vedge="<b>"]
0 -> 1 [edge_type="prior2", vedge="<b>"]
1 -> 2 [edge_type="prior0", vedge="<b>"]
}

How would an alternate color pass every 4 elements to repeat the same component pattern with Array.map function?

I'm trying to send my child components in a reaction app an alternate color as a property, and I'm not really sure how to do it. The color of each CardSimpleRow component must alternate in 4 different colors and once the 4th color is there, it returns to the beginning of the color, let's say. I want to use map because my matrix is dynamic and writing each row of the matrix to render seems unnecessary.
export const FollowScreen = () => {
const alternatingColor = [ ["#d72226", "#a8232a"], ["#123", "#a33a"], ["#f3f3f3", "#a8232a"], ["#dd26", "#a8232a"] ]
return (
<>
{
data.map((elements, index) => {
return <CardSimpleRow
color={index % 4 ? alternatingColor[1] : alternatingColor[0]}
elements={elements}
/>
})
}
</>
)
It's a gradient so I need to send the 1st array, then the 2nd array, then the 3rd, then the 4th and after that go back to the 1st array>
Example if there are 8 CardSimpleRow, I need 4 cards with the array from 0 to 4 and then the other four with the array from 0 to 4 again
If I got it right, you need something like:
alternatingColor[0]
alternatingColor[1]
alternatingColor[2]
alternatingColor[4]
alternatingColor[0]
alternatingColor[1]
...
To obtain that you just need to change a single line:
...
color={alternatingColor[index % 4]}
...
this will access the correct element in alternatingColor by taking the integer remainder based on the index.
Index 0 => remainder of 0 / 4 == 0
Index 1 => remainder of 1 / 4 == 1
...
Index 5 => remainder of 5 / 4 == 1

Update operator yields empty object in JQ

I cannot understand the behaviour of the update operator of jq (version 1.6) shown in the following examples.
Why does example 1 return an updated object, but example 2 and 3 return an empty object or a wrong result?
The difference between the examples is only the calling order of the function to convert a string into a number.
#!/bin/bash
#
# strange behaviour jq
# example 1 - works as expected
jq -n '
def numberify($x): $x | tonumber? // 0;
"1" as $stringValue
| numberify($stringValue) as $intValue
# | { } # version 1: a.b does not exist yet
| { a: { b: 1 } } # version 2: a.b exists already
| .["a"] |= { b: (.b + $intValue) }
'
# result example 1, version 1 - expected
# {
# "a": {
# "b": 1
# }
# }
# result example 1, version 2 - expected
# {
# "a": {
# "b": 2
# }
# }
# example 2 - erroneous result
jq -n '
def numberify($x): $x | tonumber? // 0;
"1" as $stringValue
# | { } # version 1: a.b does not exist yet
| { a: { b: 1 } } # version 2: a.b exists already
| .["a"] |= { b: (.b + numberify($stringValue)) }
'
# result example 2, version 1 - unexpected
# {}
# result example 2, version 2 - unexpected
# {}
# example 3 - erroneous result
jq -n '
def numberify($x): $x | try tonumber catch 0;
"1" as $stringValue
# | { } # version 1: a.b does not exist yet
| { a: { b: 1 } } # version 2: a.b exists already
| .["a"] |= { b: (.b + numberify($stringValue)) }
'
# result example 3, version 1 - unexpected
# {
# "a": {
# "b": 0
# }
# }
# result example 3, version 2 - unexpected
# {
# "a": {
# "b": 1
# }
# }
#oguzismail That's a good idea to use '+=' instead of '|='.
I hadn't thought of it before.
Currently, my code with the workaround for the bug looks like this:
def numberify($x): $x | tonumber? // 0;
"1" as $sumReqSize
| "10" as $sumResSize
| { statistics: { count: 1, sumReqSize: 2, sumResSize: 20 } }
| [numberify($sumReqSize), numberify($sumResSize)] as $sizes # workaround for bug
| .statistics |= {
count: (.count + 1),
sumReqSize: (.sumReqSize + $sizes[0]),
sumResSize: (.sumResSize + $sizes[1])
}
'
Following your suggestion it will be more concise and doesn't need the ugly workaround:
def numberify($x): $x | tonumber? // 0;
"1" as $sumReqSize
| "10" as $sumResSize
| { statistics: { count: 1, sumReqSize: 2, sumResSize: 20 } }
| .statistics.count += 1
| .statistics.sumReqSize += numberify($sumReqSize)
| .statistics.sumResSize += numberify($sumResSize)
This is a bug in jq 1.6. One option would be to use an earlier version of jq (e.g. jq 1.5).
Another would be to avoid |= by using = instead, along the lines of:
.a = (.a | ...)
or if the RHS does not actually depend on the LHS (as in your original examples), simply replacing |= by =.
This is a bug in jq 1.6. In this case you can use try-catch instead.
def numberify($x): $x | try tonumber catch 0;
But I don't know if there is a generic way to walk around this issue.

Create graph having nodes with no labels and no separations between its edges with Graphviz

I want to generate this kind of graphs with graphviz :
I tried the following code :
graph{
node [shape=none label=""]
1 [pos="0,0!"]
2 [pos="1.2145,0.694!"]
3 [pos="1.2145,2.082!"]
4 [pos="0.0,2.776!"]
5 [pos="-1.2145,2.082!"]
6 [pos="-1.2145,0.694!"]
1 -- 2
2 -- 3
3 -- 4
4 -- 5
5 -- 6
6 -- 1
}
But I get the following output
Is it possible to make nodes without labels and edges without any separation between than ?
Thanks for your answers.
digraph D {
graph [nodesep=.02]
node [shape=hexagon]
A B C
}
Gives this:
And this:
digraph D {
graph [nodesep=.02]
node [shape=hexagon orientation=30]
A B C
}
Gives this:

Blinking color sequence in Angular

I have a task to create 4 blinking divs in an Angular project. The colors come from an API in an array with 16 elements and each element is an array with 4 elements (string).
ColorPatterns[
Pattern1["Color1", "Color2", "Color3", "Color4"],
Pattern2["Color1", "Color2", "Color3", "Color4"],
...
Pattern16["Color1", "Color2", "Color3", "Color4"],
]
Color1 is for the first div, Color2 is for the second div and so on.
The sequence of 16 must change per 1 second and after the last element (Pattern16) the sequence should start over: Pattern1 -> Pattern2 -> ... -> Pattern16 -> Pattern1 -> ... .
How should this problem be solved in Angular?
Use an Observable to do the timing stuff. If we can to it for one div then others can be repeated.
Observable.interval(1000) //emit every 1 sec with values = 0 then 1 them 2 ..
.map(value=>ColorPaterns[value%16][0]) // 0 for 1st color
.subscribe((firstColor)=>{
// set 1st div color here
})

Resources