From e1abc59e998713a8e9cadbf586317473d6ca0de7 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Mon, 29 May 2023 14:58:39 +0200 Subject: [PATCH] added IPO bars --- .../src/components/StockPrice.vue | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/stockingly-frontend/src/components/StockPrice.vue b/stockingly-frontend/src/components/StockPrice.vue index dd88ae5..dcbf2eb 100644 --- a/stockingly-frontend/src/components/StockPrice.vue +++ b/stockingly-frontend/src/components/StockPrice.vue @@ -15,7 +15,8 @@ Current price:
- + {{ ticker }}: ${{ maxPrice[ticker] }}
@@ -38,7 +39,8 @@ flex: 1 0; } -.toolbar .chips, .toolbar .label { +.toolbar .chips, +.toolbar .label { flex: 0 0; text-align: center; } @@ -78,6 +80,23 @@ const optToDuration: Record props.colors[props.tickers.indexOf(ticker)]; +const minDates = (data: PriceHistory[]) => { + const toReturn = Object.fromEntries(props.tickers.map(t => [t, +Infinity])); + + for (const d of data ?? []) { + for (const key in d) { + if (key === 'date' || typeof d[key] !== 'number') continue; + if (Date.parse(d.date) < toReturn[key]) { + toReturn[key] = Date.parse(d.date); + } + } + } + + console.log(toReturn); + + return toReturn; +}; + const maxPrice = computed(() => { const maxVal = Object.fromEntries(props.tickers.map(t => [t, NaN])); let maxDate = -Infinity; @@ -144,7 +163,16 @@ const options = computed(() => { lineDash: [Infinity] }, { lineDash: [Infinity] - }] + }], + crossLines: Object.entries(minDates(stockPrice.data ?? [])) + .map(([key, value]: [string, number]) => ({ + type: 'line', + value, + label: { + text: key + ' IPO', + position: 'top', + } + })) }, { type: 'number', @@ -160,7 +188,7 @@ const options = computed(() => { lineDash: [Infinity] }, { lineDash: [Infinity] - }] + }], }, ], legend: {