Skip to content

Device names overflow rack unit boundaries in SVG rendering #19902

@MarcoSpiz

Description

@MarcoSpiz

NetBox version

v4.3.4

Feature type

Change to existing functionality

Proposed functionality

In the rack elevation SVG rendering, device names should be automatically truncated if they exceed a reasonable length, to ensure they remain within the visual bounds of the device slot. The truncation should append an ellipsis (…) to indicate the text was shortened. This approach preserves readability and prevents label overflow without requiring layout changes.

A possible implementation could be:
dcim/svg/racks.py

def _truncate_text(self, text, max_chars):
    return text if len(text) <= max_chars else text[:max_chars - 1] + '…'

And in the _draw_device method:

font_size = 14  # derived from .875rem = 14px
char_width = font_size * 0.6  # average character width in px
max_chars = int(size[0] / char_width)
display_name = self._truncate_text(name, max_chars)
...
link.add(Text(display_name, ...)

From this:

Image

To this:
Image

Use case

This functionality increases the usability of the elevation function, allowing good graphic rendering even with long names,
without removing any functionality, still allowing users to see the complete name by hovering over it with the mouse.

Database changes

No response

External dependencies

No response

Metadata

Metadata

Assignees

Labels

complexity: lowRequires minimal effort to implementstatus: acceptedThis issue has been accepted for implementationtype: featureIntroduction of new functionality to the application

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions