mirror of
https://github.com/Relintai/pandemonium_engine_easy_charts.git
synced 2025-02-10 16:20:06 +01:00
refactor: use two blank lines between functions
This commit is contained in:
parent
a743850f13
commit
8fef90ed31
@ -115,12 +115,15 @@ var templates: Dictionary = {}
|
|||||||
signal chart_plotted(chart)
|
signal chart_plotted(chart)
|
||||||
signal point_pressed(point)
|
signal point_pressed(point)
|
||||||
|
|
||||||
|
|
||||||
func _point_plotted():
|
func _point_plotted():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
_get_children()
|
_get_children()
|
||||||
|
|
||||||
|
|
||||||
func _get_children():
|
func _get_children():
|
||||||
OutlinesTween = $OutlinesTween
|
OutlinesTween = $OutlinesTween
|
||||||
FunctionsTween = $FunctionsTween
|
FunctionsTween = $FunctionsTween
|
||||||
@ -130,6 +133,7 @@ func _get_children():
|
|||||||
Outlines = $Outlines
|
Outlines = $Outlines
|
||||||
Grid = $Grid
|
Grid = $Grid
|
||||||
|
|
||||||
|
|
||||||
func _set_size(size: Vector2):
|
func _set_size(size: Vector2):
|
||||||
SIZE = size
|
SIZE = size
|
||||||
build_chart()
|
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(0, Vector2(origin.x, origin.y / 2))
|
||||||
Grid.get_node("HLine").set_point_position(1, Vector2(SIZE.x, origin.y / 2))
|
Grid.get_node("HLine").set_point_position(1, Vector2(SIZE.x, origin.y / 2))
|
||||||
|
|
||||||
|
|
||||||
func clear():
|
func clear():
|
||||||
Outlines.points = []
|
Outlines.points = []
|
||||||
Grid.get_node("HLine").queue_free()
|
Grid.get_node("HLine").queue_free()
|
||||||
Grid.get_node("VLine").queue_free()
|
Grid.get_node("VLine").queue_free()
|
||||||
|
|
||||||
|
|
||||||
func load_font():
|
func load_font():
|
||||||
if font != null:
|
if font != null:
|
||||||
font_size = font.get_height()
|
font_size = font.get_height()
|
||||||
@ -164,6 +170,7 @@ func load_font():
|
|||||||
if bold_font != null:
|
if bold_font != null:
|
||||||
PointData.Data.set("custom_fonts/font",bold_font)
|
PointData.Data.set("custom_fonts/font",bold_font)
|
||||||
|
|
||||||
|
|
||||||
func _plot(source_: String, delimiter_: String, are_values_columns_: bool, x_values_index_: int):
|
func _plot(source_: String, delimiter_: String, are_values_columns_: bool, x_values_index_: int):
|
||||||
randomize()
|
randomize()
|
||||||
|
|
||||||
@ -184,6 +191,7 @@ func _plot(source_: String, delimiter_: String, are_values_columns_: bool, x_val
|
|||||||
create_legend()
|
create_legend()
|
||||||
emit_signal("chart_plotted", self)
|
emit_signal("chart_plotted", self)
|
||||||
|
|
||||||
|
|
||||||
func plot():
|
func plot():
|
||||||
randomize()
|
randomize()
|
||||||
|
|
||||||
@ -207,17 +215,20 @@ func plot():
|
|||||||
create_legend()
|
create_legend()
|
||||||
emit_signal("chart_plotted", self)
|
emit_signal("chart_plotted", self)
|
||||||
|
|
||||||
|
|
||||||
func calculate_colors():
|
func calculate_colors():
|
||||||
if function_colors.empty() or function_colors.size() < functions:
|
if function_colors.empty() or function_colors.size() < functions:
|
||||||
for function in functions:
|
for function in functions:
|
||||||
function_colors.append(Color("#1e1e1e"))
|
function_colors.append(Color("#1e1e1e"))
|
||||||
|
|
||||||
|
|
||||||
func draw_chart():
|
func draw_chart():
|
||||||
draw_outlines()
|
draw_outlines()
|
||||||
draw_v_grid()
|
draw_v_grid()
|
||||||
draw_h_grid()
|
draw_h_grid()
|
||||||
draw_functions()
|
draw_functions()
|
||||||
|
|
||||||
|
|
||||||
func draw_outlines():
|
func draw_outlines():
|
||||||
if boxed:
|
if boxed:
|
||||||
Outlines.set_default_color(box_color)
|
Outlines.set_default_color(box_color)
|
||||||
@ -263,6 +274,7 @@ func draw_outlines():
|
|||||||
OutlinesTween.start()
|
OutlinesTween.start()
|
||||||
yield(OutlinesTween, "tween_all_completed")
|
yield(OutlinesTween, "tween_all_completed")
|
||||||
|
|
||||||
|
|
||||||
func draw_v_grid():
|
func draw_v_grid():
|
||||||
for p in x_chors.size():
|
for p in x_chors.size():
|
||||||
var point: Vector2 = origin + Vector2((p) * x_pass, 0)
|
var point: Vector2 = origin + Vector2((p) * x_pass, 0)
|
||||||
@ -282,6 +294,7 @@ func draw_v_grid():
|
|||||||
GridTween.start()
|
GridTween.start()
|
||||||
yield(GridTween,"tween_all_completed")
|
yield(GridTween,"tween_all_completed")
|
||||||
|
|
||||||
|
|
||||||
func draw_h_grid():
|
func draw_h_grid():
|
||||||
for p in y_chors.size():
|
for p in y_chors.size():
|
||||||
var point: Vector2 = origin - Vector2(0, p * y_pass)
|
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.rect_position = point
|
||||||
lbl.set_text(text)
|
lbl.set_text(text)
|
||||||
|
|
||||||
|
|
||||||
func draw_functions():
|
func draw_functions():
|
||||||
for function in point_positions.size():
|
for function in point_positions.size():
|
||||||
draw_function(function, point_positions[function])
|
draw_function(function, point_positions[function])
|
||||||
|
|
||||||
|
|
||||||
func draw_function(f_index: int, function: Array):
|
func draw_function(f_index: int, function: Array):
|
||||||
var line: Line2D = Line2D.new()
|
var line: Line2D = Line2D.new()
|
||||||
var backline: 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
|
line.antialiased = true
|
||||||
Functions.add_child(line)
|
Functions.add_child(line)
|
||||||
|
|
||||||
|
|
||||||
func read_datas(source: String, delimiter: String):
|
func read_datas(source: String, delimiter: String):
|
||||||
var file: File = File.new()
|
var file: File = File.new()
|
||||||
file.open(source, File.READ)
|
file.open(source, File.READ)
|
||||||
@ -373,6 +389,7 @@ func read_datas(source: String, delimiter: String):
|
|||||||
content.erase(data)
|
content.erase(data)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
func structure_datas(database: Array, are_values_columns: bool, x_values_index: int):
|
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
|
# @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
|
# @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)
|
p = (h_dist * multi) + (x_margin_min if not origin_at_zero else 0)
|
||||||
x_labels.append(p as String)
|
x_labels.append(p as String)
|
||||||
|
|
||||||
|
|
||||||
func build_chart():
|
func build_chart():
|
||||||
origin = Vector2(OFFSET.x, SIZE.y - OFFSET.y)
|
origin = Vector2(OFFSET.x, SIZE.y - OFFSET.y)
|
||||||
|
|
||||||
|
|
||||||
func calculate_pass():
|
func calculate_pass():
|
||||||
if invert_chart:
|
if invert_chart:
|
||||||
x_chors = y_labels as PoolStringArray
|
x_chors = y_labels as PoolStringArray
|
||||||
@ -474,6 +493,7 @@ func calculate_pass():
|
|||||||
x_pass = (SIZE.x - OFFSET.x) / (x_chors.size() - 1)
|
x_pass = (SIZE.x - OFFSET.x) / (x_chors.size() - 1)
|
||||||
y_pass = origin.y / (y_chors.size() - 1)
|
y_pass = origin.y / (y_chors.size() - 1)
|
||||||
|
|
||||||
|
|
||||||
func calculate_coordinates():
|
func calculate_coordinates():
|
||||||
x_coordinates.clear()
|
x_coordinates.clear()
|
||||||
y_coordinates.clear()
|
y_coordinates.clear()
|
||||||
@ -545,6 +565,7 @@ func calculate_coordinates():
|
|||||||
x_coordinates[y] + origin.x,
|
x_coordinates[y] + origin.x,
|
||||||
origin.y - y_coordinates[cluster][y]))
|
origin.y - y_coordinates[cluster][y]))
|
||||||
|
|
||||||
|
|
||||||
func redraw():
|
func redraw():
|
||||||
build_chart()
|
build_chart()
|
||||||
calculate_pass()
|
calculate_pass()
|
||||||
@ -556,27 +577,33 @@ func show_data(point):
|
|||||||
PointData.update_datas(point)
|
PointData.update_datas(point)
|
||||||
PointData.show()
|
PointData.show()
|
||||||
|
|
||||||
|
|
||||||
func hide_data():
|
func hide_data():
|
||||||
PointData.hide()
|
PointData.hide()
|
||||||
|
|
||||||
|
|
||||||
func clear_points():
|
func clear_points():
|
||||||
function_colors.clear()
|
function_colors.clear()
|
||||||
if Functions.get_children():
|
if Functions.get_children():
|
||||||
for function in Functions.get_children():
|
for function in Functions.get_children():
|
||||||
function.queue_free()
|
function.queue_free()
|
||||||
|
|
||||||
|
|
||||||
func set_legend(l: Array):
|
func set_legend(l: Array):
|
||||||
legend = l
|
legend = l
|
||||||
|
|
||||||
|
|
||||||
func get_legend():
|
func get_legend():
|
||||||
return legend
|
return legend
|
||||||
|
|
||||||
|
|
||||||
func invert_chart():
|
func invert_chart():
|
||||||
invert_chart = !invert_chart
|
invert_chart = !invert_chart
|
||||||
count_functions()
|
count_functions()
|
||||||
redraw()
|
redraw()
|
||||||
create_legend()
|
create_legend()
|
||||||
|
|
||||||
|
|
||||||
func count_functions():
|
func count_functions():
|
||||||
if are_values_columns:
|
if are_values_columns:
|
||||||
if not invert_chart:
|
if not invert_chart:
|
||||||
@ -589,6 +616,7 @@ func count_functions():
|
|||||||
else:
|
else:
|
||||||
functions = datas.size() - 1
|
functions = datas.size() - 1
|
||||||
|
|
||||||
|
|
||||||
func create_legend():
|
func create_legend():
|
||||||
legend.clear()
|
legend.clear()
|
||||||
for function in functions:
|
for function in functions:
|
||||||
@ -606,6 +634,7 @@ func create_legend():
|
|||||||
function_legend.create_legend(f_name, function_colors[function], bold_font, font_color)
|
function_legend.create_legend(f_name, function_colors[function], bold_font, font_color)
|
||||||
legend.append(function_legend)
|
legend.append(function_legend)
|
||||||
|
|
||||||
|
|
||||||
func apply_template(template_name: int):
|
func apply_template(template_name: int):
|
||||||
template = template_name
|
template = template_name
|
||||||
templates = Utilities._load_templates()
|
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("VLine").set_default_color(v_lines_color)
|
||||||
Grid.get_node("HLine").set_default_color(h_lines_color)
|
Grid.get_node("HLine").set_default_color(h_lines_color)
|
||||||
|
|
||||||
|
|
||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
_ready()
|
_ready()
|
||||||
|
|
||||||
|
|
||||||
# Signal Repeaters
|
# Signal Repeaters
|
||||||
func point_pressed(point: Point) -> Point:
|
func point_pressed(point: Point) -> Point:
|
||||||
return point
|
return point
|
||||||
|
Loading…
Reference in New Issue
Block a user