Skip to content

Commit

Permalink
Circular drawer scale (#82)
Browse files Browse the repository at this point in the history
* add cli argument for circular drawer: maximum distance to scale runs to

* Fix typos, implement scaling of distances and rings

* Fix year and help text

* quantity only if argument is given

* examples for animated gifs
  • Loading branch information
lowtower authored Feb 27, 2021
1 parent f51a133 commit 3e297b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Binary file added examples/circular.fix.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/circular.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions gpxtrackposter/circular_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, the_poster: Poster) -> None:
super().__init__(the_poster)
self._rings = False
self._ring_color = "darkgrey"
self._max_distance = None

def create_args(self, args_parser: argparse.ArgumentParser) -> None:
"""Add arguments to the parser"""
Expand All @@ -61,11 +62,20 @@ def create_args(self, args_parser: argparse.ArgumentParser) -> None:
default="darkgrey",
help="Color of distance rings.",
)
group.add_argument(
"--circular-ring-max-distance",
dest="circular_ring_max_distance",
metavar="DISTANCE KM",
type=float,
help="Maximum distance for scaling the track length.",
)

def fetch_args(self, args: argparse.Namespace) -> None:
"""Get arguments from the parser"""
self._rings = args.circular_rings
self._ring_color = args.circular_ring_color
if args.circular_ring_max_distance:
self._max_distance = abs(args.circular_ring_max_distance) * Units().km

def draw(self, dr: svgwrite.Drawing, g: svgwrite.container.Group, size: XY, offset: XY) -> None:
"""Draw the circular Poster using distances broken down by time"""
Expand Down Expand Up @@ -195,6 +205,8 @@ def _draw_rings(
return
min_length = length_range.lower()
max_length = length_range.upper()
if self._max_distance:
max_length = self._max_distance
assert min_length is not None
assert max_length is not None
ring_distance = self._determine_ring_distance(max_length)
Expand Down Expand Up @@ -229,6 +241,8 @@ def _draw_circle_segment(
has_special = len([t for t in tracks if t.special]) > 0
color = self.color(self.poster.length_range_by_date, length, has_special)
max_length = self.poster.length_range_by_date.upper()
if self._max_distance:
max_length = self._max_distance.to_base_units()
assert max_length is not None
r1 = rr.lower()
assert r1 is not None
Expand Down

0 comments on commit 3e297b8

Please sign in to comment.