Преглед изворни кода

Show percentages on pie chart

Make graphs take up more room
Fix collapsed settings not having currency format
Closes #3
master
Chris Smith пре 13 година
родитељ
комит
3859f6d0aa
2 измењених фајлова са 10 додато и 6 уклоњено
  1. 7
    3
      analyser.js
  2. 3
    3
      index.html

+ 7
- 3
analyser.js Прегледај датотеку

@@ -292,9 +292,13 @@ function shouldMerge(a, b) {
292 292
  */
293 293
 function drawCategoryPieChart(included, incoming) {
294 294
  var pieData = getCategoryTotals(included, incoming);
295
+ var total = 0;
296
+
297
+ $.each(pieData, function(_, amount) { total += amount; });
298
+
295 299
  var seriesData = [];
296 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 304
  seriesData.sort(function(a, b) { return b.data - a.data; });
@@ -361,7 +365,7 @@ function showSelectedMonths(start, end, incoming, outgoing, categoryFilter, expa
361 365
    lastEntry.Amount = Math.round(100 * (lastEntry.Amount + this.Amount)) / 100;
362 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 370
    tr.addClass('collapsed hidden' + lastEntry.id);
367 371
   } else {
@@ -508,7 +512,7 @@ $(function() {
508 512
  });
509 513
 
510 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 518
  $.history.init(handleStateChange);

+ 3
- 3
index.html Прегледај датотеку

@@ -38,14 +38,14 @@
38 38
 
39 39
   <div class="left">
40 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 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 43
   </div>
44 44
   <div class="right">
45 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 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 49
   </div>
50 50
  </body>
51 51
 </html>

Loading…
Откажи
Сачувај