Skip to content

Commit

Permalink
Bugfix/circular drawer units (#101)
Browse files Browse the repository at this point in the history
* - add wheel

* - bump-year to 2022

* - use given units for circular_ring_max_distance

* - use given units for circular_ring_max_distance

* - make use of units for max_length

* - update-readme

* - remove min_length, convert after assert

---------

Co-authored-by: Lowtower <lowtower@lowtower.de>
  • Loading branch information
lowtower and Lowtower authored Feb 19, 2023
1 parent 445202f commit e8da1e3
Show file tree
Hide file tree
Showing 28 changed files with 43 additions and 41 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2021 Florian Pigorsch & Contributors
Copyright (c) 2016-2022 Florian Pigorsch & Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ COPYRIGHT_FILES = README.md LICENSE gpxtrackposter/*.py tests/*.py scripts/*.py
.PHONY: setup
setup:
python3 -m venv .env
.env/bin/pip install --upgrade pip
.env/bin/pip install --upgrade pip wheel
.env/bin/pip install --upgrade -r requirements.txt
.env/bin/pip install --upgrade -r requirements-dev.txt
.env/bin/pip install .
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ usage: create_poster [-h] [--gpx-dir DIR] [--output FILE]
[--heatmap-center LAT,LNG] [--heatmap-radius RADIUS_KM]
[--heatmap-line-transparency-width TRANSP_1,WIDTH_1, TRANSP_2,WIDTH_2, TRANSP_3,WIDTH_3]
[--circular-rings] [--circular-ring-color COLOR]
[--circular-ring-max-distance DISTANCE KM]
[--circular-ring-max-distance DISTANCE]
optional arguments:
-h, --help show this help message and exit
Expand Down Expand Up @@ -104,8 +104,9 @@ Circular Type Options:
--circular-rings Draw distance rings.
--circular-ring-color COLOR
Color of distance rings.
--circular-ring-max-distance DISTANCE KM
Maximum distance for scaling the track length.
--circular-ring-max-distance DISTANCE
Maximum distance for scaling the track lengths (in
given units).
```

Example:
Expand Down Expand Up @@ -249,6 +250,6 @@ E.g. use [Poedit](https://poedit.net/) or [Localise Online Editor](https://local
`msgfmt gpxposter.po -o gpxposter.mo`

## License
[MIT](https://github.com/flopp/GpxTrackPoster/blob/master/LICENSE) &copy; 2016-2021 Florian Pigorsch
[MIT](https://github.com/flopp/GpxTrackPoster/blob/master/LICENSE) &copy; 2016-2022 Florian Pigorsch

[strava-activity-type]: https://developers.strava.com/docs/reference/#api-models-ActivityType
2 changes: 1 addition & 1 deletion gpxtrackposter/calendar_drawer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Draw a calendar poster."""
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
23 changes: 12 additions & 11 deletions gpxtrackposter/circular_drawer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Draw a circular Poster."""
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down Expand Up @@ -44,6 +44,7 @@ def __init__(self, the_poster: Poster) -> None:
self._rings = False
self._ring_color = "darkgrey"
self._max_distance = None
self._unit = Units().km

def create_args(self, args_parser: argparse.ArgumentParser) -> None:
"""Add arguments to the parser"""
Expand All @@ -65,17 +66,17 @@ def create_args(self, args_parser: argparse.ArgumentParser) -> None:
group.add_argument(
"--circular-ring-max-distance",
dest="circular_ring_max_distance",
metavar="DISTANCE KM",
metavar="DISTANCE",
type=float,
help="Maximum distance for scaling the track length.",
help="Maximum distance for scaling the track lengths (in given units).",
)

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
self._max_distance = abs(args.circular_ring_max_distance)

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 All @@ -84,6 +85,11 @@ def draw(self, dr: svgwrite.Drawing, g: svgwrite.container.Group, size: XY, offs
if self.poster.length_range_by_date is None:
return

if self.poster.units == "imperial":
self._unit = Units().mile
if self._max_distance:
self._max_distance = self._max_distance * self._unit

years = self.poster.years.count()
_, counts = utils.compute_grid(years, size)
if counts is None:
Expand Down Expand Up @@ -194,11 +200,7 @@ def _draw_year(self, dr: svgwrite.Drawing, g: svgwrite.container.Group, size: XY

def _determine_ring_distance(self, max_length: pint.Quantity) -> typing.Optional[pint.Quantity]:
ring_distance = None
if self.poster.units == "metric":
unit = Units().km
else:
unit = Units().mile
for distance in [1.0 * unit, 5.0 * unit, 10.0 * unit, 50.0 * unit]:
for distance in [1.0 * self._unit, 5.0 * self._unit, 10.0 * self._unit, 50.0 * self._unit]:
if max_length < distance:
continue
ring_distance = distance
Expand All @@ -212,12 +214,11 @@ def _draw_rings(
length_range = self.poster.length_range_by_date
if not length_range.is_valid():
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
max_length = max_length.to(self._unit)
ring_distance = self._determine_ring_distance(max_length)
if ring_distance is None:
return
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/github_drawer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2020-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/grid_drawer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Draw a grid poster."""
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/heatmap_drawer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Draw a heatmap poster."""
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/localization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/poster.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Create a poster from track data."""
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/quantity_range.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/timezone_adjuster.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/track.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Create and maintain info about a given activity track (corresponding to one GPX file)."""
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/track_loader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Handle parsing of GPX files and writing/loading of cached data"""


# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/tracks_drawer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Contains the base class TracksDrawer, which other Drawers inherit from."""
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/units.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Assorted utility methods for use in creating posters."""
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/value_range.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Represent a range of numerical values"""
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/xy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Represent x,y coords with properly overloaded operations."""
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion gpxtrackposter/year_range.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Represent a range of years, with ability to update based on a track"""
# Copyright 2016-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2016-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion scripts/bump_year.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright 2018-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2018-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_copyright.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright 2018-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2018-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_readme.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright 2018-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2018-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_timezone_adjuster.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2020-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_track_loader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2020-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2021 Florian Pigorsch & Contributors. All rights reserved.
# Copyright 2018-2022 Florian Pigorsch & Contributors. All rights reserved.
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.
Expand Down

0 comments on commit e8da1e3

Please sign in to comment.