Skip to content

Commit ede4b9a

Browse files
author
minjk-bl
committed
Add kde, stat option to histplot
1 parent a4e6038 commit ede4b9a

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

data/m_visualize/seabornLibrary.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ define([
4848
/** Distribution plots */
4949
'histplot': {
5050
name: 'Histogram Plot',
51-
code: '${allocateTo} = sns.histplot(${data}${x}${y}${hue}${bins}${etc})',
51+
code: '${allocateTo} = sns.histplot(${data}${x}${y}${hue}${bins}${kde}${stat}${etc})',
5252
description: 'Plot univariate or bivariate histograms to show distributions of datasets.',
5353
options: [
5454
{ name: 'data', component: ['var_select'], var_type: ['DataFrame', 'Series', 'list'], usePair: true },
5555
{ name: 'x', component: ['col_select'], usePair: true },
5656
{ name: 'y', component: ['col_select'], usePair: true },
5757
{ name: 'hue', component: ['col_select'], usePair: true },
58-
{ name: 'bins', component: ['col_select'], usePair: true },
58+
{ name: 'bins', component: ['input_number'], usePair: true },
59+
{ name: 'kde', component: ['option_select'], usePair: true },
60+
{ name: 'stat', component: ['bool_select'], usePair: true },
5961
{ name: 'allocateTo', label: 'Allocate To', component: ['input'], usePair: true }
6062
]
6163
},

html/m_visualize/seaborn.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,24 @@
9696

9797
</select>
9898
</div>
99-
<div class="vp-grid-box sb-option bins">
99+
<div class="vp-grid-box sb-option">
100100
<label for="bins" class="vp-bold">Bins</label>
101101
<input type="number" class="vp-input vp-state" id="bins" placeholder="Type bins" step="5" min="0" />
102102
</div>
103+
<div class="vp-grid-box sb-option">
104+
<label for="kde" class="vp-bold">Kde</label>
105+
<select id="kde" class="vp-select vp-state">
106+
<option value="">Select option...</option>
107+
<option value="True">True</option>
108+
<option value="False">False</option>
109+
</select>
110+
</div>
111+
<div class="vp-grid-box sb-option">
112+
<label for="stat" class="vp-bold">Stat</label>
113+
<select id="stat" class="vp-state">
114+
<!-- Auto-create -->
115+
</select>
116+
</div>
103117
</div>
104118
<label for="userOption" class="vp-bold">User Option</label>
105119
<input type="text" id="userOption" class="vp-input vp-state wp100" placeholder="key=value, ..."/>

js/m_visualize/Seaborn.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ define([
4545
x: '',
4646
y: '',
4747
hue: '',
48+
bins: '',
49+
kde: '',
50+
stat: '',
4851
// axes options
4952
x_limit_from: '',
5053
x_limit_to: '',
@@ -127,6 +130,16 @@ define([
127130
{ label: 'diamond', value: 'D', title: 'diamond' },
128131
{ label: 'thin diamond', value: 'd', title: 'thin_diamond' }
129132
]
133+
134+
this.statList = [
135+
{ label: 'Select option...', value: '' },
136+
{ label: 'count', value: "'count'" },
137+
{ label: 'frequency', value: "'frequency'" },
138+
{ label: 'density', value: "'density'" },
139+
{ label: 'probability', value: "'probability'" },
140+
{ label: 'proportion', value: "'proportion'" },
141+
{ label: 'percent', value: "'percent'" }
142+
];
130143
}
131144

132145
_bindEvent() {
@@ -174,7 +187,9 @@ define([
174187
let chartType = $(this).val();
175188
$(that.wrapSelector('.sb-option')).hide();
176189
if (chartType == 'histplot') {
177-
$(that.wrapSelector('.sb-option.bins')).show();
190+
$(that.wrapSelector('#bins')).closest('.sb-option').show();
191+
$(that.wrapSelector('#kde')).closest('.sb-option').show();
192+
$(that.wrapSelector('#stat')).closest('.sb-option').show();
178193
}
179194
});
180195

@@ -357,6 +372,18 @@ define([
357372
$(page).find('#yticks_label').prop('readonly', false);
358373
}
359374

375+
// stat options
376+
let statTag = new com_String();
377+
this.statList.forEach(stat => {
378+
let selectedFlag = '';
379+
if (stat.value == that.state.stat) {
380+
selectedFlag = 'selected';
381+
}
382+
statTag.appendFormatLine('<option value="{0}" {1}>{2}</option>',
383+
stat.value, selectedFlag, stat.label);
384+
});
385+
$(page).find('#stat').html(statTag.toString());
386+
360387
// preview sample count
361388
let sampleCountList = [30, 50, 100, 300, 500, 700, 1000];
362389
let sampleCountTag = new com_String();
@@ -373,7 +400,9 @@ define([
373400
// data options depend on chart type
374401
$(page).find('.sb-option').hide();
375402
if (this.state.chartType == 'histplot') {
376-
$(page).find('.sb-option.bins').show();
403+
$(page).find('#bins').closest('.sb-option').show();
404+
$(page).find('#kde').closest('.sb-option').show();
405+
$(page).find('#stat').closest('.sb-option').show();
377406
}
378407

379408
//================================================================

0 commit comments

Comments
 (0)