Merge pull request #18 from fenix-hub/dev

Dev
This commit is contained in:
Nicolò Santilio 2020-10-22 18:06:45 +02:00 committed by GitHub
commit 26b88a8ce7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -114,146 +114,146 @@ var invert_chart : bool = false setget set_invert_chart
# .......................... Properties Manager .................................... # .......................... Properties Manager ....................................
func _get(property): func _get(property):
match property: match property:
"Chart_Properties/origin_at_zero": "Chart_Properties/origin_at_zero":
return origin_at_zero return origin_at_zero
"Chart_Properties/are_values_columns": "Chart_Properties/are_values_columns":
return are_values_columns return are_values_columns
"Chart_Properties/show_x_values_as_labels": "Chart_Properties/show_x_values_as_labels":
return show_x_values_as_labels return show_x_values_as_labels
"Chart_Properties/labels_index": "Chart_Properties/labels_index":
return labels_index return labels_index
"Chart_Properties/function_names_index": "Chart_Properties/function_names_index":
return function_names_index return function_names_index
"Chart_Properties/use_height_as_radius": "Chart_Properties/use_height_as_radius":
return use_height_as_radius return use_height_as_radius
"Chart_Properties/radius": "Chart_Properties/radius":
return radius return radius
"Chart_Properties/column_width": "Chart_Properties/column_width":
return column_width return column_width
"Chart_Properties/column_gap": "Chart_Properties/column_gap":
return column_gap return column_gap
"Chart_Display/full_scale": "Chart_Display/full_scale":
return full_scale return full_scale
"Chart_Display/x_decim": "Chart_Display/x_decim":
return x_decim return x_decim
"Chart_Display/y_decim": "Chart_Display/y_decim":
return y_decim return y_decim
"Chart_Style/points_shape": "Chart_Style/points_shape":
return points_shape return points_shape
"Chart_Style/function_colors": "Chart_Style/function_colors":
return function_colors return function_colors
"Chart_Style/template": "Chart_Style/template":
return template return template
"Chart_Style/outline_color": "Chart_Style/outline_color":
return outline_color return outline_color
"Chart_Style/grid_color": "Chart_Style/grid_color":
return grid_color return grid_color
"Chart_Style/box_color": "Chart_Style/box_color":
return box_color return box_color
"Chart_Style/v_lines_color": "Chart_Style/v_lines_color":
return v_lines_color return v_lines_color
"Chart_Style/h_lines_color": "Chart_Style/h_lines_color":
return h_lines_color return h_lines_color
"Chart_Style/font": "Chart_Style/font":
return font return font
"Chart_Style/bold_font": "Chart_Style/bold_font":
return bold_font return bold_font
"Chart_Style/font_color": "Chart_Style/font_color":
return font_color return font_color
"Chart_Modifiers/rotation": "Chart_Modifiers/rotation":
return rotation return rotation
"Chart_Modifiers/invert_chart": "Chart_Modifiers/invert_chart":
return invert_chart return invert_chart
func _set(property, value): func _set(property, value):
match property: match property:
"Chart_Properties/origin_at_zero": "Chart_Properties/origin_at_zero":
origin_at_zero = value origin_at_zero = value
return true return true
"Chart_Properties/are_values_columns": "Chart_Properties/are_values_columns":
are_values_columns = value are_values_columns = value
return true return true
"Chart_Properties/show_x_values_as_labels": "Chart_Properties/show_x_values_as_labels":
show_x_values_as_labels = value show_x_values_as_labels = value
return true return true
"Chart_Properties/labels_index": "Chart_Properties/labels_index":
labels_index = value labels_index = value
return true return true
"Chart_Properties/function_names_index": "Chart_Properties/function_names_index":
function_names_index = value function_names_index = value
return true return true
"Chart_Properties/use_height_as_radius": "Chart_Properties/use_height_as_radius":
use_height_as_radius = value use_height_as_radius = value
return true return true
"Chart_Properties/radius": "Chart_Properties/radius":
radius = value radius = value
return true return true
"Chart_Properties/column_width": "Chart_Properties/column_width":
column_width = value column_width = value
return true return true
"Chart_Properties/column_gap": "Chart_Properties/column_gap":
column_width = value column_width = value
return true return true
"Chart_Display/full_scale": "Chart_Display/full_scale":
full_scale = value full_scale = value
return true return true
"Chart_Display/x_decim": "Chart_Display/x_decim":
x_decim = value x_decim = value
return true return true
"Chart_Display/y_decim": "Chart_Display/y_decim":
y_decim = value y_decim = value
return true return true
"Chart_Style/points_shape": "Chart_Style/points_shape":
points_shape = value points_shape = value
return true return true
"Chart_Style/function_colors": "Chart_Style/function_colors":
function_colors = value function_colors = value
return true return true
"Chart_Style/template": "Chart_Style/template":
template = value template = value
apply_template(template) apply_template(template)
return true return true
"Chart_Style/outline_color": "Chart_Style/outline_color":
outline_color = value outline_color = value
return true return true
"Chart_Style/grid_color": "Chart_Style/grid_color":
grid_color = value grid_color = value
return true return true
"Chart_Style/box_color": "Chart_Style/box_color":
box_color = value box_color = value
return true return true
"Chart_Style/v_lines_color": "Chart_Style/v_lines_color":
v_lines_color = value v_lines_color = value
return true return true
"Chart_Style/h_lines_color": "Chart_Style/h_lines_color":
h_lines_color = value h_lines_color = value
return true return true
"Chart_Style/font": "Chart_Style/font":
font = value font = value
return true return true
"Chart_Style/bold_font": "Chart_Style/bold_font":
bold_font = value bold_font = value
return true return true
"Chart_Style/font_color": "Chart_Style/font_color":
font_color = value font_color = value
apply_template(template) apply_template(template)
return true return true
"Chart_Modifiers/rotation": "Chart_Modifiers/rotation":
rotation = value rotation = value
return true return true
"Chart_Modifiers/invert_chart": "Chart_Modifiers/invert_chart":
invert_chart = value invert_chart = value
return true return true
func _ready(): func _ready():
templates = Utilities._load_templates() templates = Utilities._load_templates()
# .......................... Shared Functions and virtuals ........................ # .......................... Shared Functions and virtuals ........................
@ -276,269 +276,269 @@ func _ready():
func plot(): func plot():
load_font() load_font()
PointData.hide() PointData.hide()
if source == "" or source == null: if source == "" or source == null:
Utilities._print_message("Can't plot a chart without a Source file. Please, choose it in editor, or use the custom function _plot().",1) Utilities._print_message("Can't plot a chart without a Source file. Please, choose it in editor, or use the custom function _plot().",1)
return return
datas = read_datas(source) datas = read_datas(source)
structure_datas(datas,are_values_columns,labels_index) structure_datas(datas,are_values_columns,labels_index)
build_chart() build_chart()
count_functions() count_functions()
calculate_pass() calculate_pass()
calculate_coordinates() calculate_coordinates()
calculate_colors() calculate_colors()
set_shapes() set_shapes()
create_legend() create_legend()
emit_signal("chart_plotted",self) emit_signal("chart_plotted",self)
func load_font(): func load_font():
if font != null: if font != null:
font_size = font.get_height() font_size = font.get_height()
var theme : Theme = Theme.new() var theme : Theme = Theme.new()
theme.set_default_font(font) theme.set_default_font(font)
PointData.set_theme(theme) PointData.set_theme(theme)
else: else:
var lbl = Label.new() var lbl = Label.new()
font = lbl.get_font("") font = lbl.get_font("")
lbl.free() lbl.free()
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 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 set_shapes(): func set_shapes():
if points_shape.empty() or points_shape.size() < functions: if points_shape.empty() or points_shape.size() < functions:
for function in functions: for function in functions:
points_shape.append(PointShapes.Dot) points_shape.append(PointShapes.Dot)
func read_datas(source : String): func read_datas(source : String):
var file : File = File.new() var file : File = File.new()
file.open(source,File.READ) file.open(source,File.READ)
var content : Array var content : Array
while not file.eof_reached(): while not file.eof_reached():
var line : PoolStringArray = file.get_csv_line(delimiter) var line : PoolStringArray = file.get_csv_line(delimiter)
content.append(line) content.append(line)
file.close() file.close()
for data in content: for data in content:
if data.size() < 2 or data.empty(): if data.size() < 2 or data.empty():
content.erase(data) content.erase(data)
return content return content
func count_functions(): func count_functions():
if are_values_columns: if are_values_columns:
if not invert_chart: if not invert_chart:
functions = datas[0].size()-1 functions = datas[0].size()-1
else: else:
functions = datas.size()-1 functions = datas.size()-1
else: else:
if invert_chart: if invert_chart:
functions = datas[0].size()-1 functions = datas[0].size()-1
else: else:
functions = datas.size()-1 functions = datas.size()-1
func clear_points(): func clear_points():
if $Points.get_children(): if $Points.get_children():
for function in Points.get_children(): for function in Points.get_children():
function.queue_free() function.queue_free()
for legend in $Legend.get_children(): for legend in $Legend.get_children():
legend.queue_free() legend.queue_free()
func redraw(): func redraw():
build_chart() build_chart()
calculate_pass() calculate_pass()
calculate_coordinates() calculate_coordinates()
update() update()
# .................. VIRTUAL FUNCTIONS ......................... # .................. VIRTUAL FUNCTIONS .........................
func calculate_pass(): func calculate_pass():
pass pass
func calculate_coordinates(): func calculate_coordinates():
pass pass
func structure_datas(database : Array, are_values_columns : bool, labels_index : int): func structure_datas(database : Array, are_values_columns : bool, labels_index : int):
pass pass
func build_chart(): func build_chart():
pass pass
func function_colors(): func function_colors():
pass pass
func create_legend(): func create_legend():
pass pass
# ........................... Shared Setters & Getters .............................. # ........................... Shared Setters & Getters ..............................
func apply_template(template_name : int): func apply_template(template_name : int):
if Engine.editor_hint: if Engine.editor_hint:
set_template(template_name) set_template(template_name)
property_list_changed_notify() property_list_changed_notify()
# !!! API v2 # !!! API v2
func set_chart_name(ch_name : String): func set_chart_name(ch_name : String):
chart_name = ch_name chart_name = ch_name
get_node("ChartName").set_text(chart_name) get_node("ChartName").set_text(chart_name)
# !!! API v2 # !!! API v2
func set_source(source_file : String): func set_source(source_file : String):
source = source_file source = source_file
# !!! API v2 # !!! API v2
func set_indexes(lb : int = 0, function_names : int = 0): func set_indexes(lb : int = 0, function_names : int = 0):
labels_index = lb labels_index = lb
function_names_index = function_names function_names_index = function_names
# !!! API v2 # !!! API v2
func set_radius(use_height : bool = false, f : float = 0): func set_radius(use_height : bool = false, f : float = 0):
use_height_as_radius = use_height use_height_as_radius = use_height
radius = f radius = f
# !!! API v2 # !!! API v2
func set_chart_colors(f_colors : Array, o_color : Color, b_color : Color, g_color : Color, h_lines : Color, v_lines : Color): func set_chart_colors(f_colors : Array, o_color : Color, b_color : Color, g_color : Color, h_lines : Color, v_lines : Color):
function_colors = f_colors function_colors = f_colors
outline_color = o_color outline_color = o_color
box_color = b_color box_color = b_color
grid_color = g_color grid_color = g_color
h_lines_color = h_lines h_lines_color = h_lines
v_lines_color = v_lines v_lines_color = v_lines
# !!! API v2 # !!! API v2
func set_chart_fonts(normal_font : Font, bold_font : Font, f_color : Color): func set_chart_fonts(normal_font : Font, bold_font : Font, f_color : Color):
font = normal_font font = normal_font
self.bold_font = bold_font self.bold_font = bold_font
font_color = f_color font_color = f_color
# !!! API v2 # !!! API v2
func set_delimiter(d : String): func set_delimiter(d : String):
d = delimiter delimiter = d
# ! API # ! API
func set_origin_at_zero(b : bool): func set_origin_at_zero(b : bool):
origin_at_zero = b origin_at_zero = b
# ! API # ! API
func set_are_values_columns(b : bool): func set_are_values_columns(b : bool):
are_values_columns = b are_values_columns = b
# ! API # ! API
func set_show_x_values_as_labels(b : bool): func set_show_x_values_as_labels(b : bool):
show_x_values_as_labels = b show_x_values_as_labels = b
func set_labels_index(i : int): func set_labels_index(i : int):
labels_index = i labels_index = i
func set_function_names_index(i : int): func set_function_names_index(i : int):
function_names_index = i function_names_index = i
func set_use_height_as_radius(b : bool): func set_use_height_as_radius(b : bool):
use_height_as_radius = b use_height_as_radius = b
func _set_radius(r : float): func _set_radius(r : float):
radius = r radius = r
# ! API # ! API
func set_column_width(f : float): func set_column_width(f : float):
column_width = f column_width = f
# ! API # ! API
func set_column_gap(f : float): func set_column_gap(f : float):
column_gap = f column_gap = f
# ! API # ! API
func set_full_scale(f : float): func set_full_scale(f : float):
full_scale = f full_scale = f
# ! API # ! API
func set_x_decim(f : float): func set_x_decim(f : float):
x_decim = f x_decim = f
# ! API # ! API
func set_y_decim(f : float): func set_y_decim(f : float):
y_decim = f y_decim = f
# ! API # ! API
func set_points_shape(a : Array): func set_points_shape(a : Array):
points_shape = a points_shape = a
# ! API # ! API
func set_function_colors(a : Array): func set_function_colors(a : Array):
function_colors = a function_colors = a
# ! API # ! API
func set_outline_color(c : Color): func set_outline_color(c : Color):
outline_color = c outline_color = c
# ! API # ! API
func set_box_color(c : Color): func set_box_color(c : Color):
box_color = c box_color = c
# ! API # ! API
func set_grid_color(c : Color): func set_grid_color(c : Color):
grid_color = c grid_color = c
# ! API # ! API
func set_v_lines_color(c : Color): func set_v_lines_color(c : Color):
v_lines_color = c v_lines_color = c
# ! API # ! API
func set_h_lines_color(c : Color): func set_h_lines_color(c : Color):
h_lines_color = c h_lines_color = c
# ! API # ! API
func set_font(f : Font): func set_font(f : Font):
font = f font = f
# ! API # ! API
func set_bold_font(f : Font): func set_bold_font(f : Font):
bold_font = f bold_font = f
# ! API # ! API
func set_font_color(c : Color): func set_font_color(c : Color):
font_color = c font_color = c
# ! API # ! API
func set_template(template_name : int): func set_template(template_name : int):
template = template_name template = template_name
templates = Utilities.templates templates = Utilities.templates
if template_name!=null: if template_name!=null:
var custom_template = templates.get(templates.keys()[template_name]) var custom_template = templates.get(templates.keys()[template_name])
function_colors = custom_template.function_colors as PoolColorArray function_colors = custom_template.function_colors as PoolColorArray
outline_color = Color(custom_template.outline_color) outline_color = Color(custom_template.outline_color)
box_color = Color(custom_template.outline_color) box_color = Color(custom_template.outline_color)
grid_color = Color(custom_template.v_lines_color) grid_color = Color(custom_template.v_lines_color)
v_lines_color = Color(custom_template.v_lines_color) v_lines_color = Color(custom_template.v_lines_color)
h_lines_color = Color(custom_template.h_lines_color) h_lines_color = Color(custom_template.h_lines_color)
box_color = Color(custom_template.outline_color) box_color = Color(custom_template.outline_color)
font_color = Color(custom_template.font_color) font_color = Color(custom_template.font_color)
# ! API # ! API
func set_rotation(f : float): func set_rotation(f : float):
rotation = f rotation = f
# ! API # ! API
func set_invert_chart(b : bool): func set_invert_chart(b : bool):
invert_chart = b invert_chart = b
func set_legend(l : Array): func set_legend(l : Array):
legend = l legend = l
func get_legend(): func get_legend():
return legend return legend
# ............................. Shared Signals .............................. # ............................. Shared Signals ..............................
func point_pressed(point : Point): func point_pressed(point : Point):
emit_signal("point_pressed",point) emit_signal("point_pressed",point)
func show_data(point : Point): func show_data(point : Point):
PointData.update_datas(point) PointData.update_datas(point)
PointData.show() PointData.show()
func hide_data(): func hide_data():
PointData.hide() PointData.hide()