1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Modify _draw_elevations

* Add legend_width argument, variable & constant
* Applied legend_width variable where required
* Removed U prefix
This commit is contained in:
Daniel Sheppard
2020-02-12 13:15:29 -06:00
parent 15bc731f61
commit 62d6e02d6b
2 changed files with 13 additions and 13 deletions

View File

@ -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

View File

@ -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):