Skip to content

Commit

Permalink
Add tbar, precommit, and cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 committed Oct 17, 2023
1 parent 82fec46 commit 8137ba9
Show file tree
Hide file tree
Showing 8 changed files with 494 additions and 356 deletions.
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
default_stages: [commit]
repos:
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-toml
- id: detect-private-key
- id: end-of-file-fixer
exclude: \.min\.js$
- id: trailing-whitespace
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
hooks:
- id: codespell
additional_dependencies:
- tomli
16 changes: 16 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[flake8]
max-line-length = 88
extend-ignore = E203

[isort]
known_first_party = ahlive
multi_line_output = 3
include_trailing_comma = True
force_grid_wrap = 0
use_parentheses = True
ensure_newline_before_comments = True
line_length = 88

[doc8]
max-line-length = 88
ignore-path = .eggs/
6 changes: 3 additions & 3 deletions tastymap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""colormap palettes for your palate"""

from .models import TastyColorMap, TastyColorBar
from .core import cook_tcmap, pair_tcbar
from .core import cook_tmap, pair_tbar
from .models import TastyBar, TastyMap

__version__ = "0.0.0"

__all__ = ["cook_tcmap", "pair_tcbar", "TastyColorMap", "TastyColorBar"]
__all__ = ["cook_tmap", "pair_tbar", "TastyMap", "TastyBar"]
38 changes: 19 additions & 19 deletions tastymap/core.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

from typing import Any
from collections.abc import Sequence
from typing import Any

from matplotlib.colors import Colormap, LinearSegmentedColormap, ListedColormap

from tastymap.models import ColorModel, TastyColorMap, MatplotlibTastyColorBar
from tastymap.models import ColorModel, MatplotlibTastyBar, TastyMap


def cook_tcmap(
def cook_tmap(
colors_or_cmap: Sequence | str | Colormap,
num_colors: int | None = None,
reverse: bool = False,
Expand All @@ -17,7 +17,7 @@ def cook_tcmap(
under: str | tuple | None = None,
over: str | tuple | None = None,
from_color_model: ColorModel | str | None = None,
) -> TastyColorMap:
) -> TastyMap:
"""Cook a completely new colormap or modify an existing one.
Args:
Expand All @@ -32,21 +32,21 @@ def cook_tcmap(
colors_or_cmap is an Sequence and not hexcodes. Defaults to None.
Returns:
TastyColorMap: A new TastyColorMap instance with the new colormap.
TastyMap: A new TastyMap instance with the new colormap.
"""
if isinstance(colors_or_cmap, str):
tmap = TastyColorMap.from_str(colors_or_cmap)
tmap = TastyMap.from_str(colors_or_cmap)
elif isinstance(colors_or_cmap, LinearSegmentedColormap):
tmap = TastyColorMap(colors_or_cmap)
tmap = TastyMap(colors_or_cmap)
elif isinstance(colors_or_cmap, ListedColormap):
tmap = TastyColorMap.from_listed_colormap(colors_or_cmap)
tmap = TastyMap.from_listed_colormap(colors_or_cmap)
elif isinstance(colors_or_cmap, Sequence):
if not isinstance(colors_or_cmap[0], str) and from_color_model is None:
raise ValueError(
"Please specify from_color_model to differentiate "
"between RGB and HSV color models."
)
tmap = TastyColorMap.from_list(
tmap = TastyMap.from_list(
colors_or_cmap, color_model=from_color_model or ColorModel.RGB
)
else:
Expand All @@ -71,26 +71,26 @@ def cook_tcmap(
return tmap


def pair_tcbar(
def pair_tbar(
plot: Any,
colors_or_cmap_or_tcmap: (Sequence | str | Colormap | TastyColorMap),
colors_or_cmap_or_tmap: (Sequence | str | Colormap | TastyMap),
bounds: tuple[float, float] | Sequence[float],
labels: list[str] | None = None,
uniform_spacing: bool = True,
**tcbar_kwargs,
**tbar_kwargs,
):
tcmap = colors_or_cmap_or_tcmap
if not isinstance(tcmap, TastyColorMap):
tcmap = cook_tcmap(colors_or_cmap_or_tcmap)
tmap = colors_or_cmap_or_tmap
if not isinstance(tmap, TastyMap):
tmap = cook_tmap(colors_or_cmap_or_tmap)

if hasattr(plot, "axes"):
tcbar = MatplotlibTastyColorBar(
tcmap,
tbar = MatplotlibTastyBar(
tmap,
bounds=bounds,
labels=labels,
uniform_spacing=uniform_spacing,
**tcbar_kwargs,
**tbar_kwargs,
)
else:
raise NotImplementedError("Only matplotlib plots are supported.")
return tcbar.add_to(plot)
return tbar.add_to(plot)
Loading

0 comments on commit 8137ba9

Please sign in to comment.