From 92b3200725c26846c1b179ac13b6cc035d0aeec3 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 | 18 ++++++++--------- .../lua/pgf/gd/examples/library.lua | 2 +- .../{SimpleDemo.lua => simpledemo.lua} | 20 ++++++++----------- 4 files changed, 20 insertions(+), 22 deletions(-) rename tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/{SimpleDemo.lua => simpledemo.lua} (75%) diff --git a/doc/generic/pgf/CHANGELOG.md b/doc/generic/pgf/CHANGELOG.md index bd8a8ab28..39396b1f0 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 "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..21086e3d1 100644 --- a/doc/generic/pgf/pgfmanual-en-gd-algorithm-layer.tex +++ b/doc/generic/pgf/pgfmanual-en-gd-algorithm-layer.tex @@ -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) @@ -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 @@ -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; @@ -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} 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 75% 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..cf67ab068 100644 --- a/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleDemo.lua +++ b/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/simpledemo.lua @@ -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 }, @@ -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 { @@ -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