Files
sorsfonalak/services/frontend/src/components/ChartTables.tsx
T

288 lines
9.6 KiB
TypeScript
Raw Normal View History

import { ANGLES, ASPECTS, POINTS, SIGNS, dms, orbText, pointName, signName } from "@/lib/astro";
import type { Aspect, Chart, Position } from "@/lib/types";
function Pos({ p }: { p: Position }) {
return (
<>
{dms(p.degree_in_sign_dms)} <span className="sym">{SIGNS[p.sign]?.glyph}</span> {signName(p.sign)}
</>
);
}
/** Sun, Moon and Ascendant signs. */
export function BigThree({ chart }: { chart: Chart }) {
const result = chart.chart;
const timeKnown = chart.highlights.time_known;
const sun = result.points.find((p) => p.id === "sun");
const moon = result.points.find((p) => p.id === "moon");
const asc = result.angles?.ascendant;
return (
<div className="big3">
<div>
<span className="muted">Nap</span>
<span className="glyph sym">{SIGNS[chart.highlights.sun ?? ""]?.glyph}</span>
<strong>{signName(chart.highlights.sun)}</strong>
{sun && <span className="muted num">{dms(sun.degree_in_sign_dms)}</span>}
</div>
<div>
<span className="muted">Hold{!timeKnown && " (közelítő)"}</span>
<span className="glyph sym">{SIGNS[chart.highlights.moon ?? ""]?.glyph}</span>
<strong>{signName(chart.highlights.moon)}</strong>
{moon && <span className="muted num">{dms(moon.degree_in_sign_dms)}</span>}
</div>
<div>
<span className="muted">Aszcendens</span>
{timeKnown ? (
<>
<span className="glyph sym">{SIGNS[chart.highlights.ascendant ?? ""]?.glyph}</span>
<strong>{signName(chart.highlights.ascendant)}</strong>
{typeof asc === "object" && asc && <span className="muted num">{dms(asc.degree_in_sign_dms)}</span>}
</>
) : (
<strong className="muted">–</strong>
)}
</div>
</div>
);
}
// Rows and columns of the aspect grid: the points drawn on the wheel, then the angles.
const GRID_POINTS = [
"sun",
"moon",
"mercury",
"venus",
"mars",
"jupiter",
"saturn",
"uranus",
"neptune",
"pluto",
"north_node",
"lilith",
"chiron",
];
const GRID_ANGLES: [string, string][] = [
["ascendant", "AC"],
["midheaven", "MC"],
];
/** The aspect grid: a square matrix with the points on both sides, only the aspect symbols in it. */
export function AspectGrid({ chart }: { chart: Chart }) {
const result = chart.chart;
const present = new Set(result.points.map((p) => p.id));
const rows: [string, string][] = GRID_POINTS.filter((id) => present.has(id)).map((id) => [
id,
POINTS[id]?.glyph ?? id,
]);
if (chart.highlights.time_known) {
for (const [key, label] of GRID_ANGLES) if (result.angles?.[key]) rows.push([key, label]);
}
const byPair = new Map<string, Aspect>();
for (const a of result.aspects ?? []) {
byPair.set(`${a.point1}|${a.point2}`, a);
byPair.set(`${a.point2}|${a.point1}`, a);
}
const label = ([id, text]: [string, string]) => (
<span className={text.length > 2 ? "sym" : "grid-angle"} aria-label={pointName(id)} role="img">
{text}
</span>
);
return (
<div className="aspect-grid-wrap">
<table className="aspect-grid" aria-label="Fényszögmátrix">
<thead>
<tr>
<td className="corner" />
{rows.map((c) => (
<th key={c[0]} scope="col" title={pointName(c[0])}>
{label(c)}
</th>
))}
</tr>
</thead>
<tbody>
{rows.map((row) => {
const [id] = row;
return (
<tr key={id}>
<th scope="row" title={pointName(id)}>
{label(row)}
</th>
{rows.map(([other]) => {
if (other === id) return <td key={other} className="diag" />;
const a = byPair.get(`${id}|${other}`);
const info = a ? ASPECTS[a.aspect] : undefined;
const text = a ? `${pointName(id)} ${info?.hu ?? a.aspect} ${pointName(other)}` : undefined;
return (
<td key={other} title={text}>
{a && (
<span className={`sym asp asp-${a.aspect}`} aria-label={text} role="img">
{info?.glyph ?? "?"}
</span>
)}
</td>
);
})}
</tr>
);
})}
</tbody>
</table>
</div>
);
}
/** Positions, angles and house cusps of a natal chart. */
export function PositionTables({ chart }: { chart: Chart }) {
const result = chart.chart;
const timeKnown = chart.highlights.time_known;
const angles = ANGLES.map(([key, label]) => [label, result.angles?.[key]] as const).filter(
(a): a is readonly [string, Position] => typeof a[1] === "object" && a[1] !== null,
);
const fortune = result.lots?.fortune;
return (
<div className="field" style={{ gap: 24 }}>
<div className="grid-2" style={{ alignItems: "start" }}>
<div className="table-wrap">
<h3 style={{ marginBottom: 8 }}>Bolygók és pontok</h3>
<table>
<thead>
<tr>
<th scope="col">Pont</th>
<th scope="col">Pozíció</th>
{timeKnown && <th scope="col">Ház</th>}
</tr>
</thead>
<tbody>
{result.points.map((p) => (
<tr key={p.id}>
<td>
<span className="sym" aria-hidden="true">
{POINTS[p.id]?.glyph}
</span>{" "}
{POINTS[p.id]?.hu ?? p.id}
{p.retrograde && (
<abbr className="retro" title="retrográd">
R
</abbr>
)}
</td>
<td className="num">
<Pos p={p} />
</td>
{timeKnown && <td className="num">{p.house ? `${p.house}.` : "–"}</td>}
</tr>
))}
{timeKnown && fortune && (
<tr>
<td>Szerencsepont</td>
<td className="num">
<Pos p={fortune} />
</td>
<td className="num">{fortune.house ? `${fortune.house}.` : "–"}</td>
</tr>
)}
</tbody>
</table>
</div>
{timeKnown && (
<div className="field" style={{ gap: 24 }}>
<div className="table-wrap">
<h3 style={{ marginBottom: 8 }}>Tengelyek</h3>
<table>
<tbody>
{angles.map(([label, p]) => (
<tr key={label}>
<td>{label}</td>
<td className="num">
<Pos p={p} />
</td>
</tr>
))}
</tbody>
</table>
</div>
{result.houses && (
<div className="table-wrap">
<h3 style={{ marginBottom: 8 }}>Házcsúcsok (Placidus)</h3>
<table>
<tbody>
{result.houses.cusps.map((c) => (
<tr key={c.house}>
<td>{c.house}. ház</td>
<td className="num">
<Pos p={c} />
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
)}
</div>
{!timeKnown && (
<p className="hint">
Születési idő nélkül a házak, a tengelyek és az Aszcendens nem számolhatók; a Hold helyzete a nap folyamán akár
jegyet is válthat, ezért közelítő.
</p>
)}
</div>
);
}
/** Every aspect with its orb and whether it is applying, closest first. */
export function AspectList({ chart }: { chart: Chart }) {
const aspects = [...(chart.chart.aspects ?? [])].sort((a, b) => a.orb - b.orb);
if (aspects.length === 0) return <p className="muted">Nincs fényszög.</p>;
return (
<div className="table-wrap">
<table>
<thead>
<tr>
<th scope="col">Fényszög</th>
<th scope="col">Orbisz</th>
<th scope="col">
<span className="sr-only">Közeledő vagy távolodó</span>
</th>
</tr>
</thead>
<tbody>
{aspects.map((a) => {
const info = ASPECTS[a.aspect];
return (
<tr key={`${a.point1}-${a.point2}-${a.aspect}`}>
<td>
<span className="sym" aria-hidden="true">
{POINTS[a.point1]?.glyph}
</span>{" "}
{pointName(a.point1)}{" "}
<span className={`aspect-tag aspect-${info?.kind ?? "neutral"}`}>
<span className="sym" aria-hidden="true">
{info?.glyph}
</span>{" "}
{info?.hu ?? a.aspect}
</span>{" "}
<span className="sym" aria-hidden="true">
{POINTS[a.point2]?.glyph}
</span>{" "}
{pointName(a.point2)}
</td>
<td className="num">{orbText(a.orb)}</td>
<td className="muted" style={{ fontSize: 13 }}>
{a.applying === true ? "közeledő" : a.applying === false ? "távolodó" : ""}
</td>
</tr>
);
})}
</tbody>
</table>
</div>
);
}