Skip to content

Commit

Permalink
continue addressing pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mezarque committed Jun 11, 2024
1 parent 2d6a87b commit 336a75e
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 77 deletions.
37 changes: 14 additions & 23 deletions arcadia_pycolor/cvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _make_cvd_dict(cvd_type: str, severity: int = 100) -> dict:
return cvd_space


def simulate_color_deficiency(
def simulate_color(
colors: Union[HexCode, list[HexCode]], cvd_type: str = "d", severity: int = 100
) -> Union[HexCode, list[HexCode]]:
"""
Expand Down Expand Up @@ -65,26 +65,20 @@ def simulate_color_deficiency(
return returned_colors


def display_all_color_deficiencies(
colors: Union[HexCode | list[HexCode]], severity: int = 100
) -> None:
def display_all_color(color: HexCode, severity: int = 100) -> None:
"""
Display all color vision deficiency types for a single HexCode or list of HexCodes.
Display all color vision deficiency types for a single HexCode.
Args:
color (HexCode): color to simulate color vision deficiency on.
severity (int): severity of the color vision deficiency, from 0 to 100.
"""
cvd_colors = [colors] + [
simulate_color_deficiency(colors, cvd_type, severity) for cvd_type in CVD_TYPES
]
cvd_colors = [color] + [simulate_color(color, cvd_type, severity) for cvd_type in CVD_TYPES]
for cvd_color in cvd_colors:
print(cvd_color.swatch())


def simulate_palette_deficiency(
palette: Palette, cvd_type: str = "d", severity: int = 100
) -> Palette:
def simulate_palette(palette: Palette, cvd_type: str = "d", severity: int = 100) -> Palette:
"""
Simulates color vision deficiency on a Palette.
Expand All @@ -93,13 +87,13 @@ def simulate_palette_deficiency(
cvd_type (str): 'd' for deuteranomaly, 'p' for protanomaly, and 't' for tritanomaly.
severity (int): severity of the color vision deficiency, from 0 to 100.
"""
cvd_hex_colors = simulate_color_deficiency(palette.colors, cvd_type=cvd_type, severity=severity)
cvd_hex_colors = simulate_color(palette.colors, cvd_type=cvd_type, severity=severity)
cvd_palette = Palette(f"{palette.name}_{cvd_type}", cvd_hex_colors)

return cvd_palette


def display_all_palette_deficiencies(palette: Palette, severity: int = 100) -> None:
def display_all_palette(palette: Palette, severity: int = 100) -> None:
"""
Display all color vision deficiency types for a Palette.
Expand All @@ -108,14 +102,14 @@ def display_all_palette_deficiencies(palette: Palette, severity: int = 100) -> N
severity (int): severity of the color vision deficiency, from 0 to 100.
"""
cvd_palettes = [palette] + [
simulate_palette_deficiency(palette, cvd_type, severity) for cvd_type in CVD_TYPES
simulate_palette(palette, cvd_type, severity) for cvd_type in CVD_TYPES
]
for palette in cvd_palettes:
print(palette.name)
print(palette.swatch())


def simulate_gradient_deficiency(gradient: Gradient, cvd_type="d", severity: int = 100) -> Gradient:
def simulate_gradient(gradient: Gradient, cvd_type="d", severity: int = 100) -> Gradient:
"""
Simulates color vision deficiency on a Gradient.
Expand All @@ -124,15 +118,13 @@ def simulate_gradient_deficiency(gradient: Gradient, cvd_type="d", severity: int
cvd_type (str): 'd' for deuteranomaly, 'p' for protanomaly, and 't' for tritanomaly.
severity (int): severity of the color vision deficiency, from 0 to 100.
"""
cvd_hex_colors = simulate_color_deficiency(
gradient.colors, cvd_type=cvd_type, severity=severity
)
cvd_hex_colors = simulate_color(gradient.colors, cvd_type=cvd_type, severity=severity)
cvd_gradient = Gradient(f"{gradient.name}_{cvd_type}", cvd_hex_colors, gradient.values)

return cvd_gradient


def display_all_gradient_deficiencies(gradient: Gradient, severity: int = 100) -> None:
def display_all_gradient(gradient: Gradient, severity: int = 100) -> None:
"""
Display all color vision deficiency types for a Gradient.
Expand All @@ -141,16 +133,15 @@ def display_all_gradient_deficiencies(gradient: Gradient, severity: int = 100) -
severity (int): severity of the color vision deficiency, from 0 to 100.
"""
cvd_gradients = [gradient] + [
simulate_gradient_deficiency(gradient, cvd_type, severity) for cvd_type in CVD_TYPES
simulate_gradient(gradient, cvd_type, severity) for cvd_type in CVD_TYPES
]
for grad in cvd_gradients:
print(grad.name)
print(grad.swatch())


def simulate_gradient_lightness(gradient: Gradient, severity: int = 100, **kwargs):
def display_all_gradient_lightness(gradient: Gradient, severity: int = 100, **kwargs):
plot_gradient_lightness(
[gradient]
+ [simulate_gradient_deficiency(gradient, cvd_type, severity) for cvd_type in CVD_TYPES],
[gradient] + [simulate_gradient(gradient, cvd_type, severity) for cvd_type in CVD_TYPES],
**kwargs,
)
23 changes: 1 addition & 22 deletions arcadia_pycolor/gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,4 @@
[0.0, 0.21, 0.5, 0.6, 0.81, 1.0],
)


_all_gradients = [
viridis,
magma,
cividis,
reds,
oranges,
yellows,
greens,
teals,
blues,
purples,
magentas,
aegean_amber,
aster_canary,
lime_rose,
seaweed_tangerine,
poppies,
pansies,
dahlias,
lillies,
]
_all_gradients = [obj for obj in globals().values() if isinstance(obj, Gradient)]
15 changes: 1 addition & 14 deletions arcadia_pycolor/palettes.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,4 @@
)
all.name = "All"

_all_palettes = [
core,
neutral,
accent,
light_accent,
accent_expanded,
light_accent_expanded,
accent_ordered,
light_ordered,
accent_all_ordered,
other,
named,
all,
]
_all_palettes = [obj for obj in globals().values() if isinstance(obj, Palette)]
Binary file modified examples/heatmap_setup.pdf
Binary file not shown.
Binary file modified examples/heatmap_style_axis.pdf
Binary file not shown.
Binary file modified examples/scatter_full_small.pdf
Binary file not shown.
Binary file modified examples/scatter_full_wide.pdf
Binary file not shown.
Binary file modified examples/scatter_half_small.pdf
Binary file not shown.
Binary file modified examples/scatter_setup.pdf
Binary file not shown.
Binary file modified examples/scatter_style_axis.pdf
Binary file not shown.
Binary file modified examples/scatter_threeq_small.pdf
Binary file not shown.
Binary file modified examples/scatter_threeq_wide.pdf
Binary file not shown.
Binary file modified examples/violin_setup.pdf
Binary file not shown.
Binary file modified examples/violin_style_axis.pdf
Binary file not shown.
36 changes: 18 additions & 18 deletions usage_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 18,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -824,7 +824,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 19,
"metadata": {},
"outputs": [
{
Expand All @@ -839,7 +839,7 @@
"\u001b[48;2;255;255;0m \u001b[0m\u001b[38;2;255;255;0m viridis_5 #ffff00\u001b[0m"
]
},
"execution_count": 21,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -850,7 +850,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 20,
"metadata": {},
"outputs": [
{
Expand All @@ -865,12 +865,12 @@
}
],
"source": [
"apc.cvd.display_all_color_deficiencies(apc.aegean)"
"apc.cvd.display_all_color(apc.aegean)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 22,
"metadata": {},
"outputs": [
{
Expand All @@ -891,18 +891,18 @@
"\u001b[48;2;255;171;172m \u001b[0m\u001b[38;2;255;171;172m tangerine_t #ffabac\u001b[0m"
]
},
"execution_count": 23,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"apc.cvd.simulate_palette_deficiency(apc.palettes.accent_ordered, \"t\")"
"apc.cvd.simulate_palette(apc.palettes.accent_ordered, \"t\")"
]
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 23,
"metadata": {},
"outputs": [
{
Expand All @@ -921,12 +921,12 @@
}
],
"source": [
"apc.cvd.display_all_palette_deficiencies(apc.palettes.accent_ordered)"
"apc.cvd.display_all_palette(apc.palettes.accent_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 24,
"metadata": {},
"outputs": [
{
Expand All @@ -945,7 +945,7 @@
}
],
"source": [
"apc.cvd.display_all_gradient_deficiencies(apc.gradients.viridis)"
"apc.cvd.display_all_gradient(apc.gradients.viridis)"
]
},
{
Expand All @@ -965,12 +965,12 @@
}
],
"source": [
"apc.cvd.simulate_gradient_lightness(apc.gradients.viridis, figsize=(10, 5))"
"apc.cvd.display_all_gradient_lightness(apc.gradients.viridis, figsize=(10, 5))"
]
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 28,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1010,7 +1010,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 29,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1064,7 +1064,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 30,
"metadata": {},
"outputs": [
{
Expand All @@ -1090,7 +1090,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 31,
"metadata": {},
"outputs": [
{
Expand All @@ -1106,7 +1106,7 @@
"\u001b[48;2;52;30;96m \u001b[0m\u001b[38;2;52;30;96m concord #341E60\u001b[0m 1.0"
]
},
"execution_count": 30,
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
Expand Down

0 comments on commit 336a75e

Please sign in to comment.