update plotting

This commit is contained in:
fenix-hub 2022-01-10 17:54:03 +01:00
parent 90128adb3c
commit 514f42d29f
3 changed files with 44 additions and 37 deletions

View File

@ -24,7 +24,7 @@ A line chart is often used to visualize a trend in data over intervals of time
a time series thus the line is often drawn chronologically. a time series thus the line is often drawn chronologically.
In these cases they are known as run charts." In these cases they are known as run charts."
} }
Chart_Properties/are_values_columns = false Chart_Properties/are_values_columns = true
Chart_Properties/labels_index = 0 Chart_Properties/labels_index = 0
Chart_Display/autoscale_x = true Chart_Display/autoscale_x = true
Chart_Display/x_decim = 1.0 Chart_Display/x_decim = 1.0
@ -85,10 +85,10 @@ __meta__ = {
[node name="CanvasLayer" type="CanvasLayer" parent="."] [node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="DataTooltip" parent="CanvasLayer" instance=ExtResource( 1 )] [node name="DataTooltip" parent="CanvasLayer" instance=ExtResource( 1 )]
margin_left = -124.653 margin_left = -126.774
margin_top = -56.7206 margin_top = -58.1348
margin_right = -124.789 margin_right = -126.91
margin_bottom = -55.9206 margin_bottom = -57.3348
[node name="PointData" parent="CanvasLayer/DataTooltip" index="0"] [node name="PointData" parent="CanvasLayer/DataTooltip" index="0"]
margin_left = -189.809 margin_left = -189.809

View File

@ -366,7 +366,8 @@ 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 if dataframe == null else dataframe.get_dataset()) plot(data if dataframe == null else dataframe.get_dataset().duplicate(true))
update()
# 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):
@ -391,21 +392,23 @@ func read_data(source : String, _delimiter : String = delimiter):
file.close() file.close()
return content.duplicate(true) return content.duplicate(true)
func slice_x(x_data : Array) -> Array:
return [x_data[0]] + Array(x_data).slice(x_data.size() - only_disp_values.x, x_data.size() -1 )
func slice_y(y_data : Array) -> Array:
return [y_data[0]] + y_data.slice(y_data.size()-only_disp_values.y, y_data.size()-1)
## TODO: Data should not be sliced!!
## Instead, only_disp_values should affect all the `range()` to plot points
func slice_data(database : Array) -> Array: func slice_data(database : Array) -> Array:
var data_to_display : Array var data_to_display : Array = database
data_to_display.resize(database.size()) if only_disp_values.y < database.size() and only_disp_values.y !=0:
if only_disp_values == Vector2(): return database.duplicate(true) data_to_display = slice_y(database)
if only_disp_values.x == 0 and only_disp_values.y < database.size(): if only_disp_values.x < database[0].size() and only_disp_values.x !=0:
data_to_display = [database[0]] + database.slice(database.size()-only_disp_values.y, database.size()-1)
elif only_disp_values.y == 0 and only_disp_values.x < database[0].size():
for row_idx in database.size(): for row_idx in database.size():
data_to_display[row_idx] = [database[row_idx][0]] + Array(database[row_idx]).slice(database[row_idx].size() - only_disp_values.x, database[row_idx].size() -1 ) data_to_display[row_idx] = slice_x(database[row_idx])
elif only_disp_values.x != 0 and only_disp_values.y != 0 and only_disp_values.y < database[0].size() and only_disp_values.x < database[0].size(): return data_to_display.duplicate(true)
for row_idx in database.size():
data_to_display[row_idx] = [database[row_idx][0]] + database[row_idx].slice(only_disp_values.x, database[row_idx].size()-only_disp_values.y)
else:
data_to_display = database.duplicate(true)
return data_to_display
# ................................. Display and Draw functions ....................... # ................................. Display and Draw functions .......................
func compute_display(): func compute_display():
@ -443,8 +446,8 @@ func load_font():
bold_font = font bold_font = font
func count_functions(): func count_functions():
if are_values_columns: functions = data[0].size()-1 if are_values_columns: functions = x_labels.size()
else: functions = y_datas.size() else: functions = y_labels.size()
func calculate_colors(): func calculate_colors():
if function_colors.size() < functions: if function_colors.size() < functions:
@ -464,7 +467,7 @@ func create_legend():
else: else:
function_legend = legend_element.instance() function_legend = legend_element.instance()
legend.append(function_legend) legend.append(function_legend)
var f_name : String = y_labels[function] if not are_values_columns else str(x_datas[function]) var f_name : String = y_labels[function] if are_values_columns else str(x_labels[function])
var legend_font : Font var legend_font : Font
if font != null: if font != null:
legend_font = font legend_font = font

View File

@ -308,40 +308,44 @@ func plot_function(id: String, x:Array, y:Array, param_dic := {}):
redraw_plot() redraw_plot()
update() update()
func _slice():
if only_disp_values.x < x_values.size() and only_disp_values.x != 0:
x_values.pop_front()
for y_data in y_datas:
y_data.pop_front()
func update_functions(new_x, new_y : Array, param_dic : = {}) : func update_functions(new_x, new_y : Array, param_dic : = {}) :
_slice()
x_values.append(new_x) x_values.append(new_x)
for function in y_labels.size():
_update_function(y_labels[function], new_y[function]) for function in y_datas.size():
y_datas[function].append(new_y[function])
calculate_range(y_labels[function])
calculate_tics() calculate_tics()
redraw_plot() redraw_plot()
update() update()
func update_function(id: String, new_x, new_y, param_dic := {}) -> void: func update_function(id: String, new_x, new_y, param_dic := {}) -> void:
_slice()
if only_disp_values.x < x_values[0].size():
x_values.pop_front()
x_values.append(new_x) x_values.append(new_x)
_update_function(id, new_y, param_dic)
calculate_tics()
redraw_plot()
update()
func _update_function(id: String, new_y, param_dic := {}):
var function = y_labels.find(id) var function = y_labels.find(id)
if function == -1: #Not found if function == -1: #Not found
ECUtilities._print_message("The identifier %s does not exist." % id,1) ECUtilities._print_message("The identifier %s does not exist." % id,1)
return return
for param in param_dic.keys():
match param:
"label":
y_labels[function] = param_dic[param]
"color":
function_colors[function] = param_dic[param]
for y_data_i in range(0, y_datas.size()): for y_data_i in range(0, y_datas.size()):
if y_data_i == function: y_datas[y_data_i].append(new_y) if y_data_i == function: y_datas[y_data_i].append(new_y)
else: y_datas[y_data_i].append(y_datas[y_data_i][y_datas[y_data_i].size()-1]) else: y_datas[y_data_i].append(y_datas[y_data_i][y_datas[y_data_i].size()-1])
calculate_range(id) calculate_range(id)
calculate_tics()
redraw_plot()
update()
func delete_function(id: String): func delete_function(id: String):
var function = y_labels.find(id) var function = y_labels.find(id)