improve readability and scaling

Signed-off-by: Ari Archer <ari@ari.lt>
This commit is contained in:
Ari Archer 2024-06-21 21:45:37 +03:00
parent f1c9b1a6c9
commit 28604e768b
No known key found for this signature in database
GPG key ID: A50D5B4B599AF8A2

View file

@ -45,7 +45,7 @@ AUTHORS: t.Tuple[str, ...] = (
)
IGNORE_REPOS: t.Tuple[str, ...] = "dino-kernel", "sysvinit"
COLOUR: str = "#ffa647"
DPI: t.Final[int] = 300
DPI: t.Final[int] = 200
COMMIT_PAGE_LIMIT: t.Final[int] = 5 # Maximum commit pages (similar to UI)
COMMIT_YEARS: t.Final[int] = (
2 # How many years should the commit plot use in your commit history?
@ -180,26 +180,28 @@ def plot_data(
plt.style.use("dark_background")
# -*- Language statistics -*-
print("Plotting languages...")
sorted_languages = sorted(language_stats.items(), key=lambda x: x[1], reverse=True)[
: 7 * LANG_COLS
]
sorted_languages: t.List[t.Tuple[str, int]] = sorted(
language_stats.items(), key=lambda x: x[1], reverse=True
)[: 7 * LANG_COLS]
languages, counts = zip(*sorted_languages)
total = sum(counts)
total: int = sum(counts)
fig_lang, ax_lang = plt.subplots(
figsize=((10 / 3) * LANG_COLS, (2 / 3) * LANG_COLS)
)
fig_lang.patch.set_facecolor("#000000")
fig_lang.patch.set_alpha(0.2)
fig_lang.patch.set_alpha(0.3)
cumulative_counts = np.cumsum([0] + list(counts[:-1]))
cumulative_counts: t.Any = np.cumsum([0] + list(counts[:-1]))
for lang, count, cum_count in zip(languages, counts, cumulative_counts):
color = language_colours.get(lang.lower(), "#CCCCCC")
ax_lang.barh(0, count, color=color, left=cum_count, edgecolor="white")
ax_lang.set_xlim(0, total) # Ensure the x-axis matches the total width of all bars
ax_lang.axis("off")
ax_lang.set_title("Top Programming Languages by Usage", fontsize=14, color=COLOUR)
ax_lang.legend(
@ -221,26 +223,27 @@ def plot_data(
plt.tight_layout()
plt.savefig("languages.png", dpi=DPI)
print("Wrote languages.png")
# -*- Commit statistics -*-
print("Plotting commits...")
two_years_ago = datetime.now() - timedelta(days=(365.25 * COMMIT_YEARS))
filtered_dates = {
two_years_ago: datetime = datetime.now() - timedelta(days=(365.25 * COMMIT_YEARS))
filtered_dates: t.Dict[str, int] = {
date: count
for date, count in commit_activity.items()
if datetime.strptime(date, "%Y-%m-%d") >= two_years_ago
}
dates = sorted(filtered_dates.keys())
counts = [filtered_dates[date] for date in dates]
dates = [np.datetime64(date) for date in dates]
dates: t.List[str] = sorted(filtered_dates.keys())
counts: t.List[int] = [filtered_dates[date] for date in dates]
dates: t.List[np.datetime64] = [np.datetime64(date) for date in dates]
fig_commits, ax_commits = plt.subplots(figsize=(16, 9))
fig_commits.patch.set_facecolor("#000000")
fig_commits.patch.set_alpha(0.2)
fig_commits.patch.set_alpha(0.3)
ax_commits.patch.set_alpha(0.2)
ax_commits.fill_between(dates, counts, color=COLOUR, alpha=0.4)
@ -255,6 +258,7 @@ def plot_data(
plt.gcf().autofmt_xdate()
plt.tight_layout()
plt.savefig("commits.png", dpi=DPI)
print("Wrote commits.png")