refactor: use two blank lines between functions

This commit is contained in:
eddex 2020-10-04 15:23:07 +02:00
parent a743850f13
commit 8fef90ed31

View File

@ -115,12 +115,15 @@ var templates: Dictionary = {}
signal chart_plotted(chart)
signal point_pressed(point)
func _point_plotted():
pass
func _ready():
_get_children()
func _get_children():
OutlinesTween = $OutlinesTween
FunctionsTween = $FunctionsTween
@ -130,6 +133,7 @@ func _get_children():
Outlines = $Outlines
Grid = $Grid
func _set_size(size: Vector2):
SIZE = size
build_chart()
@ -146,11 +150,13 @@ func _set_size(size: Vector2):
Grid.get_node("HLine").set_point_position(0, Vector2(origin.x, origin.y / 2))
Grid.get_node("HLine").set_point_position(1, Vector2(SIZE.x, origin.y / 2))
func clear():
Outlines.points = []
Grid.get_node("HLine").queue_free()
Grid.get_node("VLine").queue_free()
func load_font():
if font != null:
font_size = font.get_height()
@ -164,6 +170,7 @@ func load_font():
if bold_font != null:
PointData.Data.set("custom_fonts/font",bold_font)
func _plot(source_: String, delimiter_: String, are_values_columns_: bool, x_values_index_: int):
randomize()
@ -184,6 +191,7 @@ func _plot(source_: String, delimiter_: String, are_values_columns_: bool, x_val
create_legend()
emit_signal("chart_plotted", self)
func plot():
randomize()
@ -207,17 +215,20 @@ func plot():
create_legend()
emit_signal("chart_plotted", self)
func calculate_colors():
if function_colors.empty() or function_colors.size() < functions:
for function in functions:
function_colors.append(Color("#1e1e1e"))
func draw_chart():
draw_outlines()
draw_v_grid()
draw_h_grid()
draw_functions()
func draw_outlines():
if boxed:
Outlines.set_default_color(box_color)
@ -263,6 +274,7 @@ func draw_outlines():
OutlinesTween.start()
yield(OutlinesTween, "tween_all_completed")
func draw_v_grid():
for p in x_chors.size():
var point: Vector2 = origin + Vector2((p) * x_pass, 0)
@ -282,6 +294,7 @@ func draw_v_grid():
GridTween.start()
yield(GridTween,"tween_all_completed")
func draw_h_grid():
for p in y_chors.size():
var point: Vector2 = origin - Vector2(0, p * y_pass)
@ -311,10 +324,12 @@ func add_label(point: Vector2, text: String):
lbl.rect_position = point
lbl.set_text(text)
func draw_functions():
for function in point_positions.size():
draw_function(function, point_positions[function])
func draw_function(f_index: int, function: Array):
var line: Line2D = Line2D.new()
var backline: Line2D = Line2D.new()
@ -360,6 +375,7 @@ func construct_line(line: Line2D, backline: Line2D, f_index: int, function: Arra
line.antialiased = true
Functions.add_child(line)
func read_datas(source: String, delimiter: String):
var file: File = File.new()
file.open(source, File.READ)
@ -373,6 +389,7 @@ func read_datas(source: String, delimiter: String):
content.erase(data)
return content
func structure_datas(database: Array, are_values_columns: bool, x_values_index: int):
# @x_values_index can be either a column or a row relative to x values
# @y_values can be either a column or a row relative to y values
@ -458,9 +475,11 @@ func structure_datas(database: Array, are_values_columns: bool, x_values_index:
p = (h_dist * multi) + (x_margin_min if not origin_at_zero else 0)
x_labels.append(p as String)
func build_chart():
origin = Vector2(OFFSET.x, SIZE.y - OFFSET.y)
func calculate_pass():
if invert_chart:
x_chors = y_labels as PoolStringArray
@ -474,6 +493,7 @@ func calculate_pass():
x_pass = (SIZE.x - OFFSET.x) / (x_chors.size() - 1)
y_pass = origin.y / (y_chors.size() - 1)
func calculate_coordinates():
x_coordinates.clear()
y_coordinates.clear()
@ -545,6 +565,7 @@ func calculate_coordinates():
x_coordinates[y] + origin.x,
origin.y - y_coordinates[cluster][y]))
func redraw():
build_chart()
calculate_pass()
@ -556,27 +577,33 @@ func show_data(point):
PointData.update_datas(point)
PointData.show()
func hide_data():
PointData.hide()
func clear_points():
function_colors.clear()
if Functions.get_children():
for function in Functions.get_children():
function.queue_free()
func set_legend(l: Array):
legend = l
func get_legend():
return legend
func invert_chart():
invert_chart = !invert_chart
count_functions()
redraw()
create_legend()
func count_functions():
if are_values_columns:
if not invert_chart:
@ -589,6 +616,7 @@ func count_functions():
else:
functions = datas.size() - 1
func create_legend():
legend.clear()
for function in functions:
@ -606,6 +634,7 @@ func create_legend():
function_legend.create_legend(f_name, function_colors[function], bold_font, font_color)
legend.append(function_legend)
func apply_template(template_name: int):
template = template_name
templates = Utilities._load_templates()
@ -624,9 +653,11 @@ func apply_template(template_name: int):
Grid.get_node("VLine").set_default_color(v_lines_color)
Grid.get_node("HLine").set_default_color(h_lines_color)
func _enter_tree():
_ready()
# Signal Repeaters
func point_pressed(point: Point) -> Point:
return point