This repository was archived by the owner on Jul 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataview.ts
More file actions
1488 lines (1189 loc) · 53.3 KB
/
dataview.ts
File metadata and controls
1488 lines (1189 loc) · 53.3 KB
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/// <reference path="./classes/storage.ts"/>
/// <reference path="../networkcube/core/networkcube.d.ts"/>
/// <reference path="./classes/vistorian.ts" />
var DATA_TABLE_MAX_LENGTH = 200;
document.getElementById('files').addEventListener('change', getFileInfos, false);
var SESSION_NAME = utils.getUrlVars()['session'];
storage.saveSessionId(SESSION_NAME); // save id for later retrieve
var tables = storage.getUserTables(SESSION_NAME);
// user's currently selected network. All visualizations will visualize this network
var currentNetwork: vistorian.Network;
// visualizations among which the user can chose
// format: [shown name, codename]
var visualizations = [
['Node Link', 'nodelink'],
['Adjacency Matrix', 'matrix'],
['Dynamic Ego Network', 'dynamicego'],
['Map', 'map'],
]
var messages: string[] = [];
init()
function init() {
loadVisualizationList()
loadNetworkList()
loadTableList()
var networkids = storage.getNetworkIds(SESSION_NAME);
if(networkids.length > 0)
showNetwork(networkids[0])
}
// loads the list of available visualizations and displays them on the left
function loadVisualizationList() {
// create visualization links
visualizations.forEach(function(v) {
$('#visualizationList')
.append('<li class="visLink" title="Show '+v[0]+' visualization.">\
<button onclick="loadVisualization(\'' + v[1] + '\')" class="visbutton hastooltip">\
<img src="logos/vis-' + v[1] + '.png" class="menuicon" />'
+ v[0] + '\
</button>\
</li>')
})
$('#visualizationList')
.append('<li class="visLink" title="Show matrix and node-link split-view."><button onclick="loadVisualization(\'mat-nl\')" class="visbutton hastooltip"><img src="logos/mat-nl.png" class="menuicon"/>Matrix + Node Link\
</button></li>')
$('#visualizationList')
.append('<li class="visLink" title="Show all visualizations."><button onclick="loadVisualization(\'tileview\')" class="visbutton hastooltip"><img src="logos/tiled.png" class="menuicon"/>All\
</button></li>')
}
// loads the list of tables in this session and displays them on the left
function loadTableList()
{
$('#tableList').empty()
var tableNames = storage.getTableNames(SESSION_NAME)
console.log('tableNames', tableNames, SESSION_NAME)
tableNames.forEach(t => {
var shownName = t;
if(t.length > 30)
shownName = t.substring(0,30) + '..';
$('#tableList').append('<li>\
<a onclick="showSingleTable(\'' + t+ '\')" class="underlined">' + shownName + '.csv</a>\
<img class="controlIcon" title="Delete this table." src="logos/delete.png" onclick="removeTable(\''+ t +'\')"/>\
</li>')
})
}
// loads the list of networks for this session and displays them on the left
function loadNetworkList() {
$('#networkList').empty()
var networkNames = storage.getNetworkIds(SESSION_NAME)
var network: vistorian.Network;
networkNames.forEach(t => {
network = storage.getNetwork(t,SESSION_NAME);
$('#networkList').append('\
<li>\
<a onclick="showNetwork(\'' + network.id + '\')" class="underlined">' + network.name + '</a>\
<img class="controlIcon" title="Delete this network." src="logos/delete.png" onclick="removeNetwork(\''+ network.id +'\')"/>\
<img class="controlIcon" title="Download this network in .vistorian format." src="logos/download.png" onclick="exportNetwork(\''+ network.id +'\')"/>\
</li>')
})
}
// VISUALIZATIONS
// creates a new visualization of the passed type
function loadVisualization(visType) {
window.open('sites/' + visType + '.html?session=' + SESSION_NAME + '&datasetName=' + currentNetwork.name);
}
// CREATE NETWORK //
function createNetwork() {
var networkIds = storage.getNetworkIds(SESSION_NAME);
var id = new Date().getTime();
currentNetwork = new vistorian.Network(id);
currentNetwork.name = 'New Network ' + currentNetwork.id;
storage.saveNetwork(currentNetwork,SESSION_NAME);
$('#chooseNetworktype').css('display', 'block')
$('#networkTables').css('display', 'none')
}
function setNodeTable(list)
{
var tableName = list.value;
if (tableName != '---') {
var table: vistorian.VTable = storage.getUserTable(tableName,SESSION_NAME);
currentNetwork.userNodeTable = table;
console.log('currentNetwork.userNodeTable', currentNetwork.userNodeTable)
showTable(table, '#nodeTableDiv', false, currentNetwork.userNodeSchema)
} else {
unshowTable('#nodeTableDiv');
currentNetwork.userNodeTable = undefined;
}
}
function setLinkTable(list) {
var tableName = list.value;
if (tableName != '---') {
var table: vistorian.VTable = storage.getUserTable(tableName,SESSION_NAME);
currentNetwork.userLinkTable = table;
showTable(table, '#linkTableDiv', false, currentNetwork.userLinkSchema);
} else {
unshowTable('#linkTableDiv');
currentNetwork.userLinkTable = undefined;
}
}
function setLocationTable(list) {
var tableName = list.value;
if (tableName != '---') {
var table: vistorian.VTable = storage.getUserTable(tableName,SESSION_NAME);
currentNetwork.userLocationTable = table;
currentNetwork.userLocationSchema = new networkcube.LocationSchema(0, 1, 2, 3, 4);
showTable(table, '#locationTableDiv', true, currentNetwork.userLocationSchema);
} else {
unshowTable('#locationTableDiv');
currentNetwork.userLocationTable = undefined;
}
}
// saves/updates and normalizes current network.
function saveCurrentNetwork(failSilently: boolean) {
console.log('Save current network')
var networkcubeDataSet: networkcube.DataSet;
saveCellChanges();
// create new network data set, if necessary
if (currentNetwork.networkCubeDataSet == undefined) {
networkcubeDataSet = new networkcube.DataSet({
name: currentNetwork.name,
nodeTable: [],
linkTable: [],
locationTable: []
});
currentNetwork.networkCubeDataSet = networkcubeDataSet;
} else {
networkcubeDataSet = currentNetwork.networkCubeDataSet;
}
currentNetwork.name = $('#networknameInput').val();
currentNetwork.networkCubeDataSet.name = $('#networknameInput').val();
if (currentNetwork.userNodeSchema.time != -1) {
currentNetwork.timeFormat = $('#timeFormatInput_' + currentNetwork.userNodeSchema.name).val()
}
if (currentNetwork.userLinkSchema.time != -1) {
currentNetwork.timeFormat = $('#timeFormatInput_' + currentNetwork.userLinkSchema.name).val()
}
// check dates if apply
checkTimeFormatting(currentNetwork);
if (!currentNetwork.userNodeTable && !currentNetwork.userLinkTable)
{
if (!failSilently)
showMessage("Cannot save without a Node table or a Link Table", 2000);
return;
}
vistorian.importIntoNetworkcube(currentNetwork, SESSION_NAME, failSilently)
// // trim cell entries (remove overhead white space)
// if (currentNetwork.userNodeTable)
// vistorian.cleanTable(currentNetwork.userNodeTable.data);
// if (currentNetwork.userLinkTable)
// vistorian.cleanTable(currentNetwork.userLinkTable.data);
// // get references to normalized tables
// // var normalizedNodeTable: any[] = currentNetwork.networkCubeDataSet.nodeTable;
// // var normalizedLinkTable: any[] = currentNetwork.networkCubeDataSet.linkTable;
// // var normalizedLocationTable: any[] = currentNetwork.networkCubeDataSet.locationTable;
// var normalizedNodeTable: any[] = [];
// var normalizedLinkTable: any[] = [];
// var normalizedLocationTable: any[] = [];
// var networkcubeNodeSchema: networkcube.NodeSchema = currentNetwork.networkCubeDataSet.nodeSchema;
// var networkcubeLinkSchema: networkcube.LinkSchema = currentNetwork.networkCubeDataSet.linkSchema;
// var networkcubeLocationSchema: networkcube.LocationSchema = currentNetwork.networkCubeDataSet.locationSchema;
// // if(normalizedLocationTable)
// // displayLocationTable();
// var locationLabels: string[] = [];
// if (currentNetwork.userLocationTable != undefined) {
// for (var i = 1; i < currentNetwork.userLocationTable.data.length; i++) {
// locationLabels.push(currentNetwork.userLocationTable.data[i][currentNetwork.userLocationSchema.label]);
// }
// }
// console.log('locationLabels', locationLabels);
// // CONVERT SINGLE-LINK TABLE
// var nodeIds: number[] = [];
// var names: string[] = [];
// var nodeLocations: number[][] = [];
// var nodeTimes: number[][] = [];
// if (currentNetwork.userNodeTable == undefined)
// {
// console.log('no node table found, create node table')
// var linkData = currentNetwork.userLinkTable.data;
// var id_source: number;
// var id_target: number;
// var name: string;
// var loc: string;
// var linkSchema: vistorian.VLinkSchema = currentNetwork.userLinkSchema;
// var timeString: string;
// var timeFormatted: string;
// // Create node table
// for (var i = 1; i < linkData.length; i++) {
// // source
// name = linkData[i][linkSchema.source];
// if (names.indexOf(name) < 0) {
// id_source = nodeIds.length
// names.push(name);
// nodeIds.push(id_source);
// nodeLocations.push([]);
// nodeTimes.push([]);
// }
// // target
// name = linkData[i][linkSchema.target];
// if (names.indexOf(name) < 0) {
// id_target = nodeIds.length;
// names.push(name);
// nodeIds.push(id_target);
// nodeLocations.push([]);
// nodeTimes.push([]);
// }
// }
// // create new link table and replace source label by source id
// normalizedLinkTable = [];
// var linkTime: string;
// var found: boolean = true;
// for (var i = 0; i < linkData.length; i++) {
// normalizedLinkTable.push([])
// for (var j = 0; j < linkData[i].length; j++) {
// normalizedLinkTable[i].push(linkData[i][j])
// }
// // replace node names by node IDs, i.e. references to node table.
// if (networkcube.isValidIndex(linkSchema.source)) {
// normalizedLinkTable[i][linkSchema.source] = nodeIds[names.indexOf(linkData[i][linkSchema.source])]
// }
// if (networkcube.isValidIndex(linkSchema.target)) {
// normalizedLinkTable[i][linkSchema.target] = nodeIds[names.indexOf(linkData[i][linkSchema.target])]
// }
// id_source = names.indexOf(linkData[i][linkSchema.source]);
// id_target = names.indexOf(linkData[i][linkSchema.target]);
// if (id_source == -1 || id_target == -1)
// continue;
// // if source and target locations are available, set to indices.
// //source location
// if (linkSchema.location_source > -1) {
// loc = linkData[i][linkSchema.location_source].trim();
// id = locationLabels.indexOf(loc);
// if (id == -1)
// continue;
// // console.log('source_location id: ', loc, id_source, id)
// // check if entry already exists for this node and this time, if not, add this location to the nodes locations.
// found = false;
// for (var t = 0; t < nodeTimes[id_source].length; t++) {
// if (nodeTimes[id_source][t] == linkData[i][linkSchema.time]) {
// found = true;
// break;
// }
// }
// if (!found) {
// nodeTimes[id_source].push(linkData[i][linkSchema.time])
// nodeLocations[id_source].push(id)
// }
// normalizedLinkTable[i][linkSchema.location_source] = id;
// }
// //target location
// if (linkSchema.location_target > -1) {
// loc = linkData[i][linkSchema.location_target].trim();
// id = locationLabels.indexOf(loc);
// if (id == -1)
// continue;
// console.log('source_location id: ', loc, id_target, id)
// // check if entry already exists for this time, if yes, discard this one.
// found = false;
// for (var t = 0; t < nodeTimes[id_target].length; t++) {
// if (nodeTimes[id_target][t] == linkData[i][linkSchema.time]) {
// found = true;
// break;
// }
// }
// if (!found) {
// nodeTimes[id_target].push(linkData[i][linkSchema.time])
// nodeLocations[id_target].push(id)
// }
// normalizedLinkTable[i][linkSchema.location_target] = id;
// }
// }
// // remove header information from user table
// normalizedLinkTable.shift();
// // create normalizedNodeTable
// var time: string;
// normalizedNodeTable = [];
// networkcubeNodeSchema.label = 1;
// var locationsFound: boolean = false;
// var timeFound: boolean = false;
// if (nodeLocations.length > 0) {
// networkcubeNodeSchema.location = 4;
// }
// if (nodeTimes.length > 0) {
// networkcubeNodeSchema.location = 3;
// }
// for (var i = 0; i < nodeIds.length; i++) {
// // duplicate node entry if there is temporal information (currently e.g.: location)
// // console.log('nodeTimes[i]', nodeLocations[i].length)
// if (nodeLocations[i].length > 0) {
// locationsFound = true;
// for (var j = 0; j < nodeLocations[i].length; j++) {
// time = undefined;
// if (nodeTimes[i][j]) {
// time = nodeTimes[i][j].toString();
// }
// normalizedNodeTable.push([nodeIds[i], names[i], nodeTimes[i][j], nodeLocations[i][j]]);
// }
// } else {
// // no locations specified
// if (networkcube.isValidIndex(currentNetwork.userNodeSchema.time)) {
// // time specified in schema
// normalizedNodeTable.push([nodeIds[i], names[i], undefined, undefined]);
// } else {
// // no time specified in schema
// normalizedNodeTable.push([nodeIds[i], names[i], undefined]);
// }
// }
// }
// }
// if (currentNetwork.userNodeTable)
// {
// networkcubeNodeSchema = new networkcube.NodeSchema(0);
// networkcubeNodeSchema.id = currentNetwork.userNodeSchema.id;
// networkcubeNodeSchema.label = currentNetwork.userNodeSchema.label;
// if (networkcube.isValidIndex(currentNetwork.userNodeSchema.time)) {
// networkcubeNodeSchema.time = currentNetwork.userNodeSchema.time;
// }
// if (networkcube.isValidIndex(currentNetwork.userNodeSchema.location)) {
// networkcubeNodeSchema.location = currentNetwork.userNodeSchema.location;
// }
// if (networkcube.isValidIndex(currentNetwork.userNodeSchema.nodeType)) {
// networkcubeNodeSchema.nodeType = currentNetwork.userNodeSchema.nodeType;
// }
// }
// else
// {
// networkcubeNodeSchema = new networkcube.NodeSchema(0);
// networkcubeNodeSchema.id = 0;
// networkcubeNodeSchema.label = 1;
// if (networkcube.isValidIndex(currentNetwork.userLinkSchema.time)) {
// networkcubeNodeSchema.time = 2;
// }
// if (networkcube.isValidIndex(currentNetwork.userLinkSchema.location_source) || networkcube.isValidIndex(currentNetwork.userLinkSchema.location_target)) {
// networkcubeNodeSchema.location = 3;
// }
// }
// // CHECK FOR SINGLE NODE-TABLE
// if (currentNetwork.userLinkTable == undefined)
// {
// console.log('Create and fill link table')
// // create link table and fill
// var nodeData = currentNetwork.userNodeTable.data;
// console.log('nodeData', nodeData)
// var nodeSchema: vistorian.VNodeSchema = currentNetwork.userNodeSchema;
// var id: number;
// var relCol: number;
// var newRow: any[];
// var nodeId: number;
// var newNodeId: number = nodeData.length + 1;
// // networkcubeLinkSchema = new networkcube.LinkSchema(0, 1, 2)
// networkcubeLinkSchema.linkType = 3;
// if (networkcube.isValidIndex(nodeSchema.time))
// networkcubeLinkSchema.time = 4;
// // copy existing nodes into normalizedTable
// for (var i = 1; i < nodeData.length; i++) {
// newRow = [];
// id = parseInt(nodeData[i][nodeSchema.id]);
// while (normalizedNodeTable.length < (id + 1)) {
// // insert empty rows if index is too small
// normalizedNodeTable.push([]);
// }
// newRow.push(id);
// newRow.push(nodeData[i][nodeSchema.label]);
// normalizedNodeTable[id] = newRow;
// }
// networkcubeNodeSchema.label = 1;
// console.log('Create new links: ' + (nodeData.length * nodeSchema.relation.length), nodeData, nodeSchema.relation)
// for (var i = 1; i < nodeData.length; i++) {
// // create relations in link table
// for (var j = 0; j < nodeSchema.relation.length; j++) {
// relCol = nodeSchema.relation[j];
// // dont create relation if field entry is empty;
// if (nodeData[i][relCol].length == 0)
// continue;
// // check if node already exist
// nodeId = -1;
// for (var k = 0; k < normalizedNodeTable.length; k++) {
// // console.log('check node existance: ', normalizedNodeTable[k][1], nodeData[i][relCol])
// if (normalizedNodeTable[k][1] == nodeData[i][relCol]) {
// nodeId = k;
// break;
// }
// }
// if (nodeId < 0) {
// // create new node in node table
// nodeId = normalizedNodeTable.length;
// newRow = [];
// newRow.push(nodeId);
// newRow.push(nodeData[i][relCol]);
// newRow.push(undefined); // time
// newRow.push(undefined); // location
// normalizedNodeTable.push(newRow)
// // console.log('create node', nodeId, nodeData[i][relCol]);
// }
// // create entry in link table
// newRow = []
// // edge id
// newRow.push(normalizedLinkTable.length);
// // source id
// newRow.push(parseInt(nodeData[i][nodeSchema.id]));
// // target id
// newRow.push(nodeId);
// // relation type
// newRow.push(nodeData[0][relCol]);
// // time
// if (nodeSchema.time > -1)
// newRow.push(nodeData[i][nodeSchema.time]);
// normalizedLinkTable.push(newRow);
// // console.log('create edge row', newRow);
// }
// }
// console.log('normalizedLinkTable', normalizedLinkTable)
// }
// // set networkcube link schema
// if (currentNetwork.userLinkTable) {
// for (var field in currentNetwork.userLinkSchema) {
// if (field == 'name') continue;
// networkcubeLinkSchema[field] = currentNetwork.userLinkSchema[field];
// }
// }
// // format times into ISO standart time
// if (currentNetwork.hasOwnProperty('timeFormat') && currentNetwork.timeFormat != undefined && currentNetwork.timeFormat.length > 0) {
// var format = currentNetwork.timeFormat;
// if (networkcubeLinkSchema.time != undefined && networkcubeLinkSchema.time > -1) {
// for (var i = 0; i < normalizedLinkTable.length; i++) {
// time = moment(normalizedLinkTable[i][networkcubeLinkSchema.time], format).format(networkcube.timeFormat())
// if (time.indexOf('Invalid') > -1)
// time = undefined;
// normalizedLinkTable[i][networkcubeLinkSchema.time] = time;
// }
// }
// if (networkcubeNodeSchema.time != undefined && networkcubeNodeSchema.time > -1) {
// for (var i = 0; i < normalizedNodeTable.length; i++) {
// time = moment(normalizedNodeTable[i][networkcubeNodeSchema.time], format).format(networkcube.timeFormat());
// if (time.indexOf('Invalid') > -1)
// time = undefined;
// normalizedNodeTable[i][networkcubeNodeSchema.time] = time
// }
// }
// }
// // sync location tables
// if (currentNetwork.userLocationTable) {
// currentNetwork.networkCubeDataSet.locationTable = currentNetwork.userLocationTable.data.slice(0);
// currentNetwork.networkCubeDataSet.locationTable.shift();
// currentNetwork.networkCubeDataSet.locationSchema = currentNetwork.userLocationSchema;
// }
// // to be save
// currentNetwork.networkCubeDataSet.nodeTable = normalizedNodeTable;
// currentNetwork.networkCubeDataSet.linkTable = normalizedLinkTable;
// currentNetwork.networkCubeDataSet.linkSchema = networkcubeLinkSchema;
// currentNetwork.networkCubeDataSet.nodeSchema = networkcubeNodeSchema;
// console.log('locationTable', currentNetwork.networkCubeDataSet.locationTable)
// // console.log('[vistorian] network created', networkcubeDataSet);
// storage.saveNetwork(currentNetwork,SESSION_NAME);
// networkcube.setDataManagerOptions({ keepOnlyOneSession: true });
// console.log('>> START IMPORT');
// networkcube.importData(SESSION_NAME, currentNetwork.networkCubeDataSet);
// console.log('>> IMPORTED: ', currentNetwork.networkCubeDataSet);
loadNetworkList();
}
// function normalizeLinkTable(n:vistorian.Network)
// {
// }
// function normalizeNodeTable(n:vistorian.Network)
// {
// }
// function createLinkTableFromNodeTable(n:vistorian.Network)
// {
// }
// function createNodeTableFromLinkTable(n:vistorian.Network)
// {
// // Create node table
// var linkData = currentNetwork.userLinkTable.data;
// var id_source: number;
// var id_target: number;
// var name: string;
// var loc: string;
// var linkSchema: vistorian.VLinkSchema = currentNetwork.userLinkSchema;
// var timeString: string;
// var timeFormatted: string;
// var nodeIds: number[] = [];
// var nodeNames: string[] = [];
// var nodeLocations: number[][] = [];
// var nodeTimes: number[][] = [];
// for (var i = 1; i < linkData.length; i++) {
// // source node
// name = linkData[i][linkSchema.source];
// if (nodeNames.indexOf(name) < 0) {
// id_source = nodeIds.length
// nodeNames.push(name);
// nodeIds.push(id_source);
// nodeLocations.push([]);
// nodeTimes.push([]);
// }
// // target node
// name = linkData[i][linkSchema.target];
// if (nodeNames.indexOf(name) < 0) {
// id_target = nodeIds.length;
// nodeNames.push(name);
// nodeIds.push(id_target);
// nodeLocations.push([]);
// nodeTimes.push([]);
// }
// // link time?
// }
// // Create node
// }
function deleteCurrentNetwork() {
storage.deleteNetwork(currentNetwork,SESSION_NAME);
unshowNetwork();
loadNetworkList();
}
function showNetwork(networkId: number) {
unshowNetwork();
$('#noNetworkTables').css('display', 'none');
console.log('networkId', networkId)
currentNetwork = storage.getNetwork(networkId,SESSION_NAME);
if (currentNetwork == null)
return;
// unshow individual tables
$('#individualTables').css('display', 'none');
$('#networkTables').css('display', 'inline');
// set network name
$('#networknameInput').val(currentNetwork.name);
// get all tables for this user so that he can select those
// he wants to create his network from.
var tables = storage.getUserTables(SESSION_NAME)
console.log('usertables', tables, tables.length)
$('#nodetableSelect').append('<option class="tableSelection">---</option>')
$('#linktableSelect').append('<option class="tableSelection">---</option>')
$('#locationtableSelect').append('<option class="tableSelection">---</option>')
$('#nodeTableContainer').css('display', 'inline')
$('#linkTableContainer').css('display', 'inline')
if(currentNetwork.networkConfig.indexOf('node') > -1)
{
$('#linkTableContainer').css('display', 'none')
}
if(currentNetwork.networkConfig.indexOf('link') > -1)
{
$('#nodeTableContainer').css('display', 'none')
}
if(currentNetwork.networkConfig == undefined){
$('#linkTableContainer').css('display', 'none')
$('#nodeTableContainer').css('display', 'none')
}
tables.forEach(t => {
console.log('attach: ', t.name)
$('#nodetableSelect')
.append('<option value="' + t.name + '">' + t.name + '</option>')
$('#linktableSelect')
.append('<option value="' + t.name + '">' + t.name + '</option>')
$('#locationtableSelect')
.append('<option value="' + t.name + '">' + t.name + '</option>')
});
// if this network already has tables, show them
if (currentNetwork.userNodeTable) {
showTable(currentNetwork.userNodeTable, '#nodeTableDiv', false, currentNetwork.userNodeSchema);
$('#nodetableSelect').val(currentNetwork.userNodeTable.name);
}
if (currentNetwork.userLinkTable) {
showTable(currentNetwork.userLinkTable, '#linkTableDiv', false, currentNetwork.userLinkSchema);
$('#linktableSelect').val(currentNetwork.userLinkTable.name);
}
if (currentNetwork.userLocationTable) {
showTable(currentNetwork.userLocationTable, '#locationTableDiv', true, currentNetwork.userLocationSchema);
$('#locationtableSelect').val(currentNetwork.userLocationTable.name);
}
$('#tileViewLink').attr('href', 'sites/tileview.html?session=' + SESSION_NAME + '&datasetName=' + currentNetwork.name.split(' ').join('___'))
$('#mat-nlViewLink').attr('href', 'sites/mat-nl.html?session=' + SESSION_NAME + '&datasetName=' + currentNetwork.name.split(' ').join('___'))
// saveCurrentNetwork(true);
// storage.saveNetwork(currentNetwork);
// MarieBoucherTest.run(SESSION_NAME, currentNetwork.name);
}
// removes a displayed table from the DOM
function unshowNetwork() {
$('#noNetworkTables').css('display', 'block');
$('#nodetableSelect').empty();
$('#linktableSelect').empty();
$('#locationtableSelect').empty();
unshowTable('#linkTableDiv');
unshowTable('#nodeTableDiv');
unshowTable('#locationTableDiv');
$('#networkTables').css('display', 'none');
$('#tileViewLink').attr('href', 'tileview.html?session=' + SESSION_NAME)
$('#mat-nlViewLink').attr('href', 'mat-nl.html?session=' + SESSION_NAME)
}
// TABLES ///
// removes a displayed table from the DOM
function unshowTable(elementName: string) {
$(elementName).empty();
}
var currentTable: vistorian.VTable;
function showSingleTable(tableName: string) {
currentTable = storage.getUserTable(tableName,SESSION_NAME);
showTable(currentTable, '#individualTable', false);
$('#individualTables').css('display', 'inline');
$('#networkTables').css('display', 'none');
$('#noNetworkTables').css('display', 'none');
}
// displays a table into the DOM
// - if schema is passed, shows the schema on the dropdown
// - if user selects a time field, displays field to specify time format
var currentTableId: string;
var currentCell;
function showTable(table: vistorian.VTable, elementName: string, isLocationTable: boolean, schema?: vistorian.VTableSchema) {
var tHead, tBody;
// console.log('showtable', table.name, table.data)
currentTable = table;
$(elementName).empty();
// table name
var tableId = 'datatable_' + table.name;
currentTableId = tableId
$('#' + tableId).remove();
var tableDiv = $('<div id="div_' + tableId + '"></div>');
$(elementName).append(tableDiv);
var tableMenu = $(elementName).prev()
tableMenu.find('.tableMenuButton').remove();
// tableDiv.append(tableMenu);
var data = table.data
if(data.length > DATA_TABLE_MAX_LENGTH){
var info = $('<p>Table shows first 200 rows out of ' + data.length + ' rows in total.</p>');
tableDiv.append(info);
}
// CREATE TABLE MENU
// export button
var csvExportButton = $('<button class="tableMenuButton" onclick="exportCurrentTableCSV(\'' + table.name + '\')">Export as CSV</button>')
tableMenu.append(csvExportButton);
// location extraction button
var extractLocationCoordinatesButton
if (isLocationTable) {
tableMenu.append($('<button class="tableMenuButton" onclick="updateLocations()">Update location coordinates</button>'))
}else{
tableMenu.append($('<button class="tableMenuButton" onclick="extractLocations()">Extract locations</button>'))
}
// replace function
// tableMenu.append('Replace <input id="replace_pattern" type="text"/> by <input type="text" id="replace_value"/><input id="replaceButton" type="button" class="tableMenuButton" onclick="replaceCellContents(\''+tableId+'\')" value="Replace"/>');
// table status
// tableMenu.append('<div id="datatable_' + table.name + '_tool" ></div>');
// tableMenu.append('<div id="datatable_' + table.name + '_error" ></div>');
// create table
var tab = $('<table id="' + tableId + '">');
tableDiv.append(tab);
tab.addClass('datatable stripe hover cell-border and order-column compact');
// create head
tHead = $('<thead>');
tab.append(tHead);
var tr = $('<tr></tr>').addClass('tableheader');
tHead.append(tr);
for (var c = 0; c < data[0].length; c++) {
var td = $('<th></th>').addClass('th').attr('contenteditable', 'false');
tr.append(td);
td.html(data[0][c]);
}
tBody = $('<tbody></tbody>');
tab.append(tBody);
// Load data into html table
for (var r = 1; r < Math.min(data.length, DATA_TABLE_MAX_LENGTH); r++) {
tr = $('<tr></tr>').addClass('tablerow')
tBody.append(tr);
for (var c = 0; c < data[r].length; c++) {
td = $('<td></td>').attr('contenteditable', 'true');
td.data('row', r);
td.data('column', c);
td.data('table', table);
tr.append(td);
td.html(data[r][c])
td.blur(function() {
console.log('td.blur');
if ($(this).html().length == 0) {
$(this).addClass('emptyTableCell')
} else {
$(this).removeClass('emptyTableCell')
}
});
td.focusin(function(e) {
console.log('td.focusin');
saveCellChanges();
currentCell = $(this);
});
td.focusout(function(e) {
console.log('td.focusout');
saveCellChanges();
});
if (typeof data[r][c] == 'string' && data[r][c].trim().length == 0)
td.addClass('emptyTableCell')
}
}
// addOption('table_select', [{'id':'datatable_' + table.id,'name':table.name}]);
// turn table into an interactive jQuery table
var dtable = $('#' + tableId).DataTable({
"autoWidth": true
});
dtable.columns.adjust().draw();
// handle cell change events and store new values in data table
// $('#' + tableId + ' tbody').on('click', 'td', function() {
// saveCellChanges();
// currentCell = $(this);
// });
// Add schema selection to table, if a schema is passed
if (schema) {
console.log('Schema', schema);
// add schema header
var schemaRow = $('<tr class="schemaRow"></tr>');
$('#' + tableId + ' > thead').append(schemaRow);
var select, cell, option, timeFormatInput;
for (var i = 0; i < table.data[0].length; i++) {
cell = $('<th class="schemaCell" id="schemaCell_' + schema.name + '_' + i + '"></th>')
schemaRow.append(cell);
select = $('<select class="schemaSelection" onchange="schemaSelectionChanged(this.value, ' + i + ' , \'' + schema.name + '\')"></select>');
cell.append(select);
select.append('<option>(Not visualized)</option>')
for (var field in schema) {
if (field == 'name'
|| field == 'constructor'
|| field == 'timeFormat')
continue;
var fieldName = '';
// Translate schema names in human readable text
switch(field){
case 'source': fieldName = 'Source Node'; break;
case 'target': fieldName = 'Target Node'; break;
case 'location_source': fieldName = 'Source Node Location'; break;
case 'location_target': fieldName = 'Target Node Location'; break;
case 'linkType': fieldName = 'Link Type'; break;
case 'location': fieldName = 'Node Location'; break;
case 'label': fieldName = 'Node'; break;
default :
fieldName = field;
fieldName = fieldName.charAt(0).toUpperCase() + fieldName.slice(1);
}
option = $('<option value='+field+'>' + fieldName + '</option>');
select.append(option);
if (i == 0 && field == 'id') {
$(option).attr('selected', 'selected');
schema[field] = 0;
}
if (schema[field] == i) {
$(option).attr('selected', 'selected');
if (field == 'time') {
var val = '';
if (currentNetwork.hasOwnProperty('timeFormat')) {
val = "value='"+currentNetwork.timeFormat+"'";
}
timeFormatInput = $('<span class="nobr"><input title="Enter a date pattern" type="text" size="12" id="timeFormatInput_' + schema.name + '" placeholder="DD/MM/YYYY" '+val+'"></input><a href="http://momentjs.com/docs/#/parsing/string-format/" target="_blank" title="Details of the date pattern syntax"><img src="logos/help.png" class="inlineicon"/></a></span>');
cell.append(timeFormatInput);
}
}
// check relations
if (field == 'relation') {
for (var k = 0; k < schema.relation.length; k++) {
if (schema.relation[k] == i) {
$(option).attr('selected', 'selected');
}
}
}
}
}
}
}
// function showLocationTable(table:any[], elementName:string, schema:networkcube.LocationSchema){
// var tHead, tBody;
// console.log('>>>Show location table');
// $(elementName).empty();
// // table name
// var tableId = 'datatable_locationTable';
// $('#'+tableId).remove();
// var tableDiv = $('<div id="div_'+ tableId +'"></div>');
// $(elementName).append(tableDiv);
// var tableMenu = $('<div class="tableMenu"></div>');
// tableDiv.append(tableMenu);
// // tableMenu.append('<p id="datatable_locationTable_name"><b>Name:</b>Locations</p>');
// // var csvExportButton = $('<button class="csvExportButton" onclick="exportCurrentTableCSV()">Export as CSV</button>')
// // tableMenu.append(csvExportButton);
// // export button
// var csvExportButton = $('<button class="tableMenuButton" onclick="exportLocationTableCSV()">Export as CSV</button>')
// tableMenu.append(csvExportButton);
// // table status
// tableMenu.append('<div id="datatable_locationTable_tool" ></div>');
// tableMenu.append('<div id="datatable_locationTable_error" ></div>');