-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_ddi.js
executable file
·7777 lines (6387 loc) · 248 KB
/
app_ddi.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
//////////
// Globals
// hostname default - the app will use it to obtain the variable metadata
// (ddi) and pre-processed data info if the file id is supplied as an
// argument (for ex., gui.html?dfId=17), but hostname isn't.
// Edit it to suit your installation.
// (NOTE that if the file id isn't supplied, the app will default to the
// local files specified below!)
// NEW: it is also possible now to supply complete urls for the ddi and
// the tab-delimited data file; the parameters are ddiurl and dataurl.
// These new parameters are optional. If they are not supplied, the app
// will go the old route - will try to cook standard dataverse urls
// for both the data and metadata, if the file id is supplied; or the
// local files if nothing is supplied.
// -- L.A.
// Kripanshu testing.
// index.js
var production = false;
var private = false;
if (production && fileid == "") {
alert("Error: No fileid has been provided.");
throw new Error("Error: No fileid has been provided.");
}
var dataverseurl = "";
if (hostname) {
dataverseurl = "https://" + hostname;
} else {
if (production) {
dataverseurl = "%PRODUCTION_DATAVERSE_URL%";
} else {
dataverseurl = "http://localhost:8080";
}
}
if (fileid && !dataurl) {
// file id supplied; we are going to assume that we are dealing with
// a dataverse and cook a standard dataverse data access url,
// with the fileid supplied and the hostname we have
// either supplied or configured:
dataurl = dataverseurl + "/api/access/datafile/" + fileid;
dataurl = dataurl + "?key=" + apikey;
// (it is also possible to supply dataurl to the script directly,
// as an argument -- L.A.)
}
if (!production) {
// base URL for the R apps:
var rappURL = "http://0.0.0.0:8000/custom/";
} else {
var rappURL = "https://beta.dataverse.org/custom/"; //this will change when/if the production host changes
}
// space index
var myspace = 0;
var svg = d3.select("#main.left div.carousel-inner").attr('id', 'innercarousel')
.append('div').attr('class', 'item active').attr('id', 'm0').append('svg').attr('id', 'whitespace');
var logArray = [];
//.attr('width', width)
//.attr('height', height);
var tempWidth = d3.select("#main.left").style("width")
var width = tempWidth.substring(0, (tempWidth.length - 2));
/*var tempHeight = d3.select("#main.left").style("height")
var height = tempHeight.substring(0,(tempHeight.length-2));*/
var height = $(window).height() - 120; // Hard coding for header and footer and bottom margin.
var forcetoggle = ["true"];
var estimated = false;
var estimateLadda = Ladda.create(document.getElementById("btnEstimate"));
var selectLadda = Ladda.create(document.getElementById("btnSelect"));
var rightClickLast = false;
// this is the initial color scale that is used to establish the initial colors of the nodes. allNodes.push() below establishes a field for the master node array allNodes called "nodeCol" and assigns a color from this scale to that field. everything there after should refer to the nodeCol and not the color scale, this enables us to update colors and pass the variable type to R based on its coloring
var colors = d3.scale.category20();
var colorTime = false;
var timeColor = '#2d6ca2';
var colorCS = false;
var csColor = '#419641';
var depVar = false;
var dvColor = '#28a4c9';
var nomColor = '#ff6600';
var subsetdiv = false;
var setxdiv = false;
var varColor = '#f0f8ff'; //d3.rgb("aliceblue");
var selVarColor = '#fa8072'; //d3.rgb("salmon");
var taggedColor = '#f5f5f5'; //d3.rgb("whitesmoke");
var d3Color = '#1f77b4'; // d3's default blue
var grayColor = '#c0c0c0';
var lefttab = "tab1"; //global for current tab in left panel
var righttab = "btnUnivariate"; // global for current tab in right panel
var zparams = {
zdata: [],
zedges: [],
ztime: [],
znom: [],
zcross: [],
zmodel: "",
zvars: [],
zdv: [],
zdataurl: "",
zsubset: [],
zsetx: [],
zmodelcount: 0,
zplot: [],
zsessionid: "",
zdatacite: "",
zmetadataurl: "",
zusername: "",
zcrosstab:[]
};
//var myjson;
var json_data_explore = "empty";
// Radius of circle
var allR = 40;
//Width and height for histgrams
var barwidth = 1.3 * allR;
var barheight = 0.5 * allR;
var barPadding = 0.35;
var barnumber = 7;
var arc0 = d3.svg.arc()
.innerRadius(allR + 5)
.outerRadius(allR + 20)
.startAngle(0)
.endAngle(3.2);
var arc1 = d3.svg.arc()
.innerRadius(allR + 5)
.outerRadius(allR + 20)
.startAngle(0)
.endAngle(1);
var arc2 = d3.svg.arc()
.innerRadius(allR + 5)
.outerRadius(allR + 20)
.startAngle(1.1)
.endAngle(2.2);
var arc3 = d3.svg.arc()
.innerRadius(allR + 5)
.outerRadius(allR + 20)
.startAngle(2.3)
.endAngle(3.3);
var arc4 = d3.svg.arc()
.innerRadius(allR + 5)
.outerRadius(allR + 20)
.startAngle(4.3)
.endAngle(5.3);
// to draw circle on the ends of the link:path
var circledata = [
{id: 0, name: 'circle', path: 'M 0, 0 m -5, 0 a 5,5 0 1,0 10,0 a 5,5 0 1,0 -10,0', viewbox: '-6 -6 12 12'}
]
// From .csv
var dataset2 = [];
var valueKey = [];
var lablArray = [];
var hold = [];
var allNodes = [];
var newallNodes = [];
var allResults = [];
var subsetNodes = [];
var links = [];
var nodes = [];
var transformVar = "";
var summaryHold = false;
var selInteract = false;
var modelCount = 0;
var callHistory = []; // unique to the space. saves transform and subset calls.
var citetoggle = false;
var connect_nodes = [];
var rightPanelList=[];
// transformation toolbar options
var transformList = ["log(d)", "exp(d)", "d^2", "sqrt(d)", "interact(d,e)"];
// arry of objects containing allNode, zparams, transform vars
var spaces = [];
var trans = []; //var list for each space contain variables in original data plus trans in that space
// end of (most) global declarations (minus functions)
// collapsable user log
$('#collapseLog').on('shown.bs.collapse', function () {
d3.select("#collapseLog div.panel-body").selectAll("p")
.data(logArray)
.enter()
.append("p")
.text(function (d) {
return d;
});
//$("#logicon").removeClass("glyphicon-chevron-up").addClass("glyphicon-chevron-down");
});
$('#collapseLog').on('hidden.bs.collapse', function () {
d3.select("#collapseLog div.panel-body").selectAll("p")
.remove();
//$("#logicon").removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-up");
});
// text for the about box
// note that .textContent is the new way to write text to a div
$('#about div.panel-body').text('TwoRavens v0.1 "Dallas" -- The Norse god Odin had two talking ravens as advisors, who would fly out into the world and report back all they observed. In the Norse, their names were "Thought" and "Memory". In our coming release, our thought-raven automatically advises on statistical model selection, while our memory-raven accumulates previous statistical univariate from Dataverse, to provide cummulative guidance and meta-analysis.'); //This is the first public release of a new, interactive Web application to explore data, view descriptive statistics, and estimate statistical models.";
//
// read DDI metadata with d3:
var metadataurl = "";
if (ddiurl) {
// a complete ddiurl is supplied:
metadataurl = ddiurl;
} else if (fileid) {
// file id supplied; we're going to cook a standard dataverse
// metadata url, with the file id provided and the hostname
// supplied or configured:
metadataurl = dataverseurl + "/api/meta/datafile/" + fileid;
} else {
// neither a full ddi url, nor file id supplied; use one of the sample DDIs that come with
// the app, in the data directory:
// metadataurl="data/qog137.xml"; // quality of government
metadataurl = "~/TwoRavens/data/fearonLaitin.xml"; // This is Fearon Laitin
//metadataurl="data/PUMS5small-ddi.xml"; // This is California PUMS subset
//metadataurl="data/BP.formatted-ddi.xml";
//metadataurl="data/FL_insurance_sample-ddi.xml";
//metadataurl="data/strezhnev_voeten_2013.xml"; // This is Strezhnev Voeten
//metadataurl="data/19.xml"; // Fearon from DVN Demo
//metadataurl="data/76.xml"; // Collier from DVN Demo
//metadataurl="data/79.xml"; // two vars from DVN Demo
//metadataurl="data/000.xml"; // one var in metadata
//metadataurl="data/0000.xml"; // zero vars in metadata
}
// Reading the pre-processed metadata:
// Pre-processed data:
var pURL = "";
if (dataurl) {
// data url is supplied
pURL = dataurl + "&format=prep";
} else {
// no dataurl/file id supplied; use one of the sample data files distributed with the
// app in the "data" directory:
//pURL = "data/preprocess2429360.txt"; // This is the Strezhnev Voeten JSON data
pURL = "data/fearonLaitin.json"; // This is the Fearon Laitin JSON data
//pURL = "data/fearonLaitinNewPreprocess3long.json"; // This is the revised (May 29, 2015) Fearon Laitin JSON data
/*
purltest = "users/" + username + "/fearonLaitinDatapreprocess.json"
//This is testing whether a newer json file exists or not. if yes, we will use that file, else use the default file
var test = UrlExists(purltest);
if (test == true) {
pURL = purltest;
console.log("test is true");
}
else
console.log("loading fearonLaitin.json");
pURL = "data/fearonLaitin.json";
*/
// console.log("yo value of test",test);
/*$.ajax({
url:purltest,
type:'HEAD',
error: function()
{
console.log("error");
pURL = "data/fearonLaitinPreprocess4.json";
//file not exists
},
success: function()
{
console.log("success");
pURL = purltest;
//file exists
}
});*/
function UrlExists(url) {
var http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
return http.status != 404;
}
//pURL = "data/fearonLaitinPreprocess4.json";
//console.log(purltest);
// console.log(pURL);
//pURL = "data/preprocessPUMS5small.json"; // This is California PUMS subset
//pURL = "data/FL_insurance_sample.tab.json";
// pURL = "data/qog_pp.json"; // This is Qual of Gov
}
var preprocess = {};
var mods = new Object;
console.log("Value of username: ", username);
//This function finds whether a key is present in the json file, and sends the key's value if present.
function findValue(json, key) {
if (key in json) return json[key];
else {
var otherValue;
for (var otherKey in json) {
if (json[otherKey] && json[otherKey].constructor === Object) {
otherValue = findValue(json[otherKey], key);
if (otherValue !== undefined) return otherValue;
}
}
}
}
//KRIPANSHU BHARGAVA : disconnect all the nodes
function disconnectAll() {
console.log("DisConnect function called");
/*
// removing the existing paths
d3.selectAll('path').style('marker-start', 0)
.style('marker-end', 0)
.style('stroke-width',0);
links=[];//to empty the links
*/
//setting all the links to invisible
path = path.data(links);
// update existing links
// VJD: dashed links between pebbles are "selected". this is disabled for now
path.classed('selected', function (d) {
// console.log("pebbles are selected : ",d);
return;
})//return d === selected_link; })
.style('marker-start', 0)
.style('marker-end', 0)
.style('stroke-width', 0);
// add new links
path.enter().append('svg:path')
.attr('class', 'link')
.style('stroke-width', 0)
.classed('selected', function (d) {
return;
})//return d === selected_link; })
.style('marker-start', 0)
.style('marker-end', 0)
.on('mousedown', function (d) { // do we ever need to select a link? make it delete..
var obj1 = JSON.stringify(d);
for (var j = 0; j < links.length; j++) {
if (obj1 === JSON.stringify(links[j])) {
links.splice(j, 1);
}
}
})
.on('mouseover', function (d) {
// if(!mousedown_node || d === mousedown_node) return;
d3.select(this)
.style('stroke', 'red')
.style("cursor", "not-allowed")
// Un-sets the "explicit" fill (might need to be null instead of '')
.classed("active", true);
/* div.transition()
.duration(200)
.style("opacity", .9);
div .html("<span style='background-color: #d9534f ; padding:2px ; font-style: oblique' >Delete this link</span>")
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
//d3.select('#start-circle').style('fill','red');
*/
// console.log("color is red")
})
.on('mouseout', function (d) {
// if(!mousedown_node || d === mousedown_node) return;
// unenlarge target node
//tooltip.style("visibility", "hidden");
// d3.select(this).attr('transform', '');
d3.select(this)
.style('stroke', '#000')
.style("cursor", "pointer")
// Un-sets the "explicit" fill (might need to be null instead of '')
.classed("active", false);
// div.transition()
// .duration(500)
// .style("opacity", 0);
// console.log("color was red")
});
//removing all the links
links = [];
}
//KRIPANSHU BHARGAVA : connect all the nodes
function connectAll() {
console.log("Connect All function called");
var connect_nodes = nodes.slice();
for (var i = 0; i < connect_nodes.length; i++) {
console.log("All connect nodes: " + connect_nodes[i].name);
}
var string_check = [];
//function to check the duplicate node
function nodesCheck(value1, value2) {
var pair1 = value1 + value2;
var pair2 = value2 + value1;
var count = 0;
// console.log("pair1 : " + pair1);
// console.log("pair2 : " + pair2);
for (var k = 0; k < string_check.length; k++) {
if (string_check[k] == pair1) {
count++;
}
if (string_check[k] == pair2) {
count++;
}
}
if (count == 2) {
return false;
}
else {
return true;
}
}
links = [];
// loops to add the all possible nodes to the links array
for (var i = 0; i < nodes.length; i++) {
for (var j = nodes.length - 1; j > 0; j--) {
string_check.push(i.toString() + j.toString());
var val1 = i.toString();
var val2 = j.toString();
if (nodesCheck(val1, val2) && i != j) {
// console.log("PAssed value : " + i.toString() + j.toString());
links.push({source: nodes[i], target: nodes[j], left: false, right: true});
}
}
}
path = path.data(links);
// update existing links
// VJD: dashed links between pebbles are "selected". this is disabled for now
path.classed('selected', function (d) {
// console.log("pebbles are selected1: ", d);
return;
})//return d === selected_link; })
.style('marker-start', function (d) {
return d ? 'url(#start-circle)' : '';
})
.style('marker-end', function (d) {
return d ? 'url(#end-circle)' : '';
})
.style('stroke-width', 2.5);
// add new links
path.enter().append('svg:path')
.attr('class', 'link')
.style('stroke-width', 2.5)
.classed('selected', function (d) {
return;
})//return d === selected_link; })
.style('marker-start', function (d) {
return d ? 'url(#start-circle)' : '';
})
.style('marker-end', function (d) {
return d ? 'url(#end-circle)' : '';
})
.on('mousedown', function (d) { // do we ever need to select a link? make it delete..
var obj1 = JSON.stringify(d);
for (var j = 0; j < links.length; j++) {
if (obj1 === JSON.stringify(links[j])) {
links.splice(j, 1);
}
}
})
.on('mouseover', function (d) {
// if(!mousedown_node || d === mousedown_node) return;
d3.select(this)
.style('stroke', 'red')
.style("cursor", "not-allowed")
// Un-sets the "explicit" fill (might need to be null instead of '')
.classed("active", true);
/* div.transition()
.duration(200)
.style("opacity", .9);
div .html("<span style='background-color: #d9534f ; padding:2px ; font-style: oblique' >Delete this link</span>")
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
//d3.select('#start-circle').style('fill','red');
*/
// console.log("color is red")
})
.on('mouseout', function (d) {
// if(!mousedown_node || d === mousedown_node) return;
// unenlarge target node
//tooltip.style("visibility", "hidden");
// d3.select(this).attr('transform', '');
d3.select(this)
.style('stroke', '#000')
.style("cursor", "pointer")
// Un-sets the "explicit" fill (might need to be null instead of '')
.classed("active", false);
// div.transition()
// .duration(500)
// .style("opacity", 0);
// console.log("color was red")
});
}
// this is the function and callback routine that loads all external data: metadata (DVN's ddi), preprocessed (for plotting distributions), and zeligmodels (produced by Zelig) and initiates the data download to the server
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
readPreprocess(url = pURL, p = preprocess, v = null, callback = function () {
//console.log(UrlExists(metadataurl));
//if(UrlExists(metadataurl)){
//d3.xml(metadataurl, "application/xml", function(xml) {
// d3.json(url, function(error, json) {
d3.json(url, function (json) {
var jsondata = json;
// console.log(jsondata);
//console.log("Findvalue: ",findValue(jsondata,"fileName"));
// var vars = xml.documentElement.getElementsByTagName("var");
var vars = jsondata.variables;
//console.log("value of vars");
// console.log(vars);
// var temp = xml.documentElement.getElementsByTagName("fileName");
var temp = findValue(jsondata, "fileName");
// console.log("value of temp");
// console.log(temp);
//
zparams.zdata = temp;//[0].childNodes[0].nodeValue;
// console.log("value of zdata: ",zparams.zdata);
// function to clean the citation so that the POST is valid json
function cleanstring(s) {
s = s.replace(/\&/g, "and");
s = s.replace(/\;/g, ",");
s = s.replace(/\%/g, "-");
return s;
}
// var cite = xml.documentElement.getElementsByTagName("biblCit");
// var cite = findValue(jsondata, "biblCit");
// zparams.zdatacite = cite;//[0].childNodes[0].nodeValue;
// console.log("value of zdatacite: ",zparams.zdatacite);
if (zparams.zdatacite !== undefined) {
zparams.zdatacite = cleanstring(zparams.zdatacite);
}
//console.log("value of zdatacite: ",zparams.zdatacite);
//
// dataset name trimmed to 12 chars
var dataname = zparams.zdata.replace(/\.(.*)/, ""); // regular expression to drop any file extension
// Put dataset name, from meta-data, into top panel
d3.select("#dataName")
.html(dataname);
// $('#cite div.panel-body').text(zparams.zdatacite);
// Put dataset name, from meta-data, into page title
d3.select("title").html("TwoRavens " + dataname)
//d3.select("#title").html("blah");
// temporary values for hold that correspond to histogram bins
hold = [.6, .2, .9, .8, .1, .3, .4];
var myvalues = [0, 0, 0, 0, 0];
//console.log("length: ",vars.length);
// console.log(vars);
//var tmp=vars.ccode;
//console.log("tmp= ",tmp);
var i = 0;
for (var key in vars) {
// console.log(vars[key]);
//p[key] = jsondata["variables"][key];
valueKey[i] = key;
if (vars[key].labl.length === 0) {
lablArray[i] = "no label";
}
else {
lablArray[i] = vars[key].labl;
}
i++;
}
//console.log("test=",ccode.labl.);
//console.log("lablArray=",lablArray);
for (i = 0; i < valueKey.length; i++) {
//valueKey[i] = vars[i].attributes.name.nodeValue;
//if(vars[i].getElementsByTagName("labl").length === 0) {lablArray[i]="no label";}
//else {lablArray[i] = vars[i].getElementsByTagName("labl")[0].childNodes[0].nodeValue;}
var datasetcount = d3.layout.histogram()
.bins(barnumber).frequency(false)
(myvalues);
// this creates an object to be pushed to allNodes. this contains all the preprocessed data we have for the variable, as well as UI data pertinent to that variable, such as setx values (if the user has selected them) and pebble coordinates
var obj1 = {
id: i,
reflexive: false,
"name": valueKey[i],
"labl": lablArray[i],
data: [5, 15, 20, 0, 5, 15, 20],
count: hold,
"nodeCol": colors(i),
"baseCol": colors(i),
"strokeColor": selVarColor,
"strokeWidth": "1",
"subsetplot": false,
"subsetrange": ["", ""],
"setxplot": false,
"setxvals": ["", ""],
"grayout": false
};
jQuery.extend(true, obj1, preprocess[valueKey[i]]);
allNodesColors(obj1);
// console.log(vars[i].childNodes[4].attributes.type.ownerElement.firstChild.data);
allNodes.push(obj1);
}
;
//console.log("allNodes: ", allNodes);
// Reading the zelig models and populating the model list in the right panel.
d3.json("data/explore.json", function (error, json) {
if (error) return console.warn(error);
var jsondata = json;
console.log("explore DATA json: ", jsondata);
for (var key in jsondata.explore) {
if (jsondata.explore.hasOwnProperty(key)) {
mods[jsondata.explore[key].name[0]] = jsondata.explore[key].description[0];
}
}
d3.json("data/zelig5choicemodels.json", function (error, json) {
if (error) return console.warn(error);
var jsondata = json;
//console.log("zelig choice models json: ", jsondata);
for (var key in jsondata.zelig5choicemodels) {
if (jsondata.zelig5choicemodels.hasOwnProperty(key)) {
mods[jsondata.zelig5choicemodels[key].name[0]] = jsondata.zelig5choicemodels[key].description[0];
}
}
scaffolding(callback = layout);
dataDownload();
});
});
});
});
//Kripanshu Bhargava plot for cross tab
function crossTabPlots(PlotNameA, PlotNameB,json_obj) {
var mydiv = "#plotA";
var mydiv1 = "#plotB";
var mydiv2 = "#SelectionData";
var count_c=0;
var count_b=0;
var plotA_size,plotB_size,plotA_sizem,plotB_sizem;
//d3.select("#resultsView_tabular").html("");
console.log("break json object:",json_obj);
// document.getElementById('plotA').style.display = "block";
//document.getElementById('plotB').style.display = "block";
$("#input1").attr("placeholder", PlotNameA).blur();
$("#input2").attr("placeholder", PlotNameB).blur();
var plot_nodes = nodes.slice();
/* for(var i=0;i<plot_nodes.length;i++) {
console.log("plot values yo:"+plot_nodes[i].plotvalues.length)
for(var j=0; j<plot_nodes[i].plotvalues.length;j++)
{
console.log("plot values : " + plot_nodes[i].plotvalues[j]);
}
}
*/
for (var i = 0; i < plot_nodes.length; i++) {
if (plot_nodes[i].name === PlotNameA) {
if (plot_nodes[i].plottype === "continuous") {
count_c++;
}
else if (plot_nodes[i].plottype === "bar") {
count_b++;
}
} else if (plot_nodes[i].name === PlotNameB) {
if (plot_nodes[i].plottype === "continuous") {
count_c++;
}
else if (plot_nodes[i].plottype === "bar") {
count_b++;
}
}
}
d3.select("#input1").on("mouseover", function() {
//console.log("mouseover function called");
d3.select("#tooltipPlotA")
.style("visibility", "visible")
.style("opacity","1")
.text(PlotNameA);
})
.on("mouseout",function(){
d3.select("#tooltipPlotA")
.style("visibility", "hidden")
.style("opacity","0")
})
;
d3.select("#input2").on("mouseover", function() {
// console.log("mouseover function called B");
d3.select("#tooltipPlotB")
.style("visibility", "visible")
.style("opacity","1")
.text(PlotNameB);
})
.on("mouseout",function(){
d3.select("#tooltipPlotB")
.style("visibility", "hidden")
.style("opacity","0")
})
;
if(count_c===2)
{
document.getElementById("plotA").style.width = "100%";
document.getElementById("plotB").style.width = "0";
}else if (count_b===2)
{
document.getElementById("plotB").style.width = "100%";
document.getElementById("plotA").style.width = "0";
}else if(count_b===1 && count_c===1)
{
document.getElementById("plotB").style.width = "50%";
document.getElementById("plotA").style.width = "50";
}
var margin_cross = {top: 30, right: 35, bottom: 40, left: 40},
width_cross = 300 - margin_cross.left - margin_cross.right,
height_cross = 160 - margin_cross.top - margin_cross.bottom;
var padding_cross = 100;
for (var i = 0; i < plot_nodes.length; i++) {
if (plot_nodes[i].name === PlotNameA) {
if (plot_nodes[i].plottype === "continuous") {
density_cross(plot_nodes[i]);
}
else if (plot_nodes[i].plottype === "bar") {
bar_cross(plot_nodes[i]);
}
} else if (plot_nodes[i].name === PlotNameB) {
if (plot_nodes[i].plottype === "continuous") {
density_cross(plot_nodes[i]);
}
else if (plot_nodes[i].plottype === "bar") {
bar_cross(plot_nodes[i]);
}
}
}
/*
d3.select(mydiv2).append("g")
.attr("id", "btnDiv")
.style('font-size', '75%')
.style("width", "280px")
.style("position","relative")
.style("left", "120px")
.style("top", "0px");
d3.select("#btnDiv")[0][0].innerHTML =[
'<h5>Data Selection</h5>',
'<p>Enter the numbers for both plots respectively to specify the distribution of the cross-tabs.</p>',
'<p id="boldstuff" style="color: #2a6496">Select between Equidistant and Equimass.</p>'
].join('\n')
d3.select("#btnDiv")
.append("input")
.attr({
"id": "a",
"placeholder": PlotNameA,
"size": 20
})
// style both of the inputs at once
// more on HTML5 <input> at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
d3.selectAll("input")
.attr({
"type": "text",
"size": 3,
"autofocus": "true",
"inputmode": "numeric"
})
.style({
"text-align": "center",
"display": "inline-block",
"margin-right": "10px"
});
var btns = d3.select("#btnDiv").selectAll("button").data(["EQUIDISTANCE", "EQUIMASS"])
btns = btns.enter().append("button").style("display", "inline-block")
// fill the buttons with the year from the data assigned to them
btns.each(function (d) {
this.innerText = d;
});
btns.on("click", getData);
d3.select(mydiv2).append("g")
.attr("id", "btnDiv1")
.style('font-size', '75%')
.style("width", "280px")
.style("position","relative")
.style("left", "-102px")
.style("top", "40px")
d3.select("#btnDiv1")
.append("input")
.attr({
"id": "b",
"placeholder": PlotNameB,
"size": 20
})
// style both of the inputs at once
// more on HTML5 <input> at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
d3.selectAll("input")
.attr({
"type": "text",
"size": 3,
"autofocus": "true",
"inputmode": "numeric"
})
.style({
"text-align": "center",
"display": "inline-block",
"margin-right": "10px"
});
var btns1 = d3.select("#btnDiv1").selectAll("button").data(["EQUIDISTANCE", "EQUIMASS"])
btns1 = btns1.enter().append("button").style("display", "inline-block")
// fill the buttons with the year from the data assigned to them
btns1.each(function (d) {
this.innerText = d;
});
btns1.on("click", getData1);
var varn1,varn2 , varsize1,varsize2;
function getData() {
if (this.innerText === "EQUIDISTANCE")
{
varn1="equidistance";
plotA_size= parseInt(d3.select("input#a")[0][0].value);
varsize1=plotA_size;
equidistance(PlotNameA,plotA_size);
}
else if (this.innerText === "EQUIMASS") {
plotA_sizem= parseInt(d3.select("input#a")[0][0].value);
varsize1=plotA_sizem
equimass(PlotNameA,plotA_sizem);
varn1="equimass";
}
}
function getData1() {
if (this.innerText === "EQUIDISTANCE")
{
varn2="equidistance";
plotB_size= parseInt(d3.select("input#b")[0][0].value);
equidistance(PlotNameB,plotB_size);
varsize2=plotB_size;
}
else if (this.innerText === "EQUIMASS") {
varn2="equimass";
plotB_sizem= parseInt(d3.select("input#b")[0][0].value);
equimass(PlotNameB,plotB_sizem);
varsize2=plotB_sizem;
}
}
*/
var varn1,varn2 , varsize1,varsize2;
//console.log("json_obj undefined");
$("#Equidistance1").click(function () {