Assemble a body's readouts once, not once per panel

Follow-up to review on #3. The card and the detail page each built their own Measured/Derived
split, kind label and provenance sentence — the drift buildBodyViewModel exists to prevent,
re-forked one layer up, and the drift would have been in which side of the measured/derived line
a quantity falls on, which is the distinction those panels exist to draw. One bodyReadouts(body)
now returns both blocks and the sentence, and both templates iterate it. The two surfaces render
identical rows as a result, and the card gains the inclination the detail page already showed.

Also from that review:

- KIND_LABELS was duplicated between the two panels; it now lives beside bodyReadouts. The third
  copy the review pointed at is a different union (search results are star/body/exoplanet, and
  label a body "Body"), so it stays where it is.
- CardRow was HudReadout renamed. Both are now Readout, which HudReadout extends with its
  derived flag.
- The enterable-systems count was a 21-line lazy memo over arrays that are already in hand; it is
  one expression where those arrays are assigned.
- buildBodyViewModel now carries hostStarId, so the detail scene stops rescanning both catalogues
  for something the builder had already resolved.
- heliocentricPeriodDays was called twice for the same body.
- The superscript helper was a split/map/join; it is a replace.
- info-panel had five computed() each wrapping one pure call with a non-null assertion, beside a
  template that inlined the same kind of call directly. They are gone with the shared readouts.
- Dropped a tautological test that compared a pure function to itself. Replaced with one that
  asserts the host star id the builder now carries.
- Removed the orphaned doc comment left behind when formatParsecs/formatAu moved out.

And one the review raised as out of scope but is worth taking: formatRadiusKm grouped thousands
above its decimal threshold and not below it, so 69,911 km sat beside a bare 6371 km. Both are
grouped now.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WaySiNst4HhDXBHnMy8p5G
This commit is contained in:
Claude
2026-08-06 03:52:11 +00:00
parent 1019727a39
commit 7b0f32f71a
12 changed files with 146 additions and 230 deletions
@@ -128,9 +128,6 @@ const EXIT_DURATION_SECONDS = 0.9;
const RETURN_DURATION_SECONDS = 1.1;
const GALACTIC_FLIGHT_SECONDS = 2.4;
/** Camera range for the readout panel, in the unit that suits the distance. */
/**
* Where the camera sits to hold the whole Galaxy: above the disc and back past the Sun, looking
* at the centre — near enough to the angle the Galaxy is usually drawn from, and it keeps the
@@ -199,6 +196,7 @@ export class GalaxySystemSceneComponent implements AfterViewInit, OnDestroy {
* over. Undefined outside the system view, and cleared when the view leaves one.
*/
readonly objectCard = signal<BodyDetailViewModel | undefined>(undefined);
private enterableSystems = 0;
private pinnedBodyId: string | null = null;
private hoveredBodyId: string | null = null;
@@ -350,6 +348,8 @@ export class GalaxySystemSceneComponent implements AfterViewInit, OnDestroy {
this.starsById = new Map(stars.map((star) => [star.id, star]));
this.bodies = bodies;
this.exoplanets = exoplanets;
// Which stars can be flown into: those with catalogued bodies of their own, plus the Sun.
this.enterableSystems = new Set<number>([...bodies.map((body) => body.systemStarId), ...exoplanets.map((exoplanet) => exoplanet.hostStarId)].filter((id) => id !== null)).size;
// Built once rather than per label refresh: it is a scan of every body and exoplanet, and the
// labels are recomputed whenever the camera moves.
this.starIdsWithBodies = new Set([...bodies.map((body) => body.systemStarId), ...exoplanets.map((exoplanet) => exoplanet.hostStarId)].filter(
@@ -683,7 +683,7 @@ export class GalaxySystemSceneComponent implements AfterViewInit, OnDestroy {
{ label: 'Radius', value: `${LOCAL_GRID_RINGS_PC[LOCAL_GRID_RINGS_PC.length - 1]} pc` },
{ label: 'Exoplanets', value: `${this.exoplanets.length}` },
// The one thing the field itself cannot show: which of those points can be flown into.
{ label: 'Systems', value: `${this.enterableSystemCount()}` }
{ label: 'Systems', value: `${this.enterableSystems}` }
]);
this.hudNote.set('Positions from measured parallaxes. Grid marks the galactic plane through the Sun.');
}
@@ -804,28 +804,6 @@ export class GalaxySystemSceneComponent implements AfterViewInit, OnDestroy {
void this.router.navigate(['/body', id]);
}
/**
* How many stars can actually be entered: those with catalogued bodies of their own, plus the
* Sun. Computed once rather than on every HUD refresh.
*/
private enterableSystems?: number;
private enterableSystemCount(): number {
if (this.enterableSystems === undefined) {
const hosts = new Set<number>();
for (const body of this.bodies) {
hosts.add(body.systemStarId);
}
for (const exoplanet of this.exoplanets) {
if (exoplanet.hostStarId !== null) {
hosts.add(exoplanet.hostStarId);
}
}
this.enterableSystems = hosts.size;
}
return this.enterableSystems;
}
/** Reacts to `NavigationStore.selectedStarId` changes coming from any source (click/search). */
private reconcileSelection(selectedStarId: number | null): void {
if (this.busy || selectedStarId === this.currentStarId) {
@@ -98,7 +98,7 @@ describe('SystemObjectCardComponent', () => {
appearance: appearance({ equilibriumTemperatureK: null }),
});
expect(block(host, 'Derived')).not.toContain('Equilibrium temp.');
expect(host.textContent).toContain('No host star in the catalogue');
expect(host.textContent).toContain('host star is not in the catalogue');
});
it('emits rather than navigating, so the scene decides what selection means', () => {
@@ -1,20 +1,7 @@
import { ChangeDetectionStrategy, Component, computed, input, output } from '@angular/core';
import { BodyDetailViewModel } from '../body-detail/body-detail.model';
import { PLANET_CLASS_LABELS } from '../../shared/astro/planet-appearance';
import { formatAu, formatDensity, formatMassEarth, formatPeriod, formatRadiusKm, formatTemperature } from '../../shared/format/quantity';
const KIND_LABELS: Record<BodyDetailViewModel['kind'], string> = {
planet: 'Planet',
moon: 'Moon',
dwarf: 'Dwarf planet',
exoplanet: 'Exoplanet',
};
interface CardRow {
readonly label: string;
readonly value: string;
}
import { bodyReadouts } from '../body-detail/body-readouts';
/**
* The card shown for a body picked in the system view, without leaving it.
@@ -24,9 +11,7 @@ interface CardRow {
* shows the same numbers over the live view, and keeps the route as the deliberate step for the
* full 3D inspection.
*
* Measured and derived quantities are kept in separate blocks, each labelled, because the
* difference matters here more than it usually would: no exoplanet has been imaged and several
* of these figures are reasoned rather than observed. Presentational only.
* The rows themselves come from `bodyReadouts`, shared with the detail page. Presentational only.
*/
@Component({
selector: 'app-system-object-card',
@@ -43,10 +28,8 @@ interface CardRow {
<div data-testid="object-card" class="hud-panel px-4 py-3 font-body">
<div class="flex items-start justify-between gap-3">
<div class="min-w-0">
<p class="truncate font-display text-lg tracking-[0.04em] text-text">
{{ body().name }}
</p>
<p class="mt-0.5 font-display text-[10px] tracking-[0.22em] text-accent uppercase">{{ kindLabel() }} · {{ body().hostStarName }}</p>
<p class="truncate font-display text-lg tracking-[0.04em] text-text">{{ body().name }}</p>
<p class="mt-0.5 font-display text-[10px] tracking-[0.22em] text-accent uppercase">{{ readouts().kindLabel }} · {{ body().hostStarName }}</p>
</div>
<button
type="button"
@@ -60,10 +43,10 @@ interface CardRow {
</button>
</div>
@if (measured().length) {
@if (readouts().measured.length) {
<p class="mt-3 text-[10px] tracking-[0.18em] text-muted uppercase">Measured</p>
<dl class="mt-1 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-sm">
@for (row of measured(); track row.label) {
@for (row of readouts().measured; track row.label) {
<dt class="text-muted">{{ row.label }}</dt>
<dd class="text-right text-text tabular-nums">{{ row.value }}</dd>
}
@@ -72,15 +55,13 @@ interface CardRow {
<p class="mt-3 text-[10px] tracking-[0.18em] text-muted uppercase">Derived</p>
<dl class="mt-1 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-sm">
@for (row of derived(); track row.label) {
@for (row of readouts().derived; track row.label) {
<dt class="text-muted">{{ row.label }}</dt>
<dd class="text-right text-text tabular-nums">{{ row.value }}</dd>
}
</dl>
<p class="mt-3 border-t border-border/50 pt-2 text-[10px] leading-relaxed text-muted">
{{ provenance() }}
</p>
<p class="mt-3 border-t border-border/50 pt-2 text-[10px] leading-relaxed text-muted">{{ readouts().provenance }}</p>
<button
type="button"
@@ -94,7 +75,7 @@ interface CardRow {
</button>
</div>
</div>
`,
`
})
export class SystemObjectCardComponent {
readonly body = input.required<BodyDetailViewModel>();
@@ -103,63 +84,5 @@ export class SystemObjectCardComponent {
/** Request for the full `/body/:id` route. */
readonly openRequested = output<void>();
readonly kindLabel = computed(() => KIND_LABELS[this.body().kind]);
/** Only what a catalogue actually published for this body. */
readonly measured = computed<readonly CardRow[]>(() => {
const body = this.body();
const rows: CardRow[] = [];
if (body.radiusKm !== undefined) {
rows.push({ label: 'Radius', value: formatRadiusKm(body.radiusKm) });
}
if (body.massEarth !== undefined) {
rows.push({ label: 'Mass', value: formatMassEarth(body.massEarth) });
}
if (body.orbit.semiMajorAxisAu !== undefined) {
rows.push({ label: 'Semi-major axis', value: formatAu(body.orbit.semiMajorAxisAu) });
}
if (body.orbit.eccentricity !== undefined) {
rows.push({ label: 'Eccentricity', value: body.orbit.eccentricity.toFixed(3) });
}
if (body.orbitalPeriodDays !== undefined && body.orbitalPeriodSource === 'measured') {
rows.push({ label: 'Period', value: formatPeriod(body.orbitalPeriodDays) });
}
if (body.discoveryYear !== undefined) {
rows.push({ label: 'Discovered', value: `${body.discoveryYear}` });
}
return rows;
});
/** Everything computed from the measurements above rather than observed directly. */
readonly derived = computed<readonly CardRow[]>(() => {
const body = this.body();
const rows: CardRow[] = [{ label: 'Class', value: PLANET_CLASS_LABELS[body.appearance.planetClass] }];
if (body.orbitalPeriodDays !== undefined && body.orbitalPeriodSource === 'derived') {
rows.push({ label: 'Period', value: formatPeriod(body.orbitalPeriodDays) });
}
if (body.appearance.equilibriumTemperatureK !== null) {
rows.push({
label: 'Equilibrium temp.',
value: formatTemperature(body.appearance.equilibriumTemperatureK),
});
}
if (body.appearance.bulkDensityGramsPerCm3 !== null) {
rows.push({
label: 'Bulk density',
value: formatDensity(body.appearance.bulkDensityGramsPerCm3),
});
}
return rows;
});
/** The same distinction the detail panel draws, stated briefly enough for a card. */
readonly provenance = computed(() => {
const body = this.body();
if (body.hasPhotography) {
return 'Surface: NASA/ESA/USGS photography.';
}
return body.appearance.equilibriumTemperatureK === null
? 'Surface illustrated from measured size and mass. No host star in the catalogue, so no temperature could be derived.'
: 'Surface illustrated from the measurements above. Not an observation — no image of this world exists.';
});
readonly readouts = computed(() => bodyReadouts(this.body()));
}