-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccountBalances.html
562 lines (389 loc) · 18.2 KB
/
AccountBalances.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<html>
<head><title>Account Balances</title></head>
<body>
<!-- IMPORTANT: When this is on github it can't find /contributionspaid/ location, must be relative -->
<!-- external libs from cdnjs -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script type ="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/1.33.1/plotly-basic.min.js"></script>
<!-- script type="text/javascript" src="https://cdn.plot.ly/plotly-basic-latest.min.js"></script -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/4.1.2/papaparse.min.js"></script>
<!-- script type="text/javascript" src="/contributionspaid/scripts/jquery.floatTHead.min.js"></script -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/floatthead/2.2.1/jquery.floatThead.min.js"></script>
<!-- PivotTable.js libs from ../dist -->
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.23.0/pivot.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.23.0/pivot.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.23.0/d3_renderers.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.23.0/plotly_renderers.min.js"></script>
<script type="text/javascript" src='https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.23.0/export_renderers.min.js'></script>
<!-- subtotal.js libs from ../dist -->
<!-- base href= "/flowerbot/contributionspaid/blob/main/" -->
<!-- base href= "/" -->
<script type="text/javascript" src="scripts/PivotJS-subtotal/subtotal.js"></script>
<link rel="stylesheet" type="text/css" href="scripts/PivotJS-subtotal/subtotal.css">
<style>
body {font-family: Verdana;}
#progressHeading {
color: grey;
font-size: smaller;
}
th.pvtRowLabel {
white-space: nowrap;
}
.ms-webpartPage-root {
border-spacing: 0px;
}
.desc {
padding-bottom: 10px;
width: 80vw;
}
.rotate {
height: 90px;/* fixed height . set fixed width to rotated elements */
width: 110px !important;/* a liitle less than parents height */
-webkit-transform: rotate(310deg);
-moz-transform: rotate(310deg);
-ms-transform: rotate(310deg);
-o-transform: rotate(310deg);
transform: rotate(310deg) translatex(-64%) translatey(56%);
transform-origin: top left;
margin-right: -73px;
}
/* extras for floating headers */
.floatThead-container {
overflow: hidden;
}
.pvtFilterBox {
z-index: 2001;
}
/* ************************* */
.pvtVal, .pvtTotal, .pvtRowLabel, .pvtGrandTotal {
font-size: 12pt !important;
font-weight: 500 !important;
}
.pvtTotal {
/* background-color: WhiteSmoke !important; */
font-weight: 500 !important;
}
</style>
<script type="text/javascript">
///prac/infrastructure/charts/Expected Contributions.csv
function fetchHeader(url, wch) {
try {
var req=new XMLHttpRequest();
req.open("HEAD", url, false);
req.send(null);
if(req.status== 200){
return req.getResponseHeader(wch);
}
else return false;
} catch(er) {
return er.message;
}
}
function fixHeader() {
var $table = $('table.pvtTable');
/*
// to use this flavor, you have to set .pvtRendererArea to a fixed height I think
$table.floatThead({
scrollContainer: function($table){
return $table.closest('.pvtRendererArea');
},
position: 'fixed',
autoReflow: true
});
*/
$table.floatThead({
position: 'fixed',
//autoReflow: true
});
}
var fromXlOne = false;
var storageTag = "-actBals";
let configShowUI = localStorage.getItem('showUi'+storageTag) === null ? false : JSON.parse(localStorage.getItem('showUi'+storageTag));
/*
function ExcelDateToJSDate(serial) {
var utc_days = Math.floor(serial - 25569);
var utc_value = utc_days * 86400;
var date_info = new Date(utc_value * 1000);
var fractional_day = serial - Math.floor(serial) + 0.0000001;
var total_seconds = Math.floor(86400 * fractional_day);
var seconds = total_seconds % 60;
total_seconds -= seconds;
var hours = Math.floor(total_seconds / (60 * 60));
var minutes = Math.floor(total_seconds / 60) % 60;
return new Date(date_info.getFullYear(), date_info.getMonth(), date_info.getDate(), hours, minutes, seconds);
}
*/
var curPath = window.location.href;
var fileNameAndPath = "data/DC Balances by Plan Activity SectorClean.csv";
var gitHubPath = "https://api.github.com/repos/flowerbot/contributionspaid/commits?path=data/DC Balances by Plan Activity SectorClean.csv&page=1&per_page=1"
const options = {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
};
var client = new XMLHttpRequest();
if(curPath.indexOf("github")>=0) {
client.open("HEAD", gitHubPath, true);
} else {
client.open("HEAD", fileNameAndPath);
}
client.onreadystatechange = function() {
if(this.readyState == 2) {
// console.log(client.getAllResponseHeaders());
//console.log(client.getResponseHeader("Last-Modified"));
var newDate = new Date(client.getResponseHeader("Last-Modified")).toLocaleDateString("en-AU", options);
var newTime = new Date(client.getResponseHeader("Last-Modified")).toLocaleTimeString("en-AU");
var dtString = newDate + " " + newTime;
console.log("NEW daTE:", newDate, "; NEW TIME:", newTime);
document.getElementById("fileDate").innerHTML = dtString;
}
}
client.send();
/*
function getFileDate(path) {
$.ajaxSetup({cache: false});
$.ajax({
type: "GET",
async: true,
timeout: 5000,
url : path,
dataType : "text",
success: function(data, textStatus, request){
var lastModified = new Date(request.getResponseHeader("Last-Modified"));
document.getElementById("fileDate").innerHTML = lastModified.toString();
},
error: function(ex) {
console.log(ex);
}
});
}*/
function toggleButtonText(val) {
if(val) {
document.getElementById('toggleHideUIButton').value= "Hide Chart Settings";
} else {
document.getElementById('toggleHideUIButton').value= "Show Chart Settings";
}
}
function toggleConfigHide(obj, toggle) {
console.log('toggling new ', toggle);
var tConfig = $("#output").data("pivotUIOptions");
console.log('showUi'+storageTag+":", localStorage.getItem('showUi'+storageTag))
var newVis = !JSON.parse(tConfig["showUI"]);
delete tConfig["showUI"];
tConfig["showUI"] = newVis;
toggleButtonText(newVis);
localStorage.setItem('pivotdatakey'+storageTag, JSON.stringify(tConfig)); // Add callback function for onRefresh
$("#output").pivotUI(fixedData, tConfig, true);
}
function revert() {
localStorage.clear();
location.reload();
}
function selectChange(obj){
var tConfig = $("#output").data("pivotUIOptions");
if($("#chartType").val() == "summary") {
delete tConfig["rows"];
delete tConfig["cols"];
delete tConfig["rendererName"];
tConfig["rows"] = ['Activity Description'];
tConfig["cols"] = [];
tConfig["rendererName"] = "Row Heatmap";
} else
if($("#chartType").val() == "planView") {
delete tConfig["rows"];
delete tConfig["cols"];
delete tConfig["rendererName"];
tConfig["rows"] = ['Activity Description', 'Plan Description'];
tConfig["cols"] = [];
tConfig["rendererName"] = "Table With Subtotal Row Heatmap";
} else
if($("#chartType").val() == "Chart") {
delete tConfig["rows"];
delete tConfig["cols"];
delete tConfig["rendererName"];
tConfig["rows"] = ['Activity Description'];
tConfig["cols"] = ['Plan Description'];
tConfig["rendererName"] = "Horizontal Stacked Bar Chart";
}
else
if($("#chartType").val() == "TSV") {
delete tConfig["rendererName"];
tConfig["rendererName"] = "TSV Export";
}
console.log("tConfig");
console.log(tConfig);
localStorage.setItem('pivotdatakey'+storageTag, JSON.stringify(tConfig)); // Add callback function for onRefresh
$("#output").pivotUI(fixedData, tConfig, true);
// localStorage.setItem('pivotdatakey'+storageTag, JSON.stringify(config, undefined, 2));
// location.reload();
}
$(function(){
// CATCH THE SCROLL EVENT
// would normally be 'document' but this is especially for SharePoint:
/* var docBody = document.getElementById('s4-workspace');
docBody.addEventListener('scroll', function(e) {
// document.getElementById('showScroll').innerHTML = window.pageYOffset + 'px';
var $table = $('table.pvtTable');
$table.trigger('reflow');
}); */
if(configShowUI == true) {
document.getElementById('toggleHideUIButton').value= "Hide Chart Settings";
} else {
document.getElementById('toggleHideUIButton').value = "Show Chart Settings";
}
// for subototals
var dataClass = $.pivotUtilities.SubtotalPivotData;
//var renderer = $.pivotUtilities.subtotal_renderers["Table With Subtotal"];
//var renderer = $.pivotUtilities.subtotal_renderers["Table With Subtotal Row Heatmap"];
var renderers = $.extend($.pivotUtilities.renderers,
$.pivotUtilities.c3_renderers,
$.pivotUtilities.plotly_renderers,
$.pivotUtilities.subtotal_renderers,
$.pivotUtilities.export_renderers);
var rendererOptions = {
//rendererOptions: {
table : {
/* clickCallback: function(e, value, filters, pivotData) {
var links = [];
pivotData.forEachMatchingRecord(filters,
function(record) { links.push(record.ProjectLink); });
if (window.confirm("Visit the project site at: "+ links[0] + " ?"))
{
var win = window.open(links[0], '_blank');
win.focus();
}
} */
},
//config["heatmap"] = {
heatmap: {
colorScaleGenerator: function(values) {
return d3.scale.linear()
// .domain(["1", "100000", "4000000", "9000000"])
// .domain([600000, 6000000])
.domain([-6000000, 0, 600000])
// .range(["#FFF", "#FF3D5A"])
// .range(["#FFF", "#9AFF3D", "#F7FF3D", "#FF3D5A"])
.range(["#9AFF3D", "#FFFFFF", "#FF0000"])
//}
}
},//;//,
};
var sum = $.pivotUtilities.aggregatorTemplates.sum;
var numberFormat = $.pivotUtilities.numberFormat;
// var intFormat = numberFormat({digitsAfterDecimal: 0});
//var intFormat = numberFormat();
var intFormat = numberFormat({digitsAfterDecimal: 0});
Papa.parse(fileNameAndPath, {
download: true,
skipEmptyLines: true,
header: true, // only if its on the first line
complete: function(parsed){
const options = {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
// hour: 'numeric',
// minute: 'numeric',
timeZoneName: 'short'
};
fixedData = parsed.data;
// var fileDate = "";
// var localDate = "";
// fileDate= ExcelDateToJSDate(parseFloat(fixedData[0].DataDate));
// getFileDate(fileNameAndPath);
document.getElementById("progressTotal").innerHTML = fixedData.length;
document.getElementById("progress").innerHTML = fixedData.length;
/*
//removed because now getting date from data set
if(curPath.indexOf("github")>=0) {
fileDate = "<a href='https://github.com/flowerbot/contributionspaid/blob/main/data/DC%20Balances%20by%20Plan%20Activity%20SectorClean.csv' target='_blank'>See GitHub commit date</a>";
localDate = fileDate;
} else {
fileDate = fetchHeader(fileNameAndPath, "Last-Modified");
localDate = new Date(fileDate).toLocaleDateString('en-au', options);
} */
// var dateTest = fetchHeader("/prac/infrastructure/charts/Expected Contributions Summary1.csv", "Last-Modified");
//var localDate = new Date(fileDate).toLocaleDateString('en-au', options);
// document.getElementById("fileDate").innerHTML = localDate;
savedConfig = JSON.parse(localStorage.getItem('pivotdatakey'+storageTag));
// savedRows = (savedConfig && savedRows) ? savedConfig.Rows;
console.log("savedConfig:");
if(savedConfig) console.log(savedConfig);
if(savedConfig) {
toggleButtonText(savedConfig.showUI);
}
$("#output").pivotUI(fixedData, {
//$("#output").pivotUI(parsed.data, {
// renderers: $.pivotUtilities.d3_renderers,
dataClass: dataClass,
// rows: ["Activity Description"], cols: ["Plan-Plan Description"],
rows: (savedConfig) ? savedConfig.rows : ["Activity Description"],
cols: (savedConfig) ? savedConfig.cols : [],
// rows: ["Plan","Charge Control"], cols: ["ExpectedYear"],
vals: ["Balance"],
renderers: renderers,
// renderer: renderer,
rendererOptions: rendererOptions,
exclusions: { Plan:["91","92","95",""]},
showUI: (savedConfig) ? savedConfig.showUI : false, //configShowUI,
inclusions: (savedConfig) ? savedConfig.inclusions : {},
rendererName: (savedConfig) ? savedConfig.rendererName : "Row Heatmap",
hiddenAttributes: ["FileDate","FileDateNum","DataDate", ""],
// aggregator:sum(intFormat)(["Sum of Expected*"])
aggregators:{
"Balance": function() {
//consol
// var balNum = parseFloat(["Balance"]);
return sum(intFormat)(["Balance"]);
},
// "Balance": function() {return sum(["Balance"])},
// "Expected": function() { return sum(intFormat)(["Expected"])},
},
onRefresh:
function(config) {
//console.log(JSON.parse(JSON.stringify(config)));
//var config_copy = JSON.parse(JSON.stringify(config));
//delete config_copy["aggregators"];
// delete config_copy["renderers"];
//delete some bulky default values
//delete config_copy["rendererOptions"];
//delete config_copy["localeStrings"];
// localStorage.setItem('pivotdatakey'+storageTag, JSON.stringify(config, undefined, 2)); // Add callback function for onRefresh
localStorage.setItem('pivotdatakey'+storageTag, JSON.stringify(config)); // Add callback function for onRefresh
//console.log(config.cols[0]);
$(".pvtColLabel").wrapInner("<div class='rotate'></div>");
fixHeader();
}
});
$(".pvtColLabel").wrapInner("<div class='rotate'></div>");
fixHeader();
}
});
// var jsonData = Papa.parse("/prac/infrastructure/siteassets/scripts/data/AccountBalance.csv");
// console.log(jsonData.data);
});
</script>
<div>
<p>How to use: Select a preset from the menu, or click 'Show Chart Settings' and drag data elements to the required axis/use the drop down arrow beside each data element to filter the chart results. </p>
<p id="progressHeading">Read <span id="progress">x</span> of <span id="progressTotal">xx</span> data rows. <span id="inclusions"></span><br />
Data Date: <span id='fileDate'></span>.</p>
</div>
<div>
<input type="button" value="Revert" onClick="revert()" title="click to clear saved settings and revert to defaults"/>
<input type="button" value="Show Chart Settings" id="toggleHideUIButton" onclick="toggleConfigHide(this)" title="Click to toggle hide/show chart settings" />
<select id="chartType" onchange="selectChange(this)">
<option value=""></option>
<option value="summary">Summary View</option>
<option value="planView">View By Plan</option>
<option value="Chart">Bar Chart</option>
<option value="TSV">Export Selected Data</option>
</select>
</div>
<div id="output"></div>
</body>
</html>