Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: borgar/mortgage-calculator
base: b449560675
...
head fork: borgar/mortgage-calculator
compare: ab1771ea45
  • 5 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 25, 2012
@borgar Tolerate escaping in url hash parameters.
fixes #11
9ca4a82
@borgar Buttons should not be "submit" to prevent problems.
Fixes #10
e8d9820
@borgar Fixing incorrect summing of loans
This was causing NaNs to appear in the final data resulting in an early cutoff of the plot as NaNs are filtered out.

Fixes #12
e77af74
@borgar Fix indentation. df54142
@borgar Sum second collection loans
Somehow I missed actually passing the second collection through the sum function. It now does what it should do.

Fixes #9
ab1771e
Showing with 33 additions and 29 deletions.
  1. +3 −3 index.html
  2. +29 −25 js/app.js
  3. +1 −1  js/jquery.to_query.js
View
6 index.html
@@ -68,7 +68,7 @@
<abbr class="unit" title="prósent">%</abbr>
</td>
<td class="actions">
- <button data-action="delete-loan">✖</button>
+ <button type="button" data-action="delete-loan">✖</button>
</td>
</tr>
@@ -76,7 +76,7 @@
</table>
<div class="buttons">
- <button data-action="add-loan">Bæta við láni</button>
+ <button type="button" data-action="add-loan">Bæta við láni</button>
</div>
</fieldset>
@@ -101,7 +101,7 @@
</table>
<div class="buttons">
- <button data-action="add-loan">Bæta við láni</button>
+ <button type="button" data-action="add-loan">Bæta við láni</button>
</div>
</fieldset>
View
54 js/app.js
@@ -271,7 +271,9 @@ jQuery(function ($) {
}
function sum_loans ( collection ) {
-
+ function add ( a, b, key ) {
+ a[ key ] = (a[ key ] || 0) + (b[ key ] || 0);
+ }
// make a copy of the first active one
var period = 0;
var principal = 0;
@@ -287,19 +289,21 @@ jQuery(function ($) {
var payments = [];
for (var p=0; p<period; p++) {
- var payment = $.extend( {}, loans[0].payments[p] );
+ var pm = $.extend( {}, loans[0].payments[p] );
for (var li=1,ll=loans.length; li<ll; li++) {
var px = loans[li].payments[p];
if ( px ) {
- payment.amount_payed += px.amount_payed;
- payment.capital_payment += px.capital_payment;
- payment.interest += px.interest;
- payment.payment_upcalc += px.payment_upcalc;
- payment.period_captial_end += px.period_captial_end;
- payment.period_captial_start += px.period_captial_start;
+ add( pm, px, 'amount_payed' );
+ add( pm, px, 'capital_payment' );
+ add( pm, px, 'interest' );
+ add( pm, px, 'payment_upcalc' );
+ add( pm, px, 'period_captial_end' );
+ add( pm, px, 'period_captial_start' );
+ pm.index = p;
+ pm.currency_worth = pm.currency_worth || px.currency_worth;
}
}
- payments.push( payment );
+ payments.push( pm );
}
var r = {
active: !!payments.length,
@@ -327,22 +331,22 @@ jQuery(function ($) {
display_driver.init.call( loan );
}
if ( !loan.active ) { return []; }
- var series = loan.payments
- .map( display_driver.calculate, loan )
- .filter(function ( d ) {
- if ( isFinite(d.x) && isFinite(d.y) ) {
- if ( d.stack && d.stack.length > stacks ) {
- stacks = d.stack.length;
- }
- if ( y_min > d.y ) { y_min = d.y; }
- if ( y_max < d.y ) { y_max = d.y; }
- if ( x_min > d.x ) { x_min = d.x; }
- if ( x_max < d.x ) { x_max = d.x; }
- return true;
+ var series = loan.payments
+ .map( display_driver.calculate, loan )
+ .filter(function ( d ) {
+ if ( isFinite(d.x) && isFinite(d.y) ) {
+ if ( d.stack && d.stack.length > stacks ) {
+ stacks = d.stack.length;
}
- return false;
- })
- ;
+ if ( y_min > d.y ) { y_min = d.y; }
+ if ( y_max < d.y ) { y_max = d.y; }
+ if ( x_min > d.x ) { x_min = d.x; }
+ if ( x_max < d.x ) { x_max = d.x; }
+ return true;
+ }
+ return false;
+ })
+ ;
return series;
})
;
@@ -559,7 +563,7 @@ jQuery(function ($) {
;
// TODO: fork in the road - small multiples for collections, or one with both?
- current_data = [ sum_loans( collection1 ), collection2.loans[0] ];
+ current_data = [ sum_loans( collection1 ), sum_loans( collection2 ) ];
plot( current_data, current_driver );
// serialize to hash
View
2  js/jquery.to_query.js
@@ -82,7 +82,7 @@
.forEach(function ( s ) {
var m = /^([^=]+)=(.*)$/.exec( s );
if ( m ) {
- param[ m[1] ] = m[2];
+ param[ decodeURIComponent(m[1]) ] = decodeURIComponent(m[2]);
}
})
;

No commit comments for this range

Something went wrong with that request. Please try again.