Update CoreDraw.py

This commit is contained in:
Redsandy 2022-03-17 00:36:05 +03:00 committed by GitHub
parent 4c7e3e296c
commit 4438bcd4ae

View File

@ -71,22 +71,46 @@ class corePlt():
self.row=params['row']
self.col=params['col']
self.name=params['name']
if 'colorType' in params.keys():
self.colorType=params['colorType']
class coreDraw():
def __init__(self, data=[], needShow=False,subplot_titles={}):
def __init__(self, data=[],needShow=False):
self.data=self.getPlts(data)
self.needShow=needShow
self.subplot_titles=subplot_titles
self.ans=self.getAns()
def getBarColorList(self,l,colorType):
if colorType=='diffAbs':
ans=['green']
for i in range(1,len(l)):
if abs(l[i])>abs(l[i-1]):
ans.append('green')
else:
ans.append('red')
elif colorType=='diff':
ans=['green']
for i in range(1,len(l)):
if (l[i])>(l[i-1]):
ans.append('green')
else:
ans.append('red')
elif colorType=='normal':
ans=[]
for i in range(len(l)):
ans.append('gray')
return ans
def getPlts(self, data):
ans=None
@ -132,17 +156,16 @@ class coreDraw():
rows=maxRow,
cols=maxCol,
shared_xaxes=True,
#vertical_spacing=0.2,
vertical_spacing=0.02,
shared_yaxes=True,
#horizontal_spacing=0.2,
horizontal_spacing=0.02,
#column_widths=[]
subplot_titles=self.subplot_titles
)
fig.update_layout(xaxis_rangeslider_visible=False)
fig.update_layout(barmode='relative')
for i in self.data:
if i.vtype=='Scatter':
@ -157,6 +180,16 @@ class coreDraw():
name=i.name),
row=i.row, col=i.col
)
elif i.vtype=='Bars':
for j in i.df.keys():
if j!='date':
try:
colorType=i.colorType
except:
colorType='normal'
colors=self.getBarColorList(i.df[j],colorType)
fig.add_trace(go.Bar(x=i.df['date'], y=i.df[j],name=j,marker_color=colors))
@ -164,7 +197,3 @@ class coreDraw():
if self.needShow:
plotly.offline.iplot(fig)
return ans