summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples')
-rw-r--r--Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/ASCIIDisplayer.lua4
-rw-r--r--Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/BindingToASCII.lua36
-rw-r--r--Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleDemo.lua32
-rw-r--r--Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleEdgeDemo.lua53
-rw-r--r--Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleHuffman.lua136
-rw-r--r--Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/library.lua2
6 files changed, 127 insertions, 136 deletions
diff --git a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/ASCIIDisplayer.lua b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/ASCIIDisplayer.lua
index 5acc28396b2..ccaa91f9992 100644
--- a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/ASCIIDisplayer.lua
+++ b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/ASCIIDisplayer.lua
@@ -5,7 +5,7 @@ require "pgf.gd.layered.library"
require "pgf.gd.force.library"
local algorithm = io.read():match("%s*graph%s*%[(.-)%]")
-
+
InterfaceToDisplay.pushPhase(algorithm, "main", 1)
InterfaceToDisplay.pushOption("level distance", 6, 2)
InterfaceToDisplay.pushOption("sibling distance", 8, 3)
@@ -27,6 +27,6 @@ end
InterfaceToDisplay.runGraphDrawingAlgorithm()
InterfaceToDisplay.renderGraph()
InterfaceToDisplay.endGraphDrawingScope()
-
+
diff --git a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/BindingToASCII.lua b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/BindingToASCII.lua
index 2b5c9cc0b6a..9752254907a 100644
--- a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/BindingToASCII.lua
+++ b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/BindingToASCII.lua
@@ -22,10 +22,10 @@ function BindingToASCII:renderStop()
for x=-30,30 do
local s = canvas[x][y]
for i=1,#s do
- pos = x+30+i-math.floor(#s/2)
- if not t[pos] or t[pos] == " " or t[pos] == "." then
- t[pos] = string.sub(s,i,i)
- end
+ pos = x+30+i-math.floor(#s/2)
+ if not t[pos] or t[pos] == " " or t[pos] == "." then
+ t[pos] = string.sub(s,i,i)
+ end
end
end
print(table.concat(t))
@@ -41,46 +41,46 @@ function BindingToASCII:renderEdge(e)
local function connect (p,q)
local x1, y1, x2, y2 = math.floor(p.x+0.5), math.floor(p.y+0.5), math.floor(q.x+0.5), math.floor(q.y+0.5)
-
+
-- Go upward with respect to x
if x2 < x1 then
x1, y1, x2, y2 = x2, y2, x1, y1
end
-
+
local delta_x = x2-x1
local delta_y = y2-y1
if math.abs(delta_x) > math.abs(delta_y) then
local slope = delta_y/delta_x
for i=x1,x2 do
- local x,y = i, math.floor(y1 + (i-x1)*slope + 0.5)
+ local x,y = i, math.floor(y1 + (i-x1)*slope + 0.5)
- if canvas[x][y] == " " then
- canvas[x][y] = '.'
- end
+ if canvas[x][y] == " " then
+ canvas[x][y] = '.'
+ end
end
elseif math.abs(delta_y) > 0 then
local slope = delta_x/delta_y
for i=y1,y2,(y1<y2 and 1) or -1 do
- local x,y = math.floor(x1 + (i-y1)*slope + 0.5), i
+ local x,y = math.floor(x1 + (i-y1)*slope + 0.5), i
- if canvas[x][y] == " " then
- canvas[x][y] = '.'
- end
+ if canvas[x][y] == " " then
+ canvas[x][y] = '.'
+ end
end
end
end
-
-
+
+
local p = e.tail.pos
-
+
for i=1,#e.path do
if type(e.path[i]) == "table" then
connect(p, e.path[i])
p = e.path[i]
end
end
-
+
connect(p, e.head.pos)
end
diff --git a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleDemo.lua b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleDemo.lua
index 46eb4eff385..da850ff0dea 100644
--- a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleDemo.lua
+++ b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleDemo.lua
@@ -29,7 +29,7 @@ declare {
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)
@@ -39,19 +39,19 @@ declare {
},
summary = [["
- This algorithm is the ``Hello World'' of graph drawing.
+ This algorithm is the ``Hello World'' of graph drawing.
"]],
- documentation = [=["
- The algorithm arranges nodes in a circle (without paying heed to the
- sizes of the nodes or to the edges). In order to ``really'' layout
- nodes in a circle, use |simple necklace layout|; the present layout
- is only intended to demonstrate how much (or little) is needed to
- implement a graph drawing algorithm.
- %
+ documentation = [=["
+ The algorithm
+ arranges nodes in a circle (without paying heed to the sizes of the
+ nodes or to the edges). In order to ``really'' layout nodes in a
+ circle, use |simple necklace layout|; the present layout is only intended
+ to demonstrate how much (or little) is needed to implement a graph
+ drawing algorithm.
\begin{codeexample}[code only, tikz syntax=false]
-- File pgf.gd.examples.SimpleDemo
local declare = require "pgf.gd.interface.InterfaceToAlgorithms".declare
-
+
declare {
key = "simple demo layout",
algorithm = {
@@ -59,7 +59,7 @@ declare {
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)
@@ -73,10 +73,10 @@ declare {
"]]
}
\end{codeexample}
-
- 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
- somewhere.
+
+ 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
+ somewhere.
"]=]
} \ No newline at end of file
diff --git a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleEdgeDemo.lua b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleEdgeDemo.lua
index c22c4decf22..8eb9d7d7019 100644
--- a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleEdgeDemo.lua
+++ b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleEdgeDemo.lua
@@ -31,34 +31,33 @@ declare {
algorithm = SimpleEdgeDemo,
summary = "This algorithm shows how edges can be created by an algorithm.",
- documentation = [["
- For its job, the algorithm uses the function |createEdge|, which can be
- called during the run of the algorithm to create edges in the
- syntactic graph. The algorithm first does exactly the same as the
- simple demo layout, then it creates an edge for every node where the
- |new edge to| option is set. You will see in the code how this
- option is declared and how we use it to look up a vertex in the
- graph by its name.
- %
+ documentation = [["
+ For its job, the algorithm uses the function |createEdge|, which can be
+ called during the run of the algorithm to create edges in the
+ syntactic graph. The algorithm first does exactly the same as the
+ simple demo layout, then it creates an edge for every node where the
+ |new edge to| option is set. You will see in the code how this
+ option is declared and how we use it to look up a vertex in the
+ graph by its name.
+
\begin{codeexample}[]
\tikz [simple edge demo layout]
\graph [radius=2cm] {
a, b, c, d, e, f;
-
+
e -> [red] f; % normal edge
-
+
% Edges generated by the algorithm:
- a[new edge to=b];
+ a[new edge to=b];
b[new edge to=d];
c[new edge to=f];
};
\end{codeexample}
-
- And the algorithm:
- %
+
+ And the algorithm:
\begin{codeexample}[code only, tikz syntax=false]
-- File pgf.gd.examples.SimpleEdgeDemo
-
+
-- Imports
local InterfaceToAlgorithms = require "pgf.gd.interface.InterfaceToAlgorithms"
local declare = InterfaceToAlgorithms.declare
@@ -72,9 +71,9 @@ declare {
summary = "This algorithm shows...",
}
\end{codeexample}
-
- Next comes the declaration of the new option |new edge to|:
- %
+
+ Next comes the declaration of the new option |new edge to|:
+
\begin{codeexample}[code only, tikz syntax=false]
declare {
key = "new edge to",
@@ -82,9 +81,9 @@ declare {
summary = "This option takes the name of a vertex..."
}
\end{codeexample}
-
- Finally, the algorithm's code:
- %
+
+ Finally, the algorithm's code:
+
\begin{codeexample}[code only, tikz syntax=false]
function SimpleEdgeDemo:run()
-- As in a SimpleDemo:
@@ -109,15 +108,15 @@ declare {
key = "new edge to",
type = "string",
- summary = [["
- This option takes the name of a vertex. An edge leading to this
- vertex is added to the syntactic digraph.
- "]]
+ summary = [["
+ This option takes the name of a vertex. An edge leading to this
+ vertex is added to the syntactic digraph.
+ "]]
}
function SimpleEdgeDemo:run()
-
+
-- As in a SimpleDemo:
local g = self.digraph
local alpha = (2 * math.pi) / #g.vertices
diff --git a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleHuffman.lua b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleHuffman.lua
index f81abf11058..270ecce2c90 100644
--- a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleHuffman.lua
+++ b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/SimpleHuffman.lua
@@ -31,26 +31,27 @@ local SimpleHuffman = {}
declare {
key = "simple Huffman layout",
algorithm = SimpleHuffman,
-
+
postconditions = {
upward_oriented = true
},
summary = [["
- This algorithm demonstrates how an algorithm can generate new nodes.
+ This algorithm demonstrates how an algorithm can generate new
+ nodes.
"]],
- documentation = [["
- The input graph should just consist of some nodes (without
- edges) and each node should have a |probability| key set. The nodes
- will then be arranged in a line (as siblings) and a Huffman tree
- will be constructed ``above'' these nodes. For the construction of
- the Huffman tree, new nodes are created and connected.
-
- \pgfgdset{
- HuffmanLabel/.style={/tikz/edge node={node[fill=white,font=\footnotesize,inner sep=1pt]{#1}}},
- HuffmanNode/.style={/tikz/.cd,circle,inner sep=0pt,outer sep=0pt,draw,minimum size=3pt}
- }
-
+ documentation = [["
+ The input graph should just consist of some nodes (without
+ edges) and each node should have a |probability| key set. The nodes
+ will then be arranged in a line (as siblings) and a Huffman tree
+ will be constructed ``above'' these nodes. For the construction of
+ the Huffman tree, new nodes are created and connected.
+
+ \pgfgdset{
+ HuffmanLabel/.style={/tikz/edge node={node[fill=white,font=\footnotesize,inner sep=1pt]{#1}}},
+ HuffmanNode/.style={/tikz/.cd,circle,inner sep=0pt,outer sep=0pt,draw,minimum size=3pt}
+ }
+
\begin{codeexample}[]
\tikz \graph [simple Huffman layout,
level distance=7mm, sibling distance=8mm, grow'=up]
@@ -60,16 +61,14 @@ declare {
c ["0.2", probability=0.2],
d ["0.1", probability=0.1],
e ["0.11", probability=0.11]
-};
+};
\end{codeexample}
- %
- The file starts with some setups and declarations:
- %
+ The file starts with some setups and declarations:
\begin{codeexample}[code only, tikz syntax=false]
-- File pgf.gd.examples.SimpleHuffman
-
+
local declare = require "pgf.gd.interface.InterfaceToAlgorithms".declare
-
+
-- The class
local SimpleHuffman = {}
@@ -86,7 +85,7 @@ declare {
initial = "1",
summary = "..."
}
-
+
-- Import
local layered = require "pgf.gd.layered"
local InterfaceToAlgorithms = require "pgf.gd.interface.InterfaceToAlgorithms"
@@ -98,31 +97,29 @@ local layer = Storage.new()
function SimpleHuffman:run()
-- Construct a Huffman tree on top of the vertices...
\end{codeexample}
-
- Next comes a setup, where we create the working list of vertices
- that changes as the Huffman coding method proceeds:
- %
+
+ Next comes a setup, where we create the working list of vertices
+ that changes as the Huffman coding method proceeds:
\begin{codeexample}[code only, tikz syntax=false]
-- Shorthand
local function prop (v)
return probability[v] or v.options['probability']
end
-
+
-- Copy the vertex table, since we are going to modify it:
local vertices = {}
for i,v in ipairs(self.ugraph.vertices) do
vertices[i] = v
end
\end{codeexample}
-
- The initial vertices are arranged in a line on the last layer. The
- function |ideal_sibling_distance| takes care of the rather
- complicated handling of the (possibly rotated) bounding boxes and
- separations. The |props| and |layer| are tables used by
- algorithms to ``store stuff'' at a vertex or at an arc. The
- table will be accessed by |arrange_layers_by_baselines| to
- determine the ideal vertical placements.
- %
+
+ The initial vertices are arranged in a line on the last layer. The
+ function |ideal_sibling_distance| takes care of the rather
+ complicated handling of the (possibly rotated) bounding boxes and
+ separations. The |props| and |layer| are tables used by
+ algorithms to ``store stuff'' at a vertex or at an arc. The
+ table will be accessed by |arrange_layers_by_baselines| to
+ determine the ideal vertical placements.
\begin{codeexample}[code only, tikz syntax=false]
-- Now, arrange the nodes in a line:
vertices [1].pos.x = 0
@@ -132,17 +129,16 @@ function SimpleHuffman:run()
vertices [i].pos.x = vertices[i-1].pos.x + d
layer[ vertices [i] ] = #vertices
end
-\end{codeexample}
-
- Now comes the actual Huffman algorithm: Always find the vertices
- with a minimal probability\dots
- %
+\end{codeexample}
+
+ Now comes the actual Huffman algorithm: Always find the vertices
+ with a minimal probability\dots
\begin{codeexample}[code only, tikz syntax=false]
-- Now, do the Huffman thing...
while #vertices > 1 do
-- Find two minimum probabilities
local min1, min2
-
+
for i=1,#vertices do
if not min1 or prop(vertices[i]) < prop(vertices[min1]) then
min2 = min1
@@ -152,11 +148,9 @@ function SimpleHuffman:run()
end
end
\end{codeexample}
- %
- \dots and connect them with a new node. This new node gets the
- option |HuffmanNode|. It is now the job of the higher layers to map
- this option to something ``nice''.
- %
+ \dots and connect them with a new node. This new node gets the
+ option |HuffmanNode|. It is now the job of the higher layers to map
+ this option to something ``nice''.
\begin{codeexample}[code only, tikz syntax=false]
-- Create new node:
local p = prop(vertices[min1]) + prop(vertices[min2])
@@ -165,29 +159,27 @@ function SimpleHuffman:run()
layer[v] = #vertices-1
v.pos.x = (vertices[min1].pos.x + vertices[min2].pos.x)/2
vertices[#vertices + 1] = v
-
+
InterfaceToAlgorithms.createEdge (self, v, vertices[min1],
{generated_options = {{key="HuffmanLabel", value = "0"}}})
InterfaceToAlgorithms.createEdge (self, v, vertices[min2],
{generated_options = {{key="HuffmanLabel", value = "1"}}})
-
+
table.remove(vertices, math.max(min1, min2))
table.remove(vertices, math.min(min1, min2))
end
\end{codeexample}
- %
- Ok, we are mainly done now. Finish by computing vertical placements
- and do formal cleanup.
+ Ok, we are mainly done now. Finish by computing vertical placements
+ and do formal cleanup.
\begin{codeexample}[code only, tikz syntax=false]
layered.arrange_layers_by_baselines(layers, self.adjusted_bb, self.ugraph)
end
\end{codeexample}
-
- In order to use the class, we have to make sure that, on the
- display layer, the options |HuffmanLabel| and |HuffmanNode| are
- defined. This is done by adding, for instance, the following to
- \tikzname:
- %
+
+ In order to use the class, we have to make sure that, on the
+ display layer, the options |HuffmanLabel| and |HuffmanNode| are
+ defined. This is done by adding, for instance, the following to
+ \tikzname:
\begin{codeexample}[code only]
\pgfkeys{
/graph drawing/HuffmanLabel/.style={
@@ -199,8 +191,8 @@ end
}
\end{codeexample}
"]]
-}
-
+}
+
---
@@ -209,18 +201,18 @@ declare {
type = "number",
initial = "1",
- summary = [["
- The probability parameter. It is used by the Huffman algorithm to
- group nodes.
- "]]
+ summary = [["
+ The probability parameter. It is used by the Huffman algorithm to
+ group nodes.
+ "]]
}
-
+
-- Imports
-
+
local Storage = require 'pgf.gd.lib.Storage'
-
+
-- Storages
-
+
local probability = Storage.new()
local layer = Storage.new()
@@ -232,13 +224,13 @@ function SimpleHuffman:run()
local function prop (v)
return probability[v] or v.options['probability']
end
-
+
-- Copy the vertex table, since we are going to modify it:
local vertices = {}
for i,v in ipairs(self.ugraph.vertices) do
vertices[i] = v
end
-
+
-- Now, arrange the nodes in a line:
vertices [1].pos.x = 0
layer[vertices [1]] = #vertices
@@ -247,7 +239,7 @@ function SimpleHuffman:run()
vertices [i].pos.x = vertices[i-1].pos.x + d
layer[vertices [i]] = #vertices
end
-
+
-- Now, do the Huffman thing...
while #vertices > 1 do
-- Find two minimum probabilities
@@ -269,7 +261,7 @@ function SimpleHuffman:run()
layer[v] = #vertices-1
v.pos.x = (vertices[min1].pos.x + vertices[min2].pos.x)/2
vertices[#vertices + 1] = v
-
+
InterfaceToAlgorithms.createEdge (self, v, vertices[min1],
{generated_options = {{key="HuffmanLabel", value = "0"}}})
InterfaceToAlgorithms.createEdge (self, v, vertices[min2],
@@ -278,7 +270,7 @@ function SimpleHuffman:run()
table.remove(vertices, math.max(min1, min2))
table.remove(vertices, math.min(min1, min2))
end
-
+
layered.arrange_layers_by_baselines(layer, self.adjusted_bb, self.ugraph)
end
diff --git a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/library.lua b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/library.lua
index 0c977600a7e..85e74970095 100644
--- a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/library.lua
+++ b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/examples/library.lua
@@ -16,7 +16,7 @@
-- graph drawing engine can be used. In particular, the algorithms of
-- this package are not really meant to be used to layout graphs
-- (although they can be used, in principle); rather you are invited
--- to have a look at their implementation and to adapt them to your needs.
+-- to have a look at their implementation and to adapt them to your needs.
--
-- @library