Skip to content

Commit 647a5f4

Browse files
Merge pull request #4 from AndreWohnsland/dev
Interactive add fix
2 parents f5c5276 + e226ebe commit 647a5f4

8 files changed

Lines changed: 43 additions & 20 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ If you want to have a complete walkthrough, you can have a look at the [usage do
5656

5757
Here you can see an example of the generated skill plot:
5858

59-
![skillist](https://github.com/AndreWohnsland/skillplotter/blob/master/docs/skills_example.png?raw=true)
59+
![skillist](https://github.com/AndreWohnsland/skillplotter/blob/master/docs/img/skills_example.png?raw=true)

docs/img/skills_example.png

47.6 KB
Loading

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ Here you will find everything to get started!
1717

1818
A small example:
1919

20-
![skillist](skills_example.png "your skillist")
20+
![skillist](img/skills_example.png "your skillist")

docs/skills_example.png

-36.8 KB
Binary file not shown.

docs/usage.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
In this section, you will get a brief introduction to the usage of the package.
44
If you want to have deeper insight into the functionality of the functions, you can always use the `--help` flag.
55

6-
!!! note
6+
!!! note "Easy Start"
77
This package is quite flexible, but the base case is quite easy.
88
So if you want a fast test, use `skill-plotter add` and then `skill-plotter` to see first results.
99

@@ -145,6 +145,10 @@ skill-plotter -c
145145
This will group the skills by your defined categories, as well the skills will be sorted within the category by decreasing level.
146146
If the default category exist, skills within this category will be shown first.
147147

148+
!!! tip "Non-Alphabetical Order"
149+
You can also use numbers for your categories to order them by increasing number.
150+
This is useful if you want a specific, non-alphabetical order of the categories.
151+
148152
This will use the skill group `group1` to plot the skills.
149153

150154
### Defining the Output File
@@ -168,6 +172,7 @@ Some options are:
168172
- `--bar-color`: The color of the bars in the plot
169173
- `--bg-color`: The color of the background bars in the plot
170174
- `--font-color`: The color of the font in the plot
175+
- `--canvas-color`: The color behind the plot
171176

172177
You can experiment with those values and find the best fit for you.
173178
I recommend using hex color codes for the colors.

skill_plotter/main.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ def main(
3838
background_height: Annotated[
3939
float, typer.Option("--bg-height", help="Height of the bars background", min=0, max=1)
4040
] = 0.7,
41-
bar_color: Annotated[str, typer.Option("--bar-color", help="Color of the bar", min=0, max=1)] = BLUE,
42-
background_color: Annotated[
43-
str, typer.Option("--bg-color", help="Color of the bars background", min=0, max=1)
44-
] = DARK_GRAY,
45-
font_color: Annotated[str, typer.Option("--font-color", help="Color of the font", min=0, max=1)] = DARK_GRAY,
41+
bar_color: Annotated[str, typer.Option("--bar-color", help="Color of the bar")] = BLUE,
42+
background_color: Annotated[str, typer.Option("--bg-color", help="Color of the bars background")] = DARK_GRAY,
43+
font_color: Annotated[str, typer.Option("--font-color", help="Color of the font")] = DARK_GRAY,
44+
canvas_color: Annotated[Optional[str], typer.Option(help="Color behind the plot")] = None,
4645
version: Annotated[Optional[bool], typer.Option("--version", "-V", callback=version_callback)] = None,
4746
):
4847
"""
@@ -58,11 +57,11 @@ def main(
5857
data = preparator.read_file(skill_group)
5958
if group_categories:
6059
data = preparator.sort_skills_by_category(data)
61-
typer.echo(data)
6260
plot_data = preparator.reduce_data(data)
6361
generate_skill_picture(
6462
plot_data, columns, save_name, file_type, bar_height,
65-
background_height, background_color, bar_color, font_color
63+
background_height, background_color, bar_color, font_color,
64+
canvas_color,
6665
)
6766

6867

skill_plotter/plotter.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import matplotlib.pyplot as plt
22
from matplotlib.axes import Axes
3-
from typing import Union
3+
from typing import Union, Optional
4+
45

56
from .preparator import split_dict_evenly
67

@@ -65,7 +66,6 @@ def generate_diagram(
6566
ax.spines["top"].set_visible(False)
6667
ax.spines["left"].set_visible(False)
6768
ax.spines["right"].set_visible(False)
68-
# plt.setp(ax.get_xticklabels(), color="w", fontsize=8)
6969
ax.get_xaxis().set_visible(False)
7070

7171

@@ -79,6 +79,7 @@ def generate_skill_picture(
7979
background_color: _COLOR = DARK_GRAY,
8080
bar_color: _COLOR = DARK_GRAY,
8181
font_color: _COLOR = BLUE,
82+
canvas_color: Optional[_COLOR] = None,
8283
):
8384
"""Generate a bar diagram for the given skills.
8485
@@ -99,7 +100,7 @@ def generate_skill_picture(
99100
# generate the diagram, splits the values into two lists to plot.
100101
# this should be done in the future over one loop
101102
# the loop decides what to put when and how many columns
102-
_, axes = plt.subplots(1, n_splits, figsize=(10 * n_splits, split_len))
103+
fig, axes = plt.subplots(1, n_splits, figsize=(10 * n_splits, split_len))
103104

104105
# will get an iterable error since when using only one column, axes is not a list
105106
# just put the Axes object into a list to fix this
@@ -108,5 +109,15 @@ def generate_skill_picture(
108109

109110
for ax, skills in zip(axes, split_skills):
110111
generate_diagram(ax, skills, bar_height, background_height, background_color, bar_color, font_color)
112+
# need also to set face color of each axis
113+
if canvas_color is not None:
114+
ax.set_facecolor(canvas_color)
115+
# set the facecolor of the canvas to the given color
116+
extra_args = {}
117+
if canvas_color is not None:
118+
fig.set_facecolor(canvas_color)
119+
# only transparent if there is no canvas color
120+
else:
121+
extra_args["transparent"] = True
111122
plt.tight_layout()
112-
plt.savefig(f"{save_name}.{file_type}", format=file_type, transparent=True)
123+
plt.savefig(f"{save_name}.{file_type}", format=file_type, **extra_args)

skill_plotter/preparator.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def sort_skills_by_category(skills: dict[str, dict[str, Any]]) -> dict[str, dict
5151
return dict(
5252
sorted(
5353
skills.items(),
54-
key=lambda x: (x[1]["category"] != _DEFAULT_CATEGORY, x[1]["category"], x[1]["level"])
54+
key=lambda x: (x[1]["category"] != _DEFAULT_CATEGORY, x[1]["category"], -x[1]["level"])
5555
)
5656
)
5757

@@ -99,21 +99,29 @@ def add_skill(
9999

100100
def interactive_add_skill(
101101
file_name: str = DEFAULT_SKILL_FILE_NAME,
102-
category: Optional[str] = None,
102+
used_category: Optional[str] = None,
103103
):
104104
"""Interactively adds skills to the skill list."""
105105
info_print(f"Using interactive mode, use Ctrl+C to exit, skills will be added to {file_name}")
106-
if category is not None:
107-
info_print(f"Using category {category}")
106+
if used_category is not None:
107+
info_print(f"Using category {used_category}")
108108
while True:
109109
skill = typer.prompt("Enter skill name")
110-
level = typer.prompt("Enter level", type=float)
111-
if category is None:
110+
level = 0
111+
while level <= 0 or level > 10:
112+
level = typer.prompt("Enter level [0-10]", type=float)
113+
if level <= 0 or level > 10:
114+
failure_print("Level must be between 0 and 10 and not 0")
115+
if used_category is None:
112116
category = typer.prompt("Enter category", default=_DEFAULT_CATEGORY)
117+
else:
118+
category = used_category
113119
# this should usually not be happening, but just in case
114120
if not category:
115121
category = _DEFAULT_CATEGORY
116122
add_skill(skill, level, category, file_name)
123+
# need to reset category!
124+
category = None
117125

118126

119127
def remove_skill(skill: str, file_name: str = DEFAULT_SKILL_FILE_NAME):

0 commit comments

Comments
 (0)