12
12
"""
13
13
import sys
14
14
import math
15
-
15
+ import re
16
16
17
17
from zoomeye import config
18
18
19
19
20
- def char_by_atan (stat , at , color ):
20
+ def char_by_atan (stat , at , color ):#用于根据给定的百分比值(at)和颜色(color),返回相应的字符,用于绘制饼状图的每个部分
21
21
"""
22
22
:param stat: list, all data and label
23
23
:param at: float, percentage
@@ -31,7 +31,7 @@ def char_by_atan(stat, at, color):
31
31
return char_by_atan (stat [1 :], at - stat [0 ][1 ], color [1 :])
32
32
33
33
34
- def show_pie_chart (stat ):
34
+ def show_pie_chart (stat ):#用于显示饼状图
35
35
"""
36
36
print pie chart in terminal
37
37
:param stat: list, all data and label
@@ -65,7 +65,7 @@ def show_pie_chart(stat):
65
65
count += 1
66
66
67
67
68
- def unicode_output ():
68
+ def unicode_output ():#用于检查当前的标准输出是否支持Unicode
69
69
"""
70
70
unicode standard output
71
71
"""
@@ -75,7 +75,7 @@ def unicode_output():
75
75
)
76
76
77
77
78
- def trim_zeros (lst ):
78
+ def trim_zeros (lst ):#用于去除列表(lst)末尾的零元素
79
79
"""
80
80
81
81
"""
@@ -87,7 +87,7 @@ def trim_zeros(lst):
87
87
return lst [:- k ] if k > 0 else lst
88
88
89
89
90
- def get_matrix (counts , max_size , bar_width ):
90
+ def get_matrix (counts , max_size , bar_width ):#用于生成直方图的矩阵表示,用于绘制直方图
91
91
"""
92
92
get the length of the histogram corresponding to each data
93
93
:param counts: list, all data
@@ -117,7 +117,7 @@ def get_matrix(counts, max_size, bar_width):
117
117
return out
118
118
119
119
120
- def generate_histogram (values , labels = None , force_ascii = False ):
120
+ def generate_histogram (values , labels = None , force_ascii = False ):#用于生成直方图
121
121
"""
122
122
print histogram in terminal
123
123
take the largest data as the standard, that is, the largest data is the longest
@@ -134,20 +134,20 @@ def generate_histogram(values, labels=None, force_ascii=False):
134
134
else :
135
135
chars = [" " , "#" , "#" , "#" , "#" , "#" , "#" , "#" , "#" ]
136
136
137
- ft = []
137
+ fmt = []
138
138
if labels is not None :
139
139
cfmt = "{{:{}s}}" .format (max ([len (str (label )) for label in labels ]))
140
- ft .append (cfmt )
140
+ fmt .append (cfmt )
141
141
# show values
142
142
all_int = all (val == int (val ) for val in values )
143
143
if all_int :
144
144
cfmt = "{{:{}d}}" .format (max ([len (str (val )) for val in values ]))
145
145
else :
146
146
cfmt = "{}"
147
- ft .append ("[" + cfmt + "]" )
147
+ fmt .append ("[" + cfmt + "]" )
148
148
149
- ft .append ("{}" )
150
- ft = " " .join (ft )
149
+ fmt .append ("{}" )
150
+ fmt = " " .join (fmt )
151
151
152
152
out = []
153
153
for k , (val , row ) in enumerate (zip (values , matrix )):
@@ -159,7 +159,7 @@ def generate_histogram(values, labels=None, force_ascii=False):
159
159
# cut off trailing zeros
160
160
r = trim_zeros (row )
161
161
data .append ("" .join (chars [item ] for item in r ))
162
- out .append (ft .format (* data ))
162
+ out .append (fmt .format (* data ))
163
163
for item in out :
164
164
print (' ' + item )
165
165
0 commit comments