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.
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_Display/autoscale_x = true
Chart_Display/x_decim = 1.0
@ -85,10 +85,10 @@ __meta__ = {
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="DataTooltip" parent="CanvasLayer" instance=ExtResource( 1 )]
margin_left = -124.653
margin_top = -56.7206
margin_right = -124.789
margin_bottom = -55.9206
margin_left = -126.774
margin_top = -58.1348
margin_right = -126.91
margin_bottom = -57.3348
[node name="PointData" parent="CanvasLayer/DataTooltip" index="0"]
margin_left = -189.809

View File

@ -366,7 +366,8 @@ func plot_placeholder() -> void:
# All data are stored.
func update_plot(new_data : Array = []) -> void:
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
func append_new_column(dataset : Array, column : Array):
@ -391,21 +392,23 @@ func read_data(source : String, _delimiter : String = delimiter):
file.close()
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:
var data_to_display : Array
data_to_display.resize(database.size())
if only_disp_values == Vector2(): return database.duplicate(true)
if only_disp_values.x == 0 and only_disp_values.y < database.size():
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():
var data_to_display : Array = database
if only_disp_values.y < database.size() and only_disp_values.y !=0:
data_to_display = slice_y(database)
if only_disp_values.x < database[0].size() and only_disp_values.x !=0:
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 )
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():
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
data_to_display[row_idx] = slice_x(database[row_idx])
return data_to_display.duplicate(true)
# ................................. Display and Draw functions .......................
func compute_display():
@ -443,8 +446,8 @@ func load_font():
bold_font = font
func count_functions():
if are_values_columns: functions = data[0].size()-1
else: functions = y_datas.size()
if are_values_columns: functions = x_labels.size()
else: functions = y_labels.size()
func calculate_colors():
if function_colors.size() < functions:
@ -464,7 +467,7 @@ func create_legend():
else:
function_legend = legend_element.instance()
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
if font != null:
legend_font = font

View File

@ -308,40 +308,44 @@ func plot_function(id: String, x:Array, y:Array, param_dic := {}):
redraw_plot()
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 : = {}) :
_slice()
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()
redraw_plot()
update()
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)
_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)
if function == -1: #Not found
ECUtilities._print_message("The identifier %s does not exist." % id,1)
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()):
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])
calculate_range(id)
calculate_tics()
redraw_plot()
update()
func delete_function(id: String):
var function = y_labels.find(id)