sync chart scale

main
Avraham Sakal 1 year ago
parent ae7ae7e7ee
commit e6a5002ec0

@ -1,5 +1,5 @@
import { signal } from "@preact/signals"; import { signal, computed } from "@preact/signals";
import { useCallback, useEffect } from "preact/hooks"; import { useEffect } from "preact/hooks";
import {trpc} from '../../trpc.js'; import {trpc} from '../../trpc.js';
import { import {
Chart as ChartJS, Chart as ChartJS,
@ -35,6 +35,13 @@ const historicalCalendarExitQuoteChartData = signal([]);
const chosenLookbackPeriodStart = signal("2022-01-01"); const chosenLookbackPeriodStart = signal("2022-01-01");
const chosenLookbackPeriodEnd = signal("2024-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 = ()=>{ const refreshHistoricalStockQuoteChartData = ()=>{
trpc.getHistoricalStockQuoteChartData trpc.getHistoricalStockQuoteChartData
@ -212,7 +219,9 @@ export function HistoricalCalendarPrices(){
callback: function(value, index, ticks) { callback: function(value, index, ticks) {
return (new Date(value as number*1000)).toISOString().substring(0,10); 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: { y: {
beginAtZero: false, beginAtZero: false,
@ -271,7 +280,9 @@ export function HistoricalCalendarPrices(){
callback: function(value, index, ticks) { callback: function(value, index, ticks) {
return (new Date(value as number*1000)).toISOString().substring(0,10); 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: { y: {
beginAtZero: true, beginAtZero: true,
@ -279,7 +290,9 @@ export function HistoricalCalendarPrices(){
callback: function(value, index, ticks) { callback: function(value, index, ticks) {
return "$"+value.toString(); return "$"+value.toString();
} }
} },
min: 0,
max: maxChartPrice.value,
} }
}, },
plugins: { plugins: {
@ -325,7 +338,7 @@ export function HistoricalCalendarPrices(){
callback: function(value, index, ticks) { callback: function(value, index, ticks) {
return value.toString()+"%"; return value.toString()+"%";
} }
} },
}, },
y: { y: {
beginAtZero: true, beginAtZero: true,
@ -333,7 +346,9 @@ export function HistoricalCalendarPrices(){
callback: function(value, index, ticks) { callback: function(value, index, ticks) {
return "$"+value.toString(); return "$"+value.toString();
} }
} },
min: 0,
max: maxChartPrice.value,
}, },
}, },
elements: { elements: {

Loading…
Cancel
Save