Skip to content

Commit 2d89301

Browse files
committed
add hypersparse argumentts for draw graph.
1 parent b00a6b4 commit 2d89301

File tree

5 files changed

+84
-56
lines changed

5 files changed

+84
-56
lines changed

docs/imgs/binary_op_A.png

-15 Bytes
Loading

docs/imgs/binary_op_B.png

31 Bytes
Loading

docs/imgs/select_op_A.png

-38 Bytes
Loading

docs/imgs/unary_op_A.png

5 Bytes
Loading

pygraphblas/gviz.py

Lines changed: 84 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def draw_vector_dot(V, name="", rankdir="LR", ioff=0, joff=0): # pragma: nocove
6464

6565

6666
def draw_graph(
67-
M,
67+
A,
68+
B=None,
6869
g=None,
6970
name="",
7071
rankdir="LR",
@@ -112,63 +113,90 @@ def draw_graph(
112113
if isinstance(label_vector, list):
113114
labeler = lambda v, i: v[i] if labels else ""
114115
else:
115-
labeler = lambda v, i: v.get(i) if labels else ""
116-
117-
for i, j, v in M:
118-
ilabel = (
119-
_str(labeler(label_vector, i), label_width)
120-
if label_vector
121-
else str(i)
122-
if labels
123-
else ""
124-
)
125-
jlabel = (
126-
_str(labeler(label_vector, j), label_width)
127-
if label_vector
128-
else str(j)
129-
if labels
130-
else ""
131-
)
132-
vlabel = weight_prefix + _str(v, label_width) if weights else None
116+
labeler = lambda v, i: v.get(i, i) if labels else ""
133117

134-
if size_vector:
135-
scale = max(size_vector[i] * size_scale, min_size)
136-
if log_scale:
137-
scale = max(log(scale), min_size)
138-
size = _str(scale, label_width)
139-
else:
140-
size = "0.5"
118+
if B is not None:
119+
hyper = True
120+
M = [A, B]
121+
else:
122+
hyper = False
123+
M = [A]
124+
125+
for m in M:
126+
for i, j, v in m:
127+
ilabel = (
128+
_str(labeler(label_vector, i), label_width)
129+
if label_vector
130+
else str(i)
131+
if labels
132+
else ""
133+
)
134+
jlabel = (
135+
_str(labeler(label_vector, j), label_width)
136+
if label_vector
137+
else str(j)
138+
if labels
139+
else ""
140+
)
141+
vlabel = weight_prefix + _str(v, label_width) if weights else None
142+
143+
if size_vector:
144+
scale = max(size_vector[i] * size_scale, min_size)
145+
if log_scale:
146+
scale = max(log(scale), min_size)
147+
size = _str(scale, label_width)
148+
else:
149+
size = "0.5"
150+
151+
args = {"width": size, "fixedsize": "true"}
152+
if hyper and m is B:
153+
args["shape"] = "point"
154+
args["style"] = "invis"
155+
args["width"] = "0"
156+
if node_attr:
157+
args.update(node_attr)
158+
if labels and m is A:
159+
args["label"] = ilabel
160+
if label_cmap and label_vector:
161+
args["color"] = rgb2hex(label_cmap(float(labeler(label_vector, i))))
162+
inode = g.node(str(i + ioff), **args)
163+
164+
args = {"width": size, "fixedsize": "true"}
165+
if hyper and m is A:
166+
args["shape"] = "point"
167+
args["style"] = "invis"
168+
args["width"] = "0"
169+
if node_attr:
170+
args.update(node_attr)
171+
if labels and (B is None or m is B):
172+
args["label"] = jlabel
173+
if label_cmap:
174+
args["color"] = rgb2hex(label_cmap(float(labeler(label_vector, j))))
175+
jnode = g.node(str(j + joff), **args)
176+
w = str(v)
177+
178+
args = {}
179+
if edge_attr:
180+
args.update(edge_attr)
181+
if labels and (B is None or m is B):
182+
args["label"] = vlabel
183+
args["tooltip"] = vlabel
184+
if edge_cmap:
185+
args["color"] = rgb2hex(edge_cmap(float(v)))
186+
if not weights:
187+
w = None
188+
if hyper:
189+
if m is A:
190+
args["dir"] = "none"
191+
args["headclips"] = "false"
192+
args["tailclips"] = "false"
193+
elif m is B:
194+
args["dir"] = "forward"
195+
args["headclips"] = "false"
196+
args["tailclips"] = "false"
197+
198+
g.edge(str(i + ioff), str(j + joff), weight=w, **args)
141199

142-
args = {"width": size, "fixedsize": "true"}
143-
if node_attr:
144-
args.update(node_attr)
145-
if labels:
146-
args["label"] = ilabel
147-
if label_cmap and label_vector:
148-
args["color"] = rgb2hex(label_cmap(float(labeler(label_vector, i))))
149-
inode = g.node(str(i + ioff), **args)
150-
151-
args = {"width": size, "fixedsize": "true"}
152-
if node_attr:
153-
args.update(node_attr)
154-
if labels:
155-
args["label"] = jlabel
156-
if label_cmap:
157-
args["color"] = rgb2hex(label_cmap(float(labeler(label_vector, j))))
158-
jnode = g.node(str(j + joff), **args)
159-
w = str(v)
160-
161-
args = {}
162-
if edge_attr:
163-
args.update(edge_attr)
164-
if labels:
165-
args["label"] = vlabel
166-
args["tooltip"] = vlabel
167-
if edge_cmap:
168-
args["color"] = rgb2hex(edge_cmap(float(v)))
169-
if not weights:
170-
w = None
171-
g.edge(str(i + ioff), str(j + joff), weight=w, **args)
172200
if filename is not None:
173201
g.render(filename, format="png")
174202
return g

0 commit comments

Comments
 (0)