From e6a5002ec039bc1392859e9b32655d73d69239d3 Mon Sep 17 00:00:00 2001 From: Avraham Sakal Date: Sun, 18 Feb 2024 20:39:36 -0500 Subject: [PATCH] sync chart scale --- .../HistoricalCalendarPrices.tsx | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/frontend/src/pages/HistoricalCalendarPrices/HistoricalCalendarPrices.tsx b/frontend/src/pages/HistoricalCalendarPrices/HistoricalCalendarPrices.tsx index 6cf6aed..44df1dd 100644 --- a/frontend/src/pages/HistoricalCalendarPrices/HistoricalCalendarPrices.tsx +++ b/frontend/src/pages/HistoricalCalendarPrices/HistoricalCalendarPrices.tsx @@ -1,5 +1,5 @@ -import { signal } from "@preact/signals"; -import { useCallback, useEffect } from "preact/hooks"; +import { signal, computed } from "@preact/signals"; +import { useEffect } from "preact/hooks"; import {trpc} from '../../trpc.js'; import { Chart as ChartJS, @@ -35,6 +35,13 @@ const historicalCalendarExitQuoteChartData = signal([]); const chosenLookbackPeriodStart = signal("2022-01-01"); const chosenLookbackPeriodEnd = signal("2024-01-01"); +const maxChartPrice = computed(()=> + Math.max( + Math.max.apply(null, historicalCalendarQuoteChartData.value.map(d=>d.y)), + Math.max.apply(null, historicalCalendarExitQuoteChartData.value.map(d=>d.y)), + ) +); + const refreshHistoricalStockQuoteChartData = ()=>{ trpc.getHistoricalStockQuoteChartData @@ -212,7 +219,9 @@ export function HistoricalCalendarPrices(){ callback: function(value, index, ticks) { return (new Date(value as number*1000)).toISOString().substring(0,10); } - } + }, + min: (new Date(chosenLookbackPeriodStart.value)).getTime()/1000, + max: (new Date(chosenLookbackPeriodEnd.value)).getTime()/1000, }, y: { beginAtZero: false, @@ -271,7 +280,9 @@ export function HistoricalCalendarPrices(){ callback: function(value, index, ticks) { return (new Date(value as number*1000)).toISOString().substring(0,10); } - } + }, + min: (new Date(chosenLookbackPeriodStart.value)).getTime()/1000, + max: (new Date(chosenLookbackPeriodEnd.value)).getTime()/1000, }, y: { beginAtZero: true, @@ -279,7 +290,9 @@ export function HistoricalCalendarPrices(){ callback: function(value, index, ticks) { return "$"+value.toString(); } - } + }, + min: 0, + max: maxChartPrice.value, } }, plugins: { @@ -325,7 +338,7 @@ export function HistoricalCalendarPrices(){ callback: function(value, index, ticks) { return value.toString()+"%"; } - } + }, }, y: { beginAtZero: true, @@ -333,7 +346,9 @@ export function HistoricalCalendarPrices(){ callback: function(value, index, ticks) { return "$"+value.toString(); } - } + }, + min: 0, + max: maxChartPrice.value, }, }, elements: {