render_tools.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. """
  2. Chart rendering tools for astro-mcp.
  3. Render visual chart wheels (SVG/PNG/JPG) from calculated chart data.
  4. Combines calculation + rendering in one step.
  5. """
  6. from __future__ import annotations
  7. from typing import Any
  8. from .server import mcp
  9. from .chart_renderer import (
  10. render_natal_wheel,
  11. render_transit_wheel,
  12. render_synastry_wheel,
  13. )
  14. from .chart_tools import (
  15. calculate_natal_chart,
  16. calculate_transit_chart,
  17. calculate_synastry_chart,
  18. calculate_composite_chart,
  19. calculate_davison_chart,
  20. )
  21. from .by_id_tools import (
  22. calculate_natal_chart_by_id,
  23. calculate_transit_chart_by_id,
  24. calculate_synastry_chart_by_id,
  25. calculate_composite_chart_by_id,
  26. calculate_davison_chart_by_id,
  27. )
  28. # ═══════════════════════════════════════════════════════════════════════
  29. # CHART RENDERING TOOLS
  30. # ═══════════════════════════════════════════════════════════════════════
  31. # These tools render visual chart wheels from birth data.
  32. # They combine calculation + rendering in one step.
  33. # For data-only output, use the calculate_* tools instead.
  34. # ═══════════════════════════════════════════════════════════════════════
  35. # ── Shared render options (used by all render_* tools) ────────────────
  36. _RENDER_STYLE_HELP = (
  37. "Chart visual style: 'modern' (clean, minimal), 'traditional' "
  38. "(ornate, classical), or 'minimal' (bare bones)."
  39. )
  40. _RENDER_COLOR_HELP = (
  41. "Color mode: 'color' (full color with element-themed zodiac ring), "
  42. "'bw' (black/white, aspect lines distinguished by style), or "
  43. "'dark' (dark background for web display)."
  44. )
  45. _RENDER_SIZE_HELP = "SVG width/height in pixels (default: 600)."
  46. _RENDER_TABLE_HELP = "Include an aspect table below the wheel."
  47. _RENDER_PLANETS_HELP = "Include a planet data table below the wheel."
  48. _RENDER_HOUSES_HELP = "Include a house cusp table below the wheel."
  49. _RENDER_TITLE_HELP = "Custom chart title. Auto-generated if not provided."
  50. # ── render_natal_chart ────────────────────────────────────────────────
  51. @mcp.tool()
  52. async def render_natal_chart(
  53. # ── Birth data (same as calculate_natal_chart) ──────────────────
  54. birth_datetime: str,
  55. latitude: float,
  56. longitude: float,
  57. elevation: float = 0.0,
  58. house_system: str = "placidus",
  59. orb_limits: dict[str, float] | None = None,
  60. top_n_aspects: int | None = None,
  61. # ── Rendering options ───────────────────────────────────────────
  62. style: str = "modern",
  63. color_mode: str = "color",
  64. size: int = 600,
  65. table_position: str = "none",
  66. include_planets: bool = False,
  67. include_houses: bool = False,
  68. title: str | None = None,
  69. subtitle: str | None = None,
  70. format: str = "svg",
  71. ) -> dict[str, Any]:
  72. """Render a natal chart wheel.
  73. Calculates planetary positions and renders a visual zodiac wheel with
  74. planets, houses, and aspect lines. Output as SVG or raster image (PNG/JPG).
  75. BIRTH DATA (required):
  76. birth_datetime: ISO 8601 datetime with timezone (e.g. "1990-05-15T10:30:00+01:00").
  77. latitude: Birth latitude in decimal degrees (-90 to 90).
  78. longitude: Birth longitude in decimal degrees (-180 to 180).
  79. BIRTH DATA (optional):
  80. elevation: Birth elevation in meters (default: 0).
  81. house_system: "placidus" (default), "equal", or "whole_sign".
  82. orb_limits: Per-aspect orb overrides, e.g. {"conjunction": 10}.
  83. top_n_aspects: Limit aspects to the N tightest by orb.
  84. RENDERING OPTIONS:
  85. style: {_RENDER_STYLE_HELP}
  86. color_mode: {_RENDER_COLOR_HELP}
  87. size: {_RENDER_SIZE_HELP}
  88. table_position: "none" (wheel only), "below" (portrait layout with tables
  89. under the wheel), or "right" (landscape layout with tables to the right).
  90. include_planets: Include a planet data table (requires table_position != "none").
  91. include_houses: Include a house cusp table (requires table_position != "none").
  92. title: Custom chart title. Auto-generated if not provided.
  93. subtitle: Custom subtitle. Auto-generated from birth data if not provided.
  94. format: Output format — "svg" (default), "png", or "jpg".
  95. Returns:
  96. Dict with "content", "format", "content_type", "width", "height",
  97. and "included" (list of what's in the chart).
  98. """
  99. from .chart_renderer import render_natal_wheel
  100. chart_data = await calculate_natal_chart(
  101. birth_datetime=birth_datetime,
  102. latitude=latitude,
  103. longitude=longitude,
  104. elevation=elevation,
  105. house_system=house_system,
  106. orb_limits=orb_limits,
  107. top_n_aspects=top_n_aspects,
  108. )
  109. if "error" in chart_data:
  110. return chart_data
  111. result = render_natal_wheel(
  112. chart_data,
  113. style=style,
  114. color_mode=color_mode,
  115. size=size,
  116. table_position=table_position,
  117. include_planets=include_planets,
  118. include_houses=include_houses,
  119. title=title,
  120. subtitle=subtitle,
  121. format=format,
  122. )
  123. result["included"] = _included_list(table_position, include_planets, include_houses)
  124. return result
  125. # ── render_natal_chart_by_id ──────────────────────────────────────────
  126. @mcp.tool()
  127. async def render_natal_chart_by_id(
  128. # ── Person lookup (same as calculate_natal_chart_by_id) ─────────
  129. person_id: str,
  130. house_system: str = "placidus",
  131. orb_limits: dict[str, float] | None = None,
  132. top_n_aspects: int | None = None,
  133. # ── Rendering options ───────────────────────────────────────────
  134. style: str = "modern",
  135. color_mode: str = "color",
  136. size: int = 600,
  137. table_position: str = "none",
  138. include_planets: bool = False,
  139. include_houses: bool = False,
  140. title: str | None = None,
  141. format: str = "svg",
  142. ) -> dict[str, Any]:
  143. """Render a natal chart wheel for a person from the database.
  144. Looks up birth data by person_id or nickname, calculates the chart,
  145. and renders it as a wheel. Output as SVG or raster image (PNG/JPG).
  146. PERSON LOOKUP (required):
  147. person_id: ID or nickname of a person in the persons database.
  148. PERSON LOOKUP (optional):
  149. house_system: "placidus" (default), "equal", or "whole_sign".
  150. orb_limits: Per-aspect orb overrides.
  151. top_n_aspects: Limit aspects to the N tightest by orb.
  152. RENDERING OPTIONS:
  153. style: {_RENDER_STYLE_HELP}
  154. color_mode: {_RENDER_COLOR_HELP}
  155. size: {_RENDER_SIZE_HELP}
  156. table_position: "none" (wheel only), "below" (portrait), or "right" (landscape).
  157. include_planets: {_RENDER_PLANETS_HELP}
  158. include_houses: {_RENDER_HOUSES_HELP}
  159. title: {_RENDER_TITLE_HELP}
  160. Returns:
  161. Dict with "svg" (SVG string), "format", "width", "height", "included".
  162. """
  163. from .chart_renderer import render_natal_wheel
  164. chart_data = await calculate_natal_chart_by_id(
  165. person_id=person_id,
  166. house_system=house_system,
  167. orb_limits=orb_limits,
  168. top_n_aspects=top_n_aspects,
  169. )
  170. if "error" in chart_data:
  171. return chart_data
  172. result = render_natal_wheel(
  173. chart_data,
  174. style=style,
  175. color_mode=color_mode,
  176. size=size,
  177. table_position=table_position,
  178. include_planets=include_planets,
  179. include_houses=include_houses,
  180. title=title,
  181. format=format,
  182. )
  183. result["included"] = _included_list(table_position, include_planets, include_houses)
  184. return result
  185. # ── render_transit_chart ──────────────────────────────────────────────
  186. @mcp.tool()
  187. async def render_transit_chart(
  188. # ── Birth data + transit date (same as calculate_transit_chart) ─
  189. birth_datetime: str,
  190. transit_datetime: str,
  191. latitude: float,
  192. longitude: float,
  193. transit_latitude: float | None = None,
  194. transit_longitude: float | None = None,
  195. elevation: float = 0.0,
  196. house_system: str = "placidus",
  197. orb_limits: dict[str, float] | None = None,
  198. # ── Rendering options ───────────────────────────────────────────
  199. style: str = "modern",
  200. color_mode: str = "color",
  201. size: int = 600,
  202. title: str | None = None,
  203. format: str = "svg",
  204. ) -> dict[str, Any]:
  205. """Render a transit chart as a bi-wheel (natal inner, transit outer).
  206. Calculates natal and transiting planet positions, then renders a bi-wheel
  207. showing natal planets inside and transiting planets outside, with
  208. transit-to-natal aspect lines. Output as SVG or raster image (PNG/JPG).
  209. BIRTH DATA (required):
  210. birth_datetime: ISO 8601 birth datetime with timezone.
  211. transit_datetime: ISO 8601 transit datetime (the "now" or future date).
  212. latitude: Birth latitude in decimal degrees.
  213. longitude: Birth longitude in decimal degrees.
  214. TRANSIT LOCATION (optional):
  215. transit_latitude: Location latitude for transit calculation. Defaults to birth latitude.
  216. transit_longitude: Location longitude for transit calculation. Defaults to birth longitude.
  217. CHART OPTIONS:
  218. elevation: Birth elevation in meters (default: 0).
  219. house_system: "placidus" (default), "equal", or "whole_sign".
  220. orb_limits: Per-aspect orb overrides.
  221. RENDERING OPTIONS:
  222. style: {_RENDER_STYLE_HELP}
  223. color_mode: {_RENDER_COLOR_HELP}
  224. size: {_RENDER_SIZE_HELP}
  225. title: {_RENDER_TITLE_HELP}
  226. format: Output format — "svg" (default), "png", or "jpg".
  227. Returns:
  228. Dict with "content", "format", "content_type", "width", "height", "included".
  229. """
  230. from .chart_renderer import render_transit_wheel
  231. chart_data = await calculate_transit_chart(
  232. birth_datetime=birth_datetime,
  233. transit_datetime=transit_datetime,
  234. latitude=latitude,
  235. longitude=longitude,
  236. transit_latitude=transit_latitude,
  237. transit_longitude=transit_longitude,
  238. elevation=elevation,
  239. house_system=house_system,
  240. orb_limits=orb_limits,
  241. )
  242. if "error" in chart_data:
  243. return chart_data
  244. result = render_transit_wheel(
  245. chart_data,
  246. style=style,
  247. color_mode=color_mode,
  248. size=size,
  249. title=title,
  250. format=format,
  251. )
  252. result["included"] = ["wheel"]
  253. return result
  254. # ── render_transit_chart_by_id ────────────────────────────────────────
  255. @mcp.tool()
  256. async def render_transit_chart_by_id(
  257. # ── Person lookup + transit date ────────────────────────────────
  258. person_id: str,
  259. transit_datetime: str,
  260. transit_latitude: float | None = None,
  261. transit_longitude: float | None = None,
  262. house_system: str = "placidus",
  263. orb_limits: dict[str, float] | None = None,
  264. # ── Rendering options ───────────────────────────────────────────
  265. style: str = "modern",
  266. color_mode: str = "color",
  267. size: int = 600,
  268. title: str | None = None,
  269. format: str = "svg",
  270. ) -> dict[str, Any]:
  271. """Render a transit bi-wheel for a person from the database.
  272. Looks up birth data by person_id, calculates transits for the given
  273. date, and renders a bi-wheel chart. Output as SVG or raster image (PNG/JPG).
  274. PERSON LOOKUP (required):
  275. person_id: ID or nickname of a person in the persons database.
  276. transit_datetime: ISO 8601 transit datetime.
  277. TRANSIT LOCATION (optional):
  278. transit_latitude: Location latitude. Defaults to birth latitude.
  279. transit_longitude: Location longitude. Defaults to birth longitude.
  280. CHART OPTIONS:
  281. house_system: "placidus" (default), "equal", or "whole_sign".
  282. orb_limits: Per-aspect orb overrides.
  283. RENDERING OPTIONS:
  284. style: {_RENDER_STYLE_HELP}
  285. color_mode: {_RENDER_COLOR_HELP}
  286. size: {_RENDER_SIZE_HELP}
  287. title: {_RENDER_TITLE_HELP}
  288. Returns:
  289. Dict with "svg", "format", "width", "height", "included".
  290. """
  291. from .chart_renderer import render_transit_wheel
  292. chart_data = await calculate_transit_chart_by_id(
  293. person_id=person_id,
  294. transit_datetime=transit_datetime,
  295. transit_latitude=transit_latitude,
  296. transit_longitude=transit_longitude,
  297. house_system=house_system,
  298. orb_limits=orb_limits,
  299. )
  300. if "error" in chart_data:
  301. return chart_data
  302. result = render_transit_wheel(
  303. chart_data,
  304. style=style,
  305. color_mode=color_mode,
  306. size=size,
  307. title=title,
  308. format=format,
  309. )
  310. result["included"] = ["wheel"]
  311. return result
  312. # ── render_synastry_chart ─────────────────────────────────────────────
  313. @mcp.tool()
  314. async def render_synastry_chart(
  315. # ── Two people's birth data (same as calculate_synastry_chart) ──
  316. person1_datetime: str,
  317. person1_latitude: float,
  318. person1_longitude: float,
  319. person2_datetime: str,
  320. person2_latitude: float,
  321. person2_longitude: float,
  322. elevation: float = 0.0,
  323. house_system: str = "placidus",
  324. orb_limits: dict[str, float] | None = None,
  325. top_n_aspects: int | None = None,
  326. # ── Rendering options ───────────────────────────────────────────
  327. style: str = "modern",
  328. color_mode: str = "color",
  329. size: int = 800,
  330. title: str | None = None,
  331. format: str = "svg",
  332. ) -> dict[str, Any]:
  333. """Render a synastry (relationship) chart with two side-by-side wheels.
  334. Calculates both natal charts and renders them side by side with
  335. interaspect lines between the two charts. Output as SVG or raster image (PNG/JPG).
  336. PERSON 1 (required):
  337. person1_datetime: ISO 8601 birth datetime with timezone.
  338. person1_latitude: Birth latitude in decimal degrees.
  339. person1_longitude: Birth longitude in decimal degrees.
  340. PERSON 2 (required):
  341. person2_datetime: ISO 8601 birth datetime with timezone.
  342. person2_latitude: Birth latitude in decimal degrees.
  343. person2_longitude: Birth longitude in decimal degrees.
  344. CHART OPTIONS:
  345. elevation: Birth elevation in meters (default: 0).
  346. house_system: "placidus" (default), "equal", or "whole_sign".
  347. orb_limits: Per-aspect orb overrides.
  348. top_n_aspects: Limit interaspects to the N tightest by orb.
  349. RENDERING OPTIONS:
  350. style: {_RENDER_STYLE_HELP}
  351. color_mode: {_RENDER_COLOR_HELP}
  352. size: {_RENDER_SIZE_HELP}
  353. title: {_RENDER_TITLE_HELP}
  354. Returns:
  355. Dict with "svg", "format", "width", "height", "included".
  356. """
  357. from .chart_renderer import render_synastry_wheel
  358. chart_data = await calculate_synastry_chart(
  359. person1_datetime=person1_datetime,
  360. person1_latitude=person1_latitude,
  361. person1_longitude=person1_longitude,
  362. person2_datetime=person2_datetime,
  363. person2_latitude=person2_latitude,
  364. person2_longitude=person2_longitude,
  365. elevation=elevation,
  366. house_system=house_system,
  367. orb_limits=orb_limits,
  368. top_n_aspects=top_n_aspects,
  369. )
  370. if "error" in chart_data:
  371. return chart_data
  372. result = render_synastry_wheel(
  373. chart_data,
  374. style=style,
  375. color_mode=color_mode,
  376. size=size,
  377. title=title,
  378. format=format,
  379. )
  380. result["included"] = ["wheel"]
  381. return result
  382. # ── render_synastry_chart_by_id ───────────────────────────────────────
  383. @mcp.tool()
  384. async def render_synastry_chart_by_id(
  385. # ── Two person IDs ──────────────────────────────────────────────
  386. person1_id: str,
  387. person2_id: str,
  388. house_system: str = "placidus",
  389. orb_limits: dict[str, float] | None = None,
  390. top_n_aspects: int | None = None,
  391. # ── Rendering options ───────────────────────────────────────────
  392. style: str = "modern",
  393. color_mode: str = "color",
  394. size: int = 800,
  395. title: str | None = None,
  396. format: str = "svg",
  397. ) -> dict[str, Any]:
  398. """Render a synastry chart for two people from the database.
  399. Looks up both persons by ID or nickname, calculates their synastry,
  400. and renders side-by-side natal wheels with interaspect lines.
  401. Output as SVG or raster image (PNG/JPG).
  402. PERSON LOOKUP (required):
  403. person1_id: ID or nickname of person 1 in the persons database.
  404. person2_id: ID or nickname of person 2 in the persons database.
  405. CHART OPTIONS:
  406. house_system: "placidus" (default), "equal", or "whole_sign".
  407. orb_limits: Per-aspect orb overrides.
  408. top_n_aspects: Limit interaspects to the N tightest by orb.
  409. RENDERING OPTIONS:
  410. style: {_RENDER_STYLE_HELP}
  411. color_mode: {_RENDER_COLOR_HELP}
  412. size: {_RENDER_SIZE_HELP}
  413. title: {_RENDER_TITLE_HELP}
  414. Returns:
  415. Dict with "svg", "format", "width", "height", "included".
  416. """
  417. from .chart_renderer import render_synastry_wheel
  418. chart_data = await calculate_synastry_chart_by_id(
  419. person1_id=person1_id,
  420. person2_id=person2_id,
  421. house_system=house_system,
  422. orb_limits=orb_limits,
  423. top_n_aspects=top_n_aspects,
  424. )
  425. if "error" in chart_data:
  426. return chart_data
  427. result = render_synastry_wheel(
  428. chart_data,
  429. style=style,
  430. color_mode=color_mode,
  431. size=size,
  432. title=title,
  433. format=format,
  434. )
  435. result["included"] = ["wheel"]
  436. return result
  437. # ── render_composite_chart ────────────────────────────────────────────
  438. @mcp.tool()
  439. async def render_composite_chart(
  440. # ── Two people's birth data (same as calculate_composite_chart) ─
  441. person1_datetime: str,
  442. person1_latitude: float,
  443. person1_longitude: float,
  444. person2_datetime: str,
  445. person2_latitude: float,
  446. person2_longitude: float,
  447. elevation: float = 0.0,
  448. house_system: str = "placidus",
  449. orb_limits: dict[str, float] | None = None,
  450. # ── Rendering options ───────────────────────────────────────────
  451. style: str = "modern",
  452. color_mode: str = "color",
  453. size: int = 600,
  454. table_position: str = "none",
  455. include_planets: bool = False,
  456. include_houses: bool = False,
  457. title: str | None = None,
  458. format: str = "svg",
  459. ) -> dict[str, Any]:
  460. """Render a composite chart (midpoint method) as a single wheel.
  461. Calculates the composite chart from two people's birth data and renders
  462. it as a standard natal-style wheel representing the relationship.
  463. Output as SVG or raster image (PNG/JPG).
  464. PERSON 1 (required):
  465. person1_datetime: ISO 8601 birth datetime with timezone.
  466. person1_latitude: Birth latitude in decimal degrees.
  467. person1_longitude: Birth longitude in decimal degrees.
  468. PERSON 2 (required):
  469. person2_datetime: ISO 8601 birth datetime with timezone.
  470. person2_latitude: Birth latitude in decimal degrees.
  471. person2_longitude: Birth longitude in decimal degrees.
  472. CHART OPTIONS:
  473. elevation: Birth elevation in meters (default: 0).
  474. house_system: "placidus" (default), "equal", or "whole_sign".
  475. orb_limits: Per-aspect orb overrides.
  476. RENDERING OPTIONS:
  477. style: {_RENDER_STYLE_HELP}
  478. color_mode: {_RENDER_COLOR_HELP}
  479. size: {_RENDER_SIZE_HELP}
  480. table_position: "none" (wheel only), "below" (portrait), or "right" (landscape).
  481. include_planets: {_RENDER_PLANETS_HELP}
  482. include_houses: {_RENDER_HOUSES_HELP}
  483. title: {_RENDER_TITLE_HELP}
  484. Returns:
  485. Dict with "svg", "format", "width", "height", "included".
  486. """
  487. from .chart_renderer import render_natal_wheel
  488. chart_data = await calculate_composite_chart(
  489. person1_datetime=person1_datetime,
  490. person1_latitude=person1_latitude,
  491. person1_longitude=person1_longitude,
  492. person2_datetime=person2_datetime,
  493. person2_latitude=person2_latitude,
  494. person2_longitude=person2_longitude,
  495. elevation=elevation,
  496. house_system=house_system,
  497. orb_limits=orb_limits,
  498. )
  499. if "error" in chart_data:
  500. return chart_data
  501. result = render_natal_wheel(
  502. chart_data,
  503. style=style,
  504. color_mode=color_mode,
  505. size=size,
  506. table_position=table_position,
  507. include_planets=include_planets,
  508. include_houses=include_houses,
  509. title=title,
  510. format=format,
  511. )
  512. result["included"] = _included_list(table_position, include_planets, include_houses)
  513. return result
  514. # ── render_composite_chart_by_id ──────────────────────────────────────
  515. @mcp.tool()
  516. async def render_composite_chart_by_id(
  517. # ── Two person IDs ──────────────────────────────────────────────
  518. person1_id: str,
  519. person2_id: str,
  520. house_system: str = "placidus",
  521. orb_limits: dict[str, float] | None = None,
  522. # ── Rendering options ───────────────────────────────────────────
  523. style: str = "modern",
  524. color_mode: str = "color",
  525. size: int = 600,
  526. table_position: str = "none",
  527. include_planets: bool = False,
  528. include_houses: bool = False,
  529. title: str | None = None,
  530. format: str = "svg",
  531. ) -> dict[str, Any]:
  532. """Render a composite chart for two people from the database.
  533. Looks up both persons by ID, calculates the composite chart, and
  534. renders it as a single natal-style wheel. Output as SVG or raster image (PNG/JPG).
  535. PERSON LOOKUP (required):
  536. person1_id: ID or nickname of person 1 in the persons database.
  537. person2_id: ID or nickname of person 2 in the persons database.
  538. CHART OPTIONS:
  539. house_system: "placidus" (default), "equal", or "whole_sign".
  540. orb_limits: Per-aspect orb overrides.
  541. RENDERING OPTIONS:
  542. style: {_RENDER_STYLE_HELP}
  543. color_mode: {_RENDER_COLOR_HELP}
  544. size: {_RENDER_SIZE_HELP}
  545. table_position: "none" (wheel only), "below" (portrait), or "right" (landscape).
  546. include_planets: {_RENDER_PLANETS_HELP}
  547. include_houses: {_RENDER_HOUSES_HELP}
  548. title: {_RENDER_TITLE_HELP}
  549. format: Output format — "svg" (default), "png", or "jpg".
  550. Returns:
  551. Dict with "content", "format", "content_type", "width", "height", "included".
  552. """
  553. from .chart_renderer import render_natal_wheel
  554. chart_data = await calculate_composite_chart_by_id(
  555. person1_id=person1_id,
  556. person2_id=person2_id,
  557. house_system=house_system,
  558. orb_limits=orb_limits,
  559. )
  560. if "error" in chart_data:
  561. return chart_data
  562. result = render_natal_wheel(
  563. chart_data,
  564. style=style,
  565. color_mode=color_mode,
  566. size=size,
  567. table_position=table_position,
  568. include_planets=include_planets,
  569. include_houses=include_houses,
  570. title=title,
  571. format=format,
  572. )
  573. result["included"] = _included_list(table_position, include_planets, include_houses)
  574. return result
  575. # ── render_davison_chart ──────────────────────────────────────────────
  576. @mcp.tool()
  577. async def render_davison_chart(
  578. # ── Two people's birth data (same as calculate_davison_chart) ───
  579. person1_datetime: str,
  580. person1_latitude: float,
  581. person1_longitude: float,
  582. person2_datetime: str,
  583. person2_latitude: float,
  584. person2_longitude: float,
  585. elevation: float = 0.0,
  586. house_system: str = "placidus",
  587. orb_limits: dict[str, float] | None = None,
  588. # ── Rendering options ───────────────────────────────────────────
  589. style: str = "modern",
  590. color_mode: str = "color",
  591. size: int = 600,
  592. table_position: str = "none",
  593. include_planets: bool = False,
  594. include_houses: bool = False,
  595. title: str | None = None,
  596. format: str = "svg",
  597. ) -> dict[str, Any]:
  598. """Render a Davison chart (midpoint in time and space) as a single wheel.
  599. Calculates the Davison chart from two people's birth data and renders
  600. it as a standard natal-style wheel. Output as SVG or raster image (PNG/JPG).
  601. PERSON 1 (required):
  602. person1_datetime: ISO 8601 birth datetime with timezone.
  603. person1_latitude: Birth latitude in decimal degrees.
  604. person1_longitude: Birth longitude in decimal degrees.
  605. PERSON 2 (required):
  606. person2_datetime: ISO 8601 birth datetime with timezone.
  607. person2_latitude: Birth latitude in decimal degrees.
  608. person2_longitude: Birth longitude in decimal degrees.
  609. CHART OPTIONS:
  610. elevation: Birth elevation in meters (default: 0).
  611. house_system: "placidus" (default), "equal", or "whole_sign".
  612. orb_limits: Per-aspect orb overrides.
  613. RENDERING OPTIONS:
  614. style: {_RENDER_STYLE_HELP}
  615. color_mode: {_RENDER_COLOR_HELP}
  616. size: {_RENDER_SIZE_HELP}
  617. table_position: "none" (wheel only), "below" (portrait), or "right" (landscape).
  618. include_planets: {_RENDER_PLANETS_HELP}
  619. include_houses: {_RENDER_HOUSES_HELP}
  620. title: {_RENDER_TITLE_HELP}
  621. Returns:
  622. Dict with "svg", "format", "width", "height", "included".
  623. """
  624. from .chart_renderer import render_natal_wheel
  625. chart_data = await calculate_davison_chart(
  626. person1_datetime=person1_datetime,
  627. person1_latitude=person1_latitude,
  628. person1_longitude=person1_longitude,
  629. person2_datetime=person2_datetime,
  630. person2_latitude=person2_latitude,
  631. person2_longitude=person2_longitude,
  632. elevation=elevation,
  633. house_system=house_system,
  634. orb_limits=orb_limits,
  635. )
  636. if "error" in chart_data:
  637. return chart_data
  638. result = render_natal_wheel(
  639. chart_data,
  640. style=style,
  641. color_mode=color_mode,
  642. size=size,
  643. table_position=table_position,
  644. include_planets=include_planets,
  645. include_houses=include_houses,
  646. title=title,
  647. format=format,
  648. )
  649. result["included"] = _included_list(table_position, include_planets, include_houses)
  650. return result
  651. # ── render_davison_chart_by_id ────────────────────────────────────────
  652. @mcp.tool()
  653. async def render_davison_chart_by_id(
  654. # ── Two person IDs ──────────────────────────────────────────────
  655. person1_id: str,
  656. person2_id: str,
  657. house_system: str = "placidus",
  658. orb_limits: dict[str, float] | None = None,
  659. # ── Rendering options ───────────────────────────────────────────
  660. style: str = "modern",
  661. color_mode: str = "color",
  662. size: int = 600,
  663. table_position: str = "none",
  664. include_planets: bool = False,
  665. include_houses: bool = False,
  666. title: str | None = None,
  667. format: str = "svg",
  668. ) -> dict[str, Any]:
  669. """Render a Davison chart for two people from the database.
  670. Looks up both persons by ID, calculates the Davison chart, and
  671. renders it as a single natal-style wheel. Output as SVG or raster image.
  672. PERSON LOOKUP (required):
  673. person1_id: ID or nickname of person 1 in the persons database.
  674. person2_id: ID or nickname of person 2 in the persons database.
  675. CHART OPTIONS:
  676. house_system: "placidus" (default), "equal", or "whole_sign".
  677. orb_limits: Per-aspect orb overrides.
  678. RENDERING OPTIONS:
  679. style: {_RENDER_STYLE_HELP}
  680. color_mode: {_RENDER_COLOR_HELP}
  681. size: {_RENDER_SIZE_HELP}
  682. table_position: "none" (wheel only), "below" (portrait), or "right" (landscape).
  683. include_planets: {_RENDER_PLANETS_HELP}
  684. include_houses: {_RENDER_HOUSES_HELP}
  685. title: {_RENDER_TITLE_HELP}
  686. Returns:
  687. Dict with "svg", "format", "width", "height", "included".
  688. """
  689. from .chart_renderer import render_natal_wheel
  690. chart_data = await calculate_davison_chart_by_id(
  691. person1_id=person1_id,
  692. person2_id=person2_id,
  693. house_system=house_system,
  694. orb_limits=orb_limits,
  695. )
  696. if "error" in chart_data:
  697. return chart_data
  698. result = render_natal_wheel(
  699. chart_data,
  700. style=style,
  701. color_mode=color_mode,
  702. size=size,
  703. table_position=table_position,
  704. include_planets=include_planets,
  705. include_houses=include_houses,
  706. title=title,
  707. format=format,
  708. )
  709. result["included"] = _included_list(table_position, include_planets, include_houses)
  710. return result
  711. # ── Helper ────────────────────────────────────────────────────────────
  712. def _included_list(table_position: str, planets: bool, houses: bool) -> list[str]:
  713. result = ["wheel"]
  714. if table_position in ("below", "right"):
  715. if planets:
  716. result.append("planet_table")
  717. if houses:
  718. result.append("house_table")
  719. return result