From c4d06f3e051851f74d500d743ccd02eb91bb82ba Mon Sep 17 00:00:00 2001 From: Jon Grace-Cox <30441316+jongracecox@users.noreply.github.com> Date: Mon, 12 Aug 2019 09:41:50 -0400 Subject: [PATCH] Add extra colors and update docs (#31) * Add a wider set of color names. * Add better documentation in readme to show use of colors and custom colors. * Add example color badges. --- README.md | 53 +++++++++++++++++++++++++++++++++ anybadge.py | 19 ++++++++++-- examples/color_aqua.svg | 23 ++++++++++++++ examples/color_black.svg | 23 ++++++++++++++ examples/color_blue.svg | 23 ++++++++++++++ examples/color_brightred.svg | 23 ++++++++++++++ examples/color_brightyellow.svg | 23 ++++++++++++++ examples/color_fuchsia.svg | 23 ++++++++++++++ examples/color_gray.svg | 23 ++++++++++++++ examples/color_green.svg | 23 ++++++++++++++ examples/color_lightgrey.svg | 23 ++++++++++++++ examples/color_lime.svg | 23 ++++++++++++++ examples/color_maroon.svg | 23 ++++++++++++++ examples/color_navy.svg | 23 ++++++++++++++ examples/color_olive.svg | 23 ++++++++++++++ examples/color_orange.svg | 23 ++++++++++++++ examples/color_purple.svg | 23 ++++++++++++++ examples/color_red.svg | 23 ++++++++++++++ examples/color_silver.svg | 23 ++++++++++++++ examples/color_teal.svg | 23 ++++++++++++++ examples/color_white.svg | 23 ++++++++++++++ examples/color_yellow.svg | 23 ++++++++++++++ examples/color_yellowgreen.svg | 23 ++++++++++++++ 23 files changed, 553 insertions(+), 2 deletions(-) create mode 100644 examples/color_aqua.svg create mode 100644 examples/color_black.svg create mode 100644 examples/color_blue.svg create mode 100644 examples/color_brightred.svg create mode 100644 examples/color_brightyellow.svg create mode 100644 examples/color_fuchsia.svg create mode 100644 examples/color_gray.svg create mode 100644 examples/color_green.svg create mode 100644 examples/color_lightgrey.svg create mode 100644 examples/color_lime.svg create mode 100644 examples/color_maroon.svg create mode 100644 examples/color_navy.svg create mode 100644 examples/color_olive.svg create mode 100644 examples/color_orange.svg create mode 100644 examples/color_purple.svg create mode 100644 examples/color_red.svg create mode 100644 examples/color_silver.svg create mode 100644 examples/color_teal.svg create mode 100644 examples/color_white.svg create mode 100644 examples/color_yellow.svg create mode 100644 examples/color_yellowgreen.svg diff --git a/README.md b/README.md index a03f983..ebcb94c 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,59 @@ For example: anybadge --value=2.22 --file=pylint.svg pylint ``` +### Colors + +Anybadge comes with some pre-defined colors, which can be referred to by name. It also +supports the use of custom colors by using the hex representation of the color. Both color +types can be used in the `default_color`, `text_color` and `thresholds` attributes. + +Here is a Python example showing use of a named color and a custom color. + +```python +import anybadge + +badge = anybadge.Badge(label='custom color', value='teal', default_color='teal', num_padding_chars=1) +badge = anybadge.Badge(label='custom color', value='teal', default_color='#008080', num_padding_chars=1) +``` + +Available named colors are: + +| Color Name | Hex Code | Example | +| ---------- | -------- | ------- | +| aqua | #00FFFF | ![](examples/color_aqua.svg) | +| black | #000000 | ![](examples/color_black.svg) | +| blue | #0000FF | ![](examples/color_blue.svg) | +| brightred | #FF0000 | ![](examples/color_brightred.svg) | +| brightyellow | #FFFF00 | ![](examples/color_brightyellow.svg) | +| fuchsia | #FF00FF | ![](examples/color_fuchsia.svg) | +| gray | #808080 | ![](examples/color_gray.svg) | +| green | #4C1 | ![](examples/color_green.svg) | +| lightgrey | #9F9F9F | ![](examples/color_lightgrey.svg) | +| lime | #00FF00 | ![](examples/color_lime.svg) | +| maroon | #800000 | ![](examples/color_maroon.svg) | +| navy | #000080 | ![](examples/color_navy.svg) | +| olive | #808000 | ![](examples/color_olive.svg) | +| orange | #FE7D37 | ![](examples/color_orange.svg) | +| purple | #800080 | ![](examples/color_purple.svg) | +| red | #E05D44 | ![](examples/color_red.svg) | +| silver | #C0C0C0 | ![](examples/color_silver.svg) | +| teal | #008080 | ![](examples/color_teal.svg) | +| white | #FFFFFF | ![](examples/color_white.svg) | +| yellow | #DFB317 | ![](examples/color_yellow.svg) | +| yellowgreen | #A4A61D | ![](examples/color_yellowgreen.svg) | + +This table was generated with the following code: + +```python +print("""| Color Name | Hex Code | Example | +| ---------- | -------- | ------- |""") +for color, hex in sorted(anybadge.COLORS.items()): + file = 'examples/color_' + color + '.svg' + anybadge.Badge(label='Color', value=color, default_color=color).write_badge(file, overwrite=True) + print("| {color} | {hex} | ![]({file}) |".format(color=color, hex=hex.upper(), file=file)) + +``` + ### Examples #### Pylint using template diff --git a/anybadge.py b/anybadge.py index 5665a92..54695ef 100755 --- a/anybadge.py +++ b/anybadge.py @@ -36,11 +36,26 @@ FONT_WIDTHS = { # Create a dictionary of colors to make selections # easier. COLORS = { + 'white': '#FFFFFF', + 'silver': '#C0C0C0', + 'gray': '#808080', + 'black': '#000000', + 'red': '#e05d44', + 'brightred': '#FF0000', + 'maroon': '#800000', + 'olive': '#808000', + 'lime': '#00FF00', + 'brightyellow': '#FFFF00', + 'yellow': '#dfb317', 'green': '#4c1', 'yellowgreen': '#a4a61d', - 'yellow': '#dfb317', + 'aqua': '#00FFFF', + 'teal': '#008080', + 'blue': '#0000FF', + 'navy': '#000080', + 'fuchsia': '#FF00FF', + 'purple': '#800080', 'orange': '#fe7d37', - 'red': '#e05d44', 'lightgrey': '#9f9f9f', } diff --git a/examples/color_aqua.svg b/examples/color_aqua.svg new file mode 100644 index 0000000..9293cd7 --- /dev/null +++ b/examples/color_aqua.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + aqua + aqua + + \ No newline at end of file diff --git a/examples/color_black.svg b/examples/color_black.svg new file mode 100644 index 0000000..21d92e6 --- /dev/null +++ b/examples/color_black.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + black + black + + \ No newline at end of file diff --git a/examples/color_blue.svg b/examples/color_blue.svg new file mode 100644 index 0000000..8a7e734 --- /dev/null +++ b/examples/color_blue.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + blue + blue + + \ No newline at end of file diff --git a/examples/color_brightred.svg b/examples/color_brightred.svg new file mode 100644 index 0000000..0a34830 --- /dev/null +++ b/examples/color_brightred.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + brightred + brightred + + \ No newline at end of file diff --git a/examples/color_brightyellow.svg b/examples/color_brightyellow.svg new file mode 100644 index 0000000..a3508c5 --- /dev/null +++ b/examples/color_brightyellow.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + brightyellow + brightyellow + + \ No newline at end of file diff --git a/examples/color_fuchsia.svg b/examples/color_fuchsia.svg new file mode 100644 index 0000000..cc5e346 --- /dev/null +++ b/examples/color_fuchsia.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + fuchsia + fuchsia + + \ No newline at end of file diff --git a/examples/color_gray.svg b/examples/color_gray.svg new file mode 100644 index 0000000..5e309a1 --- /dev/null +++ b/examples/color_gray.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + gray + gray + + \ No newline at end of file diff --git a/examples/color_green.svg b/examples/color_green.svg new file mode 100644 index 0000000..fd379ae --- /dev/null +++ b/examples/color_green.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + green + green + + \ No newline at end of file diff --git a/examples/color_lightgrey.svg b/examples/color_lightgrey.svg new file mode 100644 index 0000000..3da03cd --- /dev/null +++ b/examples/color_lightgrey.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + lightgrey + lightgrey + + \ No newline at end of file diff --git a/examples/color_lime.svg b/examples/color_lime.svg new file mode 100644 index 0000000..959b7b9 --- /dev/null +++ b/examples/color_lime.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + lime + lime + + \ No newline at end of file diff --git a/examples/color_maroon.svg b/examples/color_maroon.svg new file mode 100644 index 0000000..73cd8c9 --- /dev/null +++ b/examples/color_maroon.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + maroon + maroon + + \ No newline at end of file diff --git a/examples/color_navy.svg b/examples/color_navy.svg new file mode 100644 index 0000000..1751f54 --- /dev/null +++ b/examples/color_navy.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + navy + navy + + \ No newline at end of file diff --git a/examples/color_olive.svg b/examples/color_olive.svg new file mode 100644 index 0000000..4b0c810 --- /dev/null +++ b/examples/color_olive.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + olive + olive + + \ No newline at end of file diff --git a/examples/color_orange.svg b/examples/color_orange.svg new file mode 100644 index 0000000..17015c4 --- /dev/null +++ b/examples/color_orange.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + orange + orange + + \ No newline at end of file diff --git a/examples/color_purple.svg b/examples/color_purple.svg new file mode 100644 index 0000000..a1f98c8 --- /dev/null +++ b/examples/color_purple.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + purple + purple + + \ No newline at end of file diff --git a/examples/color_red.svg b/examples/color_red.svg new file mode 100644 index 0000000..30b2b32 --- /dev/null +++ b/examples/color_red.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + red + red + + \ No newline at end of file diff --git a/examples/color_silver.svg b/examples/color_silver.svg new file mode 100644 index 0000000..e25bf7d --- /dev/null +++ b/examples/color_silver.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + silver + silver + + \ No newline at end of file diff --git a/examples/color_teal.svg b/examples/color_teal.svg new file mode 100644 index 0000000..095ebed --- /dev/null +++ b/examples/color_teal.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + teal + teal + + \ No newline at end of file diff --git a/examples/color_white.svg b/examples/color_white.svg new file mode 100644 index 0000000..6a79aef --- /dev/null +++ b/examples/color_white.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + white + white + + \ No newline at end of file diff --git a/examples/color_yellow.svg b/examples/color_yellow.svg new file mode 100644 index 0000000..899c2c5 --- /dev/null +++ b/examples/color_yellow.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + yellow + yellow + + \ No newline at end of file diff --git a/examples/color_yellowgreen.svg b/examples/color_yellowgreen.svg new file mode 100644 index 0000000..f60ce56 --- /dev/null +++ b/examples/color_yellowgreen.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Color + Color + + + yellowgreen + yellowgreen + + \ No newline at end of file