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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Default configuration:
```json
{
"output_path": "assets/github-stats.svg",
"max_languages": 6,
"max_languages": 8,
"exclude_languages": [],
"theme": {
"background": "#0d1117",
Expand All @@ -175,18 +175,19 @@ Default configuration:

### Number of languages

Display between one and six language entries:
Display between one and eight language entries:

```json
"max_languages": 6
"max_languages": 8
```

Supported values:

```text
1–6
1–8
```

With eight entries, the language legend is displayed in two columns with four rows each.
When more languages exist than the configured limit, the remaining languages are grouped under `Other`.

### Exclude languages
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"output_path": "assets/github-stats.svg",
"max_languages": 6,
"max_languages": 8,
"exclude_languages": [],
"theme": {
"background": "#0d1117",
Expand Down
14 changes: 7 additions & 7 deletions scripts/generate_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
DEFAULT_CONFIG: dict[str, Any] = {
"username": "",
"output_path": "assets/github-stats.svg",
"max_languages": 6,
"max_languages": 8,
"exclude_languages": [],
"theme": {
"background": "#0d1117",
Expand Down Expand Up @@ -422,13 +422,13 @@ def load_config(
]

if (
not isinstance(max_languages, int)
or isinstance(max_languages, bool)
or not 1 <= max_languages <= 6
not isinstance(max_languages, int)
or isinstance(max_languages, bool)
or not 1 <= max_languages <= 8
):
raise ConfigurationError(
"'max_languages' must be an "
"integer from 1 to 6."
"'max_languages' must be an "
"integer from 1 to 8."
)

excluded = config[
Expand Down Expand Up @@ -1196,7 +1196,7 @@ def build_language_svg(
legend_y = (
bar_y
+ 34
+ row * 31
+ row * 26
)

legend.append(
Expand Down
56 changes: 55 additions & 1 deletion tests/test_generate_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,32 @@ def test_load_config_merges_defaults(self) -> None:
"",
)

def test_eight_languages_are_allowed(
self,
) -> None:
with tempfile.TemporaryDirectory() as directory:
path = self.write_config(
directory,
{
"max_languages": 8,
},
)

config = generator.load_config(path)

self.assertEqual(
config["max_languages"],
8,
)

def test_invalid_language_limit_is_rejected(
self,
) -> None:
with tempfile.TemporaryDirectory() as directory:
path = self.write_config(
directory,
{
"max_languages": 7,
"max_languages": 9,
},
)

Expand Down Expand Up @@ -414,6 +432,42 @@ def make_stats(self) -> dict:
],
}

def test_language_legend_supports_eight_entries(
self,
) -> None:
languages = [
{
"name": f"Language {index}",
"percentage": 12.5,
"color": "#58a6ff",
}
for index in range(1, 9)
]

_, legend = generator.build_language_svg(
languages,
bar_x=535,
bar_y=98,
bar_width=405,
bar_height=7,
muted="#8b949e",
)

self.assertEqual(
legend.count("<circle"),
8,
)

self.assertEqual(
legend.count('cx="540"'),
4,
)

self.assertEqual(
legend.count('cx="740"'),
4,
)

def test_svg_contains_expected_metadata(
self,
) -> None:
Expand Down