Skip to content

Commit 0b04f6b

Browse files
added log file compat
1 parent 44f08a1 commit 0b04f6b

File tree

1 file changed

+103
-11
lines changed

1 file changed

+103
-11
lines changed

ti_python_module/ti_plotlib.py

Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""
22
Class containing all the TI Plotlib elements.
33
"""
4-
from typing import overload
5-
from ti_python_module import err as err
4+
from ti_python_module.file_handler import create_log as log
5+
from ti_python_module.err import withConsole as err
6+
from ti_python_module.err import onlyCheck as cerr
67

78

89
def cls():
@@ -13,6 +14,7 @@ def cls():
1314
None: None
1415
"""
1516
print("Clearing screen / display")
17+
log("Clearing the display / screen", "INFO", "TI Plotlib", "Clear Screen")
1618
return None
1719

1820
def window(x_min:int, x_max:int, y_min:int, y_max:int):
@@ -28,6 +30,16 @@ def window(x_min:int, x_max:int, y_min:int, y_max:int):
2830
Returns:
2931
list: a list containing the following data: [x_min, x_max, y_min, y_max]
3032
"""
33+
34+
35+
if cerr.type_error(int, x_min) == False: log("Argument 'x_min' has to be type integer!", "ERROR", "TI Plotlib", "Window")
36+
if cerr.type_error(int, x_max) == False: log("Argument 'x_max' has to be type integer!", "ERROR", "TI Plotlib", "Window")
37+
if cerr.type_error(int, y_min) == False: log("Argument 'y_min' has to be type integer!", "ERROR", "TI Plotlib", "Window")
38+
if cerr.type_error(int, y_max) == False: log("Argument 'y_max' has to be type integer!", "ERROR", "TI Plotlib", "Window")
39+
40+
if cerr.relation.smaller_error(x_min, x_max) == False: log("Argument 'x_min' has to be smaller then 'x_max'!", "ERROR", "TI Plotlib", "Window")
41+
if cerr.relation.smaller_error(y_min, y_max) == False: log("Argument 'y_min' has to be smaller then 'y_max'!", "ERROR", "TI Plotlib", "Window")
42+
3143
err.type_error(int, "int", x_min)
3244
err.type_error(int, "int", x_max)
3345
err.type_error(int, "int", y_min)
@@ -37,9 +49,10 @@ def window(x_min:int, x_max:int, y_min:int, y_max:int):
3749
err.relation.smaller_error(y_min, y_max)
3850

3951
print("Setting the horizontal interval to '" + str(x_max - x_min) + "' pixels and the vertical interval to '" + str(y_max - y_min) + "' pixels.")
52+
log("Setting the horizontal interval of the plotting window to '" + str(x_max - x_min) + "' pixels and the vertical interval to '" + str(y_max - y_min) + "' pixels.", "INFO", "TI Plotlib", "Window")
4053
return [x_min, x_max, y_min, y_max]
4154

42-
def auto_window(x_list:list, y_list:list):
55+
def auto_window(x_list:list[int], y_list:list[int]):
4356
"""
4457
Autoscales the plotting window to fit the data ranges within x-list and y-list specified in the program prior to the auto_window().
4558
@@ -50,10 +63,14 @@ def auto_window(x_list:list, y_list:list):
5063
Returns:
5164
list: a list containing the following data: [x_list, y_list]
5265
"""
53-
err.type_error(list, "list", x_list)
54-
err.type_error(list, "list", y_list)
66+
if cerr.type_error(list[int], x_list) == False: log("Argument 'x_list' has to be type list!", "ERROR", "TI Plotlib", "Auto Window")
67+
if cerr.type_error(list[int], y_list) == False: log("Argument 'x_list' has to be type list!", "ERROR", "TI Plotlib", "Auto Window")
68+
69+
err.type_error(list[int], "list", x_list)
70+
err.type_error(list[int], "list", y_list)
5571

5672
print("Auto-scaling the window to fit the specified plotting data")
73+
log("Automatically scaling the plotting window to fit the given data range.", "INFO", "TI Plotlib", "Auto Window")
5774
return [x_list, y_list]
5875

5976
def grid(x_scale:float, y_scale:float, style:str):
@@ -68,13 +85,18 @@ def grid(x_scale:float, y_scale:float, style:str):
6885
Returns:
6986
list: a list containing the followig data: [x_scale, y_scale, style]
7087
"""
88+
if cerr.type_error(float, x_scale) == False: log("Argument 'x_scale' has to be type float!", "ERROR", "TI Plotlib", "Grid")
89+
if cerr.type_error(float, y_scale) == False: log("Argument 'y_scale' has to be type float!", "ERROR", "TI Plotlib", "Grid")
90+
if cerr.type_error(str, style) == False: log("Argument 'style' has to be type string!", "ERROR", "TI Plotlib", "Grid")
7191
err.type_error(float, "float", x_scale)
7292
err.type_error(float, "float", y_scale)
7393
err.type_error(str, "str", style)
7494

95+
if cerr.argument_error(style, "solid", "dotted", "dashed") == False: log("Argument 'style' can only be on of these: 'solid', 'dotted', 'dashed'!", "ERROR", "TI Plotlib", "Grid")
7596
err.argument_error(style, "solid", "dotted", "dashed")
7697

7798
print("Setting the grid scale to '" + str(x_scale) + ", " + str(y_scale) + "' with the style '" + style + "'")
99+
log("Setting the grid scale to '" + str(x_scale) + " x' and '" + str(y_scale) + " y' with style '" + style + "'", "INFO", "TI Plotlib", "Grid")
78100
return [x_scale, y_scale, style]
79101

80102
def axes(mode:str):
@@ -87,10 +109,13 @@ def axes(mode:str):
87109
Returns:
88110
list: a list containing the following data: [mode]
89111
"""
112+
if cerr.type_error(str, mode) == False: log("Argument 'mode' has to be type string!", "ERROR", "TI Plotlib", "Axes")
90113
err.type_error(str, "str", mode)
91114

115+
if cerr.argument_error(mode, "off", "on", "axes", "window") == False: log("Argument 'mode' can only be one of these: 'off', 'on', 'axes', 'window'!", "ERROR", "TI Plotlib", "Axes")
92116
err.argument_error(mode, "off", "on", "axes", "window")
93117
print("Setting axes mode to '" + mode + "'")
118+
log("Setting the axes mode to '" + mode + "'", "INFO", "TI Plotlib", "Axes")
94119
return [mode]
95120

96121
def labels(x_name:str, y_name:str, x_row:int, y_row:int):
@@ -106,12 +131,17 @@ def labels(x_name:str, y_name:str, x_row:int, y_row:int):
106131
Returns:
107132
list: a list containing the following data: [x_name, y_name, x_row, y_row]
108133
"""
134+
if cerr.type_error(str, x_name) == False: log("Argument 'x_name' has to be type string!", "ERROR", "TI Plotlib", "Labels")
135+
if cerr.type_error(str, y_name) == False: log("Argument 'y_name' has to be type string!", "ERROR", "TI Plotlib", "Labels")
136+
if cerr.type_error(int, x_row) == False: log("Argument 'x_row' has to be type integer!", "ERROR", "TI Plotlib", "Labels")
137+
if cerr.type_error(int, y_row) == False: log("Argument 'y_row' has to be type integer!", "ERROR", "TI Plotlib", "Labels")
109138
err.type_error(str, "str", x_name)
110139
err.type_error(str, "str", y_name)
111140
err.type_error(int, "int", x_row)
112141
err.type_error(int, "int", y_row)
113142

114143
print("Displaying '" + x_name + "' at row '" + str(x_row) + "' for the x axis. Displaying '" + y_name + "' at row '" + str(y_row) + "' for the y axis.")
144+
log("Displaying '" + x_name + "' at row '" + str(x_row) + "' for the x axis. Displaying '" + y_name + "' at row '" + str(y_row) + "' for the y axis.", "INFO", "TI Plotlib", "Screen")
115145
return[x_name, y_name, x_row, y_row]
116146

117147
def title(title:str):
@@ -124,8 +154,10 @@ def title(title:str):
124154
Returns:
125155
list: a list containing the following data: [title]
126156
"""
157+
if cerr.type_error(str, title) == False: log("Argument 'title' has to be type string!", "ERROR", "TI Plotlib", "Title")
127158
err.type_error(str, "str", title)
128159

160+
log("Setting the title of the plotting window to '" + title + "'", "INFO", "TI Plotlib", "Title")
129161
print("Setting the title of the window to '" + title + "'")
130162
return [title]
131163

@@ -136,6 +168,7 @@ def show_plot():
136168
Returns:
137169
None: None
138170
"""
171+
log("Displaying the buffered drawing output", "INFO", "TI Plotlib", "Show Plot")
139172
print("Displaying buffered drawing output")
140173
return None
141174

@@ -146,6 +179,7 @@ def use_buffer():
146179
Returns:
147180
None: None
148181
"""
182+
log("Enabling the use of the offscreen buffer for faster plotting", "INFO", "TI Plotlib", "Use Buffer")
149183
print("Enabling offscreen buffer")
150184
return None
151185

@@ -161,6 +195,15 @@ def colour(red:float, green:float, blue:float):
161195
Returns:
162196
list: a list containing the following data: [red, green, blue]
163197
"""
198+
if cerr.type_error(float, red) == False: log("Argument 'red' has to be type float!", "ERROR", "TI Plotlib", "Colour")
199+
if cerr.type_error(float, green) == False: log("Argument 'green' has to be type float!", "ERROR", "TI Plotlib", "Colour")
200+
if cerr.type_error(float, blue) == False: log("Argument 'blue' has to be type float!", "ERROR", "TI Plotlib", "Colour")
201+
202+
if cerr.range_error(0, 255, red) == False: log("Argument 'red' has to be between the values 0 and 255 (included)!", "ERROR", "TI Plotlib", "Colour")
203+
if cerr.range_error(0, 255, green) == False: log("Argument 'green' has to be between the values 0 and 255 (included)!", "ERROR", "TI Plotlib", "Colour")
204+
if cerr.range_error(0, 255, blue) == False: log("Argument 'blue' has to be between the values 0 and 255 (included)!", "ERROR", "TI Plotlib", "Colour")
205+
206+
164207
err.type_error(float, "float", red)
165208
err.type_error(float, "float", green)
166209
err.type_error(float, "float", blue)
@@ -169,6 +212,7 @@ def colour(red:float, green:float, blue:float):
169212
err.range_error(0, 255, green)
170213
err.range_error(0, 255, blue)
171214

215+
log("Setting the plotting colout to '" + str(red) + " red', '"+ str(green) + " green', '" + str(blue) + " blue'", "INFO", "TI Plotlib", "Colour")
172216
print("Setting the colour to '" + str(red) + " red', '"+ str(green) + " green', '" + str(blue) + " blue'")
173217
return [red, green, blue]
174218

@@ -184,35 +228,49 @@ def scatter(x_list:list, y_list:list, mark:str):
184228
Returns:
185229
list: a list containing the following data: [x_list, y_list, mark]
186230
"""
231+
if cerr.type_error(list, x_list) == False: log("Argument 'x_list' has to be type list!", "ERROR", "TI Plotlib", "Scatter")
232+
if cerr.type_error(list, y_list) == False: log("Argument 'y_list' has to be type list!", "ERROR", "TI Plotlib", "Scatter")
233+
if cerr.type_error(str, mark) == False: log("Argument 'mark' has to be type string!", "ERROR", "TI Plotlib", "Scatter")
234+
235+
if cerr.argument_error(mark, "o", "+", "x", ".") == False: log("Argument 'mark' can only be one of these: 'o', '+', 'x', '.'!", "ERROR", "TI Plotlib", "Scatter")
236+
187237
err.type_error(list, "list", x_list)
188238
err.type_error(list, "list", y_list)
189239
err.type_error(str, "str", mark)
190240

191241
err.argument_error(mark, "o", "+", "x", ".")
192242

243+
log("Scattering mark '" + mark + "' at the values from the given lists", "INFO", "TI Plotlib", "Scatter")
193244
print("Scattering mark '" + mark + "' in between the given lists")
194245
return [x_list, y_list, mark]
195246

196247

197248
def plot(x_list:list, y_list:list, mark:str):
198249
"""
199-
Plots a line using ordered pairs from specified x-list and y-list.
250+
Plots a line using ordered pairs from specified x-list and y-list. To use just one value, put this one value in a list.
200251
201252
202253
Args:
203254
x_list (list): The list of the possible x values.
204255
y_list (list): The list of the possible y values.
205-
mark (str): The mark to scatter. Possible Options: 'o', '+', 'x', '.'.
256+
mark (str): The mark to plot. Possible Options: 'o', '+', 'x', '.'.
206257
207258
Returns:
208259
list: a list containing the following data: [x_list, y_list, mark]
209260
"""
261+
if cerr.type_error(list, x_list) == False: log("Argument 'x_list' has to be type list!", "ERROR", "TI Plotlib", "Plot")
262+
if cerr.type_error(list, y_list) == False: log("Argument 'y_list' has to be type list!", "ERROR", "TI Plotlib", "Plot")
263+
if cerr.type_error(str, mark) == False: log("Argument 'mark' has to be type string!", "ERROR", "TI Plotlib", "Plot")
264+
265+
if cerr.argument_error(mark, "o", "+", "x", ".") == False: log("Argument 'mark' can only be one of these: 'o', '+', 'x', '.'!", "ERROR", "TI Plotlib", "Plot")
266+
210267
err.type_error(list, "list", x_list)
211268
err.type_error(list, "list", y_list)
212269
err.type_error(str, "str", mark)
213270

214271
err.argument_error(mark, "o", "+", "x", ".")
215272

273+
log("Plotting a line with the mark '" + mark + "' in between the range of the specifed lists", "INFO", "TI Plotlib", "Plot")
216274
print("Plotting line with mark '" + mark + "' in between the given lists")
217275
return [x_list, y_list, mark]
218276

@@ -230,21 +288,30 @@ def line(x1:float, y1:float, x2:float, y2:float, mode:str):
230288
Returns:
231289
list: a list containing the following data: [x1, y1, x2, y2, mode]
232290
"""
291+
if cerr.type_error(float, x1) == False: log("Argument 'x1' has to be type float!", "ERROR", "TI Plotlib", "Line")
292+
if cerr.type_error(float, y1) == False: log("Argument 'y1' has to be type float!", "ERROR", "TI Plotlib", "Line")
293+
if cerr.type_error(float, x2) == False: log("Argument 'x2' has to be type float!", "ERROR", "TI Plotlib", "Line")
294+
if cerr.type_error(float, y2) == False: log("Argument 'y2' has to be type float!", "ERROR", "TI Plotlib", "Line")
295+
if cerr.type_error(str, mode) == False: log("Argument 'mode' has to be type string!", "ERROR", "TI Plotlib", "Line")
296+
297+
298+
if cerr.argument_error(mode, "default", "arrow") == False: log("Argument 'mode' can only be one of these: 'default', 'arrow'!", "ERROR", "TI Plotlib", "Line")
299+
300+
233301
err.type_error(float, "float", x1)
234302
err.type_error(float, "float", y1)
235303
err.type_error(float, "float", x2)
236304
err.type_error(float, "float", y2)
237305
err.type_error(str, "str", mode)
238306

239-
err.relation.smaller_error(x1, x2)
240-
err.relation.smaller_error(y1, y2)
241307

242308
err.argument_error(mode, "default", "arrow")
243309

310+
log("Drawing a line of type '" + mode + "' from '(" + str(x1) + "|" + str(y1) + ")' to '(" + str(x2) + "|" + str(y2) + ")'", "INFO", "TI Plotlib", "Line")
244311
print("Drawing line of type '" + mode + "' from '(" + str(x1) + "|" + str(y1) + ")' to '(" + str(x2) + "|" + str(y2) + ")'")
245312
return [x1, y1, x2, y2, mode]
246313

247-
def line_reg(x_list:list, y_list:list, display:str):
314+
def lin_reg(x_list:list, y_list:list, display:str):
248315
"""
249316
Calculates and draws the linear regression model, ax+b, of x-list,y-list.
250317
@@ -257,12 +324,20 @@ def line_reg(x_list:list, y_list:list, display:str):
257324
Returns:
258325
list: a list containing the following data: [x_list, y_list, display]
259326
"""
327+
if cerr.type_error(list, x_list) == False: log("Argument 'x_list' has to be type list!", "ERROR", "TI Plotlib", "Linear Regression")
328+
if cerr.type_error(list, y_list) == False: log("Argument 'y_list' has to be type list!", "ERROR", "TI Plotlib", "Linear Regression")
329+
if cerr.type_error(str, display) == False: log("Argument 'dsiplay' has to be type string!", "ERROR", "TI Plotlib", "Linear Regression ")
330+
331+
if cerr.argument_error(display, "left", "center", "right") == False: log("Argument 'display' can only be one of these: 'left', 'center', 'right'!", "ERROR", "TI Plotlib", "Linear Regression")
332+
333+
260334
err.type_error(list, "list", x_list)
261335
err.type_error(list, "list", y_list)
262336
err.type_error(str, "str", display)
263337

264338
err.argument_error(display, "left", "center", "right")
265339

340+
log("Drawing linear regression model ax+b using the given lists with the alignment '" + display + "'", "INFO", "TI Plotlib", "Linear Regressio")
266341
print("Drawing linear regression model with display alignment '" + display + "'")
267342
return [x_list, y_list, display]
268343

@@ -277,12 +352,20 @@ def pen(thickness:str, style:str):
277352
Returns:
278353
list: list: a list containing the following data: [thickness, style]
279354
"""
355+
if cerr.type_error(str, thickness) == False: log("Argument 'thickness' has to be type string!", "ERROR", "TI Plotlib", "Pen")
356+
if cerr.type_error(str, style) == False: log("Argument 'style' has to be type string!", "ERROR", "TI Plotlib", "Pen")
357+
358+
if cerr.argument_error(thickness, "thin", "medium", "thick") == False: log("Argument 'thickness' can only be one of these: 'thin', 'medium', 'thick'!", "ERROR", "TI Plotlib", "Pen")
359+
if cerr.argument_error(style, "solid", "dotted", "dashed") == False: log("Argument 'style' can only be one of these: 'solid', 'dotted', 'dashed'!", "ERROR", "TI Plotlib", "Pen")
360+
361+
280362
err.type_error(str, "str", thickness)
281363
err.type_error(str, "str", style)
282364

283365
err.argument_error(thickness, "thin", "medium", "thick")
284366
err.argument_error(style, "solid", "dotted", "dashed")
285367

368+
log("Setting the thickness of the plotting pen to '" + thickness + "' and the line style to '" + style + "'", "INFO", "TI Plotlib", "Pen")
286369
print("Setting pen thickness to '" + thickness + "' and line style to '" + style + "'")
287370
return [thickness, style]
288371

@@ -298,11 +381,20 @@ def text_at(line: int, text: str, align: str):
298381
Returns:
299382
list: list: list: a list containing the following data: [line, text, align]
300383
"""
384+
385+
if cerr.type_error(int, line) == False: log("Argument 'line' has to be type integer!", "ERROR", "TI Plotlib", "Text At")
386+
if cerr.type_error(str, text) == False: log("Argument 'text' has to be type string!", "ERROR", "TI Plotlib", "Text At")
387+
if cerr.type_error(str, align) == False: log("Argument 'align' has to be type string!", "ERROR", "TI Plotlib", "Text At")
388+
if cerr.argument_error(align, "left", "center", "right") == False: log("Argument 'align' can only be one of these: 'left', 'center', 'right'!", "ERROR", "TI Plotlib", "Text At")
389+
if cerr.range_error(1, 13, line) == False: log("Argument 'line' has to be between the values 1 and 13 (included)!", "ERROR", "TI Plotlib", "Text At")
390+
391+
301392
err.type_error(int, "int", line)
302393
err.type_error(str, "str", text)
303394
err.type_error(str, "str", align)
304395
err.argument_error(align, "left", "center", "right")
305396
err.range_error(1, 13, line)
306397

307-
print("Showing text '" + text + "' at line " + str(line) + " with alignement '" + align + "' !")
398+
log("Showing text '" + text + "' at line " + str(line) + " with alignement '" + align + "'", "INFO", "TI Plotlib", "Text At")
399+
print("Showing text '" + text + "' at line " + str(line) + " with alignement '" + align + "'")
308400
return [text, line, align]

0 commit comments

Comments
 (0)