Browse Source

Show percentages on pie chart

Make graphs take up more room
Fix collapsed settings not having currency format
Closes #3
master
Chris Smith 13 years ago
parent
commit
3859f6d0aa
2 changed files with 10 additions and 6 deletions
  1. 7
    3
      analyser.js
  2. 3
    3
      index.html

+ 7
- 3
analyser.js View File

292
  */
292
  */
293
 function drawCategoryPieChart(included, incoming) {
293
 function drawCategoryPieChart(included, incoming) {
294
  var pieData = getCategoryTotals(included, incoming);
294
  var pieData = getCategoryTotals(included, incoming);
295
+ var total = 0;
296
+
297
+ $.each(pieData, function(_, amount) { total += amount; });
298
+
295
  var seriesData = [];
299
  var seriesData = [];
296
  $.each(pieData, function(category, amount) {
300
  $.each(pieData, function(category, amount) {
297
-  seriesData.push({ label: category + ' (' + Math.round(amount) + ')', data: amount });
301
+  seriesData.push({ label: category + ' (£' + amount.toCurrency() + ', ' + Math.floor(100 * amount / total) + '%)', data: amount });
298
  });
302
  });
299
 
303
 
300
  seriesData.sort(function(a, b) { return b.data - a.data; });
304
  seriesData.sort(function(a, b) { return b.data - a.data; });
361
    lastEntry.Amount = Math.round(100 * (lastEntry.Amount + this.Amount)) / 100;
365
    lastEntry.Amount = Math.round(100 * (lastEntry.Amount + this.Amount)) / 100;
362
    $('#collapseHandle' + lastEntry.id).data('total', lastEntry.Amount);
366
    $('#collapseHandle' + lastEntry.id).data('total', lastEntry.Amount);
363
 
367
 
364
-   !expanded[lastEntry.id] && tr.hide() && $('.amount', lastEntry.tr).text(lastEntry.Amount);
368
+   !expanded[lastEntry.id] && tr.hide() && $('.amount', lastEntry.tr).text(lastEntry.Amount.toCurrency());
365
 
369
 
366
    tr.addClass('collapsed hidden' + lastEntry.id);
370
    tr.addClass('collapsed hidden' + lastEntry.id);
367
   } else {
371
   } else {
508
  });
512
  });
509
 
513
 
510
  $('#expense').bind('plotclick', function(event, pos, item) {
514
  $('#expense').bind('plotclick', function(event, pos, item) {
511
-  setState({ categoryFilter: item.series.label.replace(/ \([0-9]+\)$/, '') }, ['expanded']);
515
+  setState({ categoryFilter: item.series.label.replace(/ \(.*$/, '') }, ['expanded']);
512
  });
516
  });
513
 
517
 
514
  $.history.init(handleStateChange);
518
  $.history.init(handleStateChange);

+ 3
- 3
index.html View File

38
 
38
 
39
   <div class="left">
39
   <div class="left">
40
    <h2>Transaction History</h2>
40
    <h2>Transaction History</h2>
41
-   <div id="history" style="width: 600px; height: 300px;" class="graph"></div>
41
+   <div id="history" style="width: 100%; height: 300px;" class="graph"></div>
42
    <div id="historytable" style="display: none;"><h3>Transactions for ??</h3><table><tr><th>Date</th><th>Type</th><th>Category</th><th>Description</th><th>Amount</th></tr></table></div>
42
    <div id="historytable" style="display: none;"><h3>Transactions for ??</h3><table><tr><th>Date</th><th>Type</th><th>Category</th><th>Description</th><th>Amount</th></tr></table></div>
43
   </div>
43
   </div>
44
   <div class="right">
44
   <div class="right">
45
    <h2>Categories</h2>
45
    <h2>Categories</h2>
46
-   <div id="expense" style="width: 600px; height: 300px;" class="graph"></div>
46
+   <div id="expense" style="width: 100%; height: 300px;" class="graph"></div>
47
    <h2>Expense Categories</h2>
47
    <h2>Expense Categories</h2>
48
-   <div id="cathistory" style="width: 600px; height: 600px;" class="graph"></div>
48
+   <div id="cathistory" style="width: 100%; height: 600px;" class="graph"></div>
49
   </div>
49
   </div>
50
  </body>
50
  </body>
51
 </html>
51
 </html>

Loading…
Cancel
Save