Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Graphs: changed expenses from line to column chart.

  • Loading branch information...
willtennien committed Jun 3, 2013
1 parent 0f92a1c commit c259a79446847ff14e8fa50dc6f0191758843cf0
@@ -63,15 +63,6 @@ optionsScrollChart =
textPosition: 'none'
###

foo = (->
i = 0

return (n) ->
i += 1
console.debug(i + ' >>> ' + n)
console.debug($('#main-chart')[0])
)()

this.createScrolledChart = (data, variable) ->
debugger
cols = data.cols
@@ -103,6 +94,8 @@ this.createScrolledChart = (data, variable) ->
redrawMainChart = (startDate, finishDate) ->
start = Math.max(0, indexOfDateAfter(startDate) - 1)
finish = indexOfDateAfter(finishDate) + 1
console.debug(cols);
console.debug(rows);
dataTable = new google.visualization.DataTable({cols: cols, rows: rows.slice(start, finish)})
elem.mainChart.draw(dataTable, variable.optionsMainChart)

@@ -176,12 +169,6 @@ this.createScrolledChart = (data, variable) ->
newX = Math.max(newX, 0)
elem.film.css('width', elem.film.width() - (newX - parseFloat(elem.film.css('left'), 10)))
elem.film.css('left', newX)
console.debug(elem.film.width())
console.debug(newX)
console.debug(parseFloat(elem.film.css('left'), 10))
console.debug(newX - parseFloat(elem.film.css('left'), 10))
console.debug(elem.film.width() - newX + parseFloat(elem.film.css('left'), 10))
console.debug(elem.film.width() - (newX - parseFloat(elem.film.css('left'), 10)))
elem.filmLabelLeft.html(scrollLabelDate(dateOnScroll(newX)))
else if filmHandleRightDraggable and minHandleDistance + elem.film.position().left + elem.filmHandleLeft.width() + elem.filmHandleRight.width() < newX
newX = Math.min(newX, elem.film.offsetParent().width())
@@ -5,6 +5,8 @@

prettyTime = (t) -> "#{t.toLocaleTimeString()} #{t.getMonth()+1}/#{t.getDate()}"

monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]
dateToMonth = (t) -> "#{monthNames[t.getMonth()]} #{t.getFullYear()}"

options =
chartType: 'ColumnChart'
@@ -38,17 +40,17 @@ options =
textPosition: 'none'


cols = [{id: 'date', type: 'date'}, {id: 'balance', type: 'number'}]
cols = [{id: 'date', type: 'string'}, {id: 'balance', type: 'number'}]

this.primeCharts = (data) ->
rows = data.map((e) ->
date = new Date(e.date)
{c:
[
{v: date, f: prettyTime(date)},
{v: dateToMonth(date)},
{
v: Number(e.total),
f: "#{e.description}\nCost: $#{e.expense.toFixed(2)}\nTotal: $#{e.total.toFixed(2)}"
v: Number(e.expense),
f: "Total: $#{e.expense.toFixed(2)}"
}
]
}
@@ -62,7 +62,7 @@ def balances_over_time_with_friends

def expenses_over_time
@title = "Expenses"
@data = JSON.unparse(current_user.get_expenses_over_time_cumulative)
@data = JSON.unparse(current_user.get_expenses_over_time_by_month)
end

def expenses_by_category
@@ -1,3 +1,5 @@
require 'time'

class Array
def sortBy! &iterator
self.sort! do |a, b|
@@ -205,6 +207,31 @@ def get_expenses_over_time
expenses
end

def bucket_of date
if date.is_a? String
date = Time.parse(date)
end
Time.gm(date.year, date.month)
end

def same_bucket d1, d2
(bucket_of d1) == (bucket_of d2)
end

def get_expenses_over_time_by_month
x = 0
get_expenses_over_time.inject [] do |rest, expense|
if rest[-1] and same_bucket rest[-1]['date'], expense['date']
rest[-1]['expense'] += expense['expense']
rest[-1]['description'] = expense['description']
rest
else
expense['date'] = bucket_of expense['date']
rest.push expense
end
end
end

def get_expenses_over_time_cumulative
total = 0
expenses = get_expenses_over_time

0 comments on commit c259a79

Please sign in to comment.
You can’t perform that action at this time.