bugfixing
This commit is contained in:
parent
6d0f71348c
commit
f1f6d851f3
@ -316,40 +316,18 @@
|
|||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportData = (format = "csv") => {
|
const exportData = (format = "csv") => {
|
||||||
if (data?.user?.tier === "Pro") {
|
if (data?.user?.tier === "Pro") {
|
||||||
// Add headers row
|
// Add headers row
|
||||||
const csvRows = [];
|
const csvRows = [];
|
||||||
|
csvRows.push("date,market-cap");
|
||||||
csvRows.push("Date,Market Cap,Growth");
|
|
||||||
|
|
||||||
// Add data rows
|
// Add data rows
|
||||||
tableList?.forEach((item, index) => {
|
const filteredData = filterDataByTimePeriod(rawData, "Max");
|
||||||
const date = item.date;
|
const { dates, marketCapList } = filteredData;
|
||||||
const marketCap = item.marketCap;
|
|
||||||
|
|
||||||
// Calculate growth percentage
|
dates.forEach((date, index) => {
|
||||||
let growth = "-";
|
csvRows.push(`${date},${marketCapList[index]}`);
|
||||||
if (index + 1 < tableList.length) {
|
|
||||||
if (item.marketCap - tableList[index + 1].marketCap > 0) {
|
|
||||||
growth = `+${(
|
|
||||||
((item.marketCap - tableList[index + 1].marketCap) /
|
|
||||||
item.marketCap) *
|
|
||||||
100
|
|
||||||
).toFixed(2)}%`;
|
|
||||||
} else if (item.marketCap - tableList[index + 1].marketCap < 0) {
|
|
||||||
growth = `-${(
|
|
||||||
Math.abs(
|
|
||||||
(tableList[index + 1].marketCap - item.marketCap) /
|
|
||||||
item.marketCap,
|
|
||||||
) * 100
|
|
||||||
).toFixed(2)}%`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const csvRow = `${date},${marketCap},${growth}`;
|
|
||||||
csvRows.push(csvRow);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create CSV blob and trigger download
|
// Create CSV blob and trigger download
|
||||||
@ -359,7 +337,10 @@
|
|||||||
const a = document.createElement("a");
|
const a = document.createElement("a");
|
||||||
a.setAttribute("hidden", "");
|
a.setAttribute("hidden", "");
|
||||||
a.setAttribute("href", url);
|
a.setAttribute("href", url);
|
||||||
a.setAttribute("download", `${$stockTicker}_market_cap.csv`);
|
a.setAttribute(
|
||||||
|
"download",
|
||||||
|
`${$stockTicker?.toLowerCase()}_market_cap.csv`,
|
||||||
|
);
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user