lukhed-basic-utils 1.2.2__tar.gz → 1.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/PKG-INFO +1 -1
- lukhed_basic_utils-1.3.0/lukhed_basic_utils/chartJsCommon.py +624 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils/githubCommon.py +1 -1
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils.egg-info/PKG-INFO +1 -1
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils.egg-info/SOURCES.txt +1 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/setup.py +1 -1
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/LICENSE +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/README.md +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils/__init__.py +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils/classCommon.py +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils/fileCommon.py +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils/listWorkCommon.py +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils/mathCommon.py +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils/osCommon.py +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils/requestsCommon.py +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils/stringCommon.py +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils/timeCommon.py +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils.egg-info/dependency_links.txt +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils.egg-info/requires.txt +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils.egg-info/top_level.txt +0 -0
- {lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/setup.cfg +0 -0
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
from lukhed_basic_utils import listWorkCommon as lC
|
|
2
|
+
import random
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def create_line_chart(x_axis_list=None, y_axis_lists=None, y_labels=None, line_label_border_colors=None,
|
|
6
|
+
point_bg_color=None, point_radii=None, additional_data=None):
|
|
7
|
+
"""
|
|
8
|
+
Creates a line chart json compatible with chartJs
|
|
9
|
+
|
|
10
|
+
:param x_axis_list: list() or None, list of x axis labels. If None is provided, defaults to a list
|
|
11
|
+
of numbers.
|
|
12
|
+
|
|
13
|
+
starting example: [Jan, Feb, March, April]
|
|
14
|
+
|
|
15
|
+
:param y_axis_lists: list() or None, list or list of list containing the y values for the lines
|
|
16
|
+
you want to plot. If multiple lines, it should be a list of lists,
|
|
17
|
+
with each list containing the y data for a line. Note, the y data in each
|
|
18
|
+
list should correspond 1 to 1 with the x axis list. If None is provided, a
|
|
19
|
+
simple, randomly generated dataset will be utilized.
|
|
20
|
+
|
|
21
|
+
example cont., 2 lines on the x axis: [[1,2,3,4], [2,4,6,8]]
|
|
22
|
+
|
|
23
|
+
:param y_labels: list() or None, Each data set provided in y_axis_list should have a label. If
|
|
24
|
+
None, then a string "line + #" will be used.
|
|
25
|
+
|
|
26
|
+
example cont: [line 1, line 2]
|
|
27
|
+
|
|
28
|
+
:param line_label_border_colors: list() or None, list of colors to be associated with each line. In chart js
|
|
29
|
+
the line color is the same as the legend label border color.
|
|
30
|
+
|
|
31
|
+
example cont: [red, blue]
|
|
32
|
+
|
|
33
|
+
:param point_bg_color: list() or None, list of colors to be associated with the point colors of each
|
|
34
|
+
line. In chartjs, the point color can be a different color than the line. This
|
|
35
|
+
point color is also the main "bg color" of the label in the legend.
|
|
36
|
+
Note: this is not a color for each point, but a color for each line whose
|
|
37
|
+
points will be of this color.
|
|
38
|
+
|
|
39
|
+
If None is provided, then the point will be
|
|
40
|
+
the same as the line color
|
|
41
|
+
|
|
42
|
+
:param point_radii None or list(). List must correspond to
|
|
43
|
+
Each point can be assigned one value (use int),
|
|
44
|
+
Assign every point its own value (use list)
|
|
45
|
+
None, it will be default chartJS value
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
:param additional_data: dict(), any additional data you want as a separate dict
|
|
49
|
+
to be available with your chart
|
|
50
|
+
|
|
51
|
+
:return: dict(), json for the chart.js is found in key "chartData"
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
if y_axis_lists is None:
|
|
55
|
+
# randomly generate y axis data of length 7
|
|
56
|
+
y_axis_lists = list()
|
|
57
|
+
i = 0
|
|
58
|
+
while i < 7:
|
|
59
|
+
n = random.randint(1, 10)
|
|
60
|
+
y_axis_lists.append(n)
|
|
61
|
+
i = i + 1
|
|
62
|
+
|
|
63
|
+
if type(y_axis_lists[0]) is not list:
|
|
64
|
+
y_axis_lists = [y_axis_lists]
|
|
65
|
+
|
|
66
|
+
if x_axis_list is None:
|
|
67
|
+
x_axis_list = list()
|
|
68
|
+
i = 0
|
|
69
|
+
while i < len(y_axis_lists[0]):
|
|
70
|
+
x_axis_list.append(i)
|
|
71
|
+
i = i + 1
|
|
72
|
+
|
|
73
|
+
if y_labels is None:
|
|
74
|
+
y_labels = list()
|
|
75
|
+
i = 1
|
|
76
|
+
while i < len(y_axis_lists) + 1:
|
|
77
|
+
y_labels.append("line " + str(i))
|
|
78
|
+
i = i + 1
|
|
79
|
+
|
|
80
|
+
if line_label_border_colors is None:
|
|
81
|
+
line_label_border_colors = lC.create_list_of_colors(len(y_axis_lists))
|
|
82
|
+
|
|
83
|
+
if point_bg_color is None:
|
|
84
|
+
point_bg_color = line_label_border_colors.copy()
|
|
85
|
+
|
|
86
|
+
if point_radii is None:
|
|
87
|
+
point_radii = len(y_axis_lists)*[3]
|
|
88
|
+
else:
|
|
89
|
+
point_radii = point_radii
|
|
90
|
+
|
|
91
|
+
data_sets = []
|
|
92
|
+
counter = 0
|
|
93
|
+
for line in y_axis_lists:
|
|
94
|
+
temp_dict = {
|
|
95
|
+
"label": y_labels[counter],
|
|
96
|
+
"data": line.copy(),
|
|
97
|
+
"pointRadius": point_radii[counter],
|
|
98
|
+
"borderColor": line_label_border_colors[counter],
|
|
99
|
+
"backgroundColor": point_bg_color[counter]
|
|
100
|
+
}
|
|
101
|
+
data_sets.append(temp_dict.copy())
|
|
102
|
+
counter = counter + 1
|
|
103
|
+
|
|
104
|
+
op_dict = {"chartData": {"labels": x_axis_list, "datasets": data_sets},
|
|
105
|
+
"additionalData": additional_data}
|
|
106
|
+
|
|
107
|
+
return op_dict
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def create_bar_chart_stacked_grouped(x_axis_list=None, bar_list=None, bar_stacks_list=None, bar_stacks_colors=None,
|
|
111
|
+
stack_value_dict=None, orientation="default", additional_data=None):
|
|
112
|
+
"""
|
|
113
|
+
Creates json for stacked barchart compatible with chartJs
|
|
114
|
+
|
|
115
|
+
:param x_axis_list: list(),
|
|
116
|
+
Each value in the list corresponds to a x-axis value, one of each corresponding to one
|
|
117
|
+
group of stacked bars. Starting example, dk salary compare for all nfl matchups. x_axis_list
|
|
118
|
+
would be each mach up ["CAR @ DET", "SEA @ LAR", ...]
|
|
119
|
+
|
|
120
|
+
:param bar_list: list()
|
|
121
|
+
of strings, list corresponding to the bars available at each x axis point. Continuing
|
|
122
|
+
example, the bars needed for each matchup would be two teams. [team1, team2]
|
|
123
|
+
|
|
124
|
+
:param bar_stacks_list: list(),
|
|
125
|
+
list corresponding to the stacks that make up each bar. Continuing the example,
|
|
126
|
+
each team bar is consisting of the salaries for each position ["QB", "RB1" "RB2"...]
|
|
127
|
+
|
|
128
|
+
:param bar_stacks_colors: list(),
|
|
129
|
+
colors for each stack in the stack list. Hex values
|
|
130
|
+
|
|
131
|
+
:param stack_value_dict: dict(),
|
|
132
|
+
the bar list values are used as keys to retrieve stack values across all axis
|
|
133
|
+
points for a common bar group. Note, the stack value list has a 1 to 1 mapping to the
|
|
134
|
+
x axis. Continuing the example
|
|
135
|
+
{
|
|
136
|
+
"team1": Two bars at each x point, so two main keys
|
|
137
|
+
{
|
|
138
|
+
"QB": [$7550, $6500, ..], Each bar has a position which is a sub key
|
|
139
|
+
"RB1": [], Each position has a list of salary values
|
|
140
|
+
"RB2": [] The salary values correspond directly to x-axis
|
|
141
|
+
}, Which in this case is a matchup.
|
|
142
|
+
"team2": So QB[0], is match-up 0, qb[1] is match-up 1
|
|
143
|
+
{ etc.
|
|
144
|
+
"QB": [],
|
|
145
|
+
"RB1": [],
|
|
146
|
+
"RB2": []
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
:param orientation: str(),
|
|
151
|
+
'vertical' or 'horizontal', default is 'vertical' corresponding to vertical bars
|
|
152
|
+
:param additional_data: dict(), Optional,
|
|
153
|
+
allows you to provide more data to be included in the json, for use in
|
|
154
|
+
in custom tooltips/legends etc. It is accessible in the final json in key "additionalData"
|
|
155
|
+
|
|
156
|
+
:return: dict(), json for the chart.js is found in key "chartData"
|
|
157
|
+
"""
|
|
158
|
+
|
|
159
|
+
if x_axis_list is None:
|
|
160
|
+
raise Exception("'x_axis_list' is a required argument")
|
|
161
|
+
if bar_stacks_list is None:
|
|
162
|
+
raise Exception("'bar_stacks_list' is a required argument")
|
|
163
|
+
if bar_list is None:
|
|
164
|
+
raise Exception("'bar_list' is a required argument")
|
|
165
|
+
if stack_value_dict is None:
|
|
166
|
+
raise Exception("'stack_value_dict' is a required argument")
|
|
167
|
+
if bar_stacks_colors is None:
|
|
168
|
+
raise Exception("'bar_stacks_colors' is a required argument")
|
|
169
|
+
if additional_data is None:
|
|
170
|
+
additional_data = {}
|
|
171
|
+
|
|
172
|
+
# For each bar
|
|
173
|
+
data_list = list()
|
|
174
|
+
a = 0
|
|
175
|
+
while a < len(bar_list):
|
|
176
|
+
|
|
177
|
+
bar_name = bar_list[a]
|
|
178
|
+
|
|
179
|
+
b = 0
|
|
180
|
+
while b < len(bar_stacks_list):
|
|
181
|
+
temp_dict = dict()
|
|
182
|
+
temp_dict["label"] = bar_stacks_list[b]
|
|
183
|
+
temp_dict["data"] = stack_value_dict[bar_name][bar_stacks_list[b]]
|
|
184
|
+
temp_dict["backgroundColor"] = bar_stacks_colors[b]
|
|
185
|
+
temp_dict["stack"] = bar_name
|
|
186
|
+
b = b + 1
|
|
187
|
+
data_list.append(temp_dict.copy())
|
|
188
|
+
|
|
189
|
+
a = a + 1
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
"chartData": {
|
|
193
|
+
"labels": x_axis_list,
|
|
194
|
+
"datasets": data_list
|
|
195
|
+
},
|
|
196
|
+
"additionalData": additional_data
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def create_bar_chart_simple(x_axis_list=None, y_axis_lists=None, y_labels=None, bar_colors=None, additional_data=None):
|
|
201
|
+
"""
|
|
202
|
+
:param x_axis_list: list() or None, list of x axis labels. If None is provided, defaults to a list
|
|
203
|
+
of numbers.
|
|
204
|
+
|
|
205
|
+
starting example: [Jan, Feb, March, April]
|
|
206
|
+
|
|
207
|
+
:param y_axis_lists: list() or None, list or list of list containing the y values for the bars
|
|
208
|
+
you want to plot. If multiple bars at each x, it should be a list of lists,
|
|
209
|
+
with each list containing the y data for the bar. Note, the y data in each
|
|
210
|
+
list should correspond 1 to 1 with the x axis list. If None is provided, a
|
|
211
|
+
simple, randomly generated dataset will be utilized.
|
|
212
|
+
|
|
213
|
+
example cont., 2 bars on the x axis: [[1,2,3,4], [2,4,6,8]]
|
|
214
|
+
|
|
215
|
+
:param y_labels: list() or None, Each data set provided in y_axis_list should have a label. If
|
|
216
|
+
None, then a string "bar + #" will be used.
|
|
217
|
+
|
|
218
|
+
example cont: [bar 1, bar 2]
|
|
219
|
+
|
|
220
|
+
:param bar_colors: list() or None, list of colors to be associated with each bar. In chart js
|
|
221
|
+
the bar color is the same as the legend label border color.
|
|
222
|
+
|
|
223
|
+
example cont: [red, blue]
|
|
224
|
+
|
|
225
|
+
:param additional_data: dict(), any additional data you want as a separate dict
|
|
226
|
+
to be available with your chart
|
|
227
|
+
|
|
228
|
+
:return: dict(), json for the chart.js is found in key "chartData"
|
|
229
|
+
"""
|
|
230
|
+
if y_axis_lists is None:
|
|
231
|
+
# randomly generate y axis data of length 7
|
|
232
|
+
y_axis_lists = list()
|
|
233
|
+
i = 0
|
|
234
|
+
while i < 7:
|
|
235
|
+
n = random.randint(1, 10)
|
|
236
|
+
y_axis_lists.append(n)
|
|
237
|
+
i = i + 1
|
|
238
|
+
|
|
239
|
+
if type(y_axis_lists[0]) is not list:
|
|
240
|
+
y_axis_lists = [y_axis_lists]
|
|
241
|
+
|
|
242
|
+
if x_axis_list is None:
|
|
243
|
+
x_axis_list = list()
|
|
244
|
+
i = 0
|
|
245
|
+
while i < len(y_axis_lists[0]):
|
|
246
|
+
x_axis_list.append("bar " + str(i))
|
|
247
|
+
i = i + 1
|
|
248
|
+
|
|
249
|
+
if y_labels is None:
|
|
250
|
+
y_labels = list()
|
|
251
|
+
i = 1
|
|
252
|
+
while i < len(y_axis_lists) + 1:
|
|
253
|
+
y_labels.append("bar " + str(i))
|
|
254
|
+
i = i + 1
|
|
255
|
+
|
|
256
|
+
if bar_colors is None:
|
|
257
|
+
bar_colors = lC.create_list_of_colors(len(y_axis_lists))
|
|
258
|
+
|
|
259
|
+
data_sets = []
|
|
260
|
+
counter = 0
|
|
261
|
+
for bar in y_axis_lists:
|
|
262
|
+
temp_dict = {
|
|
263
|
+
"label": y_labels[counter],
|
|
264
|
+
"data": bar.copy(),
|
|
265
|
+
"borderColor": bar_colors[counter],
|
|
266
|
+
"backgroundColor": bar_colors[counter]
|
|
267
|
+
}
|
|
268
|
+
data_sets.append(temp_dict.copy())
|
|
269
|
+
counter = counter + 1
|
|
270
|
+
|
|
271
|
+
op_dict = {"chartData": {"labels": x_axis_list, "datasets": data_sets},
|
|
272
|
+
"additionalData": additional_data}
|
|
273
|
+
|
|
274
|
+
return op_dict
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def create_doughnut_chart(data_values_list=None, data_labels=None, slice_colors=None,
|
|
278
|
+
additional_data=None):
|
|
279
|
+
data_values_list = parse_core_value_list(data_values_list)
|
|
280
|
+
data_labels = parse_labels(data_values_list, data_labels)
|
|
281
|
+
slice_colors = parse_core_color_list(data_values_list, slice_colors)
|
|
282
|
+
|
|
283
|
+
chart_dict = {
|
|
284
|
+
"labels": data_labels,
|
|
285
|
+
"datasets": [{"label": "Dataset 1", "data": data_values_list, "backgroundColor": slice_colors}]
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return {
|
|
289
|
+
"chartData": chart_dict,
|
|
290
|
+
"additionalData": additional_data
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def create_bubble_chart(x_axis_list=None, y_axis_list=None, radius_list=None, data_set_label=None,
|
|
295
|
+
bubble_colors=None, bubble_border_colors=None, additional_data=None):
|
|
296
|
+
"""
|
|
297
|
+
Note: If there is a choice to use different color bubbles within the same data set, you will want to turn
|
|
298
|
+
the legend off via the config constant which is set up on the javascript side.
|
|
299
|
+
|
|
300
|
+
Note 2: This function does not support multiple bubble data sets (just one set for now)
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
:param x_axis_list: list() or None, list of x axis points. If None is provided,
|
|
304
|
+
defaults to a list of numbers is provided. Note this must correspond
|
|
305
|
+
1 to 1 with the y_axis_list to form points.
|
|
306
|
+
|
|
307
|
+
starting example: [1, 2 ,3 ,4]
|
|
308
|
+
|
|
309
|
+
:param y_axis_list: list() or None, list containing the y value for the bubbles
|
|
310
|
+
you want to plot. Note, the y data in the list should correspond 1 to 1
|
|
311
|
+
with the x axis list. If None is provided, a simple, randomly generated
|
|
312
|
+
dataset will be utilized.
|
|
313
|
+
|
|
314
|
+
example cont.,: [1,2,3,4]
|
|
315
|
+
|
|
316
|
+
:param radius_list: list() or None, list containing the radius value for each bubble. Note,
|
|
317
|
+
this list should correspond 1 to 1 with each point provided via the x-list
|
|
318
|
+
and y-list parameters.
|
|
319
|
+
|
|
320
|
+
example cont.: [10, 15, 20, 30]
|
|
321
|
+
|
|
322
|
+
:param data_set_label: str() or None, Each data set provided in y_axis_list should have a label.
|
|
323
|
+
If None, then a string "Bubble Set" will be used.
|
|
324
|
+
|
|
325
|
+
example cont: [Games]
|
|
326
|
+
|
|
327
|
+
:param bubble_colors: list() or None, list of colors to be associated with each bubble. By
|
|
328
|
+
default, red bubbles are created. Note that if providing more than one
|
|
329
|
+
color, the data set legend will have the color of the first bubble, so
|
|
330
|
+
you may want to hide the legend via frontend.
|
|
331
|
+
|
|
332
|
+
example cont: [red, blue]
|
|
333
|
+
|
|
334
|
+
Javascript side:
|
|
335
|
+
const config = {
|
|
336
|
+
type: 'bubble',
|
|
337
|
+
data: data, ->>> output of this function goes here.
|
|
338
|
+
options: {
|
|
339
|
+
plugins: {
|
|
340
|
+
legend: {
|
|
341
|
+
display: false
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
:param bubble_border_colors: list() or None, by default, this will be same color as background color.
|
|
348
|
+
|
|
349
|
+
example cont: [black, black]
|
|
350
|
+
|
|
351
|
+
:param additional_data: dict(), any additional data you want as a separate dict
|
|
352
|
+
to be available with your chart
|
|
353
|
+
|
|
354
|
+
:return: dict(), json for the chart.js is found in key "chartData"
|
|
355
|
+
"""
|
|
356
|
+
|
|
357
|
+
if y_axis_list is None:
|
|
358
|
+
# randomly generate y axis data of length 7
|
|
359
|
+
y_axis_list = list()
|
|
360
|
+
i = 0
|
|
361
|
+
while i < 7:
|
|
362
|
+
n = random.randint(1, 10)
|
|
363
|
+
y_axis_list.append(n)
|
|
364
|
+
i = i + 1
|
|
365
|
+
|
|
366
|
+
if radius_list is None:
|
|
367
|
+
# randomly generate radius sizes for 7 points
|
|
368
|
+
radius_list = list()
|
|
369
|
+
i = 0
|
|
370
|
+
while i < 7:
|
|
371
|
+
n = random.randint(1, 40)
|
|
372
|
+
radius_list.append(n)
|
|
373
|
+
i = i + 1
|
|
374
|
+
|
|
375
|
+
if x_axis_list is None:
|
|
376
|
+
# add to x axis list points from 0 to 6
|
|
377
|
+
x_axis_list = list()
|
|
378
|
+
i = 0
|
|
379
|
+
while i < len(y_axis_list):
|
|
380
|
+
x_axis_list.append(i)
|
|
381
|
+
i = i + 1
|
|
382
|
+
|
|
383
|
+
if data_set_label is None:
|
|
384
|
+
data_set_label = "Bubble Set"
|
|
385
|
+
|
|
386
|
+
if bubble_colors is None:
|
|
387
|
+
bubble_colors = ["red"] * len(y_axis_list)
|
|
388
|
+
|
|
389
|
+
if bubble_border_colors is None:
|
|
390
|
+
bubble_border_colors = bubble_colors.copy()
|
|
391
|
+
|
|
392
|
+
data_sets = []
|
|
393
|
+
counter = 0
|
|
394
|
+
|
|
395
|
+
bubble_data = []
|
|
396
|
+
i = 0
|
|
397
|
+
while i < len(y_axis_list):
|
|
398
|
+
bubble_data.append({
|
|
399
|
+
"x": x_axis_list[i],
|
|
400
|
+
"y": y_axis_list[i],
|
|
401
|
+
"r": radius_list[i]
|
|
402
|
+
})
|
|
403
|
+
i = i + 1
|
|
404
|
+
|
|
405
|
+
temp_dict = {
|
|
406
|
+
"label": data_set_label,
|
|
407
|
+
"data": bubble_data,
|
|
408
|
+
"borderColor": bubble_border_colors,
|
|
409
|
+
"backgroundColor": bubble_colors
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
data_sets.append(temp_dict.copy())
|
|
413
|
+
|
|
414
|
+
op_dict = {"chartData": {"datasets": data_sets},
|
|
415
|
+
"additionalData": additional_data}
|
|
416
|
+
|
|
417
|
+
return op_dict
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def create_scatter_chart(x_axis_list=None, y_axis_list=None, data_set_label=None,
|
|
421
|
+
point_bg_colors=None, point_outline_colors=None, additional_data=None, point_radius=None,
|
|
422
|
+
point_style="circle", point_border_width=None, hover_radius=None):
|
|
423
|
+
"""
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
:param x_axis_list: list() or None, list of x axis points. If None is provided,
|
|
427
|
+
defaults to a list of numbers is provided. Note this must correspond
|
|
428
|
+
1 to 1 with the y_axis_list to form points.
|
|
429
|
+
|
|
430
|
+
starting example: [1, 2 ,3 ,4]
|
|
431
|
+
|
|
432
|
+
:param y_axis_list: list() or None, list containing the y value for the bubbles
|
|
433
|
+
you want to plot. Note, the y data in the list should correspond 1 to 1
|
|
434
|
+
with the x axis list. If None is provided, a simple, randomly generated
|
|
435
|
+
dataset will be utilized.
|
|
436
|
+
|
|
437
|
+
example cont.,: [1,2,3,4]
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
:param data_set_label: str() or None, Each data set provided in y_axis_list should have a label.
|
|
441
|
+
If None, then a string "Bubble Set" will be used.
|
|
442
|
+
|
|
443
|
+
example cont: [Games]
|
|
444
|
+
|
|
445
|
+
:param point_bg_colors: list() or None, list of colors to be associated with each point. By
|
|
446
|
+
default, red bubbles are created. Note that if providing more than one
|
|
447
|
+
color, the data set legend will have the color of the first bubble, so
|
|
448
|
+
you may want to hide the legend via frontend.
|
|
449
|
+
|
|
450
|
+
example cont: [red, blue]
|
|
451
|
+
Note: You can achieve transparency with: 'rgba(0, 0, 0, 0.0)'
|
|
452
|
+
|
|
453
|
+
Javascript side:
|
|
454
|
+
const config = {
|
|
455
|
+
type: 'scatter',
|
|
456
|
+
data: data, ->>> output of this function goes here.
|
|
457
|
+
options: {
|
|
458
|
+
plugins: {
|
|
459
|
+
legend: {
|
|
460
|
+
display: false
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
:param point_outline_colors: list() or None, list of colors for the point
|
|
467
|
+
|
|
468
|
+
:param point_radius: int(), size of the points in the set
|
|
469
|
+
|
|
470
|
+
:param point_style: str():
|
|
471
|
+
'circle'
|
|
472
|
+
'cross'
|
|
473
|
+
'crossRot'
|
|
474
|
+
'dash'
|
|
475
|
+
'line'
|
|
476
|
+
'rect'
|
|
477
|
+
'rectRounded'
|
|
478
|
+
'rectRot'
|
|
479
|
+
'star'
|
|
480
|
+
'triangle'
|
|
481
|
+
|
|
482
|
+
:param point_border_width: int(), this is the width of the line of the point.
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
:param additional_data: dict(), any additional data you want as a separate dict
|
|
486
|
+
to be available with your chart
|
|
487
|
+
|
|
488
|
+
:return: dict(), json for the chart.js is found in key "chartData"
|
|
489
|
+
"""
|
|
490
|
+
|
|
491
|
+
if y_axis_list is None:
|
|
492
|
+
# randomly generate y axis data of length 7
|
|
493
|
+
y_axis_list = list()
|
|
494
|
+
i = 0
|
|
495
|
+
while i < 7:
|
|
496
|
+
n = random.randint(1, 10)
|
|
497
|
+
y_axis_list.append(n)
|
|
498
|
+
i = i + 1
|
|
499
|
+
|
|
500
|
+
if x_axis_list is None:
|
|
501
|
+
# add to x axis list points from 0 to 6
|
|
502
|
+
x_axis_list = list()
|
|
503
|
+
i = 0
|
|
504
|
+
while i < len(y_axis_list):
|
|
505
|
+
x_axis_list.append(i)
|
|
506
|
+
i = i + 1
|
|
507
|
+
|
|
508
|
+
if data_set_label is None:
|
|
509
|
+
data_set_label = "Scatter Dataset"
|
|
510
|
+
|
|
511
|
+
if point_bg_colors is None:
|
|
512
|
+
point_bg_colors = ["red"] * len(y_axis_list)
|
|
513
|
+
|
|
514
|
+
if point_outline_colors is None:
|
|
515
|
+
point_outline_colors = ["black"] * len(y_axis_list)
|
|
516
|
+
|
|
517
|
+
if point_radius is None:
|
|
518
|
+
point_radius = 10
|
|
519
|
+
|
|
520
|
+
if point_border_width is None:
|
|
521
|
+
point_border_width = 3
|
|
522
|
+
|
|
523
|
+
if hover_radius is None:
|
|
524
|
+
hover_radius = 4
|
|
525
|
+
|
|
526
|
+
data_sets = []
|
|
527
|
+
|
|
528
|
+
scatter_data = []
|
|
529
|
+
i = 0
|
|
530
|
+
while i < len(y_axis_list):
|
|
531
|
+
scatter_data.append({
|
|
532
|
+
"x": x_axis_list[i],
|
|
533
|
+
"y": y_axis_list[i]
|
|
534
|
+
})
|
|
535
|
+
i = i + 1
|
|
536
|
+
|
|
537
|
+
temp_dict = {
|
|
538
|
+
"label": data_set_label,
|
|
539
|
+
"type": "scatter",
|
|
540
|
+
"data": scatter_data,
|
|
541
|
+
"backgroundColor": point_bg_colors,
|
|
542
|
+
"borderColor": point_outline_colors,
|
|
543
|
+
"pointRadius": point_radius,
|
|
544
|
+
"pointStyle": point_style,
|
|
545
|
+
"hoverRadius": hover_radius,
|
|
546
|
+
"pointBorderWidth": point_border_width
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
data_sets.append(temp_dict.copy())
|
|
550
|
+
|
|
551
|
+
op_dict = {"chartData": {"datasets": data_sets},
|
|
552
|
+
"additionalData": additional_data}
|
|
553
|
+
|
|
554
|
+
return op_dict
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
def parse_labels(value_list, corresponding_labels):
|
|
558
|
+
"""
|
|
559
|
+
Labels are optionally provided with each chart type. Use this function to parse a label input. If None is provided
|
|
560
|
+
by the user, then this function generates label list.
|
|
561
|
+
|
|
562
|
+
:param value_list: list(), the set of values that need labels
|
|
563
|
+
:param corresponding_labels: list() or None, the label parameter provided by the end user.
|
|
564
|
+
:return: list(), list of labels. If labels were provided by end user, just return the list. If not, labels are
|
|
565
|
+
generated for the list. "data 1", "data 2", etc.
|
|
566
|
+
"""
|
|
567
|
+
|
|
568
|
+
labels_list = list()
|
|
569
|
+
if corresponding_labels is None:
|
|
570
|
+
i = 1
|
|
571
|
+
while i < len(value_list) + 1:
|
|
572
|
+
labels_list.append("data " + str(i))
|
|
573
|
+
i = i + 1
|
|
574
|
+
else:
|
|
575
|
+
labels_list = corresponding_labels
|
|
576
|
+
|
|
577
|
+
return labels_list
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
def parse_core_value_list(value_list):
|
|
581
|
+
"""
|
|
582
|
+
Each chart js function allows a user to call the function without inputting any parameter. In this case, we create
|
|
583
|
+
a random chart. This allows them to the output of the function, or create a placeholder chart easily.
|
|
584
|
+
|
|
585
|
+
This function parses the users core value list (i.e. the values of the chart that are essential to make a chart)
|
|
586
|
+
|
|
587
|
+
:param value_list: list() or None. If there is a list of values, this function just returns back the list. If None,
|
|
588
|
+
this function creates a random list of values between 1 and 10 and of length 7.
|
|
589
|
+
:return:
|
|
590
|
+
"""
|
|
591
|
+
|
|
592
|
+
op_list = list()
|
|
593
|
+
if value_list is None:
|
|
594
|
+
# randomly generate y axis data of length 7
|
|
595
|
+
|
|
596
|
+
i = 0
|
|
597
|
+
while i < 7:
|
|
598
|
+
n = random.randint(1, 10)
|
|
599
|
+
op_list.append(n)
|
|
600
|
+
i = i + 1
|
|
601
|
+
else:
|
|
602
|
+
op_list = value_list
|
|
603
|
+
|
|
604
|
+
return op_list
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
def parse_core_color_list(values_list, core_colors_list):
|
|
608
|
+
"""
|
|
609
|
+
Each graph has a core color for data points (line color, pie slice color, bar color). If none is provided, this
|
|
610
|
+
function will generate colors.
|
|
611
|
+
|
|
612
|
+
:param values_list:
|
|
613
|
+
:param core_colors_list:
|
|
614
|
+
:return:
|
|
615
|
+
"""
|
|
616
|
+
|
|
617
|
+
op_list = list()
|
|
618
|
+
if core_colors_list is None:
|
|
619
|
+
op_list = lC.create_list_of_colors(len(values_list))
|
|
620
|
+
else:
|
|
621
|
+
op_list = core_colors_list
|
|
622
|
+
|
|
623
|
+
return op_list
|
|
624
|
+
|
|
@@ -421,7 +421,7 @@ class GithubHelper:
|
|
|
421
421
|
if self.file_exists(path_as_list_or_str):
|
|
422
422
|
status = self.update_file(content, path_as_list_or_str, message=message)
|
|
423
423
|
else:
|
|
424
|
-
status = self.create_file(content, path_as_list_or_str,
|
|
424
|
+
status = self.create_file(content, path_as_list_or_str, message=message)
|
|
425
425
|
|
|
426
426
|
return status
|
|
427
427
|
|
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name="lukhed_basic_utils",
|
|
5
|
-
version="1.
|
|
5
|
+
version="1.3.0",
|
|
6
6
|
description="A collection of basic utility functions",
|
|
7
7
|
long_description=open("README.md").read(),
|
|
8
8
|
long_description_content_type="text/markdown",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils.egg-info/requires.txt
RENAMED
|
File without changes
|
{lukhed_basic_utils-1.2.2 → lukhed_basic_utils-1.3.0}/lukhed_basic_utils.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|