diff --git a/src/routes/hedge-funds/[slug]/+page.svelte b/src/routes/hedge-funds/[slug]/+page.svelte index b93a31a4..934e4edf 100644 --- a/src/routes/hedge-funds/[slug]/+page.svelte +++ b/src/routes/hedge-funds/[slug]/+page.svelte @@ -4,6 +4,10 @@ import cardBackground from "$lib/images/bg-hedge-funds.png"; import { abbreviateNumber, formatString } from '$lib/utils'; + import PercentIcon from "lucide-svelte/icons/percent"; + import MoneyIcon from 'lucide-svelte/icons/circle-dollar-sign'; + + import { Chart } from 'svelte-echarts' import { init, use } from 'echarts/core' import { BarChart } from 'echarts/charts' @@ -159,12 +163,37 @@ function formatToFY(dateString) { } + const plotTabs = [ + { + title: "Performance", + }, + { + title: "Market Value", + }, + ]; - async function getPlotOptions() { + let activePlotIdx = 0; + + +async function handleMode(i) { + activePlotIdx = i; + if (activePlotIdx === 0) { + optionsData = await getPerformancePlot(); + } + else { + optionsData = await getValuePlot(); + } + + } + + + async function getPerformancePlot() { // Initialize boughtList and soldList arrays const data = rawData?.summary?.slice(0,20) - ?.map(item => ({ date: item?.date, performancePercentage: item?.performancePercentage })) - ?.reverse(); + ?.map(item => ({ date: item?.date, performancePercentage: item?.performancePercentage })); + + data.sort((a, b) => new Date(a?.date) - new Date(b?.date)); + const updatedData = addSpyPerformance(data, spyData); const dates = updatedData?.map(item => formatToFY(item?.date)); @@ -233,14 +262,78 @@ function formatToFY(dateString) { return option; } + + async function getValuePlot() { + // Initialize boughtList and soldList arrays + const data = rawData?.summary?.slice(0,20) + ?.map(item => ({ date: item?.date, marketValue: item?.marketValue })); + + data.sort((a, b) => new Date(a?.date) - new Date(b?.date)); + + const dates = data?.map(item => formatToFY(item?.date)); + + const hedgeFundValue = data?.map(item => item?.marketValue) + + const { unit, denominator } = normalizer(Math.max(...hedgeFundValue) ?? 0); + + + const option = { + silent: true, + animation: false, + tooltip: { + trigger: 'axis', + hideDelay: 100, // Set the delay in milliseconds + }, + grid: { + left: $screenWidth < 640 ? '0.5%' : '0.5%', + right: $screenWidth < 640 ? '1%' : '5%', + bottom: '0%', + containLabel: true + }, + xAxis: { + data: dates, + type: 'category', + axisLabel: { + color: '#fff' + } + }, + yAxis: [ + { + type: 'value', + splitLine: { + show: false, // Disable x-axis grid lines + }, + axisLabel: { + color: '#fff', // Change label color to white + formatter: function (value) { + return value >= 0 ? '$'+(value / denominator)?.toFixed(0) + unit : ''; // Format value in millions + }, + }, + }, + ], + series: [ + { name: 'Hedge Fund', + data: hedgeFundValue, + type: 'bar', + showSymbol: false, + itemStyle: { + color: '#36A2EB' // Change bar color to white + }, + }, + ] + }; + + + return option; + } + onMount(async () => { - optionsData = await getPlotOptions(); + optionsData = await getPerformancePlot(); isLoaded = true; }); - function prevPage() { if (currentPage > 1) { currentPage -= 1; @@ -273,17 +366,8 @@ onMount(async () => { $: totalPages = Math?.ceil(rawList.length / itemsPerPage); - let charNumber = 40; - $: { - if ($screenWidth < 640) - { - charNumber = 15; - } - else { - charNumber = 40; - } - } - + $: charNumber = $screenWidth < 640 ? 15 : 40; + @@ -516,16 +600,45 @@ onMount(async () => {
- + {#if activePlotIdx === 0} + Performance History + {:else} + + Portofolio Value History + {/if}
+ +
+ {#each plotTabs as item, i} + + {/each} + + + +
- -
+ +
@@ -657,7 +770,7 @@ onMount(async () => {
-
+
{#each tabs as item, i} @@ -669,21 +782,15 @@ onMount(async () => { > {#if activeIdx === i}
{/if} - {#if item?.title === 'Stocks'} - - {item?.title} - - {:else if item?.title === 'Options'} - - {item?.title} - - {/if} + + + {item?.title} + {/each} @@ -740,30 +847,30 @@ onMount(async () => { - + {item?.weight >= 0.01 ? item?.weight?.toFixed(2) : '< 0.01'}% {#if changeAssetType === 'Stocks'} - + {item?.changeInSharesNumberPercentage !== 0 ? abbreviateNumber(item?.changeInSharesNumberPercentage?.toFixed(2))+'%' : '-'} - + {item?.sharesNumber !== 0 ? abbreviateNumber(item?.sharesNumber?.toFixed(2)) : '-'} {/if} - + {abbreviateNumber(item?.marketValue,true)} - + ${item?.avgPricePaid} {#if changeAssetType === 'Options'} - + {formatString(item?.putCallShare)} {/if}