Skip to content

Commit 5d3e539

Browse files
author
minjk-bl
committed
Chart Setting - import seaborn, add default setting
1 parent 084735e commit 5d3e539

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

html/m_visualize/chartSetting.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<body>
2-
<div class="vp-grid-border-box vp-grid-col-95">
2+
<div class="vp-chart-setting-body vp-grid-border-box vp-grid-col-95">
33
<label for="figureWidth" class="">Figure size</label>
44
<div>
55
<input type="number" id="figureWidth" class="vp-input m vp-state" placeholder="width" value="12">
@@ -12,4 +12,8 @@
1212
<label for="fontSize" class="">Font size</label>
1313
<input type="number" id="fontSize" class="vp-input vp-state" placeholder="size" value="10">
1414
</div>
15+
<label class="mt5">
16+
<input type="checkbox" id="setDefault">
17+
<span title="Set chart setting to default.">Set Default</span>
18+
</label>
1519
</body>

js/m_visualize/ChartSetting.js

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,18 @@ define([
4242
super._bindEvent();
4343

4444
let that = this;
45-
45+
// setting popup - set default
46+
$(this.wrapSelector('#setDefault')).on('change', function() {
47+
let checked = $(this).prop('checked');
48+
49+
if (checked) {
50+
// disable input
51+
$(that.wrapSelector('.vp-chart-setting-body input')).prop('disabled', true);
52+
} else {
53+
// enable input
54+
$(that.wrapSelector('.vp-chart-setting-body input')).prop('disabled', false);
55+
}
56+
});
4657
}
4758

4859
templateForBody() {
@@ -113,31 +124,40 @@ define([
113124
generateImportCode() {
114125
var code = new com_String();
115126
code.appendLine('import matplotlib.pyplot as plt');
116-
code.append('import seaborn as sns');
127+
code.appendLine('import seaborn as sns');
128+
code.append('%matplotlib inline');
117129
return [code.toString()];
118130
}
119131

120132
generateCode() {
121133
var code = new com_String();
122134

123135
// get parameters
124-
let { figureWidth, figureHeight, styleSheet, fontName, fontSize } = this.state;
125-
126-
code.appendLine('import matplotlib.pyplot as plt');
127-
code.appendFormatLine("plt.rc('figure', figsize=({0}, {1}))", figureWidth, figureHeight);
128-
if (styleSheet && styleSheet.length > 0) {
129-
code.appendFormatLine("plt.style.use('{0}')", styleSheet);
130-
}
131-
code.appendLine();
132-
133-
code.appendLine('from matplotlib import rcParams');
134-
if (fontName && fontName.length > 0) {
135-
code.appendFormatLine("rcParams['font.family'] = '{0}'", fontName);
136-
}
137-
if (fontSize && fontSize.length > 0) {
138-
code.appendFormatLine("rcParams['font.size'] = {0}", fontSize);
136+
let setDefault = $(this.wrapSelector('#setDefault')).prop('checked');
137+
if (setDefault == true) {
138+
code.appendLine('from matplotlib import rcParams, rcParamsDefault');
139+
code.append('rcParams.update(rcParamsDefault)');
140+
} else {
141+
// get parameters
142+
let { figureWidth, figureHeight, styleSheet, fontName, fontSize } = this.state;
143+
144+
code.appendLine('import matplotlib.pyplot as plt');
145+
code.appendLine('import seaborn as sns');
146+
code.appendFormatLine("plt.rc('figure', figsize=({0}, {1}))", figureWidth, figureHeight);
147+
if (styleSheet && styleSheet.length > 0) {
148+
code.appendFormatLine("plt.style.use('{0}')", styleSheet);
149+
}
150+
code.appendLine();
151+
152+
code.appendLine('from matplotlib import rcParams');
153+
if (fontName && fontName.length > 0) {
154+
code.appendFormatLine("rcParams['font.family'] = '{0}'", fontName);
155+
}
156+
if (fontSize && fontSize.length > 0) {
157+
code.appendFormatLine("rcParams['font.size'] = {0}", fontSize);
158+
}
159+
code.append("rcParams['axes.unicode_minus'] = False");
139160
}
140-
code.append("rcParams['axes.unicode_minus'] = False");
141161

142162
return code.toString();
143163
}

js/m_visualize/Seaborn.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ define([
491491
var fontSize = $(this.wrapSelector('#fontSize')).val();
492492

493493
code.appendLine('import matplotlib.pyplot as plt');
494+
code.appendLine('import seaborn as sns');
494495
code.appendFormatLine("plt.rc('figure', figsize=({0}, {1}))", figWidth, figHeight);
495496
if (styleName && styleName.length > 0) {
496497
code.appendFormatLine("plt.style.use('{0}')", styleName);

0 commit comments

Comments
 (0)