From c15613d7fef42c4314c6c0ba902a475a59850157 Mon Sep 17 00:00:00 2001 From: dreng Date: Fri, 12 May 2023 13:47:15 +0200 Subject: [PATCH] fix physics and icon placement --- netbox_topology_views/views.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/netbox_topology_views/views.py b/netbox_topology_views/views.py index 69f1563..3286cdd 100644 --- a/netbox_topology_views/views.py +++ b/netbox_topology_views/views.py @@ -150,15 +150,18 @@ def create_node( if group_id is None or group_id == "default": group_id = Coordinate.get_or_create_default_group(group_id) if not group_id: - print('Exception occured while handling default group. Setting node to 0;0.') - node["x"] = 0 - node["y"] = 0 + print('Exception occured while handling default group.') return node group = get_object_or_404(CoordinateGroup, pk=group_id) node["physics"] = True + # Coords must be set even if no coords have been stored. Otherwise nodes with coords + # will not be placed correctly by vis-network. + node["x"] = 0 + node["y"] = 0 if Coordinate.objects.filter(group=group, device=device.pk).values('x') and Coordinate.objects.filter(group=group, device=device.pk).values('y'): + # Coordinates data for the device exists in Coordinates Group. Let's assign them node["x"] = Coordinate.objects.get(group=group, device=device.pk).x node["y"] = Coordinate.objects.get(group=group, device=device.pk).y node["physics"] = False @@ -171,12 +174,6 @@ def create_node( node["x"] = int(cords[0]) node["y"] = int(cords[1]) node["physics"] = False - elif save_coords: - node["physics"] = False - else: - node["physics"] = True - node["x"] = 0 - node["y"] = 0 dev_title = " %s
" % (node_content) node["title"] = dev_title