This commit is contained in:
MuslemRahimi 2025-02-21 18:44:18 +01:00
parent b39e3f327c
commit c9df82745f
3 changed files with 295 additions and 456 deletions

View File

@ -17,7 +17,7 @@
// White House coordinates
const LON = -77.0365427;
const LAT = 38.8950368;
const ZOOM = 5;
const ZOOM = 4.5;
let mapElement;
let map;

View File

@ -19,7 +19,7 @@ type FlyAndScaleParams = {
};
export function removeCompanyStrings(name) {
const wordsToRemove = ["Technologies", "Inc."];
const wordsToRemove = ["Technologies", "Inc.","Corp.","Corporation","Holding","Limited","Group"];
if (!name) return "";
return wordsToRemove?.reduce((acc, word) => acc.replace(word, "").trim(), name);
}

View File

@ -6,9 +6,6 @@
import { screenWidth } from "$lib/store";
import ArrowLogo from "lucide-svelte/icons/move-up-right";
import { Chart } from "svelte-echarts";
import ScrollToTop from "$lib/components/ScrollToTop.svelte";
import { init, use } from "echarts/core";
import { LineChart, BarChart } from "echarts/charts";
import {
@ -84,128 +81,6 @@
return text.slice(0, maxLength) + "...";
}
function plotData() {
const history = data?.getEggPrice?.history || [];
const dateList = history.map((item) => item?.date ?? null);
const priceList = history.map((item) => item?.price ?? null);
const yoyChangeList = history.map((item) => item?.yoyChange ?? null);
const options = {
animation: false,
tooltip: {
trigger: "axis",
hideDelay: 100,
borderColor: "#969696", // Black border color
borderWidth: 1, // Border width of 1px
backgroundColor: "#313131", // Optional: Set background color for contrast
textStyle: {
color: "#fff", // Optional: Text color for better visibility
},
formatter: function (params) {
const timestamp = params[0].axisValue;
let result = timestamp + "<br/>";
params?.forEach((param) => {
const marker =
'<span style="display:inline-block;margin-right:4px;' +
"border-radius:10px;width:10px;height:10px;background-color:" +
param.color +
'"></span>';
// Check if it's "YoY Change" and append "%"
const value =
param.seriesName === "YoY Change"
? param.value + "%"
: param.value;
result += marker + param.seriesName + ": " + value + "<br/>";
});
return result;
},
axisPointer: {
lineStyle: {
color: "#fff",
},
},
},
silent: true,
grid: {
left: $screenWidth < 640 ? "5%" : "4%",
right: $screenWidth < 640 ? "5%" : "0%",
bottom: "4%",
containLabel: true,
},
xAxis: [
{
type: "category",
data: dateList,
axisLabel: {
color: "#fff",
formatter: function (value) {
// Assuming dates are in the format 'yyyy-mm-dd'
const dateParts = value.split("-");
const monthIndex = parseInt(dateParts[1]) - 1; // Months are zero-indexed in JavaScript Date objects
const year = parseInt(dateParts[0]);
const day = parseInt(dateParts[2]);
return `${day} ${monthNames[monthIndex]} ${year}`;
},
},
},
],
yAxis: [
{
type: "value",
splitLine: {
show: false, // Disable x-axis grid lines
},
axisLabel: {
show: false, // Hide y-axis labels
},
},
{
type: "value",
splitLine: {
show: false, // Disable x-axis grid lines
},
position: "right",
axisLabel: {
show: false, // Hide y-axis labels
},
},
],
series: [
{
name: "Price per Dozens",
type: "line",
data: priceList,
yAxisIndex: 1,
lineStyle: { width: 2 },
itemStyle: {
color: "#fff",
},
smooth: true,
showSymbol: false,
},
{
name: "YoY Change",
type: "bar",
lineStyle: { width: 2 },
data: yoyChangeList,
itemStyle: {
color: "#2b7fff",
},
smooth: true,
showSymbol: false,
},
],
};
return options;
}
let options = plotData();
function latestInfoDate(inputDate) {
// Create a Date object for the input date and convert it to New York time zone
const inputDateLocal = new Date(inputDate).toLocaleString("en-US", {
@ -256,30 +131,14 @@
>
<div class="w-full mt-5">
<div class="lg:float-left lg:w-[calc(100%-336px-20px)]">
<h1 class="text-xl sm:text-2xl font-bold mb-4 w-full">
<div class=" border-b-[2px]">
<h1 class="mb-1 text-white text-2xl sm:text-3xl font-bold">
POTUS Tracker
</h1>
</div>
</div>
<div class=" lg:float-left lg:w-[calc(100%-336px-40px)]">
<nav class=" border-b-[2px] overflow-x-scroll whitespace-nowrap">
<ul
class="flex flex-row items-center w-full text-[1rem] text-white"
>
{#each tabs as item, i}
<button
on:click={() => (activeIdx = i)}
class="p-2 px-5 cursor-pointer {activeIdx === i
? 'text-white bg-primary sm:hover:bg-opacity-[0.95] font-semibold'
: 'text-gray-400 sm:hover:text-white sm:hover:bg-primary sm:hover:bg-opacity-[0.95]'}"
>
{item.title}
</button>
{/each}
</ul>
</nav>
{#if activeIdx === 0}
<div class="mt-5 mb-5">
<Infobox
text={`Since the inauguration of Donald J. Trump on January 20, 2025, the
@ -289,10 +148,11 @@
</div>
<h2
class="text-white text-[1rem] sm:text-lg font-semibold mb-2 mt-4"
class="text-white text-[1rem] sm:text-xl font-semibold mb-2 mt-4"
>
The US President is currently located in {data?.getData?.city ??
"n/a"}
The President is in {(data?.getData?.city === "Washington"
? "the White House"
: data?.getData?.city) ?? "n/a"}
</h2>
<div class="w-full m-auto border border-gray-800 rounded-[10px]">
@ -301,44 +161,9 @@
<span class="text-gray-300 text-xs">
Map data © OpenStreetMap
</span>
{:else}
<h2 class="text-white text-lg font-semibold mt-4">
Quick Stats:
</h2>
<div
class="grid grid-cols-2 sm:grid-cols-4 md:grid-cols-6 gap-x-0 text-white mt-2 text-sm sm:text-[1rem] w-full"
>
<div class="whitespace-nowrap">
Current Price: {data?.getEggPrice?.currentPrice}
</div>
<div class="whitespace-nowrap">
<span class=" font-normal">Avg. Price:</span>
{data?.getEggPrice?.avgPrice}
</div>
<div class="whitespace-nowrap">
<span class=" font-normal">Min. Price:</span>
{data?.getEggPrice?.minPrice}
</div>
<div class="whitespace-nowrap">
<span class=" font-normal">Max. Price:</span>
{data?.getEggPrice?.maxPrice}
</div>
</div>
<div
class="app w-full relative border border-gray-800 rounded mt-5 mb-5 p-3"
>
<Chart {init} {options} class="chart" />
</div>
<Infobox
text="The historical egg prices are sourced from Federal Reserve Economic Data (FRED), which collects egg prices nationwide once a month and calculates the average."
/>
{/if}
<nav
class=" border-b-[2px] overflow-x-scroll whitespace-nowrap mt-10 sm:mt-6"
class=" border-b-[2px] whitespace-nowrap mt-10 sm:mt-6 overflow-hidden"
>
<ul
class="flex flex-row items-center w-full text-[1rem] text-white"
@ -357,15 +182,19 @@
</nav>
{#if subActiveIdx === 0}
<h3 class="text-white text-lg font-semibold mb-2 mt-6">
<h3
class="text-white text-lg sm:text-xl font-semibold mb-2 mt-6 border-y border-gray-800 pt-2 pb-2"
>
Official Presidential Schedule
</h3>
<div
class="max-h-[600px] bg-[#1F1F1F] overflow-y-auto border border-gray-800 rounded-md p-4 no-scrollbar"
>
<div class="space-y-4">
{#each Object.entries(groupedByDate) as [date, items], indexA}
<div class="my-4">
<div
class="border-b border-gray-800 pb-2 w-full flex flex-row items-center justify-between"
class="border-b border-gray-200 pb-2 w-full flex flex-row items-center justify-between"
>
<span
class="text-[1rem] sm:text-lg font-semibold text-white"
@ -446,15 +275,21 @@
</div>
{/each}
</div>
</div>
{:else}
<h3 class="text-white text-lg font-semibold mb-2 mt-6">
AI Analysis of Recent Executive Orders
<h3
class="text-white text-lg sm:text-xl font-semibold mb-2 mt-6 border-y border-gray-800 pt-2 pb-2"
>
AI Executive Orders Analysis
</h3>
<div
class="max-h-[600px] bg-[#1F1F1F] overflow-y-auto border border-gray-800 rounded-md p-4 no-scrollbar"
>
<div class="space-y-4">
{#each Object.entries(groupedOrders) as [date, items], indexA}
<div class="my-4">
<div
class="border-b border-gray-800 pb-2 flex flex-row items-center"
class="border-b border-gray-300 pb-2 flex flex-row items-center"
>
<span class="text-lg font-semibold text-white"
>{date}</span
@ -585,8 +420,10 @@
<g id="Icons1" serif:id="Icons">
<g id="Strike"> </g> <g id="H1"> </g>
<g id="H2"> </g> <g id="H3"> </g>
<g id="list-ul"> </g> <g id="hamburger-1"> </g>
<g id="hamburger-2"> </g> <g id="list-ol"> </g>
<g id="list-ul"> </g>
<g id="hamburger-1"> </g>
<g id="hamburger-2"> </g>
<g id="list-ol"> </g>
<g id="list-task"> </g> <g id="trash"> </g>
<g id="vertical-menu"> </g>
<g id="horizontal-menu"> </g>
@ -601,19 +438,22 @@
d="M55.925,25.32l-4.005,0l0,-10.481l-27.894,27.893l-2.832,-2.832l27.895,-27.895l-10.484,0l0,-4.005l17.318,0l0.002,0.001l0,17.319Z"
></path>
</g> <g id="hr"> </g> <g id="info"> </g>
<g id="warning"> </g> <g id="plus-circle"> </g>
<g id="warning"> </g>
<g id="plus-circle"> </g>
<g id="minus-circle"> </g> <g id="vue"> </g>
<g id="cog"> </g> <g id="logo"> </g>
<g id="radio-check"> </g>
<g id="eye-slash"> </g> <g id="eye"> </g>
<g id="toggle-off"> </g> <g id="shredder"> </g>
<g id="toggle-off"> </g>
<g id="shredder"> </g>
<g
id="spinner--loading--dots-"
serif:id="spinner [loading, dots]"
>
</g> <g id="react"> </g>
<g id="check-selected"> </g>
<g id="turn-off"> </g> <g id="code-block"> </g>
<g id="turn-off"> </g>
<g id="code-block"> </g>
<g id="user"> </g> <g id="coffee-bean"> </g>
<g id="coffee-beans">
<g id="coffee-bean1" serif:id="coffee-bean">
@ -635,6 +475,7 @@
</div>
{/each}
</div>
</div>
{/if}
</div>
@ -702,8 +543,6 @@
</div>
</section>
<ScrollToTop />
<style>
.app {
height: 500px;