bugfixing heatmap

This commit is contained in:
MuslemRahimi 2024-08-08 10:54:23 +02:00
parent 2a4d10a7db
commit 4671c27f31

View File

@ -15,11 +15,11 @@ export let data;
let cloudFrontUrl = import.meta.env.VITE_IMAGE_URL;
let displayIndex = 'S&P500';
let lowestSumCategory = null;
let highestSumCategory = null;
let lowestSum = Infinity;
let highestSum = -Infinity;
let lowestAvg = Infinity;
let lowestAvgCategory = '';
let highestAvg = -Infinity;
let highestAvgCategory = '';
let rawData;
@ -100,26 +100,24 @@ function getLevelOption() {
}
function plotData(fontSize) {
lowestSum = Infinity;
highestSum = -Infinity;
rawData.forEach(category => {
let sum = category?.children?.reduce((acc, stock) => acc + stock?.changesPercentage, 0);
if (sum < lowestSum) {
lowestSum = sum;
lowestSumCategory = category.name;
}
});
if (category?.children && category.children.length > 0) {
let sum = category.children.reduce((acc, stock) => acc + (stock?.changesPercentage || 0), 0);
let avg = sum / category.children.length;
rawData?.forEach(category => {
let sum = category?.children?.reduce((acc, stock) => acc + stock?.changesPercentage, 0);
if (sum > highestSum) {
highestSum = sum;
highestSumCategory = category.name;
if (avg < lowestAvg) {
lowestAvg = avg;
lowestAvgCategory = category.name;
}
if (avg > highestAvg) {
highestAvg = avg;
highestAvgCategory = category.name;
}
}
});
});
options = {
@ -376,8 +374,8 @@ $: {
<div class="w-full sm:flex sm:flex-row sm:items-center m-auto text-gray-100 border border-gray-800 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>
<span>
Today, <label on:click={() => sectorSelector(lowestSumCategory)} class="cursor-pointer text-blue-400 sm:hover:text-white">{lowestSumCategory}</label> took the lead as the {displayIndex} largest loser, marking a cumulative return of <span class="text-white font-medium">{lowestSum?.toFixed(2)}%</span>,
while <label on:click={() => sectorSelector(highestSumCategory)} class="cursor-pointer text-blue-400 sm:hover:text-white">{highestSumCategory}</label> surged ahead as the top performer with an impressive cumulative return of <span class="text-white font-medium">{highestSum?.toFixed(2)}%</span>.
Today, <label on:click={() => sectorSelector(lowestAvgCategory)} class="cursor-pointer text-blue-400 sm:hover:text-white">{lowestAvgCategory}</label> took the lead as the {displayIndex} largest loser, marking a average return of <span class="text-white font-medium">{lowestAvg?.toFixed(2)}%</span>,
while <label on:click={() => sectorSelector(highestAvgCategory)} class="cursor-pointer text-blue-400 sm:hover:text-white">{highestAvgCategory}</label> surged ahead as the top performer with an impressive average return of <span class="text-white font-medium">{highestAvg?.toFixed(2)}%</span>.
</span>
</div>