Skip to content

Commit

Permalink
Use canonical colors for languages
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 16, 2024
1 parent 4a3e639 commit 66389a6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,34 @@ def setup(app):
try:
langs = linguist(basedir)
labels = [lang[0] for lang in langs]
counts = [countfiles(lang) for lang in labels]
sizes = [lang[1] for lang in langs]
color_map = {
'C': "#555555",
'C++': "#f34b7d",
'C#': "#178600",
'Java': "#b07219",
'JavaScript': "#f1e05a",
'Python': "#3572A5",
'Rust': "#dea584",
'Makefile': "#427819",
}
colors = [color_map[lang] for lang in labels]
_, ax = plt.subplots()
ax.pie(sizes, labels=labels, autopct='%1.1f%%', labeldistance=None, pctdistance=0.85)
ax.pie(sizes, labels=labels, colors=colors, autopct='%1.1f%%', labeldistance=None, pctdistance=0.85)
plt.legend(title='Languages', loc='right', bbox_to_anchor=(1,0.5), bbox_transform=plt.gcf().transFigure)
plt.savefig('languages.svg', transparent=True, bbox_inches='tight')

counts = [countfiles(lang) for lang in labels]
sizes = [float(size) / count for size, count in zip(sizes, counts)]
pairs = sorted(zip(sizes, labels), reverse=True)
labels = [lang[1] for lang in pairs]
sizes = [lang[0] for lang in pairs]
pos = labels.index('Makefile')
labels.pop(pos)
sizes.pop(pos)
colors = [color_map[lang] for lang in labels]
_, ax = plt.subplots()
ax.pie(sizes, labels=labels, autopct='%1.1f%%', labeldistance=None, pctdistance=0.85)
ax.pie(sizes, labels=labels, colors=colors, autopct='%1.1f%%', labeldistance=None, pctdistance=0.85)
plt.legend(title='Languages', loc='right', bbox_to_anchor=(1,0.5), bbox_transform=plt.gcf().transFigure)
plt.savefig('languages-normalized.svg', transparent=True, bbox_inches='tight')
except Exception:
Expand Down

0 comments on commit 66389a6

Please sign in to comment.