From 92399e9b800fc743b44bfbbbe120a281f012b647 Mon Sep 17 00:00:00 2001 From: Ken Kunz Date: Tue, 6 Aug 2024 13:34:00 -0500 Subject: [PATCH] improve strategy performance chart max timeframe - prevent error when no chart data - use weekly timeframe when time span > 1 year --- src/lib/chart/PerformanceChart.svelte | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/chart/PerformanceChart.svelte b/src/lib/chart/PerformanceChart.svelte index 66f47cdca..5ba92a446 100644 --- a/src/lib/chart/PerformanceChart.svelte +++ b/src/lib/chart/PerformanceChart.svelte @@ -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' },