@@ -182,6 +182,7 @@ define([
182182 FrameEditor . prototype . close = function ( ) {
183183 this . unbindEvent ( ) ;
184184 $ ( this . wrapSelector ( ) ) . remove ( ) ;
185+ $ ( vpCommon . formatString ( '.{0}.{1}' , VP_FE_BTN , this . uuid ) ) . remove ( ) ;
185186 }
186187
187188 FrameEditor . prototype . init = function ( state = undefined ) {
@@ -190,6 +191,8 @@ define([
190191 originObj : '' ,
191192 tempObj : '_vp' ,
192193 returnObj : '_vp' ,
194+ columnList : [ ] ,
195+ indexList : [ ] ,
193196 selected : [ ] ,
194197 axis : FRAME_AXIS . NONE ,
195198 lines : TABLE_LINES ,
@@ -303,7 +306,7 @@ define([
303306 page . appendFormatLine ( '<div class="{0}"><img src="{1}"/></div>' , VP_FE_DF_REFRESH , '/nbextensions/visualpython/resource/refresh.svg' ) ;
304307 page . appendLine ( '</div>' ) ;
305308 page . appendLine ( '<div>' ) ;
306- page . appendFormatLine ( '<label for="{0}" class=" {1}">{2} </label>' , 'vp_feReturn' , 'vp-orange-text ', 'Allocate to' ) ;
309+ page . appendFormatLine ( '<label for="{0}"> {1}</label>' , 'vp_feReturn' , 'Allocate to' ) ;
307310 page . appendFormatLine ( '<input type="text" class="{0}" id="{1}" placeholder="{2}"/>' , 'vp-input' , 'vp_feReturn' , 'Variable name' ) ;
308311 page . appendLine ( '</div>' ) ;
309312 page . appendLine ( '</div>' ) ;
@@ -553,19 +556,39 @@ define([
553556
554557 // tab 4. apply
555558 content . appendFormatLine ( '<div class="{0} {1}" style="display: none;">' , 'vp-popup-tab' , 'apply' ) ;
556- content . appendLine ( '<label>lambda x:</label>' ) ;
559+ content . appendLine ( '<table><colgroup><col width="80px"><col width="*"></colgroup>' ) ;
560+ content . appendLine ( '<tr><th><label>column</label></th>' ) ;
561+ content . appendFormatLine ( '<td>{0}</td></tr>' , this . renderColumnList ( this . state . columnList ) ) ;
562+ content . appendLine ( '<tr><th><label>lambda x:</label></th>' ) ;
557563 var suggestInput = new vpSuggestInputText . vpSuggestInputText ( ) ;
558564 suggestInput . setComponentID ( 'vp_popupAddApply' ) ;
559- suggestInput . addClass ( 'vp-input vp-popup-apply' ) ;
565+ suggestInput . addClass ( 'vp-input vp-popup-apply-lambda ' ) ;
560566 suggestInput . setSuggestList ( function ( ) { return [ 'x' , 'min(x)' , 'max(x)' , 'sum(x)' , 'mean(x)' ] ; } ) ;
561567 suggestInput . setValue ( 'x' ) ;
562568 suggestInput . setNormalFilter ( false ) ;
563- content . appendLine ( suggestInput . toTagString ( ) ) ;
569+ content . appendFormatLine ( '<td>{0}</td>' , suggestInput . toTagString ( ) ) ;
570+ content . appendLine ( '</tr></table>' ) ;
564571 content . appendLine ( '</div>' ) ; // end of vp-popup-tab apply
565572 content . appendLine ( '</div>' ) ; // end of vp-popup-addpage
566573 return content . toString ( ) ;
567574 }
568575
576+ /**
577+ * Render column list for [add column > apply]
578+ * @param {Array } columnList
579+ * @returns
580+ */
581+ FrameEditor . prototype . renderColumnList = function ( columnList ) {
582+ var selectTag = new sb . StringBuilder ( ) ;
583+ selectTag . appendFormatLine ( '<select class="{0}">' , 'vp-popup-apply-column' ) ;
584+ columnList && columnList . forEach ( ( col , idx ) => {
585+ var colLabel = convertToStr ( col , typeof col == 'string' ) ;
586+ selectTag . appendFormatLine ( '<option value="{0}">{1}</option>' , colLabel , col ) ;
587+ } ) ;
588+ selectTag . appendLine ( '</select>' ) ;
589+ return selectTag . toString ( ) ;
590+ }
591+
569592 FrameEditor . prototype . bindEventForPopupPage = function ( ) {
570593 var that = this ;
571594 ///// add page
@@ -719,7 +742,8 @@ define([
719742 }
720743 }
721744 } else if ( tab == 'apply' ) {
722- content [ 'apply' ] = $ ( this . wrapSelector ( '.vp-popup-apply' ) ) . val ( ) ;
745+ content [ 'column' ] = $ ( this . wrapSelector ( '.vp-popup-apply-column' ) ) . val ( ) ;
746+ content [ 'apply' ] = $ ( this . wrapSelector ( '.vp-popup-apply-lambda' ) ) . val ( ) ;
723747 }
724748 break ;
725749 case FRAME_EDIT_TYPE . ADD_ROW :
@@ -770,6 +794,7 @@ define([
770794
771795 /** open preview box */
772796 FrameEditor . prototype . openPreview = function ( ) {
797+ this . closeDataview ( ) ;
773798 $ ( this . wrapSelector ( '.' + VP_FE_PREVIEW_BOX ) ) . show ( ) ;
774799
775800 if ( ! this . cmpreviewall ) {
@@ -823,6 +848,7 @@ define([
823848 }
824849
825850 FrameEditor . prototype . openDataview = function ( ) {
851+ this . closePreview ( ) ;
826852 this . dataviewOpened = true ;
827853 $ ( this . wrapSelector ( '.' + VP_FE_INFO ) ) . show ( ) ;
828854 }
@@ -1058,7 +1084,7 @@ define([
10581084 }
10591085 code . append ( ')' ) ;
10601086 } else if ( tab == 'apply' ) {
1061- code . appendFormat ( "{0}[{1}] = {2}.apply(lambda x: {3 })" , tempObj , name , tempObj , content . apply ) ;
1087+ code . appendFormat ( "{0}[{1}] = {2}[{3}] .apply(lambda x: {4 })" , tempObj , name , tempObj , content . column , content . apply ) ;
10621088 }
10631089 break ;
10641090 case FRAME_EDIT_TYPE . ADD_ROW :
@@ -1090,11 +1116,14 @@ define([
10901116 kernelApi . executePython ( code . toString ( ) , function ( result ) {
10911117 try {
10921118 var data = JSON . parse ( result . substr ( 1 , result . length - 2 ) . replaceAll ( '\\\\' , '\\' ) ) ;
1093- // console.l og (data);
1119+ // console.log (data);
10941120 var columnList = data . columns ;
10951121 var indexList = data . index ;
10961122 var dataList = data . data ;
10971123
1124+ that . state . columnList = columnList ;
1125+ that . state . indexList = indexList ;
1126+
10981127 // table
10991128 var table = new sb . StringBuilder ( ) ;
11001129 // table.appendFormatLine('<table border="{0}" class="{1}">', 1, 'dataframe');
@@ -1191,11 +1220,11 @@ define([
11911220
11921221 FrameEditor . prototype . saveState = function ( ) {
11931222 // if there's anything to save, you can properly save it here.
1194- console . log ( 'frame' , 'saveState' , this . state ) ;
1223+ // console.log('frame', 'saveState', this.state);
11951224 }
11961225
11971226 FrameEditor . prototype . loadState = function ( state ) {
1198- console . log ( 'frame' , 'loadState' , state ) ;
1227+ // console.log('frame', 'loadState', state);
11991228 var {
12001229 originObj,
12011230 returnObj,
@@ -1254,8 +1283,6 @@ define([
12541283 // close popup
12551284 $ ( document ) . on ( 'click' , this . wrapSelector ( '.' + VP_FE_CLOSE ) , function ( event ) {
12561285 that . close ( ) ;
1257-
1258- $ ( vpCommon . formatString ( '.{0}.{1}' , VP_FE_BTN , this . uuid ) ) . remove ( ) ;
12591286 // vpCommon.removeHeadScript("vpSubsetEditor");
12601287 } ) ;
12611288
@@ -1343,8 +1370,13 @@ define([
13431370 // close menu
13441371 that . hideMenu ( ) ;
13451372 }
1346- if ( ! $ ( evt . target ) . hasClass ( '.' + VP_FE_BUTTON_DATAVIEW ) ) {
1347- // close info
1373+ if ( ! $ ( evt . target ) . hasClass ( VP_FE_BUTTON_PREVIEW )
1374+ && ! $ ( evt . target ) . hasClass ( VP_FE_PREVIEW_BOX )
1375+ && $ ( that . wrapSelector ( '.' + VP_FE_PREVIEW_BOX ) ) . has ( evt . target ) . length === 0 ) {
1376+ that . closePreview ( ) ;
1377+ }
1378+ if ( ! $ ( evt . target ) . hasClass ( VP_FE_BUTTON_DATAVIEW )
1379+ && $ ( that . wrapSelector ( '.' + VP_FE_INFO ) ) . has ( evt . target ) . length === 0 ) {
13481380 that . closeDataview ( ) ;
13491381 }
13501382 } ) ;
@@ -1589,7 +1621,7 @@ define([
15891621
15901622 // click preview
15911623 $ ( document ) . on ( 'click' , this . wrapSelector ( '.' + VP_FE_BUTTON_PREVIEW ) , function ( evt ) {
1592- evt . stopPropagation ( ) ;
1624+ // evt.stopPropagation();
15931625 if ( that . previewOpened ) {
15941626 that . closePreview ( ) ;
15951627 } else {
@@ -1599,7 +1631,7 @@ define([
15991631
16001632 // click dataview
16011633 $ ( document ) . on ( 'click' , this . wrapSelector ( '.' + VP_FE_BUTTON_DATAVIEW ) , function ( evt ) {
1602- evt . stopPropagation ( ) ;
1634+ // evt.stopPropagation();
16031635 if ( that . dataviewOpened ) {
16041636 that . closeDataview ( ) ;
16051637 } else {
@@ -1638,14 +1670,14 @@ define([
16381670
16391671 // click others
16401672 $ ( document ) . on ( 'click.' + this . uuid , function ( evt ) {
1641- if ( ! $ ( evt . target ) . hasClass ( '.' + VP_FE_BUTTON_DETAIL ) ) {
1673+ if ( ! $ ( evt . target ) . hasClass ( VP_FE_BUTTON_DETAIL ) ) {
16421674 $ ( that . wrapSelector ( '.' + VP_FE_DETAIL_BOX ) ) . hide ( ) ;
16431675 }
1644- if ( ! $ ( evt . target ) . hasClass ( '.' + VP_FE_BUTTON_PREVIEW )
1676+ if ( ! $ ( evt . target ) . hasClass ( VP_FE_BUTTON_PREVIEW )
16451677 && $ ( that . wrapSelector ( '.' + VP_FE_PREVIEW_BOX ) ) . has ( evt . target ) . length === 0 ) {
16461678 that . closePreview ( ) ;
16471679 }
1648- if ( ! $ ( evt . target ) . hasClass ( '.' + VP_FE_BUTTON_DATAVIEW )
1680+ if ( ! $ ( evt . target ) . hasClass ( VP_FE_BUTTON_DATAVIEW )
16491681 && $ ( that . wrapSelector ( '.' + VP_FE_INFO ) ) . has ( evt . target ) . length === 0 ) {
16501682 that . closeDataview ( ) ;
16511683 }
@@ -1681,10 +1713,10 @@ define([
16811713 if ( e . keyCode == keyCode . shiftKey ) {
16821714 that . keyboardManager . keyCheck . shiftKey = false ;
16831715 }
1684- if ( e . keyCode == keyCode . escKey ) {
1685- // close on esc
1686- that . close ( ) ;
1687- }
1716+ // if (e.keyCode == keyCode.escKey) {
1717+ // // close on esc
1718+ // that.close();
1719+ // }
16881720 } ) ;
16891721 }
16901722
0 commit comments