reflexive 1.2.0__py3-none-any.whl → 1.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
reflexive/visualise.py CHANGED
@@ -1,3 +1,6 @@
1
+ from graph_tool.all import *
2
+ import cairo
3
+
1
4
  from reflexive import session
2
5
  from reflexive import cfg
3
6
 
@@ -183,4 +186,151 @@ class Display:
183
186
  b = v[0]
184
187
  e = v[1]
185
188
  #print("New offsets:",len(new_offsets[k]))
186
- return new_offsets
189
+ return new_offsets
190
+
191
+ class RES_graph:
192
+
193
+ #
194
+ gt_props = {0:{ "lbl":"RR",
195
+ "pos":(0.2,6.5),
196
+ "clr":"#00AEEF"},
197
+ 1:{ "lbl":"NR",
198
+ "pos":(5,10),
199
+ "clr":"#ED1B23"},
200
+ 2:{ "lbl":"AR",
201
+ "pos":(9.8,6.5),
202
+ "clr":"#00A64F"},
203
+ 3:{ "lbl":"AF",
204
+ "pos":(7.9,1),
205
+ "clr":"#EC008C"},
206
+ 4:{ "lbl":"EP",
207
+ "pos":(2.1,1),
208
+ "clr":"#FFF200"}}
209
+
210
+
211
+ # re_props = {"RR":{
212
+ # "idx": 0,
213
+ # "pos":(0.2,6.5),
214
+ # "clr":"#00AEEF"},
215
+ # "NR":{
216
+ # "idx": 1,
217
+ # "pos":(5,10),
218
+ # "clr":"#ED1B23"},
219
+ # "AR":{
220
+ # "idx": 2,
221
+ # "pos":(9.8,6.5),
222
+ # "clr":"#00A64F"},
223
+ # "AF":{
224
+ # "idx": 3,
225
+ # "pos":(7.9,1),
226
+ # "clr":"#EC008C"},
227
+ # "EP":{
228
+ # "idx": 4,
229
+ # "pos":(2.1,1),
230
+ # "clr":"#FFF200"}}
231
+
232
+ #
233
+ edges = dict()
234
+ #
235
+ iso_vertices = set()
236
+ #
237
+ v_label = None
238
+ #
239
+ v_color = None
240
+ #
241
+ v_pos = None
242
+
243
+ #
244
+ def __init__(self,matrix=None):
245
+ self._setup(matrix)
246
+
247
+ #
248
+ def _setup(self,matrix):
249
+ if matrix:
250
+ # Edges from matrix
251
+ self.edges = self._matrix_to_dict(matrix)
252
+ self.graph = Graph(g=self.edges.keys(),directed=False)
253
+ self.e_weight = self.graph.new_ep("double",vals=self.edges.values())
254
+ # Handle colour of isolated vertices
255
+ default_clrs = self._get_prop_values('clr')
256
+ actual_clrs = []
257
+ for i in range(5):
258
+ if i in self.iso_vertices:
259
+ clr = "#cccccc"
260
+ else:
261
+ clr = default_clrs[i]
262
+ actual_clrs.append(clr)
263
+ self.v_color = self.graph.new_vp("string",vals=actual_clrs)
264
+ else:
265
+ # No edges
266
+ self.graph = Graph(g=self._empty_edge_dict(),directed=False)
267
+ self.e_weight = self.graph.new_ep("double")
268
+ self.v_color = self.graph.new_vp("string",val="#cccccc")
269
+ # Vertex properties common to all graphs
270
+ self.v_label = self.graph.new_vp("string",vals=self._get_prop_values('lbl'))
271
+ self.v_pos = self.graph.new_vp("vector<double>",vals=self._get_prop_values('pos'))
272
+
273
+
274
+
275
+ #
276
+ def _matrix_to_dict(self,matrix):
277
+ edges = {}
278
+ for r,row in enumerate(matrix):
279
+ # if empty row, add to iso_vertices
280
+ if sum(row) == 0:
281
+ self.iso_vertices.add(r)
282
+ else:
283
+ for c,weight in enumerate(row):
284
+ if weight > 0:
285
+ edge = tuple(sorted((r,c)))
286
+ #print("r,c:",edge," - ",weight)
287
+ edges[edge] = weight
288
+ return edges
289
+
290
+ #
291
+ def _empty_edge_dict(self):
292
+ empty_edges = {}
293
+ for idx in self.gt_props.keys():
294
+ empty_edges[idx] = []
295
+ return empty_edges
296
+
297
+ #
298
+ def _get_prop_values(self,key):
299
+ values_list = self.gt_props.values()
300
+ return [p[key] for p in values_list]
301
+
302
+ # flip coordinates for graph-tool
303
+ def _flipY(self,vpositions):
304
+ x, y = ungroup_vector_property(vpositions, [0, 1])
305
+ y.fa *= -1
306
+ y.fa -= y.fa.min()
307
+ return group_vector_property([x, y])
308
+
309
+ #
310
+ def show(self,inline=True):
311
+ graph = self.graph
312
+ positions = self._flipY(self.v_pos)
313
+ labels = self.v_label
314
+ colors = self.v_color
315
+ weights = self.e_weight
316
+ graph_draw(graph, inline=inline,output_size=(300,300),fit_view=0.7,
317
+ pos=positions,
318
+ vertex_text=labels,
319
+ vertex_font_family="sans serif",
320
+ vertex_font_size=18,
321
+ vertex_font_weight=cairo.FONT_WEIGHT_BOLD,
322
+ vertex_fill_color=colors,
323
+ vertex_size = 50,
324
+ vertex_halo=False,
325
+ vertex_pen_width=1.2,
326
+ vertex_color="#999999",
327
+ edge_pen_width=weights)
328
+
329
+ def get_vertex_labels(self):
330
+ return self._get_prop_values('lbl')
331
+
332
+ def get_vertex_colours(self):
333
+ return self._get_prop_values('clr')
334
+
335
+ def get_vertex_positions(self):
336
+ return self._get_prop_values('pos')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reflexive
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: Supports AWS Reflexive Expressions Systems (RES) Analysis
5
5
  Project-URL: Repository, https://github.com/nlytx/reflexive.git
6
6
  Author-email: Andrew Gibson <andrew@nlytx.io>
@@ -3,8 +3,8 @@ reflexive/analyse.py,sha256=UzWwgjAFNjeWFkCQ2o99g2vWajf17_OtSq4dFCvuPYU,17489
3
3
  reflexive/cfg.py,sha256=Ges35G234P2lvOQHgPZQae5hMSOGyBsmp1bY_yQEKkk,4303
4
4
  reflexive/session.py,sha256=MbqwTsYTgq_e_gw3mb1eRv6USs-zZ2cTCrvUNWuKfAQ,10067
5
5
  reflexive/util.py,sha256=WQ1oyzDi1i8wQ6IBwBPk6IFy07YKhg-Ug2FsOGVJRJQ,3649
6
- reflexive/visualise.py,sha256=BhTdTZXqMzI-dc4h_trEKYCDyBO4kPut6Ppn28yb5qU,6553
7
- reflexive-1.2.0.dist-info/METADATA,sha256=RKfdY47-ewjNWlQcs_wPsDkTPkhHo2MC87PWZ4nBVbM,574
8
- reflexive-1.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
- reflexive-1.2.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
10
- reflexive-1.2.0.dist-info/RECORD,,
6
+ reflexive/visualise.py,sha256=76ItFjz9KyPCxlfKuF16dmY5kLVbdTXAHyfcndMStH0,11355
7
+ reflexive-1.2.1.dist-info/METADATA,sha256=sFL4BMnt-cMD8Ks--16hSTDmLI6F7anBF9zR_61hJDA,574
8
+ reflexive-1.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ reflexive-1.2.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
10
+ reflexive-1.2.1.dist-info/RECORD,,