-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathev_embedding_visualizer.lua
339 lines (284 loc) · 10.7 KB
/
ev_embedding_visualizer.lua
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
----------------------------------------------------------------------
-- LINEAR EMBEDDING VISUALIZER IPELET
----------------------------------------------------------------------
--[[
This file is an extension of the drawing editor Ipe (ipe7.sourceforge.net)
Copyright (c) 2020-2024 Lluís Alemany-Puig
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
--]]
--[[
You'll find the instruction manual at:
https://github.com/lluisalemanypuig/ipe.embedviz
--]]
------------------------------------------------------------------------
------------------------------------------------------------------------
label = "Embedding visualizer"
about = [[
Tool for drawing linear and circular embeddings of graphs.
]]
if _G["next_multiple_four"] == nil then
------------------------------------------------------------------------
--- AUXILIARY FUNCTIONS
_G.dofile(_G.os.getenv("HOME") .. "/.ipe/ipelets/ev_auxiliary_functions.lua")
_G.dofile(_G.os.getenv("HOME") .. "/.ipe/ipelets/ev_make_dialog.lua")
------------------------------------------------------------------------
--- PARSE INPUT DATA
_G.dofile(_G.os.getenv("HOME") .. "/.ipe/ipelets/ev_parse_input_data.lua")
------------------------------------------------------------------------
--- DATA STRUCTURES
_G.dofile(_G.os.getenv("HOME") .. "/.ipe/ipelets/ev_queue.lua")
------------------------------------------------------------------------
--- DRAW DATA
_G.dofile(_G.os.getenv("HOME") .. "/.ipe/ipelets/ev_bipartite_draw_input_data.lua")
_G.dofile(_G.os.getenv("HOME") .. "/.ipe/ipelets/ev_circular_draw_input_data.lua")
_G.dofile(_G.os.getenv("HOME") .. "/.ipe/ipelets/ev_linear_draw_input_data.lua")
end
function run(model)
-- VARIABLES
local xoffset = 16 -- default distance between consecutive points
local xstart = 4 -- starting x coordinate of an embedding
local ystart = 40 -- starting y coordinate of an embedding
local circular_radius = 22 -- radius of the circle
local bipartite_height = 26 -- height of a bipartite drawing
--------------------------------------------------------------------
-- construct and execute the dialog
local d = _G.make_dialog(model)
if not d:execute() then
return
end
-- parse and convert the data from the boxes
local success, parsed_data = _G.parse_data(d, model)
-- if errors were found...
if not success then
-- halt
return
end
-- from this point we can assume that the input data is formatted correctly
-- update x-offset
if parsed_data["xoffset"] ~= nil then
xoffset = parsed_data["xoffset"]
end
-- update circular radius
if parsed_data["circular_radius"] ~= nil then
circular_radius = parsed_data["circular_radius"]
end
-- update bipartite height
if parsed_data["bipartite_height"] ~= nil then
bipartite_height = parsed_data["bipartite_height"]
end
-- check existence of metrics
local has_metric_D = parsed_data["calculate_D"]
local has_metric_C = parsed_data["calculate_C"]
-- calculate labels dimensions
local
vertex_labels_width, vertex_labels_height, vertex_labels_depth,
vertex_labels_max_width, vertex_labels_max_height, vertex_labels_max_depth,
position_labels_width, position_labels_height, position_labels_depth,
position_labels_max_width, position_labels_max_height, position_labels_max_depth
=
_G.calculate_labels_dimensions
(
model,
parsed_data["automatic_spacing"],
parsed_data["n"],
parsed_data["INTvertex_to_STRvertex"],
xoffset
)
-- color vertices
local color_per_vertex = _G.bicolor_vertices_graph(
parsed_data["n"],
parsed_data["adjacency_matrix"],
parsed_data["bicolor_vertices"]
)
-- prior to drawing the objects, deselect all objects
local p = model:page()
p:deselectAll()
local prev_Nobj = #p
local num_arrangements = parsed_data["num_arrangements"]
-- draw all arrangements given
if parsed_data["draw_linear"] then
local ycoord = ystart
local max_width = 0
for i = num_arrangements,1, -1 do
local height, ycoord_vertices, width =
_G.linear_draw_data(
model,
{
n = parsed_data["n"],
adjacency_matrix = parsed_data["adjacency_matrix"],
root_vertices = parsed_data["root_vertices"],
automatic_spacing = parsed_data["automatic_spacing"],
INTvertex_to_STRvertex = parsed_data["INTvertex_to_STRvertex"],
calculate_D = parsed_data["calculate_D"],
calculate_C = parsed_data["calculate_C"],
color_per_vertex = color_per_vertex,
arrangement = parsed_data["arrangements"][i],
inverse_arrangement = parsed_data["inverse_arrangements"][i]
},
{
vertex_labels_width = vertex_labels_width,
vertex_labels_height = vertex_labels_height,
vertex_labels_depth = vertex_labels_depth,
vertex_labels_max_width = vertex_labels_max_width,
vertex_labels_max_height = vertex_labels_max_height,
vertex_labels_max_depth = vertex_labels_max_depth,
position_labels_width = position_labels_width,
position_labels_height = position_labels_height,
position_labels_depth = position_labels_depth,
position_labels_max_width = position_labels_max_width,
position_labels_max_height = position_labels_max_height,
position_labels_max_depth = position_labels_max_depth
},
{
xcoord = xstart,
ycoord = ycoord
}
)
if max_width < width then
max_width = width
end
--------------------------------------------------------------------
-- calculate new y coordinate for the vertices' marks
-- increment by POSITIONS and VERTEX LABELS
ycoord = ycoord + (ycoord - ycoord_vertices)
-- increment by the largest arc's radius plus some more space
ycoord = ycoord + height + 8
-- increment by METRICS height
if has_metric_D then
-- height of the label with $D=...$ plus some more
ycoord = ycoord + 8
end
if has_metric_C then
-- height of the label with $C=...$ plus some more
ycoord = ycoord + 8
end
end
xstart = xstart + max_width
end
if parsed_data["draw_circular"] then
local xcoord = xstart + 3*circular_radius + 8
local ycoord = ystart
local max_width = 0
for i = num_arrangements,1, -1 do
local height, width =
_G.circular_draw_data(
model,
{
n = parsed_data["n"],
adjacency_matrix = parsed_data["adjacency_matrix"],
root_vertices = parsed_data["root_vertices"],
automatic_spacing = parsed_data["automatic_spacing"],
INTvertex_to_STRvertex = parsed_data["INTvertex_to_STRvertex"],
calculate_D = parsed_data["calculate_D"],
calculate_C = parsed_data["calculate_C"],
color_per_vertex = color_per_vertex,
arrangement = parsed_data["arrangements"][i],
inverse_arrangement = parsed_data["inverse_arrangements"][i]
},
{
vertex_labels_width = vertex_labels_width,
vertex_labels_height = vertex_labels_height,
vertex_labels_depth = vertex_labels_depth,
vertex_labels_max_width = vertex_labels_max_width,
vertex_labels_max_height = vertex_labels_max_height,
vertex_labels_max_depth = vertex_labels_max_depth,
position_labels_width = position_labels_width,
position_labels_height = position_labels_height,
position_labels_depth = position_labels_depth,
position_labels_max_width = position_labels_max_width,
position_labels_max_height = position_labels_max_height,
position_labels_max_depth = position_labels_max_depth
},
{
radius = circular_radius,
xcoord = xcoord,
ycoord = ycoord
}
)
if max_width < width then
max_width = width
end
--------------------------------------------------------------------
-- calculate new y coordinate for the vertices' marks
-- increment by POSITIONS and VERTEX LABELS
ycoord = ycoord + 24 + height
-- increment by METRICS height
if has_metric_C then
-- height of the label with $C=...$ plus some more
ycoord = ycoord + 8
end
end
xstart = xstart + max_width + 12
end
if parsed_data["draw_bipartite"] then
local xcoord = xstart + 40
local ycoord = ystart
local max_width = 0
if not parsed_data["bicolor_vertices"] then
color_per_vertex = _G.bicolor_vertices_graph(
parsed_data["n"],
parsed_data["adjacency_matrix"],
true
)
end
for i = num_arrangements,1, -1 do
local width =
_G.bipartite_draw_data(
model,
{
n = parsed_data["n"],
adjacency_matrix = parsed_data["adjacency_matrix"],
root_vertices = parsed_data["root_vertices"],
automatic_spacing = parsed_data["automatic_spacing"],
INTvertex_to_STRvertex = parsed_data["INTvertex_to_STRvertex"],
calculate_C = parsed_data["calculate_C"],
color_per_vertex = color_per_vertex,
arrangement = parsed_data["arrangements"][i],
inverse_arrangement = parsed_data["inverse_arrangements"][i]
},
{
vertex_labels_width = vertex_labels_width,
vertex_labels_height = vertex_labels_height,
vertex_labels_depth = vertex_labels_depth,
vertex_labels_max_width = vertex_labels_max_width,
vertex_labels_max_height = vertex_labels_max_height,
vertex_labels_max_depth = vertex_labels_max_depth,
position_labels_width = position_labels_width,
position_labels_height = position_labels_height,
position_labels_depth = position_labels_depth,
position_labels_max_width = position_labels_max_width,
position_labels_max_height = position_labels_max_height,
position_labels_max_depth = position_labels_max_depth
},
{
height = bipartite_height,
xcoord = xcoord,
ycoord = ycoord
}
)
--------------------------------------------------------------------
-- calculate new y coordinate for the vertices' marks
-- increment by POSITIONS and VERTEX LABELS
ycoord = ycoord + 2*(bipartite_height + vertex_labels_max_height + vertex_labels_max_depth) + 12
-- increment by METRICS height
if has_metric_C then
-- height of the label with $C=...$ plus some more
ycoord = ycoord + 8
end
end
xstart = xstart + max_width
end
-- select all created objects
for i = prev_Nobj+1,#p do
p:setSelect(i, 1)
end
end