From 78bbb88c63604ba375076ca7bdc574f397b1edd0 Mon Sep 17 00:00:00 2001 From: Hanson Char Date: Mon, 24 Jun 2024 20:40:51 -0700 Subject: [PATCH] Fix broken example of simpledemo.lua to work with "simple demo layout" Signed-off-by: Hanson Char --- doc/generic/pgf/CHANGELOG.md | 2 ++ .../pgf/pgfmanual-en-gd-algorithm-layer.tex | 21 +++------------- .../lua/pgf/gd/examples/library.lua | 2 +- .../{SimpleDemo.lua => simpledemo.lua} | 24 ++++++++----------- 4 files changed, 16 insertions(+), 33 deletions(-) rename tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/{SimpleDemo.lua => simpledemo.lua} (72%) diff --git a/doc/generic/pgf/CHANGELOG.md b/doc/generic/pgf/CHANGELOG.md index bd8a8ab28..51315b223 100644 --- a/doc/generic/pgf/CHANGELOG.md +++ b/doc/generic/pgf/CHANGELOG.md @@ -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 @@ -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 diff --git a/doc/generic/pgf/pgfmanual-en-gd-algorithm-layer.tex b/doc/generic/pgf/pgfmanual-en-gd-algorithm-layer.tex index 1c7eb7e92..d2efa1816 100644 --- a/doc/generic/pgf/pgfmanual-en-gd-algorithm-layer.tex +++ b/doc/generic/pgf/pgfmanual-en-gd-algorithm-layer.tex @@ -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 @@ -177,7 +162,7 @@ \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} @@ -185,7 +170,7 @@ \subsubsection{The Hello World of Graph Drawing} 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; @@ -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} diff --git a/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/library.lua b/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/library.lua index 0c977600a..5bf604854 100644 --- a/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/library.lua +++ b/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/library.lua @@ -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" diff --git a/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleDemo.lua b/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/simpledemo.lua similarity index 72% rename from tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleDemo.lua rename to tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/simpledemo.lua index 46eb4eff3..5d6be8983 100644 --- a/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleDemo.lua +++ b/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/simpledemo.lua @@ -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 }, @@ -49,11 +46,11 @@ 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) @@ -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 }, @@ -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. "]=] } \ No newline at end of file