Download script.js from Shichi1462/pensionpulse-visualizer: direct link, hf CLI and curl.
- Browser
- Download file 5.76 kB
-
https://huggingface.co/spaces/Shichi1462/pensionpulse-visualizer/resolve/main/script.js
- Command line
-
hf download hf://spaces/Shichi1462/pensionpulse-visualizer/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Shichi1462/pensionpulse-visualizer/resolve/main/script.js
5.76 kB
| document.addEventListener('DOMContentLoaded', function() { | |
| // Register dashboard cards component | |
| if (!customElements.get('dashboard-card')) { | |
| customElements.define('dashboard-card', class extends HTMLElement {}); | |
| } | |
| // Portfolio data | |
| const portfolioData = { | |
| "HDFC Bank Ltd": { value: 28425.57, percentage: 9.82, industry: "Banking" }, | |
| "Bajaj Holdings & Investment Ltd.": { value: 27400.34, percentage: 9.47, industry: "Holding Companies" }, | |
| "Kotak Mahindra Bank Ltd": { value: 26014.42, percentage: 8.99, industry: "Banking" }, | |
| "ITC Ltd": { value: 25127.19, percentage: 8.68, industry: "Tobacco" }, | |
| "ICICI Bank Ltd": { value: 14669.21, percentage: 5.07, industry: "Banking" }, | |
| "Bajaj Finance Ltd.": { value: 13727.38, percentage: 4.74, industry: "Finance" }, | |
| "Power Grid Corporation of India Ltd.": { value: 12370.09, percentage: 4.27, industry: "Energy" }, | |
| "Tata Consultancy Services Ltd": { value: 12041.54, percentage: 4.16, industry: "IT Services" }, | |
| "Infosys Ltd": { value: 10106.66, percentage: 3.49, industry: "IT Services" }, | |
| "Mahindra & Mahindra Ltd": { value: 8514.66, percentage: 2.94, industry: "Automobiles" } | |
| }; | |
| // Asset allocation data | |
| const assetData = { | |
| labels: ["Equity", "Money Market", "Cash"], | |
| datasets: [{ | |
| data: [91.62, 8.32, 0.06], | |
| backgroundColor: ["#4f46e5", "#10b981", "#3b82f6"], | |
| borderWidth: 0 | |
| }] | |
| }; | |
| // Portfolio history data | |
| const historyData = { | |
| labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep"], | |
| datasets: [{ | |
| label: "NAV (₹)", | |
| data: [12.45, 12.52, 12.58, 12.62, 12.71, 12.78, 12.82, 12.88, 12.89], | |
| borderColor: "#4f46e5", | |
| backgroundColor: "rgba(79, 70, 229, 0.1)", | |
| fill: true, | |
| tension: 0.3 | |
| }] | |
| }; | |
| // Initialize charts | |
| function initCharts() { | |
| // Asset allocation pie chart | |
| const assetCtx = document.getElementById('assetChart').getContext('2d'); | |
| new Chart(assetCtx, { | |
| type: 'pie', | |
| data: assetData, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { | |
| position: 'right', | |
| }, | |
| tooltip: { | |
| callbacks: { | |
| label: function(context) { | |
| return `${context.label}: ${context.raw}%`; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| // Top holdings bar chart | |
| const holdingsCtx = document.getElementById('holdingsChart').getContext('2d'); | |
| const holdingsLabels = Object.keys(portfolioData); | |
| const holdingsValues = Object.values(portfolioData).map(item => item.value); | |
| new Chart(holdingsCtx, { | |
| type: 'bar', | |
| data: { | |
| labels: holdingsLabels, | |
| datasets: [{ | |
| label: 'Value (₹ Cr)', | |
| data: holdingsValues, | |
| backgroundColor: '#4f46e5', | |
| borderRadius: 4 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| scales: { | |
| y: { | |
| beginAtZero: true, | |
| title: { | |
| display: true, | |
| text: 'Value (₹ Cr)' | |
| } | |
| }, | |
| x: { | |
| ticks: { | |
| autoSkip: false, | |
| maxRotation: 45, | |
| minRotation: 45 | |
| } | |
| } | |
| }, | |
| plugins: { | |
| legend: { | |
| display: false | |
| } | |
| } | |
| } | |
| }); | |
| // Portfolio history line chart | |
| const historyCtx = document.getElementById('historyChart').getContext('2d'); | |
| new Chart(historyCtx, { | |
| type: 'line', | |
| data: historyData, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| scales: { | |
| y: { | |
| beginAtZero: false, | |
| title: { | |
| display: true, | |
| text: 'NAV (₹)' | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| // Populate table with portfolio data | |
| function populateTable() { | |
| const tableBody = document.querySelector('tbody'); | |
| Object.entries(portfolioData).forEach(([company, data]) => { | |
| const row = document.createElement('tr'); | |
| row.innerHTML = ` | |
| <td class="px-6 py-4 whitespace-nowrap font-medium text-gray-900">${company}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-gray-500">${data.industry}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-gray-900">${data.value.toLocaleString('en-IN')}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-gray-900">${data.percentage}%</td> | |
| `; | |
| tableBody.appendChild(row); | |
| }); | |
| } | |
| // Initialize everything | |
| initCharts(); | |
| populateTable(); | |
| // Refresh feather icons after dynamic content | |
| setTimeout(() => feather.replace(), 100); | |
| }); |