Skip to content

Commit c1147ae

Browse files
author
minjk-bl
committed
Add Sort option to Plotly app
1 parent 8235e0a commit c1147ae

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

html/m_visualize/plotly.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@
7878

7979
</select>
8080
</div>
81+
<div class="vp-grid-box pt-option">
82+
<label class="vp-bold">Sort</label>
83+
<select id="sort" class="vp-select vp-state">
84+
<option value="">Select option...</option>
85+
<option value="total descending">Total descending</option>
86+
<option value="total ascending">Total ascending</option>
87+
</select>
88+
</div>
8189
</div>
8290
<label for="userOption" class="vp-bold">User Option</label>
8391
<input type="text" id="userOption" class="vp-input vp-state wp100" placeholder="key=value, ..."/>

js/m_visualize/Plotly.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ define([
4141
x_start: '', x_end: '',
4242
values: '', names: '', parents: '',
4343
color: '',
44+
sort: '',
4445
userOption: '',
4546
title: '',
4647
x_label: '',
@@ -136,6 +137,7 @@ define([
136137
$(that.wrapSelector('#y')).closest('.pt-option').show();
137138
$(that.wrapSelector('#color')).closest('.pt-option').show();
138139
}
140+
$(that.wrapSelector('#sort')).closest('.pt-option').show();
139141
});
140142

141143
// use data or not
@@ -348,6 +350,7 @@ define([
348350
$(page).find('#y').closest('.pt-option').show();
349351
$(page).find('#color').closest('.pt-option').show();
350352
}
353+
$(page).find('#sort').closest('.pt-option').show();
351354

352355
//================================================================
353356
// Load state
@@ -482,7 +485,7 @@ define([
482485
*/
483486
let {
484487
chartType,
485-
data, x, y, color, setXY,
488+
data, x, y, color, setXY, sort,
486489
userOption, userCode,
487490
title, x_label, y_label
488491
} = this.state;
@@ -549,6 +552,11 @@ define([
549552
, etcOptionCode.length > 0? ', ' + etcOptionCode.join(', '): '');
550553
code.appendFormatLine("fig = {0}", generatedCode);
551554

555+
// sort code
556+
if (sort && sort != '') {
557+
code.appendFormatLine("fig.update_xaxes(categoryorder='{0}')", sort);
558+
}
559+
552560
if (userCode && userCode != '') {
553561
code.appendLine(userCode);
554562
}

0 commit comments

Comments
 (0)