Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #14241, Fixes #13922: Update the CableRender #14750

Merged
merged 3 commits into from
Apr 23, 2024

Conversation

Moehritz
Copy link

@Moehritz Moehritz commented Jan 9, 2024

Fixes: #14241, Fixes: #13922

This commit updates the cable rendering logic to fix both issue #14241 and #13922. Before, objects, terminations and cables where drawn in the svg without context of each other.
Now the following changes are applied:

  • Hosts and Terminations are where possible sorted alphabetically
  • Terminations and Cables are visually connected, and if necessary not in a vertical line
  • Terminations and Hosts are visually aligning
  • Cable Tooltips contain more information

Before:
image
After:
image

…e CableRender

This commit updates the cable rendering logic to fix
both issue netbox-community#14722 and netbox-community#13922. Before, objects, terminations
and cables where drawn in the svg without context of each
other.
Now the following changes are applied:
- Hosts and Terminations are where possible sorted alphabetically
- Terminations and Cables are visually connected, and if necessary not in a vertical line
- Terminations and Hosts are visually aligning
- Cable Tooltips contain more information
Copy link
Member

@DanSheps DanSheps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to test this and let you know if I come across anything. For now, see my comments below but you can wait until Jeremy pipes in as to whether he wants to take action on those.

This is similar to what I was going to do, but not exactly. Definintely seems like a workable solution though.

netbox/dcim/svg/cables.py Outdated Show resolved Hide resolved
netbox/dcim/svg/cables.py Outdated Show resolved Hide resolved
netbox/dcim/svg/cables.py Outdated Show resolved Hide resolved
netbox/dcim/svg/cables.py Outdated Show resolved Hide resolved
netbox/dcim/svg/cables.py Outdated Show resolved Hide resolved
netbox/dcim/svg/cables.py Outdated Show resolved Hide resolved
Copy link
Member

@DanSheps DanSheps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traceback (most recent call last):
  File "C:\Development\netbox\venv\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Development\netbox\venv\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Development\netbox\venv\lib\site-packages\django\views\decorators\csrf.py", line 56, in wrapper_view
    return view_func(*args, **kwargs)
  File "C:\Development\netbox\venv\lib\site-packages\rest_framework\viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Development\netbox\netbox\netbox\netbox\api\viewsets\__init__.py", line 93, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "C:\Development\netbox\venv\lib\site-packages\rest_framework\views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "C:\Development\netbox\venv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "C:\Development\netbox\venv\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
    raise exc
  File "C:\Development\netbox\venv\lib\site-packages\rest_framework\views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "C:\Development\netbox\netbox\netbox\dcim\api\views.py", line 60, in trace
    return HttpResponse(drawing.render().tostring(), content_type='image/svg+xml')
  File "C:\Development\netbox\netbox\netbox\dcim\svg\cables.py", line 405, in render
    start = near[0].bottom_center
IndexError: list index out of range

Repro:

  1. Create device
  2. Create interfaces (2)
  3. Create device
  4. Create Rear Ports (2, 1 position)
  5. Create Front Ports (2)
  6. Connect Int1 to FP1
  7. Connect RP1 to RP2
  8. Connect FP2 to Int2

This is also reproducable with going through a "proper" panel system (Switch 1 --> Panel 1 --> Panel 2 --> Switch 2

@DanSheps DanSheps changed the title Fixes #14722, Fixes #13922: Update the CableRender Fixes #14241, Fixes #13922: Update the CableRender Jan 9, 2024
also remove out-of-scope changes to tooltips
@Moehritz
Copy link
Author

Traceback (most recent call last):
  File "C:\Development\netbox\venv\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Development\netbox\venv\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Development\netbox\venv\lib\site-packages\django\views\decorators\csrf.py", line 56, in wrapper_view
    return view_func(*args, **kwargs)
  File "C:\Development\netbox\venv\lib\site-packages\rest_framework\viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Development\netbox\netbox\netbox\netbox\api\viewsets\__init__.py", line 93, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "C:\Development\netbox\venv\lib\site-packages\rest_framework\views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "C:\Development\netbox\venv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "C:\Development\netbox\venv\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
    raise exc
  File "C:\Development\netbox\venv\lib\site-packages\rest_framework\views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "C:\Development\netbox\netbox\netbox\dcim\api\views.py", line 60, in trace
    return HttpResponse(drawing.render().tostring(), content_type='image/svg+xml')
  File "C:\Development\netbox\netbox\netbox\dcim\svg\cables.py", line 405, in render
    start = near[0].bottom_center
IndexError: list index out of range

Repro:

  1. Create device
  2. Create interfaces (2)
  3. Create device
  4. Create Rear Ports (2, 1 position)
  5. Create Front Ports (2)
  6. Connect Int1 to FP1
  7. Connect RP1 to RP2
  8. Connect FP2 to Int2

This is also reproducable with going through a "proper" panel system (Switch 1 --> Panel 1 --> Panel 2 --> Switch 2

This happened due to a_terminations containing the far end and vice-versa.
I did not anticipate this - and corrected for it in a kinda ugly manner (if any of the lists ists empty, redo them backwards). Not sure if there is a better way to solve it right there

@Moehritz Moehritz requested a review from DanSheps January 10, 2024 13:42
@DanSheps
Copy link
Member

This happened due to a_terminations containing the far end and vice-versa.
I did not anticipate this - and corrected for it in a kinda ugly manner (if any of the lists ists empty, redo them backwards). Not sure if there is a better way to solve it right there

There might be, I will review when I have time

Copy link
Member

@DanSheps DanSheps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks reasonable now to me, but I would like a second set of eyes on this.

@DanSheps DanSheps removed the request for review from jeremystretch April 23, 2024 02:52
@DanSheps DanSheps merged commit cad3e34 into netbox-community:develop Apr 23, 2024
DanSheps added a commit that referenced this pull request Apr 23, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
@Moehritz Moehritz deleted the 13922-svg-uneven branch August 7, 2024 10:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi-termination Cable Trace: Interfaces are randomly swapped SVG error when rendering uneven interfaces
2 participants