add paywall to download button
This commit is contained in:
parent
be62e9f6d6
commit
a0c8a3900a
@ -1708,7 +1708,7 @@
|
||||
{/await}
|
||||
</div>
|
||||
</Lazy>
|
||||
|
||||
<!--
|
||||
<Lazy>
|
||||
<div
|
||||
class="w-full mt-10 sm:mt-5 m-auto sm:pl-6 sm:pb-6 sm:pt-6 {!$borrowedShareComponent
|
||||
@ -1720,7 +1720,8 @@
|
||||
{/await}
|
||||
</div>
|
||||
</Lazy>
|
||||
|
||||
-->
|
||||
<!--
|
||||
<Lazy>
|
||||
<div
|
||||
class="w-full mt-10 sm:mt-5 m-auto sm:pl-6 sm:pb-6 sm:pt-6 {!$marketMakerComponent
|
||||
@ -1732,6 +1733,7 @@
|
||||
{/await}
|
||||
</div>
|
||||
</Lazy>
|
||||
-->
|
||||
|
||||
<Lazy>
|
||||
<div
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js";
|
||||
import { Button } from "$lib/components/shadcn/button/index.js";
|
||||
import { abbreviateNumber } from "$lib/utils";
|
||||
import { goto } from "$app/navigation";
|
||||
//import * as XLSX from 'xlsx';
|
||||
|
||||
import { init, use } from "echarts/core";
|
||||
@ -332,53 +333,54 @@
|
||||
};
|
||||
|
||||
const exportFundamentalData = (format = "csv") => {
|
||||
const data = fullStatement;
|
||||
if (!data || data.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (data?.user?.tier === "Pro") {
|
||||
const data = fullStatement;
|
||||
if (!data || data.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let properties = [
|
||||
{
|
||||
key: filterRule === "annual" ? "calendarYear" : "date",
|
||||
label: filterRule === "annual" ? "Year" : "Quarter",
|
||||
},
|
||||
];
|
||||
let properties = [
|
||||
{
|
||||
key: filterRule === "annual" ? "calendarYear" : "date",
|
||||
label: filterRule === "annual" ? "Year" : "Quarter",
|
||||
},
|
||||
];
|
||||
|
||||
for (let i = 0; i < statementConfig?.length; i++) {
|
||||
properties.push({
|
||||
key: statementConfig[i]?.propertyName,
|
||||
label: statementConfig[i]?.label,
|
||||
});
|
||||
}
|
||||
for (let i = 0; i < statementConfig?.length; i++) {
|
||||
properties.push({
|
||||
key: statementConfig[i]?.propertyName,
|
||||
label: statementConfig[i]?.label,
|
||||
});
|
||||
}
|
||||
|
||||
// Helper function to handle special cases
|
||||
// Helper function to handle special cases
|
||||
|
||||
// Create rows for CSV/Excel
|
||||
let rows = data.map((item) =>
|
||||
properties?.map((property) => item[property?.key] || 0),
|
||||
);
|
||||
// Create rows for CSV/Excel
|
||||
let rows = data.map((item) =>
|
||||
properties?.map((property) => item[property?.key] || 0),
|
||||
);
|
||||
|
||||
// Include headers
|
||||
const headers = properties.map((prop) => prop.label);
|
||||
rows.unshift(headers);
|
||||
// Include headers
|
||||
const headers = properties.map((prop) => prop.label);
|
||||
rows.unshift(headers);
|
||||
|
||||
// Check the format to export
|
||||
if (format.toLowerCase() === "csv") {
|
||||
const csvContent = rows?.map((row) => row.join(",")).join("\n");
|
||||
const blob = new Blob([csvContent], {
|
||||
type: "data:text/csv;charset=utf-8",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download =
|
||||
$stockTicker.toLowerCase() +
|
||||
`${filterRule === "annual" ? "_annual" : "_quarter"}_balance_sheet_statement.csv`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
} /*else if (format.toLowerCase() === "excel") {
|
||||
// Check the format to export
|
||||
if (format.toLowerCase() === "csv") {
|
||||
const csvContent = rows.map((row) => row.join(",")).join("\n");
|
||||
const blob = new Blob([csvContent], {
|
||||
type: "data:text/csv;charset=utf-8",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download =
|
||||
$stockTicker.toLowerCase() +
|
||||
`${filterRule === "annual" ? "_annual" : "_quarter"}_cashflow_statement.csv`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
} /*else if (format.toLowerCase() === "excel") {
|
||||
const worksheet = XLSX.utils.aoa_to_sheet(rows);
|
||||
const workbook = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, "Ratios Statement");
|
||||
@ -389,6 +391,9 @@
|
||||
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
goto("/pricing");
|
||||
}
|
||||
};
|
||||
|
||||
$: {
|
||||
@ -623,6 +628,17 @@
|
||||
class="ml-2 w-full border-gray-600 border bg-[#09090B] sm:hover:bg-[#27272A] ease-out flex flex-row justify-between items-center px-3 py-2 text-white rounded-lg truncate"
|
||||
>
|
||||
<span class="truncate text-white">Download</span>
|
||||
<svg
|
||||
class="{data?.user?.tier === 'Pro'
|
||||
? 'hidden'
|
||||
: ''} ml-1 -mt-0.5 w-3.5 h-3.5"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
><path
|
||||
fill="#A3A3A3"
|
||||
d="M17 9V7c0-2.8-2.2-5-5-5S7 4.2 7 7v2c-1.7 0-3 1.3-3 3v7c0 1.7 1.3 3 3 3h10c1.7 0 3-1.3 3-3v-7c0-1.7-1.3-3-3-3M9 7c0-1.7 1.3-3 3-3s3 1.3 3 3v2H9z"
|
||||
/></svg
|
||||
>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
import { Button } from "$lib/components/shadcn/button/index.js";
|
||||
//import * as XLSX from 'xlsx';
|
||||
import { Chart } from "svelte-echarts";
|
||||
|
||||
import { goto } from "$app/navigation";
|
||||
import { init, use } from "echarts/core";
|
||||
import { LineChart, BarChart } from "echarts/charts";
|
||||
import { GridComponent, TooltipComponent } from "echarts/components";
|
||||
@ -278,53 +278,54 @@
|
||||
};
|
||||
|
||||
const exportFundamentalData = (format = "csv") => {
|
||||
const data = fullStatement;
|
||||
if (!data || data.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (data?.user?.tier === "Pro") {
|
||||
const data = fullStatement;
|
||||
if (!data || data.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let properties = [
|
||||
{
|
||||
key: filterRule === "annual" ? "calendarYear" : "date",
|
||||
label: filterRule === "annual" ? "Year" : "Quarter",
|
||||
},
|
||||
];
|
||||
let properties = [
|
||||
{
|
||||
key: filterRule === "annual" ? "calendarYear" : "date",
|
||||
label: filterRule === "annual" ? "Year" : "Quarter",
|
||||
},
|
||||
];
|
||||
|
||||
for (let i = 0; i < statementConfig?.length; i++) {
|
||||
properties.push({
|
||||
key: statementConfig[i]?.propertyName,
|
||||
label: statementConfig[i]?.label,
|
||||
});
|
||||
}
|
||||
for (let i = 0; i < statementConfig?.length; i++) {
|
||||
properties.push({
|
||||
key: statementConfig[i]?.propertyName,
|
||||
label: statementConfig[i]?.label,
|
||||
});
|
||||
}
|
||||
|
||||
// Helper function to handle special cases
|
||||
// Helper function to handle special cases
|
||||
|
||||
// Create rows for CSV/Excel
|
||||
let rows = data.map((item) =>
|
||||
properties?.map((property) => item[property?.key] || 0),
|
||||
);
|
||||
// Create rows for CSV/Excel
|
||||
let rows = data.map((item) =>
|
||||
properties?.map((property) => item[property?.key] || 0),
|
||||
);
|
||||
|
||||
// Include headers
|
||||
const headers = properties.map((prop) => prop.label);
|
||||
rows.unshift(headers);
|
||||
// Include headers
|
||||
const headers = properties.map((prop) => prop.label);
|
||||
rows.unshift(headers);
|
||||
|
||||
// Check the format to export
|
||||
if (format.toLowerCase() === "csv") {
|
||||
const csvContent = rows?.map((row) => row.join(",")).join("\n");
|
||||
const blob = new Blob([csvContent], {
|
||||
type: "data:text/csv;charset=utf-8",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download =
|
||||
$stockTicker.toLowerCase() +
|
||||
`${filterRule === "annual" ? "_annual" : "_quarter"}_cashflow_statement.csv`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
} /*else if (format.toLowerCase() === "excel") {
|
||||
// Check the format to export
|
||||
if (format.toLowerCase() === "csv") {
|
||||
const csvContent = rows.map((row) => row.join(",")).join("\n");
|
||||
const blob = new Blob([csvContent], {
|
||||
type: "data:text/csv;charset=utf-8",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download =
|
||||
$stockTicker.toLowerCase() +
|
||||
`${filterRule === "annual" ? "_annual" : "_quarter"}_cashflow_statement.csv`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
} /*else if (format.toLowerCase() === "excel") {
|
||||
const worksheet = XLSX.utils.aoa_to_sheet(rows);
|
||||
const workbook = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, "Ratios Statement");
|
||||
@ -335,6 +336,9 @@
|
||||
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
goto("/pricing");
|
||||
}
|
||||
};
|
||||
|
||||
$: {
|
||||
@ -567,6 +571,17 @@
|
||||
class="ml-2 w-full border-gray-600 border bg-[#09090B] sm:hover:bg-[#27272A] ease-out flex flex-row justify-between items-center px-3 py-2 text-white rounded-lg truncate"
|
||||
>
|
||||
<span class="truncate text-white">Download</span>
|
||||
<svg
|
||||
class="{data?.user?.tier === 'Pro'
|
||||
? 'hidden'
|
||||
: ''} ml-1 -mt-0.5 w-3.5 h-3.5"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
><path
|
||||
fill="#A3A3A3"
|
||||
d="M17 9V7c0-2.8-2.2-5-5-5S7 4.2 7 7v2c-1.7 0-3 1.3-3 3v7c0 1.7 1.3 3 3 3h10c1.7 0 3-1.3 3-3v-7c0-1.7-1.3-3-3-3M9 7c0-1.7 1.3-3 3-3s3 1.3 3 3v2H9z"
|
||||
/></svg
|
||||
>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
} from "$lib/store";
|
||||
import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js";
|
||||
import { Button } from "$lib/components/shadcn/button/index.js";
|
||||
import { goto } from "$app/navigation";
|
||||
import { Chart } from "svelte-echarts";
|
||||
import { init, use } from "echarts/core";
|
||||
import { BarChart } from "echarts/charts";
|
||||
@ -260,55 +261,59 @@
|
||||
}
|
||||
|
||||
const exportData = (format = "csv") => {
|
||||
// Add headers row
|
||||
const csvRows = [];
|
||||
csvRows.push("Date,Employees,Change,Growth");
|
||||
if (data?.user?.tier === "Pro") {
|
||||
// Add headers row
|
||||
const csvRows = [];
|
||||
csvRows.push("Date,Employees,Change,Growth");
|
||||
|
||||
// Add data rows
|
||||
historyList.forEach((item, index) => {
|
||||
const date = new Date(item.filingDate).toLocaleString("en-US", {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: "numeric",
|
||||
// Add data rows
|
||||
historyList.forEach((item, index) => {
|
||||
const date = new Date(item.filingDate).toLocaleString("en-US", {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: "numeric",
|
||||
});
|
||||
|
||||
const employees = item.employeeCount;
|
||||
|
||||
// Calculate change
|
||||
const change =
|
||||
index + 1 < historyList.length
|
||||
? item.employeeCount - historyList[index + 1].employeeCount
|
||||
: 0;
|
||||
|
||||
// Calculate growth percentage
|
||||
let growth = "0.00%";
|
||||
if (index + 1 < historyList.length) {
|
||||
const growthValue =
|
||||
((item.employeeCount - historyList[index + 1].employeeCount) /
|
||||
item.employeeCount) *
|
||||
100;
|
||||
if (growthValue > 0) {
|
||||
growth = `+${growthValue.toFixed(2)}%`;
|
||||
} else if (growthValue < 0) {
|
||||
growth = `-${Math.abs(growthValue).toFixed(2)}%`;
|
||||
}
|
||||
}
|
||||
|
||||
const csvRow = `${date},${employees},${change},${growth}`;
|
||||
csvRows.push(csvRow);
|
||||
});
|
||||
|
||||
const employees = item.employeeCount;
|
||||
|
||||
// Calculate change
|
||||
const change =
|
||||
index + 1 < historyList.length
|
||||
? item.employeeCount - historyList[index + 1].employeeCount
|
||||
: 0;
|
||||
|
||||
// Calculate growth percentage
|
||||
let growth = "0.00%";
|
||||
if (index + 1 < historyList.length) {
|
||||
const growthValue =
|
||||
((item.employeeCount - historyList[index + 1].employeeCount) /
|
||||
item.employeeCount) *
|
||||
100;
|
||||
if (growthValue > 0) {
|
||||
growth = `+${growthValue.toFixed(2)}%`;
|
||||
} else if (growthValue < 0) {
|
||||
growth = `-${Math.abs(growthValue).toFixed(2)}%`;
|
||||
}
|
||||
}
|
||||
|
||||
const csvRow = `${date},${employees},${change},${growth}`;
|
||||
csvRows.push(csvRow);
|
||||
});
|
||||
|
||||
// Create CSV blob and trigger download
|
||||
const csv = csvRows.join("\n");
|
||||
const blob = new Blob([csv], { type: "text/csv" });
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.setAttribute("hidden", "");
|
||||
a.setAttribute("href", url);
|
||||
a.setAttribute("download", `${$stockTicker}_employees.csv`);
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
// Create CSV blob and trigger download
|
||||
const csv = csvRows.join("\n");
|
||||
const blob = new Blob([csv], { type: "text/csv" });
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.setAttribute("hidden", "");
|
||||
a.setAttribute("href", url);
|
||||
a.setAttribute("download", `${$stockTicker}_employees.csv`);
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
} else {
|
||||
goto("/pricing");
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@ -546,6 +551,17 @@
|
||||
class="ml-2 w-full border-gray-600 border bg-[#09090B] sm:hover:bg-[#27272A] ease-out flex flex-row justify-between items-center px-3 py-2 text-white rounded-lg truncate"
|
||||
>
|
||||
<span class="truncate text-white">Download</span>
|
||||
<svg
|
||||
class="{data?.user?.tier === 'Pro'
|
||||
? 'hidden'
|
||||
: ''} ml-1 -mt-0.5 w-3.5 h-3.5"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
><path
|
||||
fill="#A3A3A3"
|
||||
d="M17 9V7c0-2.8-2.2-5-5-5S7 4.2 7 7v2c-1.7 0-3 1.3-3 3v7c0 1.7 1.3 3 3 3h10c1.7 0 3-1.3 3-3v-7c0-1.7-1.3-3-3-3M9 7c0-1.7 1.3-3 3-3s3 1.3 3 3v2H9z"
|
||||
/></svg
|
||||
>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
import { Button } from "$lib/components/shadcn/button/index.js";
|
||||
//import * as XLSX from 'xlsx';
|
||||
import { Chart } from "svelte-echarts";
|
||||
|
||||
import { goto } from "$app/navigation";
|
||||
import { init, use } from "echarts/core";
|
||||
import { LineChart, BarChart } from "echarts/charts";
|
||||
import { GridComponent, TooltipComponent } from "echarts/components";
|
||||
@ -258,53 +258,54 @@
|
||||
displayStatement = "revenue";
|
||||
|
||||
const exportFundamentalData = (format = "csv") => {
|
||||
const data = fullStatement;
|
||||
if (!data || data.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (data?.user?.tier === "Pro") {
|
||||
const data = fullStatement;
|
||||
if (!data || data.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let properties = [
|
||||
{
|
||||
key: filterRule === "annual" ? "calendarYear" : "date",
|
||||
label: filterRule === "annual" ? "Year" : "Quarter",
|
||||
},
|
||||
];
|
||||
let properties = [
|
||||
{
|
||||
key: filterRule === "annual" ? "calendarYear" : "date",
|
||||
label: filterRule === "annual" ? "Year" : "Quarter",
|
||||
},
|
||||
];
|
||||
|
||||
for (let i = 0; i < statementConfig?.length; i++) {
|
||||
properties.push({
|
||||
key: statementConfig[i]?.propertyName,
|
||||
label: statementConfig[i]?.label,
|
||||
});
|
||||
}
|
||||
for (let i = 0; i < statementConfig?.length; i++) {
|
||||
properties.push({
|
||||
key: statementConfig[i]?.propertyName,
|
||||
label: statementConfig[i]?.label,
|
||||
});
|
||||
}
|
||||
|
||||
// Helper function to handle special cases
|
||||
// Helper function to handle special cases
|
||||
|
||||
// Create rows for CSV/Excel
|
||||
let rows = data.map((item) =>
|
||||
properties?.map((property) => item[property?.key] || 0),
|
||||
);
|
||||
// Create rows for CSV/Excel
|
||||
let rows = data.map((item) =>
|
||||
properties?.map((property) => item[property?.key] || 0),
|
||||
);
|
||||
|
||||
// Include headers
|
||||
const headers = properties.map((prop) => prop.label);
|
||||
rows.unshift(headers);
|
||||
// Include headers
|
||||
const headers = properties.map((prop) => prop.label);
|
||||
rows.unshift(headers);
|
||||
|
||||
// Check the format to export
|
||||
if (format.toLowerCase() === "csv") {
|
||||
const csvContent = rows.map((row) => row.join(",")).join("\n");
|
||||
const blob = new Blob([csvContent], {
|
||||
type: "data:text/csv;charset=utf-8",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download =
|
||||
$stockTicker.toLowerCase() +
|
||||
`${filterRule === "annual" ? "_annual" : "_quarter"}_income_statement.csv`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
} /*else if (format.toLowerCase() === "excel") {
|
||||
// Check the format to export
|
||||
if (format.toLowerCase() === "csv") {
|
||||
const csvContent = rows.map((row) => row.join(",")).join("\n");
|
||||
const blob = new Blob([csvContent], {
|
||||
type: "data:text/csv;charset=utf-8",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download =
|
||||
$stockTicker.toLowerCase() +
|
||||
`${filterRule === "annual" ? "_annual" : "_quarter"}_income_statement.csv`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
} /*else if (format.toLowerCase() === "excel") {
|
||||
const worksheet = XLSX.utils.aoa_to_sheet(rows);
|
||||
const workbook = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, "Ratios Statement");
|
||||
@ -315,6 +316,9 @@
|
||||
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
goto("/pricing");
|
||||
}
|
||||
};
|
||||
|
||||
$: {
|
||||
@ -548,6 +552,17 @@
|
||||
class="ml-2 w-full border-gray-600 border bg-[#09090B] sm:hover:bg-[#27272A] ease-out flex flex-row justify-between items-center px-3 py-2 text-white rounded-lg truncate"
|
||||
>
|
||||
<span class="truncate text-white">Download</span>
|
||||
<svg
|
||||
class="{data?.user?.tier === 'Pro'
|
||||
? 'hidden'
|
||||
: ''} ml-1 -mt-0.5 w-3.5 h-3.5"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
><path
|
||||
fill="#A3A3A3"
|
||||
d="M17 9V7c0-2.8-2.2-5-5-5S7 4.2 7 7v2c-1.7 0-3 1.3-3 3v7c0 1.7 1.3 3 3 3h10c1.7 0 3-1.3 3-3v-7c0-1.7-1.3-3-3-3M9 7c0-1.7 1.3-3 3-3s3 1.3 3 3v2H9z"
|
||||
/></svg
|
||||
>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js";
|
||||
import { Button } from "$lib/components/shadcn/button/index.js";
|
||||
//import * as XLSX from 'xlsx';
|
||||
import { goto } from "$app/navigation";
|
||||
import { Chart } from "svelte-echarts";
|
||||
|
||||
import { init, use } from "echarts/core";
|
||||
@ -242,50 +243,54 @@
|
||||
}
|
||||
|
||||
const exportData = (format = "csv") => {
|
||||
// Add headers row
|
||||
const csvRows = [];
|
||||
if (data?.user?.tier === "Pro") {
|
||||
// Add headers row
|
||||
const csvRows = [];
|
||||
|
||||
csvRows.push("Date,Market Cap,Growth");
|
||||
csvRows.push("Date,Market Cap,Growth");
|
||||
|
||||
// Add data rows
|
||||
tableList?.forEach((item, index) => {
|
||||
const date = item.date;
|
||||
const marketCap = item.marketCap;
|
||||
// Add data rows
|
||||
tableList?.forEach((item, index) => {
|
||||
const date = item.date;
|
||||
const marketCap = item.marketCap;
|
||||
|
||||
// Calculate growth percentage
|
||||
let growth = "-";
|
||||
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)}%`;
|
||||
// Calculate growth percentage
|
||||
let growth = "-";
|
||||
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);
|
||||
});
|
||||
const csvRow = `${date},${marketCap},${growth}`;
|
||||
csvRows.push(csvRow);
|
||||
});
|
||||
|
||||
// Create CSV blob and trigger download
|
||||
const csv = csvRows.join("\n");
|
||||
const blob = new Blob([csv], { type: "text/csv" });
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.setAttribute("hidden", "");
|
||||
a.setAttribute("href", url);
|
||||
a.setAttribute("download", `${$stockTicker}_market_cap.csv`);
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
// Create CSV blob and trigger download
|
||||
const csv = csvRows.join("\n");
|
||||
const blob = new Blob([csv], { type: "text/csv" });
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.setAttribute("hidden", "");
|
||||
a.setAttribute("href", url);
|
||||
a.setAttribute("download", `${$stockTicker}_market_cap.csv`);
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
} else {
|
||||
goto("/pricing");
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@ -447,6 +452,17 @@
|
||||
class="ml-2 w-full border-gray-600 border bg-[#09090B] sm:hover:bg-[#27272A] ease-out flex flex-row justify-between items-center px-3 py-2 text-white rounded-lg truncate"
|
||||
>
|
||||
<span class="truncate text-white">Download</span>
|
||||
<svg
|
||||
class="{data?.user?.tier === 'Pro'
|
||||
? 'hidden'
|
||||
: ''} ml-1 -mt-0.5 w-3.5 h-3.5"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
><path
|
||||
fill="#A3A3A3"
|
||||
d="M17 9V7c0-2.8-2.2-5-5-5S7 4.2 7 7v2c-1.7 0-3 1.3-3 3v7c0 1.7 1.3 3 3 3h10c1.7 0 3-1.3 3-3v-7c0-1.7-1.3-3-3-3M9 7c0-1.7 1.3-3 3-3s3 1.3 3 3v2H9z"
|
||||
/></svg
|
||||
>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js";
|
||||
import { Button } from "$lib/components/shadcn/button/index.js";
|
||||
//import * as XLSX from 'xlsx';
|
||||
import { goto } from "$app/navigation";
|
||||
import { init, use } from "echarts/core";
|
||||
import { LineChart, BarChart } from "echarts/charts";
|
||||
import { GridComponent, TooltipComponent } from "echarts/components";
|
||||
@ -217,53 +218,54 @@
|
||||
}
|
||||
|
||||
const exportFundamentalData = (format = "csv") => {
|
||||
const data = fullStatement;
|
||||
if (!data || data.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (data?.user?.tier === "Pro") {
|
||||
const data = fullStatement;
|
||||
if (!data || data.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let properties = [
|
||||
{
|
||||
key: filterRule === "annual" ? "calendarYear" : "date",
|
||||
label: filterRule === "annual" ? "Year" : "Quarter",
|
||||
},
|
||||
];
|
||||
let properties = [
|
||||
{
|
||||
key: filterRule === "annual" ? "calendarYear" : "date",
|
||||
label: filterRule === "annual" ? "Year" : "Quarter",
|
||||
},
|
||||
];
|
||||
|
||||
for (let i = 0; i < statementConfig?.length; i++) {
|
||||
properties.push({
|
||||
key: statementConfig[i]?.propertyName,
|
||||
label: statementConfig[i]?.label,
|
||||
});
|
||||
}
|
||||
for (let i = 0; i < statementConfig?.length; i++) {
|
||||
properties.push({
|
||||
key: statementConfig[i]?.propertyName,
|
||||
label: statementConfig[i]?.label,
|
||||
});
|
||||
}
|
||||
|
||||
// Helper function to handle special cases
|
||||
// Helper function to handle special cases
|
||||
|
||||
// Create rows for CSV/Excel
|
||||
let rows = data.map((item) =>
|
||||
properties?.map((property) => item[property?.key] || 0),
|
||||
);
|
||||
// Create rows for CSV/Excel
|
||||
let rows = data.map((item) =>
|
||||
properties?.map((property) => item[property?.key] || 0),
|
||||
);
|
||||
|
||||
// Include headers
|
||||
const headers = properties.map((prop) => prop.label);
|
||||
rows.unshift(headers);
|
||||
// Include headers
|
||||
const headers = properties.map((prop) => prop.label);
|
||||
rows.unshift(headers);
|
||||
|
||||
// Check the format to export
|
||||
if (format.toLowerCase() === "csv") {
|
||||
const csvContent = rows.map((row) => row.join(",")).join("\n");
|
||||
const blob = new Blob([csvContent], {
|
||||
type: "data:text/csv;charset=utf-8",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download =
|
||||
$stockTicker.toLowerCase() +
|
||||
`${filterRule === "annual" ? "_annual" : "_quarter"}_ratios_statement.csv`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
} /*else if (format.toLowerCase() === "excel") {
|
||||
// Check the format to export
|
||||
if (format.toLowerCase() === "csv") {
|
||||
const csvContent = rows.map((row) => row.join(",")).join("\n");
|
||||
const blob = new Blob([csvContent], {
|
||||
type: "data:text/csv;charset=utf-8",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download =
|
||||
$stockTicker.toLowerCase() +
|
||||
`${filterRule === "annual" ? "_annual" : "_quarter"}_balance_sheet_statement.csv`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
} /*else if (format.toLowerCase() === "excel") {
|
||||
const worksheet = XLSX.utils.aoa_to_sheet(rows);
|
||||
const workbook = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, "Ratios Statement");
|
||||
@ -274,6 +276,9 @@
|
||||
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
goto("/pricing");
|
||||
}
|
||||
};
|
||||
|
||||
fullStatement = data?.getRatiosStatement;
|
||||
@ -532,6 +537,17 @@
|
||||
class="ml-2 w-full border-gray-600 border bg-[#09090B] sm:hover:bg-[#27272A] ease-out flex flex-row justify-between items-center px-3 py-2 text-white rounded-lg truncate"
|
||||
>
|
||||
<span class="truncate text-white">Download</span>
|
||||
<svg
|
||||
class="{data?.user?.tier === 'Pro'
|
||||
? 'hidden'
|
||||
: ''} ml-1 -mt-0.5 w-3.5 h-3.5"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
><path
|
||||
fill="#A3A3A3"
|
||||
d="M17 9V7c0-2.8-2.2-5-5-5S7 4.2 7 7v2c-1.7 0-3 1.3-3 3v7c0 1.7 1.3 3 3 3h10c1.7 0 3-1.3 3-3v-7c0-1.7-1.3-3-3-3M9 7c0-1.7 1.3-3 3-3s3 1.3 3 3v2H9z"
|
||||
/></svg
|
||||
>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user