@@ -21,8 +21,9 @@ define([
21
21
'vp_base/js/com/component/PopupComponent' ,
22
22
'vp_base/js/com/component/SuggestInput' ,
23
23
'vp_base/js/com/component/DataSelector' ,
24
+ 'vp_base/js/com/component/MultiSelector' ,
24
25
'vp_base/js/m_apps/Subset'
25
- ] , function ( frameHtml , frameCss , com_Const , com_String , com_util , PopupComponent , SuggestInput , DataSelector , Subset ) {
26
+ ] , function ( frameHtml , frameCss , com_Const , com_String , com_util , PopupComponent , SuggestInput , DataSelector , MultiSelector , Subset ) {
26
27
27
28
/**
28
29
* Frame
@@ -1427,6 +1428,7 @@ define([
1427
1428
content . appendLine ( '<tr><th><label>Add type</label></th>' ) ;
1428
1429
content . appendFormatLine ( '<td><select class="{0}">' , 'vp-inner-popup-addtype' ) ;
1429
1430
content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'calculate' , 'Calculate' ) ;
1431
+ content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'statistics' , 'Statistics' ) ;
1430
1432
content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'replace' , 'Replace' ) ;
1431
1433
content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'condition' , 'Condition' ) ;
1432
1434
content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'apply' , 'Apply' ) ;
@@ -1461,7 +1463,26 @@ define([
1461
1463
content . appendLine ( '</table>' ) ;
1462
1464
content . appendLine ( '</div>' ) ; // end of vp-inner-popup-tab value
1463
1465
1464
- // tab 2. replace
1466
+ // tab 2. statistics
1467
+ content . appendFormatLine ( '<div class="{0} {1}" style="display:none;">' , 'vp-inner-popup-tab' , 'statistics' ) ;
1468
+ content . appendFormatLine ( '<div class="{0}">' , 'vp-grid-col-120' ) ;
1469
+ content . appendLine ( '<label class="vp-orange-text">Columns</label>' ) ;
1470
+ content . appendFormatLine ( '<div class="{0}" style="height: 150px;"></div>' , 'vp-inner-popup-stats-col-list' ) ;
1471
+ content . appendLine ( '<label>Method</label>' ) ;
1472
+ content . appendFormatLine ( '<select class="vp-select {0}">' , 'vp-inner-popup-stats-method' ) ;
1473
+ let methodList = [
1474
+ 'sum' , 'mean' , 'median' , 'max' , 'min' , 'std' , 'var'
1475
+ ] ;
1476
+ methodList . forEach ( method => {
1477
+ content . appendFormatLine ( '<option data-code="{0}" value="{1}">{2}</option>' ,
1478
+ method , method , method ) ;
1479
+ } ) ;
1480
+ content . appendLine ( '</select>' ) ;
1481
+
1482
+ content . appendLine ( '</div>' ) ;
1483
+ content . appendLine ( '</div>' ) ;
1484
+
1485
+ // tab 3. replace
1465
1486
content . appendFormatLine ( '<div class="{0} {1}" style="display:none;">' , 'vp-inner-popup-tab' , 'replace' ) ;
1466
1487
content . appendFormatLine ( '<div class="{0}">' , 'vp-grid-col-120' ) ;
1467
1488
content . appendLine ( '<label class="vp-orange-text">Target column</label>' ) ;
@@ -1486,7 +1507,7 @@ define([
1486
1507
content . appendLine ( '</div>' ) ;
1487
1508
content . appendLine ( '</div>' ) ;
1488
1509
1489
- // tab 3 . condition
1510
+ // tab 4 . condition
1490
1511
// replace page - 2. condition
1491
1512
content . appendFormatLine ( '<div class="{0} {1}" style="display:none;">' , 'vp-inner-popup-tab' , 'condition' ) ;
1492
1513
// value
@@ -1505,7 +1526,7 @@ define([
1505
1526
content . appendLine ( '</table>' ) ;
1506
1527
content . appendLine ( '</div>' ) ;
1507
1528
1508
- // tab 4 . apply
1529
+ // tab 5 . apply
1509
1530
content . appendFormatLine ( '<div class="{0} {1}" style="display: none;">' , 'vp-inner-popup-tab' , 'apply' ) ;
1510
1531
content . appendLine ( '<div class="vp-grid-box">' ) ;
1511
1532
content . appendLine ( '<div class="vp-grid-col-120">' ) ;
@@ -2263,6 +2284,11 @@ define([
2263
2284
} ) ;
2264
2285
} ) ;
2265
2286
2287
+ // bind multiselector
2288
+ this . statsSelector = new MultiSelector ( this . wrapSelector ( '.vp-inner-popup-stats-col-list' ) ,
2289
+ { mode : 'columns' , parent : this . state . tempObj , showDescription : false }
2290
+ ) ;
2291
+
2266
2292
// bind codemirror for apply textarea
2267
2293
this . applyCm = this . initCodemirror ( {
2268
2294
key : 'vp-inner-popup-apply-lambda' ,
@@ -2547,6 +2573,10 @@ define([
2547
2573
} ) ;
2548
2574
content [ 'values' ] = values ;
2549
2575
content [ 'opers' ] = opers ;
2576
+ } else if ( tab == 'statistics' ) {
2577
+ var colList = this . statsSelector . getDataList ( ) ;
2578
+ content [ 'columns' ] = colList . map ( x => x . code ) ;
2579
+ content [ 'method' ] = $ ( this . wrapSelector ( '.vp-inner-popup-stats-method' ) ) . val ( ) ;
2550
2580
} else if ( tab == 'replace' ) {
2551
2581
content [ 'target' ] = $ ( this . wrapSelector ( '.vp-inner-popup-value-col-list option:selected' ) ) . data ( 'code' ) ;
2552
2582
var useregex = $ ( this . wrapSelector ( '.vp-inner-popup-use-regex' ) ) . prop ( 'checked' ) ;
@@ -3102,6 +3132,14 @@ define([
3102
3132
} else {
3103
3133
code . appendFormat ( "{0}[{1}] = {2}" , tempObj , content . name , valueStr ) ;
3104
3134
}
3135
+ } else if ( tab == 'statistics' ) {
3136
+ code . appendFormat ( "{0}[{1}] = " , tempObj , content . name ) ;
3137
+ code . append ( tempObj ) ;
3138
+ if ( content [ 'columns' ] . length > 0 ) {
3139
+ code . appendFormat ( "[[{0}]]" , content [ 'columns' ] . join ( ',' ) ) ;
3140
+ }
3141
+ code . appendFormat ( ".apply(lambda x: x.{0}(), axis=1)" , content . method ) ;
3142
+ // code.appendFormat(".{0}(axis=1)", content.method); // FIXME: for pandas version upper 2.0.0
3105
3143
} else if ( tab == 'replace' ) {
3106
3144
var replaceStr = new com_String ( ) ;
3107
3145
var targetName = content [ 'target' ] ;
0 commit comments