From 15bc731f611f170cf4107b08e974a9785bd4058f Mon Sep 17 00:00:00 2001 From: Dan Sheppard Date: Tue, 11 Feb 2020 23:31:51 -0600 Subject: [PATCH 1/2] Convert rack units to part of SVG rendered document --- netbox/dcim/models/__init__.py | 21 ++++++++++++++----- netbox/project-static/css/rack_elevation.css | 9 ++++++++ netbox/templates/dcim/inc/rack_elevation.html | 6 ------ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/netbox/dcim/models/__init__.py b/netbox/dcim/models/__init__.py index c31f4c713..8f70fa25d 100644 --- a/netbox/dcim/models/__init__.py +++ b/netbox/dcim/models/__init__.py @@ -435,9 +435,20 @@ class RackElevationHelperMixin: def _draw_elevations(self, elevation, reserved_units, face, unit_width, unit_height): - drawing = self._setup_drawing(unit_width, unit_height * self.u_height) + # Setup vars for the rack unit + position_width = 30 + + drawing = self._setup_drawing(unit_width + position_width, unit_height * self.u_height) unit_cursor = 0 + for ru in range(0, self.u_height): + start_y = ru * unit_height + position_coordinates = (15, start_y + unit_height / 2 + 2) + unit = ru + 1 if self.desc_units else self.u_height - ru + drawing.add( + drawing.text("U" + str(unit), position_coordinates, class_="unit") + ) + for unit in elevation: # Loop through all units in the elevation @@ -447,9 +458,9 @@ class RackElevationHelperMixin: # Setup drawing coordinates start_y = unit_cursor * unit_height end_y = unit_height * height - start_cordinates = (0, start_y) - end_cordinates = (unit_width, end_y) - text_cordinates = (unit_width / 2, start_y + end_y / 2) + start_cordinates = (position_width, start_y) + end_cordinates = (position_width + unit_width, end_y) + text_cordinates = (position_width + (unit_width / 2), start_y + end_y / 2) # Draw the device if device and device.face == face: @@ -471,7 +482,7 @@ class RackElevationHelperMixin: unit_cursor += height # Wrap the drawing with a border - drawing.add(drawing.rect((0, 0), (unit_width, self.u_height * unit_height), class_='rack')) + drawing.add(drawing.rect((30, 0), (unit_width, self.u_height * unit_height), class_='rack')) return drawing diff --git a/netbox/project-static/css/rack_elevation.css b/netbox/project-static/css/rack_elevation.css index 06120c223..cbb5015a5 100644 --- a/netbox/project-static/css/rack_elevation.css +++ b/netbox/project-static/css/rack_elevation.css @@ -56,3 +56,12 @@ text { .blocked:hover+.add-device { fill: none; } + +.unit { + margin: 0; + padding: 5px 0px; + + fill: #c0c0c0; + font-size: 10px; + font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; +} diff --git a/netbox/templates/dcim/inc/rack_elevation.html b/netbox/templates/dcim/inc/rack_elevation.html index 1ab2e05ac..b0fcf4908 100644 --- a/netbox/templates/dcim/inc/rack_elevation.html +++ b/netbox/templates/dcim/inc/rack_elevation.html @@ -1,11 +1,5 @@ {% load helpers %} - -
From 62d6e02d6bdb6d1a35d94e96d8de1e8e6b6625dd Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Wed, 12 Feb 2020 13:15:29 -0600 Subject: [PATCH 2/2] Modify _draw_elevations * Add legend_width argument, variable & constant * Applied legend_width variable where required * Removed U prefix --- netbox/dcim/constants.py | 2 ++ netbox/dcim/models/__init__.py | 24 +++++++++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/netbox/dcim/constants.py b/netbox/dcim/constants.py index 0e05867e4..13a5052e4 100644 --- a/netbox/dcim/constants.py +++ b/netbox/dcim/constants.py @@ -9,6 +9,8 @@ from .choices import InterfaceTypeChoices RACK_U_HEIGHT_DEFAULT = 42 +RACK_ELEVATION_LEGEND_WIDTH_DEFAULT = 30 + RACK_ELEVATION_UNIT_WIDTH_DEFAULT = 230 RACK_ELEVATION_UNIT_HEIGHT_DEFAULT = 20 diff --git a/netbox/dcim/models/__init__.py b/netbox/dcim/models/__init__.py index 8f70fa25d..4a817ce11 100644 --- a/netbox/dcim/models/__init__.py +++ b/netbox/dcim/models/__init__.py @@ -433,20 +433,17 @@ class RackElevationHelperMixin: link.add(drawing.rect(start, end, class_=class_)) link.add(drawing.text("add device", insert=text, class_='add-device')) - def _draw_elevations(self, elevation, reserved_units, face, unit_width, unit_height): + def _draw_elevations(self, elevation, reserved_units, face, unit_width, unit_height, legend_width): - # Setup vars for the rack unit - position_width = 30 - - drawing = self._setup_drawing(unit_width + position_width, unit_height * self.u_height) + drawing = self._setup_drawing(unit_width + legend_width, unit_height * self.u_height) unit_cursor = 0 for ru in range(0, self.u_height): start_y = ru * unit_height - position_coordinates = (15, start_y + unit_height / 2 + 2) + position_coordinates = (legend_width / 2, start_y + unit_height / 2 + 2) unit = ru + 1 if self.desc_units else self.u_height - ru drawing.add( - drawing.text("U" + str(unit), position_coordinates, class_="unit") + drawing.text(str(unit), position_coordinates, class_="unit") ) for unit in elevation: @@ -458,9 +455,9 @@ class RackElevationHelperMixin: # Setup drawing coordinates start_y = unit_cursor * unit_height end_y = unit_height * height - start_cordinates = (position_width, start_y) - end_cordinates = (position_width + unit_width, end_y) - text_cordinates = (position_width + (unit_width / 2), start_y + end_y / 2) + start_cordinates = (legend_width, start_y) + end_cordinates = (legend_width + unit_width, end_y) + text_cordinates = (legend_width + (unit_width / 2), start_y + end_y / 2) # Draw the device if device and device.face == face: @@ -482,7 +479,7 @@ class RackElevationHelperMixin: unit_cursor += height # Wrap the drawing with a border - drawing.add(drawing.rect((30, 0), (unit_width, self.u_height * unit_height), class_='rack')) + drawing.add(drawing.rect((legend_width, 0), (unit_width, self.u_height * unit_height), class_='rack')) return drawing @@ -505,7 +502,8 @@ class RackElevationHelperMixin: self, face=DeviceFaceChoices.FACE_FRONT, unit_width=RACK_ELEVATION_UNIT_WIDTH_DEFAULT, - unit_height=RACK_ELEVATION_UNIT_HEIGHT_DEFAULT + unit_height=RACK_ELEVATION_UNIT_HEIGHT_DEFAULT, + legend_width=RACK_ELEVATION_LEGEND_WIDTH_DEFAULT ): """ Return an SVG of the rack elevation @@ -518,7 +516,7 @@ class RackElevationHelperMixin: elevation = self.merge_elevations(face) reserved_units = self.get_reserved_units() - return self._draw_elevations(elevation, reserved_units, face, unit_width, unit_height) + return self._draw_elevations(elevation, reserved_units, face, unit_width, unit_height, legend_width) class Rack(ChangeLoggedModel, CustomFieldModel, RackElevationHelperMixin):