1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
-- Copyright 2014 by Till Tantau
--
-- This file may be distributed an/or modified
--
-- 1. under the LaTeX Project Public License and/or
-- 2. under the GNU Public License
--
-- See the file doc/generic/pgf/licenses/LICENSE for more information
-- @release $Header: /cvsroot/pgf/pgf/generic/pgf/graphdrawing/lua/pgf/gd/routing/Hints.lua,v 1.2 2015/05/18 17:01:16 tantau Exp $
---
-- The |Hints| class provides a way for graph drawing algorithms to
-- communicate certain possibilities concerning the routing of edges
-- to edge routing algorithms. This partly decouples the choice of the
-- vertex positioning algorithms from the choice of edge routing
-- algorithm. For instance, for a simple necklace routing, it is
-- unclear whether the edges on the necklace should be routing ``along
-- the necklace'' or not. Thus, necklace routing algoirthms will
-- ``hint'' that a necklace is present and only when the
-- |necklace routing| algorithm is selected will these hints lead to
-- actual bending of edges.
--
-- For each kind of hint, there are methods in this class for creating
-- the hints and other methods for reading them. Hints are always
-- local to the ugraph.
local Hints = {}
-- Namespace
require("pgf.gd.routing").Hints = Hints
-- Imports
local Storage = require("pgf.gd.lib.Storage")
local Coordinate = require("pgf.gd.model.Coordinate")
-- The necklace storage
local necklaces = Storage.new()
---
-- Adds a necklace hint. In this case, the hint indicates that the
-- given sequence of vertices lie on a circle.
--
-- The idea is that an algorithm may specify that in a
-- given graph certain sequences of nodes form a ``necklace,'' which
-- is typically a circle. There may be more than one necklace inside a
-- given graph. For each necklace,
-- whenever an arc connects subsequent nodes on the necklace, they get
-- bend in such a way that they lie follow the path of the
-- necklace. If an arc lies on more than one necklace, the ``last one
-- wins.''
--
-- @param ugraph The ugraph to which this hint is added
-- @param necklace The sequence of vertices that form the necklace. If
-- the necklace is closed, the last vertex must equal the first one.
-- @param center If provided, must be |Coordinate| that specifies the
-- center of the circle on which the vertices lie. If not provided,
-- the origin is assumed.
-- @param clockwise If |true|, the vertices are in clockwise order,
-- otherwise in counter-clockwise order.
function Hints.addNecklaceCircleHint(ugraph, necklace, center, clockwise)
local a = necklaces[ugraph] or {}
necklaces[ugraph] = a
a[#a+1] = {
necklace = necklace,
center = center or Coordinate.origin,
clockwise = clockwise
}
end
---
-- Gets the necklace hints.
--
-- This function will return an array whose entries are necklace
-- hints. Each entry in the array has a |necklace| field, which is the
-- field passed to the |addNecklaceXxxx| methods. For a circle
-- necklace, the |center| and |clockwise| fields will be set. (Other
-- necklaces are not yet implemented.)
--
-- @param ugraph The ugraph for which the necklace hints are
-- requested.
-- @return The array of necklaces as described above.
function Hints.getNecklaceHints(ugraph)
return necklaces[ugraph] or {}
end
-- done
return Hints
|