Skip to content

Commit c0e4486

Browse files
author
minjk-bl
committed
Add x_label, y_label option on Plotly app
1 parent e4ff2e5 commit c0e4486

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

html/m_visualize/plotly.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@
7070
<label class="vp-bold">Parents</label>
7171
<select id="parents" class="vp-select vp-state">
7272

73+
</select>
74+
</div>
75+
<div class="vp-grid-box pt-option">
76+
<label class="vp-bold">Color</label>
77+
<select id="color" class="vp-select vp-state">
78+
7379
</select>
7480
</div>
7581
</div>
@@ -79,7 +85,16 @@
7985
<div class="vp-tab-page vp-grid-box" data-type="info" style="display: none;">
8086
<label for="title" class="vp-bold">Title</label>
8187
<input type="text" id="title" class="vp-input vp-state wp100" placeholder="Title for the chart" />
82-
88+
<div class="vp-grid-col-p50">
89+
<div class="vp-grid-box">
90+
<label for="x_label" class="vp-bold">X Label</label>
91+
<input type="text" id="x_label" class="vp-input vp-state" placeholder="Type X Label" />
92+
</div>
93+
<div class="vp-grid-box">
94+
<label for="y_label" class="vp-bold">Y Label</label>
95+
<input type="text" id="y_label" class="vp-input vp-state" placeholder="Type Y Label" />
96+
</div>
97+
</div>
8398

8499
</div>
85100
<div class="vp-tab-page vp-grid-box" data-type="style" style="display: none;">

js/m_visualize/Plotly.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ define([
3737
this.state = {
3838
chartType: 'scatter',
3939
data: '',
40+
x: '', y: '', z: '',
41+
x_start: '', x_end: '',
42+
values: '', names: '', parents: '',
43+
color: '',
4044
userOption: '',
4145
title: '',
46+
x_label: '',
47+
y_label: '',
4248
userCode: '',
4349
autoRefresh: true,
4450
...this.state
@@ -453,9 +459,9 @@ define([
453459
*/
454460
let {
455461
chartType,
456-
data, x, y, setXY,
462+
data, x, y, color, setXY,
457463
userOption, userCode,
458-
title
464+
title, x_label, y_label
459465
} = this.state;
460466
let code = new com_String();
461467
let config = this.chartConfig[chartType];
@@ -465,6 +471,42 @@ define([
465471
if (title != '') {
466472
etcOptionCode.push(com_util.formatString("title='{0}'", title));
467473
}
474+
let labelOptions = [];
475+
// add x_label
476+
if (x_label != '') {
477+
if (setXY === true) {
478+
// replace 'x' to x_label
479+
labelOptions.push(com_util.formatString("'x': '{0}'", x_label));
480+
} else {
481+
// if x is selected
482+
if (x != '') {
483+
// replace x column name to x_label
484+
labelOptions.push(com_util.formatString("{0}: '{1}'", x, x_label));
485+
} else {
486+
// replace 'index' to x_label
487+
labelOptions.push(com_util.formatString("'index': '{0}'", x_label));
488+
}
489+
}
490+
}
491+
// add y_label
492+
if (y_label != '') {
493+
if (setXY === true) {
494+
// replace 'y' to y_label
495+
labelOptions.push(com_util.formatString("'y': '{0}'", y_label));
496+
} else {
497+
// if y is selected
498+
if (y != '') {
499+
// replace y column name to y_label
500+
labelOptions.push(com_util.formatString("{0}: '{1}'", y, y_label));
501+
} else {
502+
// replace 'index' to y_label
503+
labelOptions.push(com_util.formatString("'index': '{0}'", y_label));
504+
}
505+
}
506+
}
507+
if (labelOptions.length > 0) {
508+
etcOptionCode.push(com_util.formatString("labels={ {0} }", labelOptions.join(', ')));
509+
}
468510
// add user option
469511
if (userOption != '') {
470512
etcOptionCode.push(userOption);

0 commit comments

Comments
 (0)