@@ -190,6 +190,8 @@ define([
190190 originObj : '' ,
191191 tempObj : '_vp' ,
192192 returnObj : '_vp' ,
193+ columnList : [ ] ,
194+ indexList : [ ] ,
193195 selected : [ ] ,
194196 axis : FRAME_AXIS . NONE ,
195197 lines : TABLE_LINES ,
@@ -553,19 +555,39 @@ define([
553555
554556 // tab 4. apply
555557 content . appendFormatLine ( '<div class="{0} {1}" style="display: none;">' , 'vp-popup-tab' , 'apply' ) ;
556- content . appendLine ( '<label>lambda x:</label>' ) ;
558+ content . appendLine ( '<table><colgroup><col width="80px"><col width="*"></colgroup>' ) ;
559+ content . appendLine ( '<tr><th><label>column</label></th>' ) ;
560+ content . appendFormatLine ( '<td>{0}</td></tr>' , this . renderColumnList ( this . state . columnList ) ) ;
561+ content . appendLine ( '<tr><th><label>lambda x:</label></th>' ) ;
557562 var suggestInput = new vpSuggestInputText . vpSuggestInputText ( ) ;
558563 suggestInput . setComponentID ( 'vp_popupAddApply' ) ;
559- suggestInput . addClass ( 'vp-input vp-popup-apply' ) ;
564+ suggestInput . addClass ( 'vp-input vp-popup-apply-lambda ' ) ;
560565 suggestInput . setSuggestList ( function ( ) { return [ 'x' , 'min(x)' , 'max(x)' , 'sum(x)' , 'mean(x)' ] ; } ) ;
561566 suggestInput . setValue ( 'x' ) ;
562567 suggestInput . setNormalFilter ( false ) ;
563- content . appendLine ( suggestInput . toTagString ( ) ) ;
568+ content . appendFormatLine ( '<td>{0}</td>' , suggestInput . toTagString ( ) ) ;
569+ content . appendLine ( '</tr></table>' ) ;
564570 content . appendLine ( '</div>' ) ; // end of vp-popup-tab apply
565571 content . appendLine ( '</div>' ) ; // end of vp-popup-addpage
566572 return content . toString ( ) ;
567573 }
568574
575+ /**
576+ * Render column list for [add column > apply]
577+ * @param {Array } columnList
578+ * @returns
579+ */
580+ FrameEditor . prototype . renderColumnList = function ( columnList ) {
581+ var selectTag = new sb . StringBuilder ( ) ;
582+ selectTag . appendFormatLine ( '<select class="{0}">' , 'vp-popup-apply-column' ) ;
583+ columnList && columnList . forEach ( ( col , idx ) => {
584+ var colLabel = convertToStr ( col , typeof col == 'string' ) ;
585+ selectTag . appendFormatLine ( '<option value="{0}">{1}</option>' , colLabel , col ) ;
586+ } ) ;
587+ selectTag . appendLine ( '</select>' ) ;
588+ return selectTag . toString ( ) ;
589+ }
590+
569591 FrameEditor . prototype . bindEventForPopupPage = function ( ) {
570592 var that = this ;
571593 ///// add page
@@ -719,7 +741,8 @@ define([
719741 }
720742 }
721743 } else if ( tab == 'apply' ) {
722- content [ 'apply' ] = $ ( this . wrapSelector ( '.vp-popup-apply' ) ) . val ( ) ;
744+ content [ 'column' ] = $ ( this . wrapSelector ( '.vp-popup-apply-column' ) ) . val ( ) ;
745+ content [ 'apply' ] = $ ( this . wrapSelector ( '.vp-popup-apply-lambda' ) ) . val ( ) ;
723746 }
724747 break ;
725748 case FRAME_EDIT_TYPE . ADD_ROW :
@@ -1060,7 +1083,7 @@ define([
10601083 }
10611084 code . append ( ')' ) ;
10621085 } else if ( tab == 'apply' ) {
1063- code . appendFormat ( "{0}[{1}] = {2}.apply(lambda x: {3 })" , tempObj , name , tempObj , content . apply ) ;
1086+ code . appendFormat ( "{0}[{1}] = {2}[{3}] .apply(lambda x: {4 })" , tempObj , name , tempObj , content . column , content . apply ) ;
10641087 }
10651088 break ;
10661089 case FRAME_EDIT_TYPE . ADD_ROW :
@@ -1092,11 +1115,14 @@ define([
10921115 kernelApi . executePython ( code . toString ( ) , function ( result ) {
10931116 try {
10941117 var data = JSON . parse ( result . substr ( 1 , result . length - 2 ) . replaceAll ( '\\\\' , '\\' ) ) ;
1095- // console.l og (data);
1118+ // console.log (data);
10961119 var columnList = data . columns ;
10971120 var indexList = data . index ;
10981121 var dataList = data . data ;
10991122
1123+ that . state . columnList = columnList ;
1124+ that . state . indexList = indexList ;
1125+
11001126 // table
11011127 var table = new sb . StringBuilder ( ) ;
11021128 // table.appendFormatLine('<table border="{0}" class="{1}">', 1, 'dataframe');
0 commit comments