mirror of
https://github.com/Relintai/pandemonium_engine_easy_charts.git
synced 2025-02-26 17:24:21 +01:00
Merge branch 'main' of https://github.com/fenix-hub/godot-engine.easy-charts
This commit is contained in:
commit
fe8b19d7b6
@ -18,8 +18,6 @@ onready var PlaceholderPoint = $Chart/Point
|
||||
onready var Space = $ImmediateGeometry
|
||||
onready var DataTooltip = $DataTooltip/DataTooltip
|
||||
|
||||
var point_node : PackedScene = preload("res://addons/easy_charts/utilities/components/point/point.gd")
|
||||
var FunctionLegend : PackedScene = preload("res://addons/easy_charts/utilities/containers/legend/function_legend.gd")
|
||||
|
||||
var font_size : float = 16
|
||||
var const_height : float = font_size/2*font_size/20
|
||||
@ -113,42 +111,42 @@ signal chart_plotted(chart)
|
||||
signal point_pressed(point)
|
||||
|
||||
func _point_plotted():
|
||||
pass
|
||||
pass
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
pass
|
||||
|
||||
func _set_size(size : Vector2):
|
||||
SIZE = size
|
||||
SIZE = size
|
||||
# build_chart()
|
||||
|
||||
func clear():
|
||||
pass
|
||||
pass
|
||||
|
||||
func load_font():
|
||||
if font != null:
|
||||
font_size = font.get_height()
|
||||
var theme : Theme = Theme.new()
|
||||
theme.set_default_font(font)
|
||||
DataTooltip.set_theme(theme)
|
||||
else:
|
||||
var lbl = Label.new()
|
||||
font = lbl.get_font("")
|
||||
lbl.free()
|
||||
if bold_font != null:
|
||||
DataTooltip.Data.set("custom_fonts/font",bold_font)
|
||||
if font != null:
|
||||
font_size = font.get_height()
|
||||
var theme : Theme = Theme.new()
|
||||
theme.set_default_font(font)
|
||||
DataTooltip.set_theme(theme)
|
||||
else:
|
||||
var lbl = Label.new()
|
||||
font = lbl.get_font("")
|
||||
lbl.free()
|
||||
if bold_font != null:
|
||||
DataTooltip.Data.set("custom_fonts/font",bold_font)
|
||||
|
||||
func _plot(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_values_index_ : int):
|
||||
randomize()
|
||||
|
||||
clear()
|
||||
|
||||
load_font()
|
||||
DataTooltip.hide()
|
||||
|
||||
datas = read_data(source_,delimiter_)
|
||||
randomize()
|
||||
|
||||
clear()
|
||||
|
||||
load_font()
|
||||
DataTooltip.hide()
|
||||
|
||||
datas = read_data(source_,delimiter_)
|
||||
# count_functions()
|
||||
structure_data(datas,are_values_columns_,x_values_index_)
|
||||
structure_data(datas,are_values_columns_,x_values_index_)
|
||||
# build_chart()
|
||||
# calculate_pass()
|
||||
# calculate_coordinates()
|
||||
@ -156,154 +154,154 @@ func _plot(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_
|
||||
# draw_chart()
|
||||
#
|
||||
# create_legend()
|
||||
emit_signal("chart_plotted", self)
|
||||
emit_signal("chart_plotted", self)
|
||||
|
||||
func plot():
|
||||
randomize()
|
||||
|
||||
clear()
|
||||
|
||||
load_font()
|
||||
DataTooltip.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
|
||||
datas = read_data(source,delimiter)
|
||||
randomize()
|
||||
|
||||
clear()
|
||||
|
||||
load_font()
|
||||
DataTooltip.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
|
||||
datas = read_data(source,delimiter)
|
||||
# count_functions()
|
||||
structure_data(datas,are_values_columns,x_values_index)
|
||||
structure_data(datas,are_values_columns,x_values_index)
|
||||
# build_chart()
|
||||
# calculate_pass()
|
||||
# calculate_coordinates()
|
||||
# calculate_colors()
|
||||
# draw_chart()
|
||||
|
||||
|
||||
# create_legend()
|
||||
emit_signal("chart_plotted", self)
|
||||
emit_signal("chart_plotted", self)
|
||||
|
||||
|
||||
func read_data(source : String, delimiter : String):
|
||||
var file : File = File.new()
|
||||
file.open(source,File.READ)
|
||||
var content : Array
|
||||
while not file.eof_reached():
|
||||
var line : PoolStringArray = file.get_csv_line(delimiter)
|
||||
content.append(line)
|
||||
file.close()
|
||||
for data in content:
|
||||
if data.size() < 2:
|
||||
content.erase(data)
|
||||
return content
|
||||
var file : File = File.new()
|
||||
file.open(source,File.READ)
|
||||
var content : Array
|
||||
while not file.eof_reached():
|
||||
var line : PoolStringArray = file.get_csv_line(delimiter)
|
||||
content.append(line)
|
||||
file.close()
|
||||
for data in content:
|
||||
if data.size() < 2:
|
||||
content.erase(data)
|
||||
return content
|
||||
|
||||
func structure_data(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
|
||||
# @y_values can be either a column or a row relative to y values
|
||||
self.are_values_columns = are_values_columns
|
||||
match are_values_columns:
|
||||
true:
|
||||
for row in database.size():
|
||||
var t_vals : Array
|
||||
for column in database[row].size():
|
||||
if column == x_values_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)
|
||||
else:
|
||||
x_datas.append(x_data.replace(",",".") as float)
|
||||
elif column == z_values_index:
|
||||
var z_data = database[row][column]
|
||||
if z_data.is_valid_float() or z_data.is_valid_integer():
|
||||
z_datas.append(z_data as float)
|
||||
else:
|
||||
z_datas.append(z_data.replace(",",".") as float)
|
||||
else:
|
||||
if row != 0:
|
||||
var y_data = database[row][column]
|
||||
if y_data.is_valid_float() or y_data.is_valid_integer():
|
||||
t_vals.append(y_data as float)
|
||||
else:
|
||||
t_vals.append(y_data.replace(",",".") as float)
|
||||
else:
|
||||
y_labels.append(str(database[row][column]))
|
||||
if not t_vals.empty():
|
||||
y_datas.append(t_vals)
|
||||
x_label = str(x_datas.pop_front())
|
||||
z_label = str(z_datas.pop_front())
|
||||
false:
|
||||
for row in database.size():
|
||||
if row == x_values_index:
|
||||
x_datas = (database[row])
|
||||
x_label = x_datas.pop_front() as String
|
||||
else:
|
||||
var values = database[row] as Array
|
||||
y_labels.append(values.pop_front() as String)
|
||||
y_datas.append(values)
|
||||
for data in y_datas:
|
||||
for value in data.size():
|
||||
data[value] = data[value] as float
|
||||
|
||||
# draw y labels
|
||||
var to_order : Array
|
||||
var to_order_min : Array
|
||||
for cluster in y_datas.size():
|
||||
# define x_chors and y_chors
|
||||
var ordered_cluster = y_datas[cluster] as Array
|
||||
ordered_cluster.sort()
|
||||
ordered_cluster = PoolIntArray(ordered_cluster)
|
||||
var margin_max = ordered_cluster[ordered_cluster.size()-1]
|
||||
var margin_min = ordered_cluster[0]
|
||||
to_order.append(margin_max)
|
||||
to_order_min.append(margin_min)
|
||||
|
||||
to_order.sort()
|
||||
to_order_min.sort()
|
||||
var margin = to_order.pop_back()
|
||||
if not origin_at_zero:
|
||||
y_margin_min = to_order_min.pop_front()
|
||||
v_dist = y_decim * pow(10.0,str(margin).length()-2)
|
||||
var multi = 0
|
||||
var p = (v_dist*multi) + ((y_margin_min) if not origin_at_zero else 0)
|
||||
y_chors.append(p as String)
|
||||
while p < margin:
|
||||
multi+=1
|
||||
p = (v_dist*multi) + ((y_margin_min) if not origin_at_zero else 0)
|
||||
y_chors.append(p as String)
|
||||
|
||||
# draw x_labels
|
||||
if not show_x_values_as_labels:
|
||||
to_order.clear()
|
||||
to_order = x_datas as PoolIntArray
|
||||
|
||||
to_order.sort()
|
||||
margin = to_order.pop_back()
|
||||
if not origin_at_zero:
|
||||
x_margin_min = to_order.pop_front()
|
||||
h_dist = x_decim * pow(10.0,str(margin).length()-2)
|
||||
multi = 0
|
||||
p = (h_dist*multi) + ((x_margin_min) if not origin_at_zero else 0)
|
||||
x_labels.append(p as String)
|
||||
while p < margin:
|
||||
multi+=1
|
||||
p = (h_dist*multi) + ((x_margin_min) if not origin_at_zero else 0)
|
||||
x_labels.append(p as String)
|
||||
# @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
|
||||
self.are_values_columns = are_values_columns
|
||||
match are_values_columns:
|
||||
true:
|
||||
for row in database.size():
|
||||
var t_vals : Array
|
||||
for column in database[row].size():
|
||||
if column == x_values_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)
|
||||
else:
|
||||
x_datas.append(x_data.replace(",",".") as float)
|
||||
elif column == z_values_index:
|
||||
var z_data = database[row][column]
|
||||
if z_data.is_valid_float() or z_data.is_valid_integer():
|
||||
z_datas.append(z_data as float)
|
||||
else:
|
||||
z_datas.append(z_data.replace(",",".") as float)
|
||||
else:
|
||||
if row != 0:
|
||||
var y_data = database[row][column]
|
||||
if y_data.is_valid_float() or y_data.is_valid_integer():
|
||||
t_vals.append(y_data as float)
|
||||
else:
|
||||
t_vals.append(y_data.replace(",",".") as float)
|
||||
else:
|
||||
y_labels.append(str(database[row][column]))
|
||||
if not t_vals.empty():
|
||||
y_datas.append(t_vals)
|
||||
x_label = str(x_datas.pop_front())
|
||||
z_label = str(z_datas.pop_front())
|
||||
false:
|
||||
for row in database.size():
|
||||
if row == x_values_index:
|
||||
x_datas = (database[row])
|
||||
x_label = x_datas.pop_front() as String
|
||||
else:
|
||||
var values = database[row] as Array
|
||||
y_labels.append(values.pop_front() as String)
|
||||
y_datas.append(values)
|
||||
for data in y_datas:
|
||||
for value in data.size():
|
||||
data[value] = data[value] as float
|
||||
|
||||
# draw y labels
|
||||
var to_order : Array
|
||||
var to_order_min : Array
|
||||
for cluster in y_datas.size():
|
||||
# define x_chors and y_chors
|
||||
var ordered_cluster = y_datas[cluster] as Array
|
||||
ordered_cluster.sort()
|
||||
ordered_cluster = PoolIntArray(ordered_cluster)
|
||||
var margin_max = ordered_cluster[ordered_cluster.size()-1]
|
||||
var margin_min = ordered_cluster[0]
|
||||
to_order.append(margin_max)
|
||||
to_order_min.append(margin_min)
|
||||
|
||||
to_order.sort()
|
||||
to_order_min.sort()
|
||||
var margin = to_order.pop_back()
|
||||
if not origin_at_zero:
|
||||
y_margin_min = to_order_min.pop_front()
|
||||
v_dist = y_decim * pow(10.0,str(margin).length()-2)
|
||||
var multi = 0
|
||||
var p = (v_dist*multi) + ((y_margin_min) if not origin_at_zero else 0)
|
||||
y_chors.append(p as String)
|
||||
while p < margin:
|
||||
multi+=1
|
||||
p = (v_dist*multi) + ((y_margin_min) if not origin_at_zero else 0)
|
||||
y_chors.append(p as String)
|
||||
|
||||
# draw x_labels
|
||||
if not show_x_values_as_labels:
|
||||
to_order.clear()
|
||||
to_order = x_datas as PoolIntArray
|
||||
|
||||
to_order.sort()
|
||||
margin = to_order.pop_back()
|
||||
if not origin_at_zero:
|
||||
x_margin_min = to_order.pop_front()
|
||||
h_dist = x_decim * pow(10.0,str(margin).length()-2)
|
||||
multi = 0
|
||||
p = (h_dist*multi) + ((x_margin_min) if not origin_at_zero else 0)
|
||||
x_labels.append(p as String)
|
||||
while p < margin:
|
||||
multi+=1
|
||||
p = (h_dist*multi) + ((x_margin_min) if not origin_at_zero else 0)
|
||||
x_labels.append(p as String)
|
||||
|
||||
func set_legend(l : Array):
|
||||
legend = l
|
||||
legend = l
|
||||
|
||||
func get_legend():
|
||||
return legend
|
||||
return legend
|
||||
|
||||
func apply_template(template_name : String):
|
||||
template = template_name
|
||||
templates = ECUtilities._load_templates()
|
||||
if template_name!=null and template_name!="":
|
||||
var custom_template = templates[template.to_lower()]
|
||||
function_colors = custom_template.function_colors
|
||||
v_lines_color = Color(custom_template.v_lines_color)
|
||||
h_lines_color = Color(custom_template.h_lines_color)
|
||||
box_color = Color(custom_template.outline_color)
|
||||
font_color = Color(custom_template.font_color)
|
||||
property_list_changed_notify()
|
||||
template = template_name
|
||||
templates = ECUtilities._load_templates()
|
||||
if template_name!=null and template_name!="":
|
||||
var custom_template = templates[template.to_lower()]
|
||||
function_colors = custom_template.function_colors
|
||||
v_lines_color = Color(custom_template.v_lines_color)
|
||||
h_lines_color = Color(custom_template.h_lines_color)
|
||||
box_color = Color(custom_template.outline_color)
|
||||
font_color = Color(custom_template.font_color)
|
||||
property_list_changed_notify()
|
||||
|
||||
func _enter_tree():
|
||||
_ready()
|
||||
_ready()
|
||||
|
@ -76,7 +76,8 @@ export (String, FILE, "*.txt, *.csv, *.res") var source : String = "" setget set
|
||||
export (String) var delimiter : String = ";" setget set_delimiter
|
||||
|
||||
var origin_at_zero : bool = false setget set_origin_at_zero#, get_origin_at_zero
|
||||
var are_values_columns : bool = false setget set_are_values_columns#, get_are_values_columns
|
||||
var are_values_columns : bool = true setget set_are_values_columns#, get_are_values_columns
|
||||
|
||||
var show_x_values_as_labels : bool = false setget set_show_x_values_as_labels#, get_show_x_values_as_labels
|
||||
var labels_index : int = 0 setget set_labels_index#, get_labels_index
|
||||
var function_names_index : int = 0 setget set_function_names_index#, get_function_names_index
|
||||
@ -86,6 +87,8 @@ var use_height_as_radius : bool = false setget set_use_height_as_radius
|
||||
var radius : float = 150.0 setget _set_radius,get_radius
|
||||
|
||||
# for columns
|
||||
var function_line_width : int = 2
|
||||
|
||||
var column_width : float = 10 setget set_column_width
|
||||
var column_gap : float = 2 setget set_column_gap
|
||||
|
||||
@ -106,6 +109,8 @@ var font : Font setget set_font
|
||||
var bold_font : Font setget set_bold_font
|
||||
var font_color : Color = Color("#1e1e1e") setget set_font_color
|
||||
|
||||
var show_points := true
|
||||
|
||||
var use_template : bool = true setget set_use_template
|
||||
var template : int = 0 setget set_template
|
||||
|
||||
@ -133,6 +138,14 @@ var treshold_draw : Vector2
|
||||
var tic_length : int = 5 setget set_tic_length # Length of the bar indicating a tic
|
||||
var label_displacement : int = 4 setget set_label_displacement # Separation between the label and both the axis and the edge border
|
||||
|
||||
var property_list: Array = []
|
||||
|
||||
|
||||
|
||||
# ..........................................
|
||||
|
||||
|
||||
|
||||
# !! API v2
|
||||
static func instance(chart_type : int):
|
||||
var chart_t : String = ECUtilities.get_chart_type(chart_type)
|
||||
@ -160,6 +173,9 @@ func _get(property):
|
||||
return column_width
|
||||
"Chart_Properties/column_gap":
|
||||
return column_gap
|
||||
"Chart_Style/function_line_width":
|
||||
return function_line_width
|
||||
|
||||
|
||||
"Chart_Display/full_scale":
|
||||
return full_scale
|
||||
@ -233,6 +249,9 @@ func _set(property, value):
|
||||
"Chart_Properties/column_gap":
|
||||
column_gap = value
|
||||
return true
|
||||
"Chart_Style/function_line_width":
|
||||
function_line_width = value
|
||||
return true
|
||||
|
||||
"Chart_Display/full_scale":
|
||||
full_scale = value
|
||||
@ -299,6 +318,9 @@ func _set(property, value):
|
||||
invert_chart = value
|
||||
return true
|
||||
|
||||
func _init():
|
||||
build_property_list()
|
||||
|
||||
# .......................... Shared Functions and virtuals ........................
|
||||
|
||||
# Structure and Display a new plot if a dataset source is given
|
||||
@ -464,6 +486,10 @@ func clean_variables():
|
||||
y_labels.clear()
|
||||
|
||||
# .................. VIRTUAL FUNCTIONS .........................
|
||||
func build_property_list():
|
||||
pass
|
||||
|
||||
|
||||
func calculate_tics():
|
||||
pass
|
||||
|
||||
|
@ -15,13 +15,6 @@ var autoscale_x = true
|
||||
var autoscale_y = true
|
||||
|
||||
|
||||
var property_list: Array = []
|
||||
|
||||
|
||||
func _init():
|
||||
build_property_list()
|
||||
|
||||
|
||||
func build_property_list():
|
||||
property_list.clear()
|
||||
|
||||
@ -30,7 +23,7 @@ func build_property_list():
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_CATEGORY,
|
||||
"name": "ScatterChartBase",
|
||||
"name": get_name(),
|
||||
"type": TYPE_STRING
|
||||
})
|
||||
property_list.append(
|
||||
@ -117,6 +110,15 @@ func build_property_list():
|
||||
"name": "Chart_Display/y_decim",
|
||||
"type": TYPE_REAL
|
||||
})
|
||||
property_list.append(
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Display/show_points",
|
||||
"type": TYPE_BOOL
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
# Chart Style
|
||||
@ -233,6 +235,9 @@ func build_property_list():
|
||||
|
||||
func _set(property, value):
|
||||
match property:
|
||||
"Chart_Display/show_points":
|
||||
show_points = value
|
||||
return true
|
||||
"Chart_Display/autoscale_x":
|
||||
autoscale_x = value
|
||||
build_property_list()
|
||||
@ -259,6 +264,8 @@ func _set(property, value):
|
||||
|
||||
func _get(property):
|
||||
match property:
|
||||
"Chart_Display/show_points":
|
||||
return show_points
|
||||
"Chart_Display/autoscale_x":
|
||||
return autoscale_x
|
||||
"Chart_Display/autoscale_y":
|
||||
@ -428,7 +435,7 @@ func structure_data(database : Array):
|
||||
|
||||
y_datas.append(y_values)
|
||||
x_datas.append(x_values if not x_values.empty() else range(y_values.size()))
|
||||
|
||||
|
||||
for function in y_labels:
|
||||
y_domain[0].append(null)
|
||||
y_domain[1].append(null)
|
||||
@ -540,7 +547,7 @@ func calculate_coordinates():
|
||||
|
||||
for function in y_labels.size():
|
||||
for val in x_datas[function].size():
|
||||
var value_x = (x_datas[function][val] - x_margin_min) * x_pass / h_dist if h_dist else 0 \
|
||||
var value_x = (int(x_datas[function][val]) - x_margin_min) * x_pass / h_dist if h_dist else 0 \
|
||||
if not show_x_values_as_labels else x_chors.find(String(x_datas[function][val])) * x_pass
|
||||
var value_y = (y_datas[function][val] - y_margin_min) * y_pass / v_dist if v_dist else 0
|
||||
|
||||
@ -585,6 +592,8 @@ func draw_chart_outlines():
|
||||
func draw_points():
|
||||
for function in point_values.size():
|
||||
var PointContainer : Control = Control.new()
|
||||
PointContainer.name = "PointContainer"
|
||||
|
||||
Points.add_child(PointContainer)
|
||||
|
||||
for function_point in point_values[function].size():
|
||||
|
@ -1,5 +1,5 @@
|
||||
tool
|
||||
extends Chart
|
||||
extends ScatterChartBase
|
||||
class_name ColumnChart
|
||||
|
||||
"""
|
||||
@ -19,348 +19,65 @@ values of more than one measured variable.
|
||||
|
||||
# ---------------------
|
||||
|
||||
func _get_property_list():
|
||||
return [
|
||||
# Chart Properties
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_CATEGORY,
|
||||
"name": "ColumnChart",
|
||||
"type": TYPE_STRING
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/are_values_columns",
|
||||
"type": TYPE_BOOL
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "-1,100,1",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/labels_index",
|
||||
"type": TYPE_INT
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/show_x_values_as_labels",
|
||||
"type": TYPE_BOOL
|
||||
},
|
||||
{
|
||||
func build_property_list():
|
||||
.build_property_list()
|
||||
|
||||
property_list.append(
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "1,20,0.5",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/column_width",
|
||||
"type": TYPE_REAL
|
||||
},
|
||||
{
|
||||
})
|
||||
property_list.append(
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "0,10,0.5",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/column_gap",
|
||||
"type": TYPE_REAL
|
||||
},
|
||||
|
||||
# Chart Display
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "0.1,10",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Display/x_decim",
|
||||
"type": TYPE_REAL
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "0.001,1,0.001",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Display/y_decim",
|
||||
"type": TYPE_REAL
|
||||
},
|
||||
|
||||
# Chart Style
|
||||
{
|
||||
"hint": 24,
|
||||
"hint_string": "%d/%d:%s"%[TYPE_INT, PROPERTY_HINT_ENUM,
|
||||
PoolStringArray(Point.SHAPES.keys()).join(",")],
|
||||
"name": "Chart_Style/points_shape",
|
||||
"type": TYPE_ARRAY,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/function_colors",
|
||||
"type": TYPE_COLOR_ARRAY
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/box_color",
|
||||
"type": TYPE_COLOR
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/v_lines_color",
|
||||
"type": TYPE_COLOR
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/h_lines_color",
|
||||
"type": TYPE_COLOR
|
||||
},
|
||||
{
|
||||
"class_name": "Font",
|
||||
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||
"hint_string": "Font",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/font",
|
||||
"type": TYPE_OBJECT
|
||||
},
|
||||
{
|
||||
"class_name": "Font",
|
||||
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||
"hint_string": "Font",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/bold_font",
|
||||
"type": TYPE_OBJECT
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/font_color",
|
||||
"type": TYPE_COLOR
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/use_template",
|
||||
"type": TYPE_BOOL
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_ENUM,
|
||||
"hint_string": PoolStringArray(ECUtilities.templates.keys()).join(","),
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/template",
|
||||
"type": TYPE_INT
|
||||
},
|
||||
|
||||
# Chart Modifiers
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Modifiers/invert_chart",
|
||||
"type": TYPE_BOOL
|
||||
},
|
||||
]
|
||||
|
||||
func build_chart():
|
||||
SIZE = get_size()
|
||||
origin = Vector2(OFFSET.x,SIZE.y-OFFSET.y)
|
||||
|
||||
func structure_data(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 == 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)
|
||||
else:
|
||||
x_datas.append(x_data)
|
||||
else:
|
||||
if row != 0:
|
||||
var y_data = database[row][column]
|
||||
if y_data.is_valid_float() or y_data.is_valid_integer():
|
||||
t_vals.append(y_data as float)
|
||||
else:
|
||||
t_vals.append(y_data.replace(",", ".") as float)
|
||||
else:
|
||||
y_labels.append(str(database[row][column]))
|
||||
if not t_vals.empty():
|
||||
y_datas.append(t_vals)
|
||||
x_label = str(x_datas.pop_front())
|
||||
else:
|
||||
for row in database.size():
|
||||
if row == labels_index:
|
||||
x_datas = (database[row])
|
||||
x_label = x_datas.pop_front() as String
|
||||
else:
|
||||
var values = database[row] as Array
|
||||
y_labels.append(values.pop_front() as String)
|
||||
y_datas.append(values)
|
||||
for data in y_datas:
|
||||
for value in data.size():
|
||||
data[value] = data[value] as float
|
||||
|
||||
# draw y labels
|
||||
var to_order: Array
|
||||
var to_order_min: Array
|
||||
for cluster in y_datas.size():
|
||||
# define x_chors and y_chors
|
||||
var ordered_cluster = y_datas[cluster].duplicate() as Array
|
||||
ordered_cluster.sort()
|
||||
var margin_max = ordered_cluster[ordered_cluster.size() - 1]
|
||||
var margin_min = ordered_cluster[0]
|
||||
to_order.append(margin_max)
|
||||
to_order_min.append(margin_min)
|
||||
|
||||
to_order.sort()
|
||||
to_order_min.sort()
|
||||
var margin = to_order.pop_back()
|
||||
if not origin_at_zero:
|
||||
y_margin_min = to_order_min.pop_front()
|
||||
v_dist = y_decim * pow(10.0, str(margin).length()-1) #* pow(10.0, (str(margin).length() - 2 if typeof(margin) == TYPE_INT else str(margin).length() - str(y_decim).length() ))
|
||||
var multi = 0
|
||||
var p = (v_dist * multi) + ((y_margin_min) if not origin_at_zero else 0)
|
||||
y_chors.append(p as String)
|
||||
while p < margin:
|
||||
multi += 1
|
||||
p = (v_dist * multi) + ((y_margin_min) if not origin_at_zero else 0)
|
||||
y_chors.append(p as String)
|
||||
|
||||
# draw x_labels
|
||||
if not show_x_values_as_labels:
|
||||
to_order.clear()
|
||||
to_order = x_datas.duplicate() as PoolIntArray
|
||||
to_order.sort()
|
||||
margin = to_order.pop_back()
|
||||
if not origin_at_zero:
|
||||
x_margin_min = to_order.pop_front()
|
||||
h_dist = x_decim * pow(10.0, str(margin).length() - 2)
|
||||
multi = 0
|
||||
p = (h_dist * multi) + ((x_margin_min) if not origin_at_zero else 0)
|
||||
x_labels.append(p as String)
|
||||
while p < margin:
|
||||
multi += 1
|
||||
p = (h_dist * multi) + ((x_margin_min) if not origin_at_zero else 0)
|
||||
x_labels.append(p as String)
|
||||
|
||||
OFFSET.x = (str(margin).length()) * font_size
|
||||
OFFSET.y = font_size * 2
|
||||
})
|
||||
|
||||
|
||||
func calculate_pass():
|
||||
if show_x_values_as_labels:
|
||||
x_chors = x_datas as PoolStringArray
|
||||
else:
|
||||
x_chors = x_labels
|
||||
|
||||
# calculate distance in pixel between 2 consecutive values/datas
|
||||
if not are_values_columns:
|
||||
x_pass = (SIZE.x - OFFSET.x*2 - (column_width) * ( y_datas.size()) - column_gap - column_width/2) / ((x_chors.size()-1) if x_chors.size()!=1 else 1)
|
||||
else:
|
||||
x_pass = (SIZE.x - OFFSET.x*2 - (column_width) * ( y_datas[0].size()+1 ) - column_gap - column_width/2) / (x_chors.size()-1)
|
||||
y_pass = (origin.y - ChartName.get_rect().size.y*2) / (y_chors.size() - 1)
|
||||
func _get_property_list():
|
||||
property_list[0].name = "ColumnChart"
|
||||
return property_list
|
||||
|
||||
|
||||
func calculate_coordinates():
|
||||
x_coordinates.clear()
|
||||
y_coordinates.clear()
|
||||
point_values.clear()
|
||||
point_positions.clear()
|
||||
|
||||
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:
|
||||
for x in x_datas.size():
|
||||
x_coordinates.append(x_pass*x)
|
||||
else:
|
||||
for x in x_datas.size():
|
||||
if origin_at_zero:
|
||||
x_coordinates.append(x_pass*x)
|
||||
else:
|
||||
x_coordinates.append((x_datas[x] - x_margin_min)*x_pass/h_dist)
|
||||
|
||||
for f in functions:
|
||||
for _i in y_labels.size():
|
||||
point_values.append([])
|
||||
point_positions.append([])
|
||||
|
||||
for cluster in y_coordinates.size():
|
||||
for y in y_coordinates[cluster].size():
|
||||
if are_values_columns:
|
||||
point_positions[y].append(Vector2(OFFSET.x/2 + column_width/2 + (column_width + column_gap)*y + x_coordinates[cluster] + origin.x, origin.y-y_coordinates[cluster][y]))
|
||||
point_values[y].append([x_datas[cluster],y_datas[cluster][y]])
|
||||
else:
|
||||
point_values[cluster].append([x_datas[y],y_datas[cluster][y]])
|
||||
point_positions[cluster].append(Vector2(OFFSET.x/2 + column_width/2 + (column_width + column_gap)*cluster + x_coordinates[y]+origin.x,origin.y-y_coordinates[cluster][y]))
|
||||
for function in y_labels.size():
|
||||
for val in x_datas[function].size():
|
||||
var value_x: float = (int(x_datas[function][val]) - x_margin_min) * x_pass / h_dist if h_dist else 0 \
|
||||
if not show_x_values_as_labels else x_chors.find(String(x_datas[function][val])) * x_pass
|
||||
var value_y: float = (y_datas[function][val] - y_margin_min) * y_pass / v_dist if v_dist else 0
|
||||
var column_offset: float = column_width/2 + (column_width + column_gap)*function - (column_width + column_gap)*functions/2
|
||||
point_values[function].append([x_datas[function][val], y_datas[function][val]])
|
||||
point_positions[function].append(Vector2(value_x + origin.x + column_offset, origin.y - value_y))
|
||||
|
||||
func _draw():
|
||||
clean_points()
|
||||
|
||||
draw_grid()
|
||||
draw_chart_outlines()
|
||||
|
||||
var defined_colors : bool = false
|
||||
if function_colors.size():
|
||||
defined_colors = true
|
||||
|
||||
for _function in point_values.size():
|
||||
var PointContainer : Control = Control.new()
|
||||
Points.add_child(PointContainer)
|
||||
|
||||
for function_point in point_values[_function].size():
|
||||
var point : Point = point_node.instance()
|
||||
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],
|
||||
Color.white, point_positions[_function][function_point] + Vector2(0,7),
|
||||
point.format_value(point_values[_function][function_point], false, false),
|
||||
y_labels[_function] as String)
|
||||
PointContainer.add_child(point)
|
||||
point.rect_size.y = origin.y - point_positions[_function][function_point].y
|
||||
draw_line( Vector2(point_positions[_function][function_point].x, origin.y),
|
||||
point_positions[_function][function_point], function_colors[_function], column_width, true)
|
||||
# draw_string(font, Vector2(point_positions[_function][function_point].x, origin.y+10), y_labels[function_point], font_color)
|
||||
if show_points:
|
||||
draw_points()
|
||||
draw_columns()
|
||||
draw_treshold()
|
||||
|
||||
func draw_grid():
|
||||
# ascisse
|
||||
for p in x_chors.size():
|
||||
var point : Vector2 = origin+Vector2((p)*x_pass,0)
|
||||
# v grid
|
||||
draw_line(point,point-Vector2(0,SIZE.y-OFFSET.y),v_lines_color,0.2,true)
|
||||
# ascisse
|
||||
draw_line(point-Vector2(0,5),point,v_lines_color,1,true)
|
||||
var calculated_gap : float
|
||||
if not are_values_columns:
|
||||
calculated_gap = ( y_datas.size() )
|
||||
else:
|
||||
calculated_gap = ( y_datas[0].size()+1 )
|
||||
draw_string(
|
||||
font,
|
||||
point + Vector2(-const_width/2*x_chors[p].length() + (column_width + column_gap) * functions, font_size),
|
||||
x_chors[p],
|
||||
font_color)
|
||||
func draw_columns():
|
||||
for function in point_values.size():
|
||||
for function_point in range(0, point_values[function].size()):
|
||||
draw_line(
|
||||
Vector2(point_positions[function][function_point].x, origin.y),
|
||||
point_positions[function][function_point],
|
||||
function_colors[function],
|
||||
column_width,
|
||||
false)
|
||||
# draw_string(font, Vector2(point_positions[function][function_point].x, origin.y+10), y_labels[function_point], font_color)
|
||||
|
||||
# ordinate
|
||||
for p in y_chors.size():
|
||||
var point : Vector2 = origin-Vector2(0,(p)*y_pass)
|
||||
# h grid
|
||||
draw_line(point,point+Vector2(SIZE.x-OFFSET.x,0),h_lines_color,0.2,true)
|
||||
# ordinate
|
||||
draw_line(point,point+Vector2(5,0),h_lines_color,1,true)
|
||||
draw_string(
|
||||
font,
|
||||
point - Vector2(y_chors[p].length() * const_width + font_size, -const_height),
|
||||
y_chors[p],
|
||||
font_color)
|
||||
|
||||
func draw_chart_outlines():
|
||||
# if boxed:
|
||||
draw_line(Vector2(origin.x,0),Vector2(SIZE.x,0),box_color,1,true)
|
||||
draw_line(Vector2(SIZE.x,0),Vector2(SIZE.x,origin.y),box_color,1,true)
|
||||
draw_line(Vector2(SIZE.x,origin.y),origin,box_color,1,true)
|
||||
draw_line(origin,Vector2(origin.x,0),box_color,1,true)
|
||||
|
@ -1,14 +1,7 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
<<<<<<<< HEAD:addons/easy_charts/ControlChart/ColumnChart/column_chart.tscn
|
||||
[ext_resource path="res://addons/easy_charts/Utilities/Point/point_data.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/easy_charts/ControlChart/ColumnChart/column_chart.gd" type="Script" id=2]
|
||||
|
||||
|
||||
========
|
||||
[ext_resource path="res://addons/easy_charts/utilities/containers/data_tooltip/data_tooltip.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/easy_charts/control_charts/ColumnChart/column_chart.gd" type="Script" id=2]
|
||||
>>>>>>>> dev:addons/easy_charts/control_charts/ColumnChart/column_chart.tscn
|
||||
|
||||
[sub_resource type="Theme" id=1]
|
||||
|
||||
@ -34,14 +27,16 @@ values of more than one measured variable."
|
||||
}
|
||||
Chart_Properties/are_values_columns = false
|
||||
Chart_Properties/labels_index = 0
|
||||
Chart_Properties/show_x_values_as_labels = true
|
||||
Chart_Properties/column_width = 2.0
|
||||
Chart_Properties/column_gap = 2.0
|
||||
Chart_Display/x_decim = 5.0
|
||||
Chart_Properties/show_x_values_as_labels = false
|
||||
Chart_Display/autoscale_x = true
|
||||
Chart_Display/x_decim = 1.0
|
||||
Chart_Display/autoscale_y = true
|
||||
Chart_Display/y_decim = 1.0
|
||||
Chart_Display/show_points = true
|
||||
Chart_Style/points_shape = [ 0 ]
|
||||
Chart_Style/function_colors = PoolColorArray( 0.117647, 0.117647, 0.117647, 1, 0.117647, 0.117647, 0.117647, 1, 0.117647, 0.117647, 0.117647, 1, 0.117647, 0.117647, 0.117647, 1 )
|
||||
Chart_Style/box_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||
Chart_Style/grid_lines_width = 1
|
||||
Chart_Style/v_lines_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||
Chart_Style/h_lines_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||
Chart_Style/font = null
|
||||
@ -49,7 +44,11 @@ Chart_Style/bold_font = null
|
||||
Chart_Style/font_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||
Chart_Style/use_template = true
|
||||
Chart_Style/template = 0
|
||||
Chart_Modifiers/treshold = Vector2( 0, 0 )
|
||||
Chart_Modifiers/only_disp_values = Vector2( 0, 0 )
|
||||
Chart_Modifiers/invert_chart = false
|
||||
Chart_Properties/column_width = 10.0
|
||||
Chart_Properties/column_gap = 2.0
|
||||
|
||||
[node name="Background" type="ColorRect" parent="."]
|
||||
visible = false
|
||||
@ -89,10 +88,11 @@ __meta__ = {
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="DataTooltip" parent="CanvasLayer" instance=ExtResource( 1 )]
|
||||
margin_left = -455.833
|
||||
margin_top = 690.354
|
||||
margin_right = -455.969
|
||||
margin_bottom = 691.154
|
||||
margin_left = -52.7918
|
||||
margin_top = -28.9529
|
||||
margin_right = -52.9281
|
||||
margin_bottom = -28.1529
|
||||
|
||||
|
||||
[node name="PointData" parent="CanvasLayer/DataTooltip" index="0"]
|
||||
margin_left = -593.381
|
||||
|
@ -14,21 +14,9 @@ class_name LineChart
|
||||
# In these cases they are known as run charts.
|
||||
# Source: Wikipedia
|
||||
|
||||
var show_points := true
|
||||
var function_line_width : int = 2
|
||||
|
||||
|
||||
func build_property_list():
|
||||
.build_property_list()
|
||||
|
||||
property_list.append(
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Display/show_points",
|
||||
"type": TYPE_BOOL
|
||||
})
|
||||
|
||||
#Find first element of Chart Display
|
||||
var position
|
||||
for i in property_list.size():
|
||||
@ -51,24 +39,6 @@ func _get_property_list():
|
||||
return property_list
|
||||
|
||||
|
||||
func _get(property):
|
||||
match property:
|
||||
"Chart_Display/show_points":
|
||||
return show_points
|
||||
"Chart_Style/function_line_width":
|
||||
return function_line_width
|
||||
|
||||
|
||||
func _set(property, value):
|
||||
match property:
|
||||
"Chart_Display/show_points":
|
||||
show_points = value
|
||||
return true
|
||||
"Chart_Style/function_line_width":
|
||||
function_line_width = value
|
||||
return true
|
||||
|
||||
|
||||
func _draw():
|
||||
draw_grid()
|
||||
draw_chart_outlines()
|
||||
|
@ -9,174 +9,174 @@ var areas : Array
|
||||
var areas_interacted : Array
|
||||
|
||||
class CustomSorter:
|
||||
static func sort_ascending(a,b):
|
||||
if a[1] < b[1]:
|
||||
return true
|
||||
return false
|
||||
static func sort_ascending(a,b):
|
||||
if a[1] < b[1]:
|
||||
return true
|
||||
return false
|
||||
|
||||
func _get_property_list():
|
||||
return [
|
||||
# Chart Properties
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/are_values_columns",
|
||||
"type": TYPE_BOOL
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "-1,100,1",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/labels_index",
|
||||
"type": TYPE_INT
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/show_x_values_as_labels",
|
||||
"type": TYPE_BOOL
|
||||
},
|
||||
return [
|
||||
# Chart Properties
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/are_values_columns",
|
||||
"type": TYPE_BOOL
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "-1,100,1",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/labels_index",
|
||||
"type": TYPE_INT
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/show_x_values_as_labels",
|
||||
"type": TYPE_BOOL
|
||||
},
|
||||
|
||||
# Chart Style
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/function_colors",
|
||||
"type": TYPE_COLOR_ARRAY
|
||||
},
|
||||
{
|
||||
"class_name": "Font",
|
||||
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||
"hint_string": "Font",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/font",
|
||||
"type": TYPE_OBJECT
|
||||
},
|
||||
{
|
||||
"class_name": "Font",
|
||||
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||
"hint_string": "Font",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/bold_font",
|
||||
"type": TYPE_OBJECT
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/font_color",
|
||||
"type": TYPE_COLOR
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_ENUM,
|
||||
"hint_string": PoolStringArray(ECUtilities.templates.keys()).join(","),
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/template",
|
||||
"type": TYPE_INT
|
||||
},
|
||||
# Chart Style
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/function_colors",
|
||||
"type": TYPE_COLOR_ARRAY
|
||||
},
|
||||
{
|
||||
"class_name": "Font",
|
||||
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||
"hint_string": "Font",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/font",
|
||||
"type": TYPE_OBJECT
|
||||
},
|
||||
{
|
||||
"class_name": "Font",
|
||||
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||
"hint_string": "Font",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/bold_font",
|
||||
"type": TYPE_OBJECT
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/font_color",
|
||||
"type": TYPE_COLOR
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_ENUM,
|
||||
"hint_string": PoolStringArray(ECUtilities.templates.keys()).join(","),
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/template",
|
||||
"type": TYPE_INT
|
||||
},
|
||||
|
||||
# Chart Modifiers
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "0,360",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Modifiers/rotation",
|
||||
"type": TYPE_REAL
|
||||
},
|
||||
]
|
||||
# Chart Modifiers
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "0,360",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Modifiers/rotation",
|
||||
"type": TYPE_REAL
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass
|
||||
pass
|
||||
|
||||
func plot_placeholder() -> void:
|
||||
data = [
|
||||
["United States",46],
|
||||
["Great Britain",27],
|
||||
["China",26],
|
||||
["Russia",19],
|
||||
["Germany",17]
|
||||
]
|
||||
|
||||
function_colors = [
|
||||
Color.red,
|
||||
Color.white,
|
||||
Color.yellow,
|
||||
Color.green,
|
||||
Color.blue
|
||||
]
|
||||
plot_from_array(data)
|
||||
data = [
|
||||
["United States",46],
|
||||
["Great Britain",27],
|
||||
["China",26],
|
||||
["Russia",19],
|
||||
["Germany",17]
|
||||
]
|
||||
|
||||
function_colors = [
|
||||
Color.red,
|
||||
Color.white,
|
||||
Color.yellow,
|
||||
Color.green,
|
||||
Color.blue
|
||||
]
|
||||
plot(data)
|
||||
|
||||
func structure_data(database: Array):
|
||||
# @labels_index can be either a column or a row relative to x values
|
||||
clean_variables()
|
||||
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 == 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)
|
||||
else:
|
||||
x_datas.append(x_data.replace(",", ".") as float)
|
||||
else:
|
||||
if row != 0:
|
||||
var y_data = database[row][column]
|
||||
if y_data.is_valid_float() or y_data.is_valid_integer():
|
||||
t_vals.append(y_data as float)
|
||||
else:
|
||||
t_vals.append(y_data.replace(",", ".") as float)
|
||||
else:
|
||||
y_labels.append(str(database[row][column]))
|
||||
if not t_vals.empty():
|
||||
y_datas.append(t_vals)
|
||||
x_label = str(x_datas.pop_front())
|
||||
else:
|
||||
for row in database.size():
|
||||
if row == labels_index:
|
||||
x_datas = (database[row])
|
||||
x_label = x_datas.pop_front() as String
|
||||
else:
|
||||
var values = database[row] as Array
|
||||
y_labels.append(values.pop_front() as String)
|
||||
y_datas.append(values)
|
||||
for data in y_datas:
|
||||
for value in data.size():
|
||||
data[value] = data[value] as float
|
||||
# @labels_index can be either a column or a row relative to x values
|
||||
clean_variables()
|
||||
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 == 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)
|
||||
else:
|
||||
x_datas.append(x_data.replace(",", ".") as float)
|
||||
else:
|
||||
if row != 0:
|
||||
var y_data = database[row][column]
|
||||
if y_data.is_valid_float() or y_data.is_valid_integer():
|
||||
t_vals.append(y_data as float)
|
||||
else:
|
||||
t_vals.append(y_data.replace(",", ".") as float)
|
||||
else:
|
||||
y_labels.append(str(database[row][column]))
|
||||
if not t_vals.empty():
|
||||
y_datas.append(t_vals)
|
||||
x_label = str(x_datas.pop_front())
|
||||
else:
|
||||
for row in database.size():
|
||||
if row == labels_index:
|
||||
x_datas = (database[row])
|
||||
x_label = x_datas.pop_front() as String
|
||||
else:
|
||||
var values = database[row] as Array
|
||||
y_labels.append(values.pop_front() as String)
|
||||
y_datas.append(values)
|
||||
for data in y_datas:
|
||||
for value in data.size():
|
||||
data[value] = data[value] as float
|
||||
|
||||
|
||||
func build_chart():
|
||||
SIZE = get_size()
|
||||
origin = SIZE/2
|
||||
radius = (SIZE.y/2 - 20) if SIZE.y < SIZE.x else (SIZE.x/2 - 20)
|
||||
SIZE = get_size()
|
||||
origin = SIZE/2
|
||||
radius = (SIZE.y/2 - 20) if SIZE.y < SIZE.x else (SIZE.x/2 - 20)
|
||||
|
||||
func calculate_pass():
|
||||
var tot : float
|
||||
for y_data in y_datas: tot+=y_data[0]
|
||||
x_pass = 360/tot
|
||||
var tot : float
|
||||
for y_data in y_datas: tot+=y_data[0]
|
||||
x_pass = 360/tot
|
||||
|
||||
func calculate_coordinates():
|
||||
area_angles.clear()
|
||||
slices.clear()
|
||||
areas.clear()
|
||||
var from : float = 0.0
|
||||
var to : float = y_datas[0][0]*x_pass
|
||||
area_angles.append([from,to])
|
||||
for info in range(y_datas.size()):
|
||||
slices.append(Slice.new(y_labels[info], str(y_datas[info][0]), from, to, x_label+" : "+x_datas[0], function_colors[info]))
|
||||
areas.append(calculate_circle_arc_polygon(origin, radius, from + rotation, to + rotation, function_colors[info]))
|
||||
from = to
|
||||
to = (y_datas[info+1][0]*x_pass + from) if info < y_datas.size()-1 else (360)
|
||||
area_angles.append([from, to])
|
||||
|
||||
create_legend()
|
||||
area_angles.clear()
|
||||
slices.clear()
|
||||
areas.clear()
|
||||
var from : float = 0.0
|
||||
var to : float = y_datas[0][0]*x_pass
|
||||
area_angles.append([from,to])
|
||||
for info in range(y_datas.size()):
|
||||
slices.append(Slice.new(y_labels[info], str(y_datas[info][0]), from, to, x_label+" : "+x_datas[0], function_colors[info]))
|
||||
areas.append(calculate_circle_arc_polygon(origin, radius, from + rotation, to + rotation, function_colors[info]))
|
||||
from = to
|
||||
to = (y_datas[info+1][0]*x_pass + from) if info < y_datas.size()-1 else (360)
|
||||
area_angles.append([from, to])
|
||||
|
||||
create_legend()
|
||||
|
||||
func calculate_circle_arc_polygon(center : Vector2, radius : float, angle_from : float, angle_to : float, color : Color) -> PoolVector2Array:
|
||||
var nb_points : int = 32
|
||||
var points_arc : PoolVector2Array = PoolVector2Array()
|
||||
var nb_points : int = 32
|
||||
var points_arc : PoolVector2Array = PoolVector2Array()
|
||||
# var chord_angle : float = ((angle_to - angle_from)/2)+angle_from
|
||||
# angle_from += 0.2
|
||||
# angle_to -= 0.2
|
||||
@ -184,43 +184,43 @@ func calculate_circle_arc_polygon(center : Vector2, radius : float, angle_from :
|
||||
# print(displacement)
|
||||
# center += displacement
|
||||
# radius+=displacement.length()
|
||||
points_arc.push_back(center)
|
||||
var colors : PoolColorArray = PoolColorArray([color])
|
||||
for i in range(nb_points + 1):
|
||||
var angle_point = deg2rad(angle_from + i * (angle_to - angle_from) / nb_points - 90)
|
||||
points_arc.push_back(center + Vector2(cos(angle_point), sin(angle_point)) * radius)
|
||||
return points_arc
|
||||
points_arc.push_back(center)
|
||||
var colors : PoolColorArray = PoolColorArray([color])
|
||||
for i in range(nb_points + 1):
|
||||
var angle_point = deg2rad(angle_from + i * (angle_to - angle_from) / nb_points - 90)
|
||||
points_arc.push_back(center + Vector2(cos(angle_point), sin(angle_point)) * radius)
|
||||
return points_arc
|
||||
|
||||
func _draw():
|
||||
_draw_areas()
|
||||
|
||||
if mouse_on_slice:
|
||||
_draw_arc(area_angles[mouse_on_area], mouse_on_area)
|
||||
mouse_on_slice = false
|
||||
_draw_areas()
|
||||
|
||||
if mouse_on_slice:
|
||||
_draw_arc(area_angles[mouse_on_area], mouse_on_area)
|
||||
mouse_on_slice = false
|
||||
|
||||
func _draw_arc(arc : Array, index : int):
|
||||
var temp_color : Color = function_colors[index]
|
||||
temp_color.a = 0.7
|
||||
draw_arc(origin, radius + 6, deg2rad(arc[0]-90 + rotation), deg2rad(arc[1]-90 + rotation), 32, temp_color, 4)
|
||||
var temp_color : Color = function_colors[index]
|
||||
temp_color.a = 0.7
|
||||
draw_arc(origin, radius + 6, deg2rad(arc[0]-90 + rotation), deg2rad(arc[1]-90 + rotation), 32, temp_color, 4)
|
||||
|
||||
func _draw_areas():
|
||||
for area_idx in range(areas.size()):
|
||||
draw_polygon(areas[area_idx], [function_colors[area_idx]])
|
||||
for area_idx in range(areas.size()):
|
||||
draw_polygon(areas[area_idx], [function_colors[area_idx]])
|
||||
|
||||
var mouse_on_area : int
|
||||
var mouse_on_slice : bool = false
|
||||
|
||||
func _gui_input(event : InputEvent):
|
||||
if event is InputEventMouseMotion:
|
||||
for area_idx in range(areas.size()):
|
||||
if Geometry.is_point_in_polygon(event.global_position - get_global_transform().origin, areas[area_idx]):
|
||||
mouse_on_slice = true
|
||||
mouse_on_area = area_idx
|
||||
show_slice_data(slices[area_idx])
|
||||
update()
|
||||
|
||||
if not mouse_on_slice:
|
||||
mouse_on_area = -1
|
||||
mouse_on_slice = false
|
||||
hide_data()
|
||||
update()
|
||||
if event is InputEventMouseMotion:
|
||||
for area_idx in range(areas.size()):
|
||||
if Geometry.is_point_in_polygon(event.global_position - get_global_transform().origin, areas[area_idx]):
|
||||
mouse_on_slice = true
|
||||
mouse_on_area = area_idx
|
||||
show_slice_data(slices[area_idx])
|
||||
update()
|
||||
|
||||
if not mouse_on_slice:
|
||||
mouse_on_area = -1
|
||||
mouse_on_slice = false
|
||||
hide_data()
|
||||
update()
|
||||
|
@ -1,10 +1,6 @@
|
||||
Year;Column 1;Column 2;Column 3;Column 4
|
||||
2009;36200;27200;26200;17200
|
||||
2010;36600;27800;26600;17800
|
||||
2011;37500;28500;27500;18500
|
||||
2012;38700;29400;28700;19400
|
||||
2013;39600;30200;29600;10200
|
||||
2014;40500;30900;20500;10900
|
||||
2015;41200;31500;21200;11500
|
||||
2016;41803;31931;21803;11931
|
||||
2017;42600;32600;22600;12600
|
||||
Year;2009;2010;2011;2012;2013;2014;2015;2016;2017
|
||||
Column 1;36200;36600;37500;38700;39600;40500;41200;41803;42600
|
||||
Column 2;27200;27800;28500;29400;30200;30900;31500;31931;32600
|
||||
Column 3;26200;26600;27500;28700;29600;20500;21200;21803;22600
|
||||
Column 4;17200;17800;18500;19400;10200;10900;11500;11931;12600
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user