|
@@ -91,6 +91,7 @@ function showSelectedMonths(start, end, incoming, outgoing) {
|
91
|
91
|
|
92
|
92
|
$(function() {
|
93
|
93
|
var transData = [{label: 'Income', data: []}, {label: 'Expense', data: []}, {label: 'Difference', data: []}];
|
|
94
|
+ var categories = {};
|
94
|
95
|
var min = new Date().getTime(), max = 0;
|
95
|
96
|
|
96
|
97
|
$.each(data, function(month, entries) {
|
|
@@ -101,6 +102,13 @@ $(function() {
|
101
|
102
|
$.each(entries, function() {
|
102
|
103
|
if (this.Category == '(Ignored)') { return; }
|
103
|
104
|
|
|
105
|
+ if (this.Amount < 0) {
|
|
106
|
+ var category = this.Category ? this.Category : 'Unsorted';
|
|
107
|
+ if (!categories[category]) { categories[category] = {}; }
|
|
108
|
+ if (!categories[category][timestamp]) { categories[category][timestamp] = 0; }
|
|
109
|
+ categories[category][timestamp] -= this.Amount;
|
|
110
|
+ }
|
|
111
|
+
|
104
|
112
|
sum[this.Amount < 0 ? 1 : 0] += this.Amount;
|
105
|
113
|
});
|
106
|
114
|
|
|
@@ -111,8 +119,27 @@ $(function() {
|
111
|
119
|
max = Math.max(max, timestamp);
|
112
|
120
|
});
|
113
|
121
|
|
|
122
|
+ var catData = [];
|
|
123
|
+ $.each(categories, function(category, entries) {
|
|
124
|
+ var series = {label: category, data: []};
|
|
125
|
+ var total = 0;
|
|
126
|
+
|
|
127
|
+ $.each(transData[0].data, function() {
|
|
128
|
+ var timestamp = this[0];
|
|
129
|
+ var val = entries[timestamp] ? entries[timestamp] : 0;
|
|
130
|
+ total += val;
|
|
131
|
+ series.data.push([timestamp, val]);
|
|
132
|
+ });
|
|
133
|
+
|
|
134
|
+ series.total = total;
|
|
135
|
+
|
|
136
|
+ catData.push(series);
|
|
137
|
+ });
|
|
138
|
+
|
|
139
|
+ catData.sort(function(a, b) { return a.total - b.total; });
|
|
140
|
+
|
114
|
141
|
plots.history = $.plot($('#history'), transData, {
|
115
|
|
- xaxis: { mode: 'time', timeformat: '%y/%m'},
|
|
142
|
+ xaxis: { mode: 'time', timeformat: '%y/%m' },
|
116
|
143
|
series: {
|
117
|
144
|
lines: { show: true, fill: true },
|
118
|
145
|
points: { show: true }
|
|
@@ -125,6 +152,15 @@ $(function() {
|
125
|
152
|
selection: { mode : "x" }
|
126
|
153
|
});
|
127
|
154
|
|
|
155
|
+ plots.cathistory = $.plot($('#cathistory'), catData, {
|
|
156
|
+ xaxis: { mode: 'time', timeformat: '%y/%m' },
|
|
157
|
+ legend: { noColumns: 2 },
|
|
158
|
+ series: {
|
|
159
|
+ stack: true,
|
|
160
|
+ lines: { show: true, fill: true }
|
|
161
|
+ },
|
|
162
|
+ });
|
|
163
|
+
|
128
|
164
|
$("#history").bind("plothover", function (event, pos, item) {
|
129
|
165
|
if (item) {
|
130
|
166
|
var id = {dataIndex: item.dataIndex, seriesIndex: item.seriesIndex};
|