Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor shape files #240

Merged
merged 5 commits into from
Nov 25, 2024
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
exclude: (\.(svg|png|pdf)$)|(CODE_OF_CONDUCT.md)

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.1
rev: v0.8.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
Expand All @@ -44,7 +44,7 @@ repos:
files: tests/.*

- repo: https://github.com/tox-dev/pyproject-fmt
rev: v2.4.3
rev: v2.5.0
hooks:
- id: pyproject-fmt
args: [--keep-full-version, --no-print-diff]
12 changes: 8 additions & 4 deletions docs/tutorials/shape-creation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ Register the shape
For the ``data-morph`` CLI to find your shape, you need to register it with the
:class:`.ShapeFactory`:

1. Add your shape class to the appropriate file inside the ``src/data_morph/shapes/``
directory. Note that the filenames correspond to the type of shape (*e.g.*, use
``src/data_morph/shapes/points.py`` for a new shape inheriting from :class:`.PointCollection`).
2. Add an entry to the ``ShapeFactory._SHAPE_MAPPING`` dictionary in
1. Add your shape class to the appropriate module inside the ``src/data_morph/shapes/``
directory. Note that these correspond to the type of shape (*e.g.*, use
``src/data_morph/shapes/points/<your_shape>.py`` for a new shape inheriting from
:class:`.PointCollection`).
2. Add your shape to ``__all__`` in that module's ``__init__.py`` (*e.g.*, use
``src/data_morph/shapes/points/__init__.py`` for a new shape inheriting from
:class:`.PointCollection`).
3. Add an entry to the ``ShapeFactory._SHAPE_MAPPING`` dictionary in
``src/data_morph/shapes/factory.py``.

Test out the shape
Expand Down
69 changes: 46 additions & 23 deletions src/data_morph/shapes/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,31 @@

from ..data.dataset import Dataset
from ..plotting.style import plot_with_custom_style
from . import circles, lines, points, polygons
from .bases.shape import Shape
from .circles import Bullseye, Circle, Rings
from .lines import (
Diamond,
HighLines,
HorizontalLines,
Rectangle,
SlantDownLines,
SlantUpLines,
Star,
VerticalLines,
WideLines,
XLines,
)
from .points import (
Club,
DotsGrid,
DownParabola,
Heart,
LeftParabola,
RightParabola,
Scatter,
Spade,
UpParabola,
)


class ShapeFactory:
Expand All @@ -34,28 +57,28 @@ class ShapeFactory:
"""

_SHAPE_MAPPING: dict = {
'bullseye': circles.Bullseye,
'circle': circles.Circle,
'high_lines': lines.HighLines,
'h_lines': lines.HorizontalLines,
'slant_down': lines.SlantDownLines,
'slant_up': lines.SlantUpLines,
'v_lines': lines.VerticalLines,
'wide_lines': lines.WideLines,
'x': lines.XLines,
'dots': points.DotsGrid,
'down_parab': points.DownParabola,
'heart': points.Heart,
'left_parab': points.LeftParabola,
'scatter': points.Scatter,
'right_parab': points.RightParabola,
'up_parab': points.UpParabola,
'diamond': polygons.Diamond,
'rectangle': polygons.Rectangle,
'rings': circles.Rings,
'star': polygons.Star,
'club': points.Club,
'spade': points.Spade,
'bullseye': Bullseye,
'circle': Circle,
'high_lines': HighLines,
'h_lines': HorizontalLines,
'slant_down': SlantDownLines,
'slant_up': SlantUpLines,
'v_lines': VerticalLines,
'wide_lines': WideLines,
'x': XLines,
'dots': DotsGrid,
'down_parab': DownParabola,
'heart': Heart,
'left_parab': LeftParabola,
'scatter': Scatter,
'right_parab': RightParabola,
'up_parab': UpParabola,
'diamond': Diamond,
'rectangle': Rectangle,
'rings': Rings,
'star': Star,
'club': Club,
'spade': Spade,
}

AVAILABLE_SHAPES: list[str] = sorted(_SHAPE_MAPPING.keys())
Expand Down
268 changes: 0 additions & 268 deletions src/data_morph/shapes/lines.py

This file was deleted.

Loading