Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/nwdiag/drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,20 @@ def node(self, node, **kwargs):
m = self.metrics

for connector in m.node(node).connectors:
self.draw_connector(connector)
if hasattr(connector, 'subject'):
network = connector.subject.network
else:
network = connector.network

linestyle=None
if network in node.linestyles:
linestyle=node.linestyles[network]
linecolor=None
if network in node.linecolors:
linecolor=node.linecolors[network]

self.draw_connector(connector,linestyle,linecolor)

if network in node.address:
label = node.address[network]
self.drawer.textarea(connector.textbox, label,
Expand All @@ -163,12 +171,17 @@ def node(self, node, **kwargs):

super(DiagramDraw, self).node(node, **kwargs)

def draw_connector(self, connector):
def draw_connector(self, connector, linestyle, linecolor):
if hasattr(connector, 'subject'):
linecolor = connector.subject.network.linecolor
lc = connector.subject.network.linecolor
ls = connector.subject.network.linestyle
else:
linecolor = connector.network.linecolor
self.drawer.line(connector.line, fill=linecolor, jump=True)
lc = connector.network.linecolor
ls = connector.network.linestyle
if linestyle is None: linestyle=ls
if linecolor is None: linecolor=lc

self.drawer.line(connector.line, fill=linecolor, style=linestyle, jump=True)

def group_label(self, group):
if group.label:
Expand Down
9 changes: 9 additions & 0 deletions src/nwdiag/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def __init__(self, _id):
super(DiagramNode, self).__init__(_id)

self.address = {}
self.linestyles = {}
self.linecolors = {}
self.networks = []
self.layouted = False

Expand All @@ -39,6 +41,12 @@ def set_attributes(self, network, attrs=None):
if attr.name == 'address':
address = re.sub(r'\s*,\s*', '\n', unquote(attr.value))
self.address[network] = address
elif attr.name == 'linestyle':
style = re.sub(r'\s*,\s*', '\n', unquote(attr.value))
self.linestyles[network] = style
elif attr.name == 'linecolor':
color = re.sub(r'\s*,\s*', '\n', unquote(attr.value))
self.linecolors[network] = color
else:
self.set_attribute(attr)

Expand All @@ -50,6 +58,7 @@ class DiagramEdge(blockdiag.elements.DiagramEdge):
class Network(blockdiag.elements.NodeGroup):
basecolor = (185, 203, 228)
linecolor = (0, 0, 0)
linestyle = "solid"

@classmethod
def set_default_linecolor(cls, color):
Expand Down
2 changes: 1 addition & 1 deletion src/nwdiag/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def __init__(self, group, metrics, x1, y1, x2, y2):
if group.nodes:
networks = group.nodes[0].networks[:]
networks.sort(key=lambda a: a.xy.y)
network = min(networks)
network = networks[0]
if self.top.x == metrics.network(network).top.x:
self.is_root_group = True

Expand Down