Skip to content

Commit

Permalink
improve strategy performance chart max timeframe
Browse files Browse the repository at this point in the history
- prevent error when no chart data
- use weekly timeframe when time span > 1 year
  • Loading branch information
kenkunz committed Aug 6, 2024
1 parent 7b4bc00 commit 92399e9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib/chart/PerformanceChart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ Display a peformance line chart for a given (static) dataset.
let viewportWidth: number;
$: hideYAxis = viewportWidth <= 576;
$: spanDays ??= differenceInCalendarDays(new Date(), data[0].DT) || 0;
// if spanDays is not set, assume "max" (full data range)
$: if (spanDays === undefined) {
spanDays ??= differenceInCalendarDays(new Date(), data[0]?.DT) || 0;
// override periodicity to weekly for time spans greater than 1 year
if (spanDays > 365) {
periodicity = { period: 7, interval: 1, timeUnit: 'day' };
}
}
const defaultOptions = {
layout: { chartType: 'mountain' },
Expand Down

0 comments on commit 92399e9

Please sign in to comment.