Skip to content

Commit

Permalink
added offset for y_axis_labels with a length greater than 1. (#119)
Browse files Browse the repository at this point in the history
* added offset for y_axis_labels with a length greater than 1. Removed seed fields from tables.py for FloorPlanTiles, attribute doesn't exist.

* Update changes/116.fixed

Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com>

* Added fix for issue 121: x,y letter coords displaying as int.

---------

Co-authored-by: DJ Howard <djhoward12@gmail.com.com>
Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 4, 2024
1 parent cbcf96c commit 7d53f79
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/116.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed Y Axis with large starting seed causing graphical bleeding.
1 change: 1 addition & 0 deletions changes/121.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed Floor Plan Tiles with Letters displaying Integer values for Floor Plan Tile views.
10 changes: 9 additions & 1 deletion nautobot_floor_plan/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class FloorPlanSVG:
RACK_BORDER_OFFSET = 8
RACK_ORIENTATION_OFFSET = 14
RACKGROUP_TEXT_OFFSET = 12
Y_LABEL_TEXT_OFFSET = 34

def __init__(self, *, floor_plan, user, base_url):
"""
Expand Down Expand Up @@ -89,6 +90,8 @@ def _setup_drawing(self, width, depth):

def _draw_grid(self, drawing):
"""Render the grid underlying all tiles."""
# Setting intial value for y axis label text to 0
y_label_text_offset = 0
# Vertical lines
for x in range(0, self.floor_plan.x_size + 1):
drawing.add(
Expand Down Expand Up @@ -128,11 +131,16 @@ def _draw_grid(self, drawing):
)
for y in range(self.floor_plan.y_origin_seed, self.floor_plan.y_size + self.floor_plan.y_origin_seed):
label = grid_number_to_letter(y) if self.floor_plan.y_axis_labels == AxisLabelsChoices.LETTERS else str(y)
# Adjust the starting position of the y_axis_label text if the length of the inital SEED value is greater than 1
if len(str(self.floor_plan.y_origin_seed)) > 1:
y_label_text_offset = self.Y_LABEL_TEXT_OFFSET - (6 - len(str(self.floor_plan.y_origin_seed)))
if len(str(self.floor_plan.y_origin_seed)) > 4:
y_label_text_offset = self.Y_LABEL_TEXT_OFFSET + 4
drawing.add(
drawing.text(
label,
insert=(
self.BORDER_WIDTH + self.TEXT_LINE_HEIGHT / 2,
self.BORDER_WIDTH + self.TEXT_LINE_HEIGHT / 2 - y_label_text_offset,
(y - self.floor_plan.y_origin_seed + 0.5) * self.GRID_SIZE_Y + self.GRID_OFFSET,
),
class_="grid-label",
Expand Down
15 changes: 11 additions & 4 deletions nautobot_floor_plan/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from nautobot.core.templatetags.helpers import hyperlinked_object

from nautobot_floor_plan import models
from nautobot_floor_plan.templatetags.seed_helpers import grid_location_conversion


class FloorPlanTable(BaseTable):
Expand Down Expand Up @@ -55,6 +56,8 @@ class FloorPlanTileTable(BaseTable):
floor_plan_tile = tables.Column(verbose_name="Tile", empty_values=[])
floor_plan = tables.Column(linkify=True)
location = tables.Column(accessor="floor_plan__location", linkify=True)
x_origin = tables.Column()
y_origin = tables.Column()
rack = tables.Column(linkify=True)
tags = TagColumn()
actions = ButtonsColumn(models.FloorPlanTile)
Expand All @@ -63,6 +66,14 @@ def render_floor_plan_tile(self, record):
"""Render a link to the detail view for the FloorPlanTile record itself."""
return hyperlinked_object(record)

def render_x_origin(self, record):
"""Render x_origin in letters if requried."""
return grid_location_conversion(record, "x")

def render_y_origin(self, record):
"""Render y_origin in letters if requried."""
return grid_location_conversion(record, "y")

class Meta(BaseTable.Meta):
"""Meta attributes."""

Expand All @@ -76,8 +87,6 @@ class Meta(BaseTable.Meta):
"y_origin",
"x_size",
"y_size",
"x_origin_seed",
"y_origin_seed",
"rack",
"rack_group",
"rack_orientation",
Expand All @@ -92,8 +101,6 @@ class Meta(BaseTable.Meta):
"location",
"x_origin",
"y_origin",
"x_origin_seed",
"y_origin_seed",
"x_size",
"y_size",
"rack",
Expand Down
11 changes: 11 additions & 0 deletions nautobot_floor_plan/templatetags/seed_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ def seed_conversion(floor_plan, axis):
seed = utils.grid_number_to_letter(seed)

return f"{seed}"

@register.filter()
def grid_location_conversion(floor_plan_tile, axis):
"""Convert FloorPlanTile coordinate to letter if necessary."""
letters = getattr(floor_plan_tile.floor_plan, f"{axis}_axis_labels")
grid = getattr(floor_plan_tile, f"{axis}_origin")

if letters == choices.AxisLabelsChoices.LETTERS:
grid = utils.grid_number_to_letter(grid)

return f"{grid}"

0 comments on commit 7d53f79

Please sign in to comment.