refactor code

This commit is contained in:
MuslemRahimi 2024-10-29 22:33:31 +01:00
parent e785e838dd
commit f3d75ea951
29 changed files with 426 additions and 4610 deletions

View File

@ -11,51 +11,51 @@
const sectorNavigation = [ const sectorNavigation = [
{ {
title: "Financial Services", title: "Financial Services",
link: "/list/financial-sector", link: "/list/sector/financial",
}, },
{ {
title: "Finance", title: "Finance",
link: "/list/financial-sector", link: "/list/sector/financial",
}, },
{ {
title: "Healthcare", title: "Healthcare",
link: "/list/healthcare-sector", link: "/list/sector/healthcare",
}, },
{ {
title: "Technology", title: "Technology",
link: "/list/technology-sector", link: "/list/sector/technology",
}, },
{ {
title: "Industrials", title: "Industrials",
link: "/list/industrials-sector", link: "/list/sector/industrials",
}, },
{ {
title: "Energy", title: "Energy",
link: "/list/energy-sector", link: "/list/sector/energy",
}, },
{ {
title: "Utilities", title: "Utilities",
link: "/list/utilities-sector", link: "/list/sector/utilities",
}, },
{ {
title: "Consumer Cyclical", title: "Consumer Cyclical",
link: "/list/consumer-cyclical-sector", link: "/list/sector/consumer-cyclical",
}, },
{ {
title: "Real Estate", title: "Real Estate",
link: "/list/real-estate-sector", link: "/list/sector/real-estate",
}, },
{ {
title: "Basic Materials", title: "Basic Materials",
link: "/list/basic-materials-sector", link: "/list/sector/basic-materials",
}, },
{ {
title: "Communication Services", title: "Communication Services",
link: "/list/communication-services-sector", link: "/list/sector/communication-services",
}, },
{ {
title: "Consumer Defensive", title: "Consumer Defensive",
link: "/list/consumer-defensive-sector", link: "/list/sector/consumer-defensive",
}, },
]; ];

View File

@ -27,51 +27,51 @@
const sectorNavigation = [ const sectorNavigation = [
{ {
title: "Financial Services", title: "Financial Services",
link: "/list/financial-sector", link: "/list/sector/financial",
}, },
{ {
title: "Finance", title: "Finance",
link: "/list/financial-sector", link: "/list/sector/financial",
}, },
{ {
title: "Healthcare", title: "Healthcare",
link: "/list/healthcare-sector", link: "/list/sector/healthcare",
}, },
{ {
title: "Technology", title: "Technology",
link: "/list/technology-sector", link: "/list/sector/technology",
}, },
{ {
title: "Industrials", title: "Industrials",
link: "/list/industrials-sector", link: "/list/sector/industrials",
}, },
{ {
title: "Energy", title: "Energy",
link: "/list/energy-sector", link: "/list/sector/energy",
}, },
{ {
title: "Utilities", title: "Utilities",
link: "/list/utilities-sector", link: "/list/sector/utilities",
}, },
{ {
title: "Consumer Cyclical", title: "Consumer Cyclical",
link: "/list/consumer-cyclical-sector", link: "/list/sector/consumer-cyclical",
}, },
{ {
title: "Real Estate", title: "Real Estate",
link: "/list/real-estate-sector", link: "/list/sector/real-estate",
}, },
{ {
title: "Basic Materials", title: "Basic Materials",
link: "/list/basic-materials-sector", link: "/list/sector/basic-materials",
}, },
{ {
title: "Communication Services", title: "Communication Services",
link: "/list/communication-services-sector", link: "/list/sector/communication-services",
}, },
{ {
title: "Consumer Defensive", title: "Consumer Defensive",
link: "/list/consumer-defensive-sector", link: "/list/sector/consumer-defensive",
}, },
]; ];

View File

@ -10,51 +10,51 @@
const sectorNavigation = [ const sectorNavigation = [
{ {
title: "Financial Services", title: "Financial Services",
link: "/list/financial-sector", link: "/list/sector/financial",
}, },
{ {
title: "Finance", title: "Finance",
link: "/list/financial-sector", link: "/list/sector/financial",
}, },
{ {
title: "Healthcare", title: "Healthcare",
link: "/list/healthcare-sector", link: "/list/sector/healthcare",
}, },
{ {
title: "Technology", title: "Technology",
link: "/list/technology-sector", link: "/list/sector/technology",
}, },
{ {
title: "Industrials", title: "Industrials",
link: "/list/industrials-sector", link: "/list/sector/industrials",
}, },
{ {
title: "Energy", title: "Energy",
link: "/list/energy-sector", link: "/list/sector/energy",
}, },
{ {
title: "Utilities", title: "Utilities",
link: "/list/utilities-sector", link: "/list/sector/utilities",
}, },
{ {
title: "Consumer Cyclical", title: "Consumer Cyclical",
link: "/list/consumer-cyclical-sector", link: "/list/sector/consumer-cyclical",
}, },
{ {
title: "Real Estate", title: "Real Estate",
link: "/list/real-estate-sector", link: "/list/sector/real-estate",
}, },
{ {
title: "Basic Materials", title: "Basic Materials",
link: "/list/basic-materials-sector", link: "/list/sector/basic-materials",
}, },
{ {
title: "Communication Services", title: "Communication Services",
link: "/list/communication-services-sector", link: "/list/sector/communication-services",
}, },
{ {
title: "Consumer Defensive", title: "Consumer Defensive",
link: "/list/consumer-defensive-sector", link: "/list/sector/consumer-defensive",
}, },
]; ];

View File

@ -9,51 +9,51 @@
const sectorNavigation = [ const sectorNavigation = [
{ {
title: "Financial Services", title: "Financial Services",
link: "/list/financial-sector", link: "/list/sector/financial",
}, },
{ {
title: "Finance", title: "Finance",
link: "/list/financial-sector", link: "/list/sector/financial",
}, },
{ {
title: "Healthcare", title: "Healthcare",
link: "/list/healthcare-sector", link: "/list/sector/healthcare",
}, },
{ {
title: "Technology", title: "Technology",
link: "/list/technology-sector", link: "/list/sector/technology",
}, },
{ {
title: "Industrials", title: "Industrials",
link: "/list/industrials-sector", link: "/list/sector/industrials",
}, },
{ {
title: "Energy", title: "Energy",
link: "/list/energy-sector", link: "/list/sector/energy",
}, },
{ {
title: "Utilities", title: "Utilities",
link: "/list/utilities-sector", link: "/list/sector/utilities",
}, },
{ {
title: "Consumer Cyclical", title: "Consumer Cyclical",
link: "/list/consumer-cyclical-sector", link: "/list/sector/consumer-cyclical",
}, },
{ {
title: "Real Estate", title: "Real Estate",
link: "/list/real-estate-sector", link: "/list/sector/real-estate",
}, },
{ {
title: "Basic Materials", title: "Basic Materials",
link: "/list/basic-materials-sector", link: "/list/sector/basic-materials",
}, },
{ {
title: "Communication Services", title: "Communication Services",
link: "/list/communication-services-sector", link: "/list/sector/communication-services",
}, },
{ {
title: "Consumer Defensive", title: "Consumer Defensive",
link: "/list/consumer-defensive-sector", link: "/list/sector/consumer-defensive",
}, },
]; ];

View File

@ -107,47 +107,47 @@
}, },
{ {
title: "Financials Sector Stocks", title: "Financials Sector Stocks",
link: "/list/financial-sector", link: "/list/sector/financial",
}, },
{ {
title: "Healthcare Sector Stocks", title: "Healthcare Sector Stocks",
link: "/list/healthcare-sector", link: "/list/sector/healthcare",
}, },
{ {
title: "Technology Sector Stocks", title: "Technology Sector Stocks",
link: "/list/technology-sector", link: "/list/sector/technology",
}, },
{ {
title: "Industrials Sector Stocks", title: "Industrials Sector Stocks",
link: "/list/industrials-sector", link: "/list/sector/industrials",
}, },
{ {
title: "Energy Sector Stocks", title: "Energy Sector Stocks",
link: "/list/energy-sector", link: "/list/sector/energy",
}, },
{ {
title: "Utilities Sector Stocks", title: "Utilities Sector Stocks",
link: "/list/utilities-sector", link: "/list/sector/utilities",
}, },
{ {
title: "Consumer Cyclical Sector Stocks", title: "Consumer Cyclical Sector Stocks",
link: "/list/consumer-cyclical-sector", link: "/list/sector/consumer-cyclical",
}, },
{ {
title: "Real Estate Sector Stocks", title: "Real Estate Sector Stocks",
link: "/list/real-estate-sector", link: "/list/sector/real-estate",
}, },
{ {
title: "Basic Materials Sector Stocks", title: "Basic Materials Sector Stocks",
link: "/list/basic-materials-sector", link: "/list/sector/basic-materials",
}, },
{ {
title: "Communication Services Sector Stocks", title: "Communication Services Sector Stocks",
link: "/list/communication-services-sector", link: "/list/sector/communication-services",
}, },
{ {
title: "Consumer Defensive Sector Stocks", title: "Consumer Defensive Sector Stocks",
link: "/list/consumer-defensive-sector", link: "/list/sector/consumer-defensive",
}, },
{ {
title: "Delisted Companies", title: "Delisted Companies",

View File

@ -309,7 +309,7 @@
<ul class="list-disc space-y-1 pl-3"> <ul class="list-disc space-y-1 pl-3">
<li class="mb-2 cursor-pointer"> <li class="mb-2 cursor-pointer">
<a <a
href="/list/financial-sector" href="/list/sector/financial"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Financials Financials
@ -317,7 +317,7 @@
</li> </li>
<li class="mb-2 cursor-pointer"> <li class="mb-2 cursor-pointer">
<a <a
href="/list/healthcare-sector" href="/list/sector/healthcare"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Healthcare Healthcare
@ -325,7 +325,7 @@
</li> </li>
<li class="mb-2 cursor-pointer"> <li class="mb-2 cursor-pointer">
<a <a
href="/list/technology-sector" href="/list/sector/technology"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Technology Technology
@ -333,7 +333,7 @@
</li> </li>
<li class="mb-2 cursor-pointer"> <li class="mb-2 cursor-pointer">
<a <a
href="/list/industrials-sector" href="/list/sector/industrials"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Industrials Industrials
@ -341,7 +341,7 @@
</li> </li>
<li class="mb-2 cursor-pointer"> <li class="mb-2 cursor-pointer">
<a <a
href="/list/energy-sector" href="/list/sector/energy"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Energy Energy
@ -349,7 +349,7 @@
</li> </li>
<li class="mb-2 cursor-pointer"> <li class="mb-2 cursor-pointer">
<a <a
href="/list/utilities-sector" href="/list/sector/utilities"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Utilities Utilities
@ -358,7 +358,7 @@
<li class="mb-2 cursor-pointer sm:hidden"> <li class="mb-2 cursor-pointer sm:hidden">
<a <a
href="/list/consumer-cyclical-sector" href="/list/sector/consumer-cyclical"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Consumer Cyclical Consumer Cyclical
@ -366,7 +366,7 @@
</li> </li>
<li class="mb-2 cursor-pointer sm:hidden"> <li class="mb-2 cursor-pointer sm:hidden">
<a <a
href="/list/real-estate-sector" href="/list/sector/real-estate"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Real Estate Real Estate
@ -374,7 +374,7 @@
</li> </li>
<li class="mb-2 cursor-pointer sm:hidden"> <li class="mb-2 cursor-pointer sm:hidden">
<a <a
href="/list/basic-materials-sector" href="/list/sector/basic-materials"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Basic Materials Basic Materials
@ -382,7 +382,7 @@
</li> </li>
<li class="mb-2 cursor-pointer sm:hidden"> <li class="mb-2 cursor-pointer sm:hidden">
<a <a
href="/list/communication-services-sector" href="/list/sector/communication-services"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Communication Services Communication Services
@ -390,7 +390,7 @@
</li> </li>
<li class="mb-2 cursor-pointer sm:hidden"> <li class="mb-2 cursor-pointer sm:hidden">
<a <a
href="/list/consumer-defensive-sector" href="/list/sector/consumer-defensive"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Consumer Defensive Consumer Defensive
@ -404,7 +404,7 @@
<ul class="list-disc space-y-1 pl-5"> <ul class="list-disc space-y-1 pl-5">
<li class="mb-2 cursor-pointer"> <li class="mb-2 cursor-pointer">
<a <a
href="/list/consumer-cyclical-sector" href="/list/sector/consumer-cyclical"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Consumer Cyclical Consumer Cyclical
@ -412,7 +412,7 @@
</li> </li>
<li class="mb-2 cursor-pointer"> <li class="mb-2 cursor-pointer">
<a <a
href="/list/real-estate-sector" href="/list/sector/real-estate"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Real Estate Real Estate
@ -420,7 +420,7 @@
</li> </li>
<li class="mb-2 cursor-pointer"> <li class="mb-2 cursor-pointer">
<a <a
href="/list/basic-materials-sector" href="/list/sector/basic-materials"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Basic Materials Basic Materials
@ -428,7 +428,7 @@
</li> </li>
<li class="mb-2 cursor-pointer"> <li class="mb-2 cursor-pointer">
<a <a
href="/list/communication-services-sector" href="/list/sector/communication-services"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Communication Services Communication Services
@ -436,7 +436,7 @@
</li> </li>
<li class="mb-2 cursor-pointer"> <li class="mb-2 cursor-pointer">
<a <a
href="/list/consumer-defensive-sector" href="/list/sector/consumer-defensive"
class="sm:hover:text-white text-blue-400 text-lg" class="sm:hover:text-white text-blue-400 text-lg"
> >
Consumer Defensive Consumer Defensive

View File

@ -1,43 +0,0 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getBasicMaterialsSector = async () => {
const postData = { filterList: "basic-materials" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "basic-materials" };
const response = await fetch(apiURL + "/historical-sector-price", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getBasicMaterialsSector: await getBasicMaterialsSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,410 +0,0 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { screenWidth } from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import InfoModal from "$lib/components/InfoModal.svelte";
import { onMount } from "svelte";
import { Chart } from "svelte-echarts";
import { init, use } from "echarts/core";
import { BarChart } from "echarts/charts";
import { GridComponent, TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
export let data;
let isLoaded = false;
use([BarChart, GridComponent, TooltipComponent, CanvasRenderer]);
let rawData = data?.getBasicMaterialsSector;
let historicalPrice = data?.getHistoricalSector;
let marketCapList = rawData?.slice(0, 50);
let optionsData;
async function handleScroll() {
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
if (isBottom && marketCapList?.length !== rawData?.length) {
const nextIndex = marketCapList?.length;
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
marketCapList = [...marketCapList, ...filteredNewResults];
}
}
function getPlotOptions() {
let dates = [];
let priceList = [];
// Iterate over the data and extract required information
historicalPrice?.forEach((item) => {
dates?.push(item?.date);
priceList?.push(item?.changesPercentage);
});
const option = {
silent: true,
tooltip: {
trigger: "axis",
hideDelay: 100, // Set the delay in milliseconds
},
animation: false,
grid: {
left: "0%",
right: "2%",
bottom: "2%",
top: "5%",
containLabel: true,
},
xAxis: {
type: "category",
boundaryGap: false,
data: dates,
axisLabel: {
color: "#fff",
},
},
yAxis: [
{
type: "value",
splitLine: {
show: false, // Disable x-axis grid lines
},
axisLabel: {
color: "#fff",
formatter: function (value, index) {
if (index % 2 === 0) {
return value?.toFixed(2) + "%"; // Format the sentiment value
} else {
return ""; // Hide this tick
}
},
},
},
],
series: [
{
name: "Daily Change [%]",
data: priceList,
type: "bar",
itemStyle: {
color: (params) => {
// Set color based on positive or negative value
return params.data >= 0 ? "#22C55E" : "#F71F4F";
},
},
},
],
};
return option;
}
onMount(async () => {
optionsData = await getPlotOptions();
isLoaded = true;
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
});
let totalMarketCap =
rawData?.reduce((total, stock) => total + stock?.marketCap, 0) ?? 0;
let totalRevenue =
rawData?.reduce((total, stock) => total + stock?.revenue, 0) ?? 0;
let totalProfits =
rawData?.reduce((total, stock) => total + stock?.netIncome, 0) ?? 0;
$: charNumber = $screenWidth < 640 ? 15 : 20;
</script>
<section class="w-full overflow-hidden m-auto">
<div
class="border border-gray-800 w-full sm:flex sm:flex-row sm:items-center m-auto text-gray-100 bg-[#09090B] sm:rounded-lg h-auto p-5 mb-4"
>
<svg
class="w-5 h-5 inline-block sm:mr-2 flex-shrink-0"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 256 256"
><path
fill="#a474f6"
d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m-4 48a12 12 0 1 1-12 12a12 12 0 0 1 12-12m12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16a16 16 0 0 1 16 16v40a8 8 0 0 1 0 16"
/></svg
>
A complete list of companies in the Basic Materials Sector that are publicly
traded on the US stock exchange.
</div>
<div
class="mb-4 grid grid-cols-2 divide-y divide-gray-600 rounded-lg border border-gray-600 bg-[#272727] shadow md:grid-cols-3 divide-x"
>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="stocksInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Stocks
<InfoModal
title={"Stocks"}
content={"The total number of companies who operate in this sector."}
id={"stocksInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{rawData?.length}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="marketCapModal"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Market Cap
<InfoModal
title={"Market Cap"}
content={"Combined market cap of all companies in this sector."}
id={"marketCapModal"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalMarketCap, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="revenueInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Revenue
<InfoModal
title={"Revenue"}
content={"The total revenue of all companies in this sector."}
id={"revenueInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalRevenue, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitsInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profits
<InfoModal
title={"Profits"}
content={"The total net income of all companies in this sector."}
id={"profitsInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalProfits, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitMarginInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profit Margin
<InfoModal
title={"Profit Margin"}
content={"The industry's profit margin, calculated by dividing the total net income by the total revenue."}
id={"profitMarginInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{((totalProfits / totalRevenue) * 100)?.toFixed(2)}%
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="peRatioInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
PE Ratio
<InfoModal
title={"PE Ratio"}
content={"The industry's PE Ratio, calculated by dividing the total market cap by the total net income."}
id={"peRatioInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{(totalMarketCap / totalProfits)?.toFixed(2)}
</div>
</div>
</div>
</div>
<h2 class="text-white text-xl sm:text-2xl mt-8 font-semibold">
Historical Performance
</h2>
<div class="app w-full h-[300px] mt-5 mb-8">
{#if isLoaded}
<Chart {init} options={optionsData} class="chart" />
{:else}
<div class="flex justify-center items-center h-80">
<div class="relative">
<label
class="bg-[#09090B] rounded-xl h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
>
<span class="loading loading-spinner loading-md text-gray-400"
></span>
</label>
</div>
</div>
{/if}
</div>
<!-- Page wrapper -->
<div class="flex justify-center w-full m-auto h-full overflow-hidden">
<!-- Content area -->
<div class="w-full overflow-x-scroll">
<table
class="table table-sm sm:table-md table-compact rounded-none sm:rounded-md w-full border-bg-[#09090B] m-auto mt-4"
>
<thead>
<tr class="border border-slate-800">
<th class="text-white font-semibold text-[1rem]">Symbol</th>
<th class="text-white font-semibold text-[1rem]">Company</th>
<th class="text-white font-semibold text-end text-[1rem]"
>Market Cap</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Revenue</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Profits</th
>
<th class="text-white font-semibold text-[1rem] text-end">Price</th>
</tr>
</thead>
<tbody>
{#each marketCapList as item, index}
<!-- row -->
<tr
on:click={() => goto("/stocks/" + item?.symbol)}
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"
>
<td
class="text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.symbol}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.name?.length > charNumber
? item?.name?.slice(0, charNumber) + "..."
: item?.name}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-end border-b-[#09090B]"
>
{abbreviateNumber(item?.marketCap, true)}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.revenue !== null
? abbreviateNumber(item?.revenue, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.netIncome !== null
? abbreviateNumber(item?.netIncome, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
<div class="flex flex-row justify-end items-center">
<div class="flex flex-col">
<span class="text-white ml-auto"
>${item.price?.toFixed(2)}</span
>
<div class="flex flex-row mt-0.5 ml-auto">
{#if item.changesPercentage >= 0}
<span class="text-[#00FC50]"
>+{item.changesPercentage?.toFixed(2)}%</span
>
{:else}
<span class="text-[#FF2F1F]"
>{item.changesPercentage?.toFixed(2)}%
</span>
{/if}
</div>
</div>
</div>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
</section>
<style>
.app {
height: 300px;
max-width: 100%; /* Ensure chart width doesn't exceed the container */
}
@media (max-width: 640px) {
.app {
height: 210px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -1,43 +0,0 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getCommunicationServicesSector = async () => {
const postData = { filterList: "communication-services" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "communication-services" };
const response = await fetch(apiURL + "/historical-sector-price", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getCommunicationServicesSector: await getCommunicationServicesSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,410 +0,0 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { screenWidth } from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import InfoModal from "$lib/components/InfoModal.svelte";
import { onMount } from "svelte";
import { Chart } from "svelte-echarts";
import { init, use } from "echarts/core";
import { BarChart } from "echarts/charts";
import { GridComponent, TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
export let data;
let isLoaded = false;
use([BarChart, GridComponent, TooltipComponent, CanvasRenderer]);
let rawData = data?.getCommunicationServicesSector;
let historicalPrice = data?.getHistoricalSector;
let marketCapList = rawData?.slice(0, 50);
let optionsData;
async function handleScroll() {
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
if (isBottom && marketCapList?.length !== rawData?.length) {
const nextIndex = marketCapList?.length;
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
marketCapList = [...marketCapList, ...filteredNewResults];
}
}
function getPlotOptions() {
let dates = [];
let priceList = [];
// Iterate over the data and extract required information
historicalPrice?.forEach((item) => {
dates?.push(item?.date);
priceList?.push(item?.changesPercentage);
});
const option = {
silent: true,
tooltip: {
trigger: "axis",
hideDelay: 100, // Set the delay in milliseconds
},
animation: false,
grid: {
left: "0%",
right: "2%",
bottom: "2%",
top: "5%",
containLabel: true,
},
xAxis: {
type: "category",
boundaryGap: false,
data: dates,
axisLabel: {
color: "#fff",
},
},
yAxis: [
{
type: "value",
splitLine: {
show: false, // Disable x-axis grid lines
},
axisLabel: {
color: "#fff",
formatter: function (value, index) {
if (index % 2 === 0) {
return value?.toFixed(2) + "%"; // Format the sentiment value
} else {
return ""; // Hide this tick
}
},
},
},
],
series: [
{
name: "Daily Change [%]",
data: priceList,
type: "bar",
itemStyle: {
color: (params) => {
// Set color based on positive or negative value
return params.data >= 0 ? "#22C55E" : "#F71F4F";
},
},
},
],
};
return option;
}
onMount(async () => {
optionsData = await getPlotOptions();
isLoaded = true;
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
});
let totalMarketCap =
rawData?.reduce((total, stock) => total + stock?.marketCap, 0) ?? 0;
let totalRevenue =
rawData?.reduce((total, stock) => total + stock?.revenue, 0) ?? 0;
let totalProfits =
rawData?.reduce((total, stock) => total + stock?.netIncome, 0) ?? 0;
$: charNumber = $screenWidth < 640 ? 15 : 20;
</script>
<section class="w-full overflow-hidden m-auto">
<div
class="border border-gray-800 w-full sm:flex sm:flex-row sm:items-center m-auto text-gray-100 bg-[#09090B] sm:rounded-lg h-auto p-5 mb-4"
>
<svg
class="w-5 h-5 inline-block sm:mr-2 flex-shrink-0"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 256 256"
><path
fill="#a474f6"
d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m-4 48a12 12 0 1 1-12 12a12 12 0 0 1 12-12m12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16a16 16 0 0 1 16 16v40a8 8 0 0 1 0 16"
/></svg
>
A complete list of companies in the Communication Services Sector that are publicly
traded on the US stock exchange.
</div>
<div
class="mb-4 grid grid-cols-2 divide-y divide-gray-600 rounded-lg border border-gray-600 bg-[#272727] shadow md:grid-cols-3 divide-x"
>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="stocksInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Stocks
<InfoModal
title={"Stocks"}
content={"The total number of companies who operate in this sector."}
id={"stocksInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{rawData?.length}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="marketCapModal"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Market Cap
<InfoModal
title={"Market Cap"}
content={"Combined market cap of all companies in this sector."}
id={"marketCapModal"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalMarketCap, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="revenueInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Revenue
<InfoModal
title={"Revenue"}
content={"The total revenue of all companies in this sector."}
id={"revenueInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalRevenue, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitsInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profits
<InfoModal
title={"Profits"}
content={"The total net income of all companies in this sector."}
id={"profitsInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalProfits, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitMarginInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profit Margin
<InfoModal
title={"Profit Margin"}
content={"The industry's profit margin, calculated by dividing the total net income by the total revenue."}
id={"profitMarginInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{((totalProfits / totalRevenue) * 100)?.toFixed(2)}%
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="peRatioInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
PE Ratio
<InfoModal
title={"PE Ratio"}
content={"The industry's PE Ratio, calculated by dividing the total market cap by the total net income."}
id={"peRatioInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{(totalMarketCap / totalProfits)?.toFixed(2)}
</div>
</div>
</div>
</div>
<h2 class="text-white text-xl sm:text-2xl mt-8 font-semibold">
Historical Performance
</h2>
<div class="app w-full h-[300px] mt-5 mb-8">
{#if isLoaded}
<Chart {init} options={optionsData} class="chart" />
{:else}
<div class="flex justify-center items-center h-80">
<div class="relative">
<label
class="bg-[#09090B] rounded-xl h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
>
<span class="loading loading-spinner loading-md text-gray-400"
></span>
</label>
</div>
</div>
{/if}
</div>
<!-- Page wrapper -->
<div class="flex justify-center w-full m-auto h-full overflow-hidden">
<!-- Content area -->
<div class="w-full overflow-x-scroll">
<table
class="table table-sm sm:table-md table-compact rounded-none sm:rounded-md w-full border-bg-[#09090B] m-auto mt-4"
>
<thead>
<tr class="border border-slate-800">
<th class="text-white font-semibold text-[1rem]">Symbol</th>
<th class="text-white font-semibold text-[1rem]">Company</th>
<th class="text-white font-semibold text-end text-[1rem]"
>Market Cap</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Revenue</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Profits</th
>
<th class="text-white font-semibold text-[1rem] text-end">Price</th>
</tr>
</thead>
<tbody>
{#each marketCapList as item, index}
<!-- row -->
<tr
on:click={() => goto("/stocks/" + item?.symbol)}
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"
>
<td
class="text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.symbol}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.name?.length > charNumber
? item?.name?.slice(0, charNumber) + "..."
: item?.name}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-end border-b-[#09090B]"
>
{abbreviateNumber(item?.marketCap, true)}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.revenue !== null
? abbreviateNumber(item?.revenue, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.netIncome !== null
? abbreviateNumber(item?.netIncome, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
<div class="flex flex-row justify-end items-center">
<div class="flex flex-col">
<span class="text-white ml-auto"
>${item.price?.toFixed(2)}</span
>
<div class="flex flex-row mt-0.5 ml-auto">
{#if item.changesPercentage >= 0}
<span class="text-[#00FC50]"
>+{item.changesPercentage?.toFixed(2)}%</span
>
{:else}
<span class="text-[#FF2F1F]"
>{item.changesPercentage?.toFixed(2)}%
</span>
{/if}
</div>
</div>
</div>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
</section>
<style>
.app {
height: 300px;
max-width: 100%; /* Ensure chart width doesn't exceed the container */
}
@media (max-width: 640px) {
.app {
height: 210px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -1,43 +0,0 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getConsumerCyclicalSector = async () => {
const postData = { filterList: "consumer-cyclical" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "consumer-cyclical" };
const response = await fetch(apiURL + "/historical-sector-price", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getConsumerCyclicalSector: await getConsumerCyclicalSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,410 +0,0 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { screenWidth } from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import InfoModal from "$lib/components/InfoModal.svelte";
import { onMount } from "svelte";
import { Chart } from "svelte-echarts";
import { init, use } from "echarts/core";
import { BarChart } from "echarts/charts";
import { GridComponent, TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
export let data;
let isLoaded = false;
use([BarChart, GridComponent, TooltipComponent, CanvasRenderer]);
let rawData = data?.getConsumerCyclicalSector;
let historicalPrice = data?.getHistoricalSector;
let marketCapList = rawData?.slice(0, 50);
let optionsData;
async function handleScroll() {
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
if (isBottom && marketCapList?.length !== rawData?.length) {
const nextIndex = marketCapList?.length;
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
marketCapList = [...marketCapList, ...filteredNewResults];
}
}
function getPlotOptions() {
let dates = [];
let priceList = [];
// Iterate over the data and extract required information
historicalPrice?.forEach((item) => {
dates?.push(item?.date);
priceList?.push(item?.changesPercentage);
});
const option = {
silent: true,
tooltip: {
trigger: "axis",
hideDelay: 100, // Set the delay in milliseconds
},
animation: false,
grid: {
left: "0%",
right: "2%",
bottom: "2%",
top: "5%",
containLabel: true,
},
xAxis: {
type: "category",
boundaryGap: false,
data: dates,
axisLabel: {
color: "#fff",
},
},
yAxis: [
{
type: "value",
splitLine: {
show: false, // Disable x-axis grid lines
},
axisLabel: {
color: "#fff",
formatter: function (value, index) {
if (index % 2 === 0) {
return value?.toFixed(2) + "%"; // Format the sentiment value
} else {
return ""; // Hide this tick
}
},
},
},
],
series: [
{
name: "Daily Change [%]",
data: priceList,
type: "bar",
itemStyle: {
color: (params) => {
// Set color based on positive or negative value
return params.data >= 0 ? "#00FC50" : "#FF2F1F";
},
},
},
],
};
return option;
}
onMount(async () => {
optionsData = await getPlotOptions();
isLoaded = true;
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
});
let totalMarketCap =
rawData?.reduce((total, stock) => total + stock?.marketCap, 0) ?? 0;
let totalRevenue =
rawData?.reduce((total, stock) => total + stock?.revenue, 0) ?? 0;
let totalProfits =
rawData?.reduce((total, stock) => total + stock?.netIncome, 0) ?? 0;
$: charNumber = $screenWidth < 640 ? 15 : 20;
</script>
<section class="w-full overflow-hidden m-auto">
<div
class="border border-gray-800 w-full sm:flex sm:flex-row sm:items-center m-auto text-gray-100 bg-[#09090B] sm:rounded-lg h-auto p-5 mb-4"
>
<svg
class="w-5 h-5 inline-block sm:mr-2 flex-shrink-0"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 256 256"
><path
fill="#a474f6"
d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m-4 48a12 12 0 1 1-12 12a12 12 0 0 1 12-12m12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16a16 16 0 0 1 16 16v40a8 8 0 0 1 0 16"
/></svg
>
A complete list of companies in the Consumer Cyclical Sector that are publicly
traded on the US stock exchange.
</div>
<div
class="mb-4 grid grid-cols-2 divide-y divide-gray-600 rounded-lg border border-gray-600 bg-[#272727] shadow md:grid-cols-3 divide-x"
>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="stocksInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Stocks
<InfoModal
title={"Stocks"}
content={"The total number of companies who operate in this sector."}
id={"stocksInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{rawData?.length}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="marketCapModal"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Market Cap
<InfoModal
title={"Market Cap"}
content={"Combined market cap of all companies in this sector."}
id={"marketCapModal"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalMarketCap, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="revenueInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Revenue
<InfoModal
title={"Revenue"}
content={"The total revenue of all companies in this sector."}
id={"revenueInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalRevenue, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitsInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profits
<InfoModal
title={"Profits"}
content={"The total net income of all companies in this sector."}
id={"profitsInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalProfits, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitMarginInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profit Margin
<InfoModal
title={"Profit Margin"}
content={"The industry's profit margin, calculated by dividing the total net income by the total revenue."}
id={"profitMarginInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{((totalProfits / totalRevenue) * 100)?.toFixed(2)}%
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="peRatioInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
PE Ratio
<InfoModal
title={"PE Ratio"}
content={"The industry's PE Ratio, calculated by dividing the total market cap by the total net income."}
id={"peRatioInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{(totalMarketCap / totalProfits)?.toFixed(2)}
</div>
</div>
</div>
</div>
<h2 class="text-white text-xl sm:text-2xl mt-8 font-semibold">
Historical Performance
</h2>
<div class="app w-full h-[300px] mt-5 mb-8">
{#if isLoaded}
<Chart {init} options={optionsData} class="chart" />
{:else}
<div class="flex justify-center items-center h-80">
<div class="relative">
<label
class="bg-[#09090B] rounded-xl h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
>
<span class="loading loading-spinner loading-md text-gray-400"
></span>
</label>
</div>
</div>
{/if}
</div>
<!-- Page wrapper -->
<div class="flex justify-center w-full m-auto h-full overflow-hidden">
<!-- Content area -->
<div class="w-full overflow-x-scroll">
<table
class="table table-sm sm:table-md table-compact rounded-none sm:rounded-md w-full border-bg-[#09090B] m-auto mt-4"
>
<thead>
<tr class="border border-slate-800">
<th class="text-white font-semibold text-[1rem]">Symbol</th>
<th class="text-white font-semibold text-[1rem]">Company</th>
<th class="text-white font-semibold text-end text-[1rem]"
>Market Cap</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Revenue</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Profits</th
>
<th class="text-white font-semibold text-[1rem] text-end">Price</th>
</tr>
</thead>
<tbody>
{#each marketCapList as item, index}
<!-- row -->
<tr
on:click={() => goto("/stocks/" + item?.symbol)}
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"
>
<td
class="text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.symbol}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.name?.length > charNumber
? item?.name?.slice(0, charNumber) + "..."
: item?.name}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-end border-b-[#09090B]"
>
{abbreviateNumber(item?.marketCap, true)}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.revenue !== null
? abbreviateNumber(item?.revenue, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.netIncome !== null
? abbreviateNumber(item?.netIncome, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
<div class="flex flex-row justify-end items-center">
<div class="flex flex-col">
<span class="text-white ml-auto"
>${item.price?.toFixed(2)}</span
>
<div class="flex flex-row mt-0.5 ml-auto">
{#if item.changesPercentage >= 0}
<span class="text-[#00FC50]"
>+{item.changesPercentage?.toFixed(2)}%</span
>
{:else}
<span class="text-[#FF2F1F]"
>{item.changesPercentage?.toFixed(2)}%
</span>
{/if}
</div>
</div>
</div>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
</section>
<style>
.app {
height: 300px;
max-width: 100%; /* Ensure chart width doesn't exceed the container */
}
@media (max-width: 640px) {
.app {
height: 210px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -1,43 +0,0 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getConsumerDefensiveSector = async () => {
const postData = { filterList: "consumer-defensive" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "consumer-defensive" };
const response = await fetch(apiURL + "/historical-sector-price", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getConsumerDefensiveSector: await getConsumerDefensiveSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,410 +0,0 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { screenWidth } from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import InfoModal from "$lib/components/InfoModal.svelte";
import { onMount } from "svelte";
import { Chart } from "svelte-echarts";
import { init, use } from "echarts/core";
import { BarChart } from "echarts/charts";
import { GridComponent, TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
export let data;
let isLoaded = false;
use([BarChart, GridComponent, TooltipComponent, CanvasRenderer]);
let rawData = data?.getConsumerDefensiveSector;
let historicalPrice = data?.getHistoricalSector;
let marketCapList = rawData?.slice(0, 50);
let optionsData;
async function handleScroll() {
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
if (isBottom && marketCapList?.length !== rawData?.length) {
const nextIndex = marketCapList?.length;
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
marketCapList = [...marketCapList, ...filteredNewResults];
}
}
function getPlotOptions() {
let dates = [];
let priceList = [];
// Iterate over the data and extract required information
historicalPrice?.forEach((item) => {
dates?.push(item?.date);
priceList?.push(item?.changesPercentage);
});
const option = {
silent: true,
tooltip: {
trigger: "axis",
hideDelay: 100, // Set the delay in milliseconds
},
animation: false,
grid: {
left: "0%",
right: "2%",
bottom: "2%",
top: "5%",
containLabel: true,
},
xAxis: {
type: "category",
boundaryGap: false,
data: dates,
axisLabel: {
color: "#fff",
},
},
yAxis: [
{
type: "value",
splitLine: {
show: false, // Disable x-axis grid lines
},
axisLabel: {
color: "#fff",
formatter: function (value, index) {
if (index % 2 === 0) {
return value?.toFixed(2) + "%"; // Format the sentiment value
} else {
return ""; // Hide this tick
}
},
},
},
],
series: [
{
name: "Daily Change [%]",
data: priceList,
type: "bar",
itemStyle: {
color: (params) => {
// Set color based on positive or negative value
return params.data >= 0 ? "#22C55E" : "#F71F4F";
},
},
},
],
};
return option;
}
onMount(async () => {
optionsData = await getPlotOptions();
isLoaded = true;
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
});
let totalMarketCap =
rawData?.reduce((total, stock) => total + stock?.marketCap, 0) ?? 0;
let totalRevenue =
rawData?.reduce((total, stock) => total + stock?.revenue, 0) ?? 0;
let totalProfits =
rawData?.reduce((total, stock) => total + stock?.netIncome, 0) ?? 0;
$: charNumber = $screenWidth < 640 ? 15 : 20;
</script>
<section class="w-full overflow-hidden m-auto">
<div
class="border border-gray-800 w-full sm:flex sm:flex-row sm:items-center m-auto text-gray-100 bg-[#09090B] sm:rounded-lg h-auto p-5 mb-4"
>
<svg
class="w-5 h-5 inline-block sm:mr-2 flex-shrink-0"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 256 256"
><path
fill="#a474f6"
d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m-4 48a12 12 0 1 1-12 12a12 12 0 0 1 12-12m12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16a16 16 0 0 1 16 16v40a8 8 0 0 1 0 16"
/></svg
>
A complete list of companies in the Consumer Defensive Sector that are publicly
traded on the US stock exchange.
</div>
<div
class="mb-4 grid grid-cols-2 divide-y divide-gray-600 rounded-lg border border-gray-600 bg-[#272727] shadow md:grid-cols-3 divide-x"
>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="stocksInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Stocks
<InfoModal
title={"Stocks"}
content={"The total number of companies who operate in this sector."}
id={"stocksInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{rawData?.length}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="marketCapModal"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Market Cap
<InfoModal
title={"Market Cap"}
content={"Combined market cap of all companies in this sector."}
id={"marketCapModal"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalMarketCap, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="revenueInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Revenue
<InfoModal
title={"Revenue"}
content={"The total revenue of all companies in this sector."}
id={"revenueInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalRevenue, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitsInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profits
<InfoModal
title={"Profits"}
content={"The total net income of all companies in this sector."}
id={"profitsInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalProfits, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitMarginInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profit Margin
<InfoModal
title={"Profit Margin"}
content={"The industry's profit margin, calculated by dividing the total net income by the total revenue."}
id={"profitMarginInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{((totalProfits / totalRevenue) * 100)?.toFixed(2)}%
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="peRatioInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
PE Ratio
<InfoModal
title={"PE Ratio"}
content={"The industry's PE Ratio, calculated by dividing the total market cap by the total net income."}
id={"peRatioInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{(totalMarketCap / totalProfits)?.toFixed(2)}
</div>
</div>
</div>
</div>
<h2 class="text-white text-xl sm:text-2xl mt-8 font-semibold">
Historical Performance
</h2>
<div class="app w-full h-[300px] mt-5 mb-8">
{#if isLoaded}
<Chart {init} options={optionsData} class="chart" />
{:else}
<div class="flex justify-center items-center h-80">
<div class="relative">
<label
class="bg-[#09090B] rounded-xl h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
>
<span class="loading loading-spinner loading-md text-gray-400"
></span>
</label>
</div>
</div>
{/if}
</div>
<!-- Page wrapper -->
<div class="flex justify-center w-full m-auto h-full overflow-hidden">
<!-- Content area -->
<div class="w-full overflow-x-scroll">
<table
class="table table-sm sm:table-md table-compact rounded-none sm:rounded-md w-full border-bg-[#09090B] m-auto mt-4"
>
<thead>
<tr class="border border-slate-800">
<th class="text-white font-semibold text-[1rem]">Symbol</th>
<th class="text-white font-semibold text-[1rem]">Company</th>
<th class="text-white font-semibold text-end text-[1rem]"
>Market Cap</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Revenue</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Profits</th
>
<th class="text-white font-semibold text-[1rem] text-end">Price</th>
</tr>
</thead>
<tbody>
{#each marketCapList as item, index}
<!-- row -->
<tr
on:click={() => goto("/stocks/" + item?.symbol)}
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"
>
<td
class="text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.symbol}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.name?.length > charNumber
? item?.name?.slice(0, charNumber) + "..."
: item?.name}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-end border-b-[#09090B]"
>
{abbreviateNumber(item?.marketCap, true)}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.revenue !== null
? abbreviateNumber(item?.revenue, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.netIncome !== null
? abbreviateNumber(item?.netIncome, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
<div class="flex flex-row justify-end items-center">
<div class="flex flex-col">
<span class="text-white ml-auto"
>${item.price?.toFixed(2)}</span
>
<div class="flex flex-row mt-0.5 ml-auto">
{#if item.changesPercentage >= 0}
<span class="text-[#00FC50]"
>+{item.changesPercentage?.toFixed(2)}%</span
>
{:else}
<span class="text-[#FF2F1F]"
>{item.changesPercentage?.toFixed(2)}%
</span>
{/if}
</div>
</div>
</div>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
</section>
<style>
.app {
height: 300px;
max-width: 100%; /* Ensure chart width doesn't exceed the container */
}
@media (max-width: 640px) {
.app {
height: 210px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -1,43 +0,0 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getEnergySector = async () => {
const postData = { filterList: "energy" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "energy" };
const response = await fetch(apiURL + "/historical-sector-price", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getEnergySector: await getEnergySector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,410 +0,0 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { screenWidth } from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import InfoModal from "$lib/components/InfoModal.svelte";
import { onMount } from "svelte";
import { Chart } from "svelte-echarts";
import { init, use } from "echarts/core";
import { BarChart } from "echarts/charts";
import { GridComponent, TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
export let data;
let isLoaded = false;
use([BarChart, GridComponent, TooltipComponent, CanvasRenderer]);
let rawData = data?.getEnergySector;
let historicalPrice = data?.getHistoricalSector;
let marketCapList = rawData?.slice(0, 50);
let optionsData;
async function handleScroll() {
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
if (isBottom && marketCapList?.length !== rawData?.length) {
const nextIndex = marketCapList?.length;
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
marketCapList = [...marketCapList, ...filteredNewResults];
}
}
function getPlotOptions() {
let dates = [];
let priceList = [];
// Iterate over the data and extract required information
historicalPrice?.forEach((item) => {
dates?.push(item?.date);
priceList?.push(item?.changesPercentage);
});
const option = {
silent: true,
tooltip: {
trigger: "axis",
hideDelay: 100, // Set the delay in milliseconds
},
animation: false,
grid: {
left: "0%",
right: "2%",
bottom: "2%",
top: "5%",
containLabel: true,
},
xAxis: {
type: "category",
boundaryGap: false,
data: dates,
axisLabel: {
color: "#fff",
},
},
yAxis: [
{
type: "value",
splitLine: {
show: false, // Disable x-axis grid lines
},
axisLabel: {
color: "#fff",
formatter: function (value, index) {
if (index % 2 === 0) {
return value?.toFixed(2) + "%"; // Format the sentiment value
} else {
return ""; // Hide this tick
}
},
},
},
],
series: [
{
name: "Daily Change [%]",
data: priceList,
type: "bar",
itemStyle: {
color: (params) => {
// Set color based on positive or negative value
return params.data >= 0 ? "#22C55E" : "#F71F4F";
},
},
},
],
};
return option;
}
onMount(async () => {
optionsData = await getPlotOptions();
isLoaded = true;
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
});
let totalMarketCap =
rawData?.reduce((total, stock) => total + stock?.marketCap, 0) ?? 0;
let totalRevenue =
rawData?.reduce((total, stock) => total + stock?.revenue, 0) ?? 0;
let totalProfits =
rawData?.reduce((total, stock) => total + stock?.netIncome, 0) ?? 0;
$: charNumber = $screenWidth < 640 ? 15 : 20;
</script>
<section class="w-full overflow-hidden m-auto">
<div
class="border border-gray-800 w-full sm:flex sm:flex-row sm:items-center m-auto text-gray-100 bg-[#09090B] sm:rounded-lg h-auto p-5 mb-4"
>
<svg
class="w-5 h-5 inline-block sm:mr-2 flex-shrink-0"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 256 256"
><path
fill="#a474f6"
d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m-4 48a12 12 0 1 1-12 12a12 12 0 0 1 12-12m12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16a16 16 0 0 1 16 16v40a8 8 0 0 1 0 16"
/></svg
>
A complete list of companies in the Energy Sector that are publicly traded on
the US stock exchange.
</div>
<div
class="mb-4 grid grid-cols-2 divide-y divide-gray-600 rounded-lg border border-gray-600 bg-[#272727] shadow md:grid-cols-3 divide-x"
>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="stocksInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Stocks
<InfoModal
title={"Stocks"}
content={"The total number of companies who operate in this sector."}
id={"stocksInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{rawData?.length}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="marketCapModal"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Market Cap
<InfoModal
title={"Market Cap"}
content={"Combined market cap of all companies in this sector."}
id={"marketCapModal"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalMarketCap, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="revenueInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Revenue
<InfoModal
title={"Revenue"}
content={"The total revenue of all companies in this sector."}
id={"revenueInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalRevenue, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitsInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profits
<InfoModal
title={"Profits"}
content={"The total net income of all companies in this sector."}
id={"profitsInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalProfits, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitMarginInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profit Margin
<InfoModal
title={"Profit Margin"}
content={"The industry's profit margin, calculated by dividing the total net income by the total revenue."}
id={"profitMarginInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{((totalProfits / totalRevenue) * 100)?.toFixed(2)}%
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="peRatioInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
PE Ratio
<InfoModal
title={"PE Ratio"}
content={"The industry's PE Ratio, calculated by dividing the total market cap by the total net income."}
id={"peRatioInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{(totalMarketCap / totalProfits)?.toFixed(2)}
</div>
</div>
</div>
</div>
<h2 class="text-white text-xl sm:text-2xl mt-8 font-semibold">
Historical Performance
</h2>
<div class="app w-full h-[300px] mt-5 mb-8">
{#if isLoaded}
<Chart {init} options={optionsData} class="chart" />
{:else}
<div class="flex justify-center items-center h-80">
<div class="relative">
<label
class="bg-[#09090B] rounded-xl h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
>
<span class="loading loading-spinner loading-md text-gray-400"
></span>
</label>
</div>
</div>
{/if}
</div>
<!-- Page wrapper -->
<div class="flex justify-center w-full m-auto h-full overflow-hidden">
<!-- Content area -->
<div class="w-full overflow-x-scroll">
<table
class="table table-sm sm:table-md table-compact rounded-none sm:rounded-md w-full border-bg-[#09090B] m-auto mt-4"
>
<thead>
<tr class="border border-slate-800">
<th class="text-white font-semibold text-[1rem]">Symbol</th>
<th class="text-white font-semibold text-[1rem]">Company</th>
<th class="text-white font-semibold text-end text-[1rem]"
>Market Cap</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Revenue</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Profits</th
>
<th class="text-white font-semibold text-[1rem] text-end">Price</th>
</tr>
</thead>
<tbody>
{#each marketCapList as item, index}
<!-- row -->
<tr
on:click={() => goto("/stocks/" + item?.symbol)}
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"
>
<td
class="text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.symbol}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.name?.length > charNumber
? item?.name?.slice(0, charNumber) + "..."
: item?.name}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-end border-b-[#09090B]"
>
{abbreviateNumber(item?.marketCap, true)}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.revenue !== null
? abbreviateNumber(item?.revenue, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.netIncome !== null
? abbreviateNumber(item?.netIncome, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
<div class="flex flex-row justify-end items-center">
<div class="flex flex-col">
<span class="text-white ml-auto"
>${item.price?.toFixed(2)}</span
>
<div class="flex flex-row mt-0.5 ml-auto">
{#if item.changesPercentage >= 0}
<span class="text-[#00FC50]"
>+{item.changesPercentage?.toFixed(2)}%</span
>
{:else}
<span class="text-[#FF2F1F]"
>{item.changesPercentage?.toFixed(2)}%
</span>
{/if}
</div>
</div>
</div>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
</section>
<style>
.app {
height: 300px;
max-width: 100%; /* Ensure chart width doesn't exceed the container */
}
@media (max-width: 640px) {
.app {
height: 210px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -1,410 +0,0 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { screenWidth } from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import InfoModal from "$lib/components/InfoModal.svelte";
import { onMount } from "svelte";
import { Chart } from "svelte-echarts";
import { init, use } from "echarts/core";
import { BarChart } from "echarts/charts";
import { GridComponent, TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
export let data;
let isLoaded = false;
use([BarChart, GridComponent, TooltipComponent, CanvasRenderer]);
let rawData = data?.getFinancialSector;
let historicalPrice = data?.getHistoricalSector;
let marketCapList = rawData?.slice(0, 50);
let optionsData;
async function handleScroll() {
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
if (isBottom && marketCapList?.length !== rawData?.length) {
const nextIndex = marketCapList?.length;
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
marketCapList = [...marketCapList, ...filteredNewResults];
}
}
function getPlotOptions() {
let dates = [];
let priceList = [];
// Iterate over the data and extract required information
historicalPrice?.forEach((item) => {
dates?.push(item?.date);
priceList?.push(item?.changesPercentage);
});
const option = {
silent: true,
tooltip: {
trigger: "axis",
hideDelay: 100, // Set the delay in milliseconds
},
animation: false,
grid: {
left: "0%",
right: "2%",
bottom: "2%",
top: "5%",
containLabel: true,
},
xAxis: {
type: "category",
boundaryGap: false,
data: dates,
axisLabel: {
color: "#fff",
},
},
yAxis: [
{
type: "value",
splitLine: {
show: false, // Disable x-axis grid lines
},
axisLabel: {
color: "#fff",
formatter: function (value, index) {
if (index % 2 === 0) {
return value?.toFixed(2) + "%"; // Format the sentiment value
} else {
return ""; // Hide this tick
}
},
},
},
],
series: [
{
name: "Daily Change [%]",
data: priceList,
type: "bar",
itemStyle: {
color: (params) => {
// Set color based on positive or negative value
return params.data >= 0 ? "#22C55E" : "#F71F4F";
},
},
},
],
};
return option;
}
onMount(async () => {
optionsData = await getPlotOptions();
isLoaded = true;
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
});
let totalMarketCap =
rawData?.reduce((total, stock) => total + stock?.marketCap, 0) ?? 0;
let totalRevenue =
rawData?.reduce((total, stock) => total + stock?.revenue, 0) ?? 0;
let totalProfits =
rawData?.reduce((total, stock) => total + stock?.netIncome, 0) ?? 0;
$: charNumber = $screenWidth < 640 ? 15 : 20;
</script>
<section class="w-full overflow-hidden m-auto">
<div
class="border border-gray-800 w-full sm:flex sm:flex-row sm:items-center m-auto text-gray-100 bg-[#09090B] sm:rounded-lg h-auto p-5 mb-4"
>
<svg
class="w-5 h-5 inline-block sm:mr-2 flex-shrink-0"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 256 256"
><path
fill="#a474f6"
d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m-4 48a12 12 0 1 1-12 12a12 12 0 0 1 12-12m12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16a16 16 0 0 1 16 16v40a8 8 0 0 1 0 16"
/></svg
>
A complete list of companies in the Financial Sector that are publicly traded
on the US stock exchange.
</div>
<div
class="mb-4 grid grid-cols-2 divide-y divide-gray-600 rounded-lg border border-gray-600 bg-[#272727] shadow md:grid-cols-3 divide-x"
>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="stocksInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Stocks
<InfoModal
title={"Stocks"}
content={"The total number of companies who operate in this sector."}
id={"stocksInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{rawData?.length}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="marketCapModal"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Market Cap
<InfoModal
title={"Market Cap"}
content={"Combined market cap of all companies in this sector."}
id={"marketCapModal"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalMarketCap, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="revenueInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Revenue
<InfoModal
title={"Revenue"}
content={"The total revenue of all companies in this sector."}
id={"revenueInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalRevenue, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitsInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profits
<InfoModal
title={"Profits"}
content={"The total net income of all companies in this sector."}
id={"profitsInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalProfits, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitMarginInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profit Margin
<InfoModal
title={"Profit Margin"}
content={"The industry's profit margin, calculated by dividing the total net income by the total revenue."}
id={"profitMarginInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{((totalProfits / totalRevenue) * 100)?.toFixed(2)}%
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="peRatioInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
PE Ratio
<InfoModal
title={"PE Ratio"}
content={"The industry's PE Ratio, calculated by dividing the total market cap by the total net income."}
id={"peRatioInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{(totalMarketCap / totalProfits)?.toFixed(2)}
</div>
</div>
</div>
</div>
<h2 class="text-white text-xl sm:text-2xl mt-8 font-semibold">
Historical Performance
</h2>
<div class="app w-full h-[300px] mt-5 mb-8">
{#if isLoaded}
<Chart {init} options={optionsData} class="chart" />
{:else}
<div class="flex justify-center items-center h-80">
<div class="relative">
<label
class="bg-[#09090B] rounded-xl h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
>
<span class="loading loading-spinner loading-md text-gray-400"
></span>
</label>
</div>
</div>
{/if}
</div>
<!-- Page wrapper -->
<div class="flex justify-center w-full m-auto h-full overflow-hidden">
<!-- Content area -->
<div class="w-full overflow-x-scroll">
<table
class="table table-sm sm:table-md table-compact rounded-none sm:rounded-md w-full border-bg-[#09090B] m-auto mt-4"
>
<thead>
<tr class="border border-slate-800">
<th class="text-white font-semibold text-[1rem]">Symbol</th>
<th class="text-white font-semibold text-[1rem]">Company</th>
<th class="text-white font-semibold text-end text-[1rem]"
>Market Cap</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Revenue</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Profits</th
>
<th class="text-white font-semibold text-[1rem] text-end">Price</th>
</tr>
</thead>
<tbody>
{#each marketCapList as item, index}
<!-- row -->
<tr
on:click={() => goto("/stocks/" + item?.symbol)}
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"
>
<td
class="text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.symbol}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.name?.length > charNumber
? item?.name?.slice(0, charNumber) + "..."
: item?.name}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-end border-b-[#09090B]"
>
{abbreviateNumber(item?.marketCap, true)}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.revenue !== null
? abbreviateNumber(item?.revenue, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.netIncome !== null
? abbreviateNumber(item?.netIncome, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
<div class="flex flex-row justify-end items-center">
<div class="flex flex-col">
<span class="text-white ml-auto"
>${item.price?.toFixed(2)}</span
>
<div class="flex flex-row mt-0.5 ml-auto">
{#if item.changesPercentage >= 0}
<span class="text-[#00FC50]"
>+{item.changesPercentage?.toFixed(2)}%</span
>
{:else}
<span class="text-[#FF2F1F]"
>{item.changesPercentage?.toFixed(2)}%
</span>
{/if}
</div>
</div>
</div>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
</section>
<style>
.app {
height: 300px;
max-width: 100%; /* Ensure chart width doesn't exceed the container */
}
@media (max-width: 640px) {
.app {
height: 210px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -1,43 +0,0 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getHealthcareSector = async () => {
const postData = { filterList: "healthcare" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "healthcare" };
const response = await fetch(apiURL + "/historical-sector-price", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getHealthcareSector: await getHealthcareSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,410 +0,0 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { screenWidth } from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import InfoModal from "$lib/components/InfoModal.svelte";
import { onMount } from "svelte";
import { Chart } from "svelte-echarts";
import { init, use } from "echarts/core";
import { BarChart } from "echarts/charts";
import { GridComponent, TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
export let data;
let isLoaded = false;
use([BarChart, GridComponent, TooltipComponent, CanvasRenderer]);
let rawData = data?.getHealthcareSector;
let historicalPrice = data?.getHistoricalSector;
let marketCapList = rawData?.slice(0, 50);
let optionsData;
async function handleScroll() {
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
if (isBottom && marketCapList?.length !== rawData?.length) {
const nextIndex = marketCapList?.length;
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
marketCapList = [...marketCapList, ...filteredNewResults];
}
}
function getPlotOptions() {
let dates = [];
let priceList = [];
// Iterate over the data and extract required information
historicalPrice?.forEach((item) => {
dates?.push(item?.date);
priceList?.push(item?.changesPercentage);
});
const option = {
silent: true,
tooltip: {
trigger: "axis",
hideDelay: 100, // Set the delay in milliseconds
},
animation: false,
grid: {
left: "0%",
right: "2%",
bottom: "2%",
top: "5%",
containLabel: true,
},
xAxis: {
type: "category",
boundaryGap: false,
data: dates,
axisLabel: {
color: "#fff",
},
},
yAxis: [
{
type: "value",
splitLine: {
show: false, // Disable x-axis grid lines
},
axisLabel: {
color: "#fff",
formatter: function (value, index) {
if (index % 2 === 0) {
return value?.toFixed(2) + "%"; // Format the sentiment value
} else {
return ""; // Hide this tick
}
},
},
},
],
series: [
{
name: "Daily Change [%]",
data: priceList,
type: "bar",
itemStyle: {
color: (params) => {
// Set color based on positive or negative value
return params.data >= 0 ? "#22C55E" : "#F71F4F";
},
},
},
],
};
return option;
}
onMount(async () => {
optionsData = await getPlotOptions();
isLoaded = true;
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
});
let totalMarketCap =
rawData?.reduce((total, stock) => total + stock?.marketCap, 0) ?? 0;
let totalRevenue =
rawData?.reduce((total, stock) => total + stock?.revenue, 0) ?? 0;
let totalProfits =
rawData?.reduce((total, stock) => total + stock?.netIncome, 0) ?? 0;
$: charNumber = $screenWidth < 640 ? 15 : 20;
</script>
<section class="w-full overflow-hidden m-auto">
<div
class="border border-gray-800 w-full sm:flex sm:flex-row sm:items-center m-auto text-gray-100 bg-[#09090B] sm:rounded-lg h-auto p-5 mb-4"
>
<svg
class="w-5 h-5 inline-block sm:mr-2 flex-shrink-0"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 256 256"
><path
fill="#a474f6"
d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m-4 48a12 12 0 1 1-12 12a12 12 0 0 1 12-12m12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16a16 16 0 0 1 16 16v40a8 8 0 0 1 0 16"
/></svg
>
A complete list of companies in the Healthcare Sector that are publicly traded
on the US stock exchange.
</div>
<div
class="mb-4 grid grid-cols-2 divide-y divide-gray-600 rounded-lg border border-gray-600 bg-[#272727] shadow md:grid-cols-3 divide-x"
>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="stocksInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Stocks
<InfoModal
title={"Stocks"}
content={"The total number of companies who operate in this sector."}
id={"stocksInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{rawData?.length}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="marketCapModal"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Market Cap
<InfoModal
title={"Market Cap"}
content={"Combined market cap of all companies in this sector."}
id={"marketCapModal"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalMarketCap, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="revenueInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Revenue
<InfoModal
title={"Revenue"}
content={"The total revenue of all companies in this sector."}
id={"revenueInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalRevenue, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitsInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profits
<InfoModal
title={"Profits"}
content={"The total net income of all companies in this sector."}
id={"profitsInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalProfits, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitMarginInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profit Margin
<InfoModal
title={"Profit Margin"}
content={"The industry's profit margin, calculated by dividing the total net income by the total revenue."}
id={"profitMarginInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{((totalProfits / totalRevenue) * 100)?.toFixed(2)}%
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="peRatioInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
PE Ratio
<InfoModal
title={"PE Ratio"}
content={"The industry's PE Ratio, calculated by dividing the total market cap by the total net income."}
id={"peRatioInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{(totalMarketCap / totalProfits)?.toFixed(2)}
</div>
</div>
</div>
</div>
<h2 class="text-white text-xl sm:text-2xl mt-8 font-semibold">
Historical Performance
</h2>
<div class="app w-full h-[300px] mt-5 mb-8">
{#if isLoaded}
<Chart {init} options={optionsData} class="chart" />
{:else}
<div class="flex justify-center items-center h-80">
<div class="relative">
<label
class="bg-[#09090B] rounded-xl h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
>
<span class="loading loading-spinner loading-md text-gray-400"
></span>
</label>
</div>
</div>
{/if}
</div>
<!-- Page wrapper -->
<div class="flex justify-center w-full m-auto h-full overflow-hidden">
<!-- Content area -->
<div class="w-full overflow-x-scroll">
<table
class="table table-sm sm:table-md table-compact rounded-none sm:rounded-md w-full border-bg-[#09090B] m-auto mt-4"
>
<thead>
<tr class="border border-slate-800">
<th class="text-white font-semibold text-[1rem]">Symbol</th>
<th class="text-white font-semibold text-[1rem]">Company</th>
<th class="text-white font-semibold text-end text-[1rem]"
>Market Cap</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Revenue</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Profits</th
>
<th class="text-white font-semibold text-[1rem] text-end">Price</th>
</tr>
</thead>
<tbody>
{#each marketCapList as item, index}
<!-- row -->
<tr
on:click={() => goto("/stocks/" + item?.symbol)}
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"
>
<td
class="text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.symbol}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.name?.length > charNumber
? item?.name?.slice(0, charNumber) + "..."
: item?.name}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-end border-b-[#09090B]"
>
{abbreviateNumber(item?.marketCap, true)}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.revenue !== null
? abbreviateNumber(item?.revenue, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.netIncome !== null
? abbreviateNumber(item?.netIncome, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
<div class="flex flex-row justify-end items-center">
<div class="flex flex-col">
<span class="text-white ml-auto"
>${item.price?.toFixed(2)}</span
>
<div class="flex flex-row mt-0.5 ml-auto">
{#if item.changesPercentage >= 0}
<span class="text-[#00FC50]"
>+{item.changesPercentage?.toFixed(2)}%</span
>
{:else}
<span class="text-[#FF2F1F]"
>{item.changesPercentage?.toFixed(2)}%
</span>
{/if}
</div>
</div>
</div>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
</section>
<style>
.app {
height: 300px;
max-width: 100%; /* Ensure chart width doesn't exceed the container */
}
@media (max-width: 640px) {
.app {
height: 210px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -4,9 +4,9 @@ export const load = async ({ locals, params }) => {
}; };
const getMarketCapCategory = async () => { const getMarketCapCategory = async () => {
const { apiKey, apiURL } = locals; const { apiKey, apiURL } = locals;
const postData = { category: params.slug }; const postData = { filterList: params.slug };
const response = await fetch(apiURL + "/cap-category", { const response = await fetch(apiURL + "/list-category", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",

View File

@ -74,7 +74,7 @@
{ key: "marketCap", label: "Market Cap", align: "right" }, { key: "marketCap", label: "Market Cap", align: "right" },
{ key: "price", label: "Price", align: "right" }, { key: "price", label: "Price", align: "right" },
{ key: "changesPercentage", label: "% Change", align: "right" }, { key: "changesPercentage", label: "% Change", align: "right" },
{ key: "revenue", label: "Revenue", align: "right" }, { key: "revenue", label: "Revenue", align: "right" },
]; ];
@ -84,7 +84,7 @@
symbol: { order: "none", type: "string" }, symbol: { order: "none", type: "string" },
name: { order: "none", type: "string" }, name: { order: "none", type: "string" },
price: { order: "none", type: "number" }, price: { order: "none", type: "number" },
changesPercentage: { order: "none", type: "number" }, changesPercentage: { order: "none", type: "number" },
marketCap: { order: "none", type: "number" }, marketCap: { order: "none", type: "number" },
revenue: { order: "none", type: "number" }, revenue: { order: "none", type: "number" },
@ -152,7 +152,7 @@
let totalRevenue = 0; let totalRevenue = 0;
$: { $: {
if ($page?.url?.pathname && typeof window !== "undefined") { if ($page?.url?.pathname) {
rawData = data?.getMarketCapCategory; rawData = data?.getMarketCapCategory;
marketCapList = rawData?.slice(0, 50); marketCapList = rawData?.slice(0, 50);

View File

@ -1,43 +0,0 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getRealEstateSector = async () => {
const postData = { filterList: "real-estate" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "real-estate" };
const response = await fetch(apiURL + "/historical-sector-price", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getRealEstateSector: await getRealEstateSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,410 +0,0 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { screenWidth } from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import InfoModal from "$lib/components/InfoModal.svelte";
import { onMount } from "svelte";
import { Chart } from "svelte-echarts";
import { init, use } from "echarts/core";
import { BarChart } from "echarts/charts";
import { GridComponent, TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
export let data;
let isLoaded = false;
use([BarChart, GridComponent, TooltipComponent, CanvasRenderer]);
let rawData = data?.getRealEstateSector;
let historicalPrice = data?.getHistoricalSector;
let marketCapList = rawData?.slice(0, 50);
let optionsData;
async function handleScroll() {
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
if (isBottom && marketCapList?.length !== rawData?.length) {
const nextIndex = marketCapList?.length;
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
marketCapList = [...marketCapList, ...filteredNewResults];
}
}
function getPlotOptions() {
let dates = [];
let priceList = [];
// Iterate over the data and extract required information
historicalPrice?.forEach((item) => {
dates?.push(item?.date);
priceList?.push(item?.changesPercentage);
});
const option = {
silent: true,
tooltip: {
trigger: "axis",
hideDelay: 100, // Set the delay in milliseconds
},
animation: false,
grid: {
left: "0%",
right: "2%",
bottom: "2%",
top: "5%",
containLabel: true,
},
xAxis: {
type: "category",
boundaryGap: false,
data: dates,
axisLabel: {
color: "#fff",
},
},
yAxis: [
{
type: "value",
splitLine: {
show: false, // Disable x-axis grid lines
},
axisLabel: {
color: "#fff",
formatter: function (value, index) {
if (index % 2 === 0) {
return value?.toFixed(2) + "%"; // Format the sentiment value
} else {
return ""; // Hide this tick
}
},
},
},
],
series: [
{
name: "Daily Change [%]",
data: priceList,
type: "bar",
itemStyle: {
color: (params) => {
// Set color based on positive or negative value
return params.data >= 0 ? "#22C55E" : "#F71F4F";
},
},
},
],
};
return option;
}
onMount(async () => {
optionsData = await getPlotOptions();
isLoaded = true;
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
});
let totalMarketCap =
rawData?.reduce((total, stock) => total + stock?.marketCap, 0) ?? 0;
let totalRevenue =
rawData?.reduce((total, stock) => total + stock?.revenue, 0) ?? 0;
let totalProfits =
rawData?.reduce((total, stock) => total + stock?.netIncome, 0) ?? 0;
$: charNumber = $screenWidth < 640 ? 15 : 20;
</script>
<section class="w-full overflow-hidden m-auto">
<div
class="border border-gray-800 w-full sm:flex sm:flex-row sm:items-center m-auto text-gray-100 bg-[#09090B] sm:rounded-lg h-auto p-5 mb-4"
>
<svg
class="w-5 h-5 inline-block sm:mr-2 flex-shrink-0"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 256 256"
><path
fill="#a474f6"
d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m-4 48a12 12 0 1 1-12 12a12 12 0 0 1 12-12m12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16a16 16 0 0 1 16 16v40a8 8 0 0 1 0 16"
/></svg
>
A complete list of companies in the Real Estate Sector that are publicly traded
on the US stock exchange.
</div>
<div
class="mb-4 grid grid-cols-2 divide-y divide-gray-600 rounded-lg border border-gray-600 bg-[#272727] shadow md:grid-cols-3 divide-x"
>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="stocksInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Stocks
<InfoModal
title={"Stocks"}
content={"The total number of companies who operate in this sector."}
id={"stocksInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{rawData?.length}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="marketCapModal"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Market Cap
<InfoModal
title={"Market Cap"}
content={"Combined market cap of all companies in this sector."}
id={"marketCapModal"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalMarketCap, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="revenueInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Revenue
<InfoModal
title={"Revenue"}
content={"The total revenue of all companies in this sector."}
id={"revenueInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalRevenue, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitsInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profits
<InfoModal
title={"Profits"}
content={"The total net income of all companies in this sector."}
id={"profitsInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalProfits, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitMarginInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profit Margin
<InfoModal
title={"Profit Margin"}
content={"The industry's profit margin, calculated by dividing the total net income by the total revenue."}
id={"profitMarginInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{((totalProfits / totalRevenue) * 100)?.toFixed(2)}%
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="peRatioInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
PE Ratio
<InfoModal
title={"PE Ratio"}
content={"The industry's PE Ratio, calculated by dividing the total market cap by the total net income."}
id={"peRatioInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{(totalMarketCap / totalProfits)?.toFixed(2)}
</div>
</div>
</div>
</div>
<h2 class="text-white text-xl sm:text-2xl mt-8 font-semibold">
Historical Performance
</h2>
<div class="app w-full h-[300px] mt-5 mb-8">
{#if isLoaded}
<Chart {init} options={optionsData} class="chart" />
{:else}
<div class="flex justify-center items-center h-80">
<div class="relative">
<label
class="bg-[#09090B] rounded-xl h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
>
<span class="loading loading-spinner loading-md text-gray-400"
></span>
</label>
</div>
</div>
{/if}
</div>
<!-- Page wrapper -->
<div class="flex justify-center w-full m-auto h-full overflow-hidden">
<!-- Content area -->
<div class="w-full overflow-x-scroll">
<table
class="table table-sm sm:table-md table-compact rounded-none sm:rounded-md w-full border-bg-[#09090B] m-auto mt-4"
>
<thead>
<tr class="border border-slate-800">
<th class="text-white font-semibold text-[1rem]">Symbol</th>
<th class="text-white font-semibold text-[1rem]">Company</th>
<th class="text-white font-semibold text-end text-[1rem]"
>Market Cap</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Revenue</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Profits</th
>
<th class="text-white font-semibold text-[1rem] text-end">Price</th>
</tr>
</thead>
<tbody>
{#each marketCapList as item, index}
<!-- row -->
<tr
on:click={() => goto("/stocks/" + item?.symbol)}
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"
>
<td
class="text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.symbol}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.name?.length > charNumber
? item?.name?.slice(0, charNumber) + "..."
: item?.name}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-end border-b-[#09090B]"
>
{abbreviateNumber(item?.marketCap, true)}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.revenue !== null
? abbreviateNumber(item?.revenue, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.netIncome !== null
? abbreviateNumber(item?.netIncome, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
<div class="flex flex-row justify-end items-center">
<div class="flex flex-col">
<span class="text-white ml-auto"
>${item.price?.toFixed(2)}</span
>
<div class="flex flex-row mt-0.5 ml-auto">
{#if item.changesPercentage >= 0}
<span class="text-[#00FC50]"
>+{item.changesPercentage?.toFixed(2)}%</span
>
{:else}
<span class="text-[#FF2F1F]"
>{item.changesPercentage?.toFixed(2)}%
</span>
{/if}
</div>
</div>
</div>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
</section>
<style>
.app {
height: 300px;
max-width: 100%; /* Ensure chart width doesn't exceed the container */
}
@media (max-width: 640px) {
.app {
height: 210px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -1,43 +1,47 @@
export const load = async ({ locals }) => { export const load = async ({ locals, params }) => {
const { apiKey, apiURL } = locals; const { apiKey, apiURL } = locals;
const getFinancialSector = async () => { const getParams = async () => {
const postData = { filterList: "financial" }; return params.slug;
};
const response = await fetch(apiURL + "/filter-stock-list", { const getSectorCategory = async () => {
method: "POST", const postData = { filterList: params.slug };
headers: {
"Content-Type": "application/json", const response = await fetch(apiURL + "/list-category", {
"X-API-KEY": apiKey, method: "POST",
}, headers: {
body: JSON.stringify(postData), "Content-Type": "application/json",
}); "X-API-KEY": apiKey,
},
const output = await response.json(); body: JSON.stringify(postData),
});
return output;
}; const output = await response.json();
return output;
const getHistoricalSector = async () => { };
const postData = { filterList: "financial" }; /*
const getHistoricalSector = async () => {
const response = await fetch(apiURL + "/historical-sector-price", { const postData = { filterList: "financial" };
method: "POST",
headers: { const response = await fetch(apiURL + "/historical-sector-price", {
"Content-Type": "application/json", method: "POST",
"X-API-KEY": apiKey, headers: {
}, "Content-Type": "application/json",
body: JSON.stringify(postData), "X-API-KEY": apiKey,
}); },
body: JSON.stringify(postData),
const output = await response.json(); });
return output; const output = await response.json();
};
return output;
// Make sure to return a promise };
return { */
getFinancialSector: await getFinancialSector(),
getHistoricalSector: await getHistoricalSector(), // Make sure to return a promise
}; return {
}; getParams: await getParams(),
getSectorCategory: await getSectorCategory(),
//getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -0,0 +1,299 @@
<script lang="ts">
import { screenWidth } from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import { onMount } from "svelte";
import { page } from "$app/stores";
import TableHeader from "$lib/components/Table/TableHeader.svelte";
export let data;
let rawData = [];
let marketCapList = [];
const BILLION = 1_000_000_000;
const MILLION = 1_000_000;
const marketCapNavigation = [
{
threshold: 200 * BILLION,
name: "Mega Cap",
link: "/list/market-cap/mega-cap-stocks",
},
{
minThreshold: 10 * BILLION,
maxThreshold: 200 * BILLION,
name: "Large Cap",
link: "/list/market-cap/large-cap-stocks",
},
{
minThreshold: 2 * BILLION,
maxThreshold: 10 * BILLION,
name: "Mid Cap",
link: "/list/market-cap/mid-cap-stocks",
},
{
minThreshold: 300 * MILLION,
maxThreshold: 2 * BILLION,
name: "Small Cap",
link: "/list/market-cap/small-cap-stocks",
},
{
minThreshold: 50 * MILLION,
maxThreshold: 300 * MILLION,
name: "Micro Cap",
link: "/list/market-cap/micro-cap-stocks",
},
{
maxThreshold: 50 * MILLION,
name: "Nano Cap",
link: "/list/market-cap/nano-cap-stocks",
},
];
async function handleScroll() {
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
if (isBottom && marketCapList?.length !== rawData?.length) {
const nextIndex = marketCapList?.length;
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
marketCapList = [...marketCapList, ...filteredNewResults];
}
}
onMount(async () => {
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
});
let columns = [
{ key: "rank", label: "Rank", align: "left" },
{ key: "symbol", label: "Symbol", align: "left" },
{ key: "name", label: "Name", align: "left" },
{ key: "marketCap", label: "Market Cap", align: "right" },
{ key: "price", label: "Price", align: "right" },
{ key: "changesPercentage", label: "% Change", align: "right" },
{ key: "revenue", label: "Revenue", align: "right" },
];
let sortOrders = {
rank: { order: "none", type: "number" },
symbol: { order: "none", type: "string" },
name: { order: "none", type: "string" },
price: { order: "none", type: "number" },
changesPercentage: { order: "none", type: "number" },
marketCap: { order: "none", type: "number" },
revenue: { order: "none", type: "number" },
};
const sortData = (key) => {
// Reset all other keys to 'none' except the current key
for (const k in sortOrders) {
if (k !== key) {
sortOrders[k].order = "none";
}
}
// Cycle through 'none', 'asc', 'desc' for the clicked key
const orderCycle = ["none", "asc", "desc"];
let originalData = data?.getSectorCategory;
const currentOrderIndex = orderCycle.indexOf(sortOrders[key].order);
sortOrders[key].order =
orderCycle[(currentOrderIndex + 1) % orderCycle.length];
const sortOrder = sortOrders[key].order;
// Reset to original data when 'none' and stop further sorting
if (sortOrder === "none") {
marketCapList = [...originalData]?.slice(0, 50); // Reset to original data (spread to avoid mutation)
return;
}
// Define a generic comparison function
const compareValues = (a, b) => {
const { type } = sortOrders[key];
let valueA, valueB;
switch (type) {
case "date":
valueA = new Date(a[key]);
valueB = new Date(b[key]);
break;
case "string":
valueA = a[key].toUpperCase();
valueB = b[key].toUpperCase();
return sortOrder === "asc"
? valueA.localeCompare(valueB)
: valueB.localeCompare(valueA);
case "number":
default:
valueA = parseFloat(a[key]);
valueB = parseFloat(b[key]);
break;
}
if (sortOrder === "asc") {
return valueA < valueB ? -1 : valueA > valueB ? 1 : 0;
} else {
return valueA > valueB ? -1 : valueA < valueB ? 1 : 0;
}
};
// Sort using the generic comparison function
marketCapList = [...originalData].sort(compareValues)?.slice(0, 50);
};
let totalMarketCap = 0;
let totalRevenue = 0;
$: {
if ($page?.url?.pathname) {
rawData = data?.getSectorCategory;
marketCapList = rawData?.slice(0, 50);
totalMarketCap = rawData?.reduce(
(total, stock) => total + stock?.marketCap,
0,
);
totalRevenue = rawData?.reduce(
(total, stock) => total + stock?.revenue,
0,
);
}
}
$: charNumber = $screenWidth < 640 ? 15 : 20;
</script>
<section class="w-full overflow-hidden m-auto">
<div
class="w-full m-auto text-white border border-gray-600 rounded-md h-auto p-5 mb-4"
>
The {data?.getParams} sector has a total of {rawData?.length} stocks, with a
combined market cap of {abbreviateNumber(totalMarketCap)} and a total revenue
of {abbreviateNumber(totalRevenue)}.
</div>
<div
class="mb-4 flex flex-col divide-y divide-gray-600 rounded-md border border-gray-600 sm:grid sm:grid-cols-3 sm:divide-x sm:divide-y-0"
>
<div class="px-4 py-3 sm:px-2 sm:py-5 md:px-3 lg:p-6">
<div class="flex items-center justify-between sm:block">
<div class="text-sm font-normal text-white">Total Stocks</div>
<div
class="mt-1 break-words font-semibold leading-8 text-white tiny:text-lg xs:text-xl sm:text-2xl"
>
{new Intl.NumberFormat("en")?.format(rawData?.length)}
</div>
</div>
</div>
<div class="px-4 py-3 sm:px-2 sm:py-5 md:px-3 lg:p-6">
<div class="flex items-center justify-between sm:block">
<div class="text-sm font-normal text-white">Total Market Cap</div>
<div
class="mt-1 break-words font-semibold leading-8 text-white tiny:text-lg xs:text-xl sm:text-2xl"
>
{abbreviateNumber(totalMarketCap)}
</div>
</div>
</div>
<div class="px-4 py-3 sm:px-2 sm:py-5 md:px-3 lg:p-6">
<div class="flex items-center justify-between sm:block">
<div class="text-sm font-normal text-white">Total Revenue</div>
<div
class="mt-1 break-words font-semibold leading-8 text-white tiny:text-lg xs:text-xl sm:text-2xl"
>
{abbreviateNumber(totalRevenue)}
</div>
</div>
</div>
</div>
<!-- Page wrapper -->
<div class="flex justify-center w-full m-auto h-full overflow-hidden">
<!-- Content area -->
<div class="w-full overflow-x-scroll">
<div class="w-full overflow-x-scroll">
<table
class="table table-sm table-compact rounded-none sm:rounded-md w-full border-bg-[#09090B] m-auto mt-4"
>
<thead>
<TableHeader {columns} {sortOrders} {sortData} />
</thead>
<tbody>
{#each marketCapList as item, index}
<!-- row -->
<tr
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B]"
>
<td
class="text-white text-center font-medium text-sm sm:text-[1rem] border-b-[#09090B]"
>
{item?.rank}
</td>
<td
class="text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
<a
href={"/stocks/" + item?.symbol}
class="sm:hover:text-white text-blue-400"
>
{item?.symbol}
</a>
</td>
<td
class="text-gray-200 border-b-[#09090B] text-sm sm:text-[1rem] whitespace-nowrap"
>
{item?.name?.length > charNumber
? item?.name?.slice(0, charNumber) + "..."
: item?.name}
</td>
<td
class="text-white font-medium text-sm sm:text-[1rem] whitespace-nowrap text-end border-b-[#09090B]"
>
{abbreviateNumber(item?.marketCap)}
</td>
<td
class="text-white text-end border-b-[#09090B] text-sm sm:text-[1rem] whitespace-nowrap"
>
{item.price?.toFixed(2)}
</td>
<td
class="text-white text-end border-b-[#09090B] text-sm sm:text-[1rem] whitespace-nowrap"
>
{#if item?.changesPercentage >= 0}
<span class="text-[#00FC50]"
>+{item?.changesPercentage?.toFixed(2)}%</span
>
{:else}
<span class="text-[#FF2F1F]"
>{item?.changesPercentage?.toFixed(2)}%</span
>
{/if}
</td>
<td
class="text-white font-medium text-sm sm:text-[1rem] whitespace-nowrap text-end border-b-[#09090B]"
>
{item?.revenue !== null
? abbreviateNumber(item?.revenue)
: "-"}
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
</div>
</section>

View File

@ -1,43 +0,0 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getTechnologySector = async () => {
const postData = { filterList: "technology" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "technology" };
const response = await fetch(apiURL + "/historical-sector-price", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getTechnologySector: await getTechnologySector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,410 +0,0 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { screenWidth } from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import InfoModal from "$lib/components/InfoModal.svelte";
import { onMount } from "svelte";
import { Chart } from "svelte-echarts";
import { init, use } from "echarts/core";
import { BarChart } from "echarts/charts";
import { GridComponent, TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
export let data;
let isLoaded = false;
use([BarChart, GridComponent, TooltipComponent, CanvasRenderer]);
let rawData = data?.getTechnologySector;
let historicalPrice = data?.getHistoricalSector;
let marketCapList = rawData?.slice(0, 50);
let optionsData;
async function handleScroll() {
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
if (isBottom && marketCapList?.length !== rawData?.length) {
const nextIndex = marketCapList?.length;
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
marketCapList = [...marketCapList, ...filteredNewResults];
}
}
function getPlotOptions() {
let dates = [];
let priceList = [];
// Iterate over the data and extract required information
historicalPrice?.forEach((item) => {
dates?.push(item?.date);
priceList?.push(item?.changesPercentage);
});
const option = {
silent: true,
tooltip: {
trigger: "axis",
hideDelay: 100, // Set the delay in milliseconds
},
animation: false,
grid: {
left: "0%",
right: "2%",
bottom: "2%",
top: "5%",
containLabel: true,
},
xAxis: {
type: "category",
boundaryGap: false,
data: dates,
axisLabel: {
color: "#fff",
},
},
yAxis: [
{
type: "value",
splitLine: {
show: false, // Disable x-axis grid lines
},
axisLabel: {
color: "#fff",
formatter: function (value, index) {
if (index % 2 === 0) {
return value?.toFixed(2) + "%"; // Format the sentiment value
} else {
return ""; // Hide this tick
}
},
},
},
],
series: [
{
name: "Daily Change [%]",
data: priceList,
type: "bar",
itemStyle: {
color: (params) => {
// Set color based on positive or negative value
return params.data >= 0 ? "#22C55E" : "#F71F4F";
},
},
},
],
};
return option;
}
onMount(async () => {
optionsData = await getPlotOptions();
isLoaded = true;
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
});
let totalMarketCap =
rawData?.reduce((total, stock) => total + stock?.marketCap, 0) ?? 0;
let totalRevenue =
rawData?.reduce((total, stock) => total + stock?.revenue, 0) ?? 0;
let totalProfits =
rawData?.reduce((total, stock) => total + stock?.netIncome, 0) ?? 0;
$: charNumber = $screenWidth < 640 ? 15 : 20;
</script>
<section class="w-full overflow-hidden m-auto">
<div
class="border border-gray-800 w-full sm:flex sm:flex-row sm:items-center m-auto text-gray-100 bg-[#09090B] sm:rounded-lg h-auto p-5 mb-4"
>
<svg
class="w-5 h-5 inline-block sm:mr-2 flex-shrink-0"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 256 256"
><path
fill="#a474f6"
d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m-4 48a12 12 0 1 1-12 12a12 12 0 0 1 12-12m12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16a16 16 0 0 1 16 16v40a8 8 0 0 1 0 16"
/></svg
>
A complete list of companies in the Technology Sector that are publicly traded
on the US stock exchange.
</div>
<div
class="mb-4 grid grid-cols-2 divide-y divide-gray-600 rounded-lg border border-gray-600 bg-[#272727] shadow md:grid-cols-3 divide-x"
>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="stocksInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Stocks
<InfoModal
title={"Stocks"}
content={"The total number of companies who operate in this sector."}
id={"stocksInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{rawData?.length}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="marketCapModal"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Market Cap
<InfoModal
title={"Market Cap"}
content={"Combined market cap of all companies in this sector."}
id={"marketCapModal"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalMarketCap, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="revenueInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Revenue
<InfoModal
title={"Revenue"}
content={"The total revenue of all companies in this sector."}
id={"revenueInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalRevenue, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitsInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profits
<InfoModal
title={"Profits"}
content={"The total net income of all companies in this sector."}
id={"profitsInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalProfits, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitMarginInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profit Margin
<InfoModal
title={"Profit Margin"}
content={"The industry's profit margin, calculated by dividing the total net income by the total revenue."}
id={"profitMarginInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{((totalProfits / totalRevenue) * 100)?.toFixed(2)}%
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="peRatioInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
PE Ratio
<InfoModal
title={"PE Ratio"}
content={"The industry's PE Ratio, calculated by dividing the total market cap by the total net income."}
id={"peRatioInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{(totalMarketCap / totalProfits)?.toFixed(2)}
</div>
</div>
</div>
</div>
<h2 class="text-white text-xl sm:text-2xl mt-8 font-semibold">
Historical Performance
</h2>
<div class="app w-full h-[300px] mt-5 mb-8">
{#if isLoaded}
<Chart {init} options={optionsData} class="chart" />
{:else}
<div class="flex justify-center items-center h-80">
<div class="relative">
<label
class="bg-[#09090B] rounded-xl h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
>
<span class="loading loading-spinner loading-md text-gray-400"
></span>
</label>
</div>
</div>
{/if}
</div>
<!-- Page wrapper -->
<div class="flex justify-center w-full m-auto h-full overflow-hidden">
<!-- Content area -->
<div class="w-full overflow-x-scroll">
<table
class="table table-sm sm:table-md table-compact rounded-none sm:rounded-md w-full border-bg-[#09090B] m-auto mt-4"
>
<thead>
<tr class="border border-slate-800">
<th class="text-white font-semibold text-[1rem]">Symbol</th>
<th class="text-white font-semibold text-[1rem]">Company</th>
<th class="text-white font-semibold text-end text-[1rem]"
>Market Cap</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Revenue</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Profits</th
>
<th class="text-white font-semibold text-[1rem] text-end">Price</th>
</tr>
</thead>
<tbody>
{#each marketCapList as item, index}
<!-- row -->
<tr
on:click={() => goto("/stocks/" + item?.symbol)}
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"
>
<td
class="text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.symbol}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.name?.length > charNumber
? item?.name?.slice(0, charNumber) + "..."
: item?.name}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-end border-b-[#09090B]"
>
{abbreviateNumber(item?.marketCap, true)}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.revenue !== null
? abbreviateNumber(item?.revenue, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.netIncome !== null
? abbreviateNumber(item?.netIncome, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
<div class="flex flex-row justify-end items-center">
<div class="flex flex-col">
<span class="text-white ml-auto"
>${item.price?.toFixed(2)}</span
>
<div class="flex flex-row mt-0.5 ml-auto">
{#if item.changesPercentage >= 0}
<span class="text-[#00FC50]"
>+{item.changesPercentage?.toFixed(2)}%</span
>
{:else}
<span class="text-[#FF2F1F]"
>{item.changesPercentage?.toFixed(2)}%
</span>
{/if}
</div>
</div>
</div>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
</section>
<style>
.app {
height: 300px;
max-width: 100%; /* Ensure chart width doesn't exceed the container */
}
@media (max-width: 640px) {
.app {
height: 210px;
}
}
.chart {
width: 100%;
}
</style>

View File

@ -1,43 +0,0 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL } = locals;
const getUtilitiesSector = async () => {
const postData = { filterList: "utilities" };
const response = await fetch(apiURL + "/filter-stock-list", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getHistoricalSector = async () => {
const postData = { filterList: "utilities" };
const response = await fetch(apiURL + "/historical-sector-price", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getUtilitiesSector: await getUtilitiesSector(),
getHistoricalSector: await getHistoricalSector(),
};
};

View File

@ -1,410 +0,0 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { screenWidth } from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import InfoModal from "$lib/components/InfoModal.svelte";
import { onMount } from "svelte";
import { Chart } from "svelte-echarts";
import { init, use } from "echarts/core";
import { BarChart } from "echarts/charts";
import { GridComponent, TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
export let data;
let isLoaded = false;
use([BarChart, GridComponent, TooltipComponent, CanvasRenderer]);
let rawData = data?.getUtilitiesSector;
let historicalPrice = data?.getHistoricalSector;
let marketCapList = rawData?.slice(0, 50);
let optionsData;
async function handleScroll() {
const scrollThreshold = document.body.offsetHeight * 0.8; // 80% of the website height
const isBottom = window.innerHeight + window.scrollY >= scrollThreshold;
if (isBottom && marketCapList?.length !== rawData?.length) {
const nextIndex = marketCapList?.length;
const filteredNewResults = rawData?.slice(nextIndex, nextIndex + 50);
marketCapList = [...marketCapList, ...filteredNewResults];
}
}
function getPlotOptions() {
let dates = [];
let priceList = [];
// Iterate over the data and extract required information
historicalPrice?.forEach((item) => {
dates?.push(item?.date);
priceList?.push(item?.changesPercentage);
});
const option = {
silent: true,
tooltip: {
trigger: "axis",
hideDelay: 100, // Set the delay in milliseconds
},
animation: false,
grid: {
left: "0%",
right: "2%",
bottom: "2%",
top: "5%",
containLabel: true,
},
xAxis: {
type: "category",
boundaryGap: false,
data: dates,
axisLabel: {
color: "#fff",
},
},
yAxis: [
{
type: "value",
splitLine: {
show: false, // Disable x-axis grid lines
},
axisLabel: {
color: "#fff",
formatter: function (value, index) {
if (index % 2 === 0) {
return value?.toFixed(2) + "%"; // Format the sentiment value
} else {
return ""; // Hide this tick
}
},
},
},
],
series: [
{
name: "Daily Change [%]",
data: priceList,
type: "bar",
itemStyle: {
color: (params) => {
// Set color based on positive or negative value
return params.data >= 0 ? "#22C55E" : "#F71F4F";
},
},
},
],
};
return option;
}
onMount(async () => {
optionsData = await getPlotOptions();
isLoaded = true;
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
});
let totalMarketCap =
rawData?.reduce((total, stock) => total + stock?.marketCap, 0) ?? 0;
let totalRevenue =
rawData?.reduce((total, stock) => total + stock?.revenue, 0) ?? 0;
let totalProfits =
rawData?.reduce((total, stock) => total + stock?.netIncome, 0) ?? 0;
$: charNumber = $screenWidth < 640 ? 15 : 20;
</script>
<section class="w-full overflow-hidden m-auto">
<div
class="border border-gray-800 w-full sm:flex sm:flex-row sm:items-center m-auto text-gray-100 bg-[#09090B] sm:rounded-lg h-auto p-5 mb-4"
>
<svg
class="w-5 h-5 inline-block sm:mr-2 flex-shrink-0"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 256 256"
><path
fill="#a474f6"
d="M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24m-4 48a12 12 0 1 1-12 12a12 12 0 0 1 12-12m12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16a16 16 0 0 1 16 16v40a8 8 0 0 1 0 16"
/></svg
>
A complete list of companies in the Utilities Sector that are publicly traded
on the US stock exchange.
</div>
<div
class="mb-4 grid grid-cols-2 divide-y divide-gray-600 rounded-lg border border-gray-600 bg-[#272727] shadow md:grid-cols-3 divide-x"
>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="stocksInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Stocks
<InfoModal
title={"Stocks"}
content={"The total number of companies who operate in this sector."}
id={"stocksInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{rawData?.length}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="marketCapModal"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Market Cap
<InfoModal
title={"Market Cap"}
content={"Combined market cap of all companies in this sector."}
id={"marketCapModal"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalMarketCap, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="revenueInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Revenue
<InfoModal
title={"Revenue"}
content={"The total revenue of all companies in this sector."}
id={"revenueInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalRevenue, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitsInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profits
<InfoModal
title={"Profits"}
content={"The total net income of all companies in this sector."}
id={"profitsInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{abbreviateNumber(totalProfits, true)}
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="profitMarginInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
Profit Margin
<InfoModal
title={"Profit Margin"}
content={"The industry's profit margin, calculated by dividing the total net income by the total revenue."}
id={"profitMarginInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{((totalProfits / totalRevenue) * 100)?.toFixed(2)}%
</div>
</div>
</div>
<div class="p-4 bp:p-5 sm:p-6">
<label
for="peRatioInfo"
class="mr-1 cursor-pointer flex flex-row items-center text-white text-[1rem] sm:text-xl font-semibold"
>
PE Ratio
<InfoModal
title={"PE Ratio"}
content={"The industry's PE Ratio, calculated by dividing the total market cap by the total net income."}
id={"peRatioInfo"}
/>
</label>
<div
class="mt-1 flex flex-col items-baseline justify-start space-y-2 bp:space-y-0"
>
<div
class="flex items-baseline text-lg sm:text-xl font-semibold text-white"
>
{(totalMarketCap / totalProfits)?.toFixed(2)}
</div>
</div>
</div>
</div>
<h2 class="text-white text-xl sm:text-2xl mt-8 font-semibold">
Historical Performance
</h2>
<div class="app w-full h-[300px] mt-5 mb-8">
{#if isLoaded}
<Chart {init} options={optionsData} class="chart" />
{:else}
<div class="flex justify-center items-center h-80">
<div class="relative">
<label
class="bg-[#09090B] rounded-xl h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
>
<span class="loading loading-spinner loading-md text-gray-400"
></span>
</label>
</div>
</div>
{/if}
</div>
<!-- Page wrapper -->
<div class="flex justify-center w-full m-auto h-full overflow-hidden">
<!-- Content area -->
<div class="w-full overflow-x-scroll">
<table
class="table table-sm sm:table-md table-compact rounded-none sm:rounded-md w-full border-bg-[#09090B] m-auto mt-4"
>
<thead>
<tr class="border border-slate-800">
<th class="text-white font-semibold text-[1rem]">Symbol</th>
<th class="text-white font-semibold text-[1rem]">Company</th>
<th class="text-white font-semibold text-end text-[1rem]"
>Market Cap</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Revenue</th
>
<th class="text-white font-semibold text-center text-[1rem]"
>Profits</th
>
<th class="text-white font-semibold text-[1rem] text-end">Price</th>
</tr>
</thead>
<tbody>
{#each marketCapList as item, index}
<!-- row -->
<tr
on:click={() => goto("/stocks/" + item?.symbol)}
class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"
>
<td
class="text-blue-400 font-medium text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.symbol}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
{item?.name?.length > charNumber
? item?.name?.slice(0, charNumber) + "..."
: item?.name}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-end border-b-[#09090B]"
>
{abbreviateNumber(item?.marketCap, true)}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.revenue !== null
? abbreviateNumber(item?.revenue, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap font-medium text-center border-b-[#09090B]"
>
{item?.netIncome !== null
? abbreviateNumber(item?.netIncome, true)
: "-"}
</td>
<td
class="text-white text-sm sm:text-[1rem] whitespace-nowrap border-b-[#09090B]"
>
<div class="flex flex-row justify-end items-center">
<div class="flex flex-col">
<span class="text-white ml-auto"
>${item.price?.toFixed(2)}</span
>
<div class="flex flex-row mt-0.5 ml-auto">
{#if item.changesPercentage >= 0}
<span class="text-[#00FC50]"
>+{item.changesPercentage?.toFixed(2)}%</span
>
{:else}
<span class="text-[#FF2F1F]"
>{item.changesPercentage?.toFixed(2)}%
</span>
{/if}
</div>
</div>
</div>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</div>
</section>
<style>
.app {
height: 300px;
max-width: 100%; /* Ensure chart width doesn't exceed the container */
}
@media (max-width: 640px) {
.app {
height: 210px;
}
}
.chart {
width: 100%;
}
</style>