-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
443 lines (368 loc) · 12.9 KB
/
index.html
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.4.2/pure-min.css">
<script type="application/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<style type="text/css">
#content {
width:700px;
margin:30px auto;
}
.thermometer {
float: left;
margin:0 150px;
width:70px;
height:400px;
position: relative;
background: #ddd;
border:1px solid #aaa;
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
-ms-border-radius: 12px;
-o-border-radius: 12px;
border-radius: 12px;
-webkit-box-shadow: 1px 1px 4px #999, 5px 0 20px #999;
-moz-box-shadow: 1px 1px 4px #999, 5px 0 20px #999;
-ms-box-shadow: 1px 1px 4px #999, 5px 0 20px #999;
-o-box-shadow: 1px 1px 4px #999, 5px 0 20px #999;
box-shadow: 1px 1px 4px #999, 5px 0 20px #999;
}
.thermometer .track {
height:380px;
top:10px;
width:20px;
border: 1px solid #aaa;
position: relative;
margin:0 auto;
background: rgb(255,255,255);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgb(0,0,0)), color-stop(1%,rgb(255,255,255)));
background: -webkit-linear-gradient(top, rgb(0,0,0) 0%,rgb(255,255,255) 10%);
background: -o-linear-gradient(top, rgb(0,0,0) 0%,rgb(255,255,255) 10%);
background: -ms-linear-gradient(top, rgb(0,0,0) 0%,rgb(255,255,255) 10%);
background: -moz-linear-gradient(top, rgb(0,0,0) 0%,rgb(255,255,255) 10%);
background: linear-gradient(to bottom, rgb(0,0,0) 0%,rgb(255,255,255) 10%);
background-position: 0 -1px;
background-size: 100% 5%;
}
.thermometer .progress {
height:0%;
width:100%;
background: rgb(20,100,20);
background: rgba(20,100,20,0.6);
position: absolute;
bottom:0;
left:0;
}
.thermometer .goal {
position:absolute;
top:0;
}
.thermometer .amount {
display: inline-block;
padding:0 5px 0 60px;
border-top:1px solid black;
font-family: Trebuchet MS;
font-weight: bold;
color:#333;
}
.thermometer .loan_amount {
position: absolute;
width: 175px;
border-top: 1px dotted red;
padding-left: 60px;
font-family: Trebuchet MS;
font-variant: small-caps;
font-size: 12px;
}
.thermometer .loan_amount .payoff {
color: gray;
}
.thermometer .progress .amount {
padding:0 60px 0 5px;
position: absolute;
border-top:1px solid #060;
color:#060;
right:0;
}
.thermometer.horizontal {
margin:100px auto;
}
.thermometer.horizontal {
width:350px;
height:70px;
}
.thermometer.horizontal .track {
width:90%;
left:0;
height:20px;
margin:14px auto;
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgb(0,0,0)), color-stop(1%,rgb(255,255,255)));
background: -webkit-linear-gradient(left, rgb(0,0,0) 0%,rgb(255,255,255) 10%);
background: -o-linear-gradient(left, rgb(0,0,0) 0%,rgb(255,255,255) 10%);
background: -ms-linear-gradient(left, rgb(0,0,0) 0%,rgb(255,255,255) 10%);
background: -moz-linear-gradient(left, rgb(0,0,0) 0%,rgb(255,255,255) 10%);
background: linear-gradient(to right, rgb(0,0,0) 0%,rgb(255,255,255) 10%);
background-size: 5% 100%;
}
.thermometer.horizontal .progress {
height:100%;
width:0%;
}
.thermometer.horizontal .goal {
left:100%;
height:100%;
}
.thermometer.horizontal .amount {
bottom:0;
position: absolute;
padding:0 5px 50px 5px;
border-top:0;
border-left:1px solid black;
}
.thermometer.horizontal .progress .amount {
border-left:0;
border-top:0;
border-right:1px solid #060;
}
#payoff_windows {
float: right;
width: 275px;
}
</style>
</head>
<body>
<div id="content">
<h1>Zicari Family Debt Freedom Thermometer</h1>
<div id="payoff_windows">
<table class="pure-table pure-table-striped">
<thead>
<tr>
<th>Monthly Payment Size</th>
<th>Time to Freedom!</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div id="thermo1" class="thermometer" style="visibility: hidden">
<div class="track">
<div class="goal">
<div class="amount" style="display: none"> 51484 </div>
</div>
<div class="progress">
<div class="amount"> 0 </div>
</div>
</div>
</div>
<p style="clear: both; padding-top: 20px">Thermometer borrowed from <a href="http://jsfiddle.net/GeekyJohn/UpnKF/" target="_blank">http://jsfiddle.net/GeekyJohn/UpnKF/</a></p>
</div>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.6.0/moment.min.js"></script>
<script type="text/javascript">
//<!--
//originally from http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript
function formatCurrency(n, c, d, t) {
"use strict";
var s, i, j;
c = isNaN(c = Math.abs(c)) ? 2 : c;
d = d === undefined ? "." : d;
t = t === undefined ? "," : t;
s = n < 0 ? "-" : "";
i = parseInt(n = Math.abs(+n || 0).toFixed(c), 10) + "";
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}
/**
* Thermometer Progress meter.
* This function will update the progress element in the "thermometer"
* to the updated percentage.
* If no parameters are passed in it will read them from the DOM
*
* @param {Number} goalAmount The Goal amount, this represents the 100% mark
* @param {Number} progressAmount The progress amount is the current amount
* @param {Boolean} animate Whether to animate the height or not
*
*/
function thermometer(id, goalAmount, progressAmount, animate) {
"use strict";
var $thermo = $("#"+id),
$progress = $(".progress", $thermo),
$goal = $(".goal", $thermo),
percentageAmount,
isHorizontal = $thermo.hasClass("horizontal"),
newCSS = {};
goalAmount = goalAmount || parseFloat( $goal.text() ),
progressAmount = progressAmount || parseFloat( $progress.text() ),
percentageAmount = Math.min( Math.round(progressAmount / goalAmount * 1000) / 10, 100); //make sure we have 1 decimal point
//let's format the numbers and put them back in the DOM
//$goal.find(".amount").text( "$" + formatCurrency( goalAmount ) );
$progress.find(".amount").text( Math.round((progressAmount / goalAmount)*100).toString() + '%' );
//let's set the progress indicator
$progress.find(".amount").hide();
newCSS[ isHorizontal ? "width" : "height" ] = percentageAmount + "%";
if (animate !== false) {
$progress.animate( newCSS, 1200, function(){
$(this).find(".amount").fadeIn(500);
});
}
else {
$progress.css( newCSS );
$progress.find(".amount").fadeIn(500);
}
}
function append_debt_markers (debt_markers, $thermometer, colors)
{
var className = '',
css_top_px = '',
index,
marker_data,
marker_html = '',
$marker = $('<div class="loan_amount"></div>'),
$new_marker = null,
payoff = '',
running_total = '',
$progress = $thermometer.find('div.progress'),
thermo_height = parseInt($thermometer.find('div.track').css('height'));
for (index in debt_markers)
{
marker_data = debt_markers[index];
className = $marker.attr('class')+' '+index;
css_top_px = Math.round(thermo_height-(thermo_height*marker_data['percent_of_total']));
payoff = formatCurrency(marker_data['payoff']);
marker_html = '<strong>'+Math.round(marker_data['percent_of_total']*100).toString()
+ '%</strong> '+marker_data['name'];
$new_marker = $marker.clone()
.attr('class', className)
.css({'top': css_top_px+'px',
'border-color': colors[index],
'color': colors[index]})
.html(marker_html);
$thermometer.find('div.track').append($new_marker);
}
}
/**
* Calculates the number of months it would take to pay off all of the debt
* based on standard repayment amounts ranging from $2,500 to $5,000 a month.
*/
function calculate_payoff_windows (total_debt, monthly_payments)
{
var monthly_payments = monthly_payments || [500, 1000, 1500, 2000, 2500, 3000, 3500, 4000],
payoff_windows = [],
payment_amount = 0;
for (index in monthly_payments)
{
payment_amount = monthly_payments[index];
payoff_windows[index] = Math.ceil(total_debt / payment_amount);
}
return {'payoff_windows': payoff_windows, 'monthly_payments': monthly_payments};
}
/**
* Displays payoff windows in the DOM that illustrate how many months it would
* take to pay off all of the debt given standard repayment amounts.
*/
function append_payment_windows_to_dom (payment_window_data)
{
var payment_window,
monthly_payment,
$tbody = $('#payoff_windows table tbody'),
cells = [],
$cell,
$row;
for (var index in payment_window_data['payoff_windows'])
{
payment_window = payment_window_data['payoff_windows'][index];
monthly_payment = payment_window_data['monthly_payments'][index];
$row = $('<tr></tr>');
cells[0] = $('<td>$'+ formatCurrency(monthly_payment) +'</td>');
cells[1] = $('<td>'+ moment().add('months', payment_window).format('MMM YYYY') +'</td>');
for (var cell_index in cells)
{
$cell = cells[cell_index];
$row.append($cell);
}
$tbody.append($row);
$row = null;
cells = [];
}
};
function add_up_debt (debt)
{
var sum = 0;
for (loan in debt)
{
sum += debt[loan];
}
return sum;
};
function calculate_debt_markers (debt, total_debt, weights)
{
var debt_markers = [],
payoff = null,
running_total = 0;
for (loan_name in debt)
{
payoff = debt[loan_name];
percent_of_total = Math.round(running_total / total_debt * 100) / 100;
debt_markers.push({'name': loan_name,
'payoff': payoff,
'weight': weights[loan_name],
'percent_of_total': percent_of_total});
}
debt_markers.sort(function (a, b) {
if (a['weight'] < b['weight']) {
return -1;
}
if (a['weight'] > b['weight']) {
return 1;
}
else {
if (a['payoff'] < b['payoff']) {
return -1;
}
if (a['payoff'] > b['payoff']) {
return 1;
}
return 0;
}
});
debt_markers.forEach(function (debt, index) {
running_total += debt['payoff'];
percent_of_total = Math.round(running_total / total_debt * 100) / 100;
debt_markers[index]['running_total'] = running_total;
debt_markers[index]['percent_of_total'] = percent_of_total;
});
return debt_markers;
};
function weightedDebt (debt) {
var weights = {},
original = debt['original'],
remaining = debt['current'];
for (debt in original) {
weights[debt] = remaining[debt] - original[debt];
}
return weights;
};
$(document).ready(function () {
var colors = ['blue', 'brown', 'goldenrod', 'cadetblue', 'forestgreen',
'crimson', 'darkblue', 'deeppink', 'darkgreen', 'darkmagenta',
'darkorange', 'darkorchid', 'darkslateblue', 'darkslategray'],
debt = {},
debt_markers = [],
$thermometer = $('#thermo1');
$.getJSON('/debt.json', function (data) {
debt = data;
var total_debt = add_up_debt(debt['original']),
remaining_debt = add_up_debt(debt['current']),
paid_off = total_debt - remaining_debt;
debt_markers = calculate_debt_markers(debt['original'], total_debt, weightedDebt(debt));
//call without the parameters to have it read from the DOM
thermometer("thermo1", total_debt, paid_off);
append_debt_markers(debt_markers, $thermometer, colors);
$thermometer.css('visibility', 'visible');
append_payment_windows_to_dom(calculate_payoff_windows(remaining_debt));
});
});
//-->
</script>
</body>
</html>