Skip to content

Commit

Permalink
Merge pull request #54 from geoneric/gh52
Browse files Browse the repository at this point in the history
Support separate arguments for vertical and horizontal spacing in metro map
  • Loading branch information
kordejong authored Dec 20, 2024
2 parents 558ac0e + d4cbeca commit d9185fd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
26 changes: 22 additions & 4 deletions source/package/adaptation_pathways/cli/plot_pathway_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ def plot_map(
return 0


def parse_spread(spread: str) -> tuple[float, float]:
spreads = spread.split(",")

if len(spreads) == 1:
result = float(spreads[0]), float(spreads[0])
else:
assert (
len(spreads) == 2
), "Pass in a single floating point value, or two separated by a comma"
result = float(spreads[0]), float(spreads[1])

return result


def main() -> int:
command = os.path.basename(sys.argv[0])
usage = f"""\
Expand All @@ -78,9 +92,13 @@ def main() -> int:
bit beyond the actual point
--show_legend Show legend
--spread=<spread> Separate overlapping lines by a percentage [0, 1] of
the range passed in. A value of 0.01 means 1% of the
range of x-coordinates. Passing in a value > 0.02 is
likely not useful. [default: 0]
the data range. A value of 0.01 means 1% of the
range. Passing in a value > 0.02 is likely not useful.
Pass in a tuple of hspread,vspread to separate between
horizontal and vertical spread. Horizontal spread is
about the separation of vertical lines (transitions).
Vertical spread is about horizontal lines (actions).
[default: 0]
--title=<title> Title
--x_label=<label> Label of x-axis
Expand All @@ -100,7 +118,7 @@ def main() -> int:
x_label = arguments["--x_label"] if arguments["--x_label"] is not None else ""
show_legend = arguments["--show_legend"]
overshoot = arguments["--overshoot"]
overlapping_lines_spread = float(arguments["--spread"])
overlapping_lines_spread: tuple[float, float] = parse_spread(arguments["--spread"])

plot_arguments: dict[str, typing.Any] = {
"title": title,
Expand Down
21 changes: 15 additions & 6 deletions source/package/adaptation_pathways/plot/pathway_map/classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def _distribute_vertically(
def _layout(
pathway_map: PathwayMap,
*,
overlapping_lines_spread: float,
overlapping_lines_spread: float | tuple[float, float],
) -> tuple[dict[ActionBegin | ActionEnd, np.ndarray], dict[str, float]]:
"""
Layout that replicates the pathway map layout of the original (pre-2024) pathway generator
Expand Down Expand Up @@ -610,11 +610,18 @@ def _layout(
pathway_map, root_action_begin, position_by_node
)

if overlapping_lines_spread > 0:
_spread_horizontally(
pathway_map, position_by_node, overlapping_lines_spread
if not isinstance(overlapping_lines_spread, tuple):
overlapping_lines_spread = (
overlapping_lines_spread,
overlapping_lines_spread,
)
_spread_vertically(pathway_map, position_by_node, overlapping_lines_spread)

horizontal_spread, vertical_spread = overlapping_lines_spread

if horizontal_spread > 0:
_spread_horizontally(pathway_map, position_by_node, horizontal_spread)
if vertical_spread > 0:
_spread_vertically(pathway_map, position_by_node, vertical_spread)

return position_by_node, y_coordinate_by_action_name

Expand All @@ -633,7 +640,9 @@ def plot(
if legend_arguments is None:
legend_arguments = {}

overlapping_lines_spread: float = arguments.get("overlapping_lines_spread", 0)
overlapping_lines_spread: tuple[float, float] = arguments.get(
"overlapping_lines_spread", (0, 0)
)

layout, y_coordinate_by_action_name = _layout(
pathway_map, overlapping_lines_spread=overlapping_lines_spread
Expand Down

0 comments on commit d9185fd

Please sign in to comment.