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):
|
func structure_datas(database: Array):
|
||||||
# @x_values_index can be either a column or a row relative to x values
|
# @labels_index can be either a column or a row relative to x values
|
||||||
self.are_values_columns = are_values_columns
|
are_values_columns = (invert_chart != are_values_columns)
|
||||||
if are_values_columns:
|
if are_values_columns:
|
||||||
for row in database.size():
|
for row in database.size():
|
||||||
var t_vals: Array
|
var t_vals: Array
|
||||||
for column in database[row].size():
|
for column in database[row].size():
|
||||||
if column == x_values_index:
|
if column == labels_index:
|
||||||
var x_data = database[row][column]
|
var x_data = database[row][column]
|
||||||
if x_data.is_valid_float() or x_data.is_valid_integer():
|
if x_data.is_valid_float() or x_data.is_valid_integer():
|
||||||
x_datas.append(x_data as float)
|
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())
|
x_label = str(x_datas.pop_front())
|
||||||
else:
|
else:
|
||||||
for row in database.size():
|
for row in database.size():
|
||||||
if row == x_values_index:
|
if row == labels_index:
|
||||||
x_datas = (database[row])
|
x_datas = (database[row])
|
||||||
x_label = x_datas.pop_front() as String
|
x_label = x_datas.pop_front() as String
|
||||||
else:
|
else:
|
||||||
@ -244,13 +244,10 @@ func build_chart():
|
|||||||
|
|
||||||
|
|
||||||
func calculate_pass():
|
func calculate_pass():
|
||||||
if invert_chart:
|
if show_x_values_as_labels:
|
||||||
x_chors = y_labels.duplicate(true) as PoolStringArray
|
x_chors = x_datas.duplicate(true) as PoolStringArray
|
||||||
else:
|
else:
|
||||||
if show_x_values_as_labels:
|
x_chors = x_labels.duplicate(true)
|
||||||
x_chors = x_datas.duplicate(true) as PoolStringArray
|
|
||||||
else:
|
|
||||||
x_chors = x_labels.duplicate(true)
|
|
||||||
|
|
||||||
# calculate distance in pixel between 2 consecutive values/datas
|
# calculate distance in pixel between 2 consecutive values/datas
|
||||||
x_pass = (SIZE.x - OFFSET.x) / (x_chors.size()-1 if x_chors.size()>1 else x_chors.size() )
|
x_pass = (SIZE.x - OFFSET.x) / (x_chors.size()-1 if x_chors.size()>1 else x_chors.size() )
|
||||||
@ -262,25 +259,15 @@ func calculate_coordinates():
|
|||||||
y_coordinates.clear()
|
y_coordinates.clear()
|
||||||
point_values.clear()
|
point_values.clear()
|
||||||
point_positions.clear()
|
point_positions.clear()
|
||||||
|
|
||||||
if invert_chart:
|
for cluster in y_datas:
|
||||||
for column in y_datas[0].size():
|
var single_coordinates: Array
|
||||||
var single_coordinates: Array
|
for value in cluster.size():
|
||||||
for row in y_datas:
|
if origin_at_zero:
|
||||||
if origin_at_zero:
|
single_coordinates.append((cluster[value] * y_pass) / v_dist)
|
||||||
single_coordinates.append((row[column] * y_pass) / v_dist)
|
else:
|
||||||
else:
|
single_coordinates.append((cluster[value] - y_margin_min) * y_pass / v_dist)
|
||||||
single_coordinates.append((row[column] - y_margin_min) * y_pass / v_dist)
|
y_coordinates.append(single_coordinates)
|
||||||
y_coordinates.append(single_coordinates)
|
|
||||||
else:
|
|
||||||
for cluster in y_datas:
|
|
||||||
var single_coordinates: Array
|
|
||||||
for value in cluster.size():
|
|
||||||
if origin_at_zero:
|
|
||||||
single_coordinates.append((cluster[value] * y_pass) / v_dist)
|
|
||||||
else:
|
|
||||||
single_coordinates.append((cluster[value] - y_margin_min) * y_pass / v_dist)
|
|
||||||
y_coordinates.append(single_coordinates)
|
|
||||||
|
|
||||||
if show_x_values_as_labels:
|
if show_x_values_as_labels:
|
||||||
for x in x_datas.size():
|
for x in x_datas.size():
|
||||||
@ -288,10 +275,7 @@ func calculate_coordinates():
|
|||||||
else:
|
else:
|
||||||
for x in x_datas.size():
|
for x in x_datas.size():
|
||||||
if origin_at_zero:
|
if origin_at_zero:
|
||||||
if invert_chart:
|
x_coordinates.append(x_datas[x] * x_pass / h_dist)
|
||||||
x_coordinates.append(x_pass * x)
|
|
||||||
else:
|
|
||||||
x_coordinates.append(x_datas[x] * x_pass / h_dist)
|
|
||||||
else:
|
else:
|
||||||
x_coordinates.append((x_datas[x] - x_margin_min) * x_pass / h_dist)
|
x_coordinates.append((x_datas[x] - x_margin_min) * x_pass / h_dist)
|
||||||
|
|
||||||
@ -299,33 +283,17 @@ func calculate_coordinates():
|
|||||||
point_values.append([])
|
point_values.append([])
|
||||||
point_positions.append([])
|
point_positions.append([])
|
||||||
|
|
||||||
if invert_chart:
|
for cluster in y_coordinates.size():
|
||||||
for function in y_coordinates.size():
|
for y in y_coordinates[cluster].size():
|
||||||
for function_value in y_coordinates[function].size():
|
if are_values_columns:
|
||||||
if are_values_columns:
|
point_values[y].append([x_datas[cluster], y_datas[cluster][y]])
|
||||||
point_positions[function_value].append(Vector2(
|
point_positions[y].append(Vector2(
|
||||||
x_coordinates[function] + origin.x,
|
x_coordinates[cluster] + origin.x, origin.y - y_coordinates[cluster][y]))
|
||||||
origin.y - y_coordinates[function][function_value]))
|
else:
|
||||||
point_values[function_value].append(
|
point_values[cluster].append([x_datas[y], y_datas[cluster][y]])
|
||||||
[x_datas[function_value], y_datas[function_value][function]])
|
point_positions[cluster].append(Vector2(
|
||||||
else:
|
x_coordinates[y] + origin.x,
|
||||||
point_positions[function].append(Vector2(
|
origin.y - y_coordinates[cluster][y]))
|
||||||
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:
|
|
||||||
point_values[y].append([x_datas[cluster], y_datas[cluster][y]])
|
|
||||||
point_positions[y].append(Vector2(
|
|
||||||
x_coordinates[cluster] + origin.x, origin.y - y_coordinates[cluster][y]))
|
|
||||||
else:
|
|
||||||
point_values[cluster].append([x_datas[y], y_datas[cluster][y]])
|
|
||||||
point_positions[cluster].append(Vector2(
|
|
||||||
x_coordinates[y] + origin.x,
|
|
||||||
origin.y - y_coordinates[cluster][y]))
|
|
||||||
|
|
||||||
func _draw():
|
func _draw():
|
||||||
clear_points()
|
clear_points()
|
||||||
@ -346,14 +314,14 @@ func _draw():
|
|||||||
point.connect("_point_pressed", self, "point_pressed")
|
point.connect("_point_pressed", self, "point_pressed")
|
||||||
point.connect("_mouse_entered", self, "show_data")
|
point.connect("_mouse_entered", self, "show_data")
|
||||||
point.connect("_mouse_exited", self, "hide_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)
|
Points.add_child(point)
|
||||||
if function_point > 0:
|
if function_point > 0:
|
||||||
draw_line(
|
draw_line(
|
||||||
point_positions[_function][function_point - 1],
|
point_positions[_function][function_point - 1],
|
||||||
point_positions[_function][function_point],
|
point_positions[_function][function_point],
|
||||||
function_colors[function_point if invert_chart else _function],
|
function_colors[_function],
|
||||||
2,
|
2,
|
||||||
false)
|
false)
|
||||||
draw_treshold()
|
draw_treshold()
|
||||||
|
@ -320,7 +320,7 @@ func plot():
|
|||||||
|
|
||||||
|
|
||||||
data = read_datas(source)
|
data = read_datas(source)
|
||||||
structure_datas(slice_data(),are_values_columns,labels_index)
|
structure_datas(slice_data())
|
||||||
build_chart()
|
build_chart()
|
||||||
count_functions()
|
count_functions()
|
||||||
calculate_pass()
|
calculate_pass()
|
||||||
@ -339,7 +339,7 @@ func plot_from_csv(csv_file : String, _delimiter : String = delimiter):
|
|||||||
return
|
return
|
||||||
|
|
||||||
data = read_datas(csv_file, _delimiter)
|
data = read_datas(csv_file, _delimiter)
|
||||||
structure_datas(slice_data(),are_values_columns,labels_index)
|
structure_datas(slice_data())
|
||||||
build_chart()
|
build_chart()
|
||||||
count_functions()
|
count_functions()
|
||||||
calculate_pass()
|
calculate_pass()
|
||||||
@ -360,7 +360,7 @@ func plot_from_array(array : Array) -> void:
|
|||||||
return
|
return
|
||||||
|
|
||||||
data = array.duplicate()
|
data = array.duplicate()
|
||||||
structure_datas(slice_data(), are_values_columns,labels_index)
|
structure_datas(slice_data())
|
||||||
build_chart()
|
build_chart()
|
||||||
count_functions()
|
count_functions()
|
||||||
calculate_pass()
|
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)
|
Utilities._print_message("Can't plot a chart with an empty Array.",1)
|
||||||
return
|
return
|
||||||
|
|
||||||
structure_datas(slice_data(),are_values_columns,labels_index)
|
structure_datas(slice_data())
|
||||||
build_chart()
|
build_chart()
|
||||||
count_functions()
|
count_functions()
|
||||||
calculate_pass()
|
calculate_pass()
|
||||||
@ -405,7 +405,7 @@ func update_plot_data(array : Array) -> void:
|
|||||||
return
|
return
|
||||||
|
|
||||||
data.append(array)
|
data.append(array)
|
||||||
structure_datas(slice_data(),are_values_columns,labels_index)
|
structure_datas(slice_data())
|
||||||
redraw()
|
redraw()
|
||||||
count_functions()
|
count_functions()
|
||||||
calculate_colors()
|
calculate_colors()
|
||||||
@ -463,16 +463,8 @@ func read_datas(source : String, _delimiter : String = delimiter):
|
|||||||
return content
|
return content
|
||||||
|
|
||||||
func count_functions():
|
func count_functions():
|
||||||
if are_values_columns:
|
if are_values_columns: functions = data[0].size()-1
|
||||||
if not invert_chart:
|
else: functions = y_datas.size()
|
||||||
functions = data[0].size()-1
|
|
||||||
else:
|
|
||||||
functions = data.size()-1
|
|
||||||
else:
|
|
||||||
if invert_chart:
|
|
||||||
functions = x_datas.size()
|
|
||||||
else:
|
|
||||||
functions = y_datas.size()
|
|
||||||
|
|
||||||
func clear_points():
|
func clear_points():
|
||||||
if $Points.get_children():
|
if $Points.get_children():
|
||||||
@ -497,7 +489,7 @@ func clean_variables():
|
|||||||
y_labels.clear()
|
y_labels.clear()
|
||||||
|
|
||||||
# .................. VIRTUAL FUNCTIONS .........................
|
# .................. VIRTUAL FUNCTIONS .........................
|
||||||
func structure_datas(database : Array, are_values_columns : bool, labels_index : int):
|
func structure_datas(database : Array):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func build_chart():
|
func build_chart():
|
||||||
@ -520,7 +512,7 @@ func create_legend():
|
|||||||
else:
|
else:
|
||||||
function_legend = LegendElement.instance()
|
function_legend = LegendElement.instance()
|
||||||
legend.append(function_legend)
|
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
|
var legend_font : Font
|
||||||
if font != null:
|
if font != null:
|
||||||
legend_font = font
|
legend_font = font
|
||||||
|
Loading…
Reference in New Issue
Block a user