Skip to content

Commit

Permalink
Removed room rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
lukakama committed Dec 16, 2023
1 parent dc1d9bc commit 672b959
Showing 1 changed file with 0 additions and 91 deletions.
91 changes: 0 additions & 91 deletions deebot_client/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from io import BytesIO
import itertools
import lzma
import re
import struct
from typing import Any, Final
import zlib
Expand Down Expand Up @@ -50,22 +49,6 @@

_SVG_MAP_MARGIN = 5

# Categorigal palette for 12 non related elements
_ROOM_COLORS = [
"#a6cee3",
"#1f78b4",
"#b2df8a",
"#33a02c",
"#fb9a99",
"#e31a1c",
"#fdbf6f",
"#ff7f00",
"#cab2d6",
"#6a3d9a",
"#ffff99",
"#b15928",
]

_OFFSET = 400
_TRACE_MAP = "trace_map"
_COLORS = {
Expand Down Expand Up @@ -357,71 +340,6 @@ def _get_svg_traces_path(self) -> svg.Path | None:

return None

def _get_svg_rooms(
self,
image_box: tuple[int, int, int, int],
image_box_center: tuple[float, float],
) -> tuple[list[svg.Element], list[svg.Element]]:
svg_rooms_elements: list[svg.Element] = []
svg_rooms_labels: list[svg.Element] = []

for room, color in zip(
sorted(self._map_data.rooms.keys()), itertools.cycle(_ROOM_COLORS)
):
# Split coordinates into a flat sequence
room_coords = re.split(
"[;,]",
_decompress_7z_base64_data(
self._map_data.rooms[room].coordinates
).decode("ascii"),
)

# Append to room svg elements
svg_rooms_elements.append(
svg.Polygon(
id=f"room_{room}",
fill=color + "50",
stroke=color + "A0",
stroke_width=2,
vector_effect="non-scaling-stroke",
transform=[svg.Translate(_OFFSET, _OFFSET), svg.Scale(0.02, 0.02)],
points=list(map(int, room_coords)),
)
)

room_name = self._map_data.rooms[room].name
if room_name != "Default":
# Calculate label positions (cannot use SVG transformations to vertically flip coordinates, as transformations are
# applied to the whole text, which would result in text to be vertically flipped...)

# Get a rough room center.
room_center_x = sum(float(x) for x in room_coords[0::2]) / (
len(room_coords) / 2
)
room_center_y = sum(float(y) for y in room_coords[1::2]) / (
len(room_coords) / 2
)

# Get map relative position
room_center_p = _calc_point(room_center_x, room_center_y, image_box)

# Add the text, with position vertically flipped on map center
svg_rooms_labels.append(
svg.Text(
id=f"room_label_{room}",
x=room_center_p[0],
y=image_box_center[1] - room_center_p[1] + image_box_center[1],
dominant_baseline="middle",
text_anchor="middle",
font_family="sans-serif",
font_size=svg.Length(4, "pt"),
style="user_select: none",
text=room_name,
)
)

return (svg_rooms_elements, svg_rooms_labels)

def enable(self) -> None:
"""Enable map."""
if self._unsubscribers:
Expand Down Expand Up @@ -542,10 +460,6 @@ def get_svg_map(self, width: int | None = None) -> str:
for subset in self._map_data.map_subsets.values()
]

svg_rooms_elements, svg_rooms_labels = self._get_svg_rooms(
image_box, image_box_center
)

svg_traces_path = self._get_svg_traces_path()

# Elements of the SVG Map to vertically flip
Expand All @@ -563,9 +477,6 @@ def get_svg_map(self, width: int | None = None) -> str:
)
)

# Rooms
svg_map_group_elements.extend(svg_rooms_elements)

# Additional subsets (VirtualWalls and NoMopZones)
svg_map_group_elements.extend(svg_subset_elements)

Expand Down Expand Up @@ -593,8 +504,6 @@ def get_svg_map(self, width: int | None = None) -> str:
transform=[svg.Scale(1, -1)],
elements=svg_map_group_elements,
),
# Elements with already flipped coordinates.
svg.G(elements=svg_rooms_labels),
]

str_svg_map = str(svg_map)
Expand Down

0 comments on commit 672b959

Please sign in to comment.