Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken example of simpledemo.lua to work with "simple demo layout" #1342

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 "very 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
21 changes: 3 additions & 18 deletions doc/generic/pgf/pgfmanual-en-gd-algorithm-layer.tex
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,6 @@ \subsubsection{The Hello World of Graph Drawing}
}
}
\end{codeexample}
\directlua{
pgf.gd.interface.InterfaceToAlgorithms.declare {
key = "very simple demo layout",
algorithm = {
run =
function (self)
local alpha = (2 * math.pi) / \luaescapestring{#}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
}
}
}

This code \emph {declares} a new algorithm (|very simple demo layout|) and
includes an implementation of the algorithm (through the |run| field of the
Expand All @@ -177,15 +162,15 @@ \subsubsection{The Hello World of Graph Drawing}
the option key |very simple demo layout| becomes available at this point and we
can use it like this:
%
\begin{codeexample}[]
\begin{codeexample}[preamble={\usetikzlibrary{graphs,graphdrawing} \usegdlibrary{simpledemo}}]
\tikz [very 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}[]
\begin{codeexample}[preamble={\usetikzlibrary{graphs,graphdrawing} \usegdlibrary{simpledemo}}]
\tikz [very simple demo layout, componentwise]
\graph {
1 -> 2 ->[orient=right] 3 -> 1;
Expand Down Expand Up @@ -797,7 +782,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 @@ -23,17 +23,14 @@ local declare = require "pgf.gd.interface.InterfaceToAlgorithms".declare
---

declare {
key = "simple demo layout",
key = "very simple demo layout",
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,21 +46,20 @@ 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 {
key = "simple demo layout",
key = "very simple demo layout",
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)
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.
"]=]
}