add economic indicator page
This commit is contained in:
parent
181d0bacd3
commit
517851eea3
@ -17,9 +17,10 @@ export let data;
|
|||||||
let cloudFrontUrl = import.meta.env.VITE_IMAGE_URL;
|
let cloudFrontUrl = import.meta.env.VITE_IMAGE_URL;
|
||||||
|
|
||||||
let isLoaded = false;
|
let isLoaded = false;
|
||||||
let rawData = data?.getEconomicData || [];
|
let rawData;
|
||||||
let tableList = [];
|
let tableList = [];
|
||||||
let optionsData;
|
let optionsData;
|
||||||
|
let optionsCPI;
|
||||||
let filterRule = 'annual';
|
let filterRule = 'annual';
|
||||||
|
|
||||||
let timePeriod = 'threeYears';
|
let timePeriod = 'threeYears';
|
||||||
@ -210,10 +211,71 @@ async function plotData() {
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function plotCPI() {
|
||||||
|
// Get the filtered data based on the selected time period
|
||||||
|
let dates = [];
|
||||||
|
let valueList = [];
|
||||||
|
// Iterate over the data and extract required information
|
||||||
|
data?.getEconomicIndicator?.cpi?.forEach(item => {
|
||||||
|
|
||||||
|
dates?.push(item?.date);
|
||||||
|
valueList?.push(item?.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
animation: false,
|
||||||
|
grid: {
|
||||||
|
left: '2%',
|
||||||
|
right: '2%',
|
||||||
|
bottom: '2%',
|
||||||
|
top: '10%',
|
||||||
|
containLabel: true
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
axisLabel: {
|
||||||
|
color: '#fff',
|
||||||
|
},
|
||||||
|
data: dates,
|
||||||
|
type: 'category',
|
||||||
|
},
|
||||||
|
yAxis: [
|
||||||
|
{
|
||||||
|
type: 'value',
|
||||||
|
splitLine: {
|
||||||
|
show: false, // Disable x-axis grid lines
|
||||||
|
},
|
||||||
|
axisLabel: {
|
||||||
|
color: '#fff', // Change label color to white
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'value',
|
||||||
|
splitLine: {
|
||||||
|
show: false, // Disable x-axis grid lines
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
series: {
|
||||||
|
name: 'CPI',
|
||||||
|
data: valueList,
|
||||||
|
type: 'line',
|
||||||
|
areaStyle: {opacity: 0.2},
|
||||||
|
smooth: true,
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
trigger: 'axis',
|
||||||
|
hideDelay: 100,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
rawData = data?.getEconomicData ?? [];
|
rawData = data?.getEconomicIndicator?.treasury ?? {};
|
||||||
optionsData = await plotData();
|
optionsData = await plotData();
|
||||||
|
optionsCPI = await plotCPI();
|
||||||
tableList = filterEndOfYearDates(rawData);
|
tableList = filterEndOfYearDates(rawData);
|
||||||
tableList?.sort((a, b) => new Date(b?.date) - new Date(a?.date));
|
tableList?.sort((a, b) => new Date(b?.date) - new Date(a?.date));
|
||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
@ -228,20 +290,20 @@ onMount(async () => {
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
<title>
|
<title>
|
||||||
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} US Economic Data · stocknear
|
{$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} US Economic Indicator · stocknear
|
||||||
</title>
|
</title>
|
||||||
<meta name="description" content={`Short interest, stock short squeeze, short interest ratio & short selling data positions for NASDAQ, NYSE & AMEX stocks to find shorts in the stock market.`} />
|
<meta name="description" content={`Economic indicators measure economic performance and identify growth trends.`} />
|
||||||
|
|
||||||
<!-- Other meta tags -->
|
<!-- Other meta tags -->
|
||||||
<meta property="og:title" content={`US Economic Data · stocknear`}/>
|
<meta property="og:title" content={`US Economic Indicator · stocknear`}/>
|
||||||
<meta property="og:description" content={`Short interest, stock short squeeze, short interest ratio & short selling data positions for NASDAQ, NYSE & AMEX stocks to find shorts in the stock market.`} />
|
<meta property="og:description" content={`Economic indicators measure economic performance and identify growth trends.`} />
|
||||||
<meta property="og:type" content="website"/>
|
<meta property="og:type" content="website"/>
|
||||||
<!-- Add more Open Graph meta tags as needed -->
|
<!-- Add more Open Graph meta tags as needed -->
|
||||||
|
|
||||||
<!-- Twitter specific meta tags -->
|
<!-- Twitter specific meta tags -->
|
||||||
<meta name="twitter:card" content="summary_large_image"/>
|
<meta name="twitter:card" content="summary_large_image"/>
|
||||||
<meta name="twitter:title" content={`US Economic Data · stocknear`}/>
|
<meta name="twitter:title" content={`US Economic Indicator · stocknear`}/>
|
||||||
<meta name="twitter:description" content={`Short interest, stock short squeeze, short interest ratio & short selling data positions for NASDAQ, NYSE & AMEX stocks to find shorts in the stock market.`} />
|
<meta name="twitter:description" content={`Economic indicators measure economic performance and identify growth trends.`} />
|
||||||
<!-- Add more Twitter meta tags as needed -->
|
<!-- Add more Twitter meta tags as needed -->
|
||||||
|
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
@ -253,7 +315,7 @@ onMount(async () => {
|
|||||||
<div class="text-sm sm:text-[1rem] breadcrumbs ml-4">
|
<div class="text-sm sm:text-[1rem] breadcrumbs ml-4">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/" class="text-gray-300">Home</a></li>
|
<li><a href="/" class="text-gray-300">Home</a></li>
|
||||||
<li class="text-gray-300">US Economic Data</li>
|
<li class="text-gray-300">US Economic Indicator</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -272,12 +334,12 @@ onMount(async () => {
|
|||||||
<div>
|
<div>
|
||||||
<div class="flex flex-row justify-center items-center">
|
<div class="flex flex-row justify-center items-center">
|
||||||
<h1 class="text-3xl sm:text-4xl text-white text-center font-bold mb-5">
|
<h1 class="text-3xl sm:text-4xl text-white text-center font-bold mb-5">
|
||||||
US Economic Data
|
Economic Indicator
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span class="text-white text-md font-medium text-center flex justify-center items-center ">
|
<span class="text-white text-md font-medium text-center flex justify-center items-center ">
|
||||||
US Economic Data such as treasury rate, CPI
|
The indicators measure economic performance and identify growth trends.
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|
||||||
@ -315,9 +377,21 @@ onMount(async () => {
|
|||||||
{#if isLoaded}
|
{#if isLoaded}
|
||||||
<div class="w-screen sm:w-full m-auto mt-20 sm:mt-10 p-3">
|
<div class="w-screen sm:w-full m-auto mt-20 sm:mt-10 p-3">
|
||||||
|
|
||||||
<h1 class="text-2xl text-gray-200 font-bold">
|
<h2 class="text-2xl text-gray-200 font-bold">
|
||||||
|
Consumer Price Index (CPI)
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="text-[1rem] text-white mt-2 mb-2">
|
||||||
|
The CPI measures the average change in prices for a typical basket of goods. It's key for tracking inflation, affecting interest rates, wages, and business decisions. Rising CPI indicates inflation, impacting purchasing power and the overall economy.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="app w-full ">
|
||||||
|
<Chart {init} options={optionsCPI} class="chart" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2 class="text-2xl text-gray-200 font-bold mt-10">
|
||||||
Treasury Rates
|
Treasury Rates
|
||||||
</h1>
|
</h2>
|
||||||
|
|
||||||
<div class="text-[1rem] text-white mt-2 mb-2">
|
<div class="text-[1rem] text-white mt-2 mb-2">
|
||||||
Treasury rates are the interest rates that the US government pays on its debt obligations, and they are a key benchmark for interest rates across the economy.
|
Treasury rates are the interest rates that the US government pays on its debt obligations, and they are a key benchmark for interest rates across the economy.
|
||||||
@ -383,7 +457,7 @@ onMount(async () => {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each tableList as item, index}
|
{#each tableList as item}
|
||||||
<!-- row -->
|
<!-- row -->
|
||||||
<tr class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer">
|
<tr class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer">
|
||||||
|
|
||||||
@ -394,7 +468,7 @@ onMount(async () => {
|
|||||||
{item?.month1}
|
{item?.month1}
|
||||||
</td>
|
</td>
|
||||||
<td class="text-white font-medium text-sm sm:text-[1rem] text-end whitespace-nowrap border-b-[#09090B]">
|
<td class="text-white font-medium text-sm sm:text-[1rem] text-end whitespace-nowrap border-b-[#09090B]">
|
||||||
{item?.month2}
|
{item?.month2 !== null ? item?.month2 : '-'}
|
||||||
</td>
|
</td>
|
||||||
<td class="text-white font-medium text-sm sm:text-[1rem] text-end whitespace-nowrap border-b-[#09090B]">
|
<td class="text-white font-medium text-sm sm:text-[1rem] text-end whitespace-nowrap border-b-[#09090B]">
|
||||||
{item?.month3}
|
{item?.month3}
|
||||||
@ -3,15 +3,15 @@ import { getCache, setCache } from '$lib/store';
|
|||||||
|
|
||||||
|
|
||||||
export const load = async ({parent}) => {
|
export const load = async ({parent}) => {
|
||||||
const getEconomicData = async () => {
|
const getEconomicIndicator = async () => {
|
||||||
let output;
|
let output;
|
||||||
const {apiKey, apiURL} = await parent();
|
const {apiKey, apiURL} = await parent();
|
||||||
|
|
||||||
const cachedData = getCache('', 'getEconomicData');
|
const cachedData = getCache('', 'getEconomicIndicator');
|
||||||
if (cachedData) {
|
if (cachedData) {
|
||||||
output = cachedData;
|
output = cachedData;
|
||||||
} else {
|
} else {
|
||||||
const response = await fetch(apiURL + '/economic-data', {
|
const response = await fetch(apiURL + '/economic-indicator', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
"Content-Type": "application/json", "X-API-KEY": apiKey
|
||||||
@ -21,7 +21,7 @@ export const load = async ({parent}) => {
|
|||||||
output = await response.json();
|
output = await response.json();
|
||||||
|
|
||||||
|
|
||||||
setCache('', output, 'getEconomicData');
|
setCache('', output, 'getEconomicIndicator');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +30,6 @@ export const load = async ({parent}) => {
|
|||||||
|
|
||||||
// Make sure to return a promise
|
// Make sure to return a promise
|
||||||
return {
|
return {
|
||||||
getEconomicData: await getEconomicData()
|
getEconomicIndicator: await getEconomicIndicator()
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -202,10 +202,10 @@ onMount( async() => {
|
|||||||
<Feedback data={data} />
|
<Feedback data={data} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!--
|
|
||||||
<div class="text-center mb-10 relative w-fit flex justify-center m-auto">
|
<div class="text-center mb-10 relative w-fit flex justify-center m-auto">
|
||||||
<a href="/corporate-lobbying-tracker" class="text-white antialiased bg-[#27272A] w-full px-4 py-2 rounded-lg m-auto font-medium text-[1rem] flex items-center">
|
<a href="/economic-indicator" class="text-white antialiased bg-[#27272A] w-full px-4 py-2 rounded-lg m-auto font-medium text-[1rem] flex items-center">
|
||||||
<span class="font-semibold">Corporate Lobbying Tracker</span>
|
<span class="font-semibold">US Economic Indicator</span>
|
||||||
</a>
|
</a>
|
||||||
<div class="absolute top-[-1.2rem] -right-5 sm:-right-8 rotate-[7deg]">
|
<div class="absolute top-[-1.2rem] -right-5 sm:-right-8 rotate-[7deg]">
|
||||||
<span class="bg-[#FBCE3C] text-black text-sm sm:text-[0.9rem] rounded-xl font-semibold sm:me-2 px-2.5 py-0.5 rounded dark:bg-red-900 dark:text-red-300">
|
<span class="bg-[#FBCE3C] text-black text-sm sm:text-[0.9rem] rounded-xl font-semibold sm:me-2 px-2.5 py-0.5 rounded dark:bg-red-900 dark:text-red-300">
|
||||||
@ -213,7 +213,7 @@ onMount( async() => {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
-->
|
|
||||||
|
|
||||||
<h1 class="text-white text-3xl font-semibold text-start w-full pl-4 pb-4 sm:pb-2">
|
<h1 class="text-white text-3xl font-semibold text-start w-full pl-4 pb-4 sm:pb-2">
|
||||||
Dashboard
|
Dashboard
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user