Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/jamstats/plots/basic_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from matplotlib.pyplot import Figure
from matplotlib import gridspec

from jamstats.plots.plot_util import build_anonymizer_map, DerbyPlot
from jamstats.plots.plot_util import build_anonymizer_map, DerbyPlot, _color_is_near_black
import traceback


Expand Down Expand Up @@ -279,11 +279,19 @@ def plot(self, derby_game: DerbyGame) -> Figure:
sns.barplot(y="Penalty", x="Count", data=pdf_penalty_counts,
hue="team", ax=ax, palette=team_color_palette)
for i, row in pdf_penalty_counts.iterrows():
offset = -.2 if row["team_number"] == 1 else .2
team_number = row["team_number"]
offset = -.2 if team_number == 1 else .2
#team_color = team_color_palette[row["team_number"] - 1]
team_color = derby_game.team_color_1 if team_number == 1 else derby_game.team_color_2
font_color = "black"
if _color_is_near_black(team_color):
font_color = "white"
ax.text(.5, penalties_inorder.index(row["Penalty"]) + offset,
row["Count"], size="small",
horizontalalignment="center",
verticalalignment="center")
verticalalignment="center",
color=font_color
)
ax.set_title(f"Penalty counts")
ax.set_ylabel("")

Expand Down
19 changes: 19 additions & 0 deletions src/jamstats/plots/plot_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,25 @@ def _color_is_near_white(color) -> bool:
pass
return False

def _color_is_near_black(color) -> bool:
"""Determine whether a color is close to black

Args:
color: color or string

Returns:
bool: whether color is close to white
"""
if type(color) == str:
color = ImageColor.getrgb(color)
try:
if max(color) < 5:
return True
except Exception:
logger.info("Can't determine whether team color is black")
pass
return False

def make_team_color_palette(derby_game: DerbyGame):
# Addressing issue 197: if either team is close to white,
# force dark theme
Expand Down