-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha6.html
700 lines (603 loc) · 20.1 KB
/
a6.html
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
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" href="./js/redmond/jquery-ui.css" rel="stylesheet" />
<link type="text/css" href="./css/jpivot-external.css" rel="stylesheet" />
<script language="javascript" type="text/javascript" src="./js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="./js/jquery-ui-1.8.custom.min.js"></script>
<script language="javascript" type="text/javascript" src="./js/jquery.tablehover.js"></script>
<script type="text/javascript" src="./jpivot5.js"></script>
<script type="text/javascript" >
var dynamic_style=[];
var debug=0;
$(document).ready
(function()
{
$("#dbg_level").slider({
value:0,
min: 0,
max: 3,
step: 1,
stop: function(event, ui) {
debug = ui.value;
}
});
debug = $("#dbg_level").slider("value");
$("#trsh_rnd").slider({
value:1,
min: 0.5,
max: 1,
step: 0.05,
slide:function(event,ui)
{
$('#trsh_txt').text(ui.value);
}
});
$(".vals_n").slider({
value:2,
min: 1,
max: 10,
step: 1,
stop:function(event, ui)
{
str='i,j,k,l,m=';
var vl=1;
$(".vals_n").each(
function(i)
{
var a = $(".vals_n").eq(i).slider("value")
vl *= a
str +='x'+a;
}
);
str += '='+vl;
$('#vals_comp').text(str);
}
});
create_data();
var pivots=$('#pv').jPivot
(data_local,{
rows:rows,cols:cols,data_col:data_col,data_headers:data_headers,aggregate:aggregate
,filter:filter
,totals_mask:totals_mask
//,styles:{Key:'class="ui-state-default"'}
,ExternalManage:true
,immediate_draw:false
,row_keys_placeholder:'qpv_row_keys_placeholder'
,col_keys_placeholder:'qpv_col_keys_placeholder'
,onAfterDraw:function(){AfterDraw()}
,onBeforeDraw:function(){
BeforeDraw()
}
,onBeforePrepare:function(){
BeforePrepare()
}
,aggregate_total_col:
{
aggregator:'SUM'
,data_col_cnt:data_col_cnt //for AVG
}
,aggregate_total_row:
{
aggregator:'SUM'
,data_col_cnt:data_col_cnt //for AVG
}
,aggregate_value:
{
aggregator:'SUM'
,precision:2
,data_col_cnt:data_col_cnt //for AVG
}
,getDataForExcel:function()
{
var tr=0; var td=0; var tmp; var cs;var rs;var cl;var bg;
$('#jpivot_placeholder tr').each(function (i)
{
pv_json[tr]=[];td=0;
$('td',this).each(function (i)
{
tmp = $(this);
cs=tmp.attr('colspan'); cs=(typeof cs === 'undefined') ? 1 : cs;
rs=tmp.attr('rowspan'); rs=(typeof rs === 'undefined') ? 1 : rs;
cl=tmp.attr('class'); cl=(typeof cl === 'undefined') ? '' : cl;
bg=tmp.css('background-color'); bg=(typeof bg === 'undefined') ? '' : bg;
pv_json[tr][td++]=[tmp.text(),cs,rs,cl,bg];
});
tr++;
});
$.postJSON(
'ajax.php?mode=export_excel'
,{pv_table:JSON.stringify(pv_json)}
)
}
,onPrintRowKey: function(key_index,total_index,val)
{
if (key_index < this.pivot_data.row_keys_length -1 )
{
return ['<a class="jpv_collapse jpv_tot_expanded" href="javascript:" onclick="collapse_row(this)">+</a>'+val, this.styles.Key+' row_key="'+key_index+'" totind="'+total_index+'"'];
}
else if (val == 'RSP')
{
return ['','class="pv_Key_rs"'];
}
else
{
//do not print collapse fror last key
return [val,this.styles.Key];
}
}
,onPrintTotalRowKey: function(key_index,val)
{
return ['<a class="jpv_collapse jpv_tot_expanded" href="javascript:" onclick="expand_row(this)">-</a><span>'+val+'</span>',this.styles.TotalRowKey];
}
,onPrintRowKeyHeader:function (key_index,val)
{
if (key_index < this.pivot_data.row_keys_length -1 )
{
return ['<a class="jpv_collapse jpv_tot_expanded" href="javascript:" onclick="row_exp_key(this)">+</a><span>'+val+'</span>',this.styles.KeyHeader+' row_key="'+key_index+'"'];
}
else
{
return[val,this.styles.KeyHeader];
}
}
,onPrintColKey: function(key_index,total_index,val)
{
if (key_index < this.pivot_data.col_keys_length -1 )
{
return ['<a class="jpv_collapse jpv_tot_expanded" href="javascript:" onclick="collapse_col(this)">+</a> '+val, this.styles.Key ];
}
else if (val == 'CSP')
{
return ['','class="pv_Key_cs"'];
}
else if (val == 'RSP')
{
return ['','class="pv_Key_rs"'];
}
else
{
//do not print collapse fror last key
return [val,this.styles.Key];
}
}
,onPrintTotalColKey: function(key_index,val)
{
return ['<a class="jpv_collapse jpv_tot_expanded" href="javascript:" onclick="expand_col(this)">-</a><span>'+val+'</span>',this.styles.TotalColKey];
}
,onPrintColKeyHeader:function (key_index,val)
{
if (key_index < this.pivot_data.col_keys_length -1 )
{
return ['<a class="jpv_collapse jpv_tot_expanded" href="javascript:" onclick="col_exp_key(this)">+</a> '+val,this.styles.KeyHeader];
}
else
{
return[val,this.styles.KeyHeader];
}
}
});
//redraw_pivot();
pv0=pivots[0];
$('#pv').jPivot('drawData');
//ready end
});
//*************************************************
//************ collapse functions *****************
//*************************************************
function create_col_dynamic_css(ind_td_rI,tr_start)
{
if (!$('#dyn_css').length) $('<style id="dyn_css"/>').appendTo('head');
var ns = " td.jpv_collapsed_col-"+tr_start+"-"+ind_td_rI+"{display:none;} ";
if ($.inArray(ns,dynamic_style) < 0)
{
dynamic_style.push(ns);
$('#dyn_css').text(dynamic_style.join("\n"));
}
return "jpv_collapsed_col-"+tr_start+"-"+ind_td_rI;
}
function create_row_dynamic_css(ind_td_rI)
{
if (!$('#dyn_css').length) $('<style id="dyn_css"/>').appendTo('head');
var ns = " td.jpv_collapsed_row"+ind_td_rI+"{display:none;} ";
if ($.inArray(ns,dynamic_style) < 0)
dynamic_style.push(ns);
$('#dyn_css').text(dynamic_style.join("\n"));
}
function collapse_col(ahref)
{
var ind_td = $(ahref).parent()[0];
var ind_tr = ind_td.parentNode; //get tr
var ind_td_rI = ind_td.realIndex; //real td index in row (not affected by collapse)
var ind_td_rcS = ind_td.cSpan;//real colSpan of td (not affected by collapse)
var start = $(ind_tr).children().index(ind_td); //index of td to show
var cspan= ind_td.colSpan;
var tr_set = $('#pv tr');
var tr_start = tr_set.index(ind_tr);
var hidden_class = create_col_dynamic_css(ind_td_rI,tr_start);
var total_col =$(ind_td).next()//total will be next td
tr_set.each(function (tr_ind) //for each row
{
$(this.cells).each(function() //get all td in row
{
//fix for collapse_all
if (tr_ind >= tr_start && this.realIndex >= ind_td_rI && this.realIndex <= ind_td_rI+ind_td_rcS-1 )
{ //these to hide
$(this).addClass(hidden_class)
}
if (tr_ind < tr_start && this.realIndex <= ind_td_rI && this.realIndex + this.cSpan >= ind_td_rI + ind_td_rcS)
{//tese to fix colspan
this.colSpan = this.colSpan-cspan > 0 ? this.colSpan-cspan : 1;
//var txt = $(this).text();$(this).text(txt+(this.colSpan-cspan > 0 ? '-'+cspan : '=1'));
}
}
);
}
)
;
$('a',total_col).removeClass('jpv_tot_expanded').addClass('jpv_tot_collapsed');
$('span',total_col).show();
}
function col_exp_key(ahref)
{ //collapse all keys in thes level
$('a.jpv_collapse',$(ahref).parent().siblings('.pv_Key:visible')).each(function(){collapse_col(this)})
}
function expand_col(ahref)
{
var ind_td = $(ahref).parent().prev()[0];
var ind_tr = ind_td.parentNode; //get tr
var ind_td_rI = ind_td.realIndex;
var ind_td_rcS = ind_td.cSpan;//real colSpan of td (not affected by collapse)
var start = $(ind_tr).children().index(ind_td); //index of td to show
var cspan= ind_td.colSpan;
var tr_set = $('#pv tr');
var tr_start = tr_set.index(ind_tr);
var hidden_class = create_col_dynamic_css(ind_td_rI,tr_start);
$(ind_td).removeClass(hidden_class);
tr_set.each(function (tr_ind) //for each row
{
$(this.cells).each(function() //get all td in row
{
if (tr_ind >= tr_start && this.realIndex >= ind_td_rI && this.realIndex <= ind_td_rI+ind_td_rcS-1 )
{ //these to hide
$(this).removeClass(hidden_class)
}
if (tr_ind < tr_start && this.realIndex <= ind_td_rI && this.realIndex + this.cSpan >= ind_td_rI + ind_td_rcS)
{//tese to fix colspan
this.colSpan += cspan;
//var txt = $(this).text();$(this).text(txt+(this.colSpan-cspan > 0 ? '-'+cspan : '=1'));
}
}
);
}
)
;
$(ahref).addClass('jpv_tot_expanded').removeClass('jpv_tot_collapsed');
$('span',ind_td).hide();
}
function row_exp_key(ahref)
{
}
function expand_row(ahref)
{
var ind_td = $(ahref).parent()[0];
var ind_td_rI = ind_td.realIndex;
var ind_tr = ind_td.parentNode; //get tr
var tr = $(ind_tr).prev()
var notfound=true;
while (notfound || !tr.length)
{
var cls = tr[0].cells;
for (var i=0; i < cls.length;i++)
{
if (cls[i].realIndex == ind_td_rI) {notfound = false;break;}
}
if (notfound) tr = tr.prev();
}
td = cls[i];
var span= td.rowSpan; //colaspn of clicked td
var tr_set = $('#pv tr');
var tr_start = tr_set.index(tr);
tr_set.slice(tr_start,tr_start+span).children().removeClass('jpv_collapsed_row'+ind_td_rI);
$(ahref).addClass('jpv_tot_expanded').removeClass('jpv_tot_collapsed');
$('span',ind_td).hide();
}
function collapse_row(ahref)
{
var ind_td = $(ahref).parent()[0];
var ind_td_rI = ind_td.realIndex;
create_row_dynamic_css(ind_td_rI);
var ind_tr = ind_td.parentNode; //get tr
var span= ind_td.rowSpan; //colaspn of clicked td
var tr_set = $('#pv tr').has('td.hoverrow');
var tr_start = tr_set.index(ind_tr); //index of clicked tr in tr_set
//set class for total key for expanding
var cells = tr_set.last().next().children().each(
function ()
{
if (this.realIndex == ind_td_rI)
$('a',this).removeClass('jpv_tot_expanded').addClass('jpv_tot_collapsed');
$('span',this).show();
}
)
//TODO see if no totals cols - collapse if had no visible td
// tr_set.slice(0,tr_start+1).each(
// function()
// {//hide row if all hidden
// $(this.cells).filter('.hoverrow').each(//all td left to clicked
// function()
// {
// if (this.realIndex < ind_td_rI && ! (this.rSpan=(this.rSpan - span > 0) ? this.rSpan - span : 0))
// $(this).addClass('jpv_collapsed_row');
// }
// )
// }
// )
tr_set.slice(tr_start).each( //all rows from clicked and below
function()
{
$(this.cells).each(
function()
{
if (this.realIndex >= ind_td_rI)
$(this).addClass('jpv_collapsed_row'+ind_td_rI);
}
)
}
);
}
var colors=[];
var use_custom_filter=0;var custom_filter_cmp=0;var custom_filter_val=0;
var tot_perc = null;
function BeforePrepare()
{
use_custom_filter = $('#use_custom_filter').is(':checked');
custom_filter_cmp = parseInt($('#custom_filter_cmp').val());
custom_filter_val = parseFloat($('#custom_filter_val').val());
}
function BeforeDraw()
{
//preapre colors
colors=[];
$('#colors input').each(function(i)
{
colors[i]=[parseFloat($(this).attr('level')),$(this).val()]
}
)
//save state
tot_perc = $('#totals_dropdown').val();
}
function AfterDraw()
{
//create totals dropdown
$('#totals_dropdown').empty();
//get cols and rows keys captions
var headers=pv0.opts.data_headers;
var l = pv0.opts.rows.length;
for (var i=0; i < l; i++)
$('#totals_dropdown').append('<option value="'+pv0.opts.rows[i]+'">'+headers[pv0.opts.rows[i]]+'</option>');
var l = pv0.opts.cols.length;
for (var i=0; i < l; i++)
$('#totals_dropdown').append('<option value="'+pv0.opts.cols[i]+'">'+headers[pv0.opts.cols[i]]+'</option>');
//restore state
$('#totals_dropdown').val(tot_perc);
/// create hover
$('#pv table').tableHover({
rowClass: 'hoverrow'
, colClass: 'hover'
//, clickClass: 'click'
, headRows: true
,footRows: true
, headCols: true
, footCols: true
,ignoreCols: [1,2,3]
});
}
function print_value_by_total($this,data_indexes)
{
var rclass = $this.styles.Value;
if (typeof data_indexes == 'undefined') return ['',rclass]; ;
var ret=0;
if (debug==1) ret='trv'
if (debug==2) ret='trv'+data_indexes.join(' +');
if (!debug)
{
ret = data_indexes[0];
}
if (data_indexes[1] > 0) ret=Math.round(100*(100*data_indexes[0]/data_indexes[1]))/100;
else ret=0;
return [ret,rclass];
}
function save_state()
{
serial=$('#pv').jPivot('saveGridParam');
console.dir(serial);
}
function restore()
{
$('#pv').jPivot('restoreGridParam',serial);//.jPivot('prepareData').jPivot('drawData')
}
function export_pivot()
{
pv0.getDataForExcel();
}
function prepare_pivot()
{
if ($('#use_percent_by_totals').is(':checked'))
{
$('#pv').jPivot('setGridParam',{
aggregate_value:{
aggregator:'PERC'
,totalBy:'GC'
,key:$('#totals_dropdown').val()
}
});
}
else
{
$('#pv').jPivot('setGridParam',{
aggregate_value:{aggregator:'SUM'}
})
}
$('#pv').jPivot('prepareData');
}
function re_create_data()
{
create_data();
$('#pv').jPivot(data_local,{});
//$('#pv').jPivot('setGridParam',{data:data_local});
}
function create_data()
{
//return;
var trsh = $("#trsh_rnd").slider("value");
data_local=[];
var snum=0;var cnt=0;
var il=$(".vals_n").eq(0).slider("value");
var jl = $(".vals_n").eq(1).slider("value");
var kl = $(".vals_n").eq(2).slider("value");
var ll = $(".vals_n").eq(3).slider("value");
var ml = $(".vals_n").eq(4).slider("value");
var nl = $(".vals_n").eq(5).slider("value");
for (var i=0; i < il; i++)
{
for (var j=0; j < jl; j++)
{
if (Math.random() > trsh) continue;
for (var k=0;k < kl; k++)
{
if (Math.random() > trsh) continue;
for (var l=0;l < ll ; l++)
{
if (Math.random() > trsh) continue;
for (var m=0;m < ml ; m++)
{
if (Math.random() > trsh) continue;
for (var n=0;n < nl; n++)
{
if (Math.random() > trsh) continue;
//data.push(['i'+i,'j'+j,'k'+k,'L'+l,'m'+m,'i'+i+'j'+j+'k'+k+'L'+l+'m'+m]) ;
data_local[cnt]=['I'+i,'J'+j,'K'+k,'L'+l,'Mдлинное длинное название'+m,'N'+n,snum++] ;
cnt++;
}
}
}
}
}
}
$('#vals_comp').text('created '+cnt+'rows');
}
var data_local=[];
var rows = [0,1,2];
var cols = [3,4,5];
var data_col=6;
var data_col_cnt=null;
var aggregate = [];
var filter = [];
var totals_mask = [1,1,1,1,1,1];
var data_headers=['capt_i','capt_j','capt_k','capt_l','capt_m','capt_n'] ;
</script>
<script type="text/javascript" src="./__data_small.js"></script>
<style>
td.jpv_collapsed_row{display:none;}
td.jpv_collapsed_col{display:none;}
a.jpv_collapse {text-decoration:none;border:1px solid black;}
a.jpv_collapse_process {background-color:yellow;}
a.jpv_tot_collapsed {background-color:red;display:inline;}
.pv_TotalColKey span,.pv_TotalRowKey span {display:none;}
.pv_TotalColKey a.jpv_tot_expanded,.pv_TotalRowKey a.jpv_tot_expanded {display:none;}
.pv_table td {
border-style:solid;
border-color:green;
border-width:1px 0 0 1px;
}
td.pv_TotalRowKey {
border-style:solid;
border-color:green;
border-width:0 0 1px 1px;
}
body *{font-size:12px;}
#chart2div, #resize_chart_1 { width: 800px; height: 400px;}
div#color_custom{display:block;}
div.controlset {display: block; float:left; width: 100%; padding: 0.25em 0;}
div.controlset label,
div.controlset input,
div.controlset div { display: inline; float: left; }
div.form-container div.controlset label { width: 100px;}
.partbl td{width:100px;vertical-align:top;}
td.click, th.click
{
background-color: #bbb;
}
td.hover, tr.hover
{
background-color: #69f;
}
th.hover, tfoot td.hover
{
background-color: ivory;
}
td.hovercell, th.hovercell
{
background-color: #abc;
}
td.hoverrow, th.hoverrow
{
background-color: #6df;
}
</style>
<a href="javascript:location.reload(true)">Refresh this page</a>
<table>
<tr>
<td style="width:220px;">
debug level:<span id="dbg_lvl"></span><div id="dbg_level" style="width:100px;"></div><br>
</td>
<td style="width:220px;">
var coplexity = <span id="vals_comp"></span>
<div class="vals_n" style="width:200px;"></div>
<div class="vals_n" style="width:200px;"></div>
<div class="vals_n" style="width:200px;"></div>
<div class="vals_n" style="width:200px;"></div>
<div class="vals_n" style="width:200px;"></div>
<div class="vals_n" style="width:200px;"></div>
<button onclick="re_create_data()">recreate</button>
</td>
<td style="width:220px;">
trash_hold: <span id="trsh_txt"></span><div id="trsh_rnd" style="width:100px;"></div><br>
</td>
</tr>
</table>
<div id="dbg_level" style="width:100px;"></div>
<table border=0 class="partbl">
<tr><th>Rows</th><th>Cols</th><th>Aggr</th><th>Filter</th><th>colors</th></tr>
<tr>
<td id='qpv_row_keys_placeholder'>drag rows here</td>
<td id='qpv_col_keys_placeholder'>drag cols here</td>
<td id='pv_aggregate_placeholder'>drag aggregates here</td>
<td id='pv_filter_placeholder'>drag filters here</td>
<td id="colors" width="120px">
<div class="controlset"><label for="color3">80</label> <input level="80" type="text" name="color3" value="#008000" /></div>
<div class="controlset"><label for="color3">50</label> <input level="50" type="text" name="color3" value="#99cc00" /></div>
<div class="controlset"><label for="color2">30</label> <input level="30" type="text" name="color2" value="#FFFF00" /></div>
<div class="controlset"><label for="color1">10</label> <input level="10" type="text" name="color1" value="#FF0000" /></div>
</td>
<td>
<input type="checkbox" id="use_custom_filter" value="1">значенение
<select id="custom_filter_cmp">
<option value="0">≥</option>
<option value="1">≠</option>
<option value="2">≤</option>
<option value="3">=</option>
</select>
<input type="text" style="width:20px;" id="custom_filter_val" value="50">
</td>
<td>
<input type="checkbox" id="use_percent_by_totals" >
%from totals by key <select id="totals_dropdown"></select>
</td>
</tr>
</table>
<button name="dr" onclick=" $('#pv').jPivot('drawData');">Draw</button>
<button name="dr" onclick="prepare_pivot()">Prepare</button>
<button name="dr" onclick="export_pivot()">Excel</button>
<button name="dr" onclick="save_state()">Save</button>
<button name="dr" onclick="restore()">Restore</button>
<div id="pv"></div>