fix plot updating

This commit is contained in:
fenix-hub 2022-01-09 19:12:10 +01:00
parent 38b78bfd64
commit 687562a7a2
3 changed files with 76 additions and 74 deletions

View File

@ -1,5 +1,5 @@
tool tool
extends Chart extends ScatterChartBase
class_name RadarChart class_name RadarChart
""" """
@ -125,75 +125,76 @@ func _get_property_list():
}, },
] ]
func structure_data(database : Array): #func structure_data(database : Array):
# @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
are_values_columns = invert_chart != are_values_columns # are_values_columns = invert_chart != are_values_columns
match are_values_columns: # match are_values_columns:
true: # true:
for row in database.size(): # for row in database.size():
var t_row : Array = [] # var t_row : Array = []
for column in database[row].size(): # for column in database[row].size():
if row == labels_index: # if row == labels_index:
if column == function_names_index: # if column == function_names_index:
pass # pass
else: # else:
x_labels.append(database[row][column]) # x_labels.append(database[row][column])
else: # else:
if column == function_names_index: # if column == function_names_index:
y_labels.append(database[row][column]) # y_labels.append(database[row][column])
else: # else:
if typeof(database[row][column]) == TYPE_INT or typeof(database[row][column]) == TYPE_REAL: # if typeof(database[row][column]) == TYPE_INT or typeof(database[row][column]) == TYPE_REAL:
t_row.append(database[row][column] as float) # t_row.append(database[row][column] as float)
else: # else:
t_row.append(database[row][column].replace(",", ".") as float) # t_row.append(database[row][column].replace(",", ".") as float)
if not t_row.empty(): # if not t_row.empty():
x_datas.append(t_row) # x_datas.append(t_row)
false: # false:
for row in database.size(): # for row in database.size():
if row == function_names_index: # if row == function_names_index:
y_labels = database[row] as PoolStringArray # y_labels = database[row] as PoolStringArray
#
var x_temp_datas : PoolRealArray = [] # var x_temp_datas : PoolRealArray = []
for column in database[row].size(): # for column in database[row].size():
if column == labels_index: # if column == labels_index:
x_labels.append(database[row][column] as String) # x_labels.append(database[row][column] as String)
else: # else:
x_temp_datas.append(database[row][column] as float) # x_temp_datas.append(database[row][column] as float)
x_datas.append(x_temp_datas) # x_datas.append(x_temp_datas)
#
#
if labels_index == -1 : # if labels_index == -1 :
for data in x_datas[0].size(): # for data in x_datas[0].size():
x_labels.append("Element %s" % data) # x_labels.append("Element %s" % data)
#
if function_names_index == -1 : # if function_names_index == -1 :
for data in x_datas.size(): # for data in x_datas.size():
y_labels.append("Function %s" % data) # y_labels.append("Function %s" % data)
#
func build_chart(): #func build_chart():
SIZE = get_size() # SIZE = get_size()
origin = OFFSET + SIZE/2 # origin = OFFSET + SIZE/2
#
#
#func calculate_pass() :
# var ordered_max : Array
# for data in x_datas :
# var ordered_data : Array = data.duplicate()
# ordered_data.sort()
# ordered_max.append(ordered_data.pop_back())
# ordered_max.sort()
# var max_value : float = ordered_max.pop_back()
# var dist = full_scale * pow(10.0,str(max_value).length()-2)
# var multi = 0
# var value = dist * multi
# x_chors.append(value as String)
# while value < max_value:
# multi+=1
# value = dist * multi
# x_chors.append(value as String)
var radar_polygon : Array var radar_polygon : Array
func calculate_pass() :
var ordered_max : Array
for data in x_datas :
var ordered_data : Array = data.duplicate()
ordered_data.sort()
ordered_max.append(ordered_data.pop_back())
ordered_max.sort()
var max_value : float = ordered_max.pop_back()
var dist = full_scale * pow(10.0,str(max_value).length()-2)
var multi = 0
var value = dist * multi
x_chors.append(value as String)
while value < max_value:
multi+=1
value = dist * multi
x_chors.append(value as String)
func calculate_coordinates(): func calculate_coordinates():
for chor in x_chors.size(): for chor in x_chors.size():
var inner_polyline : PoolVector2Array var inner_polyline : PoolVector2Array

View File

@ -45,6 +45,8 @@ var y_coordinates : Array
# data contained in file # data contained in file
var data : Array var data : Array
# If using a Dataframe
var dataframe: DataFrame
# amount of functions to represent # amount of functions to represent
var functions : int = 0 var functions : int = 0
@ -325,10 +327,6 @@ func plot(_dataset: Array = read_data(source, delimiter)) -> void:
load_font() load_font()
data_tooltip.hide() data_tooltip.hide()
if source == "" or source == null:
ECUtilities._print_message("Can't plot a chart without a Source file. Please, choose it in editor, or use the custom function _plot().",1)
return
if _dataset.empty(): if _dataset.empty():
ECUtilities._print_message("Can't plot a chart with an empty Array.",1) ECUtilities._print_message("Can't plot a chart with an empty Array.",1)
return return
@ -341,9 +339,14 @@ func plot(_dataset: Array = read_data(source, delimiter)) -> void:
if not is_connected("item_rect_changed", self, "redraw_plot"): connect("item_rect_changed", self, "redraw_plot") if not is_connected("item_rect_changed", self, "redraw_plot"): connect("item_rect_changed", self, "redraw_plot")
func plot_from_source(file : String, _delimiter : String = delimiter) -> void: func plot_from_source(file : String, _delimiter : String = delimiter) -> void:
if source == "" or source == null:
ECUtilities._print_message("Can't plot a chart without a Source file. Please, choose it in editor, or use the custom function _plot().",1)
return
plot(read_data(file, _delimiter)) plot(read_data(file, _delimiter))
func plot_from_dataframe(dataframe : DataFrame) -> void: func plot_from_dataframe(dataframe : DataFrame) -> void:
self.dataframe = dataframe
plot(dataframe.get_dataset()) plot(dataframe.get_dataset())
func plot_placeholder() -> void: func plot_placeholder() -> void:
@ -354,7 +357,7 @@ func plot_placeholder() -> void:
# All data are stored. # All data are stored.
func update_plot(new_data : Array = []) -> void: func update_plot(new_data : Array = []) -> void:
if not new_data.empty(): data.append(new_data) if not new_data.empty(): data.append(new_data)
plot(data) plot(data if dataframe == null else dataframe.get_dataset())
# Append a new column to data # Append a new column to data
func append_new_column(dataset : Array, column : Array): func append_new_column(dataset : Array, column : Array):

View File

@ -540,8 +540,6 @@ func draw_chart_outlines():
func draw_points(): func draw_points():
for function in point_values.size(): for function in point_values.size():
var PointContainer : Control = Control.new() var PointContainer : Control = Control.new()
PointContainer.name = "PointContainer"
Points.add_child(PointContainer) Points.add_child(PointContainer)
for function_point in point_values[function].size(): for function_point in point_values[function].size():