Control Graphviz arrows direction - graphviz

I'm tying to draw the IDEF0 diagram example using Graphviz
digraph UDEF0 {
"Plan New Information Program" [shape=box]
"Issues" [shape=none]
"Operation Data" [shape=none]
"Program Charter" [shape=none]
"Program Team" [shape=none]
"Program Plan" [shape=none]
"Issues" -> "Plan New Information Program"
"Operation Data" -> "Plan New Information Program"
"Program Charter" -> "Plan New Information Program"
"Program Team" -> "Plan New Information Program"
"Plan New Information Program" -> "Program Plan"
}
The problem is that I can't find the way to control direction of arrows around the central box.
I've tried to use hidden "frame" made of invisible South, North, East and West nodes to connect arrows to them. Unfortunately the "frame" works well only if it is empty, and when I connect my "payload" nodes to it, the structure breaks:
digraph UDEF0 {
rankdir=LR
"Plan New Information Program" [shape=box]
"Issues" [shape=none]
"Operation Data" [shape=none]
"Program Charter" [shape=none]
"Program Team" [shape=none]
"Program Plan" [shape=none]
"Program Plan" [shape=none]
"West" [shape=none]
"North" [shape=none]
"South" [shape=none]
"East" [shape=none]
"West" -> "North" -> "East"
"West" -> "South" -> "East"
"West" -> "Issues" -> "Plan New Information Program"
"West" -> "Operation Data" -> "Plan New Information Program"
"North" -> "Program Charter" -> "Plan New Information Program"
"South" -> "Program Team" -> "Plan New Information Program"
"East" -> "Plan New Information Program" -> "Program Plan"
}
Is the any correct way to implement this diagram style?

Using shape = record brings you close to what you want - here my re-written attempt:
digraph UDEF0
{
A[ label = "Plan New\nInformation\nProgram", shape=box, style = filled, fillcolor = grey ]
B[ shape = record, color = white, label = "{ Operation Data | Issues }" ]
node[ shape = none ]
c[ label = "Program Charter" ]
d[ label = "Program Team" ]
e[ label = "Program Plan" ]
{ rank = same; A B e }
c -> A;
A -> d[ dir = back ];
edge[ minlen = 3]
B -> A;
B -> A;
A -> e;
}
yields
E D I T 2018-11-29
In order to avoid the issues that #McKay has shown in his comment, I have re-coded the sample using a HTML like label:
digraph UDEF0
{
A[ label = "Plan New\nInformation\nProgram", shape=box, style = filled, fillcolor = grey ]
B[ shape = plaintext, label =<
<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="15">
<TR>
<TD PORT = "p1">Issues</TD>
</TR>
<TR>
<TD PORT = "p2">Operation Data</TD>
</TR>
</TABLE>>];
node[ shape = none ]
c[ label = "Program Charter" ]
d[ label = "Program Team" ]
e[ label = "Program Plan" ]
{ rank = same; A B e }
c -> A;
A -> d[ dir = back ];
edge[ minlen = 3]
B:p1 -> A;
B:p2 -> A;
A -> e;
}
Which gives us
without warning or error message on my Linux box with graphviz version 2.38.0 (20140413.2041).

Related

How to get file to properly compile. Latex returning *geometry* driver: auto-detecting

\documentclass[12pt]{article}
\usepackage{tikz-er2}
\usepackage[landscape,margin=1cm]{geometry}
%\usepackage{lscape}
\usetikzlibrary{shadows,positioning}
\begin{document}
\tikzset{every entity/.style = {top color=purple,bottom color=yellow!30,draw=blue!50!black!100,drop shadow},
every attribute/.style = {top color=white, bottom color=yellow!20,draw=yellow, drop shadow},
every relationship/.style = {top color=white, bottom color=red!20,draw=red!50!black!100, drop shadow},
every edg/.style={link},
every isa/.style = {top color=white, bottom color=green!20,draw=green!50!black!100, drop shadow}
}
%\begin{landscape}
\resizebox{0.8\textwidth}{!}{%
\begin{tikzpicture}[scale=0.5];
\node[entity] (Artist) {Artist};
\node[attribute](AID)[above right= 1cm of Artist]{\key{Artist\_ID}};
\node[attribute](Name)[below = 1cm of Artist]{Name};
\node[attribute](Bplace)[above = 1cm of Artist]{Birthplace};
\node[attribute](age)[left = 1cm of Artist]{age};
\node[entity] (ArtFacts) [above right = 2em of Artist ] {ArtFacts} edge (Artist);
\node[attribute](AI)[right= 1cm of Artist]{\key{Art\_ID}};
\node[attribute](AID[below = 1cm of ArtFacts]{Artist\_ID};
\node[derived attribute](year)[above = 1cm of ArtFacts]{Year Created};
\node[attribute](title)[above left = 1cm of ArtFacts]{title};
\node[attribute](Price)[right = 1cm of ArtFacts]{price};
\node[attribute](medium)[below right = 1cm of ArtFacts]{medium};
\end{tikzpicture}
}
%\end{landscape}
\end{document}
Trying to create an ER diagram for an art management project. Running into compiling errors when I start 2nd entity and attributes. the first part runs correctly
(AID is missing the closing parenthesis
\documentclass[12pt]{article}
\usepackage{tikz-er2}
\usepackage[landscape,margin=1cm]{geometry}
%\usepackage{lscape}
\usetikzlibrary{shadows,positioning}
\begin{document}
\tikzset{every entity/.style = {top color=purple,bottom color=yellow!30,draw=blue!50!black!100,drop shadow},
every attribute/.style = {top color=white, bottom color=yellow!20,draw=yellow, drop shadow},
every relationship/.style = {top color=white, bottom color=red!20,draw=red!50!black!100, drop shadow},
every edg/.style={link},
every isa/.style = {top color=white, bottom color=green!20,draw=green!50!black!100, drop shadow}
}
%\begin{landscape}
\resizebox{0.8\textwidth}{!}{%
\begin{tikzpicture}[scale=0.5];
\node[entity] (Artist) {Artist};
\node[attribute](AID)[above right= 1cm of Artist]{\key{Artist\_ID}};
\node[attribute](Name)[below = 1cm of Artist]{Name};
\node[attribute](Bplace)[above = 1cm of Artist]{Birthplace};
\node[attribute](age)[left = 1cm of Artist]{age};
\node[entity] (ArtFacts) [above right = 2em of Artist ] {ArtFacts} edge (Artist);
\node[attribute](AI)[right= 1cm of Artist]{\key{Art\_ID}};
\node[attribute](AID)[below = 1cm of ArtFacts]{Artist\_ID};
\node[derived attribute](year)[above = 1cm of ArtFacts]{Year Created};
\node[attribute](title)[above left = 1cm of ArtFacts]{title};
\node[attribute](Price)[right = 1cm of ArtFacts]{price};
\node[attribute](medium)[below right = 1cm of ArtFacts]{medium};
\end{tikzpicture}
}
%\end{landscape}
\end{document}

Fine tuning edge and label placement in dot

I'm plotting a graph in dot. In order to make it legible I need to fine-tune the placement of the edge labels, as well as (if possible) making certain edges straight while others are curved. I would appreciate general advice on how to accomplish these things in dot, but for the sake of concreteness I include my specific problem below.
Here is the code, followed by what it currently looks like:
digraph myGraph {
rankdir=BT;
splines=line;
"AB.BC" -> "AB.AC.BC" [weight=4]
"AB.BC" -> "ABC" [color=red,style=dashed,label="I(A;C|B)"]
"A.B.C" -> "A.BC" [color=red, label="I(B;C)"]
"A.B.C" -> "AC.B" [color=red, label="I(A;C)"]
"A.B.C" -> "AB.C" [color=red, label="I(A;B)"]
"A.BC" -> "AB.BC" [color=red, label="I(A;B)"]
"A.BC" -> "AC.BC" [color=red, label="I(A;C)"]
"AB.AC.BC" -> "ABC" [weight=4]
"AC.B" -> "AC.BC" [color=red, label="I(B;C)"]
"AC.B" -> "AB.AC" [color=red, label="I(A;B)"]
"AC.BC" -> "AB.AC.BC" [weight=4]
"AC.BC" -> "ABC" [color=red,style=dashed, label="I(A;B|C)"]
"AB.AC" -> "AB.AC.BC" [weight=4]
"AB.AC" -> "ABC" [color=red,style=dashed, label="I(B;C|A)"]
"AB.C" -> "AB.BC" [color=red, label="I(A;B)"]
"AB.C" -> "AB.AC" [color=red, label="I(A;C)"]
}
This is close to what I want, but it has a few problems:
The labels are placed in such a way that you can't easily see which one is associated with which edge
For some reason, some of the edges have a bend in them at the label. (They came out as straight lines before I added the labels.)
I've tried playing with the rowsep and nodesep attributes but wasn't able to improve it. If I remove the splines=line line it becomes legible but isn't really what I want:
It's fine for the dotted edges to be curved -- it's actually good, because it will prevent them from overlapping the second node from the top -- but the solid ones really should be straight.
I'd like any advice on how to fine tune node, edge and label placement (as the documentation is really unhelpful and good examples are hard to find), but specifically, my questions are:
Can I tell dot to make specific edges curved while keeping others straight? (I know there is a splineType edge attribute, but the documentation doesn't give me a clue how to use it and I'm not even sure this is what it does.)
If the above is not possible, how can I tell dot to make the straight lines dead straight, rather than bending at the label?
For straight edges, how can I fine tune the placement of the labels? I don't mind doing it by hand, and there seem to be several edge attributes that should help me do that, but none of them seem to have any effect whatsoever, so I must be doing something wrong.
As a bonus question: is there a way that I can give the nodes a more grid-like layout, so that they're nicely vertically aligned?
Any answer is appreciated, but most especially helpful would be answers that explain how to handle these issues more generally, for the sake of future visitors, rather than just fixing my code.
If you use the neato layout engine, you can set the nodes explicit coordinates with attribute pos="x,y". In dot layout engine this is possible by using {rank=same; node1; node2; ...} for vertical alignment and group attribute (node1[group=g1]; node3[group=g1];) for horizontal alignment.
The position of the labels can be changed using the attributes headlabel and taillabel.
Image:
Script:
digraph myGraph {
layout=neato
splines=true
rankdir=BT
node [pin=true]
"A.B.C" [pos="0,0"]
"AC.B" [pos="0,2"]
"A.BC" [pos="-2,2"]
"AB.C" [pos="2,2"]
"AC.BC" [pos="-2,4"]
"AB.BC" [pos="0,4"]
"AB.AC" [pos="2,4"]
"AB.AC.BC" [pos="0,6"]
"ABC" [pos="0,8"]
"AB.BC" -> "AB.AC.BC"
"AB.BC" -> "ABC" [color=red,style=dashed,taillabel="I(A;C|B)"]
"A.B.C" -> "A.BC" [color=red, label="I(B;C)"]
"A.B.C" -> "AC.B" [color=red, label="I(A;C)"]
"A.B.C" -> "AB.C" [color=red, label="I(A;B)"]
"A.BC" -> "AB.BC" [color=red, taillabel="I(A;B)"]
"A.BC" -> "AC.BC" [color=red, taillabel="I(A;C)"]
"AB.AC.BC" -> "ABC"
"AC.B" -> "AC.BC" [color=red, taillabel="I(B;C)"]
"AC.B" -> "AB.AC" [color=red, taillabel="I(A;B)"]
"AC.BC" -> "AB.AC.BC"
"AC.BC" -> "ABC" [color=red,style=dashed, label="I(A;B|C)"]
"AB.AC" -> "AB.AC.BC"
"AB.AC" -> "ABC" [color=red,style=dashed, label="I(B;C|A)"]
"AB.C" -> "AB.BC" [color=red, taillabel="I(A;B)"]
"AB.C" -> "AB.AC" [color=red, taillabel="I(A;C)"]
}

Hide and unhide a view in Red language

I am trying following code to have a second view which can be hidden and shown again repeatedly while preserving values in its fields:
Red []
secondFstr: ""
secondshownonce: false
secondshowing: false
secondview: does [
secondshownonce: true
if not secondshowing [
secondshowing: true
view [ below
text "second view"
f2: field secondFstr []
b3: button "Hide" [
secondshowing: false
unview ]]]]
view [ below
text "first view"
b1: button "Print f2 text" [
either not secondshownonce
[print "not shown"]
[print f2/text] ]
b2: button "Show 2nd view" [secondview] ]
It works all right if 'hide' button is used for second view. But if the second view is closed by clicking 'x' at its top right corner, it cannot be shown again. How can I solve this problem?
You need to add an handler to the close event on that child window, in order to reset your flag properly, like this:
view/options [
below
text "second view"
f2: field secondFstr []
b3: button "Hide" [
secondshowing: false
unview
]
][
actors: object [
on-close: func [face event][
secondshowing: false
]
]
]

Graphviz compacting graph

I'm generating a graph with graphviz and the circo tool it provides.
The graph generated is a nice shape, but the lengths of the edges between the nodes are a lot larger than they need to be, which makes the text of the nodes be small (relative to the output image) and so hard to read.
How can I make the node be bigger (relatively) in the output image, so that the text inside the nodes is easier to read,
Output image:
Source graph file:
digraph G {
FoundUrlToFollow [shape=box];
"Fetch the URL" [shape=circle];
FoundUrlToFollow -> "Fetch the URL";
ResponseReceived [shape=box];
"Fetch the URL" [shape=circle, label=<Fetch the URL>];
"Fetch the URL" -> ResponseReceived;
ResponseError [shape=box];
"Fetch the URL" [shape=circle, label=<Fetch the URL>];
"Fetch the URL" -> ResponseError;
ResponseReceived [shape=box];
"Log response" [shape=circle];
ResponseReceived -> "Log response";
ResponseReceived [shape=box];
"Is the response OK?" [shape=circle];
ResponseReceived -> "Is the response OK?";
ResponseOk [shape=box];
"Is the response OK?" [shape=circle, label=<Is the response<br/>OK?>];
"Is the response OK?" -> ResponseOk;
ResponseOk [shape=box];
"Is the response HTML?" [shape=circle];
ResponseOk -> "Is the response HTML?";
HtmlToParse [shape=box];
"Is the response HTML?" [shape=circle, label=<Is the response<br/>HTML?>];
"Is the response HTML?" -> HtmlToParse;
HtmlToParse [shape=box];
"Parse the HTML to find links" [shape=circle];
HtmlToParse -> "Parse the HTML to find links";
FoundUrl [shape=box];
"Parse the HTML to find links" [shape=circle, label=<Parse the HTML<br/>to find links>];
"Parse the HTML to find links" -> FoundUrl;
FoundUrl [shape=box];
"Should we follow this URL?" [shape=circle];
FoundUrl -> "Should we follow this URL?";
FoundUrlToSkip [shape=box];
"Should we follow this URL?" [shape=circle, label=<Should we<br/>follow this<br/>URL?>];
"Should we follow this URL?" -> FoundUrlToSkip;
FoundUrlToFollow [shape=box];
"Should we follow this URL?" [shape=circle, label=<Should we<br/>follow this<br/>URL?>];
"Should we follow this URL?" -> FoundUrlToFollow;
FoundUrlToSkip [shape=box];
"Log skipped links" [shape=circle];
FoundUrlToSkip -> "Log skipped links";
graph [label="Switches are circles. Events are boxes.", fontsize="12", overlap=scale];
edge [splines=curved];
}
Command:
circo -Tpng -ograph_so.png graph.dot
I would try to add mindist (less than 1) to graph:
graph [..., overlap=scale, mindist=.6];
[edit]
maybe the renderer version make a difference: here is the outcome on my machine
Try varying -Gsize (units of inches) and -Gdpi. You'll find that if you change them both together, you get different outputs with the same pixel size, but with different spacing between the nodes relative to the size of the nodes themselves. -Gnodesep and -Nfontsize might also be useful to tweak. You might also have better luck by rendering to EPS or PDF or SVG and then converting that to PNG, instead of using Graphviz's PNG renderer. Getting pleasing output from Graphviz is, in my experience, a very inexact science.

Why is ResearchKit on xcode 7.1.1 only allowing me to ask one type of each questiontype?

So I am trying to write a code for ResearchKit on 7.1.1 with Swift and I am having trouble with asking multiple question types. By question type I mean asking the user to input "text field" data and "selecting one out of a list" data.
It works if I run the code with just question 1 and 2. But if I include question 3, the code breaks down and gives an error.
import Foundation
import ResearchKit
public var SurveyTask: ORKOrderedTask {
var steps = [ORKStep]()
//TODO: add instructions step
let instructionStep = ORKInstructionStep(identifier: "IntroStep")
instructionStep.title = "Introduction"
instructionStep.text = "10 Questions that you can just answer or skip! (Althought we do hope you will answer them.)"
steps += [instructionStep]
//TODO: add questions
//question 1
let nameAnswerFormat = ORKTextAnswerFormat(maximumLength: 2)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle = "What is the child's age?"
let nameQuestionStep = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle, answer: nameAnswerFormat)
steps += [nameQuestionStep]
//question 2
let questQuestionStepTitle = "Has there been any other incidences of this disease in other family members?"
let textChoices = [
ORKTextChoice(text: "Yes", value: 0),
ORKTextChoice(text: "No", value: 1),
]
let questAnswerFormat: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormatWithStyle(.SingleChoice, textChoices: textChoices)
let questQuestionStep = ORKQuestionStep(identifier: "TextChoiceQuestionStep", title: questQuestionStepTitle, answer: questAnswerFormat)
steps += [questQuestionStep]
//question 3
let questQuestionStepTitle2 = "Is the tumor in one or both eyes?"
let textChoices2 = [
ORKTextChoice(text: "Right Eye", value: 0),
ORKTextChoice(text: "Left Eye", value: 1),
ORKTextChoice(text: "Both Eyes", value: 2),
]
let questAnswerFormat2: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormatWithStyle(.SingleChoice, textChoices: textChoices2)
let questQuestionStep2 = ORKQuestionStep(identifier: "TextChoiceQuestionStep", title: questQuestionStepTitle2, answer: questAnswerFormat2)
steps += [questQuestionStep2]
/*//question 4
let questQuestionStepTitle3 = "Do you know anything about genetic counselling?"
let textChoices3 = [
ORKTextChoice(text: "Yes", value: 0),
ORKTextChoice(text: "No", value: 1),
]
let questAnswerFormat3: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormatWithStyle(.SingleChoice, textChoices: textChoices3)
let questQuestionStep3 = ORKQuestionStep(identifier: "TextChoiceQuestionStep", title: questQuestionStepTitle3, answer: questAnswerFormat3)
steps += [questQuestionStep3]
//question 5
let nameAnswerFormat2 = ORKTextAnswerFormat(maximumLength: 300)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle2 = "How did you first realize your child was sick?"
let nameQuestionStep2 = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle2, answer: nameAnswerFormat2)
steps += [nameQuestionStep2]
//question 6
let nameAnswerFormat3 = ORKTextAnswerFormat(maximumLength: 300)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle3 = "What treatment is the child taking?"
let nameQuestionStep3 = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle3, answer: nameAnswerFormat3)
steps += [nameQuestionStep3]
//question 7
let nameAnswerFormat4 = ORKTextAnswerFormat(maximumLength: 100)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle4 = "How long has the treatment been ongoing?"
let nameQuestionStep4 = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle4, answer: nameAnswerFormat4)
steps += [nameQuestionStep4]
//question 8
let nameAnswerFormat5 = ORKTextAnswerFormat(maximumLength: 300)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle5 = "What major questions do you have about the process and about the treatment itself?"
let nameQuestionStep5 = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle5, answer: nameAnswerFormat5)
steps += [nameQuestionStep5]
//question 9
let nameAnswerFormat6 = ORKTextAnswerFormat(maximumLength: 300)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle6 = "Are there any side effects of the treatment?? State any if there is."
let nameQuestionStep6 = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle6, answer: nameAnswerFormat6)
steps += [nameQuestionStep6]
//question 10
let nameAnswerFormat7 = ORKTextAnswerFormat(maximumLength: 100)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle7 = "How has your day been? "
let nameQuestionStep7 = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle7, answer: nameAnswerFormat7)
steps += [nameQuestionStep7]*/
//TODO: add summary step
let summaryStep = ORKCompletionStep(identifier: "SummaryStep")
summaryStep.title = "Right. Off you go!"
summaryStep.text = "That was easy!"
steps += [summaryStep]
return ORKOrderedTask(identifier: "SurveyTask", steps: steps)
}
Any help would be appreciated, thanks!
Question 3:
Try changing identifier to #2:
let questQuestionStep2 = ORKQuestionStep(identifier: "TextChoiceQuestionStep2",...

Resources