Skip to content

Commit

Permalink
Better text measurement in timeline (#115)
Browse files Browse the repository at this point in the history
* Better text measurement in timeline

* Use shortName for organizations in title
  • Loading branch information
gordonhart authored Feb 11, 2025
1 parent 216540e commit 8f93c56
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/components/FactSheet/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ function renderTimeline(
const baseColor = '#828282';

ctx.font = `12px ${LABEL_FONT_FAMILY}`;
const { width: textWidthPx, actualBoundingBoxAscent: textHeightPx } = ctx.measureText('0000');
const years = new Set(items.map(({ date }) => date.getFullYear().toString()));
const measurements = [...years].map(year => ctx.measureText(year));
const textWidthPx = Math.max(...measurements.map(({ width }) => width));
const textHeightPx = Math.max(...measurements.map(({ actualBoundingBoxAscent }) => actualBoundingBoxAscent));
const timelineLeft = dotRadius * 2 + 1 + textWidthPx;
ctx.lineWidth = 1;
ctx.strokeStyle = baseColor;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useFocusItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function getFocusItem(id: string | null, bodies: Array<CelestialBody>): FocusIte
type: FocusItemType.ORGANIZATION,
item: organization,
color: organization.color,
name: organization.name,
name: organization.shortName,
};
}
return undefined;
Expand Down

0 comments on commit 8f93c56

Please sign in to comment.