Skip to content

Commit 0413293

Browse files
author
minjk-bl
committed
Seaborn - add index to x, y, hue option
1 parent 9896428 commit 0413293

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

js/com/com_generatorV2.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,13 @@ define([
657657
* @param {array} columnInputIdList
658658
* @param {string} tagType input / select (tag type)
659659
* @param {array/boolean} columnWithEmpty boolean array or value to decide whether select tag has empty space
660+
* @param {array/boolean} columnWithIndex boolean array or value to decide whether select tag has index option
660661
* Usage :
661662
* $(document).on('change', this.wrapSelector('#dataframe_tag_id'), function() {
662663
* pdGen.vp_bindColumnSource(that.wrapSelector(), this, ['column_input_id'], 'select', [true, true, true]);
663664
* });
664665
*/
665-
var vp_bindColumnSource = function(selector, target, columnInputIdList, tagType="input", columnWithEmpty=false) {
666+
var vp_bindColumnSource = function(selector, target, columnInputIdList, tagType="input", columnWithEmpty=false, columnWithIndex=false) {
666667
var varName = '';
667668
if ($(target).length > 0) {
668669
varName = $(target).val();
@@ -702,6 +703,20 @@ define([
702703
let { result, type, msg } = resultObj;
703704
var varResult = JSON.parse(result);
704705

706+
// check if it needs to add index option
707+
let addIndex = false;
708+
if (Array.isArray(columnWithIndex)) {
709+
addIndex = columnWithIndex[idx];
710+
} else {
711+
addIndex = columnWithIndex;
712+
}
713+
if (addIndex == true) {
714+
varResult = [
715+
{value: varName + '.index', label: 'index'},
716+
...varResult
717+
]
718+
}
719+
705720
// check if it needs to add empty option
706721
let addEmpty = false;
707722
if (Array.isArray(columnWithEmpty)) {
@@ -711,7 +726,7 @@ define([
711726
}
712727
if (addEmpty == true) {
713728
varResult = [
714-
{value: '', label: ''},
729+
{value: '', label: 'Select option...'},
715730
...varResult
716731
]
717732
}

js/m_visualize/Seaborn.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ define([
246246
$(that.wrapSelector('#hue')).prop('disabled', false);
247247

248248
// bind column source using selected dataframe
249-
com_generator.vp_bindColumnSource(that.wrapSelector(), $(that.wrapSelector('#data')), ['x', 'y', 'hue'], 'select', true);
249+
com_generator.vp_bindColumnSource(that.wrapSelector(), $(that.wrapSelector('#data')), ['x', 'y', 'hue'], 'select', true, true);
250250
} else {
251251
$(that.wrapSelector('#x')).prop('disabled', true);
252252
$(that.wrapSelector('#y')).prop('disabled', true);
@@ -592,7 +592,7 @@ define([
592592
// data sampling code for preview
593593
convertedData = data + '.sample(n=' + sampleCount + ', random_state=0)';
594594
// replace pre-defined options
595-
generatedCode = generatedCode.replace(data, convertedData);
595+
generatedCode = generatedCode.replaceAll(data, convertedData);
596596
}
597597

598598
code.appendFormatLine("{0}{1}", indent, generatedCode);
@@ -603,7 +603,8 @@ define([
603603
code.appendLine(chartCode.toString());
604604
}
605605

606-
return code.toString();
606+
// remove last Enter(\n) from code and then run it
607+
return code.toString().replace(/\n+$/, "");
607608
}
608609

609610
}

0 commit comments

Comments
 (0)