54 lines
2.1 KiB
Svelte
54 lines
2.1 KiB
Svelte
<script lang="ts">
|
|
import * as race from '$lib/race';
|
|
import * as racecourse from '$lib/data/racecourse';
|
|
import CourseChart from '$lib/CourseChart.svelte';
|
|
|
|
interface Props {
|
|
course: racecourse.Course;
|
|
}
|
|
|
|
let { course }: Props = $props();
|
|
|
|
function slopeprops(s: racecourse.Slope) {
|
|
if (s.per > 0) {
|
|
return { fy: 'Slope', x1: s.start, x2: s.end, label: `+${s.per / 10000}`, color: 'white' };
|
|
}
|
|
if (s.per < 0) {
|
|
return { fy: 'Slope', x1: s.start, x2: s.end, label: `${s.per / 10000}`, color: 'cyan' };
|
|
}
|
|
return { fy: 'Slope', x1: s.start, x2: s.end, color: 'none' };
|
|
}
|
|
function spanprops(s: racecourse.Span) {
|
|
if (s.corner != null) {
|
|
if (s.corner === 4) {
|
|
return { fy: 'Span', x1: s.start, x2: s.end, label: 'C4', color: 'red' };
|
|
}
|
|
return { fy: 'Span', x1: s.start, x2: s.end, label: `C${s.corner}`, color: 'cyan' };
|
|
}
|
|
if (s.straight != null) {
|
|
return { fy: 'Span', x1: s.start, x2: s.end, label: `S${s.straight}`, color: 'white' };
|
|
}
|
|
return { fy: 'Span', x1: s.start, x2: s.end, label: '~', color: 'pink' };
|
|
}
|
|
|
|
const poskeep = $derived((course.distance * 10) / 24);
|
|
const spotStruggle = $derived((course.distance * 9) / 24);
|
|
const rushStart = $derived(course.distance / 24);
|
|
const rushEnd = $derived((course.distance * 10) / 24);
|
|
const slopes = $derived(racecourse.fillSlopes(course.slopes, course.distance));
|
|
const phases = $derived(race.phases(course.distance));
|
|
const draw = $derived([
|
|
...slopes.map(slopeprops),
|
|
...course.spans.map(spanprops),
|
|
{ fy: 'Phase', x1: 0, x2: phases[race.Phase.EarlyRace], label: 'Early', color: 'cyan' },
|
|
{ fy: 'Phase', x1: phases[race.Phase.EarlyRace], x2: phases[race.Phase.MidRace], label: 'Mid', color: 'yellow' },
|
|
{ fy: 'Phase', x1: phases[race.Phase.MidRace], x2: phases[race.Phase.LateRace], label: 'Late', color: 'magenta' },
|
|
{ fy: 'Phase', x1: phases[race.Phase.LateRace], x2: phases[race.Phase.LastSpurt], label: 'Spurt', color: 'magenta' },
|
|
{ fy: 'PosKeep', x1: 0, x2: poskeep, color: 'purple' },
|
|
{ fy: 'SpotS', x1: 150, x2: spotStruggle, color: 'green' },
|
|
{ fy: 'Rush', x1: rushStart, x2: rushEnd, color: 'red' },
|
|
]);
|
|
</script>
|
|
|
|
<CourseChart {course} {draw} />
|