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
6 changes: 4 additions & 2 deletions src/jamstats/plots/basic_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ def plot(self, derby_game: DerbyGame) -> Figure:
sns.lineplot(x="prd_jam", y="TotalScore",
data=pdf_jam_data_long[pdf_jam_data_long.team == derby_game.team_1_name],
label=derby_game.team_1_name,
estimator=None, color=team_color_palette[0])
estimator=None, color=team_color_palette[0],
linewidth=5)
sns.lineplot(x="prd_jam", y="TotalScore",
data=pdf_jam_data_long[pdf_jam_data_long.team == derby_game.team_2_name],
label=derby_game.team_2_name,
estimator=None, color=team_color_palette[1])
estimator=None, color=team_color_palette[1],
linewidth=5)

# determine break betwen periods, if any. Draw a line there.
n_periods = len(set(derby_game.pdf_jams_data.PeriodNumber))
Expand Down
27 changes: 27 additions & 0 deletions src/jamstats/plots/plot_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import random
from matplotlib.pyplot import Figure
from pandas.api.types import CategoricalDtype
from PIL import ImageColor

from abc import ABC, abstractmethod

Expand Down Expand Up @@ -99,8 +100,34 @@ def prepare_to_plot(theme:str = DEFAULT_THEME) -> None:
logger.info(f"Using theme {theme}")
sns.set_style(theme)

def _color_is_near_white(color) -> bool:
"""Determine whether a color is close to white

Args:
color: color or string

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

def make_team_color_palette(derby_game: DerbyGame):
# Addressing issue 197: if either team is close to white,
# force dark theme
if (
_color_is_near_white(derby_game.team_color_1) or
_color_is_near_white(derby_game.team_color_2)
):
logger.warning("A team is white, so forcing dark theme.")
sns.set_style("dark")
return sns.color_palette([derby_game.team_color_1, derby_game.team_color_2])


Expand Down