-
Notifications
You must be signed in to change notification settings - Fork 1
/
subjarr.js
139 lines (107 loc) · 14.1 KB
/
subjarr.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
var datafg=[
[{'letter':'AE','frequency':0.52},{'letter':'AG','frequency':0.54},{'letter':'AR','frequency':0.57},{'letter':'BT','frequency':0.57},{'letter':'CE','frequency':0.59},{'letter':'CH','frequency':0.62},{'letter':'CSE','frequency':0.64},{'letter':'ECE','frequency':0.68},{'letter':'EE','frequency':0.53},{'letter':'GG','frequency':0.56},{'letter':'HS','frequency':0.61},{'letter':'IM','frequency':0.62},{'letter':'MA','frequency':0.53},{'letter':'ME','frequency':0.59},{'letter':'MI','frequency':0.5},{'letter':'MT','frequency':0.54},{'letter':'NA','frequency':0.51},{'letter':'PH','frequency':0.57}],
[{'letter':'AE','frequency':0.57},{'letter':'AG','frequency':0.53},{'letter':'AR','frequency':0.56},{'letter':'BT','frequency':0.63},{'letter':'CE','frequency':0.54},{'letter':'CH','frequency':0.54},{'letter':'CSE','frequency':0.55},{'letter':'ECE','frequency':0.63},{'letter':'EE','frequency':0.57},{'letter':'GG','frequency':0.62},{'letter':'HS','frequency':0.56},{'letter':'IM','frequency':0.59},{'letter':'MA','frequency':0.55},{'letter':'ME','frequency':0.53},{'letter':'MI','frequency':0.47},{'letter':'MT','frequency':0.55},{'letter':'NA','frequency':0.52},{'letter':'PH','frequency':0.57}],
[{'letter':'AE','frequency':0.63},{'letter':'AG','frequency':0.66},{'letter':'AR','frequency':0.64},{'letter':'BT','frequency':0.73},{'letter':'CE','frequency':0.67},{'letter':'CH','frequency':0.65},{'letter':'CSE','frequency':0.61},{'letter':'ECE','frequency':0.7},{'letter':'EE','frequency':0.65},{'letter':'GG','frequency':0.68},{'letter':'HS','frequency':0.71},{'letter':'IM','frequency':0.63},{'letter':'MA','frequency':0.63},{'letter':'ME','frequency':0.66},{'letter':'MI','frequency':0.54},{'letter':'MT','frequency':0.6},{'letter':'NA','frequency':0.58},{'letter':'PH','frequency':0.66}],
[{'letter':'AE','frequency':0.67},{'letter':'AG','frequency':0.6},{'letter':'AR','frequency':0.62},{'letter':'BT','frequency':0.59},{'letter':'CE','frequency':0.6},{'letter':'CH','frequency':0.63},{'letter':'CSE','frequency':0.58},{'letter':'ECE','frequency':0.71},{'letter':'EE','frequency':0.62},{'letter':'GG','frequency':0.7},{'letter':'HS','frequency':0.68},{'letter':'IM','frequency':0.55},{'letter':'MA','frequency':0.62},{'letter':'ME','frequency':0.63},{'letter':'MI','frequency':0.5},{'letter':'MT','frequency':0.6},{'letter':'NA','frequency':0.51},{'letter':'PH','frequency':0.6}],
[{'letter':'AE','frequency':0.56},{'letter':'AG','frequency':0.53},{'letter':'AR','frequency':0.69},{'letter':'BT','frequency':0.63},{'letter':'CE','frequency':0.56},{'letter':'CH','frequency':0.67},{'letter':'CSE','frequency':0.78},{'letter':'ECE','frequency':0.67},{'letter':'EE','frequency':0.53},{'letter':'GG','frequency':0.6},{'letter':'HS','frequency':0.73},{'letter':'IM','frequency':0.59},{'letter':'MA','frequency':0.69},{'letter':'ME','frequency':0.64},{'letter':'MI','frequency':0.45},{'letter':'MT','frequency':0.56},{'letter':'NA','frequency':0.45},{'letter':'PH','frequency':0.71}],
[{'letter':'AE','frequency':0.71},{'letter':'AG','frequency':0.74},{'letter':'AR','frequency':0.71},{'letter':'BT','frequency':0.67},{'letter':'CE','frequency':0.69},{'letter':'CH','frequency':0.78},{'letter':'CSE','frequency':0.71},{'letter':'ECE','frequency':0.73},{'letter':'EE','frequency':0.74},{'letter':'GG','frequency':0.76},{'letter':'HS','frequency':0.79},{'letter':'IM','frequency':0.7},{'letter':'MA','frequency':0.7},{'letter':'ME','frequency':0.73},{'letter':'MI','frequency':0.66},{'letter':'MT','frequency':0.58},{'letter':'NA','frequency':0.62},{'letter':'PH','frequency':0.69}],
[{'letter':'AE','frequency':0.71},{'letter':'AG','frequency':0.82},{'letter':'AR','frequency':0.81},{'letter':'BT','frequency':0.79},{'letter':'CE','frequency':0.76},{'letter':'CH','frequency':0.79},{'letter':'CSE','frequency':0.77},{'letter':'ECE','frequency':0.78},{'letter':'EE','frequency':0.78},{'letter':'GG','frequency':0.73},{'letter':'HS','frequency':0.81},{'letter':'IM','frequency':0.77},{'letter':'MA','frequency':0.79},{'letter':'ME','frequency':0.78},{'letter':'MI','frequency':0.7},{'letter':'MT','frequency':0.7},{'letter':'NA','frequency':0.73},{'letter':'PH','frequency':0.72}]
];
var payf=[[{'letter':'AE','frequency':0.103448275862069},{'letter':'AG','frequency':0.32},{'letter':'AR','frequency':0.14},{'letter':'BT','frequency':0.2},{'letter':'CE','frequency':0.186046511627907},{'letter':'CH','frequency':0.159090909090909},{'letter':'CSE','frequency':0.1375},{'letter':'ECE','frequency':0.16},{'letter':'EE','frequency':0.152542372881356},{'letter':'GG','frequency':0.173913043478261},{'letter':'HS','frequency':0.1875},{'letter':'IM','frequency':0.172413793103448},{'letter':'MA','frequency':0.133333333333333},{'letter':'ME','frequency':0.108695652173913},{'letter':'MI','frequency':0.0625},{'letter':'MT','frequency':0.153846153846154},{'letter':'NA','frequency':0.2},{'letter':'PH','frequency':0.538461538461538}],[{'letter':'AE','frequency':0},{'letter':'AG','frequency':0},{'letter':'AR','frequency':0.06},{'letter':'BT','frequency':0.0666666666666667},{'letter':'CE','frequency':0},{'letter':'CH','frequency':0},{'letter':'CSE','frequency':0},{'letter':'ECE','frequency':0.04},{'letter':'EE','frequency':0.0169491525423729},{'letter':'GG','frequency':0},{'letter':'HS','frequency':0},{'letter':'IM','frequency':0.0344827586206897},{'letter':'MA','frequency':0},{'letter':'ME','frequency':0.0108695652173913},{'letter':'MI','frequency':0.03125},{'letter':'MT','frequency':0.0769230769230769},{'letter':'NA','frequency':0.0666666666666667},{'letter':'PH','frequency':0.0384615384615385}],[{'letter':'AE','frequency':0.0344827586206897},{'letter':'AG','frequency':0.04},{'letter':'AR','frequency':0.08},{'letter':'BT','frequency':0},{'letter':'CE','frequency':0.0465116279069767},{'letter':'CH','frequency':0.0681818181818182},{'letter':'CSE','frequency':0.0375},{'letter':'ECE','frequency':0.02},{'letter':'EE','frequency':0.0847457627118644},{'letter':'GG','frequency':0.0434782608695652},{'letter':'HS','frequency':0},{'letter':'IM','frequency':0.0689655172413793},{'letter':'MA','frequency':0.0666666666666667},{'letter':'ME','frequency':0.0543478260869565},{'letter':'MI','frequency':0.03125},{'letter':'MT','frequency':0.0769230769230769},{'letter':'NA','frequency':0.0666666666666667},{'letter':'PH','frequency':0.0769230769230769}],[{'letter':'AE','frequency':0.275862068965517},{'letter':'AG','frequency':0.16},{'letter':'AR','frequency':0.18},{'letter':'BT','frequency':0.0666666666666667},{'letter':'CE','frequency':0.116279069767442},{'letter':'CH','frequency':0.113636363636364},{'letter':'CSE','frequency':0.0375},{'letter':'ECE','frequency':0.04},{'letter':'EE','frequency':0.135593220338983},{'letter':'GG','frequency':0.217391304347826},{'letter':'HS','frequency':0},{'letter':'IM','frequency':0.103448275862069},{'letter':'MA','frequency':0.0333333333333333},{'letter':'ME','frequency':0.108695652173913},{'letter':'MI','frequency':0.15625},{'letter':'MT','frequency':0.0769230769230769},{'letter':'NA','frequency':0.166666666666667},{'letter':'PH','frequency':0.0769230769230769}],[{'letter':'AE','frequency':0.413793103448276},{'letter':'AG','frequency':0.24},{'letter':'AR','frequency':0.24},{'letter':'BT','frequency':0.4},{'letter':'CE','frequency':0.348837209302326},{'letter':'CH','frequency':0.25},{'letter':'CSE','frequency':0.0625},{'letter':'ECE','frequency':0.24},{'letter':'EE','frequency':0.23728813559322},{'letter':'GG','frequency':0.304347826086957},{'letter':'HS','frequency':0.125},{'letter':'IM','frequency':0.310344827586207},{'letter':'MA','frequency':0.3},{'letter':'ME','frequency':0.315217391304348},{'letter':'MI','frequency':0.46875},{'letter':'MT','frequency':0.384615384615385},{'letter':'NA','frequency':0.233333333333333},{'letter':'PH','frequency':0.153846153846154}],[{'letter':'AE','frequency':0.103448275862069},{'letter':'AG','frequency':0.2},{'letter':'AR','frequency':0.18},{'letter':'BT','frequency':0.2},{'letter':'CE','frequency':0.116279069767442},{'letter':'CH','frequency':0.318181818181818},{'letter':'CSE','frequency':0.2375},{'letter':'ECE','frequency':0.28},{'letter':'EE','frequency':0.203389830508475},{'letter':'GG','frequency':0.173913043478261},{'letter':'HS','frequency':0.3125},{'letter':'IM','frequency':0.172413793103448},{'letter':'MA','frequency':0.233333333333333},{'letter':'ME','frequency':0.195652173913043},{'letter':'MI','frequency':0.21875},{'letter':'MT','frequency':0.115384615384615},{'letter':'NA','frequency':0.133333333333333},{'letter':'PH','frequency':0.0384615384615385}],[{'letter':'AE','frequency':0},{'letter':'AG','frequency':0.04},{'letter':'AR','frequency':0.06},{'letter':'BT','frequency':0},{'letter':'CE','frequency':0.116279069767442},{'letter':'CH','frequency':0.0681818181818182},{'letter':'CSE','frequency':0.3375},{'letter':'ECE','frequency':0.18},{'letter':'EE','frequency':0.135593220338983},{'letter':'GG','frequency':0.0434782608695652},{'letter':'HS','frequency':0.3125},{'letter':'IM','frequency':0.137931034482759},{'letter':'MA','frequency':0.2},{'letter':'ME','frequency':0.152173913043478},{'letter':'MI','frequency':0.03125},{'letter':'MT','frequency':0.0769230769230769},{'letter':'NA','frequency':0.133333333333333},{'letter':'PH','frequency':0.0384615384615385}],[{'letter':'AE','frequency':0.0689655172413793},{'letter':'AG','frequency':0},{'letter':'AR','frequency':0.06},{'letter':'BT','frequency':0.0666666666666667},{'letter':'CE','frequency':0.0697674418604651},{'letter':'CH','frequency':0.0227272727272727},{'letter':'CSE','frequency':0.15},{'letter':'ECE','frequency':0},{'letter':'EE','frequency':0.04},{'letter':'GG','frequency':0.0338983050847458},{'letter':'HS','frequency':0.0434782608695652},{'letter':'IM','frequency':0.0625},{'letter':'MA','frequency':0},{'letter':'ME','frequency':0.0333333333333333},{'letter':'MI','frequency':0.0543478260869565},{'letter':'MT','frequency':0},{'letter':'NA','frequency':0.0384615384615385},{'letter':'PH','frequency':0}]];
var payproshno=["Placements don't matter to me.","I am okay with a package below 6 lpa.","I need a package between 6 to 8 lpa to be happy.","I need a package between 8 to 10 lpa to be happy.","I want a package between 10 to 15 lpa to be happy.","I want a package between 15 to 20 lpa to be happy.","I want a package between 20 to 50 lpa to be happy.","I want a package above 50 lpa to be happy."]
var proshno=["How satisfied are you with your CGPA?","How satisfied are you with your Department?","How satisfied are you with IIT?","How satisfied are you with your Hall?",
"How satisfied are you with your Social Life?","How comfortable are you with your Body Image?","How satisfied are you with your Friend Circle?"];
var datea=[{'letter':'op','frequency':0.9}];
var foopay=[{'letter':'op','frequency':0.7}];
visualize(datafg,"div.dephpindtxt",proshno,"div.dephpar","button.depsort","button.depnxt",datea,"dso","Happiness Index");
visualize(payf,"div.paydeptxt",payproshno,"div.paydeparea","button.paydepsrt","button.paydepnxt",foopay,"dsog","Percentage of Students");
function visualize(dataf,tgttxt,qstnarray,tgtdiv,btnsrt,btnnxt,pseudodata,btnid,labee){
var data=dataf[0];
var sortcoun=0;
var counter=0;
d3.select(tgttxt).text(qstnarray[0]);
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 350 - margin.top - margin.bottom;
var formatPercent = d3.format(".0%");
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .1, 1);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.tickFormat(formatPercent);
var svgd1 = d3.select(tgtdiv).append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
data.forEach(function(d) {
d.frequency = +d.frequency;
});
x.domain(data.map(function(d) { return d.letter; }));
y.domain([0, d3.max(pseudodata, function(d) { return d.frequency; })]);
svgd1.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svgd1.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text(labee);
svgd1.selectAll(".barf")
.data(data)
.enter().append("rect")
.attr("class", "barf")
.attr("x", function(d) { return x(d.letter); })
.attr("width", x.rangeBand())
.attr("y", function(d) { return y(d.frequency); })
.attr("height", function(d) { return height - y(d.frequency); });
d3.select(btnsrt)
.on("click", function() {
sortcoun++;
var btnval=sortcoun%2==1?"Unsort":"Sort";
document.getElementById("dso").innerHTML=btnval;
// Copy-on-write since tweens are evaluated after a delay.
var x0 = x.domain(data.sort(sortcoun%2==1
? function(a, b) { return b.frequency - a.frequency; }
: function(a, b) { return d3.ascending(a.letter, b.letter); })
.map(function(d) { return d.letter; }))
.copy();
svgd1.selectAll(".barf")
.sort(function(a, b) { return x0(a.letter) - x0(b.letter); });
var transition = svgd1.transition().duration(750),
delay = function(d, i) { return i * 50; };
transition.selectAll(".barf")
.delay(delay)
.attr("x", function(d) { return x0(d.letter); });
transition.select(".x.axis")
.call(xAxis)
.selectAll("g")
.delay(delay);
});
d3.select(btnnxt)
.on("click", function() {
counter++;
sortcoun=0;
d3.select(tgttxt).text(qstnarray[counter%(dataf.length)]);
document.getElementById("dso").innerHTML="Sort";
data=dataf[counter%dataf.length];
svgd1.selectAll(".barf")
.data(data)
.transition()
.attr("x", function(d) { return x(d.letter); })
.attr("width", x.rangeBand())
.attr("y", function(d) { return y(d.frequency); })
.attr("height", function(d) { return height - y(d.frequency); });
});
};