From 73fa465a8c769f0b32d96549655de1adaa4183b7 Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Wed, 29 Jun 2022 13:45:19 +0900 Subject: [PATCH 01/13] Fix bug - checkmodule spells --- js/m_apps/Import.js | 1 - js/m_visualize/WordCloud.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/js/m_apps/Import.js b/js/m_apps/Import.js index e023b307..e82e97e2 100644 --- a/js/m_apps/Import.js +++ b/js/m_apps/Import.js @@ -46,7 +46,6 @@ define([ /** Write codes executed before rendering */ this.config.dataview = false; this.config.sizeLevel = 1; - this.config.checkModules = ['pd']; let savedData = vpConfig.getDataSimple('', 'vpimport'); // Reset abnormal data diff --git a/js/m_visualize/WordCloud.js b/js/m_visualize/WordCloud.js index fad25ba2..6645b70f 100644 --- a/js/m_visualize/WordCloud.js +++ b/js/m_visualize/WordCloud.js @@ -31,7 +31,7 @@ define([ this.config.installButton = true; this.config.importButton = true; this.config.dataview = false; - this.config.checkModules = ['Counter', 'plt', 'Wordcloud']; + this.config.checkModules = ['Counter', 'plt', 'WordCloud']; this.state = { data: '', From 8562f05d8c71a3c22eccf864d880fe630c7c56a3 Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Wed, 29 Jun 2022 14:09:52 +0900 Subject: [PATCH 02/13] Fix bug on checking required input tags --- js/com/component/PopupComponent.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/com/component/PopupComponent.js b/js/com/component/PopupComponent.js index 35e02fcc..012baf34 100644 --- a/js/com/component/PopupComponent.js +++ b/js/com/component/PopupComponent.js @@ -709,7 +709,9 @@ define([ */ checkRequiredOption() { let requiredFilled = true; - let requiredTags = $(this.wrapSelector('input[required=true],input[required=required]')); + let requiredTags = $(this.wrapSelector('input[required=true]') + ',' + this.wrapSelector('input[required=required]')); + + vpLog.display(VP_LOG_TYPE.DEVELOP, 'checkRequiredOption', this, requiredTags); if (requiredTags) { for (let i = 0; i < requiredTags.length; i++) { From 6d9b89160e7296a6938d622e68a98d9388a41372 Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Wed, 29 Jun 2022 14:18:38 +0900 Subject: [PATCH 03/13] Fix bug on Profiling app which is not checking its required modules --- js/m_apps/Profiling.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/m_apps/Profiling.js b/js/m_apps/Profiling.js index 2052a433..5dcd3643 100644 --- a/js/m_apps/Profiling.js +++ b/js/m_apps/Profiling.js @@ -82,8 +82,10 @@ define([ code.append(saveas); break; } - com_interface.insertCell('code', code.toString(), true, 'Data Analysis > Profiling'); - that.loadReportList(); + that.checkAndRunModules(true).then(function() { + com_interface.insertCell('code', code.toString(), true, 'Data Analysis > Profiling'); + that.loadReportList(); + }); }); } From f22a617a330bf5fbd9a45dc600fb612e97eee3a5 Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Wed, 29 Jun 2022 14:22:36 +0900 Subject: [PATCH 04/13] Edit ModelInfo > plot_feature_importances - removed top_count option's max limit --- js/m_ml/ModelInfo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/m_ml/ModelInfo.js b/js/m_ml/ModelInfo.js index 43482fbd..0d13f337 100644 --- a/js/m_ml/ModelInfo.js +++ b/js/m_ml/ModelInfo.js @@ -438,7 +438,7 @@ define([ options: [ { name: 'fi_featureData', label: 'Feature Data', component: ['data_select'], var_type: ['DataFrame', 'Series', 'ndarray', 'list', 'dict'], value: 'X_train' }, { name: 'sort', label: 'Sort data', component: ['bool_checkbox'], value: true, usePair: true }, - { name: 'top_count', label: 'Top count', component: ['input_number'], min: 0, max: 5, usePair: true }, + { name: 'top_count', label: 'Top count', component: ['input_number'], min: 0, usePair: true }, ] } } From 2e5313c7c754c8e3818d264d6923352c8852e584 Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Wed, 29 Jun 2022 14:33:03 +0900 Subject: [PATCH 05/13] Edit Import app's default packages --- js/m_apps/Import.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/js/m_apps/Import.js b/js/m_apps/Import.js index e82e97e2..4d8ab01b 100644 --- a/js/m_apps/Import.js +++ b/js/m_apps/Import.js @@ -29,6 +29,14 @@ define([ , include: [ '%matplotlib inline' ] + }, + { i0: 'seaborn', i1: 'sns', type: 'module'}, + { + i0: 'plotly.express', i1: 'px', type: 'module' + , include: [ + 'from plotly.offline import init_notebook_mode', + 'init_notebook_mode(connected=True)' + ] } ], 'machine-learning': [ @@ -242,14 +250,19 @@ define([ // module sbCode.appendFormat("import {0}{1}", pacI0, ((pacI1 === undefined || pacI1 === "") ? "" : (" as " + pacI1))); } - } - // Need additional code? - if (pacI0 == 'matplotlib.pyplot' || pacI0 == 'matplotlib') { - sbCode.appendLine(); - sbCode.append('%matplotlib inline'); + // Need additional code? + if (pacI0 == 'matplotlib.pyplot' || pacI0 == 'matplotlib') { + sbCode.appendLine(); + sbCode.append('%matplotlib inline'); + } + if (pacI0 == 'plotly.express' || pacI0 == 'plotly') { + sbCode.appendLine(); + sbCode.appendLine('from plotly.offline import init_notebook_mode'); + sbCode.append('init_notebook_mode(connected=True)'); + } } - + importMeta.push({ i0: pacI0, i1: pacI1, type: pacType, checked: pacChecked }); } this.state.importMeta = importMeta; From afbbfb898df0ed44a476fda9ec19e9a4dbe86c1b Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Wed, 29 Jun 2022 15:25:02 +0900 Subject: [PATCH 06/13] Edit Seaborn app not to auto-import on loading preview, add inner function _vp_seaborn_show_values() for preview code --- js/com/com_Config.js | 10 ++++++++- js/m_visualize/Seaborn.js | 23 ++++++++++++++----- python/visualizationCommand.py | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 python/visualizationCommand.py diff --git a/js/com/com_Config.js b/js/com/com_Config.js index 40377d72..f1ea30f8 100644 --- a/js/com/com_Config.js +++ b/js/com/com_Config.js @@ -104,7 +104,14 @@ define([ '%matplotlib inline' ] }, - { library: 'seaborn', alias:'sns' } + { library: 'seaborn', alias:'sns' }, + { + library: 'plotly.express', alias: 'px', + include: [ + 'from plotly.offline import init_notebook_mode', + 'init_notebook_mode(connected=True)' + ] + } ] } @@ -251,6 +258,7 @@ define([ 'fileNaviCommand.py', 'pandasCommand.py', 'variableCommand.py', + 'visualizationCommand.py', // 'userCommand.py' ]; let promiseList = []; diff --git a/js/m_visualize/Seaborn.js b/js/m_visualize/Seaborn.js index eb92cf84..a1efa26c 100644 --- a/js/m_visualize/Seaborn.js +++ b/js/m_visualize/Seaborn.js @@ -280,10 +280,8 @@ define([ $(this.wrapSelector('#showValues')).on('change', function() { let checked = $(this).prop('checked'); if (checked === true) { - that.config.checkModules = ['plt', 'sns', 'np', 'vp_seaborn_show_values']; $(that.wrapSelector('#showValuesPrecision')).attr('disabled', false); } else { - that.config.checkModules = ['plt', 'sns']; $(that.wrapSelector('#showValuesPrecision')).attr('disabled', true); } }); @@ -696,6 +694,9 @@ define([ }); this.closeInnerPopup(); + + // load preview + this.loadPreview(); } loadPreview() { @@ -802,7 +803,19 @@ define([ let config = this.chartConfig[chartType]; let state = JSON.parse(JSON.stringify(this.state)); - if (preview && useSampling) { + // set checkmodules + if (preview === true) { + // no auto-import for preview + this.config.checkModules = []; + } else { + if (showValues && showValues === true) { + this.config.checkModules = ['plt', 'sns', 'np', 'vp_seaborn_show_values']; + } else { + this.config.checkModules = ['plt', 'sns']; + } + } + + if (preview === true && useSampling) { // data sampling code for preview // convertedData = data + '.sample(n=' + sampleCount + ', random_state=0)'; // convertedData = com_util.formatString('_vp_sample({0}, {1})', data, sampleCount); @@ -965,7 +978,7 @@ define([ chartCode.appendFormatLine("plt.grid({0})", gridCodeList.join(', ')); } - if (preview) { + if (preview === true) { // Ignore warning code.appendLine('import warnings'); code.appendLine('with warnings.catch_warnings():'); @@ -978,7 +991,7 @@ define([ if (showValues && showValues === true) { code.appendLine('ax = ' + generatedCode); - code.append("vp_seaborn_show_values(ax"); + code.append("_vp_seaborn_show_values(ax"); if (showValuesPrecision !== '') { code.appendFormat(", precision={0}", showValuesPrecision); } diff --git a/python/visualizationCommand.py b/python/visualizationCommand.py new file mode 100644 index 00000000..644940cd --- /dev/null +++ b/python/visualizationCommand.py @@ -0,0 +1,40 @@ +import numpy as _vp_np +def _vp_seaborn_show_values(axs, precision=1, space=0.01): + """ + Show values on Seaborn plots + - inner function for showing preview on Seaborn app + """ + pstr = '{:.' + str(precision) + 'f}' + + def _single(ax): + # check orient + orient = 'v' + if len(ax.patches) == 1: + # check if 0 + if ax.patches[0].get_x() == 0: + orient = 'h' + else: + # compare 0, 1 patches + p0 = ax.patches[0] + p1 = ax.patches[1] + if p0.get_x() == p1.get_x(): + orient = 'h' + + if orient == 'v': + for p in ax.patches: + _x = p.get_x() + p.get_width() / 2 + _y = p.get_y() + p.get_height() + (p.get_height()*space) + value = pstr.format(p.get_height()) + ax.text(_x, _y, value, ha='center') + elif orient == 'h': + for p in ax.patches: + _x = p.get_x() + p.get_width() + (space - 0.01) + _y = p.get_y() + p.get_height() / 2 + value = pstr.format(p.get_width()) + ax.text(_x, _y, value, ha='left') + + if isinstance(axs, _vp_np.ndarray): + for idx, ax in _vp_np.ndenumerate(axs): + _single(ax) + else: + _single(axs) \ No newline at end of file From 5c0a16aa994983ecb9ed883f84925ad3b6babf90 Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Wed, 29 Jun 2022 15:25:26 +0900 Subject: [PATCH 07/13] Edit Plotly, WordCloud app not to auto-import on loading preview --- js/m_visualize/Plotly.js | 5 +++++ js/m_visualize/WordCloud.js | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/js/m_visualize/Plotly.js b/js/m_visualize/Plotly.js index 511e4ae0..45d962d1 100644 --- a/js/m_visualize/Plotly.js +++ b/js/m_visualize/Plotly.js @@ -549,6 +549,11 @@ define([ // let height = $(this.wrapSelector('#vp_ptPreview')).height(); // console.log(width, height); etcOptionCode.push(com_util.formatString('width={0}, height={1}', width, height)); + + // no auto-import for preview + this.config.checkModules = []; + } else { + this.config.checkModules = ['px']; } let generatedCode = com_generator.vp_codeGenerator(this, config, this.state diff --git a/js/m_visualize/WordCloud.js b/js/m_visualize/WordCloud.js index 6645b70f..4c8b53cd 100644 --- a/js/m_visualize/WordCloud.js +++ b/js/m_visualize/WordCloud.js @@ -304,11 +304,16 @@ define([ let code = new com_String(); // preview option - if (preview) { + if (preview === true) { // Ignore warning code.appendLine('import warnings'); code.appendLine('with warnings.catch_warnings():'); code.appendLine(" warnings.simplefilter('ignore')"); + + // no auto-import for preview + this.config.checkModules = []; + } else { + this.config.checkModules = ['Counter', 'plt', 'WordCloud']; } // counter for top limit From bb93591fa1b542a9bf70df957f249f43ac4733c3 Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Wed, 29 Jun 2022 15:25:43 +0900 Subject: [PATCH 08/13] Add auto-import on DataSets app --- js/m_ml/DataSets.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/m_ml/DataSets.js b/js/m_ml/DataSets.js index b5f2acf3..1849dfd5 100644 --- a/js/m_ml/DataSets.js +++ b/js/m_ml/DataSets.js @@ -30,6 +30,7 @@ define([ super._init(); this.config.sizeLevel = 2; this.config.dataview = false; + this.config.checkModules = ['pd']; this.state = { loadType: 'load_boston', From cedc3f31cb26fc5398669d8cefcb211b89a4a386 Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Wed, 29 Jun 2022 16:37:57 +0900 Subject: [PATCH 09/13] Edit vp_seaborn_show_values function code to check isnan for x, y coordinates of value position --- python/userCommand.py | 10 ++++++---- python/visualizationCommand.py | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/python/userCommand.py b/python/userCommand.py index 96307fc6..6383f560 100644 --- a/python/userCommand.py +++ b/python/userCommand.py @@ -119,14 +119,16 @@ def _single(ax): for p in ax.patches: _x = p.get_x() + p.get_width() / 2 _y = p.get_y() + p.get_height() + (p.get_height()*space) - value = pstr.format(p.get_height()) - ax.text(_x, _y, value, ha='center') + if not _vp_np.isnan(_x) and not _vp_np.isnan(_y): + value = pstr.format(p.get_height()) + ax.text(_x, _y, value, ha='center') elif orient == 'h': for p in ax.patches: _x = p.get_x() + p.get_width() + (space - 0.01) _y = p.get_y() + p.get_height() / 2 - value = pstr.format(p.get_width()) - ax.text(_x, _y, value, ha='left') + if not _vp_np.isnan(_x) and not _vp_np.isnan(_y): + value = pstr.format(p.get_width()) + ax.text(_x, _y, value, ha='left') if isinstance(axs, _vp_np.ndarray): for idx, ax in _vp_np.ndenumerate(axs): diff --git a/python/visualizationCommand.py b/python/visualizationCommand.py index 644940cd..25775d61 100644 --- a/python/visualizationCommand.py +++ b/python/visualizationCommand.py @@ -24,14 +24,16 @@ def _single(ax): for p in ax.patches: _x = p.get_x() + p.get_width() / 2 _y = p.get_y() + p.get_height() + (p.get_height()*space) - value = pstr.format(p.get_height()) - ax.text(_x, _y, value, ha='center') + if not _vp_np.isnan(_x) and not _vp_np.isnan(_y): + value = pstr.format(p.get_height()) + ax.text(_x, _y, value, ha='center') elif orient == 'h': for p in ax.patches: _x = p.get_x() + p.get_width() + (space - 0.01) _y = p.get_y() + p.get_height() / 2 - value = pstr.format(p.get_width()) - ax.text(_x, _y, value, ha='left') + if not _vp_np.isnan(_x) and not _vp_np.isnan(_y): + value = pstr.format(p.get_width()) + ax.text(_x, _y, value, ha='left') if isinstance(axs, _vp_np.ndarray): for idx, ax in _vp_np.ndenumerate(axs): From e0b9d284feae29cb3990a23f89880300cb9bd65b Mon Sep 17 00:00:00 2001 From: minjk-bl Date: Wed, 29 Jun 2022 16:38:38 +0900 Subject: [PATCH 10/13] Edit show values, sort option layout and operations --- html/m_visualize/seaborn.html | 52 ++++++++++------ js/m_visualize/Seaborn.js | 113 +++++++++++++++++++--------------- 2 files changed, 98 insertions(+), 67 deletions(-) diff --git a/html/m_visualize/seaborn.html b/html/m_visualize/seaborn.html index 21208027..0e39d194 100644 --- a/html/m_visualize/seaborn.html +++ b/html/m_visualize/seaborn.html @@ -114,29 +114,34 @@ -
- - -
-
-
-
+
+ + - - +
-
- - - +
+ +
+ + +
+
@@ -207,7 +212,16 @@ - +
+
+ + +
+ + +
+
+