Initial commit
This commit is contained in:
+388
@@ -0,0 +1,388 @@
|
||||
import os
|
||||
import random
|
||||
import time
|
||||
|
||||
import pandas as pd
|
||||
|
||||
from Simple_Drawing.settings import BASE_DIR
|
||||
|
||||
url_ = "127.0.0.1:8000"
|
||||
|
||||
|
||||
# 保存单个文件
|
||||
def keep_file(file_data, file_path, file_name=None, ui=0):
|
||||
if file_name is not None:
|
||||
file_path = os.path.join(file_path, file_name)
|
||||
if ui:
|
||||
with open(file_path, 'w') as f:
|
||||
f.write(file_data)
|
||||
else:
|
||||
with open(file_path, 'wb+') as f:
|
||||
for chunk1 in file_data.chunks():
|
||||
f.write(chunk1)
|
||||
|
||||
|
||||
# 保存多个文件
|
||||
def keep_files(na, c):
|
||||
cmd = '''
|
||||
cd %s/file_keep/%s
|
||||
mkdir morefile
|
||||
''' % (BASE_DIR, c)
|
||||
os.system(cmd)
|
||||
|
||||
for file in na:
|
||||
with open('%s' % os.path.join(f'{BASE_DIR}/file_keep/{c}/morefile/', file.name), 'wb') as f:
|
||||
for i in file.chunks():
|
||||
f.write(i)
|
||||
f.close()
|
||||
|
||||
|
||||
# 返回唯一文件编号
|
||||
def generate_id():
|
||||
a = time.asctime(time.localtime(time.time()))
|
||||
b = a[-15:] + str(random.randint(0, 1000))
|
||||
c = b.replace(" ", "")
|
||||
c = c.replace(":", "0")
|
||||
return c
|
||||
|
||||
|
||||
# 给出文件路径
|
||||
def path_out(sort, name=generate_id(), show=None, out=None):
|
||||
if show == 1:
|
||||
return os.path.join(BASE_DIR, "static", "img_eg", "show_chart", name)
|
||||
if out == 1:
|
||||
return os.path.join(BASE_DIR, 'file_keep', sort, "img", name)
|
||||
return os.path.join(BASE_DIR, 'file_keep', sort, "file", name), name
|
||||
|
||||
|
||||
# 选出需要的列
|
||||
def pick_col(file_path, col, sep=","):
|
||||
midwest = pd.read_csv(file_path, sep=sep)
|
||||
col = set(midwest[col])
|
||||
return col
|
||||
|
||||
|
||||
# 返回页数
|
||||
def return_pages(su: int) -> int:
|
||||
if su % 12 != 0:
|
||||
return (su // 12) + 1
|
||||
else:
|
||||
return su // 12
|
||||
|
||||
|
||||
class ChartParameter(object):
|
||||
def __init__(self, data):
|
||||
if 'name' in data:
|
||||
self.name = data['name']
|
||||
if 'html_name' in data:
|
||||
self.html_name = data['html_name']
|
||||
if 'value' in data:
|
||||
self.value = data['value']
|
||||
if 'astrict' in data:
|
||||
self.astrict = data['astrict']
|
||||
if 'input_type' in data:
|
||||
self.input_type = data['input_type']
|
||||
if 'Basics' in data:
|
||||
self.Basics = data['Basics']
|
||||
if 'Senior' in data:
|
||||
self.Senior = data['Senior']
|
||||
|
||||
self.colors = 0
|
||||
self.colors_dict = {}
|
||||
|
||||
def html_out_Basics(self):
|
||||
code = ""
|
||||
for title in self.Basics:
|
||||
code += f"""
|
||||
<dd style="overflow: hidden">
|
||||
<div class="color">
|
||||
<label style="" class="label_meg"><b>{title} </b></label>
|
||||
</div>
|
||||
</dd>
|
||||
"""
|
||||
for d in self.Basics[title]:
|
||||
parameter = ChartParameter(d)
|
||||
if parameter.input_type == "text":
|
||||
parameter.input_type = f"""
|
||||
<input {parameter.astrict} type="text" id="{parameter.name}" lay-verify="required" value="{parameter.value}"
|
||||
autocomplete="off" class="layui-input"
|
||||
style="height: 25px; width:80px;margin-top: 6px">
|
||||
"""
|
||||
if parameter.input_type == "number":
|
||||
parameter.input_type = f"""
|
||||
<input {parameter.astrict} type="number" id="{parameter.name}" lay-verify="required" value="{parameter.value}"
|
||||
autocomplete="off" class="layui-input" min="0" max="999"
|
||||
style="height: 25px; width:80px;margin-top: 6px">
|
||||
"""
|
||||
if parameter.input_type == "date":
|
||||
parameter.input_type = f"""
|
||||
<input {parameter.astrict} type="date" id="{parameter.name}" lay-verify="required" value="{parameter.value}"
|
||||
autocomplete="off" class="layui-input"
|
||||
style="height: 25px; width:80px;margin-top: 6px">
|
||||
"""
|
||||
if parameter.input_type == "color_name":
|
||||
self.colors_dict[f"color{self.colors}"] = "color_name"
|
||||
parameter.input_type = f"""
|
||||
<div style="margin-left: 30px;">
|
||||
<div id="color{self.colors}" style="margin-left: 30px; display: inline-block"></div>
|
||||
</div>
|
||||
"""
|
||||
self.colors += 1
|
||||
if parameter.input_type == "rgb":
|
||||
self.colors_dict[f"color{self.colors}"] = "rgb"
|
||||
f"""
|
||||
<div style="margin-left: 30px;">
|
||||
<div id="color{self.colors}" style="margin-left: 30px; display: inline-block"></div>
|
||||
</div>
|
||||
"""
|
||||
self.colors += 1
|
||||
|
||||
if parameter.input_type == "palettes":
|
||||
parameter.input_type = f"""
|
||||
<select {parameter.astrict} id="{parameter.name}" lay-verify="required" value="{parameter.value}" autocomplete="off"
|
||||
class="layui-input" style="height: 25px; width:80px;margin-top: 6px">
|
||||
<option value="YlOrRd">YlOrRd</option>
|
||||
<option value="YlOrBr">YlOrBr</option>
|
||||
<option value="YlGnBu">YlGnBu</option>
|
||||
<option value="Reds">Reds</option>
|
||||
<option value="RdPu">RdPu</option>
|
||||
<option value="Purples">Purples</option>
|
||||
<option value="PuRd">PuRd</option>
|
||||
<option value="PuBuGn">PuBuGn</option>
|
||||
<option value="PuBu">PuBu</option>
|
||||
<option value="OrRd">OrRd</option>
|
||||
<option value="Oranges">Oranges</option>
|
||||
<option value="Greys">Greys</option>
|
||||
<option value="Greens">Greens</option>
|
||||
<option value="GnBu">GnBu</option>
|
||||
<option value="BuPn">BuPn</option>
|
||||
<option value="BuGn">BuGn</option>
|
||||
<option value="Blues">Blues</option>
|
||||
<option value="Set3">Set3</option>
|
||||
<option value="Set2">Set2</option>
|
||||
<option value="Set1">Set1</option>
|
||||
<option value="Pastel2">Pastel2</option>
|
||||
<option value="Pastel1">Pastel1</option>
|
||||
<option value="Paired">Paired</option>
|
||||
<option value="Dark2">Dark2</option>
|
||||
<option value="Accent">Accent</option>
|
||||
<option value="Spectral">Spectral</option>
|
||||
<option value="RdYlGn">RdYlGn</option>
|
||||
<option value="RdYlBn">RdYlBn</option>
|
||||
<option value="RdGy">RdGy</option>
|
||||
<option value="RdBu">RdBu</option>
|
||||
<option value="PuOr">PuOr</option>
|
||||
<option value="PRGn">PRGn</option>
|
||||
<option value="PiYG">PiYG</option>
|
||||
<option value="BrBG">BrBG</option>
|
||||
</select>
|
||||
"""
|
||||
if parameter.input_type == "add":
|
||||
parameter.input_type = f"""
|
||||
<select {parameter.astrict} id="{parameter.name}" lay-verify="required" value="{parameter.value}" autocomplete="off"
|
||||
class="layui-input" style="height: 25px; width:80px;margin-top: 6px">
|
||||
<option value="TRUE">YES</option>
|
||||
<option value="FALSE">NO</option>
|
||||
</select>
|
||||
"""
|
||||
if parameter.input_type == "position":
|
||||
parameter.input_type = f"""
|
||||
<select {parameter.astrict} id="{parameter.name}" lay-verify="required" value="{parameter.value}" autocomplete="off"
|
||||
class="layui-input" style="height: 25px; width:80px;margin-top: 6px">
|
||||
<option value="right">Right</option>
|
||||
<option value="left">Left</option>
|
||||
<option value="top">Top</option>
|
||||
<option value="bottom">Bottom</option>
|
||||
</select>
|
||||
"""
|
||||
|
||||
code += f"""
|
||||
<dd style="overflow: hidden">
|
||||
<div class="color">
|
||||
<label class="label_meg">{parameter.html_name} </label>
|
||||
<div class="layui-input-inline" style="float: right">
|
||||
{parameter.input_type}
|
||||
</div>
|
||||
</div>
|
||||
</dd>
|
||||
"""
|
||||
return code
|
||||
|
||||
def html_out_Senior(self):
|
||||
code = ""
|
||||
for title in self.Senior:
|
||||
code += f"""
|
||||
<dd style="overflow: hidden">
|
||||
<div class="color">
|
||||
<label style="" class="label_meg"><b>{title} </b></label>
|
||||
</div>
|
||||
</dd>
|
||||
"""
|
||||
for d in self.Senior[title]:
|
||||
parameter = ChartParameter(d)
|
||||
if parameter.input_type == "text":
|
||||
parameter.input_type = f"""
|
||||
<input {parameter.astrict} type="text" id="{parameter.name}" lay-verify="required" value="{parameter.value}"
|
||||
autocomplete="off" class="layui-input"
|
||||
style="height: 25px; width:80px;margin-top: 6px">
|
||||
"""
|
||||
if parameter.input_type == "number":
|
||||
parameter.input_type = f"""
|
||||
<input {parameter.astrict} type="number" id="{parameter.name}" lay-verify="required" value="{parameter.value}"
|
||||
autocomplete="off" class="layui-input" min="0" max="999"
|
||||
style="height: 25px; width:80px;margin-top: 6px">
|
||||
"""
|
||||
if parameter.input_type == "date":
|
||||
parameter.input_type = f"""
|
||||
<input {parameter.astrict} type="date" id="{parameter.name}" lay-verify="required" value="{parameter.value}"
|
||||
autocomplete="off" class="layui-input
|
||||
style="height: 25px; width:80px;margin-top: 6px">
|
||||
"""
|
||||
if parameter.input_type == "color_name":
|
||||
self.colors_dict[f"color{self.colors}"] = "color_name"
|
||||
parameter.input_type = f"""
|
||||
<div style="margin-left: 30px;">
|
||||
<div id="color{self.colors}" style="margin-left: 30px; display: inline-block"></div>
|
||||
</div>
|
||||
"""
|
||||
self.colors += 1
|
||||
if parameter.input_type == "rgb":
|
||||
self.colors_dict[f"color{self.colors}"] = "rgb"
|
||||
f"""
|
||||
<div style="margin-left: 30px;">
|
||||
<div id="color{self.colors}" style="margin-left: 30px; display: inline-block"></div>
|
||||
</div>
|
||||
"""
|
||||
self.colors += 1
|
||||
if parameter.input_type == "palettes":
|
||||
parameter.input_type = f"""
|
||||
<select {parameter.astrict} id="{parameter.name}" lay-verify="required" value="{parameter.value}" autocomplete="off"
|
||||
class="layui-input" style="height: 25px; width:80px;margin-top: 6px">
|
||||
<option value="YlOrRd">YlOrRd</option>
|
||||
<option value="YlOrBr">YlOrBr</option>
|
||||
<option value="YlGnBu">YlGnBu</option>
|
||||
<option value="Reds">Reds</option>
|
||||
<option value="RdPu">RdPu</option>
|
||||
<option value="Purples">Purples</option>
|
||||
<option value="PuRd">PuRd</option>
|
||||
<option value="PuBuGn">PuBuGn</option>
|
||||
<option value="PuBu">PuBu</option>
|
||||
<option value="OrRd">OrRd</option>
|
||||
<option value="Oranges">Oranges</option>
|
||||
<option value="Greys">Greys</option>
|
||||
<option value="Greens">Greens</option>
|
||||
<option value="GnBu">GnBu</option>
|
||||
<option value="BuPn">BuPn</option>
|
||||
<option value="BuGn">BuGn</option>
|
||||
<option value="Blues">Blues</option>
|
||||
<option value="Set3">Set3</option>
|
||||
<option value="Set2">Set2</option>
|
||||
<option value="Set1">Set1</option>
|
||||
<option value="Pastel2">Pastel2</option>
|
||||
<option value="Pastel1">Pastel1</option>
|
||||
<option value="Paired">Paired</option>
|
||||
<option value="Dark2">Dark2</option>
|
||||
<option value="Accent">Accent</option>
|
||||
<option value="Spectral">Spectral</option>
|
||||
<option value="RdYlGn">RdYlGn</option>
|
||||
<option value="RdYlBn">RdYlBn</option>
|
||||
<option value="RdGy">RdGy</option>
|
||||
<option value="RdBu">RdBu</option>
|
||||
<option value="PuOr">PuOr</option>
|
||||
<option value="PRGn">PRGn</option>
|
||||
<option value="PiYG">PiYG</option>
|
||||
<option value="BrBG">BrBG</option>
|
||||
</select>
|
||||
"""
|
||||
if parameter.input_type == "add":
|
||||
parameter.input_type = f"""
|
||||
<select {parameter.astrict} id="{parameter.name}" lay-verify="required" value="{parameter.value}" autocomplete="off"
|
||||
class="layui-input" style="height: 25px; width:80px;margin-top: 6px">
|
||||
<option value="TRUE">YES</option>
|
||||
<option value="FALSE">NO</option>
|
||||
</select>
|
||||
"""
|
||||
if parameter.input_type == "position":
|
||||
parameter.input_type = f"""
|
||||
<select {parameter.astrict} id="{parameter.name}" lay-verify="required" value="{parameter.value}" autocomplete="off"
|
||||
class="layui-input" style="height: 25px; width:80px;margin-top: 6px">
|
||||
<option value="right">Right</option>
|
||||
<option value="left">Left</option>
|
||||
<option value="top">Top</option>
|
||||
<option value="bottom">Bottom</option>
|
||||
</select>
|
||||
"""
|
||||
|
||||
code += f"""
|
||||
<dd style="overflow: hidden">
|
||||
<div class="color">
|
||||
<label class="label_meg">{parameter.html_name} </label>
|
||||
<div class="layui-input-inline" style="float: right">
|
||||
{parameter.input_type}
|
||||
</div>
|
||||
</div>
|
||||
</dd>
|
||||
"""
|
||||
return code
|
||||
|
||||
def js_out(self):
|
||||
code = ""
|
||||
for title in self.Basics:
|
||||
for d in self.Basics[title]:
|
||||
parameter = ChartParameter(d)
|
||||
code += f"""{parameter.name}: (document.getElementById("{parameter.name}").value),
|
||||
"""
|
||||
for title in self.Senior:
|
||||
for d in self.Senior[title]:
|
||||
parameter = ChartParameter(d)
|
||||
code += f"""{parameter.name}: (document.getElementById("{parameter.name}").value),
|
||||
"""
|
||||
return code
|
||||
|
||||
def color_js(self):
|
||||
code = ""
|
||||
for i in self.colors_dict.keys():
|
||||
if self.colors_dict[i] == "rgb":
|
||||
fl = "rgb"
|
||||
else:
|
||||
fl = "hex"
|
||||
code += """
|
||||
layui.use('colorpicker', function()
|
||||
{
|
||||
var $ = layui.$
|
||||
, colorpicker = layui.colorpicker;
|
||||
|
||||
colorpicker.render({
|
||||
elem: '%s'
|
||||
, color: '#2ec770' //设置默认色
|
||||
, size: "xs"
|
||||
, format: '%s'
|
||||
, done: function (color) {
|
||||
layer.tips('选择了:' + color, this.elem);
|
||||
}
|
||||
});
|
||||
})
|
||||
""" % (i, fl)
|
||||
|
||||
return code
|
||||
|
||||
|
||||
Treemap = {
|
||||
"Basics": {
|
||||
"title": [
|
||||
{"name": "title", "value": "title", "astrict": "", "input_type": "text", "html_name": "Title"},
|
||||
{"name": "title_font_size", "value": "12", "astrict": "", "input_type": "number", "html_name": "Title Size"}
|
||||
],
|
||||
"data": [
|
||||
{"name": "group_by_column", "value": "group_by_column", "astrict": "", "input_type": "text",
|
||||
"html_name": "Group By Column"},
|
||||
{"name": "data_column", "value": "data_column", "astrict": "", "input_type": "text",
|
||||
"html_name": "Data Column"}
|
||||
]
|
||||
},
|
||||
"Senior": {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user