Skip to content

Commit

Permalink
Fix broken example of simpledemo.lua to work with "simple demo layout"
Browse files Browse the repository at this point in the history
Signed-off-by: Hanson Char <[email protected]>
  • Loading branch information
hansonchar committed Jun 25, 2024
1 parent 12f1783 commit 92b3200
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
2 changes: 2 additions & 0 deletions doc/generic/pgf/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Output bounding box adjustment in pgfsys-dvisvgm.def #1275
- Fix shadings under LuaMetaTeX
- Resolve missing `gnuplot` plots in manual #1238
- Fix broken example of simpledemo.lua to work with "simple demo layout"

### Changed

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

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

Expand Down
18 changes: 9 additions & 9 deletions doc/generic/pgf/pgfmanual-en-gd-algorithm-layer.tex
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ \subsubsection{The Hello World of Graph Drawing}
%
\begin{codeexample}[code only, tikz syntax=false]
pgf.gd.interface.InterfaceToAlgorithms.declare {
key = "very simple demo layout",
key = "simple demo layout",
algorithm = {
run =
function (self)
Expand Down Expand Up @@ -155,7 +155,7 @@ \subsubsection{The Hello World of Graph Drawing}
}
}

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

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

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

\includeluadocumentationof{pgf.gd.examples.library}
\includeluadocumentationof{pgf.gd.examples.SimpleDemo}
\includeluadocumentationof{pgf.gd.examples.simpledemo}
\includeluadocumentationof{pgf.gd.examples.SimpleEdgeDemo}
\includeluadocumentationof{pgf.gd.examples.SimpleHuffman}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local examples


-- Load algorithms from:
require "pgf.gd.examples.SimpleDemo"
require "pgf.gd.examples.simpledemo"
require "pgf.gd.examples.SimpleEdgeDemo"
require "pgf.gd.examples.SimpleHuffman"

Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ declare {
algorithm = {
run =
function (self)
local g = self.digraph
local alpha = (2 * math.pi) / #g.vertices

for i,vertex in ipairs(g.vertices) do
local radius = vertex.options['radius'] or g.options['radius']
vertex.pos.x = radius * math.cos(i * alpha)
vertex.pos.y = radius * math.sin(i * alpha)
local alpha = (2 * math.pi) / #self.ugraph.vertices
for i,vertex in ipairs(self.ugraph.vertices) do
vertex.pos.x = math.cos(i * alpha) * 25
vertex.pos.y = math.sin(i * alpha) * 25
end
end
},
Expand All @@ -49,7 +46,7 @@ declare {
implement a graph drawing algorithm.
%
\begin{codeexample}[code only, tikz syntax=false]
-- File pgf.gd.examples.SimpleDemo
-- File pgf.gd.examples.simpledemo
local declare = require "pgf.gd.interface.InterfaceToAlgorithms".declare
declare {
Expand All @@ -61,9 +58,8 @@ declare {
local alpha = (2 * math.pi) / #g.vertices
for i,vertex in ipairs(g.vertices) do
local radius = vertex.options['radius'] or g.options['radius']
vertex.pos.x = radius * math.cos(i * alpha)
vertex.pos.y = radius * math.sin(i * alpha)
vertex.pos.x = math.cos(i * alpha)
vertex.pos.y = math.sin(i * alpha)
end
end
},
Expand All @@ -76,7 +72,7 @@ declare {
On the display layer (\tikzname, that is) the algorithm can now
immediately be employed; you just need to say
|\usegdlibrary{examples.SimpleDemo}| at the beginning
|\usegdlibrary{simpledemo}| at the beginning
somewhere.
"]=]
}

0 comments on commit 92b3200

Please sign in to comment.