-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
280 lines (248 loc) · 15.4 KB
/
Copy pathindex.html
File metadata and controls
280 lines (248 loc) · 15.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Investment Calculator</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="icon" href="https://i.imgur.com/jQzq7WM.png" type="image/png">
<script>
tailwind.config = {
darkMode: 'class',
theme: { extend: { colors: { primary: 'var(--primary)' } } }
}
</script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
:root { --primary: #6366f1; }
body { font-family: 'Inter', sans-serif; transition: background 0.4s ease; }
/* Slider Styling */
.slider { -webkit-appearance: none; width: 100%; height: 6px; background: #e2e8f0; border-radius: 5px; outline: none; }
.dark .slider { background: #334155; }
.slider::-webkit-slider-thumb {
-webkit-appearance: none; width: 22px; height: 22px;
background: var(--primary); cursor: pointer; border-radius: 50%;
border: 4px solid white; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.15);
}
.dark .slider::-webkit-slider-thumb { border-color: #0f172a; }
/* Expanding Theme Picker */
.theme-pill { max-width: 44px; transition: max-width 0.5s cubic-bezier(0.4, 0, 0.2, 1); overflow: hidden; }
.theme-pill.expanded { max-width: 320px; }
.theme-circle { width: 26px; height: 26px; border-radius: 50%; cursor: pointer; flex-shrink: 0; transition: transform 0.2s; }
.theme-circle:hover { transform: scale(1.1); }
.tab-active { border-bottom: 3px solid var(--primary); color: var(--primary); font-weight: 700; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
/* Custom Scrollbar for Tabs on Mobile */
.no-scrollbar::-webkit-scrollbar { display: none; }
</style>
</head>
<body class="bg-slate-50 dark:bg-slate-950 p-4 md:p-10 text-slate-900 dark:text-slate-100 min-h-screen">
<div class="max-w-5xl mx-auto">
<!-- Header -->
<div class="flex items-center justify-between mb-8">
<div>
<h1 class="text-2xl font-bold tracking-tight">Invest<span style="color: var(--primary)">Logic</span></h1>
<p class="text-[10px] uppercase tracking-[0.2em] text-slate-400 font-bold hidden md:block">Financial Intelligence</p>
</div>
<div class="flex items-center gap-3">
<!-- Theme Picker -->
<div id="theme-pill" class="theme-pill flex items-center bg-white dark:bg-slate-900 p-2 rounded-full border border-slate-200 dark:border-slate-800 shadow-sm">
<button onclick="document.getElementById('theme-pill').classList.toggle('expanded')" id="current-color-btn" class="theme-circle shadow-md ring-2 ring-white dark:ring-slate-800" style="background: var(--primary)"></button>
<div class="flex gap-2.5 ml-4 mr-2" id="theme-options"></div>
</div>
<!-- Dark Mode Toggle with Sun/Moon Icons -->
<button onclick="toggleDark()" class="p-2.5 rounded-full bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 shadow-sm hover:bg-slate-100 dark:hover:bg-slate-800 transition-all">
<span id="sun-icon" class="hidden text-lg">☀️</span>
<span id="moon-icon" class="text-lg">🌙</span>
</button>
</div>
</div>
<!-- Main Card -->
<div class="bg-white dark:bg-slate-900 rounded-[2.5rem] shadow-2xl shadow-slate-200 dark:shadow-none overflow-hidden border border-slate-100 dark:border-slate-800">
<!-- Navigation Tabs -->
<div class="flex px-8 pt-6 border-b border-slate-100 dark:border-slate-800 gap-8 overflow-x-auto no-scrollbar">
<button onclick="switchTab('sip')" id="tab-sip" class="pb-4 text-xs uppercase tracking-widest font-bold text-slate-400 tab-active">SIP</button>
<button onclick="switchTab('lumpsum')" id="tab-lumpsum" class="pb-4 text-xs uppercase tracking-widest font-bold text-slate-400">Lumpsum</button>
<button onclick="switchTab('swp')" id="tab-swp" class="pb-4 text-xs uppercase tracking-widest font-bold text-slate-400">SWP</button>
</div>
<div class="p-6 md:p-12 grid grid-cols-1 lg:grid-cols-2 gap-10 lg:gap-20">
<!-- Inputs -->
<div class="space-y-8">
<h2 id="calc-title" class="text-xl font-bold tracking-tight text-slate-700 dark:text-slate-200 uppercase text-xs">SIP Calculator</h2>
<div id="inputs-container" class="space-y-8"></div>
</div>
<!-- Results Section (Mobile Optimized) -->
<div class="bg-slate-50/50 dark:bg-slate-800/40 rounded-[2.5rem] p-6 md:p-10 border border-slate-100 dark:border-slate-800 flex flex-col items-center">
<div class="w-full max-w-[240px] mb-10">
<canvas id="resultChart"></canvas>
</div>
<div class="w-full space-y-4">
<!-- Result 1 -->
<div class="bg-white dark:bg-slate-900 p-5 rounded-2xl border border-slate-100 dark:border-slate-800 shadow-sm">
<p class="text-[10px] font-bold text-slate-400 uppercase tracking-widest mb-1" id="label-1">Invested</p>
<p class="text-xl md:text-2xl font-bold break-all leading-tight text-slate-800 dark:text-slate-100" id="res-invested">₹0</p>
</div>
<!-- Result 2 -->
<div class="bg-white dark:bg-slate-900 p-5 rounded-2xl border border-slate-100 dark:border-slate-800 shadow-sm">
<p class="text-[10px] font-bold text-slate-400 uppercase tracking-widest mb-1" id="label-2">Returns</p>
<p class="text-xl md:text-2xl font-bold break-all leading-tight" style="color: var(--primary)" id="res-returns">₹0</p>
</div>
<!-- Main Total -->
<div id="total-container" class="p-6 rounded-2xl shadow-xl transition-all duration-500 text-white" style="background: var(--primary)">
<p class="text-[10px] font-bold opacity-80 uppercase tracking-widest mb-1">Total Value</p>
<p class="text-2xl md:text-3xl font-bold break-all leading-tight" id="res-total">₹0</p>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
let currentTab = 'sip';
let chart = null;
let themeColor = localStorage.getItem('themeColor') || '#6366f1';
const configs = {
sip: { title: "SIP Plan", labels: ["Total Invested", "Est. Returns"], inputs: [
{ id: 'amount', label: 'Monthly Investment', min: 500, max: 1000000, step: 500, val: 25000, suffix: '₹' },
{ id: 'rate', label: 'Expected Return Rate', min: 1, max: 50, step: 0.1, val: 12, suffix: '%' },
{ id: 'years', label: 'Time Period', min: 1, max: 80, step: 1, val: 10, suffix: 'Yr' }
]},
lumpsum: { title: "Lumpsum Plan", labels: ["Principal Amount", "Est. Returns"], inputs: [
{ id: 'amount', label: 'One-time Investment', min: 5000, max: 10000000, step: 5000, val: 1000000, suffix: '₹' },
{ id: 'rate', label: 'Expected Return Rate', min: 1, max: 50, step: 0.1, val: 12, suffix: '%' },
{ id: 'years', label: 'Time Period', min: 1, max: 80, step: 1, val: 10, suffix: 'Yr' }
]},
swp: { title: "Withdrawal Plan", labels: ["Total Withdrawal", "Final Balance"], inputs: [
{ id: 'amount', label: 'Total Investment', min: 100000, max: 50000000, step: 10000, val: 1000000, suffix: '₹' },
{ id: 'withdrawal', label: 'Monthly Withdrawal', min: 1000, max: 500000, step: 500, val: 10000, suffix: '₹' },
{ id: 'rate', label: 'Expected Returns', min: 1, max: 50, step: 0.1, val: 15, suffix: '%' },
{ id: 'years', label: 'Tenure', min: 1, max: 80, step: 1, val: 5, suffix: 'Yr' }
]}
};
function updateTheme(color) {
themeColor = color;
document.documentElement.style.setProperty('--primary', color);
document.getElementById('current-color-btn').style.background = color;
localStorage.setItem('themeColor', color);
document.getElementById('theme-pill').classList.remove('expanded');
if(chart) updateChart(null, null, true);
}
function toggleDark() {
const isDark = document.documentElement.classList.toggle('dark');
localStorage.setItem('theme', isDark ? 'dark' : 'light');
updateThemeIcons(isDark);
if(chart) updateChart(null, null, true);
}
function updateThemeIcons(isDark) {
document.getElementById('sun-icon').classList.toggle('hidden', !isDark);
document.getElementById('moon-icon').classList.toggle('hidden', isDark);
}
function switchTab(tab) {
currentTab = tab;
document.querySelectorAll('button[id^="tab-"]').forEach(b => b.classList.remove('tab-active'));
document.getElementById(`tab-${tab}`).classList.add('tab-active');
document.getElementById('total-container').style.display = (tab === 'swp') ? 'none' : 'block';
renderInputs();
calculate();
}
function renderInputs() {
const container = document.getElementById('inputs-container');
const config = configs[currentTab];
document.getElementById('calc-title').innerText = config.title;
document.getElementById('label-1').innerText = config.labels[0];
document.getElementById('label-2').innerText = config.labels[1];
container.innerHTML = config.inputs.map(input => `
<div class="space-y-4">
<div class="flex justify-between items-center">
<label class="text-[10px] font-bold text-slate-400 uppercase tracking-widest">${input.label}</label>
<div class="bg-slate-100 dark:bg-slate-800 px-3 py-1.5 rounded-xl flex items-center border border-slate-200 dark:border-slate-700 min-w-[120px] justify-end">
<input type="number" id="num-${input.id}" value="${input.val}"
class="w-full text-right font-bold bg-transparent outline-none text-lg" style="color: var(--primary)"
oninput="sync('${input.id}', false)">
<span class="ml-2 text-[10px] font-bold text-slate-400 uppercase">${input.suffix}</span>
</div>
</div>
<input type="range" id="range-${input.id}" min="${input.min}" max="${input.max}" step="${input.step}" value="${input.val}"
class="slider" oninput="sync('${input.id}', true)">
</div>
`).join('');
}
function sync(id, isSlider) {
const val = document.getElementById(isSlider ? `range-${id}` : `num-${id}`).value;
document.getElementById(isSlider ? `num-${id}` : `range-${id}`).value = val;
calculate();
}
function calculate() {
const P = parseFloat(document.getElementById('num-amount').value) || 0;
const r = (parseFloat(document.getElementById('num-rate').value) || 0) / 100;
const n = parseFloat(document.getElementById('num-years').value) || 0;
let v1 = 0, v2 = 0, total = 0;
if (currentTab === 'sip') {
const i = r / 12;
total = P * ((Math.pow(1 + i, n * 12) - 1) / i) * (1 + i);
v1 = P * n * 12;
v2 = total - v1;
} else if (currentTab === 'lumpsum') {
total = P * Math.pow(1 + r, n);
v1 = P;
v2 = total - v1;
} else if (currentTab === 'swp') {
const W = parseFloat(document.getElementById('num-withdrawal').value) || 0;
const i = r / 12;
v2 = P * Math.pow(1 + i, n * 12) - (W * (Math.pow(1 + i, n * 12) - 1) / i);
v1 = W * n * 12;
total = Math.max(0, v2);
v2 = total;
}
updateUI(v1, v2, total);
}
function updateUI(v1, v2, total) {
const fmt = (n) => "₹" + Math.round(n).toLocaleString('en-IN');
document.getElementById('res-invested').innerText = fmt(v1);
document.getElementById('res-returns').innerText = fmt(v2);
document.getElementById('res-total').innerText = fmt(total);
// Dynamic Font Scaling for very long numbers
['res-invested', 'res-returns', 'res-total'].forEach(id => {
const el = document.getElementById(id);
const len = el.innerText.length;
if (len > 15) el.className = "text-lg font-bold break-all leading-tight";
else if (len > 12) el.className = "text-xl font-bold break-all leading-tight";
else el.className = (id === 'res-total') ? "text-2xl md:text-3xl font-bold break-all leading-tight" : "text-xl md:text-2xl font-bold break-all leading-tight";
});
updateChart(v1, v2);
}
let lV1 = 0, lV2 = 0;
function updateChart(v1, v2, force = false) {
if (v1 !== null) lV1 = v1; if (v2 !== null) lV2 = v2;
const isDark = document.documentElement.classList.contains('dark');
const data = {
labels: configs[currentTab].labels,
datasets: [{
data: [lV1, lV2],
backgroundColor: [isDark ? '#1e293b' : '#f1f5f9', themeColor],
borderWidth: 0,
hoverOffset: 0
}]
};
if (chart) { chart.data = data; chart.update(force ? 'default' : 'none'); }
else { chart = new Chart(document.getElementById('resultChart'), { type: 'doughnut', data: data, options: { cutout: '80%', plugins: { legend: { display: false } } } }); }
}
// Init
const presets = ['#6366f1', '#0ea5e9', '#10b981', '#f59e0b', '#ef4444', '#ec4899'];
document.getElementById('theme-options').innerHTML = presets.map(c => `<div class="theme-circle" style="background:${c}" onclick="updateTheme('${c}')"></div>`).join('');
if (localStorage.getItem('theme') === 'dark') {
document.documentElement.classList.add('dark');
updateThemeIcons(true);
}
updateTheme(themeColor);
switchTab('sip');
// Auto-close theme picker when clicking outside
window.addEventListener('click', (e) => {
if (!document.getElementById('theme-pill').contains(e.target)) {
document.getElementById('theme-pill').classList.remove('expanded');
}
});
</script>
</body>
</html>