mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 00:15:17 -06:00
Improved SVG rendering of multiple rear ports (with positions) per path trace. Include asymmetric path detection
This commit is contained in:
parent
359b366b27
commit
5bb373fe2a
@ -34,9 +34,13 @@ class Node(Hyperlink):
|
|||||||
radius: Box corner radius, for rounded corners (default: 10)
|
radius: Box corner radius, for rounded corners (default: 10)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, position, width, url, color, labels, radius=10, **extra):
|
object = None
|
||||||
|
|
||||||
|
def __init__(self, position, width, url, color, labels, radius=10, object=object, **extra):
|
||||||
super(Node, self).__init__(href=url, target='_parent', **extra)
|
super(Node, self).__init__(href=url, target='_parent', **extra)
|
||||||
|
|
||||||
|
self.object = object
|
||||||
|
|
||||||
x, y = position
|
x, y = position
|
||||||
|
|
||||||
# Add the box
|
# Add the box
|
||||||
@ -77,7 +81,7 @@ class Connector(Group):
|
|||||||
labels: Iterable of text labels
|
labels: Iterable of text labels
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, start, url, color, labels=[], **extra):
|
def __init__(self, start, url, color, labels=[], description=[], **extra):
|
||||||
super().__init__(class_='connector', **extra)
|
super().__init__(class_='connector', **extra)
|
||||||
|
|
||||||
self.start = start
|
self.start = start
|
||||||
@ -104,6 +108,8 @@ class Connector(Group):
|
|||||||
text_coords = (start[0] + PADDING * 2, cursor - LINE_HEIGHT / 2)
|
text_coords = (start[0] + PADDING * 2, cursor - LINE_HEIGHT / 2)
|
||||||
text = Text(label, insert=text_coords, class_='bold' if not i else [])
|
text = Text(label, insert=text_coords, class_='bold' if not i else [])
|
||||||
link.add(text)
|
link.add(text)
|
||||||
|
if len(description) > 0:
|
||||||
|
link.set_desc("\n".join(description))
|
||||||
|
|
||||||
self.add(link)
|
self.add(link)
|
||||||
|
|
||||||
@ -206,7 +212,8 @@ class CableTraceSVG:
|
|||||||
url=f'{self.base_url}{term.get_absolute_url()}',
|
url=f'{self.base_url}{term.get_absolute_url()}',
|
||||||
color=self._get_color(term),
|
color=self._get_color(term),
|
||||||
labels=self._get_labels(term),
|
labels=self._get_labels(term),
|
||||||
radius=5
|
radius=5,
|
||||||
|
object=term
|
||||||
)
|
)
|
||||||
nodes_height = max(nodes_height, node.box['height'])
|
nodes_height = max(nodes_height, node.box['height'])
|
||||||
nodes.append(node)
|
nodes.append(node)
|
||||||
@ -238,20 +245,39 @@ class CableTraceSVG:
|
|||||||
Polyline(points=points, style=f'stroke: #{connector.color}'),
|
Polyline(points=points, style=f'stroke: #{connector.color}'),
|
||||||
))
|
))
|
||||||
|
|
||||||
def draw_cable(self, cable):
|
def draw_cable(self, cable, terminations, cable_count=0):
|
||||||
labels = [
|
if cable_count > 2:
|
||||||
f'Cable {cable}',
|
labels = [f'{cable}']
|
||||||
cable.get_status_display()
|
description = [
|
||||||
]
|
f'Cable {cable}',
|
||||||
if cable.type:
|
cable.get_status_display()
|
||||||
labels.append(cable.get_type_display())
|
]
|
||||||
if cable.length and cable.length_unit:
|
if cable.type:
|
||||||
labels.append(f'{cable.length} {cable.get_length_unit_display()}')
|
description.append(cable.get_type_display())
|
||||||
|
if cable.length and cable.length_unit:
|
||||||
|
description.append(f'{cable.length} {cable.get_length_unit_display()}')
|
||||||
|
else:
|
||||||
|
labels = [
|
||||||
|
f'Cable {cable}',
|
||||||
|
cable.get_status_display()
|
||||||
|
]
|
||||||
|
description = []
|
||||||
|
if cable.type:
|
||||||
|
labels.append(cable.get_type_display())
|
||||||
|
if cable.length and cable.length_unit:
|
||||||
|
labels.append(f'{cable.length} {cable.get_length_unit_display()}')
|
||||||
|
|
||||||
|
if len(terminations) == 1:
|
||||||
|
center = terminations[0].bottom_center[0]
|
||||||
|
else:
|
||||||
|
termination_centers = [term.bottom_center[0] for term in terminations]
|
||||||
|
center = sum(termination_centers) / len(termination_centers)
|
||||||
connector = Connector(
|
connector = Connector(
|
||||||
start=(self.center + OFFSET, self.cursor),
|
start=(center, self.cursor),
|
||||||
color=cable.color or '000000',
|
color=cable.color or '000000',
|
||||||
url=f'{self.base_url}{cable.get_absolute_url()}',
|
url=f'{self.base_url}{cable.get_absolute_url()}',
|
||||||
labels=labels
|
labels=labels,
|
||||||
|
description=description
|
||||||
)
|
)
|
||||||
|
|
||||||
self.cursor += connector.height
|
self.cursor += connector.height
|
||||||
@ -334,34 +360,47 @@ class CableTraceSVG:
|
|||||||
|
|
||||||
# Connector (a Cable or WirelessLink)
|
# Connector (a Cable or WirelessLink)
|
||||||
if links:
|
if links:
|
||||||
link = links[0] # Remove Cable from list
|
link_cables = {}
|
||||||
|
fanin = False
|
||||||
|
fanout = False
|
||||||
|
|
||||||
# Cable
|
# Determine if we have fanins or fanouts
|
||||||
if type(link) is Cable:
|
if len(near_ends) > len(set(links)):
|
||||||
|
self.cursor += FANOUT_HEIGHT
|
||||||
|
fanin = True
|
||||||
|
if len(far_ends) > len(set(links)):
|
||||||
|
fanout = True
|
||||||
|
cursor = self.cursor
|
||||||
|
for link in links:
|
||||||
|
# Cable
|
||||||
|
if type(link) is Cable and not link_cables.get(link.pk):
|
||||||
|
self.cursor = cursor
|
||||||
|
near_end_link_terminations = [term for term in terminations if term.object.cable == link]
|
||||||
|
cable = self.draw_cable(link, near_end_link_terminations, cable_count=len(links))
|
||||||
|
link_cables.update({link.pk: cable})
|
||||||
|
self.connectors.append(cable)
|
||||||
|
|
||||||
# Account for fan-ins height
|
# Draw fan-ins
|
||||||
if len(near_ends) > 1:
|
if len(near_ends) > 1 and fanin:
|
||||||
self.cursor += FANOUT_HEIGHT
|
for term in terminations:
|
||||||
|
if term.object.cable == link:
|
||||||
|
self.draw_fanin(term, cable)
|
||||||
|
|
||||||
cable = self.draw_cable(link)
|
# WirelessLink
|
||||||
self.connectors.append(cable)
|
elif type(link) is WirelessLink:
|
||||||
|
wirelesslink = self.draw_wirelesslink(link)
|
||||||
# Draw fan-ins
|
self.connectors.append(wirelesslink)
|
||||||
if len(near_ends) > 1:
|
|
||||||
for term in terminations:
|
|
||||||
self.draw_fanin(term, cable)
|
|
||||||
|
|
||||||
# WirelessLink
|
|
||||||
elif type(link) is WirelessLink:
|
|
||||||
wirelesslink = self.draw_wirelesslink(link)
|
|
||||||
self.connectors.append(wirelesslink)
|
|
||||||
|
|
||||||
# Far end termination(s)
|
# Far end termination(s)
|
||||||
if len(far_ends) > 1:
|
if len(far_ends) > 1:
|
||||||
self.cursor += FANOUT_HEIGHT
|
if fanout:
|
||||||
terminations = self.draw_terminations(far_ends)
|
self.cursor += FANOUT_HEIGHT
|
||||||
for term in terminations:
|
terminations = self.draw_terminations(far_ends)
|
||||||
self.draw_fanout(term, cable)
|
for term in terminations:
|
||||||
|
if hasattr(term.object, 'cable') and link_cables.get(term.object.cable.pk):
|
||||||
|
self.draw_fanout(term, link_cables.get(term.object.cable.pk))
|
||||||
|
else:
|
||||||
|
self.draw_terminations(far_ends)
|
||||||
elif far_ends:
|
elif far_ends:
|
||||||
self.draw_terminations(far_ends)
|
self.draw_terminations(far_ends)
|
||||||
else:
|
else:
|
||||||
|
@ -23,7 +23,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="trace-end">
|
<div class="trace-end">
|
||||||
{% if path.is_split %}
|
{% if path.is_split and path.get_asymmetric_nodes %}
|
||||||
|
<h3 class="text-danger">{% trans "Asymmetric Path" %}!</h3>
|
||||||
|
<p>{% trans "The nodes below have no links and result in an asymmetric path" %}:</p>
|
||||||
|
<ul class="text-start">
|
||||||
|
{% for next_node in path.get_asymmetric_nodes %}
|
||||||
|
<li class="text-muted">{{ next_node|linkify }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% elif path.is_split %}
|
||||||
<h3 class="text-danger">{% trans "Path split" %}!</h3>
|
<h3 class="text-danger">{% trans "Path split" %}!</h3>
|
||||||
<p>{% trans "Select a node below to continue" %}:</p>
|
<p>{% trans "Select a node below to continue" %}:</p>
|
||||||
<ul class="text-start">
|
<ul class="text-start">
|
||||||
|
Loading…
Reference in New Issue
Block a user