From 37de186e3af6bfbfd1d03a7b6b33fa6bc4ccb159 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Thu, 20 Feb 2025 23:24:46 +0100 Subject: [PATCH] ui fixes --- .../stocks/[tickerID]/insider/+layout.svelte | 3 +- .../stocks/[tickerID]/statistics/+page.svelte | 1 - .../statistics/revenue/+layout.svelte | 57 +++++++++ .../statistics/revenue/+page.svelte | 113 ++++++++++++------ 4 files changed, 137 insertions(+), 37 deletions(-) diff --git a/src/routes/stocks/[tickerID]/insider/+layout.svelte b/src/routes/stocks/[tickerID]/insider/+layout.svelte index cb226948..d8393fbf 100644 --- a/src/routes/stocks/[tickerID]/insider/+layout.svelte +++ b/src/routes/stocks/[tickerID]/insider/+layout.svelte @@ -1,6 +1,5 @@
@@ -109,6 +140,32 @@ {/if} + + {#if newsList?.length !== 0} +
+
+

+ {$stockTicker} News +

+
    + {#each newsList?.slice(0, 10) as item} +
  • + {formatDate(item?.publishedDate)} ago - + {item?.title} + - {item?.site} +
  • + {/each} +
+
+
+ {/if} diff --git a/src/routes/stocks/[tickerID]/statistics/revenue/+page.svelte b/src/routes/stocks/[tickerID]/statistics/revenue/+page.svelte index 71b0065a..cdedb6f5 100644 --- a/src/routes/stocks/[tickerID]/statistics/revenue/+page.svelte +++ b/src/routes/stocks/[tickerID]/statistics/revenue/+page.svelte @@ -3,8 +3,6 @@ import { abbreviateNumber, monthNames } from "$lib/utils"; import SEO from "$lib/components/SEO.svelte"; - import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js"; - import { Button } from "$lib/components/shadcn/button/index.js"; //import * as XLSX from 'xlsx'; import { goto } from "$app/navigation"; import { Chart } from "svelte-echarts"; @@ -22,7 +20,6 @@ let rawData = data?.getHistoricalRevenue || {}; let tableList = []; - let timePeriod = "3Y"; const tabs = [ { @@ -33,25 +30,49 @@ }, ]; let activeIdx = 0; + let timeIdx = 0; + + const plotTabs = [ + { + title: "Annual", + }, + { + title: "Quarterly", + }, + ]; function changeTablePeriod(index) { activeIdx = index; + const rawData = data?.getHistoricalRevenue; if (activeIdx === 0) { - tableList = rawData?.annual; + // Clone the array before sorting + tableList = [...rawData?.annual]; + tableList.sort((a, b) => new Date(b?.date) - new Date(a?.date)); } else { - tableList = rawData?.quarter; + tableList = [...rawData?.quarter]; + tableList.sort((a, b) => new Date(b?.date) - new Date(a?.date)); } - tableList?.sort((a, b) => new Date(b?.date) - new Date(a?.date)); } - async function changeStatement(state) { - timePeriod = state; - - optionsData = await plotData(); + async function changeTimePeriod(state) { + timeIdx = state; + optionsData = plotData(); } function plotData() { - const filteredData = filterDataByTimePeriod(rawData, timePeriod); + let filteredData = []; + const rawData = data?.getHistoricalRevenue; + if (timeIdx === 0) { + // Clone the array before sorting + filteredData = [...rawData?.annual]; + } else { + filteredData = [...rawData?.quarter]; + } + // Sort ascending for plotting + filteredData.sort((a, b) => new Date(a?.date) - new Date(b?.date)); + + const dates = filteredData.map((item) => item?.date); + const valueList = filteredData.map((item) => item?.revenue); const options = { animation: false, @@ -65,10 +86,9 @@ xAxis: [ { type: "category", - data: filteredData?.dates, + data: dates, axisLabel: { color: "#fff", - formatter: function (value) { // Assuming dates are in the format 'yyyy-mm-dd' const dateParts = value.split("-"); @@ -86,7 +106,6 @@ splitLine: { show: false, // Disable x-axis grid lines }, - axisLabel: { show: false, // Hide y-axis labels }, @@ -94,14 +113,15 @@ ], series: [ { - name: "Mkt Cap", - data: filteredData?.marketCapList, - type: "line", + name: "Revenue", + data: valueList, + type: "bar", smooth: true, symbol: "none", itemStyle: { - color: "#fff", + color: "#f2f1f0", }, + barWidth: "60%", }, ], tooltip: { @@ -116,10 +136,8 @@ formatter: function (params) { // Get the timestamp from the first parameter const timestamp = params[0].axisValue; - // Initialize result with timestamp let result = timestamp + "
"; - // Add each series data params.forEach((param) => { const marker = @@ -134,7 +152,6 @@ abbreviateNumber(param.value, false, true) + "
"; }); - return result; }, axisPointer: { @@ -148,12 +165,8 @@ return options; } - $: { - if ($stockTicker) { - tableList = rawData?.annual; - tableList?.sort((a, b) => new Date(b?.date) - new Date(a?.date)); - } - } + changeTablePeriod(0); + optionsData = plotData();
-

+

Revenue Chart -

+ +
+ class="inline-flex justify-center w-full rounded-md sm:w-auto sm:ml-auto" + > +
+ {#each plotTabs as item, i} + + {/each} +
+
+ {#if optionsData !== null}
@@ -357,7 +400,9 @@ Date{activeIdx === 0 + ? "Fiscal Year End" + : "Quarter Ended"} Revenue - {@html abbreviateNumber(item?.revenue, false, true)} + {abbreviateNumber(item?.revenue)}