jellyfin-tools/jellyfin-year-review/web/src/lib/radar.js
jellyfin-year-review/web/src/lib/radar.jsRaw
1// Use the same zero-based scale as the bar chart, with room for sparse datasets.
2export function radarGeometry(values) {
3 const max = Math.max(1, ...values);
4 const axisCount = Math.max(3, values.length);
5 const axes = Array.from({ length: axisCount }, (_, index) => {
6 const angle = index * 2 * Math.PI / axisCount - Math.PI / 2;
7 const x = Math.cos(angle), y = Math.sin(angle);
8 const fraction = Math.max(0, values[index] ?? 0) / max;
9 return { x, y, valueX: x * fraction, valueY: y * fraction };
10 });
11 return { max, axes };
12}