mirror of
https://github.com/Relintai/pandemonium_engine_easy_charts.git
synced 2025-01-02 14:29:45 +01:00
@invert_chart and @are_values_columns fixed
This commit is contained in:
parent
90f3ea8a56
commit
d85a85d71e
@ -154,14 +154,14 @@ func _get_property_list():
|
||||
]
|
||||
|
||||
|
||||
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
|
||||
self.are_values_columns = are_values_columns
|
||||
func structure_datas(database: Array):
|
||||
# @labels_index can be either a column or a row relative to x values
|
||||
are_values_columns = (invert_chart != are_values_columns)
|
||||
if are_values_columns:
|
||||
for row in database.size():
|
||||
var t_vals: Array
|
||||
for column in database[row].size():
|
||||
if column == x_values_index:
|
||||
if column == labels_index:
|
||||
var x_data = database[row][column]
|
||||
if x_data.is_valid_float() or x_data.is_valid_integer():
|
||||
x_datas.append(x_data as float)
|
||||
@ -181,7 +181,7 @@ func structure_datas(database: Array, are_values_columns: bool, x_values_index:
|
||||
x_label = str(x_datas.pop_front())
|
||||
else:
|
||||
for row in database.size():
|
||||
if row == x_values_index:
|
||||
if row == labels_index:
|
||||
x_datas = (database[row])
|
||||
x_label = x_datas.pop_front() as String
|
||||
else:
|
||||
@ -244,9 +244,6 @@ func build_chart():
|
||||
|
||||
|
||||
func calculate_pass():
|
||||
if invert_chart:
|
||||
x_chors = y_labels.duplicate(true) as PoolStringArray
|
||||
else:
|
||||
if show_x_values_as_labels:
|
||||
x_chors = x_datas.duplicate(true) as PoolStringArray
|
||||
else:
|
||||
@ -263,16 +260,6 @@ func calculate_coordinates():
|
||||
point_values.clear()
|
||||
point_positions.clear()
|
||||
|
||||
if invert_chart:
|
||||
for column in y_datas[0].size():
|
||||
var single_coordinates: Array
|
||||
for row in y_datas:
|
||||
if origin_at_zero:
|
||||
single_coordinates.append((row[column] * y_pass) / v_dist)
|
||||
else:
|
||||
single_coordinates.append((row[column] - y_margin_min) * y_pass / v_dist)
|
||||
y_coordinates.append(single_coordinates)
|
||||
else:
|
||||
for cluster in y_datas:
|
||||
var single_coordinates: Array
|
||||
for value in cluster.size():
|
||||
@ -288,9 +275,6 @@ func calculate_coordinates():
|
||||
else:
|
||||
for x in x_datas.size():
|
||||
if origin_at_zero:
|
||||
if invert_chart:
|
||||
x_coordinates.append(x_pass * x)
|
||||
else:
|
||||
x_coordinates.append(x_datas[x] * x_pass / h_dist)
|
||||
else:
|
||||
x_coordinates.append((x_datas[x] - x_margin_min) * x_pass / h_dist)
|
||||
@ -299,22 +283,6 @@ func calculate_coordinates():
|
||||
point_values.append([])
|
||||
point_positions.append([])
|
||||
|
||||
if invert_chart:
|
||||
for function in y_coordinates.size():
|
||||
for function_value in y_coordinates[function].size():
|
||||
if are_values_columns:
|
||||
point_positions[function_value].append(Vector2(
|
||||
x_coordinates[function] + origin.x,
|
||||
origin.y - y_coordinates[function][function_value]))
|
||||
point_values[function_value].append(
|
||||
[x_datas[function_value], y_datas[function_value][function]])
|
||||
else:
|
||||
point_positions[function].append(Vector2(
|
||||
x_coordinates[function_value] + origin.x,
|
||||
origin.y - y_coordinates[function][function_value]))
|
||||
point_values[function].append(
|
||||
[x_datas[function_value], y_datas[function_value][function]])
|
||||
else:
|
||||
for cluster in y_coordinates.size():
|
||||
for y in y_coordinates[cluster].size():
|
||||
if are_values_columns:
|
||||
@ -346,14 +314,14 @@ func _draw():
|
||||
point.connect("_point_pressed", self, "point_pressed")
|
||||
point.connect("_mouse_entered", self, "show_data")
|
||||
point.connect("_mouse_exited", self, "hide_data")
|
||||
point.create_point(points_shape[_function],function_colors[function_point if invert_chart else _function],Color.white,point_positions[_function][function_point],point.format_value(point_values[_function][function_point], false, false),y_labels[function_point if invert_chart else _function] as String)
|
||||
point.create_point(points_shape[_function],function_colors[_function],Color.white,point_positions[_function][function_point],point.format_value(point_values[_function][function_point], false, false),y_labels[_function] as String)
|
||||
|
||||
Points.add_child(point)
|
||||
if function_point > 0:
|
||||
draw_line(
|
||||
point_positions[_function][function_point - 1],
|
||||
point_positions[_function][function_point],
|
||||
function_colors[function_point if invert_chart else _function],
|
||||
function_colors[_function],
|
||||
2,
|
||||
false)
|
||||
draw_treshold()
|
||||
|
@ -320,7 +320,7 @@ func plot():
|
||||
|
||||
|
||||
data = read_datas(source)
|
||||
structure_datas(slice_data(),are_values_columns,labels_index)
|
||||
structure_datas(slice_data())
|
||||
build_chart()
|
||||
count_functions()
|
||||
calculate_pass()
|
||||
@ -339,7 +339,7 @@ func plot_from_csv(csv_file : String, _delimiter : String = delimiter):
|
||||
return
|
||||
|
||||
data = read_datas(csv_file, _delimiter)
|
||||
structure_datas(slice_data(),are_values_columns,labels_index)
|
||||
structure_datas(slice_data())
|
||||
build_chart()
|
||||
count_functions()
|
||||
calculate_pass()
|
||||
@ -360,7 +360,7 @@ func plot_from_array(array : Array) -> void:
|
||||
return
|
||||
|
||||
data = array.duplicate()
|
||||
structure_datas(slice_data(), are_values_columns,labels_index)
|
||||
structure_datas(slice_data())
|
||||
build_chart()
|
||||
count_functions()
|
||||
calculate_pass()
|
||||
@ -385,7 +385,7 @@ func plot_from_dataframe(dataframe : DataFrame) -> void:
|
||||
Utilities._print_message("Can't plot a chart with an empty Array.",1)
|
||||
return
|
||||
|
||||
structure_datas(slice_data(),are_values_columns,labels_index)
|
||||
structure_datas(slice_data())
|
||||
build_chart()
|
||||
count_functions()
|
||||
calculate_pass()
|
||||
@ -405,7 +405,7 @@ func update_plot_data(array : Array) -> void:
|
||||
return
|
||||
|
||||
data.append(array)
|
||||
structure_datas(slice_data(),are_values_columns,labels_index)
|
||||
structure_datas(slice_data())
|
||||
redraw()
|
||||
count_functions()
|
||||
calculate_colors()
|
||||
@ -463,16 +463,8 @@ func read_datas(source : String, _delimiter : String = delimiter):
|
||||
return content
|
||||
|
||||
func count_functions():
|
||||
if are_values_columns:
|
||||
if not invert_chart:
|
||||
functions = data[0].size()-1
|
||||
else:
|
||||
functions = data.size()-1
|
||||
else:
|
||||
if invert_chart:
|
||||
functions = x_datas.size()
|
||||
else:
|
||||
functions = y_datas.size()
|
||||
if are_values_columns: functions = data[0].size()-1
|
||||
else: functions = y_datas.size()
|
||||
|
||||
func clear_points():
|
||||
if $Points.get_children():
|
||||
@ -497,7 +489,7 @@ func clean_variables():
|
||||
y_labels.clear()
|
||||
|
||||
# .................. VIRTUAL FUNCTIONS .........................
|
||||
func structure_datas(database : Array, are_values_columns : bool, labels_index : int):
|
||||
func structure_datas(database : Array):
|
||||
pass
|
||||
|
||||
func build_chart():
|
||||
@ -520,7 +512,7 @@ func create_legend():
|
||||
else:
|
||||
function_legend = LegendElement.instance()
|
||||
legend.append(function_legend)
|
||||
var f_name : String = y_labels[function]
|
||||
var f_name : String = y_labels[function] if not are_values_columns else str(x_datas[function])
|
||||
var legend_font : Font
|
||||
if font != null:
|
||||
legend_font = font
|
||||
|
Loading…
Reference in New Issue
Block a user