-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContentView.js
309 lines (279 loc) · 7.02 KB
/
ContentView.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
var ht = "590px";
var maxht = 300;
var wt = "160px";
var curDS = "DS1";
var curLabs = [];
var curLabsSheets = [];
var curSheets = 12;
var curExcel = "pattern";
var cnt=0;
var colorcode = {};
colorcode['front-page']='lightblue';
colorcode['business']='orange';
colorcode['on-air']='lightgreen';
colorcode['health']='pink';
colorcode['sports']='grey';
colorcode['misc']='red';
var pgCat = {};
pgCat['front-page']=["front-page"];
pgCat['business']=["business","tech"];
pgCat['on-air']=["on-air","local","news","weather"];
pgCat['health']=["health","living","travel"];
pgCat['sports']=["sports","msn-sports"];
pgCat['misc']=["opinion","misc","summary","bbs"];
pgCat['clothing']=["clothing","handbags"];
pgCat['movies']=["movies","games"];
pgCat['home&garden']=["home&garden","tools"];
pgCat['electronics']=["electronics","computers"];
colorcode['clothing']='orange';
colorcode['movies']='pink';
colorcode['home&garden']='lightgreen';
colorcode['electronics']='cyan';
function getValues(path,callback){
var vals=[];
var labs=[];
var fulls=[];
var clicks=[];
$.getJSON(path, function(json) {
for(i=0;i<json.length;i++){
vals.push(json[i].value);
labs.push(json[i].event);
fulls.push(json[i].full);
clicks.push(json[i].clicks);
}
callback([vals,labs,fulls,clicks]);
});
}
var cont = document.getElementById("icon");
cont.innerHTML = '<p><img src="users.jpg" onclick="fullPattern()" style="width:18px;height:20px; float:left;"></img> </p>';
getValues("DS1/context.json",function(v){
curLabs = v[1];
curLabsSheets = v[3];
updateCV("content",ht,wt,v[0],v[1],'-16px');
updatePV('pattern',curSheets);
});
function fullPattern(){
updatePV('pattern',curSheets);
}
function whichDS(){
choice=document.getElementById("ds").value;
if(choice==1){
curDS = "DS1";
curSheets = 12;
getValues("DS1/context.json",function(v){
curLabs = v[1];
curLabsSheets = v[3];
updateCV("content",ht,wt,v[0],v[1],'-16px');
updatePV('pattern',curSheets);
updatePageCategory();
document.getElementById("sequenc").innerHTML = "";
document.getElementById("bars").innerHTML = "";
});
}else{
curDS = "DS2";
curSheets = 15;
getValues("DS2/context.json",function(v){
curLabs = v[1];
curLabsSheets = v[3];
updateCV("content",ht,wt,v[0],v[1],'-16px');
updatePV('pattern',curSheets);
updatePageCategory();
document.getElementById("sequenc").innerHTML = "";
document.getElementById("bars").innerHTML = "";
});
}
}
function upd(det,fullPath,idName,full){
//console.log(fullPath);
getValues(fullPath,function(v){
var m = v[3].pop();
//console.log(m);
var lab = {};
for(i=0;i<v[1].length;i++){
var k = v[1][i].split(':')[0];
var key="";
for(ks in pgCat){
if(ks==k){
key=ks;
}
else{
for(var j=0; j<pgCat[ks].length;j++){
if(pgCat[ks][j]==k){
key=ks;
break;
}
}
}
}
if(!(key in lab)){
lab[key]=0;
}
lab[key] +=1;
}
//console.log(lab);
var values = [];
for(var i in lab){
values.push(lab[i]);
}
//console.log(lab);
var cc = "";
var max = Math.max.apply(null, values);
for(var i in lab){
if(lab[i] == max){
var cc="";
for(k in pgCat){
if(k==i){
cc = colorcode[k];
break;
}
else{
for(var j=0; j<pgCat[k].length;j++){
if(pgCat[k][j]==i){
cc=colorcode[k];
break;
}
}
}
}
break;
}
}
//console.log(cc);
det.innerHTML += '<div style="display: inline-block; height:620px;" id="'+idName+'\"> <p id="hd" style="color: '+cc+';"><img src="users.jpg" onclick="updateSeq()" onmouseover="fullEvent(this)" onmouseout="lessEvent(this)" class="'+idName+'" id="dicon"></img> - '+m+'</p></div>';
updateCV(idName,"550px",wt,v[0],v[1],'-16px');
});
}
function fullEvent(x){
var det = document.getElementById("dyn");
var fullPath = curDS+'/'+curExcel+'-'+(x.className.substr(-1)-1)+'.json';
var idName = x.className;
getValues(fullPath,function(v){
updateCV(idName,"550px",wt,v[0],v[2],'-26px');
});
}
function lessEvent(x){
//console.log("hello");
var det = document.getElementById("dyn");
var fullPath = curDS+'/'+curExcel+'-'+(x.className.substr(-1)-1)+'.json';
var idName = x.className;
getValues(fullPath,function(v){
updateCV(idName,"550px",wt,v[0],v[1],'-16px');
});
//console.log(idName);
}
function updatePV(sheetName,cnt){
var det = document.getElementById("dyn");
det.innerHTML="";
var fullPath = curDS+'/'+sheetName+'-'+0+'.json';
var idName = "dynamic"+1;
upd(det,fullPath,idName,0);
for(j=2;j<=cnt;j=j+1){
fullPath = curDS+'/'+sheetName+'-'+(j-1)+'.json';
idName = "dynamic"+j;
upd(det,fullPath,idName,0);
}
}
function updateCV(vid,ht,wt,vals,labs,pad){
var series = [];
for (i=0;i<vals.length;i++){
var x = labs[i].split(":")[0];
var cc="";
for(k in pgCat){
if(k==x){
cc = colorcode[k];
break;
}
else{
for(var j=0; j<pgCat[k].length;j++){
if(pgCat[k][j]==x){
cc=colorcode[k];
break;
}
}
}
}
var it={"values":[vals[i]],
"background-color": cc};
//console.log(labs[i].split("-"));
series[i] = it;
}
//console.log(series);
var myConfig = {
"type":"vfunnel", //or "vfunnel"
"scale-y": {
"placement": "opposite",
"labels": labs,
"item": {
"font-color": "black",
"font-family": "sans-serif",
"font-weight": "bold",
"padding": pad
},
"guide": {
"line-color": "none"
}},
"plot":{
"hover-state": {
"background-color": "white",
"border-color": "lightgray",
"border-width": 3,
"line-style": "solid"
}
},
"series":series
};
zingchart.render({
id : vid,
data : myConfig,
height: ht,
width: wt
});
zingchart.bind(null, 'node_click', function(e) {
if(e.id=="content"){
var fn = curLabs[e.plotindex].split(':')[0];
var fnd= "data/".concat(fn);
curExcel = fn;
var nsheets = curLabsSheets[e.plotindex];
//console.log(nsheets);
console.log(fn);
updatePV(fn,nsheets);
//sequence(fn.concat(".csv"));
//cnt=1;
if(cnt==0){
document.getElementById("sequenc").innerHTML = "";
document.getElementById("bars").innerHTML = "";
sequence(fnd.concat(".csv"));
bars(fnd.concat("_count.csv"));
cnt=1;
}
else{
//cnt=0;
}
}
else{
sheetno=1;
if(e.id.length==8){
sheetno=e.id[e.id.length-1];
}
else{
console.log("in else")
sheetno=e.id.slice(-2);
}
console.log(sheetno);
//bars();
var temp="";
var t2=temp.concat(curDS,"/pattern-",sheetno-1,".json");
console.log(t2);
var fns = "";
var fn = "health";
getValues(t2,function(v){
fns = v[1];
//console.log(fns);
fn = fns[e.plotindex].split(':')[0];
//console.log(fn.concat(".csv"));
alignSeq(fn);
});
}
});
cnt=0;
}