-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComponentsInitialization.js
executable file
·1465 lines (1386 loc) · 79.4 KB
/
ComponentsInitialization.js
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
define(function (require) {
return function (GEPPETTO) {
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = "geppetto/extensions/geppetto-vfb/css/VFB.css";
document.getElementsByTagName("head")[0].appendChild(link);
// any required stuff
var Query = require('./../../js/geppettoModel/model/Query');
var ImportType = require('./../../js/geppettoModel/model/ImportType');
var Bloodhound = require("typeahead.js/dist/bloodhound.min.js");
var vfbTutorial = require('./tutorials/controlPanelTutorial.json');
var markdown = require( "markdown" ).markdown;
var stackMD = window.origin+"/extensions/geppetto-vfb/mdHelpFiles/stack.md";
var termMD = window.origin+"/extensions/geppetto-vfb/mdHelpFiles/term.md";
//Retrieve
function getMDText(urlLocation){
var result = null;
$.ajax( { url: urlLocation,
type: 'get',
dataType: 'html',
async: false,
success: function(data) { result = data; }
}
);
return result;
}
//retrieve MD files text output and stores it into local variables
var termHelpInfo = getMDText(termMD);
var stackHelpInfo = getMDText(stackMD);
/*ADD COMPONENTS*/
//Logo initialization
GEPPETTO.ComponentFactory.addComponent('LOGO', {logo: 'gpt-fly'}, document.getElementById("geppettologo"));
//Tutorial component initialization
GEPPETTO.ComponentFactory.addWidget('TUTORIAL', {
name: 'VFB Tutorial',
tutorialData: vfbTutorial,
isStateless: true,
closeByDefault : true
}, function() {
//temporary until sessions allow to customise the tutorial component
GEPPETTO.Tutorial.addTutorial("https://raw.githubusercontent.com/jrmartin/vfb-extension/vfb-8/17/tutorials/queryTutorial.json");
GEPPETTO.Tutorial.addTutorial("https://raw.githubusercontent.com/jrmartin/vfb-extension/vfb-8/17/tutorials/spotlightTutorial.json");
GEPPETTO.Tutorial.addTutorial("https://raw.githubusercontent.com/jrmartin/vfb-extension/vfb-8/17/tutorials/termTutorial.json");
GEPPETTO.Tutorial.addTutorial("https://raw.githubusercontent.com/jrmartin/vfb-extension/vfb-8/17/tutorials/stackTutorial.json");
});
//Control panel initialization
GEPPETTO.ComponentFactory.addComponent('CONTROLPANEL', {enableInfiniteScroll: true}, document.getElementById("controlpanel"), function () {
// CONTROLPANEL configuration
// set column meta - which custom controls to use, source configuration for data, custom actions
var controlPanelColMeta = [
{
"columnName": "path",
"order": 1,
"locked": false,
"displayName": "Path",
"source": "$entity$.getPath()"
},
{
"columnName": "name",
"order": 2,
"locked": false,
"customComponent": GEPPETTO.LinkComponent,
"displayName": "Name",
"source": "$entity$.getName()",
"actions": "setTermInfo($entity$['$entity$' + '_meta'], $entity$.getName());"
},
{
"columnName": "type",
"order": 3,
"locked": false,
"customComponent": GEPPETTO.LinkArrayComponent,
"displayName": "Type",
"source": "$entity$.$entity$_meta.getTypes().map(function (t) {return t.type.getInitialValue().value})",
"actions": "window.fetchVariableThenRun('$entity$', window.setTermInfoCallback);",
},
{
"columnName": "controls",
"order": 4,
"locked": false,
"customComponent": GEPPETTO.ControlsComponent,
"displayName": "Controls",
"cssClassName": "controlpanel-controls-column",
"source": "",
"actions": "GEPPETTO.ControlPanel.refresh();"
},
{
"columnName": "image",
"order": 5,
"locked": false,
"customComponent": GEPPETTO.ImageComponent,
"displayName": "Image",
"cssClassName": "img-column",
"source": "GEPPETTO.ModelFactory.getAllVariablesOfMetaType($entity$.$entity$_meta.getType(), 'ImageType')[0].getInitialValues()[0].value.data"
}
];
GEPPETTO.ControlPanel.setColumnMeta(controlPanelColMeta);
// which columns to display
GEPPETTO.ControlPanel.setColumns(['name', 'type', 'controls', 'image']);
// which instances to display in the control panel
GEPPETTO.ControlPanel.setDataFilter(function (entities) {
var visualInstances = GEPPETTO.ModelFactory.getAllInstancesWithCapability(GEPPETTO.Resources.VISUAL_CAPABILITY, entities);
var visualParents = [];
for (var i = 0; i < visualInstances.length; i++) {
if (visualInstances[i].getParent() != null){
visualParents.push(visualInstances[i].getParent());
}
}
visualInstances = visualInstances.concat(visualParents);
var compositeInstances = [];
for (var i = 0; i < visualInstances.length; i++) {
if (visualInstances[i].getType().getMetaType() == GEPPETTO.Resources.COMPOSITE_TYPE_NODE) {
compositeInstances.push(visualInstances[i]);
}
}
return compositeInstances;
});
// custom controls configuration in the controls column
GEPPETTO.ControlPanel.setControlsConfig({
"VisualCapability": {
"select": {
"id": "select",
"condition": "GEPPETTO.SceneController.isSelected($instance$.$instance$_obj != undefined ? [$instance$.$instance$_obj] : []) || GEPPETTO.SceneController.isSelected($instance$.$instance$_swc != undefined ? [$instance$.$instance$_swc] : [])",
"false": {
"actions": ["$instance$.select()"],
"icon": "fa-hand-stop-o",
"label": "Unselected",
"tooltip": "Select",
"id": "select",
},
"true": {
"actions": ["$instance$.deselect()"],
"icon": "fa-hand-rock-o",
"label": "Selected",
"tooltip": "Deselect",
"id": "deselect",
}
},
"color": {
"id": "color",
"actions": ["$instance$.setColor('$param$');"],
"icon": "fa-tint",
"label": "Color",
"tooltip": "Color"
},
"zoom": {
"id": "zoom",
"actions": ["GEPPETTO.SceneController.zoomTo($instances$)"],
"icon": "fa-search-plus",
"label": "Zoom",
"tooltip": "Zoom"
},
"visibility_obj": {
"showCondition": "$instance$.getType().hasVariable($instance$.getId() + '_obj')",
"condition": "(function() { var visible = false; if ($instance$.getType().$instance$_obj != undefined && $instance$.getType().$instance$_obj.getType().getMetaType() != GEPPETTO.Resources.IMPORT_TYPE && $instance$.$instance$_obj != undefined) { visible = GEPPETTO.SceneController.isVisible([$instance$.$instance$_obj]); } return visible; })()",
"false": {
"id": "visibility_obj",
"actions": ["(function(){var instance = Instances.getInstance('$instance$.$instance$_obj'); if (instance.getType().getMetaType() == GEPPETTO.Resources.IMPORT_TYPE) { var col = instance.getParent().getColor(); instance.getType().resolve(function() { instance.setColor(col); GEPPETTO.trigger('experiment:visibility_changed', instance); GEPPETTO.ControlPanel.refresh(); }); } else { GEPPETTO.SceneController.show([instance]); }})()"],
"icon": "fa-eye-slash",
"label": "Hidden",
"tooltip": "Show 3D Volume"
},
"true": {
"id": "visibility_obj",
"actions": ["GEPPETTO.SceneController.hide([$instance$.$instance$_obj])"],
"icon": "fa-eye",
"label": "Visible",
"tooltip": "Hide 3D Volume"
}
},
"visibility_swc": {
"showCondition": "$instance$.getType().hasVariable($instance$.getId() + '_swc')",
"condition": "(function() { var visible = false; if ($instance$.getType().$instance$_swc != undefined && $instance$.getType().$instance$_swc.getType().getMetaType() != GEPPETTO.Resources.IMPORT_TYPE && $instance$.$instance$_swc != undefined) { visible = GEPPETTO.SceneController.isVisible([$instance$.$instance$_swc]); } return visible; })()",
"false": {
"id": "visibility_swc",
"actions": ["(function(){var instance = Instances.getInstance('$instance$.$instance$_swc'); if (instance.getType().getMetaType() == GEPPETTO.Resources.IMPORT_TYPE) { var col = instance.getParent().getColor(); instance.getType().resolve(function() { instance.setColor(col); GEPPETTO.trigger('experiment:visibility_changed', instance); GEPPETTO.ControlPanel.refresh(); }); } else { GEPPETTO.SceneController.show([instance]); }})()"],
"icon": "fa-eye-slash",
"label": "Hidden",
"tooltip": "Show 3D Skeleton"
},
"true": {
"id": "visibility_swc",
"actions": ["GEPPETTO.SceneController.hide([$instance$.$instance$_swc])"],
"icon": "fa-eye",
"label": "Visible",
"tooltip": "Hide 3D Skeleton"
}
},
},
"Common": {
"info": {
"id": "info",
"actions": ["var displayTxt = '$instance$'.split('.')['$instance$'.split('.').length - 1]; setTermInfo($instance$[displayTxt + '_meta'], displayTxt);"],
"icon": "fa-info-circle",
"label": "Info",
"tooltip": "Info"
},
"delete": {
"showCondition": "$instance$.getId()!=window.templateID",
"id": "delete",
"actions": ["if($instance$.getPath() == ((window.termInfoPopup.data != undefined) ? eval(window.termInfoPopup.data).getParent().getPath() : undefined)) { setTermInfo(window[window.templateID][window.templateID+'_meta'], window[window.templateID][window.templateID+'_meta'].getParent().getId());} $instance$.deselect(); $instance$.delete();"],
"icon": "fa-trash-o",
"label": "Delete",
"tooltip": "Delete"
}
}
});
// which controls will be rendered, strings need to match ids in the controls configuration
GEPPETTO.ControlPanel.setControls({
"Common": ['info', 'delete'],
"VisualCapability": ['select', 'color', 'visibility', 'zoom', 'visibility_obj', 'visibility_swc']
});
});
//Spotlight initialization
GEPPETTO.ComponentFactory.addComponent('SPOTLIGHT', {indexInstances: false}, document.getElementById("spotlight"), function () {
// SPOTLIGHT configuration
var spotlightConfig = {
"SpotlightBar": {
"DataSources": {},
"CompositeType": {
"type": {
"actions": [
"setTermInfo($variableid$['$variableid$' + '_meta'],'$variableid$');GEPPETTO.Spotlight.close();",
],
"icon": "fa-info-circle",
"label": "Show info",
"tooltip": "Show info"
},
"query": {
actions: [
"window.fetchVariableThenRun('$variableid$', window.addToQueryCallback);"
],
icon: "fa-quora",
label: "Add to query",
tooltip: "Add to query"
},
},
"VisualCapability": {
"buttonOne": {
"condition": "GEPPETTO.SceneController.isSelected($instances$)",
"false": {
"actions": ["GEPPETTO.SceneController.select($instances$)"],
"icon": "fa-hand-stop-o",
"label": "Unselected",
"tooltip": "Select"
},
"true": {
"actions": ["GEPPETTO.SceneController.deselect($instances$)"],
"icon": "fa-hand-rock-o",
"label": "Selected",
"tooltip": "Deselect"
},
},
"buttonTwo": {
"condition": "GEPPETTO.SceneController.isVisible($instances$)",
"false": {
"actions": [
"GEPPETTO.SceneController.show($instances$)"
],
"icon": "fa-eye-slash",
"label": "Hidden",
"tooltip": "Show"
},
"true": {
"actions": [
"GEPPETTO.SceneController.hide($instances$)"
],
"icon": "fa-eye",
"label": "Visible",
"tooltip": "Hide"
}
},
"buttonThree": {
"actions": [
"GEPPETTO.SceneController.zoomTo($instances$);GEPPETTO.Spotlight.close();"
],
"icon": "fa-search-plus",
"label": "Zoom",
"tooltip": "Zoom"
},
}
}
};
GEPPETTO.Spotlight.setButtonBarConfiguration(spotlightConfig);
// external datasource configuration
var spotlightDataSourceConfig = {
VFB: {
url: "https://www.virtualflybrain.org/search/select?fl=short_form,label,synonym,id,type,has_narrow_synonym_annotation,has_broad_synonym_annotation&start=0&fq=ontology_name:(fbbt)&fq=is_obsolete:false&fq=shortform_autosuggest:VFB_*%20OR%20shortform_autosuggest:FB*&rows=250&bq=is_defining_ontology:true%5E100.0%20label_s:%22%22%5E2%20synonym_s:%22%22%20in_subset_annotation:BRAINNAME%5E3%20short_form:FBbt_00003982%5E2&q=*$SEARCH_TERM$*%20OR%20$SEARCH_TERM$&defType=edismax&qf=label%20synonym%20label_autosuggest_ws%20label_autosuggest_e%20label_autosuggest%20synonym_autosuggest_ws%20synonym_autosuggest_e%20synonym_autosuggest%20shortform_autosuggest%20has_narrow_synonym_annotation%20has_broad_synonym_annotation&wt=json&indent=true",
crossDomain: true,
id: "short_form",
label: {field: "label", formatting: "$VALUE$"},
explode_fields: [{field: "short_form", formatting: "$VALUE$ ($LABEL$)"}],
explode_arrays: [{field: "synonym", formatting: "$VALUE$ ($LABEL$)"}],
type: {
class: {
icon: "fa-file-text-o",
buttons: {
buttonOne: {
actions: ["window.fetchVariableThenRun('$ID$', window.setTermInfoCallback);"],
icon: "fa-info-circle",
label: "Show info",
tooltip: "Show info"
},
buttonTwo: {
actions: ["window.fetchVariableThenRun('$ID$', window.addToQueryCallback, '$LABEL$');"],
icon: "fa-quora",
label: "Add to query",
tooltip: "Add to query"
}
}
},
individual: {
icon: "fa-file-image-o",
buttons: {
buttonOne: {
actions: ["window.fetchVariableThenRun('$ID$', window.setTermInfoCallback);"],
icon: "fa-info-circle",
label: "Show info",
tooltip: "Show info"
},
buttonTwo: {
actions: ["window.fetchVariableThenRun('$ID$', window.addToSceneCallback);"],
icon: "fa-file-image-o",
label: "Add to scene",
tooltip: "Add to scene"
},
buttonThree: {
actions: ["window.fetchVariableThenRun('$ID$', window.addToQueryCallback, '$LABEL$');"],
icon: "fa-quora",
label: "Add to query",
tooltip: "Add to query"
}
}
}
},
bloodhoundConfig: {
datumTokenizer: function (d) {
return Bloodhound.tokenizers.nonword(d.label.replace('_', ' '));
},
queryTokenizer: function (q) {
return Bloodhound.tokenizers.nonword(q.replace('_', ' '));
},
sorter: function (a, b) {
var term = $('#typeahead').val();
return customSorter(a, b, term);
}
}
}
};
GEPPETTO.Spotlight.addDataSource(spotlightDataSourceConfig);
});
//Foreground initialization
GEPPETTO.ComponentFactory.addComponent('FOREGROUND', {addToForegroundControls : false}, document.getElementById("foreground-toolbar"));
//Query control initialization
GEPPETTO.ComponentFactory.addComponent('QUERY', {enableInfiniteScroll: true}, document.getElementById("querybuilder"), function () {
// QUERY configuration
var queryResultsColMeta = [
{
"columnName": "id",
"order": 1,
"locked": false,
"visible": true,
"displayName": "ID",
},
{
"columnName": "name",
"order": 2,
"locked": false,
"visible": true,
"customComponent": GEPPETTO.QueryLinkComponent,
"actions": "window.fetchVariableThenRun('$entity$', function(){ var instance = Instances.getInstance('$entity$.$entity$_meta'); setTermInfo(instance, instance.getParent().getName());});",
"displayName": "Name",
"cssClassName": "query-results-name-column",
},
{
"columnName": "description",
"order": 3,
"locked": false,
"visible": true,
"displayName": "Definition",
"cssClassName": "query-results-description-column"
},
{
"columnName": "type",
"order": 4,
"locked": false,
"visible": true,
"displayName": "Type",
"cssClassName": "query-results-type-column"
},
{
"columnName": "controls",
"order": 5,
"locked": false,
"visible": false,
"customComponent": GEPPETTO.QueryResultsControlsComponent,
"displayName": "Controls",
"actions": "",
"cssClassName": "query-results-controls-column"
},
{
"columnName": "images",
"order": 6,
"locked": false,
"visible": true,
"customComponent": GEPPETTO.SlideshowImageComponent,
"displayName": "Images",
"actions": "window.fetchVariableThenRun('$entity$', function () { var meta = '$entity$' + '.' + '$entity$' + '_meta'; var inst = Instances.getInstance(meta); setTermInfo(inst, $entity$.getName()); resolve3D('$entity$'); });",
"cssClassName": "query-results-images-column"
}
];
GEPPETTO.QueryBuilder.setResultsColumnMeta(queryResultsColMeta);
// which columns to display in the results
GEPPETTO.QueryBuilder.setResultsColumns(['name', 'description', 'type', 'images']);
var queryResultsControlConfig = {
"Common": {
"info": {
"id": "info",
"actions": [
"window.fetchVariableThenRun('$ID$', window.setTermInfoCallback);"
],
"icon": "fa-info-circle",
"label": "Info",
"tooltip": "Info"
},
"flybase": {
"showCondition": "'$ID$'.startsWith('FBbt')",
"id": "flybase",
"actions": [
"window.open('http://flybase.org/cgi-bin/cvreport.html?rel=is_a&id=' + '$ID$'.replace(/_/g, ':'), '_blank').focus()"
],
"icon": "gpt-fly",
"label": "FlyBase",
"tooltip": "FlyBase Term"
},
"flybase": {
"showCondition": "('$ID$'.startsWith('FB') && !'$ID$'.startsWith('FBbt'))",
"id": "flybase",
"actions": [
"window.open('http://flybase.org/reports/' + '$ID$'.replace(/_/g, ':'), '_blank').focus()"
],
"icon": "gpt-fly",
"label": "FlyBase",
"tooltip": "FlyBase Report"
}
}
};
GEPPETTO.QueryBuilder.setResultsControlsConfig(queryResultsControlConfig);
// add datasource config to query control
var queryBuilderDatasourceConfig = {
VFB: {
url: "https://www.virtualflybrain.org/search/select?fl=short_form,label,synonym,id,type,has_narrow_synonym_annotation,has_broad_synonym_annotation&start=0&fq=ontology_name:(fbbt)&fq=is_obsolete:false&fq=shortform_autosuggest:VFB_*%20OR%20shortform_autosuggest:FBbt_*&rows=250&bq=is_defining_ontology:true%5E100.0%20label_s:%22%22%5E2%20synonym_s:%22%22%20in_subset_annotation:BRAINNAME%5E3%20short_form:FBbt_00003982%5E2&q=*$SEARCH_TERM$*%20OR%20$SEARCH_TERM$&defType=edismax&qf=label%20synonym%20label_autosuggest_ws%20label_autosuggest_e%20label_autosuggest%20synonym_autosuggest_ws%20synonym_autosuggest_e%20synonym_autosuggest%20shortform_autosuggest%20has_narrow_synonym_annotation%20has_broad_synonym_annotation&wt=json&indent=true",
crossDomain: true,
id: "short_form",
label: {field: "label", formatting: "$VALUE$"},
explode_fields: [{field: "short_form", formatting: "$VALUE$ ($LABEL$)"}],
explode_arrays: [{field: "synonym", formatting: "$VALUE$ ($LABEL$)"}],
type: {
class: {
actions: ["window.fetchVariableThenRun('$ID$', function(){ GEPPETTO.QueryBuilder.addQueryItem({ term: '$LABEL$', id: '$ID$'}); });"],
icon: "fa-dot-circle-o"
},
individual: {
actions: ["window.fetchVariableThenRun('$ID$', function(){ GEPPETTO.QueryBuilder.addQueryItem({ term: '$LABEL$', id: '$ID$'}); });"],
icon: "fa-square-o"
}
},
queryNameToken: '$NAME',
resultsFilters: {
getId: function (record) {
return record[0]
},
getName: function (record) {
return record[1]
},
getDescription: function (record) {
return record[2]
},
getType: function (record) {
return record[3]
},
getImageData: function (record) {
return record[4]
},
getRecords: function (payload) {
return payload.results.map(function (item) {
return item.values
})
}
},
bloodhoundConfig: {
datumTokenizer: function (d) {
return Bloodhound.tokenizers.nonword(d.label.replace('_', ' '));
},
queryTokenizer: function (q) {
return Bloodhound.tokenizers.nonword(q.replace('_', ' '));
},
sorter: function (a, b) {
var term = $("#query-typeahead").val();
return customSorter(a, b, term);
}
}
}
};
GEPPETTO.QueryBuilder.addDataSource(queryBuilderDatasourceConfig);
});
//Canvas initialisation
window.vfbCanvas = undefined;
GEPPETTO.ComponentFactory.addComponent('CANVAS', {}, document.getElementById("sim"), function () {
this.flipCameraY();
this.flipCameraZ();
this.setWireframe(true);
this.displayAllInstances();
window.vfbCanvas = this;
if(window.StackViewer1 != undefined){
window.StackViewer1.setCanvasRef(this);
}
});
//Loading spinner initialization
GEPPETTO.Spinner.setLogo("gpt-fly");
// VFB initialization routines
window.initVFB = function () {
window.templateID = undefined;
window.redirectURL = '$PROTOCOL$//$HOST$/?i=$TEMPLATE$,$VFB_ID$&id=$VFB_ID$';
// widgets default dimensions and positions
var getStackViewerDefaultWidth = function() { return Math.ceil(window.innerWidth / 4); };
var getStackViewerDefaultHeight = function() { return Math.ceil(window.innerHeight/4) - 10; };
var getTermInfoDefaultWidth = function() { return Math.ceil(window.innerWidth / 4); };
var getTermInfoDefaultHeight = function() { return ((window.innerHeight - Math.ceil(window.innerHeight/4))-20); };
var getTermInfoDefaultX = function() { return (window.innerWidth - (Math.ceil(window.innerWidth / 4) + 10)); };
var getStackViewerDefaultX = function() { return (window.innerWidth - (Math.ceil(window.innerWidth / 4) + 10)); };
var getStackViewerDefaultY = function() { return (window.innerHeight - Math.ceil(window.innerHeight/4)); };
var getTermInfoDefaultY = function() {return 10;};
var getButtonBarDefaultX = function() { return (Math.ceil(window.innerWidth / 2) - 125); };
var getButtonBarDefaultY = function() { return 10; };
// logic to assign colours to elements in the scene
window.colours = ["0x5b5b5b", "0x00ff00", "0xff0000", "0x0000ff", "0x0084f6", "0x008d46", "0xa7613e", "0x4f006a", "0x00fff6", "0x3e7b8d", "0xeda7ff", "0xd3ff95", "0xb94fff", "0xe51a58", "0x848400", "0x00ff95", "0x61002c", "0xf68412", "0xcaff00", "0x2c3e00", "0x0035c1", "0xffca84", "0x002c61", "0x9e728d", "0x4fb912", "0x9ec1ff", "0x959e7b", "0xff7bb0", "0x9e0900", "0xffb9b9", "0x8461ca", "0x9e0072", "0x84dca7", "0xff00f6", "0x00d3ff", "0xff7258", "0x583e35", "0x003e35", "0xdc61dc", "0x6172b0", "0xb9ca2c", "0x12b0a7", "0x611200", "0x2c002c", "0x5800ca", "0x95c1ca", "0xd39e23", "0x84b058", "0xe5edb9", "0xf6d3ff", "0xb94f61", "0x8d09a7", "0x6a4f00", "0x003e9e", "0x7b3e7b", "0x3e7b61", "0xa7ff61", "0x0095d3", "0x3e7200", "0xb05800", "0xdc007b", "0x9e9eff", "0x4f4661", "0xa7fff6", "0xe5002c", "0x72dc72", "0xffed7b", "0xb08d46", "0x6172ff", "0xdc4600", "0x000072", "0x090046", "0x35ed4f", "0x2c0000", "0xa700ff", "0x00f6c1", "0x9e002c", "0x003eff", "0xf69e7b", "0x6a7235", "0xffff46", "0xc1b0b0", "0x727272", "0xc16aa7", "0x005823", "0xff848d", "0xb08472", "0x004661", "0x8dff12", "0xb08dca", "0x724ff6", "0x729e00", "0xd309c1", "0x9e004f", "0xc17bff", "0x8d95b9", "0xf6a7d3", "0x232309", "0xff6aca", "0x008d12", "0xffa758", "0xe5c19e", "0x00122c", "0xc1b958", "0x00c17b", "0x462c00", "0x7b3e58", "0x9e46a7", "0x4f583e", "0x6a35b9", "0x72b095", "0xffb000", "0x4f3584", "0xb94635", "0x61a7ff", "0xd38495", "0x7b613e", "0x6a004f", "0xed58ff", "0x95d300", "0x35a7c1", "0x00009e", "0x7b3535", "0xdcff6a", "0x95d34f", "0x84ffb0", "0x843500", "0x4fdce5", "0x462335", "0x002c09", "0xb9dcc1", "0x588d4f", "0x9e7200", "0xca4684", "0x00c146", "0xca09ed", "0xcadcff", "0x0058a7", "0x2ca77b", "0x8ddcff", "0x232c35", "0xc1ffb9", "0x006a9e", "0x0058ff", "0xf65884", "0xdc7b46", "0xca35a7", "0xa7ca8d", "0x4fdcc1", "0x6172d3", "0x6a23ff", "0x8d09ca", "0xdcc12c", "0xc1b97b", "0x3e2358", "0x7b6195", "0xb97bdc", "0xffdcd3", "0xed5861", "0xcab9ff", "0x3e5858", "0x729595", "0x7bff7b", "0x95356a", "0xca9eb9", "0x723e1a", "0x95098d", "0xf68ddc", "0x61b03e", "0xffca61", "0xd37b72", "0xffed9e", "0xcaf6ff", "0x58c1ff", "0x8d61ed", "0x61b972", "0x8d6161", "0x46467b", "0x0058d3", "0x58dc09", "0x001a72", "0xd33e2c", "0x959546", "0xca7b00", "0x4f6a8d", "0x9584ff", "0x46238d", "0x008484", "0xf67235", "0x9edc84", "0xcadc6a", "0xb04fdc", "0x4f0912", "0xff1a7b", "0x7bb0d3", "0x1a001a", "0x8d35f6", "0x5800a7", "0xed8dff", "0x969696", "0xffd300"];
window.coli = 0;
window.setSepCol = function (entityPath) {
var c = coli;
coli++;
if (coli > 199) {
coli = 0;
}
if (Instances.getInstance(entityPath).setColor != undefined){
Instances.getInstance(entityPath).setColor(colours[c], true).setOpacity(0.3, true);
try {
Instances.getInstance(entityPath)[entityPath + '_swc'].setOpacity(1.0);
} catch (ignore) {
}
if (c = 0) {
Instances.getInstance(entityPath).setOpacity(0.2, true);
}
}else{
console.log('Issue setting colour for ' + entityPath);
}
};
// custom handler for resolving 3d geometries
window.resolve3D = function (path, callback) {
var rootInstance = Instances.getInstance(path);
window.updateHistory(rootInstance.getName());
GEPPETTO.SceneController.deselectAll();
// check if we can set templateID (first template loaded will be kept as templateID)
if(window.templateID == undefined){
var superTypes = rootInstance.getType().getSuperType();
for(var i=0; i<superTypes.length; i++){
if(superTypes[i].getId() == 'Template'){
window.templateID = rootInstance.getId();
}
}
} else {
// check if the user is adding to the scene something belonging to another template
var superTypes = rootInstance.getType().getSuperType();
var templateID = "unknown";
for(var i=0; i<superTypes.length; i++){
if(superTypes[i].getId() == window.templateID){
templateID = superTypes[i].getId()
}
if(superTypes[i].getId() == 'Class'){
templateID = window.templateID;
return; // Exit if Class - Class doesn't have image types.
}
}
var meta = rootInstance[rootInstance.getId() + '_meta'];
if(meta != undefined){
if (typeof meta.getType().template != "undefined"){
var templateMarkup = meta.getType().template.getValue().wrappedObj.value.html;
var domObj = $(templateMarkup);
var anchorElement = domObj.filter('a');
// extract ID
var templateID = anchorElement.attr('instancepath');
if (window.EMBEDDED){
var curHost = parent.document.location.host;
var curProto = parent.document.location.protocol;
}else{
var curHost = document.location.host;
var curProto = document.location.protocol;
}
if(templateID != window.templateID){
// open new window with the new template and the instance ID
var targetWindow = '_blank';
var newUrl = window.redirectURL.replace(/\$VFB_ID\$/gi, rootInstance.getId()).replace(/\$TEMPLATE\$/gi, templateID).replace(/\$HOST\$/gi, curHost).replace(/\$PROTOCOL\$/gi, curProto);
window.open(newUrl, targetWindow);
// stop flow here, we don't want to add to scene something with a different template
return;
}
}
}
}
var instance = undefined;
// check if we have swc
try {
instance = Instances.getInstance(path + "." + path + "_swc");
} catch (ignore) {
}
// if no swc check if we have obj
if (instance == undefined) {
try {
instance = Instances.getInstance(path + "." + path + "_obj");
} catch (ignore) {
}
}
// if anything was found resolve type (will add to scene)
if (instance != undefined) {
var postResolve = function () {
setSepCol(path);
if (callback != undefined) {
callback();
}
};
if(instance.getType() instanceof ImportType) {
instance.getType().resolve(postResolve);
} else {
// add instance to scene
vfbCanvas.display([instance]);
// trigger update for components that are listening
GEPPETTO.trigger(GEPPETTO.Events.Instances_created, [instance]);
postResolve();
}
}
// independently from the above, check if we have slices for the instance
try {
instance = Instances.getInstance(path + "." + path + "_slices");
if(instance.getType() instanceof ImportType){
instance.getType().resolve();
}
} catch (ignore) {
// any alternative handling goes here
}
};
window.fetchVariableThenRun = function(variableId, callback, label){
GEPPETTO.SceneController.deselectAll(); // signal something is happening!
var variables = GEPPETTO.ModelFactory.getTopLevelVariablesById([variableId]);
if (!variables.length>0) {
Model.getDatasources()[0].fetchVariable(variableId, function() {
callback(variableId, label);
});
} else {
callback(variableId, label);
}
};
window.addToSceneCallback = function(variableId){
var instance = Instances.getInstance(variableId);
var meta = Instances.getInstance(variableId + '.' + variableId + '_meta');
resolve3D(variableId, function() {
GEPPETTO.SceneController.deselectAll();
instance.select();
//GEPPETTO.Spotlight.openToInstance(instance);
setTermInfo(meta, meta.getParent().getId());
});
};
window.addToQueryCallback = function(variableId, label) {
window.clearQS();
GEPPETTO.QueryBuilder.clearAllQueryItems();
GEPPETTO.QueryBuilder.switchView(false);
GEPPETTO.QueryBuilder.addQueryItem({
term: (label != undefined) ? label : eval(variableId).getName(),
id: variableId
});
GEPPETTO.QueryBuilder.open();
};
window.setTermInfoCallback = function(variableId){
var instance = Instances.getInstance(variableId + '.' + variableId + '_meta');
setTermInfo(instance, instance.getParent().getId());
};
// custom handler for term info clicks
window.customHandler = function (node, path, widget) {
var n;
var otherId;
var otherName;
try {
n = eval(path);
} catch (ex) {
node = undefined;
}
var meta = path + "." + path + "_meta";
var target = widget;
// if (GEPPETTO.isKeyPressed("meta")) {
// target = G.addWidget(1, {isStateless: true}).addCustomNodeHandler(customHandler, 'click');
//}
if (n != undefined) {
var metanode = Instances.getInstance(meta);
if (target.data == metanode){
window.resolve3D(path);
}else{
target.setData(metanode).setName(n.getName());
}
} else {
// check for passed ID:
if (path.indexOf(',')>-1){
otherId = path.split(',')[1];
otherName = path.split(',')[2];
path = path.split(',')[0];
}
// try to evaluate as path in Model
var entity = Model[path];
if(entity instanceof Query){
GEPPETTO.trigger('spin_logo');
$("body").css("cursor", "progress");
// clear query builder
GEPPETTO.QueryBuilder.clearAllQueryItems();
var callback = function(){
// check if any results with count flag
if(GEPPETTO.QueryBuilder.props.model.count > 0){
// runQuery if any results
GEPPETTO.QueryBuilder.runQuery();
} else {
GEPPETTO.QueryBuilder.switchView(false);
}
// show query component
GEPPETTO.QueryBuilder.open();
$("body").css("cursor", "default");
GEPPETTO.trigger('stop_spin_logo');
};
// add query item + selection
if (otherId == undefined) {
GEPPETTO.QueryBuilder.addQueryItem({ term: widget.name, id: widget.data.getParent().getId(), queryObj: entity}, callback);
}else{
if (window[otherId] == undefined){
window.fetchVariableThenRun(otherId, function(){GEPPETTO.QueryBuilder.addQueryItem({ term: otherName, id: otherId, queryObj: entity}, callback)});
}else{
GEPPETTO.QueryBuilder.addQueryItem({ term: otherName, id: otherId, queryObj: entity}, callback);
}
}
} else {
Model.getDatasources()[0].fetchVariable(path, function () {
Instances.getInstance(meta);
target.setData(eval(meta)).setName(eval(path).getName());
resolve3D(path);
});
}
}
};
// set term info on selection
GEPPETTO.on(GEPPETTO.Events.Select, function (instance) {
var selection = GEPPETTO.SceneController.getSelection();
if (selection.length > 0 && instance.isSelected()) {
var latestSelection = instance;
var currentSelectionName = getTermInfoWidget().name;
if(latestSelection.getChildren().length > 0){
// it's a wrapper object - if name is different from current selection set term info
if(currentSelectionName != latestSelection.getName()) {
setTermInfo(latestSelection[latestSelection.getId() + "_meta"], latestSelection[latestSelection.getId() + "_meta"].getName());
}
} else {
// it's a leaf (no children) / grab parent if name is different from current selection set term info
var parent = latestSelection.getParent();
if(parent != null && currentSelectionName != parent.getName()){
setTermInfo(parent[parent.getId() + "_meta"], parent[parent.getId() + "_meta"].getName());
}
}
}
if (window.StackViewer1 != undefined){
updateStackWidget();
}
});
// stack widget helper methods
var getSliceInstances = function(){
var potentialInstances = GEPPETTO.ModelFactory.getAllPotentialInstancesEndingWith('_slices');
var sliceInstances = [];
var instance;
for(var i=0; i<potentialInstances.length; i++){
instance = Instances.getInstance(potentialInstances[i],false);
if (instance){
sliceInstances.push(instance);
}
}
return sliceInstances;
};
var updateStackWidget = function(){
window.checkConnection();
console.log('Updating stack...');
window.StackViewer1.setData({
instances: getSliceInstances()
});
};
window.addStackWidget = function(){
var sliceInstances = getSliceInstances();
if (window.StackViewer1 == undefined){
var config;
var domainId = [];
var domainName = [];
if (typeof sliceInstances[0] !== "undefined"){
config = JSON.parse(sliceInstances[0].getValue().wrappedObj.value.data);
}
if (config == undefined || typeof config !== "undefined"){
config = {
serverUrl: 'http://www.virtualflybrain.org/fcgi/wlziipsrv.fcgi',
templateId: 'NOTSET'
};
}
G.addWidget(8, {isStateless: true}).setConfig(config).setData({
instances: sliceInstances
});
// set canvas if it's already there
if(window.vfbCanvas != undefined){
window.StackViewer1.setCanvasRef(window.vfbCanvas);
}
// set initial position:
window.StackViewer1.setPosition(getStackViewerDefaultX(), getStackViewerDefaultY());
window.StackViewer1.setSize(getStackViewerDefaultHeight(), getStackViewerDefaultWidth());
window.StackViewer1.setName('Slice Viewer');
window.StackViewer1.setTrasparentBackground(true);
window.StackViewer1.showHistoryIcon(false);
window.StackViewer1.setHelpInfo(stackHelpInfo);
window.StackViewer1.$el.bind('restored', function(event,id) {
if(id == window.StackViewer1.getId()){
if(window.StackViewer1 != undefined) {
window.StackViewer1.setSize(getStackViewerDefaultHeight(), getStackViewerDefaultWidth());
window.StackViewer1.setPosition(getStackViewerDefaultX(), getStackViewerDefaultY());
}
}
});
// on change to instances reload stack:
GEPPETTO.on(GEPPETTO.Events.Instance_deleted, function(path){
console.log(path.split('.')[0] + ' deleted...');
if (window.StackViewer1 != undefined){
if(path!=undefined && path.length > 0){
window.StackViewer1.removeSlice(path);
}else{
console.log('Removing instance issue: ' + path);
}
}
});
GEPPETTO.on(GEPPETTO.Events.Instances_created, function(instances){
console.log('Instance created...');
if (window.StackViewer1 != undefined){
if(instances!=undefined && instances.length > 0){
var config = {
serverUrl: 'http://www.virtualflybrain.org/fcgi/wlziipsrv.fcgi',
templateId: window.templateID
};
instances.forEach(function (parentInstance){
parentInstance.parent.getChildren().forEach(function (instance){
if (instance.getName() == 'Stack Viewer Slices'){
window.StackViewer1.addSlices(instance);
if (instance.parent.getId() == window.templateID){
try{
config=JSON.parse(instance.getValue().wrappedObj.value.data);
window.StackViewer1.setConfig(config);
}catch (err){
console.log(err.message);
window.StackViewer1.setConfig(config);
}
}
console.log('Passing instance: ' + instance.getId());
}
})
});
}
}
});
// on colour change update:
GEPPETTO.on(GEPPETTO.Events.Color_set, function(instances){
console.log('Colour change...');
if (window.StackViewer1 != undefined){
if(instances!=undefined && instances.instance){
if (instances.instance.getType().getMetaType() == 'CompositeType'){
instances.instance.getChildren().forEach(function (instance){if (instance.getName() == 'Stack Viewer Slices'){window.StackViewer1.addSlices(instance)}});
}else if (instances.instance.parent && instances.instance.parent.getType().getMetaType() == 'CompositeType'){
instances.instance.parent.getChildren().forEach(function (instance){if (instance.getName() == 'Stack Viewer Slices'){window.StackViewer1.addSlices(instance)}});
}else{
console.log('Colour setting issue: ' + instances);
}
}else{
console.log('Colour setting issue! ' + instances);
}
}
});
$('.ui-dialog-titlebar-minimize').hide(); //hide all minimize buttons
} else {
window.vfbWindowResize();
$('#' + window.StackViewer1.getId()).parent().effect('shake', {distance:5, times: 3}, 500);
}
};
// custom sorter for bloodhound
window.customSorter = function (a, b, InputString) {
//move exact matches to top
if (InputString == a.label) {
return -1;
}
if (InputString == b.label) {
return 1;
}
//close match without case matching
if (InputString.toLowerCase() == a.label.toLowerCase()) {
return -1;
}
if (InputString.toLowerCase() == b.label.toLowerCase()) {
return 1;
}
//match ignoring joinging nonwords
Bloodhound.tokenizers.nonword("test thing-here12 34f").join(' ');
if (Bloodhound.tokenizers.nonword(InputString.toLowerCase()).join(' ') == Bloodhound.tokenizers.nonword(a.label.toLowerCase()).join(' ')) {
return -1;
}
if (Bloodhound.tokenizers.nonword(InputString.toLowerCase()).join(' ') == Bloodhound.tokenizers.nonword(b.label.toLowerCase()).join(' ')) {
return 1;
}
//match against id
if (InputString.toLowerCase() == a.id.toLowerCase()) {
return -1;
}
if (InputString.toLowerCase() == b.id.toLowerCase()) {
return 1;
}
//pick up any match without nonword join character match
if (Bloodhound.tokenizers.nonword(a.label.toLowerCase()).join(' ').indexOf(Bloodhound.tokenizers.nonword(InputString.toLowerCase()).join(' ')) < 0 && Bloodhound.tokenizers.nonword(b.label.toLowerCase()).join(' ').indexOf(Bloodhound.tokenizers.nonword(InputString.toLowerCase()).join(' ')) > -1) {
return 1;
}
if (Bloodhound.tokenizers.nonword(b.label.toLowerCase()).join(' ').indexOf(Bloodhound.tokenizers.nonword(InputString.toLowerCase()).join(' ')) < 0 && Bloodhound.tokenizers.nonword(a.label.toLowerCase()).join(' ').indexOf(Bloodhound.tokenizers.nonword(InputString.toLowerCase()).join(' ')) > -1) {
return -1;
}
//also with underscores ignored
if (Bloodhound.tokenizers.nonword(a.label.toLowerCase()).join(' ').replace('_', ' ').indexOf(Bloodhound.tokenizers.nonword(InputString.toLowerCase()).join(' ').replace('_', ' ')) < 0 && Bloodhound.tokenizers.nonword(b.label.toLowerCase()).join(' ').replace('_', ' ').indexOf(Bloodhound.tokenizers.nonword(InputString.toLowerCase()).join(' ').replace('_', ' ')) > -1) {
return 1;
}
if (Bloodhound.tokenizers.nonword(b.label.toLowerCase()).join(' ').replace('_', ' ').indexOf(Bloodhound.tokenizers.nonword(InputString.toLowerCase()).join(' ').replace('_', ' ')) < 0 && Bloodhound.tokenizers.nonword(a.label.toLowerCase()).join(' ').replace('_', ' ').indexOf(Bloodhound.tokenizers.nonword(InputString.toLowerCase()).join(' ').replace('_', ' ')) > -1) {
return -1;
}
//if not found in one then advance the other
if (a.label.toLowerCase().indexOf(InputString.toLowerCase()) < 0 && b.label.toLowerCase().indexOf(InputString.toLowerCase()) > -1) {
return 1;
}
if (b.label.toLowerCase().indexOf(InputString.toLowerCase()) < 0 && a.label.toLowerCase().indexOf(InputString.toLowerCase()) > -1) {
return -1;