Skip to content

Commit

Permalink
add value thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
wspr committed Apr 1, 2024
1 parent b645f7f commit 9b8a783
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions ausankey/ausankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,13 @@ def __init__(
title_font=None,
sort="bottom", # "top", "bottom", "none"
valign="bottom", # "top","center"
value_format=".0f",
value_gap=None,
value_font=None,
value_loc=("right", "left", "left"),
value_format = ".0f",
value_gap = None,
value_font = None,
value_loc=("both", "right", "right"),
value_thresh_val = 0,
value_thresh_sum = 0,
value_thresh_max = 0,
):
self.ax = ax
self.node_width = node_width
Expand Down Expand Up @@ -281,6 +284,9 @@ def __init__(
self.value_gap = label_gap if value_gap is None else value_gap
self.value_font = value_font or {}
self.value_loc = value_loc
self.value_thresh_val = value_thresh_val
self.value_thresh_sum = value_thresh_sum
self.value_thresh_max = value_thresh_max

def setup(self, data):
self.data = data
Expand Down Expand Up @@ -644,10 +650,17 @@ def draw_label(x, y, label, ha):
if self.value_loc[ind] in ("right", "both"):
sides.append(1)
for lr in sides:
val = len_lr[lr]
if (
val < self.value_thresh_val or
val < self.value_thresh_sum * self.weight_sum[ii+lr] or
val < self.value_thresh_max * max(self.data[2 * ii + 1])
):
continue
self.ax.text(
x_lr[lr] + (1 - 2 * lr) * x_value_gap,
bot_lr[lr] + len_lr[lr] / 2,
f"{format(len_lr[lr],self.value_format)}",
f"{format(val,self.value_format)}",
ha=ha[lr],
va="center",
**self.value_font,
Expand Down

0 comments on commit 9b8a783

Please sign in to comment.