Skip to content

Commit 92b3200

Browse files
committed
Fix broken example of simpledemo.lua to work with "simple demo layout"
Signed-off-by: Hanson Char <[email protected]>
1 parent 12f1783 commit 92b3200

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

doc/generic/pgf/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1818
- Output bounding box adjustment in pgfsys-dvisvgm.def #1275
1919
- Fix shadings under LuaMetaTeX
2020
- Resolve missing `gnuplot` plots in manual #1238
21+
- Fix broken example of simpledemo.lua to work with "simple demo layout"
2122

2223
### Changed
2324

@@ -40,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4041
- Yukai Chou (@muzimuzhi)
4142
- Alexander Grahn
4243
- Max Chernoff
44+
- Hanson Char
4345

4446
## [3.1.10] - 2023-01-13 Henri Menke
4547

doc/generic/pgf/pgfmanual-en-gd-algorithm-layer.tex

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ \subsubsection{The Hello World of Graph Drawing}
126126
%
127127
\begin{codeexample}[code only, tikz syntax=false]
128128
pgf.gd.interface.InterfaceToAlgorithms.declare {
129-
key = "very simple demo layout",
129+
key = "simple demo layout",
130130
algorithm = {
131131
run =
132132
function (self)
@@ -155,7 +155,7 @@ \subsubsection{The Hello World of Graph Drawing}
155155
}
156156
}
157157

158-
This code \emph {declares} a new algorithm (|very simple demo layout|) and
158+
This code \emph {declares} a new algorithm (|simple demo layout|) and
159159
includes an implementation of the algorithm (through the |run| field of the
160160
|algorithm| field). When the |run| method is called, the |self| parameter will
161161
contain the to-be-drawn graph in its |ugraph| field. It is now the job of the
@@ -171,22 +171,22 @@ \subsubsection{The Hello World of Graph Drawing}
171171

172172
Executing the code ``just'' declares the algorithm, this is what the |declare|
173173
function does. Inside some internal tables, the algorithm layer will store the
174-
fact that a |very simple demo layout| is now available. The algorithm layer
174+
fact that a |simple demo layout| is now available. The algorithm layer
175175
will also communicate with the display layer through the binding layer to
176176
advertise this fact to the ``user''. In the case of \tikzname, this means that
177-
the option key |very simple demo layout| becomes available at this point and we
177+
the option key |simple demo layout| becomes available at this point and we
178178
can use it like this:
179179
%
180-
\begin{codeexample}[]
181-
\tikz [very simple demo layout]
180+
\begin{codeexample}[preamble={\usetikzlibrary{graphs,graphdrawing} \usegdlibrary{simpledemo}}]
181+
\tikz [simple demo layout]
182182
\graph { f -> c -> e -> a -> {b -> {c, d, f}, e -> b}};
183183
\end{codeexample}
184184

185185
It turns out, that our little algorithm is already more powerful than one might
186186
expect. Consider the following example:
187187
%
188-
\begin{codeexample}[]
189-
\tikz [very simple demo layout, componentwise]
188+
\begin{codeexample}[preamble={\usetikzlibrary{graphs,graphdrawing} \usegdlibrary{simpledemo}}]
189+
\tikz [simple demo layout, componentwise]
190190
\graph {
191191
1 -> 2 ->[orient=right] 3 -> 1;
192192
a -- b --[orient=45] c -- d -- a;
@@ -797,7 +797,7 @@ \subsection{Examples of Implementations of Graph Drawing Algorithms}
797797
\label{section-gd-examples}
798798

799799
\includeluadocumentationof{pgf.gd.examples.library}
800-
\includeluadocumentationof{pgf.gd.examples.SimpleDemo}
800+
\includeluadocumentationof{pgf.gd.examples.simpledemo}
801801
\includeluadocumentationof{pgf.gd.examples.SimpleEdgeDemo}
802802
\includeluadocumentationof{pgf.gd.examples.SimpleHuffman}
803803

tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/library.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ local examples
2424

2525

2626
-- Load algorithms from:
27-
require "pgf.gd.examples.SimpleDemo"
27+
require "pgf.gd.examples.simpledemo"
2828
require "pgf.gd.examples.SimpleEdgeDemo"
2929
require "pgf.gd.examples.SimpleHuffman"
3030

tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleDemo.lua renamed to tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/simpledemo.lua

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ declare {
2727
algorithm = {
2828
run =
2929
function (self)
30-
local g = self.digraph
31-
local alpha = (2 * math.pi) / #g.vertices
32-
33-
for i,vertex in ipairs(g.vertices) do
34-
local radius = vertex.options['radius'] or g.options['radius']
35-
vertex.pos.x = radius * math.cos(i * alpha)
36-
vertex.pos.y = radius * math.sin(i * alpha)
30+
local alpha = (2 * math.pi) / #self.ugraph.vertices
31+
for i,vertex in ipairs(self.ugraph.vertices) do
32+
vertex.pos.x = math.cos(i * alpha) * 25
33+
vertex.pos.y = math.sin(i * alpha) * 25
3734
end
3835
end
3936
},
@@ -49,7 +46,7 @@ declare {
4946
implement a graph drawing algorithm.
5047
%
5148
\begin{codeexample}[code only, tikz syntax=false]
52-
-- File pgf.gd.examples.SimpleDemo
49+
-- File pgf.gd.examples.simpledemo
5350
local declare = require "pgf.gd.interface.InterfaceToAlgorithms".declare
5451
5552
declare {
@@ -61,9 +58,8 @@ declare {
6158
local alpha = (2 * math.pi) / #g.vertices
6259
6360
for i,vertex in ipairs(g.vertices) do
64-
local radius = vertex.options['radius'] or g.options['radius']
65-
vertex.pos.x = radius * math.cos(i * alpha)
66-
vertex.pos.y = radius * math.sin(i * alpha)
61+
vertex.pos.x = math.cos(i * alpha)
62+
vertex.pos.y = math.sin(i * alpha)
6763
end
6864
end
6965
},
@@ -76,7 +72,7 @@ declare {
7672
7773
On the display layer (\tikzname, that is) the algorithm can now
7874
immediately be employed; you just need to say
79-
|\usegdlibrary{examples.SimpleDemo}| at the beginning
75+
|\usegdlibrary{simpledemo}| at the beginning
8076
somewhere.
8177
"]=]
8278
}

0 commit comments

Comments
 (0)