Best Python code snippet using autotest_python
sql_chart.py
Source:sql_chart.py
...111 zdict[ylist[i]]=[]112 for row in datas:113 zdict[row[1]].append(str(row[2])) 114 if chart_type == 'line': # æ线å¾115 if style.setdefault('toolbox_opts_is_show',False):116 toolbox_opts=opts.ToolboxOpts()117 else:118 toolbox_opts=None119 120 if style.setdefault('datazoom_opts',None)=='horizontal':121 datazoom_opts=opts.DataZoomOpts()122 elif style.setdefault('datazoom_opts',None)=='vertical':123 datazoom_opts=opts.DataZoomOpts(orient="vertical")124 elif style.setdefault('datazoom_opts',None)=='inside':125 datazoom_opts=opts.DataZoomOpts(type_="inside")126 else:127 datazoom_opts=None128 129 c = Line(themetype)130 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),131 pos_right=style.setdefault('title_pos_right',None)),132 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),133 pos_left=style.setdefault('legend_pos_left',None),134 pos_right=style.setdefault('legend_pos_right',None)),135 toolbox_opts=toolbox_opts,136 datazoom_opts=datazoom_opts,137 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),138 formatter=style.setdefault('xaxis_opts_formatter',"{value}")),139 axistick_opts=opts.AxisTickOpts(is_align_with_label=True),140 is_scale=False,141 boundary_gap=False,),142 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))), 143 )144 c.add_xaxis(xlist)145 for i in range(len(ylist)):146 name = ylist[i]147 c.add_yaxis(name, zdict[name],148 markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_=style.setdefault('type_',"max"))]),149 is_smooth=style.setdefault('is_smooth',True),150 label_opts=opts.LabelOpts(is_show=style.setdefault('is_show',False)),151 areastyle_opts=opts.AreaStyleOpts(opacity=style.setdefault('opacity',0))152 ) 153 return c154 elif chart_type == 'pie':# 饼å¾155 if style.setdefault('toolbox_opts_is_show',False):156 toolbox_opts=opts.ToolboxOpts()157 else:158 toolbox_opts=None159 160 if style.setdefault('datazoom_opts',None)=='horizontal':161 datazoom_opts=opts.DataZoomOpts()162 elif style.setdefault('datazoom_opts',None)=='vertical':163 datazoom_opts=opts.DataZoomOpts(orient="vertical")164 elif style.setdefault('datazoom_opts',None)=='inside':165 datazoom_opts=opts.DataZoomOpts(type_="inside")166 else:167 datazoom_opts=None168 c = Pie(themetype)169 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),170 pos_right=style.setdefault('title_pos_right',None)),171 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),172 pos_left=style.setdefault('legend_pos_left',None),173 pos_right=style.setdefault('legend_pos_right',None)),174 toolbox_opts=toolbox_opts,175 datazoom_opts=datazoom_opts,176 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),177 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),178 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),179 )180 for i in range(len(ylist)):181 name = ylist[i]182 data_pair = list(zip(xlist,zdict[name]))183 c.add(series_name=name,data_pair=data_pair,184 rosetype=style.setdefault('rosetype',None),#"radius"185 radius=style.setdefault('radius',None),#["30%", "55%"]186 center=style.setdefault('center',None),#["75%", "50%"]187 )188 c.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))189 return c190 elif chart_type == 'bar': # æ±å½¢å¾191 if style.setdefault('toolbox_opts_is_show',False):192 toolbox_opts=opts.ToolboxOpts()193 else:194 toolbox_opts=None195 196 if style.setdefault('datazoom_opts',None)=='horizontal':197 datazoom_opts=opts.DataZoomOpts()198 elif style.setdefault('datazoom_opts',None)=='vertical':199 datazoom_opts=opts.DataZoomOpts(orient="vertical")200 elif style.setdefault('datazoom_opts',None)=='inside':201 datazoom_opts=opts.DataZoomOpts(type_="inside")202 else:203 datazoom_opts=None204 205 c = Bar(themetype)206 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),207 pos_right=style.setdefault('title_pos_right',None)),208 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),209 pos_left=style.setdefault('legend_pos_left',None),210 pos_right=style.setdefault('legend_pos_right',None)),211 toolbox_opts=toolbox_opts,212 datazoom_opts=datazoom_opts,213 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),214 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),215 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),216 )217 c.add_xaxis(xlist)218 for i in range(len(ylist)):219 name = ylist[i]220 c.add_yaxis(name, zdict[name]) 221 #翻转 XY è½´222 #c.reversal_axis()223 #c.set_series_opts(label_opts=opts.LabelOpts(position="right")) 224 #ç¹ï¼çº¿ çæ大å¼,æå°å¼,å¹³åå¼225 #c.set_series_opts(226 # label_opts=opts.LabelOpts(is_show=False),227 # markpoint_opts=opts.MarkPointOpts(228 # data=[229 # opts.MarkPointItem(type_="max", name="æ大å¼"),230 # opts.MarkPointItem(type_="min", name="æå°å¼"),231 # opts.MarkPointItem(type_="average", name="å¹³åå¼"),232 # ]233 # ),234 # markline_opts=opts.MarkLineOpts(235 # data=[236 # opts.MarkLineItem(type_="min", name="æå°å¼"),237 # opts.MarkLineItem(type_="max", name="æ大å¼"),238 # opts.MarkLineItem(type_="average", name="å¹³åå¼"),239 #èªå®ä¹ 线240 # opts.MarkLineItem(y=50, name="yAxis=50")241 # ]242 # ),243 #) 244 return c245 elif chart_type == 'calendar': # æ¥åå¾246 if style.setdefault('toolbox_opts_is_show',False):247 toolbox_opts=opts.ToolboxOpts()248 else:249 toolbox_opts=None250 251 if style.setdefault('datazoom_opts',None)=='horizontal':252 datazoom_opts=opts.DataZoomOpts()253 elif style.setdefault('datazoom_opts',None)=='vertical':254 datazoom_opts=opts.DataZoomOpts(orient="vertical")255 elif style.setdefault('datazoom_opts',None)=='inside':256 datazoom_opts=opts.DataZoomOpts(type_="inside")257 else:258 datazoom_opts=None259 260 c = Calendar(themetype)261 c.add("", datas, calendar_opts=opts.CalendarOpts(range_=xlist[0]))262 c.set_global_opts(263 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),264 pos_right=style.setdefault('title_pos_right',None)),265 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),266 pos_left=style.setdefault('legend_pos_left',None),267 pos_right=style.setdefault('legend_pos_right',None)),268 toolbox_opts=toolbox_opts,269 datazoom_opts=datazoom_opts,270 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),271 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),272 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),273 visualmap_opts=opts.VisualMapOpts(274 max_=style.setdefault('max_',20000),275 min_=style.setdefault('min_',500),276 orient=style.setdefault('orient',"horizontal"),277 is_piecewise=style.setdefault('is_piecewise',True),278 pos_top=style.setdefault('pos_top',"230px"),279 pos_left=style.setdefault('pos_left',"100px"))280 )281 return c282 elif chart_type == 'funnel': # æ¼æå¾283 if style.setdefault('toolbox_opts_is_show',False):284 toolbox_opts=opts.ToolboxOpts()285 else:286 toolbox_opts=None287 288 if style.setdefault('datazoom_opts',None)=='horizontal':289 datazoom_opts=opts.DataZoomOpts()290 elif style.setdefault('datazoom_opts',None)=='vertical':291 datazoom_opts=opts.DataZoomOpts(orient="vertical")292 elif style.setdefault('datazoom_opts',None)=='inside':293 datazoom_opts=opts.DataZoomOpts(type_="inside")294 else:295 datazoom_opts=None296 297 c = Funnel(themetype)298 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),299 pos_right=style.setdefault('title_pos_right',None)),300 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),301 pos_left=style.setdefault('legend_pos_left',None),302 pos_right=style.setdefault('legend_pos_right',None)),303 toolbox_opts=toolbox_opts,304 datazoom_opts=datazoom_opts,305 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),306 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),307 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),308 )309 c.add("", datas, sort_=style.setdefault('sort_',"descending"),label_opts=opts.LabelOpts(position=style.setdefault('position',"inside")))310 return c311 elif chart_type == 'gauge': # 仪表ç312 if style.setdefault('toolbox_opts_is_show',False):313 toolbox_opts=opts.ToolboxOpts()314 else:315 toolbox_opts=None316 317 if style.setdefault('datazoom_opts',None)=='horizontal':318 datazoom_opts=opts.DataZoomOpts()319 elif style.setdefault('datazoom_opts',None)=='vertical':320 datazoom_opts=opts.DataZoomOpts(orient="vertical")321 elif style.setdefault('datazoom_opts',None)=='inside':322 datazoom_opts=opts.DataZoomOpts(type_="inside")323 else:324 datazoom_opts=None325 326 c = Gauge(themetype)327 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),328 pos_right=style.setdefault('title_pos_right',None)),329 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),330 pos_left=style.setdefault('legend_pos_left',None),331 pos_right=style.setdefault('legend_pos_right',None)),332 toolbox_opts=toolbox_opts,333 datazoom_opts=datazoom_opts,334 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),335 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),336 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),337 )338 c.add("", datas, title_label_opts=opts.LabelOpts(339 font_size=style.setdefault('font_size', 40), 340 color=style.setdefault('color', "blue"), 341 font_family=style.setdefault('font_family', "Microsoft YaHei")342 ))343 return c344 elif chart_type == 'graph': # å
³ç³»å¾345 if style.setdefault('toolbox_opts_is_show',False):346 toolbox_opts=opts.ToolboxOpts()347 else:348 toolbox_opts=None349 350 if style.setdefault('datazoom_opts',None)=='horizontal':351 datazoom_opts=opts.DataZoomOpts()352 elif style.setdefault('datazoom_opts',None)=='vertical':353 datazoom_opts=opts.DataZoomOpts(orient="vertical")354 elif style.setdefault('datazoom_opts',None)=='inside':355 datazoom_opts=opts.DataZoomOpts(type_="inside")356 else:357 datazoom_opts=None358 359 c = Graph(themetype)360 xs = f_get_query_record(conn, x,database_type)361 nodes = []362 for row in xs:363 nodes.append({"name": row[0], "symbolSize": row[1]})364 links = []365 for row in datas:366 links.append({"source": row[0], "target": row[1]})367 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),368 pos_right=style.setdefault('title_pos_right',None)),369 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),370 pos_left=style.setdefault('legend_pos_left',None),371 pos_right=style.setdefault('legend_pos_right',None)),372 toolbox_opts=toolbox_opts,373 datazoom_opts=datazoom_opts,374 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),375 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),376 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),377 )378 c.add("", nodes, links, repulsion=style.setdefault('repulsion',4000))379 return c380 elif chart_type == 'graph2': # å
³ç³»å¾2381 if style.setdefault('toolbox_opts_is_show',False):382 toolbox_opts=opts.ToolboxOpts()383 else:384 toolbox_opts=None385 386 if style.setdefault('datazoom_opts',None)=='horizontal':387 datazoom_opts=opts.DataZoomOpts()388 elif style.setdefault('datazoom_opts',None)=='vertical':389 datazoom_opts=opts.DataZoomOpts(orient="vertical")390 elif style.setdefault('datazoom_opts',None)=='inside':391 datazoom_opts=opts.DataZoomOpts(type_="inside")392 else:393 datazoom_opts=None394 xs = f_get_query_record(conn, x,database_type)395 nodes = []396 for row in xs:397 if row[4] !='':398 label =eval(row[4])399 else:400 label =''401 nodes.append({"name": row[0], "symbolSize": row[1],"category": row[2],"draggable": row[3],"label": label,"value": row[5]})402 ys = f_get_query_record(conn, y,database_type)403 categories = []404 for row in ys:405 categories.append({"name": row[0]}) 406 links = []407 for row in datas:408 links.append({"source": row[0], "target": row[1]})409 410 c = Graph(themetype)411 c.add(412 "",413 nodes,414 links,415 categories,416 repulsion=style.setdefault('repulsion',50),417 linestyle_opts=opts.LineStyleOpts(curve=0.2),418 label_opts=opts.LabelOpts(is_show=style.setdefault('label_opts_is_show',False)),419 )420 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),421 pos_right=style.setdefault('title_pos_right',None)),422 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),423 pos_left=style.setdefault('legend_pos_left',None),424 pos_right=style.setdefault('legend_pos_right',None),425 is_show=style.setdefault('legend_opts_is_show',False)),426 toolbox_opts=toolbox_opts,427 datazoom_opts=datazoom_opts,428 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),429 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),430 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),431 )432 return c433 elif chart_type == 'graph3': # å
³ç³»å¾3434 if style.setdefault('toolbox_opts_is_show',False):435 toolbox_opts=opts.ToolboxOpts()436 else:437 toolbox_opts=None438 439 if style.setdefault('datazoom_opts',None)=='horizontal':440 datazoom_opts=opts.DataZoomOpts()441 elif style.setdefault('datazoom_opts',None)=='vertical':442 datazoom_opts=opts.DataZoomOpts(orient="vertical")443 elif style.setdefault('datazoom_opts',None)=='inside':444 datazoom_opts=opts.DataZoomOpts(type_="inside")445 else:446 datazoom_opts=None447 448 xs = f_get_query_record(conn, x,database_type)449 nodes = []450 for row in xs:451 if row[4] !='':452 label =eval(row[4])453 nodes.append({"id": row[0],"name": row[1], "symbolSize": float(row[2]),"category": int(row[3]),"label": label,"value": float(row[5]),"x": float(row[6]),"y": float(row[7])})454 ys = f_get_query_record(conn, y,database_type)455 categories = []456 for row in ys:457 categories.append({"name": row[0]}) 458 links = []459 for row in datas:460 links.append({"id": row[0], "source": row[1], "target": row[2]})461 c = Graph(themetype)462 c.add(463 "",464 nodes=nodes,465 links=links,466 categories=categories,467 layout=style.setdefault('layout',"circular"),468 is_rotate_label=style.setdefault('is_rotate_label',True),469 linestyle_opts=opts.LineStyleOpts(color=style.setdefault('color',"source"), curve=style.setdefault('curve',0.3)),470 label_opts=opts.LabelOpts(position=style.setdefault('position',"right")),471 )472 c.set_global_opts(473 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),474 pos_right=style.setdefault('title_pos_right',None)),475 legend_opts=opts.LegendOpts(orient=style.setdefault('orient',"vertical"),476 pos_top=style.setdefault('legend_pos_top',None),477 pos_left=style.setdefault('legend_pos_left',None),478 pos_right=style.setdefault('legend_pos_right',None),479 ),480 toolbox_opts=toolbox_opts,481 datazoom_opts=datazoom_opts,482 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),483 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),484 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),485 )486 return c487 elif chart_type == 'graph4': # å
³ç³»å¾4488 if style.setdefault('toolbox_opts_is_show',False):489 toolbox_opts=opts.ToolboxOpts()490 else:491 toolbox_opts=None492 493 if style.setdefault('datazoom_opts',None)=='horizontal':494 datazoom_opts=opts.DataZoomOpts()495 elif style.setdefault('datazoom_opts',None)=='vertical':496 datazoom_opts=opts.DataZoomOpts(orient="vertical")497 elif style.setdefault('datazoom_opts',None)=='inside':498 datazoom_opts=opts.DataZoomOpts(type_="inside")499 else:500 datazoom_opts=None501 502 xs = f_get_query_record(conn, x,database_type)503 nodes = []504 for row in xs:505 nodes.append({506 "x": float(row[0]),507 "y": float(row[1]),508 "id": row[2],509 "name": row[3], 510 "symbolSize": float(row[4]),511 "itemStyle": eval(row[5])512 })513 links = []514 for row in datas:515 links.append({"source": row[0], "target": row[1]})516 #file=open('a.txt','w') 517 #file.writelines([str(line)+"\n" for line in nodes]); 518 #file.close() 519 c = Graph(themetype)520 c.add(521 "",522 nodes=nodes,523 links=links,524 layout=style.setdefault('layout',"none"),525 label_opts=opts.LabelOpts(is_show=style.setdefault('is_show',False)),526 linestyle_opts=opts.LineStyleOpts(width=style.setdefault('width',0.5), curve=style.setdefault('curve',0.3), opacity=style.setdefault('opacity',0.7)),527 )528 c.set_global_opts(529 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),530 pos_right=style.setdefault('title_pos_right',None)),531 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),532 pos_left=style.setdefault('legend_pos_left',None),533 pos_right=style.setdefault('legend_pos_right',None),534 ),535 toolbox_opts=toolbox_opts,536 datazoom_opts=datazoom_opts,537 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),538 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),539 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),540 )541 return c542 elif chart_type == 'liquid': # æ°´çå¾543 if style.setdefault('toolbox_opts_is_show',False):544 toolbox_opts=opts.ToolboxOpts()545 else:546 toolbox_opts=None547 548 if style.setdefault('datazoom_opts',None)=='horizontal':549 datazoom_opts=opts.DataZoomOpts()550 elif style.setdefault('datazoom_opts',None)=='vertical':551 datazoom_opts=opts.DataZoomOpts(orient="vertical")552 elif style.setdefault('datazoom_opts',None)=='inside':553 datazoom_opts=opts.DataZoomOpts(type_="inside")554 else:555 datazoom_opts=None556 557 c = Liquid(themetype)558 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),559 pos_right=style.setdefault('title_pos_right',None)),560 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),561 pos_left=style.setdefault('legend_pos_left',None),562 pos_right=style.setdefault('legend_pos_right',None)),563 toolbox_opts=toolbox_opts,564 datazoom_opts=datazoom_opts,565 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),566 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),567 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),568 )569 c.add("lq", datas, is_outline_show=style.setdefault('is_outline_show',True))570 return c571 elif chart_type == 'parallel': # å¹³è¡åæ ç³»572 if style.setdefault('toolbox_opts_is_show',False):573 toolbox_opts=opts.ToolboxOpts()574 else:575 toolbox_opts=None576 577 if style.setdefault('datazoom_opts',None)=='horizontal':578 datazoom_opts=opts.DataZoomOpts()579 elif style.setdefault('datazoom_opts',None)=='vertical':580 datazoom_opts=opts.DataZoomOpts(orient="vertical")581 elif style.setdefault('datazoom_opts',None)=='inside':582 datazoom_opts=opts.DataZoomOpts(type_="inside")583 else:584 datazoom_opts=None585 586 xs = f_get_query_record(conn, x,database_type)587 schemas = []588 for row in xs:589 strdata = row[3]590 datalist = strdata.split(",")591 schemas.append({"dim": row[0], "name": row[1], "type_": row[2], "data": datalist})592 c = Parallel(themetype)593 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),594 pos_right=style.setdefault('title_pos_right',None)),595 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),596 pos_left=style.setdefault('legend_pos_left',None),597 pos_right=style.setdefault('legend_pos_right',None)),598 toolbox_opts=toolbox_opts,599 datazoom_opts=datazoom_opts,600 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),601 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),602 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),603 )604 c.add_schema(schemas)605 c.add("parallel", datas)606 return c607 elif chart_type == 'polar': # æåæ ç³»608 if style.setdefault('toolbox_opts_is_show',False):609 toolbox_opts=opts.ToolboxOpts()610 else:611 toolbox_opts=None612 613 if style.setdefault('datazoom_opts',None)=='horizontal':614 datazoom_opts=opts.DataZoomOpts()615 elif style.setdefault('datazoom_opts',None)=='vertical':616 datazoom_opts=opts.DataZoomOpts(orient="vertical")617 elif style.setdefault('datazoom_opts',None)=='inside':618 datazoom_opts=opts.DataZoomOpts(type_="inside")619 else:620 datazoom_opts=None621 622 c = Polar(themetype)623 mytype=style.setdefault('type_',"scatter")624 if mytype=="bar":625 if style.setdefault('muti_bar',True):626 c.add_schema(angleaxis_opts=opts.AngleAxisOpts(data=xlist, type_="category"))627 else:628 c.add_schema(629 radiusaxis_opts=opts.RadiusAxisOpts(data=xlist, type_="category"),630 angleaxis_opts=opts.AngleAxisOpts(is_clockwise=style.setdefault('is_clockwise',True), 631 max_=style.setdefault('max_',60)),)632 for i in range(len(ylist)):633 name = ylist[i]634 c.add(name, zdict[name], type_=mytype, stack="stack0") 635 else:636 c.add("", datas, type_=mytype, 637 effect_opts=opts.EffectOpts(scale=style.setdefault('effect_opts_scale',10), period=style.setdefault('effect_opts_period',5)),638 label_opts=opts.LabelOpts(is_show=style.setdefault('is_show',False)))639 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),640 pos_right=style.setdefault('title_pos_right',None)),641 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),642 pos_left=style.setdefault('legend_pos_left',None),643 pos_right=style.setdefault('legend_pos_right',None)),644 toolbox_opts=toolbox_opts,645 datazoom_opts=datazoom_opts,646 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),647 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),648 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),649 )650 return c651 elif chart_type == 'radar': # é·è¾¾å¾652 if style.setdefault('toolbox_opts_is_show',False):653 toolbox_opts=opts.ToolboxOpts()654 else:655 toolbox_opts=None656 657 if style.setdefault('datazoom_opts',None)=='horizontal':658 datazoom_opts=opts.DataZoomOpts()659 elif style.setdefault('datazoom_opts',None)=='vertical':660 datazoom_opts=opts.DataZoomOpts(orient="vertical")661 elif style.setdefault('datazoom_opts',None)=='inside':662 datazoom_opts=opts.DataZoomOpts(type_="inside")663 else:664 datazoom_opts=None665 666 xs = f_get_query_record(conn, x,database_type)667 schemas = []668 for row in xs:669 schemas.append({"name": row[0], "max_": row[1], "min_": row[2]})670 c = Radar(themetype)671 c.add_schema(schemas)672 v =[]673 name =''674 color=''675 for row in datas:676 if row[0]!=name:677 if len(v)>0:678 c.add(name, v, color=color)679 v =[]680 name = row[0]681 color = row[1]682 v.append(row[2:])683 c.add(name, v, color=color)684 c.set_series_opts(label_opts=opts.LabelOpts(is_show=style.setdefault('is_show',False)))685 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),686 pos_right=style.setdefault('title_pos_right',None)),687 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),688 pos_left=style.setdefault('legend_pos_left',None),689 pos_right=style.setdefault('legend_pos_right',None)),690 toolbox_opts=toolbox_opts,691 datazoom_opts=datazoom_opts,692 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),693 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),694 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),695 )696 return c697 elif chart_type == 'sankey': # æ¡åºå¾698 if style.setdefault('toolbox_opts_is_show',False):699 toolbox_opts=opts.ToolboxOpts()700 else:701 toolbox_opts=None702 703 if style.setdefault('datazoom_opts',None)=='horizontal':704 datazoom_opts=opts.DataZoomOpts()705 elif style.setdefault('datazoom_opts',None)=='vertical':706 datazoom_opts=opts.DataZoomOpts(orient="vertical")707 elif style.setdefault('datazoom_opts',None)=='inside':708 datazoom_opts=opts.DataZoomOpts(type_="inside")709 else:710 datazoom_opts=None711 712 xs = f_get_query_record(conn, x,database_type)713 nodes = []714 for row in xs:715 nodes.append({"name": row[0]})716 links = []717 for row in datas:718 links.append({"source": row[0], "target": row[1], "value": row[2]})719 c = Sankey(themetype)720 c.add(721 "sankey",722 nodes=nodes,723 links=links,724 linestyle_opt=opts.LineStyleOpts(opacity=style.setdefault('opacity',0.2), curve=style.setdefault('curve',0.5), color=style.setdefault('color',"source")),725 label_opts=opts.LabelOpts(position=style.setdefault('position',"right")),726 )727 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),728 pos_right=style.setdefault('title_pos_right',None)),729 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),730 pos_left=style.setdefault('legend_pos_left',None),731 pos_right=style.setdefault('legend_pos_right',None)),732 toolbox_opts=toolbox_opts,733 datazoom_opts=datazoom_opts,734 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),735 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),736 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),737 )738 return c739 elif chart_type == 'sunburst': # ææ¥å¾740 if style.setdefault('toolbox_opts_is_show',False):741 toolbox_opts=opts.ToolboxOpts()742 else:743 toolbox_opts=None744 745 if style.setdefault('datazoom_opts',None)=='horizontal':746 datazoom_opts=opts.DataZoomOpts()747 elif style.setdefault('datazoom_opts',None)=='vertical':748 datazoom_opts=opts.DataZoomOpts(orient="vertical")749 elif style.setdefault('datazoom_opts',None)=='inside':750 datazoom_opts=opts.DataZoomOpts(type_="inside")751 else:752 datazoom_opts=None753 754 j = []755 for row in datas:756 j.append(eval(row[0]))757 c = Sunburst(themetype)758 c.add(759 "",760 data_pair=j,761 highlight_policy=style.setdefault('highlight_policy',"ancestor"),762 radius=style.setdefault('radius',[0, "95%"]),763 sort_=style.setdefault('sort_',"null"),764 levels=style.setdefault('levels',[765 {},766 {767 "r0": "15%",768 "r": "35%",769 "itemStyle": {"borderWidth": 2},770 "label": {"rotate": "tangential"},771 },772 {"r0": "35%", "r": "70%", "label": {"align": "right"}},773 {774 "r0": "70%",775 "r": "72%",776 "label": {"position": "outside", "padding": 3, "silent": False},777 "itemStyle": {"borderWidth": 3},778 },779 ],)780 )781 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),782 pos_right=style.setdefault('title_pos_right',None)),783 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),784 pos_left=style.setdefault('legend_pos_left',None),785 pos_right=style.setdefault('legend_pos_right',None)),786 toolbox_opts=toolbox_opts,787 datazoom_opts=datazoom_opts,788 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),789 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),790 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),791 )792 c.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}"))793 return c794 elif chart_type == 'themeriver': # 主é¢æ²³æµå¾795 if style.setdefault('toolbox_opts_is_show',False):796 toolbox_opts=opts.ToolboxOpts()797 else:798 toolbox_opts=None799 800 if style.setdefault('datazoom_opts',None)=='horizontal':801 datazoom_opts=opts.DataZoomOpts()802 elif style.setdefault('datazoom_opts',None)=='vertical':803 datazoom_opts=opts.DataZoomOpts(orient="vertical")804 elif style.setdefault('datazoom_opts',None)=='inside':805 datazoom_opts=opts.DataZoomOpts(type_="inside")806 else:807 datazoom_opts=None808 809 c = ThemeRiver(themetype)810 c.add(811 xlist,812 datas,813 singleaxis_opts=opts.SingleAxisOpts(type_=style.setdefault('type_',"time"), pos_bottom=style.setdefault('pos_bottom',"10%")),814 )815 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),816 pos_right=style.setdefault('title_pos_right',None)),817 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),818 pos_left=style.setdefault('legend_pos_left',None),819 pos_right=style.setdefault('legend_pos_right',None)),820 toolbox_opts=toolbox_opts,821 datazoom_opts=datazoom_opts,822 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),823 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),824 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),825 )826 return c827 elif chart_type == 'wordcloud': # è¯äºå¾828 if style.setdefault('toolbox_opts_is_show',False):829 toolbox_opts=opts.ToolboxOpts()830 else:831 toolbox_opts=None832 if style.setdefault('SymbolType_DIAMOND',False):833 myshape=SymbolType.DIAMOND834 else:835 myshape=None836 837 if style.setdefault('datazoom_opts',None)=='horizontal':838 datazoom_opts=opts.DataZoomOpts()839 elif style.setdefault('datazoom_opts',None)=='vertical':840 datazoom_opts=opts.DataZoomOpts(orient="vertical")841 elif style.setdefault('datazoom_opts',None)=='inside':842 datazoom_opts=opts.DataZoomOpts(type_="inside")843 else:844 datazoom_opts=None845 846 c = WordCloud(themetype)847 c.add("", datas, word_size_range=style.setdefault('word_size_range',[20, 100]), shape=myshape)848 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),849 pos_right=style.setdefault('title_pos_right',None)),850 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),851 pos_left=style.setdefault('legend_pos_left',None),852 pos_right=style.setdefault('legend_pos_right',None)),853 toolbox_opts=toolbox_opts,854 datazoom_opts=datazoom_opts,855 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),856 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),857 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),858 )859 return c860 elif chart_type == 'boxpolt': # 箱形å¾861 if style.setdefault('toolbox_opts_is_show',False):862 toolbox_opts=opts.ToolboxOpts()863 else:864 toolbox_opts=None865 866 if style.setdefault('datazoom_opts',None)=='horizontal':867 datazoom_opts=opts.DataZoomOpts()868 elif style.setdefault('datazoom_opts',None)=='vertical':869 datazoom_opts=opts.DataZoomOpts(orient="vertical")870 elif style.setdefault('datazoom_opts',None)=='inside':871 datazoom_opts=opts.DataZoomOpts(type_="inside")872 else:873 datazoom_opts=None874 875 c = Boxplot(themetype)876 c.add_xaxis(xlist)877 for i in range(len(ylist)):878 name = ylist[i]879 vn=[]880 for v in zdict[name]:881 vn.append(list(map(int, v.split(","))))882 c.add_yaxis(name, c.prepare_data(vn))883 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),884 pos_right=style.setdefault('title_pos_right',None)),885 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),886 pos_left=style.setdefault('legend_pos_left',None),887 pos_right=style.setdefault('legend_pos_right',None)),888 toolbox_opts=toolbox_opts,889 datazoom_opts=datazoom_opts,890 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),891 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),892 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),893 )894 return c895 elif chart_type == 'effectscatter': # æ¶æ¼ªç¹ææ£ç¹å¾896 if style.setdefault('toolbox_opts_is_show',False):897 toolbox_opts=opts.ToolboxOpts()898 else:899 toolbox_opts=None900 901 if style.setdefault('datazoom_opts',None)=='horizontal':902 datazoom_opts=opts.DataZoomOpts()903 elif style.setdefault('datazoom_opts',None)=='vertical':904 datazoom_opts=opts.DataZoomOpts(orient="vertical")905 elif style.setdefault('datazoom_opts',None)=='inside':906 datazoom_opts=opts.DataZoomOpts(type_="inside")907 else:908 datazoom_opts=None909 910 c = EffectScatter(themetype)911 c.add_xaxis(xlist)912 c.add_yaxis("", datas)913 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),914 pos_right=style.setdefault('title_pos_right',None)),915 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),916 pos_left=style.setdefault('legend_pos_left',None),917 pos_right=style.setdefault('legend_pos_right',None)),918 toolbox_opts=toolbox_opts,919 datazoom_opts=datazoom_opts,920 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),921 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),922 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),923 )924 return c925 elif chart_type == 'heatmap': # çåå¾926 if style.setdefault('toolbox_opts_is_show',False):927 toolbox_opts=opts.ToolboxOpts()928 else:929 toolbox_opts=None930 931 if style.setdefault('datazoom_opts',None)=='horizontal':932 datazoom_opts=opts.DataZoomOpts()933 elif style.setdefault('datazoom_opts',None)=='vertical':934 datazoom_opts=opts.DataZoomOpts(orient="vertical")935 elif style.setdefault('datazoom_opts',None)=='inside':936 datazoom_opts=opts.DataZoomOpts(type_="inside")937 else:938 datazoom_opts=None939 940 c = HeatMap(themetype)941 c.add_xaxis(xlist)942 c.add_yaxis("series0",ylist , datas)943 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),944 pos_right=style.setdefault('title_pos_right',None)),945 visualmap_opts=opts.VisualMapOpts(),946 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),947 pos_left=style.setdefault('legend_pos_left',None),948 pos_right=style.setdefault('legend_pos_right',None)),949 toolbox_opts=toolbox_opts,950 datazoom_opts=datazoom_opts,951 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),952 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),953 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),954 )955 return c956 elif chart_type == 'kline': # K线å¾957 if style.setdefault('toolbox_opts_is_show',False):958 toolbox_opts=opts.ToolboxOpts()959 else:960 toolbox_opts=None961 962 if style.setdefault('datazoom_opts',None)=='horizontal':963 datazoom_opts=opts.DataZoomOpts()964 elif style.setdefault('datazoom_opts',None)=='vertical':965 datazoom_opts=opts.DataZoomOpts(orient="vertical")966 elif style.setdefault('datazoom_opts',None)=='inside':967 datazoom_opts=opts.DataZoomOpts(type_="inside")968 else:969 datazoom_opts=None970 971 c = Kline(themetype)972 c.add_xaxis(xlist)973 c.add_yaxis("kline", datas,itemstyle_opts=opts.ItemStyleOpts(974 color=style.setdefault('color',"#ec0000"),975 color0=style.setdefault('color0',"#00da3c"),976 border_color=style.setdefault('border_color',"#8A0000"),977 border_color0=style.setdefault('border_color0',"#008F28"),978 ),979 markline_opts=opts.MarkLineOpts(980 data=[opts.MarkLineItem(type_="max", value_dim="close")]981 ),982 )983 c.set_global_opts(984 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),985 pos_right=style.setdefault('title_pos_right',None)),986 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),987 pos_left=style.setdefault('legend_pos_left',None),988 pos_right=style.setdefault('legend_pos_right',None)),989 toolbox_opts=toolbox_opts,990 datazoom_opts=datazoom_opts,991 xaxis_opts=opts.AxisOpts(is_scale=True,axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),992 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),993 yaxis_opts=opts.AxisOpts(is_scale=True,axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),994 )995 return c996 elif chart_type == 'pictorialbar': # 象形æ±ç¶å¾997 if style.setdefault('toolbox_opts_is_show',False):998 toolbox_opts=opts.ToolboxOpts()999 else:1000 toolbox_opts=None1001 1002 if style.setdefault('datazoom_opts',None)=='horizontal':1003 datazoom_opts=opts.DataZoomOpts()1004 elif style.setdefault('datazoom_opts',None)=='vertical':1005 datazoom_opts=opts.DataZoomOpts(orient="vertical")1006 elif style.setdefault('datazoom_opts',None)=='inside':1007 datazoom_opts=opts.DataZoomOpts(type_="inside")1008 else:1009 datazoom_opts=None1010 1011 ys = f_get_query_record(conn, y,database_type)1012 symbols = {}1013 for row in ys:1014 symbols[row[0]]=row[1]1015 c = PictorialBar(themetype)1016 c.add_xaxis(xlist)1017 v =[]1018 name =''1019 i=51020 for row in datas:1021 if row[0]!=name:1022 if len(v)>0:1023 c.add_yaxis(name, 1024 v,1025 label_opts=opts.LabelOpts(is_show=False),1026 symbol_size=22,1027 symbol_repeat="fixed",1028 symbol_offset=[0, i],1029 is_symbol_clip=True)1030 v =[]1031 i=i-201032 name = row[0]1033 v.append({"value": row[2], "symbol": symbols[row[1]]})1034 c.add_yaxis(name, 1035 v,1036 label_opts=opts.LabelOpts(is_show=False),1037 symbol_size=22,1038 symbol_repeat="fixed",1039 symbol_offset=[0, i],1040 is_symbol_clip=True)1041 c.reversal_axis()1042 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1043 pos_right=style.setdefault('title_pos_right',None)),1044 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1045 pos_left=style.setdefault('legend_pos_left',None),1046 pos_right=style.setdefault('legend_pos_right',None)),1047 toolbox_opts=toolbox_opts,1048 datazoom_opts=datazoom_opts,1049 xaxis_opts=opts.AxisOpts(is_show=True,axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1050 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1051 yaxis_opts=opts.AxisOpts(1052 axistick_opts=opts.AxisTickOpts(is_show=False),1053 axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(opacity=0)),1054 axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))1055 ) 1056 )1057 return c1058 elif chart_type == 'scatter': # æ£ç¹å¾1059 if style.setdefault('toolbox_opts_is_show',False):1060 toolbox_opts=opts.ToolboxOpts()1061 else:1062 toolbox_opts=None1063 1064 if style.setdefault('datazoom_opts',None)=='horizontal':1065 datazoom_opts=opts.DataZoomOpts()1066 elif style.setdefault('datazoom_opts',None)=='vertical':1067 datazoom_opts=opts.DataZoomOpts(orient="vertical")1068 elif style.setdefault('datazoom_opts',None)=='inside':1069 datazoom_opts=opts.DataZoomOpts(type_="inside")1070 else:1071 datazoom_opts=None1072 1073 c = Scatter(themetype)1074 c.add_xaxis(xlist)1075 v =[]1076 name =''1077 for row in datas:1078 if row[0]!=name:1079 if len(v)>0:1080 c.add_yaxis(name, v)1081 v =[]1082 name = row[0]1083 v.append(row[2])1084 c.add_yaxis(name, v)1085 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1086 pos_right=style.setdefault('title_pos_right',None)),1087 visualmap_opts=opts.VisualMapOpts(type_="size", max_=150, min_=20),1088 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1089 pos_left=style.setdefault('legend_pos_left',None),1090 pos_right=style.setdefault('legend_pos_right',None)),1091 toolbox_opts=toolbox_opts,1092 datazoom_opts=datazoom_opts,1093 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1094 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1095 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),1096 )1097 return c1098 elif chart_type == 'overlap': # å±å å¤å¾1099 if style.setdefault('toolbox_opts_is_show',False):1100 toolbox_opts=opts.ToolboxOpts()1101 else:1102 toolbox_opts=None1103 1104 if style.setdefault('datazoom_opts',None)=='horizontal':1105 datazoom_opts=opts.DataZoomOpts()1106 elif style.setdefault('datazoom_opts',None)=='vertical':1107 datazoom_opts=opts.DataZoomOpts(orient="vertical")1108 elif style.setdefault('datazoom_opts',None)=='inside':1109 datazoom_opts=opts.DataZoomOpts(type_="inside")1110 else:1111 datazoom_opts=None1112 1113 v1 = []1114 v2 = []1115 v3 = []1116 for row in datas:1117 v1.append(row[0])1118 v2.append(row[1])1119 v3.append(row[2])1120 c = Bar(themetype)1121 c.add_xaxis(xlist)1122 c.add_yaxis("è¸åé", v1)1123 c.add_yaxis("éæ°´é", v2)1124 c.extend_axis(1125 yaxis=opts.AxisOpts(1126 axislabel_opts=opts.LabelOpts(formatter="{value} °C"), interval=51127 )1128 )1129 c.set_series_opts(label_opts=opts.LabelOpts(is_show=False))1130 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1131 pos_right=style.setdefault('title_pos_right',None)),1132 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1133 pos_left=style.setdefault('legend_pos_left',None),1134 pos_right=style.setdefault('legend_pos_right',None)),1135 toolbox_opts=toolbox_opts,1136 datazoom_opts=datazoom_opts,1137 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1138 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1139 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),1140 )1141 line = Line(themetype).add_xaxis(xlist).add_yaxis("å¹³å温度", v3, yaxis_index=1)1142 c.overlap(line)1143 return c1144 elif chart_type == 'tree': # æ å¾1145 if style.setdefault('toolbox_opts_is_show',False):1146 toolbox_opts=opts.ToolboxOpts()1147 else:1148 toolbox_opts=None1149 1150 if style.setdefault('datazoom_opts',None)=='horizontal':1151 datazoom_opts=opts.DataZoomOpts()1152 elif style.setdefault('datazoom_opts',None)=='vertical':1153 datazoom_opts=opts.DataZoomOpts(orient="vertical")1154 elif style.setdefault('datazoom_opts',None)=='inside':1155 datazoom_opts=opts.DataZoomOpts(type_="inside")1156 else:1157 datazoom_opts=None1158 1159 j = []1160 for row in datas:1161 j.append(eval(row[0]))1162 c = Tree(themetype)1163 c.add("", j, collapse_interval=2, orient=style.setdefault('orient',"LR"),label_opts=opts.LabelOpts(1164 position=style.setdefault('position',None),1165 horizontal_align=style.setdefault('horizontal_align',None),1166 vertical_align=style.setdefault('vertical_align',None),1167 rotate=style.setdefault('rotate',None)1168 )1169 )1170 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1171 pos_right=style.setdefault('title_pos_right',None)),1172 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1173 pos_left=style.setdefault('legend_pos_left',None),1174 pos_right=style.setdefault('legend_pos_right',None)),1175 toolbox_opts=toolbox_opts,1176 datazoom_opts=datazoom_opts,1177 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1178 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1179 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),1180 )1181 return c1182 elif chart_type == 'treemap': # ç©å½¢æ å¾1183 if style.setdefault('toolbox_opts_is_show',False):1184 toolbox_opts=opts.ToolboxOpts()1185 else:1186 toolbox_opts=None1187 1188 if style.setdefault('datazoom_opts',None)=='horizontal':1189 datazoom_opts=opts.DataZoomOpts()1190 elif style.setdefault('datazoom_opts',None)=='vertical':1191 datazoom_opts=opts.DataZoomOpts(orient="vertical")1192 elif style.setdefault('datazoom_opts',None)=='inside':1193 datazoom_opts=opts.DataZoomOpts(type_="inside")1194 else:1195 datazoom_opts=None1196 1197 j = []1198 for row in datas:1199 j.append(eval(row[0]))1200 c = TreeMap(themetype)1201 c.add(xlist[0], j[0])1202 c.set_global_opts(title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1203 pos_right=style.setdefault('title_pos_right',None)),1204 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1205 pos_left=style.setdefault('legend_pos_left',None),1206 pos_right=style.setdefault('legend_pos_right',None)),1207 toolbox_opts=toolbox_opts,1208 datazoom_opts=datazoom_opts,1209 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1210 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1211 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),1212 )1213 return c1214 elif chart_type == 'geo': # å°çåæ ç³»1215 if style.setdefault('toolbox_opts_is_show',False):1216 toolbox_opts=opts.ToolboxOpts()1217 else:1218 toolbox_opts=None1219 1220 if style.setdefault('datazoom_opts',None)=='horizontal':1221 datazoom_opts=opts.DataZoomOpts()1222 elif style.setdefault('datazoom_opts',None)=='vertical':1223 datazoom_opts=opts.DataZoomOpts(orient="vertical")1224 elif style.setdefault('datazoom_opts',None)=='inside':1225 datazoom_opts=opts.DataZoomOpts(type_="inside")1226 else:1227 datazoom_opts=None1228 1229 c = Geo(themetype)1230 c.add_schema(maptype=xlist[0])1231 if style.setdefault('ChartType','None')=='None':1232 c.add(xlist[0],datas)1233 elif style.setdefault('ChartType','None')=='HEATMAP': 1234 c.add(xlist[0],datas,type_=ChartType.HEATMAP) 1235 elif style.setdefault('ChartType','None')=='EFFECT_SCATTER': 1236 c.add(xlist[0],datas,type_=ChartType.EFFECT_SCATTER)1237 c.set_series_opts(label_opts=opts.LabelOpts(is_show=False))1238 c.set_global_opts(visualmap_opts=opts.VisualMapOpts(is_piecewise=style.setdefault('is_piecewise',None)),1239 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1240 pos_right=style.setdefault('title_pos_right',None)),1241 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1242 pos_left=style.setdefault('legend_pos_left',None),1243 pos_right=style.setdefault('legend_pos_right',None)),1244 toolbox_opts=toolbox_opts,1245 datazoom_opts=datazoom_opts,1246 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1247 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1248 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),1249 )1250 return c1251 elif chart_type == 'geo_lines': # å°çåæ ç³»31252 if style.setdefault('toolbox_opts_is_show',False):1253 toolbox_opts=opts.ToolboxOpts()1254 else:1255 toolbox_opts=None1256 1257 if style.setdefault('datazoom_opts',None)=='horizontal':1258 datazoom_opts=opts.DataZoomOpts()1259 elif style.setdefault('datazoom_opts',None)=='vertical':1260 datazoom_opts=opts.DataZoomOpts(orient="vertical")1261 elif style.setdefault('datazoom_opts',None)=='inside':1262 datazoom_opts=opts.DataZoomOpts(type_="inside")1263 else:1264 datazoom_opts=None1265 1266 ys = f_get_query_record(conn, y,database_type)1267 c = Geo(themetype)1268 c.add_schema(maptype=xlist[0],1269 itemstyle_opts=opts.ItemStyleOpts(color=style.setdefault('back_color',"#323c48"), border_color=style.setdefault('border_color',"#111")))1270 c.add(xlist[0],datas,type_=ChartType.EFFECT_SCATTER,color=style.setdefault('dot_color',"red"))1271 c.add(1272 xlist[0],1273 ys,1274 type_=ChartType.LINES,1275 effect_opts=opts.EffectOpts(1276 symbol=SymbolType.ARROW, symbol_size=style.setdefault('symbol_size',6), color=style.setdefault('line_color',"blue")1277 ),1278 linestyle_opts=opts.LineStyleOpts(curve=style.setdefault('curve',0.2)),1279 )1280 c.set_series_opts(label_opts=opts.LabelOpts(is_show=False))1281 c.set_global_opts(1282 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1283 pos_right=style.setdefault('title_pos_right',None)),1284 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1285 pos_left=style.setdefault('legend_pos_left',None),1286 pos_right=style.setdefault('legend_pos_right',None)),1287 toolbox_opts=toolbox_opts,1288 datazoom_opts=datazoom_opts,1289 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1290 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1291 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),1292 )1293 return c1294 elif chart_type == 'map': # å°å¾1295 if style.setdefault('toolbox_opts_is_show',False):1296 toolbox_opts=opts.ToolboxOpts()1297 else:1298 toolbox_opts=None1299 1300 if style.setdefault('datazoom_opts',None)=='horizontal':1301 datazoom_opts=opts.DataZoomOpts()1302 elif style.setdefault('datazoom_opts',None)=='vertical':1303 datazoom_opts=opts.DataZoomOpts(orient="vertical")1304 elif style.setdefault('datazoom_opts',None)=='inside':1305 datazoom_opts=opts.DataZoomOpts(type_="inside")1306 else:1307 datazoom_opts=None1308 1309 c = Map(themetype)1310 c.add(xlist[1],datas, xlist[0])1311 c.set_series_opts(label_opts=opts.LabelOpts(is_show=style.setdefault('is_show',False)))1312 if style.setdefault('max_',0) ==0 :1313 c.set_global_opts(1314 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1315 pos_right=style.setdefault('title_pos_right',None)),1316 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1317 pos_left=style.setdefault('legend_pos_left',None),1318 pos_right=style.setdefault('legend_pos_right',None)),1319 toolbox_opts=toolbox_opts,1320 )1321 else:1322 c.set_global_opts(1323 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1324 pos_right=style.setdefault('title_pos_right',None)),1325 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1326 pos_left=style.setdefault('legend_pos_left',None),1327 pos_right=style.setdefault('legend_pos_right',None)),1328 toolbox_opts=toolbox_opts,1329 datazoom_opts=datazoom_opts,1330 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1331 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1332 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),1333 visualmap_opts=opts.VisualMapOpts(max_=style.setdefault('max_',200),is_piecewise=style.setdefault('is_piecewise',True))1334 )1335 return c1336 elif chart_type == 'bar3d': # 3Dæ±ç¶å¾1337 if style.setdefault('toolbox_opts_is_show',False):1338 toolbox_opts=opts.ToolboxOpts()1339 else:1340 toolbox_opts=None1341 1342 if style.setdefault('datazoom_opts',None)=='horizontal':1343 datazoom_opts=opts.DataZoomOpts()1344 elif style.setdefault('datazoom_opts',None)=='vertical':1345 datazoom_opts=opts.DataZoomOpts(orient="vertical")1346 elif style.setdefault('datazoom_opts',None)=='inside':1347 datazoom_opts=opts.DataZoomOpts(type_="inside")1348 else:1349 datazoom_opts=None1350 1351 c = Bar3D(themetype)1352 c.add(1353 "",1354 [[d[1], d[0], d[2]] for d in datas],1355 xaxis3d_opts=opts.Axis3DOpts(xlist, type_="category"),1356 yaxis3d_opts=opts.Axis3DOpts(ylist, type_="category"),1357 zaxis3d_opts=opts.Axis3DOpts(type_="value"),1358 )1359 c.set_global_opts(1360 visualmap_opts=opts.VisualMapOpts(max_=style.setdefault('max_',80)),1361 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1362 pos_right=style.setdefault('title_pos_right',None)),1363 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1364 pos_left=style.setdefault('legend_pos_left',None),1365 pos_right=style.setdefault('legend_pos_right',None)),1366 toolbox_opts=toolbox_opts,1367 datazoom_opts=datazoom_opts,1368 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1369 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1370 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),1371 )1372 return c1373 elif chart_type == 'bar3d_stack': # å å æ±ç¶å¾1374 if style.setdefault('toolbox_opts_is_show',False):1375 toolbox_opts=opts.ToolboxOpts()1376 else:1377 toolbox_opts=None1378 1379 if style.setdefault('datazoom_opts',None)=='horizontal':1380 datazoom_opts=opts.DataZoomOpts()1381 elif style.setdefault('datazoom_opts',None)=='vertical':1382 datazoom_opts=opts.DataZoomOpts(orient="vertical")1383 elif style.setdefault('datazoom_opts',None)=='inside':1384 datazoom_opts=opts.DataZoomOpts(type_="inside")1385 else:1386 datazoom_opts=None1387 1388 c = Bar3D(themetype)1389 for _ in range(7):1390 c.add(1391 "",1392 datas,1393 shading="lambert",1394 xaxis3d_opts=opts.Axis3DOpts(data=xlist, type_="value"),1395 yaxis3d_opts=opts.Axis3DOpts(data=ylist, type_="value"),1396 zaxis3d_opts=opts.Axis3DOpts(type_="value"),1397 )1398 c.set_global_opts(1399 visualmap_opts=opts.VisualMapOpts(max_=style.setdefault('max_',80)),1400 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1401 pos_right=style.setdefault('title_pos_right',None)),1402 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1403 pos_left=style.setdefault('legend_pos_left',None),1404 pos_right=style.setdefault('legend_pos_right',None)),1405 toolbox_opts=toolbox_opts,1406 datazoom_opts=datazoom_opts,1407 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1408 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1409 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),1410 )1411 c.set_series_opts(**{"stack": "stack"})1412 return c1413 elif chart_type == 'line3d': # 3Dæ线å¾1414 if style.setdefault('toolbox_opts_is_show',False):1415 toolbox_opts=opts.ToolboxOpts()1416 else:1417 toolbox_opts=None1418 1419 if style.setdefault('datazoom_opts',None)=='horizontal':1420 datazoom_opts=opts.DataZoomOpts()1421 elif style.setdefault('datazoom_opts',None)=='vertical':1422 datazoom_opts=opts.DataZoomOpts(orient="vertical")1423 elif style.setdefault('datazoom_opts',None)=='inside':1424 datazoom_opts=opts.DataZoomOpts(type_="inside")1425 else:1426 datazoom_opts=None1427 1428 c = Line3D(themetype)1429 c.add(1430 "",1431 datas,1432 xaxis3d_opts=opts.Axis3DOpts(xlist, type_="value"),1433 yaxis3d_opts=opts.Axis3DOpts(ylist, type_="value"),1434 grid3d_opts=opts.Grid3DOpts(width=style.setdefault('width',100), 1435 height=style.setdefault('height',100), 1436 depth=style.setdefault('depth',100),1437 is_rotate=style.setdefault('is_rotate',False)),1438 )1439 c.set_global_opts(1440 visualmap_opts=opts.VisualMapOpts(1441 max_=style.setdefault('max_',30), min_=style.setdefault('min_',0), range_color=style.setdefault('range_color',[]).split(',')1442 ),1443 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1444 pos_right=style.setdefault('title_pos_right',None)),1445 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1446 pos_left=style.setdefault('legend_pos_left',None),1447 pos_right=style.setdefault('legend_pos_right',None)),1448 toolbox_opts=toolbox_opts,1449 datazoom_opts=datazoom_opts,1450 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1451 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1452 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),1453 )1454 return c1455 elif chart_type == 'scatter3d': # 3Dæ£ç¹å¾1456 if style.setdefault('toolbox_opts_is_show',False):1457 toolbox_opts=opts.ToolboxOpts()1458 else:1459 toolbox_opts=None1460 1461 if style.setdefault('datazoom_opts',None)=='horizontal':1462 datazoom_opts=opts.DataZoomOpts()1463 elif style.setdefault('datazoom_opts',None)=='vertical':1464 datazoom_opts=opts.DataZoomOpts(orient="vertical")1465 elif style.setdefault('datazoom_opts',None)=='inside':1466 datazoom_opts=opts.DataZoomOpts(type_="inside")1467 else:1468 datazoom_opts=None1469 1470 c = Scatter3D(themetype)1471 c.add(xlist[0], datas)1472 c.set_global_opts(1473 visualmap_opts=opts.VisualMapOpts(range_color=style.setdefault('range_color',[]).split(',')),1474 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1475 pos_right=style.setdefault('title_pos_right',None)),1476 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1477 pos_left=style.setdefault('legend_pos_left',None),1478 pos_right=style.setdefault('legend_pos_right',None)),1479 toolbox_opts=toolbox_opts,1480 datazoom_opts=datazoom_opts,1481 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1482 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1483 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),1484 )1485 return c1486 elif chart_type == 'surface3d': # 3Dæ²é¢å¾1487 if style.setdefault('toolbox_opts_is_show',False):1488 toolbox_opts=opts.ToolboxOpts()1489 else:1490 toolbox_opts=None1491 1492 if style.setdefault('datazoom_opts',None)=='horizontal':1493 datazoom_opts=opts.DataZoomOpts()1494 elif style.setdefault('datazoom_opts',None)=='vertical':1495 datazoom_opts=opts.DataZoomOpts(orient="vertical")1496 elif style.setdefault('datazoom_opts',None)=='inside':1497 datazoom_opts=opts.DataZoomOpts(type_="inside")1498 else:1499 datazoom_opts=None1500 1501 c = Surface3D(themetype)1502 c.add(1503 xlist[0],1504 datas,1505 xaxis3d_opts=opts.Axis3DOpts(type_="value"),1506 yaxis3d_opts=opts.Axis3DOpts(type_="value"),1507 grid3d_opts=opts.Grid3DOpts(width=style.setdefault('width',100), 1508 height=style.setdefault('height',100), 1509 depth=style.setdefault('depth',100)),1510 )1511 c.set_global_opts(1512 visualmap_opts=opts.VisualMapOpts(1513 max_=style.setdefault('max_',3), min_=style.setdefault('min_',-3), range_color=style.setdefault('range_color',[]).split(',')1514 ),1515 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1516 pos_right=style.setdefault('title_pos_right',None)),1517 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1518 pos_left=style.setdefault('legend_pos_left',None),1519 pos_right=style.setdefault('legend_pos_right',None)),1520 toolbox_opts=toolbox_opts,1521 datazoom_opts=datazoom_opts,1522 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1523 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1524 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),1525 )1526 return c1527 elif chart_type == 'mapglobe': # å°çå°å¾1528 if style.setdefault('toolbox_opts_is_show',False):1529 toolbox_opts=opts.ToolboxOpts()1530 else:1531 toolbox_opts=None1532 1533 if style.setdefault('datazoom_opts',None)=='horizontal':1534 datazoom_opts=opts.DataZoomOpts()1535 elif style.setdefault('datazoom_opts',None)=='vertical':1536 datazoom_opts=opts.DataZoomOpts(orient="vertical")1537 elif style.setdefault('datazoom_opts',None)=='inside':1538 datazoom_opts=opts.DataZoomOpts(type_="inside")1539 else:1540 datazoom_opts=None1541 1542 high = max([x for _, x in datas])1543 low = min([x for _, x in datas])1544 c = MapGlobe(themetype)1545 c.add_schema()1546 c.add(1547 maptype=style.setdefault('maptype',"world"),1548 series_name=xlist[0],1549 data_pair=datas,1550 is_map_symbol_show=style.setdefault('is_map_symbol_show',False),1551 label_opts=opts.LabelOpts(is_show=style.setdefault('is_show',False)),1552 )1553 c.set_global_opts(1554 visualmap_opts=opts.VisualMapOpts(1555 min_=low,1556 max_=high,1557 range_text=["max", "min"],1558 is_calculable=style.setdefault('is_calculable',True),1559 range_color=style.setdefault('range_color',["lightskyblue", "yellow", "orangered"]).split(',')),1560 title_opts=opts.TitleOpts(title=title,pos_top=style.setdefault('title_pos_top',None),1561 pos_right=style.setdefault('title_pos_right',None)),1562 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1563 pos_left=style.setdefault('legend_pos_left',None),1564 pos_right=style.setdefault('legend_pos_right',None)),1565 toolbox_opts=toolbox_opts,1566 datazoom_opts=datazoom_opts,1567 xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=style.setdefault('yaxis_opts_rotate',0),1568 formatter=style.setdefault('xaxis_opts_formatter',"{value}"))),1569 yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter=style.setdefault('yaxis_opts_formatter',"{value}"))),1570 )1571 return c1572 elif chart_type == 'kline_profession': # å¤å¾èå¨1573 def calculate_ma(day_count: int, d):1574 result: List[Union[float, str]] = []1575 for i in range(len(d)):1576 if i < day_count:1577 result.append("-")1578 continue1579 sum_total = 0.01580 for j in range(day_count):1581 sum_total += float(d[i - j][1])1582 result.append(abs(float("%.3f" % (sum_total / day_count))))1583 return result1584 kline = Kline(themetype)1585 kline.add_xaxis(xaxis_data=xlist)1586 kline.add_yaxis(series_name="Dow-Jones index",y_axis=datas,itemstyle_opts=opts.ItemStyleOpts(color=style.setdefault('color',"#ec0000"), color0=style.setdefault('color0',"#00da3c")))1587 kline.set_global_opts(title_opts=opts.TitleOpts(title=title,subtitle="MA(5,10,30,60)",),1588 xaxis_opts=opts.AxisOpts(type_="category"),1589 yaxis_opts=opts.AxisOpts(is_scale=True,splitarea_opts=opts.SplitAreaOpts(is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1))),1590 legend_opts=opts.LegendOpts(is_show=False, pos_bottom=10, pos_left="center"),1591 datazoom_opts=[opts.DataZoomOpts(is_show=False,type_="inside",xaxis_index=[0, 1],range_start=0,range_end=100,),1592 opts.DataZoomOpts(is_show=True,xaxis_index=[0, 1],type_="slider",pos_top="90%",range_start=0,range_end=100,)],1593 tooltip_opts=opts.TooltipOpts(trigger="axis",axis_pointer_type="cross",background_color="rgba(245, 245, 245, 0.8)",1594 border_width=1,border_color="#ccc",textstyle_opts=opts.TextStyleOpts(color="#000")),1595 visualmap_opts=opts.VisualMapOpts(is_show=False,dimension=2,series_index=5,is_piecewise=True,1596 pieces=[{"value": 1, "color": "#ec0000"},{"value": -1, "color": "#00da3c"}]),1597 axispointer_opts=opts.AxisPointerOpts(is_show=True,link=[{"xAxisIndex": "all"}],label=opts.LabelOpts(background_color="#777")),1598 brush_opts=opts.BrushOpts(x_axis_index="all",brush_link="all",out_of_brush={"colorAlpha": 0.1},brush_type="lineX")1599 )1600 line = Line(themetype)1601 line.add_xaxis(xaxis_data=xlist)1602 line.add_yaxis(series_name="MA5",y_axis=calculate_ma(day_count=5, d=datas),is_smooth=True,is_hover_animation=False,1603 linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),label_opts=opts.LabelOpts(is_show=False))1604 line.add_yaxis(series_name="MA10",y_axis=calculate_ma(day_count=10, d=datas),is_smooth=True,is_hover_animation=False,1605 linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),label_opts=opts.LabelOpts(is_show=False))1606 line.add_yaxis(series_name="MA30",y_axis=calculate_ma(day_count=30, d=datas),is_smooth=True,is_hover_animation=False,1607 linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),label_opts=opts.LabelOpts(is_show=False))1608 line.add_yaxis(series_name="MA60",y_axis=calculate_ma(day_count=60, d=datas),is_smooth=True,is_hover_animation=False,1609 linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),label_opts=opts.LabelOpts(is_show=False))1610 line.set_global_opts(xaxis_opts=opts.AxisOpts(type_="category"))1611 bar = Bar(themetype)1612 bar.add_xaxis(xaxis_data=xlist)1613 bar.add_yaxis(series_name="Volume",yaxis_data=[[i, datas[i][3], 1 if datas[i][0] > datas[i][1] else -1] for i in range(len(datas))],1614 xaxis_index=1,yaxis_index=1,label_opts=opts.LabelOpts(is_show=False))1615 bar.set_global_opts(xaxis_opts=opts.AxisOpts(type_="category",is_scale=True,grid_index=1,boundary_gap=False,1616 axisline_opts=opts.AxisLineOpts(is_on_zero=False),axistick_opts=opts.AxisTickOpts(is_show=False),1617 splitline_opts=opts.SplitLineOpts(is_show=False),axislabel_opts=opts.LabelOpts(is_show=False),1618 split_number=20,min_="dataMin",max_="dataMax",),1619 yaxis_opts=opts.AxisOpts(grid_index=1,is_scale=True,split_number=2,1620 axislabel_opts=opts.LabelOpts(is_show=False),1621 axisline_opts=opts.AxisLineOpts(is_show=False),1622 axistick_opts=opts.AxisTickOpts(is_show=False),1623 splitline_opts=opts.SplitLineOpts(is_show=False)),1624 legend_opts=opts.LegendOpts(is_show=False),1625 )1626 # Kline And Line1627 overlap_kline_line = kline.overlap(line)1628 # Grid Overlap + Bar1629 c = Grid()1630 c.add(overlap_kline_line,grid_opts=opts.GridOpts(pos_left="10%", pos_right="8%", height="50%"))1631 c.add(bar,grid_opts=opts.GridOpts(pos_left="10%", pos_right="8%", pos_top="70%", height="16%"))1632 return c1633 elif chart_type == 'table': # è¡¨æ ¼1634 c = Table(themetype)1635 c.add(xlist, datas)1636 c.set_global_opts(title_opts=opts.ComponentTitleOpts(title=title),)1637 return c1638 elif chart_type == 'timeline_bar': # æ¶é´çº¿è½®ææ±ç¶å¾1639 c = Timeline()1640 for i in ylist:1641 b = Bar(themetype)1642 b.add_xaxis(xlist)1643 b.add_yaxis(i, zdict[i]) 1644 b.set_global_opts(title_opts=opts.TitleOpts("{}".format(i),pos_top=style.setdefault('title_pos_top',None),1645 pos_right=style.setdefault('title_pos_right',None)),1646 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1647 pos_left=style.setdefault('legend_pos_left',None),1648 pos_right=style.setdefault('legend_pos_right',None)),1649 )1650 c.add(b, "{}".format(i))1651 return c1652 elif chart_type == 'timeline_pie': # æ¶é´çº¿è½®æ饼å¾1653 c = Timeline()1654 for i in ylist:1655 b = Pie(themetype)1656 data_pair = list(zip(xlist,zdict[i]))1657 b.add(series_name=i,data_pair=data_pair)1658 b.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))1659 b.set_global_opts(title_opts=opts.TitleOpts("{}".format(i),pos_top=style.setdefault('title_pos_top',None),1660 pos_right=style.setdefault('title_pos_right',None)),1661 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1662 pos_left=style.setdefault('legend_pos_left',None),1663 pos_right=style.setdefault('legend_pos_right',None)),1664 )1665 c.add(b, "{}".format(i))1666 return c1667 elif chart_type == 'timeline_map': # æ¶é´çº¿è½®æå°å¾1668 zdict={}1669 for i in range(len(ylist)):1670 zdict[ylist[i]]=[]1671 for row in datas:1672 row=list(row)1673 i=row[0]1674 del row[0]1675 zdict[i].append(row)1676 c = Timeline()1677 for i in ylist:1678 b = Map(themetype)1679 b.add(xlist[1],zdict[i], xlist[0])1680 b.set_series_opts(label_opts=opts.LabelOpts(is_show=style.setdefault('is_show',False)))1681 if style.setdefault('max_',0) ==0 :1682 b.set_global_opts(1683 title_opts=opts.TitleOpts("{}".format(i),pos_top=style.setdefault('title_pos_top',None),1684 pos_right=style.setdefault('title_pos_right',None)),1685 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1686 pos_left=style.setdefault('legend_pos_left',None),1687 pos_right=style.setdefault('legend_pos_right',None)),1688 )1689 else: 1690 b.set_global_opts(1691 title_opts=opts.TitleOpts("{}".format(i),pos_top=style.setdefault('title_pos_top',None),1692 pos_right=style.setdefault('title_pos_right',None)),1693 legend_opts=opts.LegendOpts(pos_top=style.setdefault('legend_pos_top',None),1694 pos_left=style.setdefault('legend_pos_left',None),1695 pos_right=style.setdefault('legend_pos_right',None)),1696 visualmap_opts=opts.VisualMapOpts(max_=style.setdefault('max_',200),is_piecewise=style.setdefault('is_piecewise',True)),1697 )1698 c.add(b, "{}".format(i))1699 return c1700 elif chart_type == 'image': # å¾å1701 c = Image(themetype)1702 c.add(src=xlist[0],style_opts=style)1703 c.set_global_opts(title_opts=ComponentTitleOpts(title=title))1704 return c1705if __name__=="__main__":1706 1707 dbinfo=["127.0.0.1","root","",3306,"orcl"] #host,user,passwd,port,sid1708 config_file="dbset.ini"1709 chart_title=""1710 chart_count = 01711 save_as = "html"#png,html1712 database_type = "MySQL"1713 opt, args = getopt.getopt(sys.argv[1:], "p:s:")1714 for o,v in opt:1715 if o == "-p":1716 config_file = v1717 elif o == "-s":1718 save_as = v1719 config = configparser.ConfigParser()1720 config.read(config_file,encoding="utf-8-sig")1721 dbinfo[0] = config.get("database","host")1722 dbinfo[1] = config.get("database","user")1723 dbinfo[2] = config.get("database","passwd")1724 dbinfo[3] = config.get("database", "port")1725 chart_title = config.get("chart", "chart_title")1726 mutli_chart_type = config.get("chart", "mutli_chart_type")1727 all_in_one_page = config.get("chart", "all_in_one_page")1728 draggable = config.get("chart", "draggable")1729 chart_count = int(config.get("chart", "chart_count"))1730 database_type = config.get("database", "type")1731 if database_type == "MySQL":1732 import MySQLdb1733 from warnings import filterwarnings1734 filterwarnings('ignore', category=MySQLdb.Warning)1735 elif database_type == "Oracle":1736 import cx_Oracle1737 dbinfo[4] = config.get("database", "sid")1738 conn = f_get_conn(dbinfo,database_type)1739 1740 if mutli_chart_type=='page':1741 if all_in_one_page =='ON':1742 if draggable=='ON':1743 page = Page(layout=Page.DraggablePageLayout)1744 else:1745 page = Page()1746 else:1747 page = Tab()1748 n = 01749 while n < chart_count:1750 n += 11751 switch = config.get ( "chart", "switch"+str(n))1752 if switch=='ON':1753 title = config.get ( "chart", "title"+str(n))1754 chart_type = config.get ( "chart", "chart_type"+str(n))1755 if chart_type[0:4] != 'grid':1756 x = config.get ( "chart", "x"+str(n))1757 y = config.get ( "chart", "y"+str(n))1758 data = config.get ( "chart", "data"+str(n))1759 strstyle = config.get ( "chart", "style"+str(n))1760 style = eval(strstyle)1761 1762 style_themetype=style.setdefault('themetype','WHITE')1763 if style_themetype=='WHITE':1764 themetype=init_opts=opts.InitOpts(theme=ThemeType.WHITE,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1765 elif style_themetype=='LIGHT':1766 themetype=init_opts=opts.InitOpts(theme=ThemeType.LIGHT,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1767 elif style_themetype=='DARK':1768 themetype=init_opts=opts.InitOpts(theme=ThemeType.DARK,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1769 elif style_themetype=='CHALK':1770 themetype=init_opts=opts.InitOpts(theme=ThemeType.CHALK,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1771 elif style_themetype=='ESSOS':1772 themetype=init_opts=opts.InitOpts(theme=ThemeType.ESSOS,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1773 elif style_themetype=='INFOGRAPHIC':1774 themetype=init_opts=opts.InitOpts(theme=ThemeType.INFOGRAPHIC,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1775 elif style_themetype=='MACARONS':1776 themetype=init_opts=opts.InitOpts(theme=ThemeType.MACARONS,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1777 elif style_themetype=='PURPLE_PASSION':1778 themetype=init_opts=opts.InitOpts(theme=ThemeType.PURPLE_PASSION,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1779 elif style_themetype=='ROMA':1780 themetype=init_opts=opts.InitOpts(theme=ThemeType.ROMA,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1781 elif style_themetype=='ROMANTIC':1782 themetype=init_opts=opts.InitOpts(theme=ThemeType.ROMANTIC,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1783 elif style_themetype=='SHINE':1784 themetype=init_opts=opts.InitOpts(theme=ThemeType.SHINE,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1785 elif style_themetype=='VINTAGE':1786 themetype=init_opts=opts.InitOpts(theme=ThemeType.VINTAGE,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1787 elif style_themetype=='WALDEN':1788 themetype=init_opts=opts.InitOpts(theme=ThemeType.WALDEN,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1789 elif style_themetype=='WESTEROS':1790 themetype=init_opts=opts.InitOpts(theme=ThemeType.WESTEROS,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1791 elif style_themetype=='WONDERLAND':1792 themetype=init_opts=opts.InitOpts(theme=ThemeType.WONDERLAND,width=style.setdefault('Initopts_width',"1000px"), height=style.setdefault('Initopts_height',"600px"))1793 if save_as=='html':1794 if all_in_one_page =='ON':1795 if mutli_chart_type=='page':1796 page.add(chart(conn,database_type,chart_type,title,x,y,data,style,themetype))1797 else:1798 page.add(chart(conn,database_type,chart_type,title,x,y,data,style,themetype),title)1799 else:1800 chart(conn,database_type,chart_type,title,x,y,data,style,themetype).render(path=title + '.' + save_as)1801 else:1802 make_snapshot(snapshot, chart(conn,database_type,chart_type,title,x,y,data,style,themetype).render(), title + '.png')1803 else:1804 grid = Grid()1805 chart_count_grid = int(config.get("chart", "chart_count"+str(n)))1806 grid_chart_type = chart_type1807 m = 01808 while m < chart_count_grid:1809 m += 11810 title = config.get ( "chart", "title"+str(n)+'_'+str(m))1811 chart_type = config.get ( "chart", "chart_type"+str(n)+'_'+str(m))1812 x = config.get ( "chart", "x"+str(n)+'_'+str(m))1813 y = config.get ( "chart", "y"+str(n)+'_'+str(m))1814 data = config.get ( "chart", "data"+str(n)+'_'+str(m))1815 strstyle = config.get ( "chart", "style"+str(n)+'_'+str(m))1816 style = eval(strstyle)1817 themetype=init_opts=opts.InitOpts(theme=ThemeType.WHITE)1818 c = chart(conn,database_type,chart_type,title,x,y,data,style,themetype)1819 if grid_chart_type == 'grid_vertical':1820 if m==1:1821 grid.add(c, grid_opts=opts.GridOpts(pos_bottom=style.setdefault('grid_pos_bottom',"60%")))1822 else:1823 grid.add(c, grid_opts=opts.GridOpts(pos_top=style.setdefault('grid_pos_top',"60%")))1824 else:1825 if m==1:1826 grid.add(c, grid_opts=opts.GridOpts(pos_left=style.setdefault('grid_pos_left',"55%")))1827 else:1828 grid.add(c, grid_opts=opts.GridOpts(pos_right=style.setdefault('grid_pos_right',"55%")))1829 if save_as=='html':1830 if all_in_one_page =='ON':1831 page.add(grid)1832 else:1833 grid.render(path=title + '.' + save_as)1834 else:1835 make_snapshot(snapshot, grid.render(), title + '.png')1836 if all_in_one_page =='ON':1837 page.render(path=chart_title + '.' + save_as)...
pytypeobject.py
Source:pytypeobject.py
...61 Generates the type structure. All slots are optional except62 'tp_name', 'tp_basicsize', and the pseudo-slot 'typestruct'.63 """64 slots = dict(self.slots)65 slots.setdefault('tp_dealloc', 'NULL')66 slots.setdefault('tp_getattr', 'NULL')67 slots.setdefault('tp_setattr', 'NULL')68 slots.setdefault('tp_compare', 'NULL')69 slots.setdefault('tp_repr', 'NULL')70 slots.setdefault('tp_as_number', 'NULL')71 slots.setdefault('tp_as_sequence', 'NULL')72 slots.setdefault('tp_as_mapping', 'NULL')73 slots.setdefault('tp_hash', 'NULL')74 slots.setdefault('tp_call', 'NULL')75 slots.setdefault('tp_str', 'NULL')76 slots.setdefault('tp_getattro', 'NULL')77 slots.setdefault('tp_setattro', 'NULL')78 slots.setdefault('tp_as_buffer', 'NULL')79 slots.setdefault('tp_flags', 'Py_TPFLAGS_DEFAULT')80 slots.setdefault('tp_doc', 'NULL')81 slots.setdefault('tp_traverse', 'NULL')82 slots.setdefault('tp_clear', 'NULL')83 slots.setdefault('tp_richcompare', 'NULL')84 slots.setdefault('tp_weaklistoffset', '0')85 slots.setdefault('tp_iter', 'NULL')86 slots.setdefault('tp_iternext', 'NULL')87 slots.setdefault('tp_methods', 'NULL')88 slots.setdefault('tp_getset', 'NULL')89 slots.setdefault('tp_descr_get', 'NULL')90 slots.setdefault('tp_descr_set', 'NULL')91 slots.setdefault('tp_dictoffset', '0')92 slots.setdefault('tp_init', 'NULL')93 slots.setdefault('tp_alloc', 'PyType_GenericAlloc')94 slots.setdefault('tp_new', 'PyType_GenericNew')95 slots.setdefault('tp_free', '0')96 slots.setdefault('tp_is_gc', 'NULL')97 98 code_sink.writeln(self.TEMPLATE % slots)99class PyNumberMethods(object):100 TEMPLATE = (101 'static PyNumberMethods %(variable)s = {\n'102 ' (binaryfunc) %(nb_add)s,\n'103 ' (binaryfunc) %(nb_subtract)s,\n'104 ' (binaryfunc) %(nb_multiply)s,\n'105 ' (binaryfunc) %(nb_divide)s,\n'106 ' (binaryfunc) %(nb_remainder)s,\n'107 ' (binaryfunc) %(nb_divmod)s,\n'108 ' (ternaryfunc) %(nb_power)s,\n'109 ' (unaryfunc) %(nb_negative)s,\n'110 ' (unaryfunc) %(nb_positive)s,\n'111 ' (unaryfunc) %(nb_absolute)s,\n'112 ' (inquiry) %(nb_nonzero)s,\n'113 ' (unaryfunc) %(nb_invert)s,\n'114 ' (binaryfunc) %(nb_lshift)s,\n'115 ' (binaryfunc) %(nb_rshift)s,\n'116 ' (binaryfunc) %(nb_and)s,\n'117 ' (binaryfunc) %(nb_xor)s,\n'118 ' (binaryfunc) %(nb_or)s,\n'119 ' (coercion) %(nb_coerce)s,\n'120 ' (unaryfunc) %(nb_int)s,\n'121 ' (unaryfunc) %(nb_long)s,\n'122 ' (unaryfunc) %(nb_float)s,\n'123 ' (unaryfunc) %(nb_oct)s,\n'124 ' (unaryfunc) %(nb_hex)s,\n'125 ' /* Added in release 2.0 */\n'126 ' (binaryfunc) %(nb_inplace_add)s,\n'127 ' (binaryfunc) %(nb_inplace_subtract)s,\n'128 ' (binaryfunc) %(nb_inplace_multiply)s,\n'129 ' (binaryfunc) %(nb_inplace_divide)s,\n'130 ' (binaryfunc) %(nb_inplace_remainder)s,\n'131 ' (ternaryfunc) %(nb_inplace_power)s,\n'132 ' (binaryfunc) %(nb_inplace_lshift)s,\n'133 ' (binaryfunc) %(nb_inplace_rshift)s,\n'134 ' (binaryfunc) %(nb_inplace_and)s,\n'135 ' (binaryfunc) %(nb_inplace_xor)s,\n'136 ' (binaryfunc) %(nb_inplace_or)s,\n'137 '\n'138 ' /* Added in release 2.2 */\n'139 ' /* The following require the Py_TPFLAGS_HAVE_CLASS flag */\n'140 ' (binaryfunc) %(nb_floor_divide)s,\n'141 ' (binaryfunc) %(nb_true_divide)s,\n'142 ' (binaryfunc) %(nb_inplace_floor_divide)s,\n'143 ' (binaryfunc) %(nb_inplace_true_divide)s,\n'144 '\n'145 '#if PY_VERSION_HEX >= 0x020500F0\n'146 ' /* Added in release 2.5 */\n'147 ' (unaryfunc) %(nb_index)s,\n'148 '\n'149 '#endif\n'150 '};\n'151 )152 def __init__(self):153 self.slots = {}154 def generate(self, code_sink):155 """156 Generates the structure. All slots are optional except 'variable'.157 """158 slots = dict(self.slots)159 slots.setdefault('nb_add', 'NULL')160 slots.setdefault('nb_subtract', 'NULL')161 slots.setdefault('nb_multiply', 'NULL')162 slots.setdefault('nb_divide', 'NULL')163 slots.setdefault('nb_remainder', 'NULL')164 slots.setdefault('nb_divmod', 'NULL')165 slots.setdefault('nb_power', 'NULL')166 slots.setdefault('nb_negative', 'NULL')167 slots.setdefault('nb_positive', 'NULL')168 slots.setdefault('nb_absolute', 'NULL')169 slots.setdefault('nb_nonzero', 'NULL')170 slots.setdefault('nb_invert', 'NULL')171 slots.setdefault('nb_lshift', 'NULL')172 slots.setdefault('nb_rshift', 'NULL')173 slots.setdefault('nb_and', 'NULL')174 slots.setdefault('nb_xor', 'NULL')175 slots.setdefault('nb_or', 'NULL')176 slots.setdefault('nb_coerce', 'NULL')177 slots.setdefault('nb_int', 'NULL')178 slots.setdefault('nb_long', 'NULL')179 slots.setdefault('nb_float', 'NULL')180 slots.setdefault('nb_oct', 'NULL')181 slots.setdefault('nb_hex', 'NULL')182 slots.setdefault('nb_inplace_add', 'NULL')183 slots.setdefault('nb_inplace_subtract', 'NULL')184 slots.setdefault('nb_inplace_multiply', 'NULL')185 slots.setdefault('nb_inplace_divide', 'NULL')186 slots.setdefault('nb_inplace_remainder', 'NULL')187 slots.setdefault('nb_inplace_power', 'NULL')188 slots.setdefault('nb_inplace_lshift', 'NULL')189 slots.setdefault('nb_inplace_rshift', 'NULL')190 slots.setdefault('nb_inplace_and', 'NULL')191 slots.setdefault('nb_inplace_xor', 'NULL')192 slots.setdefault('nb_inplace_or', 'NULL')193 slots.setdefault('nb_floor_divide', 'NULL')194 slots.setdefault('nb_true_divide', 'NULL')195 slots.setdefault('nb_inplace_floor_divide', 'NULL')196 slots.setdefault('nb_inplace_true_divide', 'NULL')197 slots.setdefault('nb_index', 'NULL')198 code_sink.writeln(self.TEMPLATE % slots)199class PySequenceMethods(object):200 TEMPLATE = '''201static PySequenceMethods %(variable)s = {202 (lenfunc) %(sq_length)s,203 (binaryfunc) %(sq_concat)s,204 (ssizeargfunc) %(sq_repeat)s,205 (ssizeargfunc) %(sq_item)s,206 (ssizessizeargfunc) %(sq_slice)s,207 (ssizeobjargproc) %(sq_ass_item)s,208 (ssizessizeobjargproc) %(sq_ass_slice)s,209 (objobjproc) %(sq_contains)s,210 /* Added in release 2.0 */211 (binaryfunc) %(sq_inplace_concat)s,212 (ssizeargfunc) %(sq_inplace_repeat)s,213};214'''215 FUNCTION_TEMPLATES = {216 "sq_length" : '''217static Py_ssize_t218%(wrapper_name)s (%(py_struct)s *py_self)219{220 PyObject *py_result;221 Py_ssize_t result;222 py_result = %(method_name)s(py_self);223 if (py_result == NULL) {224 return -1;225 }226 result = PyInt_AsSsize_t(py_result);227 Py_DECREF(py_result);228 return result;229}230''',231 # This hacky version is necessary 'cause if we're calling a function rather than a method232 # or an overloaded wrapper the args parameter gets tacked into the call sequence.233 "sq_length_ARGS" : '''234static Py_ssize_t235%(wrapper_name)s (%(py_struct)s *py_self)236{237 PyObject *py_result;238 PyObject *args;239 Py_ssize_t result;240 args = PyTuple_New (0);241 py_result = %(method_name)s(py_self, args, NULL);242 Py_DECREF(args);243 if (py_result == NULL) {244 return -1;245 }246 result = PyInt_AsSsize_t(py_result);247 Py_DECREF(py_result);248 return result;249}250''',251 "sq_item" : '''252static PyObject*253%(wrapper_name)s (%(py_struct)s *py_self, Py_ssize_t py_i)254{255 PyObject *result;256 PyObject *args;257 args = Py_BuildValue("(i)", py_i);258 result = %(method_name)s(py_self, args, NULL);259 Py_DECREF(args);260 if (PyErr_ExceptionMatches(PyExc_IndexError) ||261 PyErr_ExceptionMatches(PyExc_StopIteration)) {262 Py_XDECREF(result);263 return NULL;264 } else {265 return result;266 }267}268''',269 "sq_ass_item" : '''270static int271%(wrapper_name)s (%(py_struct)s *py_self, Py_ssize_t py_i, PyObject *py_val)272{273 PyObject *result;274 PyObject *args;275 args = Py_BuildValue("(iO)", py_i, py_val);276 result = %(method_name)s(py_self, args, NULL);277 Py_DECREF(args);278 if (result == NULL) {279 return -1;280 } else {281 Py_DECREF(result);282 return 0;283 }284}285''',286 }287 def __init__(self):288 self.slots = {}289 def generate(self, code_sink):290 """291 Generates the structure. All slots are optional except 'variable'.292 """293 slots = dict(self.slots)294 slots.setdefault('sq_length', 'NULL')295 slots.setdefault('sq_concat', 'NULL')296 slots.setdefault('sq_repeat', 'NULL')297 slots.setdefault('sq_item', 'NULL')298 slots.setdefault('sq_slice', 'NULL')299 slots.setdefault('sq_ass_item', 'NULL')300 slots.setdefault('sq_ass_slice', 'NULL')301 slots.setdefault('sq_contains', 'NULL')302 slots.setdefault('sq_inplace_concat', 'NULL')303 slots.setdefault('sq_inplace_repeat', 'NULL')...
execute.py
Source:execute.py
...59def _do_preamble(globals: Dict[str, object], should_log_stacks=False) -> None:60 """Add key-value pairs expected by Concat code to the passed-in mapping.61 This mutates the mapping, but anything already in the mapping is preserved.62 """63 globals.setdefault('concat', concat)64 globals.setdefault('py_call', py_call)65 globals.setdefault('stack', LoggableStack('stack', should_log_stacks))66 globals.setdefault('stash', LoggableStack('stash', should_log_stacks))67 def push(val: object) -> Callable[[List[object], List[object]], None]:68 def push_func(stack: List[object], _: List[object]):69 stack.append(val)70 return push_func71 globals.setdefault('push', push)72 # needed by generated code to work73 globals.setdefault('concat', concat)74 globals.setdefault('to_int', concat.stdlib.pyinterop.to_int)75 globals.setdefault('to_bool', concat.stdlib.pyinterop.to_bool)76 globals.setdefault('to_complex', concat.stdlib.pyinterop.to_complex)77 globals.setdefault('len', concat.stdlib.pyinterop.len)78 globals.setdefault('getitem', concat.stdlib.pyinterop.getitem)79 globals.setdefault('to_float', concat.stdlib.pyinterop.to_float)80 globals.setdefault('decode_bytes', concat.stdlib.pyinterop.decode_bytes)81 globals.setdefault('to_tuple', concat.stdlib.pyinterop.to_tuple)82 globals.setdefault('to_bytes', concat.stdlib.pyinterop.to_bytes)83 globals.setdefault('to_list', concat.stdlib.pyinterop.to_list)84 globals.setdefault('to_bytearray', concat.stdlib.pyinterop.to_bytearray)85 globals.setdefault('to_set', concat.stdlib.pyinterop.to_set)86 globals.setdefault('add_to_set', concat.stdlib.pyinterop.add_to_set)87 globals.setdefault('to_frozenset', concat.stdlib.pyinterop.to_frozenset)88 globals.setdefault('to_dict', concat.stdlib.pyinterop.to_dict)89 globals.setdefault('user_defined_function', udf)90 globals.setdefault('method', concat.stdlib.pyinterop.method)91 globals.setdefault('with_async', concat.stdlib.pyinterop.with_async)92 globals.setdefault('for_async', concat.stdlib.pyinterop.for_async)93 globals.setdefault('coroutine', concat.stdlib.pyinterop.coroutine)94 globals.setdefault('math', concat.stdlib.pyinterop.math)95 globals.setdefault('import_module', concat.stdlib.pyinterop.import_module)96 globals.setdefault(97 'import_advanced', concat.stdlib.pyinterop.import_advanced98 )99 globals.setdefault('custom_class', concat.stdlib.pyinterop.custom_class)100 globals.setdefault('instance', concat.stdlib.pyinterop.instance)101 globals.setdefault('open', concat.stdlib.pyinterop.open)102 globals.setdefault('popen', concat.stdlib.pyinterop.popen)103 globals.setdefault('fdopen', concat.stdlib.pyinterop.fdopen)104 globals.setdefault('call', concat.stdlib.pyinterop.call)105 globals.setdefault('curry', concat.stdlib.compositional.curry)106 globals.setdefault('drop', concat.stdlib.shuffle_words.drop)107 globals.setdefault('drop_2', concat.stdlib.shuffle_words.drop_2)108 globals.setdefault('drop_3', concat.stdlib.shuffle_words.drop_3)109 globals.setdefault('nip', concat.stdlib.shuffle_words.nip)110 globals.setdefault('nip_2', concat.stdlib.shuffle_words.nip_2)111 globals.setdefault('dup', concat.stdlib.shuffle_words.dup)112 globals.setdefault('dup_2', concat.stdlib.shuffle_words.dup_2)113 globals.setdefault('swap', concat.stdlib.shuffle_words.swap)114 globals.setdefault('dup_3', concat.stdlib.shuffle_words.dup_3)115 globals.setdefault('over', concat.stdlib.shuffle_words.over)116 globals.setdefault('over_2', concat.stdlib.shuffle_words.over_2)117 globals.setdefault('pick', concat.stdlib.shuffle_words.pick)118 globals.setdefault('to_slice', concat.stdlib.pyinterop.to_slice)119 globals.setdefault('choose', concat.stdlib.execution.choose)120 globals.setdefault('if_then', concat.stdlib.execution.if_then)121 globals.setdefault('if_not', concat.stdlib.execution.if_not)122 globals.setdefault('case', concat.stdlib.execution.case)123 globals.setdefault('loop', concat.stdlib.execution.loop)124 globals.setdefault('True', lambda s, _: s.append(True))125 globals.setdefault('False', lambda s, _: s.append(False))126 globals.setdefault('None', lambda s, _: s.append(None))127 globals.setdefault('NotImplemented', lambda s, _: s.append(NotImplemented))128 globals.setdefault('Ellipsis', lambda s, _: s.append(...))129 globals.setdefault('...', lambda s, _: s.append(...))130 # Operators131 globals.setdefault('is', lambda s, _: s.append(s.pop() is s.pop()))132 globals.setdefault('>=', lambda s, _: s.append(s.pop(-2) >= s.pop()))133 globals.setdefault('-', lambda s, _: s.append(s.pop(-2) - s.pop()))134 globals.setdefault('+', lambda s, _: s.append(s.pop(-2) + s.pop()))135def execute(136 filename: str,137 ast: ast.Module,138 globals: Dict[str, object],139 locals: Optional[Dict[str, object]] = None,140 should_log_stacks=False,141) -> None:142 _do_preamble(globals, should_log_stacks)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!