Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
FlowForge
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timon Römer
FlowForge
Commits
20525c4e
Commit
20525c4e
authored
7 months ago
by
Timon Römer
Browse files
Options
Downloads
Patches
Plain Diff
Adds curvature for backwards edges in Tikz
parent
80baff5f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
MainWindow.xaml.cs
+94
-34
94 additions, 34 deletions
MainWindow.xaml.cs
with
94 additions
and
34 deletions
MainWindow.xaml.cs
+
94
−
34
View file @
20525c4e
...
...
@@ -272,7 +272,7 @@ namespace FlowForge
}
}
private
string
GenerateTikzCode
()
private
string
GenerateTikzCode
_Curved
()
{
if
(
_flowGraph
==
null
)
throw
new
InvalidOperationException
(
"Flow graph is not initialized."
);
...
...
@@ -305,7 +305,17 @@ namespace FlowForge
foreach
(
var
edge
in
_flowGraph
.
GetEdges
())
{
string
label
=
$"
{
edge
.
Residual
}
/
{
edge
.
MaxFlow
}
"
;
tikzBuilder
.
AppendLine
(
$"\\path[every node/.style=
{{
font
=
\\
tiny
}}
] (
{
edge
.
Source
.
Id
}
) edge node
{{
\\
texttt
{{{
label
}}}}}
(
{
edge
.
Target
.
Id
}
);"
);
if
(
edge
.
IsBackwards
)
{
// Reverse edge styling (curved, dashed, different color)
tikzBuilder
.
AppendLine
(
$"\\path[every node/.style=
{{
font
=
\\
tiny
}}
,bend right,dashed,red] (
{
edge
.
Source
.
Id
}
) edge [pos=0.5,sloped] node
{{
\\
texttt
{{{
label
}}}}}
(
{
edge
.
Target
.
Id
}
);"
);
}
else
{
// Normal edge styling
tikzBuilder
.
AppendLine
(
$"\\path[every node/.style=
{{
font
=
\\
tiny
}}
] (
{
edge
.
Source
.
Id
}
) edge [pos=0.5,sloped] node
{{
\\
texttt
{{{
label
}}}}}
(
{
edge
.
Target
.
Id
}
);"
);
}
}
tikzBuilder
.
AppendLine
(
"\\end{tikzpicture}"
);
...
...
@@ -314,14 +324,64 @@ namespace FlowForge
return
tikzBuilder
.
ToString
();
}
private
string
GenerateTikzCode
()
{
if
(
_flowGraph
==
null
)
throw
new
InvalidOperationException
(
"Flow graph is not initialized."
);
var
tikzBuilder
=
new
System
.
Text
.
StringBuilder
();
tikzBuilder
.
AppendLine
(
"\\documentclass[tikz,border=3mm]{standalone}"
);
tikzBuilder
.
AppendLine
(
"\\usetikzlibrary{arrows.meta,positioning}"
);
tikzBuilder
.
AppendLine
(
"\\usepackage{amsmath}"
);
tikzBuilder
.
AppendLine
(
"\\begin{document}"
);
// Global scaling and styles for smaller nodes and text
tikzBuilder
.
AppendLine
(
"\\begin{tikzpicture}[scale=3,->,>=stealth,shorten >=1pt,auto,node distance=2cm,thick,"
);
tikzBuilder
.
AppendLine
(
"main node/.style={circle,draw,minimum size=1mm,inner sep=1pt,font=\\scriptsize}]"
);
// Nodes
foreach
(
var
vertex
in
_flowGraph
.
Graph
.
Vertices
)
{
if
(
_nodePositions
.
ContainsKey
(
vertex
.
Id
))
{
var
position
=
_nodePositions
[
vertex
.
Id
];
// Format x and y as floating-point values with two decimal places
string
formattedX
=
(
position
.
X
/
100.0
).
ToString
(
"F2"
,
System
.
Globalization
.
CultureInfo
.
InvariantCulture
);
string
formattedY
=
(
position
.
Y
/
100.0
).
ToString
(
"F2"
,
System
.
Globalization
.
CultureInfo
.
InvariantCulture
);
tikzBuilder
.
AppendLine
(
$"\\node[main node] (
{
vertex
.
Id
}
) at (
{
formattedX
}
,
{
formattedY
}
)
{{{
vertex
.
Id
}}}
;"
);
}
}
// Edges
foreach
(
var
edge
in
_flowGraph
.
GetEdges
())
{
string
label
=
$"
{
edge
.
Residual
}
/
{
edge
.
MaxFlow
}
"
;
if
(
edge
.
IsBackwards
)
{
// Reverse edge styling: offset slightly above forward edges
tikzBuilder
.
AppendLine
(
$"\\path[every node/.style=
{{
font
=
\\
tiny
}}
,dashed,red] (
{
edge
.
Source
.
Id
}
) edge [pos=0.5,above] node
{{
\\
texttt
{{{
label
}}}}}
(
{
edge
.
Target
.
Id
}
);"
);
}
else
{
// Normal edge styling
tikzBuilder
.
AppendLine
(
$"\\path[every node/.style=
{{
font
=
\\
tiny
}}
] (
{
edge
.
Source
.
Id
}
) edge [pos=0.5,below] node
{{
\\
texttt
{{{
label
}}}}}
(
{
edge
.
Target
.
Id
}
);"
);
}
}
tikzBuilder
.
AppendLine
(
"\\end{tikzpicture}"
);
tikzBuilder
.
AppendLine
(
"\\end{document}"
);
return
tikzBuilder
.
ToString
();
}
private
void
ExportGraphToLatex
(
string
filePath
)
{
try
{
string
tikzCode
=
GenerateTikzCode
();
string
tikzCode
=
GenerateTikzCode
_Curved
();
System
.
IO
.
File
.
WriteAllText
(
filePath
,
tikzCode
);
MessageBox
.
Show
(
$"Graph successfully exported to LaTeX file:\n
{
filePath
}
"
,
"Export Successful"
,
MessageBoxButton
.
OK
,
MessageBoxImage
.
Information
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment