Skip to content

Commit

Permalink
change svg template lib to tagit
Browse files Browse the repository at this point in the history
  • Loading branch information
hoishing committed Oct 6, 2024
1 parent 50126c2 commit c992845
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 44 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ read the [docs] for complete references
## Tech Stack
- [ptag] for creating and manipulating XML(SVG)
- [tagit] for creating and manipulating SVG
- [pyswisseph] python extension to the Swiss Ephemeris
- [mkdocs-material] for docs site generation
Expand All @@ -363,7 +363,7 @@ read the [docs] for complete references
[MIT-badge]: https://img.shields.io/github/license/hoishing/natal
[MIT-url]: https://opensource.org/licenses/MIT
[mkdocs-material]: https://github.com/squidfunk/mkdocs-material
[ptag]: https://github.com/hoishing/ptag
[tagit]: https://github.com/hoishing/tagit
[pypi-badge]: https://img.shields.io/pypi/v/natal
[pypi-url]: https://pypi.org/project/natal
[pyswisseph]: https://github.com/astrorigin/pyswisseph
47 changes: 24 additions & 23 deletions natal/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from natal.const import SIGN_MEMBERS
from natal.data import Data
from natal.utils import DotDict
from ptag import Tag, circle, line, path, svg, text
from tagit import circle, line, path, svg, text


class Chart(DotDict):
Expand Down Expand Up @@ -56,16 +56,15 @@ def __init__(
self.ring_thickness = self.max_radius * config.chart.ring_thickness_fraction
self.font_size = self.ring_thickness * self.config.chart.font_size_fraction

@property
def svg_root(self) -> Tag:
def svg_root(self, content: str | list[str]) -> str:
"""
Generate an SVG root element with sensible defaults.
Returns:
Tag: An SVG root element.
"""
return svg(
"",
content,
height=self.height,
width=self.width,
# viewbox=None,
Expand All @@ -82,7 +81,7 @@ def sector(
stroke_color: str = "black",
stroke_width: float = 1,
stroke_opacity: float = 1,
) -> Tag:
) -> str:
"""
Create a sector shape in SVG format.
Expand Down Expand Up @@ -126,7 +125,7 @@ def sector(
stroke_opacity=stroke_opacity,
)

def background(self, radius: float, **kwargs) -> Tag:
def background(self, radius: float, **kwargs) -> str:
"""
Create a background circle for the chart.
Expand All @@ -139,7 +138,7 @@ def background(self, radius: float, **kwargs) -> Tag:
"""
return circle(cx=self.cx, cy=self.cy, r=radius, **kwargs)

def sign_wheel(self) -> list[Tag]:
def sign_wheel(self) -> list[str]:
"""
Generate the zodiac sign wheel.
Expand Down Expand Up @@ -184,7 +183,7 @@ def sign_wheel(self) -> list[Tag]:

return wheel

def house_wheel(self) -> list[Tag]:
def house_wheel(self) -> list[str]:
"""
Generate the house wheel.
Expand Down Expand Up @@ -229,7 +228,7 @@ def house_wheel(self) -> list[Tag]:

return wheel

def vertex_line(self) -> list[Tag]:
def vertex_line(self) -> list[str]:
"""
Generate vertex lines for the chart.
Expand Down Expand Up @@ -281,7 +280,7 @@ def vertex_line(self) -> list[Tag]:

return lines

def outer_body_wheel(self) -> list[Tag]:
def outer_body_wheel(self) -> list[str]:
"""
Generate the outer body wheel for single or composite charts.
Expand All @@ -292,7 +291,7 @@ def outer_body_wheel(self) -> list[Tag]:
data = self.data2 or self.data1
return self.body_wheel(radius, data, self.config.chart.outer_min_degree)

def inner_body_wheel(self) -> list[Tag] | None:
def inner_body_wheel(self) -> list[str] | None:
"""
Generate the inner body wheel for composite charts.
Expand All @@ -306,7 +305,7 @@ def inner_body_wheel(self) -> list[Tag] | None:
data = self.data1
return self.body_wheel(radius, data, self.config.chart.inner_min_degree)

def outer_aspect(self) -> list[Tag]:
def outer_aspect(self) -> list[str]:
"""
Generate aspect lines for the outer wheel in single charts.
Expand All @@ -320,7 +319,7 @@ def outer_aspect(self) -> list[Tag]:
aspects = self.data1.aspects
return self.aspect_lines(radius, orb, aspects)

def inner_aspect(self) -> list[Tag]:
def inner_aspect(self) -> list[str]:
"""
Generate aspect lines for the inner wheel in composite charts.
Expand All @@ -345,15 +344,17 @@ def svg(self) -> str:
Returns:
str: SVG content.
"""
with self.svg_root as canvas:
self.sign_wheel()
self.house_wheel()
self.vertex_line()
self.outer_body_wheel()
self.inner_body_wheel()
self.outer_aspect()
self.inner_aspect()
return str(canvas)
return self.svg_root(
[
self.sign_wheel(),
self.house_wheel(),
self.vertex_line(),
self.outer_body_wheel(),
self.inner_body_wheel(),
self.outer_aspect(),
self.inner_aspect(),
]
)

# utils ======================================================

Expand Down Expand Up @@ -518,7 +519,7 @@ def body_wheel(self, wheel_radius: float, data: Data, min_degree: float):
)
return output

def aspect_lines(self, radius: float, orb: Orb, aspects: list[Aspect]) -> list[Tag]:
def aspect_lines(self, radius: float, orb: Orb, aspects: list[Aspect]) -> list[str]:
"""
Draw aspect lines between aspectable celestial bodies.
Expand Down
16 changes: 11 additions & 5 deletions natal/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from math import floor
from natal.classes import Aspect
from natal.data import Data
from ptag import div, h4
from tagit import div, h4
from tabulate import tabulate
from typing import Iterable, Literal, NamedTuple

Expand Down Expand Up @@ -253,7 +253,9 @@ def full_report(self, kind: ReportKind) -> str:
output += self.table_of("hemisphere", kind)
if self.data2:
output += self.table_of("data2_celestial_body", kind)
output += self.table_of("composite_aspect", kind, colalign=("left", "center", "left", "center"))
output += self.table_of(
"composite_aspect", kind, colalign=("left", "center", "left", "center")
)
else:
output += self.table_of("aspect", kind)
output += self.table_of("cross_ref", kind, tablefmt="rounded_grid")
Expand All @@ -280,15 +282,19 @@ def table_of(
base_option = dict(headers="firstrow")

if kind == "ascii":
options = base_option | {"tablefmt": "github", "numalign": "center"} | ascii_options
options = (
base_option
| {"tablefmt": "github", "numalign": "center"}
| ascii_options
)
output = f"# {stat.title}\n\n"
output += tabulate(stat.grid, **options)
output += "\n\n\n"
return output
elif kind == "html":
options = base_option | {"tablefmt": "html"}
output = div(h4(stat.title), class_=f"tabulate {fn_name}")
output.add(tabulate(stat.grid, **options))
tb = tabulate(stat.grid, **options)
output = div([h4(stat.title), tb], class_=f"tabulate {fn_name}")
return str(output)


Expand Down
13 changes: 1 addition & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "natal"
version = "0.1.2"
version = "0.2.0"
description = "create SVG natal chart in python with ease"
license = "MIT"
repository = "https://github.com/hoishing/natal"
Expand All @@ -18,7 +18,6 @@ pandas = "^2.2.2"
tabulate2 = { extras = ["widechars"], version = "^1.9.0" }
darkdetect = "^0.8.0"
tagit = "^0.6.1"
ptag = "^0.2.1"

[tool.poetry.group.dev]
optional = true
Expand Down

0 comments on commit c992845

Please sign in to comment.