mirror of
https://github.com/Relintai/pandemonium_engine_easy_charts.git
synced 2025-01-02 14:29:45 +01:00
Add files via upload
This commit is contained in:
parent
6605f4cf1c
commit
3397384582
397
addons/easy_charts/BarChart/BarChart.gd
Normal file
397
addons/easy_charts/BarChart/BarChart.gd
Normal file
@ -0,0 +1,397 @@
|
|||||||
|
tool
|
||||||
|
extends Control
|
||||||
|
|
||||||
|
onready var PointData = $PointData/PointData
|
||||||
|
onready var Points = $Points
|
||||||
|
onready var Legend = $Legend
|
||||||
|
|
||||||
|
var point_node : PackedScene = preload("../Utilities/Point/Point.tscn")
|
||||||
|
var FunctionLegend : PackedScene = preload("../Utilities/Legend/FunctionLegend.tscn")
|
||||||
|
|
||||||
|
var font_size : float = 16
|
||||||
|
var const_height : float = font_size/2*font_size/20
|
||||||
|
var const_width : float = font_size/2
|
||||||
|
|
||||||
|
var source : String
|
||||||
|
var delimiter : String
|
||||||
|
|
||||||
|
var OFFSET : Vector2 = Vector2(50,30)
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------#
|
||||||
|
var origin : Vector2
|
||||||
|
|
||||||
|
# actual distance between x and y values
|
||||||
|
var x_pass : float
|
||||||
|
var y_pass : float
|
||||||
|
|
||||||
|
# vertical distance between y consecutive points used for intervals
|
||||||
|
var v_dist : float
|
||||||
|
|
||||||
|
# quantization, representing the interval in which values will be displayed
|
||||||
|
var x_decim : float = 1.0
|
||||||
|
export (float) var y_decim : float = 5.0
|
||||||
|
|
||||||
|
# define values on x an y axis
|
||||||
|
var x_chors : Array
|
||||||
|
var y_chors : Array
|
||||||
|
|
||||||
|
# actual coordinates of points (in pixel)
|
||||||
|
var x_coordinates : Array
|
||||||
|
var y_coordinates : Array
|
||||||
|
|
||||||
|
# datas contained in file
|
||||||
|
var datas : Array
|
||||||
|
|
||||||
|
# amount of functions to represent
|
||||||
|
var functions : int = 0
|
||||||
|
|
||||||
|
|
||||||
|
# database values
|
||||||
|
var x_datas : Array
|
||||||
|
var y_datas : Array
|
||||||
|
|
||||||
|
# labels displayed on chart
|
||||||
|
var x_label : String
|
||||||
|
var y_labels : Array
|
||||||
|
|
||||||
|
# actual values of point, from the database
|
||||||
|
var point_values : Array
|
||||||
|
|
||||||
|
# actual position of points in pixel
|
||||||
|
var point_positions : Array
|
||||||
|
|
||||||
|
var legend : Array setget set_legend,get_legend
|
||||||
|
var are_values_columns : bool
|
||||||
|
|
||||||
|
# ---------------------
|
||||||
|
export (bool) var invert_xy : bool
|
||||||
|
var SIZE : Vector2 = Vector2()
|
||||||
|
export (PoolColorArray) var function_colors = [Color("#1e1e1e")]
|
||||||
|
export (Color) var v_lines_color : Color = Color("#cacaca")
|
||||||
|
export (Color) var h_lines_color : Color = Color("#cacaca")
|
||||||
|
export (Color) var outline_color : Color = Color("#1e1e1e")
|
||||||
|
export (Font) var font : Font
|
||||||
|
export (Font) var bold_font : Font
|
||||||
|
export (Color) var font_color : Color = Color("#1e1e1e")
|
||||||
|
export (String,"Default","Clean","Minimal","Invert") var template : String = "Default" setget apply_template
|
||||||
|
|
||||||
|
signal linechart_plotted()
|
||||||
|
|
||||||
|
#func _ready():
|
||||||
|
# plot_line_chart("res://ChartNode/datas.csv",";",true,0)
|
||||||
|
|
||||||
|
func plot_line_chart(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_values_ : int, invert_xy_ : bool = false):
|
||||||
|
randomize()
|
||||||
|
|
||||||
|
load_font()
|
||||||
|
PointData.hide()
|
||||||
|
|
||||||
|
datas = read_datas(source_,delimiter_)
|
||||||
|
count_functions()
|
||||||
|
structure_datas(datas,are_values_columns_,x_values_)
|
||||||
|
build_chart()
|
||||||
|
calculate_pass()
|
||||||
|
calculate_coordinates()
|
||||||
|
calculate_colors()
|
||||||
|
create_legend()
|
||||||
|
emit_signal("linechart_plotted")
|
||||||
|
|
||||||
|
func calculate_colors():
|
||||||
|
if function_colors.empty() or function_colors.size() < functions:
|
||||||
|
for function in functions:
|
||||||
|
function_colors.append(Color("#1e1e1e"))
|
||||||
|
|
||||||
|
func load_font():
|
||||||
|
if font != null:
|
||||||
|
font_size = font.get_height()
|
||||||
|
var theme : Theme = Theme.new()
|
||||||
|
theme.set_default_font(font)
|
||||||
|
PointData.set_theme(theme)
|
||||||
|
else:
|
||||||
|
var lbl = Label.new()
|
||||||
|
font = lbl.get_font("")
|
||||||
|
lbl.free()
|
||||||
|
if bold_font != null:
|
||||||
|
PointData.Data.set("custom_fonts/font",bold_font)
|
||||||
|
|
||||||
|
func read_datas(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
|
||||||
|
|
||||||
|
func structure_datas(database : Array, are_values_columns : bool, x_values : int):
|
||||||
|
# @x_values 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:
|
||||||
|
x_datas.append(database[row][column])
|
||||||
|
else:
|
||||||
|
if row != 0:
|
||||||
|
t_vals.append(float(database[row][column]))
|
||||||
|
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())
|
||||||
|
false:
|
||||||
|
for row in database.size():
|
||||||
|
if row == x_values:
|
||||||
|
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
|
||||||
|
|
||||||
|
var to_order : Array
|
||||||
|
for cluster in y_datas.size():
|
||||||
|
# define x_chors and y_chors
|
||||||
|
var margin = y_datas[cluster][y_datas[cluster].size()-1]
|
||||||
|
to_order.append(margin)
|
||||||
|
|
||||||
|
to_order.sort()
|
||||||
|
var margin = to_order.pop_back()
|
||||||
|
v_dist = y_decim * pow(10.0,str(margin).length()-2)
|
||||||
|
var multi = 0
|
||||||
|
var p = v_dist*multi
|
||||||
|
y_chors.append(p as String)
|
||||||
|
while p < margin:
|
||||||
|
multi+=1
|
||||||
|
p = v_dist*multi
|
||||||
|
y_chors.append(p as String)
|
||||||
|
|
||||||
|
func build_chart():
|
||||||
|
SIZE = get_parent().get_size()
|
||||||
|
origin = Vector2(OFFSET.x,SIZE.y-OFFSET.y)
|
||||||
|
|
||||||
|
func calculate_pass():
|
||||||
|
if invert_xy:
|
||||||
|
x_chors = y_labels as PoolStringArray
|
||||||
|
else:
|
||||||
|
x_chors = x_datas as PoolStringArray
|
||||||
|
# calculate distance in pixel between 2 consecutive values/datas
|
||||||
|
x_pass = (SIZE.x - OFFSET.x) / (x_chors.size()-1)
|
||||||
|
y_pass = origin.y / (y_chors.size()-1)
|
||||||
|
|
||||||
|
func calculate_coordinates():
|
||||||
|
x_coordinates.clear()
|
||||||
|
y_coordinates.clear()
|
||||||
|
point_values.clear()
|
||||||
|
point_positions.clear()
|
||||||
|
|
||||||
|
if invert_xy:
|
||||||
|
for column in y_datas[0].size():
|
||||||
|
var single_coordinates : Array
|
||||||
|
for row in y_datas:
|
||||||
|
single_coordinates.append((row[column]*y_pass)/v_dist)
|
||||||
|
y_coordinates.append(single_coordinates)
|
||||||
|
else:
|
||||||
|
for cluster in y_datas:
|
||||||
|
var single_coordinates : Array
|
||||||
|
for value in cluster.size():
|
||||||
|
single_coordinates.append((cluster[value]*y_pass)/v_dist)
|
||||||
|
y_coordinates.append(single_coordinates)
|
||||||
|
|
||||||
|
for x in x_chors.size():
|
||||||
|
x_coordinates.append(x_pass*x)
|
||||||
|
|
||||||
|
for f in functions:
|
||||||
|
point_values.append([])
|
||||||
|
point_positions.append([])
|
||||||
|
|
||||||
|
if invert_xy:
|
||||||
|
for function in y_coordinates.size()-1:
|
||||||
|
for function_value in y_coordinates[function].size():
|
||||||
|
point_positions[function].append(Vector2(x_coordinates[function_value]+origin.x,origin.y-y_coordinates[function][function_value]))
|
||||||
|
point_values[function].append([x_chors[function_value],y_datas[function_value][function]])
|
||||||
|
else:
|
||||||
|
for cluster in y_coordinates.size():
|
||||||
|
for y in y_coordinates[cluster].size():
|
||||||
|
point_values[cluster].append([x_chors[y],y_datas[cluster][y]])
|
||||||
|
point_positions[cluster].append(Vector2(x_coordinates[y]+origin.x,origin.y-y_coordinates[cluster][y]))
|
||||||
|
|
||||||
|
func redraw():
|
||||||
|
build_chart()
|
||||||
|
calculate_pass()
|
||||||
|
calculate_coordinates()
|
||||||
|
update()
|
||||||
|
|
||||||
|
func _draw():
|
||||||
|
clear_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)
|
||||||
|
|
||||||
|
if invert_xy:
|
||||||
|
for function_point in point_values[_function].size():
|
||||||
|
var point : Control = point_node.instance()
|
||||||
|
point.connect("_mouse_entered",self,"show_data",[point])
|
||||||
|
point.connect("_mouse_exited",self,"hide_data")
|
||||||
|
point.create_point(function_colors[_function], Color.white, point_positions[_function][function_point],point.format_value(point_values[_function][function_point],false,true),x_datas[_function])
|
||||||
|
PointContainer.add_child(point)
|
||||||
|
if function_point > 0:
|
||||||
|
draw_line(point_positions[_function][function_point-1],point_positions[_function][function_point],function_colors[_function],2,true)
|
||||||
|
else:
|
||||||
|
for function_point in point_values[_function].size():
|
||||||
|
var point : Control = point_node.instance()
|
||||||
|
point.connect("_mouse_entered",self,"show_data",[point])
|
||||||
|
point.connect("_mouse_exited",self,"hide_data")
|
||||||
|
point.create_point(function_colors[_function], Color.white, point_positions[_function][function_point],point.format_value(point_values[_function][function_point],false,true),y_labels[_function])
|
||||||
|
PointContainer.add_child(point)
|
||||||
|
if function_point > 0:
|
||||||
|
draw_line(point_positions[_function][function_point-1],point_positions[_function][function_point],function_colors[_function],2,true)
|
||||||
|
|
||||||
|
func create_legend():
|
||||||
|
legend.clear()
|
||||||
|
for function in functions:
|
||||||
|
var function_legend = FunctionLegend.instance()
|
||||||
|
var f_name : String
|
||||||
|
if invert_xy:
|
||||||
|
f_name = x_datas[function]
|
||||||
|
else:
|
||||||
|
f_name = y_labels[function]
|
||||||
|
var legend_font : Font
|
||||||
|
if font != null:
|
||||||
|
legend_font = font
|
||||||
|
if bold_font != null:
|
||||||
|
legend_font = bold_font
|
||||||
|
function_legend.create_legend(f_name,function_colors[function],bold_font,font_color)
|
||||||
|
legend.append(function_legend)
|
||||||
|
|
||||||
|
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)
|
||||||
|
draw_string(font,point+Vector2(-const_width/2*x_chors[p].length(),font_size+const_height),x_chors[p],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():
|
||||||
|
draw_line(origin,SIZE-Vector2(0,OFFSET.y),outline_color,1,true)
|
||||||
|
draw_line(origin,Vector2(OFFSET.x,0),outline_color,1,true)
|
||||||
|
draw_line(Vector2(OFFSET.x,0),Vector2(SIZE.x,0),outline_color,1,true)
|
||||||
|
draw_line(Vector2(SIZE.x,0),SIZE-Vector2(0,OFFSET.y),outline_color,1,true)
|
||||||
|
|
||||||
|
var can_grab_x : bool = false
|
||||||
|
var can_grab_y : bool = false
|
||||||
|
var can_move : bool = false
|
||||||
|
var range_mouse : float = 7
|
||||||
|
|
||||||
|
#func _input(event):
|
||||||
|
# if not can_grab_x and (event.position.x > (SIZE.x-range_mouse + rect_position.x) and event.position.x < (SIZE.x+range_mouse + rect_position.x)) :
|
||||||
|
# set_default_cursor_shape(Control.CURSOR_HSIZE)
|
||||||
|
# if Input.is_action_pressed("mouse_left"):
|
||||||
|
# can_grab_x = true
|
||||||
|
#
|
||||||
|
# if Input.is_action_just_released("mouse_left") and can_grab_x:
|
||||||
|
# can_grab_x = false
|
||||||
|
#
|
||||||
|
# if not can_grab_y and (event.position.y > ( rect_position.y + origin.y-range_mouse) and event.position.y < (rect_position.y+ origin.y+range_mouse)) :
|
||||||
|
# set_default_cursor_shape(Control.CURSOR_VSIZE)
|
||||||
|
# if Input.is_action_pressed("mouse_left"):
|
||||||
|
# can_grab_y = true
|
||||||
|
#
|
||||||
|
# if Input.is_action_just_released("mouse_left") and can_grab_y:
|
||||||
|
# can_grab_y = false
|
||||||
|
#
|
||||||
|
# if (event.position.x > SIZE.x-range_mouse+rect_position.x and event.position.x < SIZE.x+range_mouse + rect_position.x) and (event.position.y > rect_position.y+origin.y-range_mouse and event.position.y < rect_position.y+origin.y+range_mouse):
|
||||||
|
# set_default_cursor_shape(Control.CURSOR_FDIAGSIZE)
|
||||||
|
# if not (event.position.x > SIZE.x-range_mouse+rect_position.x and event.position.x < SIZE.x+range_mouse + rect_position.x) and not (event.position.y > rect_position.y+ origin.y-range_mouse and event.position.y < rect_position.y+origin.y+range_mouse ):
|
||||||
|
# set_default_cursor_shape(Control.CURSOR_ARROW)
|
||||||
|
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
if can_grab_x:
|
||||||
|
PointData.hide()
|
||||||
|
get_parent().rect_size.x = get_global_mouse_position().x - rect_position.x
|
||||||
|
redraw()
|
||||||
|
|
||||||
|
if can_grab_y:
|
||||||
|
PointData.hide()
|
||||||
|
get_parent().rect_size.y = get_global_mouse_position().y - rect_position.y + OFFSET.y
|
||||||
|
redraw()
|
||||||
|
|
||||||
|
func show_data(point):
|
||||||
|
PointData.update_datas(point)
|
||||||
|
PointData.show()
|
||||||
|
|
||||||
|
func hide_data():
|
||||||
|
PointData.hide()
|
||||||
|
|
||||||
|
func clear_points():
|
||||||
|
if Points.get_children():
|
||||||
|
for function in Points.get_children():
|
||||||
|
function.queue_free()
|
||||||
|
for legend in Legend.get_children():
|
||||||
|
legend.queue_free()
|
||||||
|
|
||||||
|
func set_legend(l : Array):
|
||||||
|
legend = l
|
||||||
|
|
||||||
|
func get_legend():
|
||||||
|
return legend
|
||||||
|
|
||||||
|
func invert_chart():
|
||||||
|
invert_xy = !invert_xy
|
||||||
|
count_functions()
|
||||||
|
redraw()
|
||||||
|
create_legend()
|
||||||
|
|
||||||
|
func count_functions():
|
||||||
|
if are_values_columns:
|
||||||
|
if not invert_xy:
|
||||||
|
functions = datas[0].size()-1
|
||||||
|
else:
|
||||||
|
functions = datas.size()-1
|
||||||
|
else:
|
||||||
|
if invert_xy:
|
||||||
|
functions = datas[0].size()-1
|
||||||
|
else:
|
||||||
|
functions = datas.size()-1
|
||||||
|
|
||||||
|
func apply_template(template_name : String):
|
||||||
|
if Engine.editor_hint:
|
||||||
|
if template_name!=null and template_name!="":
|
||||||
|
template = template_name
|
||||||
|
var custom_template = get_parent().templates[template_name.to_lower()]
|
||||||
|
function_colors[0] = Color(custom_template.function_color)
|
||||||
|
v_lines_color = Color(custom_template.v_lines_color)
|
||||||
|
h_lines_color = Color(custom_template.h_lines_color)
|
||||||
|
outline_color = Color(custom_template.outline_color)
|
||||||
|
font_color = Color(custom_template.font_color)
|
||||||
|
property_list_changed_notify()
|
54
addons/easy_charts/BarChart/BarChart.tscn
Normal file
54
addons/easy_charts/BarChart/BarChart.tscn
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/easy_charts/Utilities/Point/PointData.tscn" type="PackedScene" id=1]
|
||||||
|
[ext_resource path="res://addons/easy_charts/BarChart/BarChart.gd" type="Script" id=2]
|
||||||
|
|
||||||
|
[sub_resource type="Theme" id=1]
|
||||||
|
|
||||||
|
[node name="BarChart" type="Control"]
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
rect_min_size = Vector2( 70, 50 )
|
||||||
|
mouse_filter = 2
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
function_colors = PoolColorArray( 0.117647, 0.117647, 0.117647, 1 )
|
||||||
|
v_lines_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||||
|
h_lines_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||||
|
outline_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||||
|
font_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||||
|
|
||||||
|
[node name="Background" type="ColorRect" parent="."]
|
||||||
|
visible = false
|
||||||
|
show_behind_parent = true
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
color = Color( 0.882353, 0.882353, 0.882353, 1 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Points" type="Control" parent="."]
|
||||||
|
margin_right = 40.0
|
||||||
|
margin_bottom = 40.0
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Legend" type="HBoxContainer" parent="."]
|
||||||
|
visible = false
|
||||||
|
margin_right = 1024.0
|
||||||
|
margin_bottom = 64.0
|
||||||
|
alignment = 1
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="PointData" parent="." instance=ExtResource( 1 )]
|
||||||
|
|
||||||
|
[node name="PointData" parent="PointData" index="0"]
|
||||||
|
theme = SubResource( 1 )
|
||||||
|
|
||||||
|
[editable path="PointData"]
|
486
addons/easy_charts/BarChart2D/BarChart2D.gd
Normal file
486
addons/easy_charts/BarChart2D/BarChart2D.gd
Normal file
@ -0,0 +1,486 @@
|
|||||||
|
tool
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
[BarChart2D] - General purpose node for Bar Charts
|
||||||
|
|
||||||
|
A bar chart or bar graph is a chart or graph that presents categorical data with
|
||||||
|
rectangular bars with heights or lengths proportional to the values that they represent.
|
||||||
|
The bars can be plotted vertically or horizontally. A vertical bar chart is sometimes
|
||||||
|
called a column chart.
|
||||||
|
A bar graph shows comparisons among discrete categories. One axis of the chart shows
|
||||||
|
the specific categories being compared, and the other axis represents a measured value.
|
||||||
|
Some bar graphs present bars clustered in groups of more than one, showing the
|
||||||
|
values of more than one measured variable.
|
||||||
|
|
||||||
|
/ source : Wikipedia /
|
||||||
|
"""
|
||||||
|
|
||||||
|
onready var FunctionsTween : Tween = $FunctionsTween
|
||||||
|
onready var OutlinesTween : Tween = $OutlinesTween
|
||||||
|
onready var GridTween : Tween = $GridTween
|
||||||
|
onready var Functions : Node2D = $Functions
|
||||||
|
onready var PointData = $PointData/PointData
|
||||||
|
onready var Outlines : Line2D = $Outlines
|
||||||
|
onready var Grid : Node2D = $Grid
|
||||||
|
|
||||||
|
var point_node : PackedScene = preload("../Utilities/Point/Point.tscn")
|
||||||
|
var FunctionLegend : PackedScene = preload("../Utilities/Legend/FunctionLegend.tscn")
|
||||||
|
|
||||||
|
var font_size : float = 16
|
||||||
|
var const_height : float = font_size/2*font_size/20
|
||||||
|
var const_width : float = font_size/2
|
||||||
|
|
||||||
|
var OFFSET : Vector2 = Vector2(0,0)
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------#
|
||||||
|
var origin : Vector2
|
||||||
|
|
||||||
|
# actual distance between x and y values
|
||||||
|
var x_pass : float
|
||||||
|
var y_pass : float
|
||||||
|
|
||||||
|
# vertical distance between y consecutive points used for intervals
|
||||||
|
var v_dist : float
|
||||||
|
|
||||||
|
# quantization, representing the interval in which values will be displayed
|
||||||
|
var x_decim : float = 1.0
|
||||||
|
|
||||||
|
# define values on x an y axis
|
||||||
|
var x_chors : Array
|
||||||
|
var y_chors : Array
|
||||||
|
|
||||||
|
# actual coordinates of points (in pixel)
|
||||||
|
var x_coordinates : Array
|
||||||
|
var y_coordinates : Array
|
||||||
|
|
||||||
|
# datas contained in file
|
||||||
|
var datas : Array
|
||||||
|
|
||||||
|
# amount of functions to represent
|
||||||
|
var functions : int = 0
|
||||||
|
|
||||||
|
|
||||||
|
# database values
|
||||||
|
var x_datas : Array
|
||||||
|
var y_datas : Array
|
||||||
|
|
||||||
|
# labels displayed on chart
|
||||||
|
var x_label : String
|
||||||
|
var y_labels : Array
|
||||||
|
|
||||||
|
# actual values of point, from the database
|
||||||
|
var point_values : Array
|
||||||
|
|
||||||
|
# actual position of points in pixel
|
||||||
|
var point_positions : Array
|
||||||
|
|
||||||
|
var legend : Array setget set_legend,get_legend
|
||||||
|
|
||||||
|
# ---------------------
|
||||||
|
#export (bool)
|
||||||
|
export (Vector2) var SIZE : Vector2 = Vector2()
|
||||||
|
export (String, FILE) var source : String = ""
|
||||||
|
export (String) var delimiter : String = ";"
|
||||||
|
|
||||||
|
export (bool) var are_values_columns : bool = false
|
||||||
|
export (bool) var invert_xy : bool = false
|
||||||
|
|
||||||
|
export (int,0,100) var x_values : int = 0
|
||||||
|
|
||||||
|
export (float,1,20,0.5) var column_width : float = 10
|
||||||
|
export (float,0,10,0.5) var column_gap : float = 2
|
||||||
|
|
||||||
|
export (float,0,10) var y_decim : float = 5.0
|
||||||
|
export (PoolColorArray) var function_colors = [Color("#1e1e1e")]
|
||||||
|
|
||||||
|
export (bool) var boxed : bool = true
|
||||||
|
export (Color) var v_lines_color : Color = Color("#cacaca")
|
||||||
|
export (Color) var h_lines_color : Color = Color("#cacaca")
|
||||||
|
export (Color) var outline_color : Color = Color("#1e1e1e")
|
||||||
|
export (float,0.01,1) var drawing_duration : float = 0.3
|
||||||
|
export (Font) var font : Font
|
||||||
|
export (Font) var bold_font : Font
|
||||||
|
export (Color) var font_color : Color = Color("#1e1e1e")
|
||||||
|
export (String,"Default","Clean","Gradient","Minimal","Invert") var template : String = "Default" setget apply_template
|
||||||
|
|
||||||
|
var templates : Dictionary = {}
|
||||||
|
|
||||||
|
signal chart_plotted(chart)
|
||||||
|
signal point_pressed(point)
|
||||||
|
|
||||||
|
func _point_drawn():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _script_changed():
|
||||||
|
_ready()
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
if Engine.editor_hint:
|
||||||
|
Outlines.set_default_color(outline_color)
|
||||||
|
Grid.get_node("VLine").set_default_color(v_lines_color)
|
||||||
|
Grid.get_node("HLine").set_default_color(h_lines_color)
|
||||||
|
if function_colors.size():
|
||||||
|
Functions.get_node("Function").set_default_color(function_colors[0])
|
||||||
|
else:
|
||||||
|
Functions.get_node("Function").set_default_color(Color("#1e1e1e"))
|
||||||
|
|
||||||
|
if SIZE!=Vector2():
|
||||||
|
build_chart()
|
||||||
|
Outlines.set_point_position(0,Vector2(origin.x,0))
|
||||||
|
Outlines.set_point_position(1,Vector2(SIZE.x,0))
|
||||||
|
Outlines.set_point_position(2,Vector2(SIZE.x,origin.y))
|
||||||
|
Outlines.set_point_position(3,origin)
|
||||||
|
Outlines.set_point_position(4,Vector2(origin.x,0))
|
||||||
|
|
||||||
|
Grid.get_node("VLine").set_point_position(0,Vector2((OFFSET.x+SIZE.x)/2,0))
|
||||||
|
Grid.get_node("VLine").set_point_position(1,Vector2((OFFSET.x+SIZE.x)/2,origin.y))
|
||||||
|
Grid.get_node("HLine").set_point_position(0,Vector2(origin.x,origin.y/2))
|
||||||
|
Grid.get_node("HLine").set_point_position(1,Vector2(SIZE.x,origin.y/2))
|
||||||
|
|
||||||
|
if function_colors.size():
|
||||||
|
Functions.get_node("Function").set_point_position(0,Vector2((OFFSET.x+SIZE.x)/2,origin.y))
|
||||||
|
Functions.get_node("Function").set_point_position(1,Vector2((OFFSET.x+SIZE.x)/2,0))
|
||||||
|
|
||||||
|
#func _ready():
|
||||||
|
# plot_line_chart("res://ChartNode/datas2.csv",";",false,0,invert_xy,function_colors,drawing_duration,SIZE)
|
||||||
|
|
||||||
|
func clear():
|
||||||
|
Outlines.points = []
|
||||||
|
Grid.get_node("HLine").queue_free()
|
||||||
|
Grid.get_node("VLine").queue_free()
|
||||||
|
Functions.get_node("Function").queue_free()
|
||||||
|
|
||||||
|
func load_font():
|
||||||
|
if font != null:
|
||||||
|
font_size = font.get_height()
|
||||||
|
var theme : Theme = Theme.new()
|
||||||
|
theme.set_default_font(font)
|
||||||
|
PointData.set_theme(theme)
|
||||||
|
if bold_font != null:
|
||||||
|
PointData.Data.set("custom_fonts/font",bold_font)
|
||||||
|
|
||||||
|
func _plot(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_values_ : int):
|
||||||
|
randomize()
|
||||||
|
|
||||||
|
clear()
|
||||||
|
|
||||||
|
load_font()
|
||||||
|
PointData.hide()
|
||||||
|
|
||||||
|
datas = read_datas(source_,delimiter_)
|
||||||
|
count_functions()
|
||||||
|
structure_datas(datas,are_values_columns_,x_values_)
|
||||||
|
build_chart()
|
||||||
|
calculate_pass()
|
||||||
|
calculate_coordinates()
|
||||||
|
calculate_colors()
|
||||||
|
draw_chart()
|
||||||
|
|
||||||
|
create_legend()
|
||||||
|
emit_signal("chart_plotted", self)
|
||||||
|
|
||||||
|
func plot():
|
||||||
|
randomize()
|
||||||
|
|
||||||
|
clear()
|
||||||
|
|
||||||
|
load_font()
|
||||||
|
PointData.hide()
|
||||||
|
|
||||||
|
if source == "" or source == null:
|
||||||
|
Utilities._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_datas(source,delimiter)
|
||||||
|
count_functions()
|
||||||
|
structure_datas(datas,are_values_columns,x_values)
|
||||||
|
build_chart()
|
||||||
|
calculate_pass()
|
||||||
|
calculate_coordinates()
|
||||||
|
calculate_colors()
|
||||||
|
draw_chart()
|
||||||
|
|
||||||
|
create_legend()
|
||||||
|
emit_signal("chart_plotted", self)
|
||||||
|
|
||||||
|
func calculate_colors():
|
||||||
|
if function_colors.empty() or function_colors.size() < functions:
|
||||||
|
for function in functions:
|
||||||
|
function_colors.append(Color("#1e1e1e"))
|
||||||
|
|
||||||
|
func draw_chart():
|
||||||
|
draw_outlines()
|
||||||
|
draw_v_grid()
|
||||||
|
draw_h_grid()
|
||||||
|
draw_functions()
|
||||||
|
|
||||||
|
func draw_outlines():
|
||||||
|
if boxed:
|
||||||
|
Outlines.set_default_color(outline_color)
|
||||||
|
OutlinesTween.interpolate_method(Outlines,"add_point",
|
||||||
|
Vector2(origin.x,0),Vector2(SIZE.x,0),drawing_duration*0.5,Tween.TRANS_QUINT,Tween.EASE_OUT)
|
||||||
|
OutlinesTween.start()
|
||||||
|
yield(OutlinesTween,"tween_all_completed")
|
||||||
|
OutlinesTween.interpolate_method(Outlines,"add_point",
|
||||||
|
Vector2(SIZE.x,0),Vector2(SIZE.x,origin.y),drawing_duration*0.5,Tween.TRANS_QUINT,Tween.EASE_OUT)
|
||||||
|
OutlinesTween.start()
|
||||||
|
yield(OutlinesTween,"tween_all_completed")
|
||||||
|
OutlinesTween.interpolate_method(Outlines,"add_point",
|
||||||
|
Vector2(SIZE.x,origin.y),origin,drawing_duration*0.5,Tween.TRANS_QUINT,Tween.EASE_OUT)
|
||||||
|
OutlinesTween.start()
|
||||||
|
yield(OutlinesTween,"tween_all_completed")
|
||||||
|
OutlinesTween.interpolate_method(Outlines,"add_point",
|
||||||
|
origin,Vector2(origin.x,0),drawing_duration*0.5,Tween.TRANS_QUINT,Tween.EASE_OUT)
|
||||||
|
OutlinesTween.start()
|
||||||
|
yield(OutlinesTween,"tween_all_completed")
|
||||||
|
|
||||||
|
func draw_v_grid():
|
||||||
|
for p in x_chors.size():
|
||||||
|
var point : Vector2 = origin+Vector2((p)*x_pass + OFFSET.x/2,0)
|
||||||
|
var v_grid : Line2D = Line2D.new()
|
||||||
|
Grid.add_child(v_grid)
|
||||||
|
v_grid.set_width(1)
|
||||||
|
v_grid.set_default_color(v_lines_color)
|
||||||
|
add_label(point+Vector2(-const_width/2*x_chors[p].length() + (column_width/2) * ( y_datas.size() if not invert_xy else y_datas[0].size()+1 ) + column_gap,font_size/2), x_chors[p])
|
||||||
|
GridTween.interpolate_method(v_grid,"add_point",Vector2(point.x,origin.y),Vector2(point.x,origin.y-5),drawing_duration/(x_chors.size()),Tween.TRANS_EXPO,Tween.EASE_OUT)
|
||||||
|
GridTween.start()
|
||||||
|
yield(GridTween,"tween_all_completed")
|
||||||
|
|
||||||
|
func draw_h_grid():
|
||||||
|
for p in y_chors.size():
|
||||||
|
var point : Vector2 = origin-Vector2(0,(p)*y_pass)
|
||||||
|
var h_grid : Line2D = Line2D.new()
|
||||||
|
Grid.add_child(h_grid)
|
||||||
|
h_grid.set_width(1)
|
||||||
|
h_grid.set_default_color(h_lines_color)
|
||||||
|
add_label(point-Vector2(y_chors[p].length()*const_width+font_size,font_size/2), y_chors[p])
|
||||||
|
GridTween.interpolate_method(h_grid,"add_point",point,Vector2(SIZE.x,point.y),drawing_duration/(y_chors.size()),Tween.TRANS_EXPO,Tween.EASE_OUT)
|
||||||
|
GridTween.start()
|
||||||
|
yield(GridTween,"tween_all_completed")
|
||||||
|
|
||||||
|
|
||||||
|
func add_label(point : Vector2, text : String):
|
||||||
|
var lbl : Label = Label.new()
|
||||||
|
if font != null:
|
||||||
|
lbl.set("custom_fonts/font",font)
|
||||||
|
lbl.set("custom_colors/font_color",font_color)
|
||||||
|
Grid.add_child(lbl)
|
||||||
|
lbl.rect_position = point
|
||||||
|
lbl.set_text(text)
|
||||||
|
|
||||||
|
func draw_functions():
|
||||||
|
for function in point_positions.size():
|
||||||
|
draw_function(function,point_positions[function])
|
||||||
|
|
||||||
|
func draw_function(f_index : int, function : Array):
|
||||||
|
for point in function.size():
|
||||||
|
var line : Line2D = Line2D.new()
|
||||||
|
var pointv : Control
|
||||||
|
pointv = point_node.instance()
|
||||||
|
line.add_child(pointv)
|
||||||
|
pointv.connect("_mouse_entered",self,"show_data",[pointv])
|
||||||
|
pointv.connect("_mouse_exited",self,"hide_data")
|
||||||
|
pointv.connect("_point_pressed",self,"point_pressed")
|
||||||
|
pointv.create_point(function_colors[f_index], Color.white, function[point]+Vector2(0,10), pointv.format_value(point_values[f_index][point],false,true),(x_datas[f_index] if invert_xy else y_labels[f_index]))
|
||||||
|
pointv.rect_size.y = origin.y - function[point].y
|
||||||
|
construct_column(line,f_index,function)
|
||||||
|
FunctionsTween.interpolate_method(line,"add_point",Vector2(function[point].x,origin.y),function[point],drawing_duration/function.size(),Tween.TRANS_QUINT,Tween.EASE_OUT)
|
||||||
|
FunctionsTween.start()
|
||||||
|
yield(FunctionsTween,"tween_all_completed")
|
||||||
|
|
||||||
|
func construct_column(line : Line2D, f_index : int, function : Array):
|
||||||
|
line.set_width(column_width)
|
||||||
|
line.set_default_color(function_colors[f_index])
|
||||||
|
line.antialiased = true
|
||||||
|
Functions.add_child(line)
|
||||||
|
|
||||||
|
func read_datas(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
|
||||||
|
|
||||||
|
func structure_datas(database : Array, are_values_columns : bool, x_values : int):
|
||||||
|
# @x_values 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:
|
||||||
|
x_datas.append(database[row][column])
|
||||||
|
else:
|
||||||
|
if row != 0:
|
||||||
|
t_vals.append(float(database[row][column]))
|
||||||
|
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())
|
||||||
|
false:
|
||||||
|
for row in database.size():
|
||||||
|
if row == x_values:
|
||||||
|
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
|
||||||
|
|
||||||
|
var to_order : Array
|
||||||
|
for cluster in y_datas.size():
|
||||||
|
# define x_chors and y_chors
|
||||||
|
var margin = y_datas[cluster][y_datas[cluster].size()-1]
|
||||||
|
to_order.append(margin)
|
||||||
|
|
||||||
|
to_order.sort()
|
||||||
|
var margin = to_order.pop_back()
|
||||||
|
v_dist = y_decim * pow(10.0,str(margin).length()-2)
|
||||||
|
var multi = 0
|
||||||
|
var p = v_dist*multi
|
||||||
|
y_chors.append(p as String)
|
||||||
|
while p < margin:
|
||||||
|
multi+=1
|
||||||
|
p = v_dist*multi
|
||||||
|
y_chors.append(p as String)
|
||||||
|
|
||||||
|
func build_chart():
|
||||||
|
origin = Vector2(OFFSET.x,SIZE.y-OFFSET.y)
|
||||||
|
|
||||||
|
func calculate_pass():
|
||||||
|
if invert_xy:
|
||||||
|
x_chors = y_labels as PoolStringArray
|
||||||
|
else:
|
||||||
|
x_chors = x_datas as PoolStringArray
|
||||||
|
# calculate distance in pixel between 2 consecutive values/datas
|
||||||
|
x_pass = (SIZE.x - OFFSET.x*2 - (column_width) * ( y_datas.size() if not invert_xy else y_datas[0].size()+1 ) - column_gap - column_width/2) / (x_chors.size()-1)
|
||||||
|
y_pass = origin.y / (y_chors.size()-1)
|
||||||
|
|
||||||
|
func calculate_coordinates():
|
||||||
|
x_coordinates.clear()
|
||||||
|
y_coordinates.clear()
|
||||||
|
point_values.clear()
|
||||||
|
point_positions.clear()
|
||||||
|
|
||||||
|
if invert_xy:
|
||||||
|
for column in y_datas[0].size():
|
||||||
|
var single_coordinates : Array
|
||||||
|
for row in y_datas:
|
||||||
|
single_coordinates.append((row[column]*y_pass)/v_dist)
|
||||||
|
y_coordinates.append(single_coordinates)
|
||||||
|
else:
|
||||||
|
for cluster in y_datas:
|
||||||
|
var single_coordinates : Array
|
||||||
|
for value in cluster.size():
|
||||||
|
single_coordinates.append((cluster[value]*y_pass)/v_dist)
|
||||||
|
y_coordinates.append(single_coordinates)
|
||||||
|
|
||||||
|
for x in x_chors.size():
|
||||||
|
x_coordinates.append(x_pass*x)
|
||||||
|
|
||||||
|
for f in functions:
|
||||||
|
point_values.append([])
|
||||||
|
point_positions.append([])
|
||||||
|
|
||||||
|
if invert_xy:
|
||||||
|
for function in y_coordinates.size():
|
||||||
|
for function_value in y_coordinates[function].size():
|
||||||
|
point_positions[function].append(Vector2(OFFSET.x/2 + column_width/2 + (column_width + column_gap)*function + x_coordinates[function_value]+origin.x, origin.y-y_coordinates[function][function_value]))
|
||||||
|
point_values[function].append([x_chors[function_value],y_datas[function_value][function]])
|
||||||
|
else:
|
||||||
|
for cluster in y_coordinates.size():
|
||||||
|
for y in y_coordinates[cluster].size():
|
||||||
|
point_values[cluster].append([x_chors[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]))
|
||||||
|
|
||||||
|
func redraw():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func invert_chart():
|
||||||
|
invert_xy = !invert_xy
|
||||||
|
count_functions()
|
||||||
|
redraw()
|
||||||
|
create_legend()
|
||||||
|
|
||||||
|
|
||||||
|
func count_functions():
|
||||||
|
if are_values_columns:
|
||||||
|
if not invert_xy:
|
||||||
|
functions = datas[0].size()-1
|
||||||
|
else:
|
||||||
|
functions = datas.size()-1
|
||||||
|
else:
|
||||||
|
if invert_xy:
|
||||||
|
functions = datas[0].size()-1
|
||||||
|
else:
|
||||||
|
functions = datas.size()-1
|
||||||
|
|
||||||
|
func show_data(point):
|
||||||
|
PointData.update_datas(point)
|
||||||
|
PointData.show()
|
||||||
|
|
||||||
|
func hide_data():
|
||||||
|
PointData.hide()
|
||||||
|
|
||||||
|
func clear_points():
|
||||||
|
function_colors.clear()
|
||||||
|
if Functions.get_children():
|
||||||
|
for function in Functions.get_children():
|
||||||
|
function.queue_free()
|
||||||
|
|
||||||
|
func create_legend():
|
||||||
|
legend.clear()
|
||||||
|
for function in functions:
|
||||||
|
var function_legend = FunctionLegend.instance()
|
||||||
|
var f_name : String
|
||||||
|
if invert_xy:
|
||||||
|
f_name = x_datas[function]
|
||||||
|
else:
|
||||||
|
f_name = y_labels[function]
|
||||||
|
var legend_font : Font
|
||||||
|
if font != null:
|
||||||
|
legend_font = font
|
||||||
|
if bold_font != null:
|
||||||
|
legend_font = bold_font
|
||||||
|
function_legend.create_legend(f_name,function_colors[function],bold_font,font_color)
|
||||||
|
legend.append(function_legend)
|
||||||
|
|
||||||
|
func set_legend(l : Array):
|
||||||
|
legend = l
|
||||||
|
|
||||||
|
func get_legend() -> Array:
|
||||||
|
return legend
|
||||||
|
|
||||||
|
func apply_template(template_name : String):
|
||||||
|
if Engine.editor_hint:
|
||||||
|
if template_name!=null and template_name!="":
|
||||||
|
template = template_name
|
||||||
|
var custom_template = templates[template_name.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)
|
||||||
|
outline_color = Color(custom_template.outline_color)
|
||||||
|
font_color = Color(custom_template.font_color)
|
||||||
|
property_list_changed_notify()
|
||||||
|
|
||||||
|
func point_pressed(point : Point):
|
||||||
|
emit_signal("point_pressed",point)
|
||||||
|
|
||||||
|
func _enter_tree():
|
||||||
|
templates = Utilities._load_templates()
|
48
addons/easy_charts/BarChart2D/BarChart2D.tscn
Normal file
48
addons/easy_charts/BarChart2D/BarChart2D.tscn
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
[gd_scene load_steps=3 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/easy_charts/BarChart2D/BarChart2D.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://addons/easy_charts/Utilities/Point/PointData.tscn" type="PackedScene" id=2]
|
||||||
|
|
||||||
|
[node name="BarChart2D" type="Node2D"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_group_": true
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Grid" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
[node name="VLine" type="Line2D" parent="Grid"]
|
||||||
|
points = PoolVector2Array( 0, 0, 0, 0 )
|
||||||
|
width = 1.0
|
||||||
|
default_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||||
|
|
||||||
|
[node name="HLine" type="Line2D" parent="Grid"]
|
||||||
|
points = PoolVector2Array( 0, 0, 0, 0 )
|
||||||
|
width = 1.0
|
||||||
|
default_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||||
|
|
||||||
|
[node name="Outlines" type="Line2D" parent="."]
|
||||||
|
points = PoolVector2Array( 0, 0, 2, 0, 2, 2, 0, 2, 0, 0 )
|
||||||
|
width = 2.0
|
||||||
|
default_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||||
|
|
||||||
|
[node name="Functions" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
[node name="Function" type="Line2D" parent="Functions"]
|
||||||
|
points = PoolVector2Array( 0, 0, 0, 0 )
|
||||||
|
width = 5.0
|
||||||
|
default_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||||
|
|
||||||
|
[node name="FunctionsTween" type="Tween" parent="."]
|
||||||
|
|
||||||
|
[node name="OutlinesTween" type="Tween" parent="."]
|
||||||
|
|
||||||
|
[node name="GridTween" type="Tween" parent="."]
|
||||||
|
|
||||||
|
[node name="PointData" parent="." instance=ExtResource( 2 )]
|
||||||
|
|
||||||
|
[node name="PointData" parent="PointData" index="0"]
|
||||||
|
visible = false
|
||||||
|
[connection signal="script_changed" from="." to="." method="_script_changed"]
|
||||||
|
|
||||||
|
[editable path="PointData"]
|
108
addons/easy_charts/BarChart2D/LineChart2D.tscn.depren
Normal file
108
addons/easy_charts/BarChart2D/LineChart2D.tscn.depren
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/easy_charts/LineChart2D/LineChart2D.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://addons/easy_charts/Utilities/Point/PointData.gd" type="Script" id=3]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id=1]
|
||||||
|
content_margin_left = 8.0
|
||||||
|
content_margin_right = 8.0
|
||||||
|
content_margin_top = 5.0
|
||||||
|
content_margin_bottom = 5.0
|
||||||
|
bg_color = Color( 1, 1, 1, 0 )
|
||||||
|
border_width_left = 2
|
||||||
|
border_width_top = 2
|
||||||
|
border_width_right = 2
|
||||||
|
border_width_bottom = 2
|
||||||
|
border_color = Color( 1, 1, 1, 1 )
|
||||||
|
corner_radius_top_left = 5
|
||||||
|
corner_radius_top_right = 5
|
||||||
|
corner_radius_bottom_right = 5
|
||||||
|
corner_radius_bottom_left = 5
|
||||||
|
corner_detail = 20
|
||||||
|
|
||||||
|
[node name="LineChart2D" type="Node2D"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
drawing_duration = 0.3
|
||||||
|
font_color = Color( 0.137255, 0.137255, 0.137255, 1 )
|
||||||
|
|
||||||
|
[node name="Grid" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
[node name="VLine" type="Line2D" parent="Grid"]
|
||||||
|
points = PoolVector2Array( 0, 0, 0, 0 )
|
||||||
|
width = 1.0
|
||||||
|
default_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||||
|
|
||||||
|
[node name="HLine" type="Line2D" parent="Grid"]
|
||||||
|
points = PoolVector2Array( 0, 0, 0, 0 )
|
||||||
|
width = 1.0
|
||||||
|
default_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||||
|
|
||||||
|
[node name="Outlines" type="Line2D" parent="."]
|
||||||
|
points = PoolVector2Array( 0, 0, 2, 0, 2, 2, 0, 2, 0, 0 )
|
||||||
|
width = 2.0
|
||||||
|
default_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||||
|
|
||||||
|
[node name="Functions" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
[node name="Function" type="Line2D" parent="Functions"]
|
||||||
|
points = PoolVector2Array( 0, 0, 0, 0 )
|
||||||
|
width = 2.0
|
||||||
|
default_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||||
|
|
||||||
|
[node name="FunctionsTween" type="Tween" parent="."]
|
||||||
|
|
||||||
|
[node name="OutlinesTween" type="Tween" parent="."]
|
||||||
|
|
||||||
|
[node name="GridTween" type="Tween" parent="."]
|
||||||
|
|
||||||
|
[node name="UI" type="CanvasLayer" parent="."]
|
||||||
|
|
||||||
|
[node name="PointData" type="PanelContainer" parent="UI"]
|
||||||
|
margin_right = 67.0
|
||||||
|
margin_bottom = 38.0
|
||||||
|
mouse_filter = 2
|
||||||
|
custom_styles/panel = SubResource( 1 )
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="PointData" type="VBoxContainer" parent="UI/PointData"]
|
||||||
|
margin_left = 8.0
|
||||||
|
margin_top = 5.0
|
||||||
|
margin_right = 59.0
|
||||||
|
margin_bottom = 36.0
|
||||||
|
custom_constants/separation = 3
|
||||||
|
alignment = 1
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Function" type="Label" parent="UI/PointData/PointData"]
|
||||||
|
margin_right = 51.0
|
||||||
|
margin_bottom = 14.0
|
||||||
|
align = 1
|
||||||
|
valign = 1
|
||||||
|
|
||||||
|
[node name="Value" type="HBoxContainer" parent="UI/PointData/PointData"]
|
||||||
|
margin_top = 17.0
|
||||||
|
margin_right = 51.0
|
||||||
|
margin_bottom = 31.0
|
||||||
|
|
||||||
|
[node name="x" type="Label" parent="UI/PointData/PointData/Value"]
|
||||||
|
margin_right = 39.0
|
||||||
|
margin_bottom = 14.0
|
||||||
|
custom_colors/font_color = Color( 1, 1, 1, 1 )
|
||||||
|
text = "Value:"
|
||||||
|
valign = 1
|
||||||
|
|
||||||
|
[node name="y" type="Label" parent="UI/PointData/PointData/Value"]
|
||||||
|
margin_left = 43.0
|
||||||
|
margin_right = 51.0
|
||||||
|
margin_bottom = 14.0
|
||||||
|
custom_colors/font_color = Color( 1, 1, 1, 1 )
|
||||||
|
text = "0"
|
||||||
|
valign = 1
|
397
addons/easy_charts/LineChart/LineChart.gd
Normal file
397
addons/easy_charts/LineChart/LineChart.gd
Normal file
@ -0,0 +1,397 @@
|
|||||||
|
tool
|
||||||
|
extends Control
|
||||||
|
|
||||||
|
onready var PointData = $PointData/PointData
|
||||||
|
onready var Points = $Points
|
||||||
|
onready var Legend = $Legend
|
||||||
|
|
||||||
|
var point_node : PackedScene = preload("../Utilities/Point/Point.tscn")
|
||||||
|
var FunctionLegend : PackedScene = preload("../Utilities/Legend/FunctionLegend.tscn")
|
||||||
|
|
||||||
|
var font_size : float = 16
|
||||||
|
var const_height : float = font_size/2*font_size/20
|
||||||
|
var const_width : float = font_size/2
|
||||||
|
|
||||||
|
var source : String
|
||||||
|
var delimiter : String
|
||||||
|
|
||||||
|
var OFFSET : Vector2 = Vector2(50,30)
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------#
|
||||||
|
var origin : Vector2
|
||||||
|
|
||||||
|
# actual distance between x and y values
|
||||||
|
var x_pass : float
|
||||||
|
var y_pass : float
|
||||||
|
|
||||||
|
# vertical distance between y consecutive points used for intervals
|
||||||
|
var v_dist : float
|
||||||
|
|
||||||
|
# quantization, representing the interval in which values will be displayed
|
||||||
|
var x_decim : float = 1.0
|
||||||
|
export (float) var y_decim : float = 5.0
|
||||||
|
|
||||||
|
# define values on x an y axis
|
||||||
|
var x_chors : Array
|
||||||
|
var y_chors : Array
|
||||||
|
|
||||||
|
# actual coordinates of points (in pixel)
|
||||||
|
var x_coordinates : Array
|
||||||
|
var y_coordinates : Array
|
||||||
|
|
||||||
|
# datas contained in file
|
||||||
|
var datas : Array
|
||||||
|
|
||||||
|
# amount of functions to represent
|
||||||
|
var functions : int = 0
|
||||||
|
|
||||||
|
|
||||||
|
# database values
|
||||||
|
var x_datas : Array
|
||||||
|
var y_datas : Array
|
||||||
|
|
||||||
|
# labels displayed on chart
|
||||||
|
var x_label : String
|
||||||
|
var y_labels : Array
|
||||||
|
|
||||||
|
# actual values of point, from the database
|
||||||
|
var point_values : Array
|
||||||
|
|
||||||
|
# actual position of points in pixel
|
||||||
|
var point_positions : Array
|
||||||
|
|
||||||
|
var legend : Array setget set_legend,get_legend
|
||||||
|
var are_values_columns : bool
|
||||||
|
|
||||||
|
# ---------------------
|
||||||
|
export (bool) var invert_xy : bool
|
||||||
|
var SIZE : Vector2 = Vector2()
|
||||||
|
export (PoolColorArray) var function_colors = [Color("#1e1e1e")]
|
||||||
|
export (Color) var v_lines_color : Color = Color("#cacaca")
|
||||||
|
export (Color) var h_lines_color : Color = Color("#cacaca")
|
||||||
|
export (Color) var outline_color : Color = Color("#1e1e1e")
|
||||||
|
export (Font) var font : Font
|
||||||
|
export (Font) var bold_font : Font
|
||||||
|
export (Color) var font_color : Color = Color("#1e1e1e")
|
||||||
|
export (String,"Default","Clean","Minimal","Invert") var template : String = "Default" setget apply_template
|
||||||
|
|
||||||
|
signal linechart_plotted()
|
||||||
|
|
||||||
|
#func _ready():
|
||||||
|
# plot_line_chart("res://ChartNode/datas.csv",";",true,0)
|
||||||
|
|
||||||
|
func plot_line_chart(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_values_ : int, invert_xy_ : bool = false):
|
||||||
|
randomize()
|
||||||
|
|
||||||
|
load_font()
|
||||||
|
PointData.hide()
|
||||||
|
|
||||||
|
datas = read_datas(source_,delimiter_)
|
||||||
|
count_functions()
|
||||||
|
structure_datas(datas,are_values_columns_,x_values_)
|
||||||
|
build_chart()
|
||||||
|
calculate_pass()
|
||||||
|
calculate_coordinates()
|
||||||
|
calculate_colors()
|
||||||
|
create_legend()
|
||||||
|
emit_signal("linechart_plotted")
|
||||||
|
|
||||||
|
func calculate_colors():
|
||||||
|
if function_colors.empty() or function_colors.size() < functions:
|
||||||
|
for function in functions:
|
||||||
|
function_colors.append(Color("#1e1e1e"))
|
||||||
|
|
||||||
|
func load_font():
|
||||||
|
if font != null:
|
||||||
|
font_size = font.get_height()
|
||||||
|
var theme : Theme = Theme.new()
|
||||||
|
theme.set_default_font(font)
|
||||||
|
PointData.set_theme(theme)
|
||||||
|
else:
|
||||||
|
var lbl = Label.new()
|
||||||
|
font = lbl.get_font("")
|
||||||
|
lbl.free()
|
||||||
|
if bold_font != null:
|
||||||
|
PointData.Data.set("custom_fonts/font",bold_font)
|
||||||
|
|
||||||
|
func read_datas(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
|
||||||
|
|
||||||
|
func structure_datas(database : Array, are_values_columns : bool, x_values : int):
|
||||||
|
# @x_values 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:
|
||||||
|
x_datas.append(database[row][column])
|
||||||
|
else:
|
||||||
|
if row != 0:
|
||||||
|
t_vals.append(float(database[row][column]))
|
||||||
|
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())
|
||||||
|
false:
|
||||||
|
for row in database.size():
|
||||||
|
if row == x_values:
|
||||||
|
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
|
||||||
|
|
||||||
|
var to_order : Array
|
||||||
|
for cluster in y_datas.size():
|
||||||
|
# define x_chors and y_chors
|
||||||
|
var margin = y_datas[cluster][y_datas[cluster].size()-1]
|
||||||
|
to_order.append(margin)
|
||||||
|
|
||||||
|
to_order.sort()
|
||||||
|
var margin = to_order.pop_back()
|
||||||
|
v_dist = y_decim * pow(10.0,str(margin).length()-2)
|
||||||
|
var multi = 0
|
||||||
|
var p = v_dist*multi
|
||||||
|
y_chors.append(p as String)
|
||||||
|
while p < margin:
|
||||||
|
multi+=1
|
||||||
|
p = v_dist*multi
|
||||||
|
y_chors.append(p as String)
|
||||||
|
|
||||||
|
func build_chart():
|
||||||
|
SIZE = get_parent().get_size()
|
||||||
|
origin = Vector2(OFFSET.x,SIZE.y-OFFSET.y)
|
||||||
|
|
||||||
|
func calculate_pass():
|
||||||
|
if invert_xy:
|
||||||
|
x_chors = y_labels as PoolStringArray
|
||||||
|
else:
|
||||||
|
x_chors = x_datas as PoolStringArray
|
||||||
|
# calculate distance in pixel between 2 consecutive values/datas
|
||||||
|
x_pass = (SIZE.x - OFFSET.x) / (x_chors.size()-1)
|
||||||
|
y_pass = origin.y / (y_chors.size()-1)
|
||||||
|
|
||||||
|
func calculate_coordinates():
|
||||||
|
x_coordinates.clear()
|
||||||
|
y_coordinates.clear()
|
||||||
|
point_values.clear()
|
||||||
|
point_positions.clear()
|
||||||
|
|
||||||
|
if invert_xy:
|
||||||
|
for column in y_datas[0].size():
|
||||||
|
var single_coordinates : Array
|
||||||
|
for row in y_datas:
|
||||||
|
single_coordinates.append((row[column]*y_pass)/v_dist)
|
||||||
|
y_coordinates.append(single_coordinates)
|
||||||
|
else:
|
||||||
|
for cluster in y_datas:
|
||||||
|
var single_coordinates : Array
|
||||||
|
for value in cluster.size():
|
||||||
|
single_coordinates.append((cluster[value]*y_pass)/v_dist)
|
||||||
|
y_coordinates.append(single_coordinates)
|
||||||
|
|
||||||
|
for x in x_chors.size():
|
||||||
|
x_coordinates.append(x_pass*x)
|
||||||
|
|
||||||
|
for f in functions:
|
||||||
|
point_values.append([])
|
||||||
|
point_positions.append([])
|
||||||
|
|
||||||
|
if invert_xy:
|
||||||
|
for function in y_coordinates.size()-1:
|
||||||
|
for function_value in y_coordinates[function].size():
|
||||||
|
point_positions[function].append(Vector2(x_coordinates[function_value]+origin.x,origin.y-y_coordinates[function][function_value]))
|
||||||
|
point_values[function].append([x_chors[function_value],y_datas[function_value][function]])
|
||||||
|
else:
|
||||||
|
for cluster in y_coordinates.size():
|
||||||
|
for y in y_coordinates[cluster].size():
|
||||||
|
point_values[cluster].append([x_chors[y],y_datas[cluster][y]])
|
||||||
|
point_positions[cluster].append(Vector2(x_coordinates[y]+origin.x,origin.y-y_coordinates[cluster][y]))
|
||||||
|
|
||||||
|
func redraw():
|
||||||
|
build_chart()
|
||||||
|
calculate_pass()
|
||||||
|
calculate_coordinates()
|
||||||
|
update()
|
||||||
|
|
||||||
|
func _draw():
|
||||||
|
clear_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)
|
||||||
|
|
||||||
|
if invert_xy:
|
||||||
|
for function_point in point_values[_function].size():
|
||||||
|
var point : Control = point_node.instance()
|
||||||
|
point.connect("_mouse_entered",self,"show_data",[point])
|
||||||
|
point.connect("_mouse_exited",self,"hide_data")
|
||||||
|
point.create_point(function_colors[_function], Color.white, point_positions[_function][function_point],point.format_value(point_values[_function][function_point],false,true),x_datas[_function])
|
||||||
|
PointContainer.add_child(point)
|
||||||
|
if function_point > 0:
|
||||||
|
draw_line(point_positions[_function][function_point-1],point_positions[_function][function_point],function_colors[_function],2,true)
|
||||||
|
else:
|
||||||
|
for function_point in point_values[_function].size():
|
||||||
|
var point : Control = point_node.instance()
|
||||||
|
point.connect("_mouse_entered",self,"show_data",[point])
|
||||||
|
point.connect("_mouse_exited",self,"hide_data")
|
||||||
|
point.create_point(function_colors[_function], Color.white, point_positions[_function][function_point],point.format_value(point_values[_function][function_point],false,true),y_labels[_function])
|
||||||
|
PointContainer.add_child(point)
|
||||||
|
if function_point > 0:
|
||||||
|
draw_line(point_positions[_function][function_point-1],point_positions[_function][function_point],function_colors[_function],2,true)
|
||||||
|
|
||||||
|
func create_legend():
|
||||||
|
legend.clear()
|
||||||
|
for function in functions:
|
||||||
|
var function_legend = FunctionLegend.instance()
|
||||||
|
var f_name : String
|
||||||
|
if invert_xy:
|
||||||
|
f_name = x_datas[function]
|
||||||
|
else:
|
||||||
|
f_name = y_labels[function]
|
||||||
|
var legend_font : Font
|
||||||
|
if font != null:
|
||||||
|
legend_font = font
|
||||||
|
if bold_font != null:
|
||||||
|
legend_font = bold_font
|
||||||
|
function_legend.create_legend(f_name,function_colors[function],bold_font,font_color)
|
||||||
|
legend.append(function_legend)
|
||||||
|
|
||||||
|
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)
|
||||||
|
draw_string(font,point+Vector2(-const_width/2*x_chors[p].length(),font_size+const_height),x_chors[p],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():
|
||||||
|
draw_line(origin,SIZE-Vector2(0,OFFSET.y),outline_color,1,true)
|
||||||
|
draw_line(origin,Vector2(OFFSET.x,0),outline_color,1,true)
|
||||||
|
draw_line(Vector2(OFFSET.x,0),Vector2(SIZE.x,0),outline_color,1,true)
|
||||||
|
draw_line(Vector2(SIZE.x,0),SIZE-Vector2(0,OFFSET.y),outline_color,1,true)
|
||||||
|
|
||||||
|
var can_grab_x : bool = false
|
||||||
|
var can_grab_y : bool = false
|
||||||
|
var can_move : bool = false
|
||||||
|
var range_mouse : float = 7
|
||||||
|
|
||||||
|
#func _input(event):
|
||||||
|
# if not can_grab_x and (event.position.x > (SIZE.x-range_mouse + rect_position.x) and event.position.x < (SIZE.x+range_mouse + rect_position.x)) :
|
||||||
|
# set_default_cursor_shape(Control.CURSOR_HSIZE)
|
||||||
|
# if Input.is_action_pressed("mouse_left"):
|
||||||
|
# can_grab_x = true
|
||||||
|
#
|
||||||
|
# if Input.is_action_just_released("mouse_left") and can_grab_x:
|
||||||
|
# can_grab_x = false
|
||||||
|
#
|
||||||
|
# if not can_grab_y and (event.position.y > ( rect_position.y + origin.y-range_mouse) and event.position.y < (rect_position.y+ origin.y+range_mouse)) :
|
||||||
|
# set_default_cursor_shape(Control.CURSOR_VSIZE)
|
||||||
|
# if Input.is_action_pressed("mouse_left"):
|
||||||
|
# can_grab_y = true
|
||||||
|
#
|
||||||
|
# if Input.is_action_just_released("mouse_left") and can_grab_y:
|
||||||
|
# can_grab_y = false
|
||||||
|
#
|
||||||
|
# if (event.position.x > SIZE.x-range_mouse+rect_position.x and event.position.x < SIZE.x+range_mouse + rect_position.x) and (event.position.y > rect_position.y+origin.y-range_mouse and event.position.y < rect_position.y+origin.y+range_mouse):
|
||||||
|
# set_default_cursor_shape(Control.CURSOR_FDIAGSIZE)
|
||||||
|
# if not (event.position.x > SIZE.x-range_mouse+rect_position.x and event.position.x < SIZE.x+range_mouse + rect_position.x) and not (event.position.y > rect_position.y+ origin.y-range_mouse and event.position.y < rect_position.y+origin.y+range_mouse ):
|
||||||
|
# set_default_cursor_shape(Control.CURSOR_ARROW)
|
||||||
|
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
if can_grab_x:
|
||||||
|
PointData.hide()
|
||||||
|
get_parent().rect_size.x = get_global_mouse_position().x - rect_position.x
|
||||||
|
redraw()
|
||||||
|
|
||||||
|
if can_grab_y:
|
||||||
|
PointData.hide()
|
||||||
|
get_parent().rect_size.y = get_global_mouse_position().y - rect_position.y + OFFSET.y
|
||||||
|
redraw()
|
||||||
|
|
||||||
|
func show_data(point):
|
||||||
|
PointData.update_datas(point)
|
||||||
|
PointData.show()
|
||||||
|
|
||||||
|
func hide_data():
|
||||||
|
PointData.hide()
|
||||||
|
|
||||||
|
func clear_points():
|
||||||
|
if Points.get_children():
|
||||||
|
for function in Points.get_children():
|
||||||
|
function.queue_free()
|
||||||
|
for legend in Legend.get_children():
|
||||||
|
legend.queue_free()
|
||||||
|
|
||||||
|
func set_legend(l : Array):
|
||||||
|
legend = l
|
||||||
|
|
||||||
|
func get_legend():
|
||||||
|
return legend
|
||||||
|
|
||||||
|
func invert_chart():
|
||||||
|
invert_xy = !invert_xy
|
||||||
|
count_functions()
|
||||||
|
redraw()
|
||||||
|
create_legend()
|
||||||
|
|
||||||
|
func count_functions():
|
||||||
|
if are_values_columns:
|
||||||
|
if not invert_xy:
|
||||||
|
functions = datas[0].size()-1
|
||||||
|
else:
|
||||||
|
functions = datas.size()-1
|
||||||
|
else:
|
||||||
|
if invert_xy:
|
||||||
|
functions = datas[0].size()-1
|
||||||
|
else:
|
||||||
|
functions = datas.size()-1
|
||||||
|
|
||||||
|
func apply_template(template_name : String):
|
||||||
|
if Engine.editor_hint:
|
||||||
|
if template_name!=null and template_name!="":
|
||||||
|
template = template_name
|
||||||
|
var custom_template = get_parent().templates[template_name.to_lower()]
|
||||||
|
function_colors[0] = Color(custom_template.function_color)
|
||||||
|
v_lines_color = Color(custom_template.v_lines_color)
|
||||||
|
h_lines_color = Color(custom_template.h_lines_color)
|
||||||
|
outline_color = Color(custom_template.outline_color)
|
||||||
|
font_color = Color(custom_template.font_color)
|
||||||
|
property_list_changed_notify()
|
49
addons/easy_charts/LineChart/LineChart.tscn
Normal file
49
addons/easy_charts/LineChart/LineChart.tscn
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/easy_charts/Utilities/Point/PointData.tscn" type="PackedScene" id=1]
|
||||||
|
[ext_resource path="res://addons/easy_charts/LineChart/LineChart.gd" type="Script" id=4]
|
||||||
|
|
||||||
|
[sub_resource type="Theme" id=1]
|
||||||
|
|
||||||
|
[node name="LineChart" type="Control"]
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
rect_min_size = Vector2( 70, 50 )
|
||||||
|
mouse_filter = 2
|
||||||
|
script = ExtResource( 4 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Background" type="ColorRect" parent="."]
|
||||||
|
visible = false
|
||||||
|
show_behind_parent = true
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
color = Color( 0.882353, 0.882353, 0.882353, 1 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Points" type="Control" parent="."]
|
||||||
|
margin_right = 40.0
|
||||||
|
margin_bottom = 40.0
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Legend" type="HBoxContainer" parent="."]
|
||||||
|
visible = false
|
||||||
|
margin_right = 1024.0
|
||||||
|
margin_bottom = 64.0
|
||||||
|
alignment = 1
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="PointData" parent="." instance=ExtResource( 1 )]
|
||||||
|
|
||||||
|
[node name="PointData" parent="PointData" index="0"]
|
||||||
|
theme = SubResource( 1 )
|
||||||
|
|
||||||
|
[editable path="PointData"]
|
494
addons/easy_charts/LineChart2D/LineChart2D.gd
Normal file
494
addons/easy_charts/LineChart2D/LineChart2D.gd
Normal file
@ -0,0 +1,494 @@
|
|||||||
|
tool
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
"""
|
||||||
|
[Linechart2D] - General purpose node for Line Charts
|
||||||
|
|
||||||
|
A line chart or line plot or line graph or curve chart is a type of chart which
|
||||||
|
displays information as a series of data points called 'markers'
|
||||||
|
connected by straight line segments.
|
||||||
|
It is a basic type of chart common in many fields. It is similar to a scatter plot
|
||||||
|
except that the measurement points are ordered (typically by their x-axis value)
|
||||||
|
and joined with straight line segments.
|
||||||
|
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.
|
||||||
|
|
||||||
|
/ source : Wikipedia /
|
||||||
|
"""
|
||||||
|
|
||||||
|
onready var FunctionsTween : Tween = $FunctionsTween
|
||||||
|
onready var OutlinesTween : Tween = $OutlinesTween
|
||||||
|
onready var GridTween : Tween = $GridTween
|
||||||
|
onready var Functions : Node2D = $Functions
|
||||||
|
onready var PointData = $PointData/PointData
|
||||||
|
onready var Outlines : Line2D = $Outlines
|
||||||
|
onready var Grid : Node2D = $Grid
|
||||||
|
|
||||||
|
var point_node : PackedScene = preload("../Utilities/Point/Point.tscn")
|
||||||
|
var FunctionLegend : PackedScene = preload("../Utilities/Legend/FunctionLegend.tscn")
|
||||||
|
|
||||||
|
var font_size : float = 16
|
||||||
|
var const_height : float = font_size/2*font_size/20
|
||||||
|
var const_width : float = font_size/2
|
||||||
|
|
||||||
|
var OFFSET : Vector2 = Vector2(0,0)
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------#
|
||||||
|
var origin : Vector2
|
||||||
|
|
||||||
|
# actual distance between x and y values
|
||||||
|
var x_pass : float
|
||||||
|
var y_pass : float
|
||||||
|
|
||||||
|
# vertical distance between y consecutive points used for intervals
|
||||||
|
var v_dist : float
|
||||||
|
|
||||||
|
# quantization, representing the interval in which values will be displayed
|
||||||
|
var x_decim : float = 1.0
|
||||||
|
|
||||||
|
# define values on x an y axis
|
||||||
|
var x_chors : Array
|
||||||
|
var y_chors : Array
|
||||||
|
|
||||||
|
# actual coordinates of points (in pixel)
|
||||||
|
var x_coordinates : Array
|
||||||
|
var y_coordinates : Array
|
||||||
|
|
||||||
|
# datas contained in file
|
||||||
|
var datas : Array
|
||||||
|
|
||||||
|
# amount of functions to represent
|
||||||
|
var functions : int = 0
|
||||||
|
|
||||||
|
|
||||||
|
# database values
|
||||||
|
var x_datas : Array
|
||||||
|
var y_datas : Array
|
||||||
|
|
||||||
|
# labels displayed on chart
|
||||||
|
var x_label : String
|
||||||
|
var y_labels : Array
|
||||||
|
|
||||||
|
# actual values of point, from the database
|
||||||
|
var point_values : Array
|
||||||
|
|
||||||
|
# actual position of points in pixel
|
||||||
|
var point_positions : Array
|
||||||
|
|
||||||
|
var legend : Array setget set_legend,get_legend
|
||||||
|
|
||||||
|
# ---------------------
|
||||||
|
export (Vector2) var SIZE : Vector2 = Vector2()
|
||||||
|
export (String, FILE) var source : String = ""
|
||||||
|
export (String) var delimiter : String = ";"
|
||||||
|
|
||||||
|
export (bool) var are_values_columns : bool = false
|
||||||
|
export (bool) var invert_xy : bool = false
|
||||||
|
|
||||||
|
export (int,0,100) var x_values : int = 0
|
||||||
|
|
||||||
|
export (float,1,20,0.5) var column_width : float = 10
|
||||||
|
export (float,0,10,0.5) var column_gap : float = 2
|
||||||
|
|
||||||
|
export (float,0,10) var y_decim : float = 5.0
|
||||||
|
export (PoolColorArray) var function_colors = [Color("#1e1e1e")]
|
||||||
|
|
||||||
|
export (bool) var boxed : bool = true
|
||||||
|
export (Color) var v_lines_color : Color = Color("#cacaca")
|
||||||
|
export (Color) var h_lines_color : Color = Color("#cacaca")
|
||||||
|
export (Color) var outline_color : Color = Color("#1e1e1e")
|
||||||
|
export (float,0.01,1) var drawing_duration : float = 0.3
|
||||||
|
export (Font) var font : Font
|
||||||
|
export (Font) var bold_font : Font
|
||||||
|
export (Color) var font_color : Color = Color("#1e1e1e")
|
||||||
|
export (String,"Default","Clean","Gradient","Minimal","Invert") var template : String = "Default" setget apply_template
|
||||||
|
|
||||||
|
var templates : Dictionary = {}
|
||||||
|
|
||||||
|
signal chart_plotted(chart)
|
||||||
|
signal point_pressed(point)
|
||||||
|
|
||||||
|
func _point_plotted():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _script_changed():
|
||||||
|
_ready()
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
if Engine.editor_hint:
|
||||||
|
Outlines.set_default_color(outline_color)
|
||||||
|
Grid.get_node("VLine").set_default_color(v_lines_color)
|
||||||
|
Grid.get_node("HLine").set_default_color(h_lines_color)
|
||||||
|
if function_colors.size():
|
||||||
|
Functions.get_node("Function").set_default_color(function_colors[0])
|
||||||
|
else:
|
||||||
|
Functions.get_node("Function").set_default_color(Color("#1e1e1e"))
|
||||||
|
|
||||||
|
if SIZE!=Vector2():
|
||||||
|
build_chart()
|
||||||
|
Outlines.set_point_position(0,Vector2(origin.x,0))
|
||||||
|
Outlines.set_point_position(1,Vector2(SIZE.x,0))
|
||||||
|
Outlines.set_point_position(2,Vector2(SIZE.x,origin.y))
|
||||||
|
Outlines.set_point_position(3,origin)
|
||||||
|
Outlines.set_point_position(4,Vector2(origin.x,0))
|
||||||
|
|
||||||
|
Grid.get_node("VLine").set_point_position(0,Vector2((OFFSET.x+SIZE.x)/2,0))
|
||||||
|
Grid.get_node("VLine").set_point_position(1,Vector2((OFFSET.x+SIZE.x)/2,origin.y))
|
||||||
|
Grid.get_node("HLine").set_point_position(0,Vector2(origin.x,origin.y/2))
|
||||||
|
Grid.get_node("HLine").set_point_position(1,Vector2(SIZE.x,origin.y/2))
|
||||||
|
|
||||||
|
if function_colors.size():
|
||||||
|
Functions.get_node("Function").set_point_position(0,origin)
|
||||||
|
Functions.get_node("Function").set_point_position(1,Vector2(SIZE.x,0))
|
||||||
|
|
||||||
|
#func _ready():
|
||||||
|
# plot_line_chart("res://ChartNode/datas2.csv",";",false,0,invert_xy,function_colors,drawing_duration,SIZE)
|
||||||
|
|
||||||
|
func clear():
|
||||||
|
Outlines.points = []
|
||||||
|
Grid.get_node("HLine").queue_free()
|
||||||
|
Grid.get_node("VLine").queue_free()
|
||||||
|
Functions.get_node("Function").queue_free()
|
||||||
|
|
||||||
|
func load_font():
|
||||||
|
if font != null:
|
||||||
|
font_size = font.get_height()
|
||||||
|
var theme : Theme = Theme.new()
|
||||||
|
theme.set_default_font(font)
|
||||||
|
PointData.set_theme(theme)
|
||||||
|
if bold_font != null:
|
||||||
|
PointData.Data.set("custom_fonts/font",bold_font)
|
||||||
|
|
||||||
|
func _plot(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_values_ : int):
|
||||||
|
randomize()
|
||||||
|
|
||||||
|
clear()
|
||||||
|
|
||||||
|
load_font()
|
||||||
|
PointData.hide()
|
||||||
|
|
||||||
|
datas = read_datas(source_,delimiter_)
|
||||||
|
count_functions()
|
||||||
|
structure_datas(datas,are_values_columns_,x_values_)
|
||||||
|
build_chart()
|
||||||
|
calculate_pass()
|
||||||
|
calculate_coordinates()
|
||||||
|
calculate_colors()
|
||||||
|
draw_chart()
|
||||||
|
|
||||||
|
create_legend()
|
||||||
|
emit_signal("chart_plotted", self)
|
||||||
|
|
||||||
|
func plot():
|
||||||
|
randomize()
|
||||||
|
|
||||||
|
clear()
|
||||||
|
|
||||||
|
load_font()
|
||||||
|
PointData.hide()
|
||||||
|
|
||||||
|
if source == "" or source == null:
|
||||||
|
Utilities._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_datas(source,delimiter)
|
||||||
|
count_functions()
|
||||||
|
structure_datas(datas,are_values_columns,x_values)
|
||||||
|
build_chart()
|
||||||
|
calculate_pass()
|
||||||
|
calculate_coordinates()
|
||||||
|
calculate_colors()
|
||||||
|
draw_chart()
|
||||||
|
|
||||||
|
create_legend()
|
||||||
|
emit_signal("chart_plotted", self)
|
||||||
|
|
||||||
|
func calculate_colors():
|
||||||
|
if function_colors.empty() or function_colors.size() < functions:
|
||||||
|
for function in functions:
|
||||||
|
function_colors.append(Color("#1e1e1e"))
|
||||||
|
|
||||||
|
func draw_chart():
|
||||||
|
draw_outlines()
|
||||||
|
draw_v_grid()
|
||||||
|
draw_h_grid()
|
||||||
|
draw_functions()
|
||||||
|
|
||||||
|
func draw_outlines():
|
||||||
|
if boxed:
|
||||||
|
Outlines.set_default_color(outline_color)
|
||||||
|
OutlinesTween.interpolate_method(Outlines,"add_point",
|
||||||
|
Vector2(origin.x,0),Vector2(SIZE.x,0),drawing_duration*0.5,Tween.TRANS_QUINT,Tween.EASE_OUT)
|
||||||
|
OutlinesTween.start()
|
||||||
|
yield(OutlinesTween,"tween_all_completed")
|
||||||
|
OutlinesTween.interpolate_method(Outlines,"add_point",
|
||||||
|
Vector2(SIZE.x,0),Vector2(SIZE.x,origin.y),drawing_duration*0.5,Tween.TRANS_QUINT,Tween.EASE_OUT)
|
||||||
|
OutlinesTween.start()
|
||||||
|
yield(OutlinesTween,"tween_all_completed")
|
||||||
|
OutlinesTween.interpolate_method(Outlines,"add_point",
|
||||||
|
Vector2(SIZE.x,origin.y),origin,drawing_duration*0.5,Tween.TRANS_QUINT,Tween.EASE_OUT)
|
||||||
|
OutlinesTween.start()
|
||||||
|
yield(OutlinesTween,"tween_all_completed")
|
||||||
|
OutlinesTween.interpolate_method(Outlines,"add_point",
|
||||||
|
origin,Vector2(origin.x,0),drawing_duration*0.5,Tween.TRANS_QUINT,Tween.EASE_OUT)
|
||||||
|
OutlinesTween.start()
|
||||||
|
yield(OutlinesTween,"tween_all_completed")
|
||||||
|
|
||||||
|
func draw_v_grid():
|
||||||
|
for p in x_chors.size():
|
||||||
|
var point : Vector2 = origin+Vector2((p)*x_pass,0)
|
||||||
|
var v_grid : Line2D = Line2D.new()
|
||||||
|
Grid.add_child(v_grid)
|
||||||
|
v_grid.set_width(1)
|
||||||
|
v_grid.set_default_color(v_lines_color)
|
||||||
|
add_label(point+Vector2(-const_width/2*x_chors[p].length(),font_size/2), x_chors[p])
|
||||||
|
GridTween.interpolate_method(v_grid,"add_point",point,point-Vector2(0,SIZE.y-OFFSET.y),drawing_duration/(x_chors.size()),Tween.TRANS_EXPO,Tween.EASE_OUT)
|
||||||
|
GridTween.start()
|
||||||
|
yield(GridTween,"tween_all_completed")
|
||||||
|
|
||||||
|
func draw_h_grid():
|
||||||
|
for p in y_chors.size():
|
||||||
|
var point : Vector2 = origin-Vector2(0,(p)*y_pass)
|
||||||
|
var h_grid : Line2D = Line2D.new()
|
||||||
|
Grid.add_child(h_grid)
|
||||||
|
h_grid.set_width(1)
|
||||||
|
h_grid.set_default_color(h_lines_color)
|
||||||
|
add_label(point-Vector2(y_chors[p].length()*const_width+font_size,font_size/2), y_chors[p])
|
||||||
|
GridTween.interpolate_method(h_grid,"add_point",point,Vector2(SIZE.x,point.y),drawing_duration/(y_chors.size()),Tween.TRANS_EXPO,Tween.EASE_OUT)
|
||||||
|
GridTween.start()
|
||||||
|
yield(GridTween,"tween_all_completed")
|
||||||
|
|
||||||
|
|
||||||
|
func add_label(point : Vector2, text : String):
|
||||||
|
var lbl : Label = Label.new()
|
||||||
|
if font != null:
|
||||||
|
lbl.set("custom_fonts/font",font)
|
||||||
|
lbl.set("custom_colors/font_color",font_color)
|
||||||
|
Grid.add_child(lbl)
|
||||||
|
lbl.rect_position = point
|
||||||
|
lbl.set_text(text)
|
||||||
|
|
||||||
|
func draw_functions():
|
||||||
|
for function in point_positions.size():
|
||||||
|
draw_function(function,point_positions[function])
|
||||||
|
|
||||||
|
func draw_function(f_index : int, function : Array):
|
||||||
|
var line : Line2D = Line2D.new()
|
||||||
|
var backline : Line2D = Line2D.new()
|
||||||
|
construct_line(line,backline,f_index,function)
|
||||||
|
var pointv : Control
|
||||||
|
for point in function.size():
|
||||||
|
pointv = point_node.instance()
|
||||||
|
line.add_child(pointv)
|
||||||
|
pointv.connect("_mouse_entered",self,"show_data",[pointv])
|
||||||
|
pointv.connect("_mouse_exited",self,"hide_data")
|
||||||
|
pointv.connect("_point_pressed",self,"point_pressed")
|
||||||
|
pointv.create_point(function_colors[f_index], Color.white, function[point],pointv.format_value(point_values[f_index][point],false,true),(x_datas[f_index] if invert_xy else y_labels[f_index]))
|
||||||
|
if point < function.size()-1:
|
||||||
|
FunctionsTween.interpolate_method(line,"add_point",function[point],function[point+1],drawing_duration/function.size(),Tween.TRANS_QUINT,Tween.EASE_OUT)
|
||||||
|
# FunctionsTween.interpolate_method(backline,"add_point",function[point],function[point+1],drawing_duration/function.size(),Tween.TRANS_QUINT,Tween.EASE_OUT)
|
||||||
|
FunctionsTween.start()
|
||||||
|
yield(FunctionsTween,"tween_all_completed")
|
||||||
|
|
||||||
|
func construct_line(line : Line2D, backline : Line2D, f_index : int, function : Array):
|
||||||
|
var midtone = Color(Color(function_colors[f_index]).r,Color(function_colors[f_index]).g,Color(function_colors[f_index]).b,Color(function_colors[f_index]).a/2)
|
||||||
|
backline.set_width(3)
|
||||||
|
backline.set_default_color(midtone)
|
||||||
|
backline.antialiased = true
|
||||||
|
Functions.add_child(backline)
|
||||||
|
line.set_width(4)
|
||||||
|
line.set_default_color(function_colors[f_index])
|
||||||
|
line.antialiased = true
|
||||||
|
Functions.add_child(line)
|
||||||
|
|
||||||
|
func read_datas(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
|
||||||
|
|
||||||
|
func structure_datas(database : Array, are_values_columns : bool, x_values : int):
|
||||||
|
# @x_values 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:
|
||||||
|
x_datas.append(database[row][column])
|
||||||
|
else:
|
||||||
|
if row != 0:
|
||||||
|
t_vals.append(float(database[row][column]))
|
||||||
|
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())
|
||||||
|
false:
|
||||||
|
for row in database.size():
|
||||||
|
if row == x_values:
|
||||||
|
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
|
||||||
|
|
||||||
|
var to_order : Array
|
||||||
|
for cluster in y_datas.size():
|
||||||
|
# define x_chors and y_chors
|
||||||
|
var margin = y_datas[cluster][y_datas[cluster].size()-1]
|
||||||
|
to_order.append(margin)
|
||||||
|
|
||||||
|
to_order.sort()
|
||||||
|
var margin = to_order.pop_back()
|
||||||
|
v_dist = y_decim * pow(10.0,str(margin).length()-2)
|
||||||
|
var multi = 0
|
||||||
|
var p = v_dist*multi
|
||||||
|
y_chors.append(p as String)
|
||||||
|
while p < margin:
|
||||||
|
multi+=1
|
||||||
|
p = v_dist*multi
|
||||||
|
y_chors.append(p as String)
|
||||||
|
|
||||||
|
func build_chart():
|
||||||
|
origin = Vector2(OFFSET.x,SIZE.y-OFFSET.y)
|
||||||
|
|
||||||
|
func calculate_pass():
|
||||||
|
if invert_xy:
|
||||||
|
x_chors = y_labels as PoolStringArray
|
||||||
|
else:
|
||||||
|
x_chors = x_datas as PoolStringArray
|
||||||
|
# calculate distance in pixel between 2 consecutive values/datas
|
||||||
|
x_pass = (SIZE.x - OFFSET.x) / (x_chors.size()-1)
|
||||||
|
y_pass = origin.y / (y_chors.size()-1)
|
||||||
|
|
||||||
|
func calculate_coordinates():
|
||||||
|
x_coordinates.clear()
|
||||||
|
y_coordinates.clear()
|
||||||
|
point_values.clear()
|
||||||
|
point_positions.clear()
|
||||||
|
|
||||||
|
if invert_xy:
|
||||||
|
for column in y_datas[0].size():
|
||||||
|
var single_coordinates : Array
|
||||||
|
for row in y_datas:
|
||||||
|
single_coordinates.append((row[column]*y_pass)/v_dist)
|
||||||
|
y_coordinates.append(single_coordinates)
|
||||||
|
else:
|
||||||
|
for cluster in y_datas:
|
||||||
|
var single_coordinates : Array
|
||||||
|
for value in cluster.size():
|
||||||
|
single_coordinates.append((cluster[value]*y_pass)/v_dist)
|
||||||
|
y_coordinates.append(single_coordinates)
|
||||||
|
|
||||||
|
for x in x_chors.size():
|
||||||
|
x_coordinates.append(x_pass*x)
|
||||||
|
|
||||||
|
for f in functions:
|
||||||
|
point_values.append([])
|
||||||
|
point_positions.append([])
|
||||||
|
|
||||||
|
if invert_xy:
|
||||||
|
for function in y_coordinates.size()-1:
|
||||||
|
for function_value in y_coordinates[function].size():
|
||||||
|
point_positions[function].append(Vector2(x_coordinates[function_value]+origin.x,origin.y-y_coordinates[function][function_value]))
|
||||||
|
point_values[function].append([x_chors[function_value],y_datas[function_value][function]])
|
||||||
|
else:
|
||||||
|
for cluster in y_coordinates.size():
|
||||||
|
for y in y_coordinates[cluster].size():
|
||||||
|
point_values[cluster].append([x_chors[y],y_datas[cluster][y]])
|
||||||
|
point_positions[cluster].append(Vector2(x_coordinates[y]+origin.x,origin.y-y_coordinates[cluster][y]))
|
||||||
|
|
||||||
|
func redraw():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func invert_chart():
|
||||||
|
invert_xy = !invert_xy
|
||||||
|
count_functions()
|
||||||
|
redraw()
|
||||||
|
create_legend()
|
||||||
|
|
||||||
|
|
||||||
|
func count_functions():
|
||||||
|
if are_values_columns:
|
||||||
|
if not invert_xy:
|
||||||
|
functions = datas[0].size()-1
|
||||||
|
else:
|
||||||
|
functions = datas.size()-1
|
||||||
|
else:
|
||||||
|
if invert_xy:
|
||||||
|
functions = datas[0].size()-1
|
||||||
|
else:
|
||||||
|
functions = datas.size()-1
|
||||||
|
|
||||||
|
func show_data(point):
|
||||||
|
PointData.update_datas(point)
|
||||||
|
PointData.show()
|
||||||
|
|
||||||
|
func hide_data():
|
||||||
|
PointData.hide()
|
||||||
|
|
||||||
|
func clear_points():
|
||||||
|
function_colors.clear()
|
||||||
|
if Functions.get_children():
|
||||||
|
for function in Functions.get_children():
|
||||||
|
function.queue_free()
|
||||||
|
|
||||||
|
func create_legend():
|
||||||
|
legend.clear()
|
||||||
|
for function in functions:
|
||||||
|
var function_legend = FunctionLegend.instance()
|
||||||
|
var f_name : String
|
||||||
|
if invert_xy:
|
||||||
|
f_name = x_datas[function]
|
||||||
|
else:
|
||||||
|
f_name = y_labels[function]
|
||||||
|
var legend_font : Font
|
||||||
|
if font != null:
|
||||||
|
legend_font = font
|
||||||
|
if bold_font != null:
|
||||||
|
legend_font = bold_font
|
||||||
|
function_legend.create_legend(f_name,function_colors[function],bold_font,font_color)
|
||||||
|
legend.append(function_legend)
|
||||||
|
|
||||||
|
func set_legend(l : Array):
|
||||||
|
legend = l
|
||||||
|
|
||||||
|
func get_legend() -> Array:
|
||||||
|
return legend
|
||||||
|
|
||||||
|
func apply_template(template_name : String):
|
||||||
|
if Engine.editor_hint:
|
||||||
|
if template_name!=null and template_name!="":
|
||||||
|
template = template_name
|
||||||
|
var custom_template = templates[template_name.to_lower()]
|
||||||
|
function_colors.resize(0)
|
||||||
|
for color in custom_template.function_colors:
|
||||||
|
function_colors.append(Color(color))
|
||||||
|
v_lines_color = Color(custom_template.v_lines_color)
|
||||||
|
h_lines_color = Color(custom_template.h_lines_color)
|
||||||
|
outline_color = Color(custom_template.outline_color)
|
||||||
|
font_color = Color(custom_template.font_color)
|
||||||
|
property_list_changed_notify()
|
||||||
|
|
||||||
|
func point_pressed(point : Point):
|
||||||
|
emit_signal("point_pressed",point)
|
||||||
|
|
||||||
|
func _enter_tree():
|
||||||
|
templates = Utilities._load_templates()
|
49
addons/easy_charts/LineChart2D/LineChart2D.tscn
Normal file
49
addons/easy_charts/LineChart2D/LineChart2D.tscn
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
[gd_scene load_steps=3 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/easy_charts/LineChart2D/LineChart2D.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://addons/easy_charts/Utilities/Point/PointData.tscn" type="PackedScene" id=2]
|
||||||
|
|
||||||
|
[node name="LineChart2D" type="Node2D"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_group_": true
|
||||||
|
}
|
||||||
|
font_color = Color( 0.137255, 0.137255, 0.137255, 1 )
|
||||||
|
|
||||||
|
[node name="Grid" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
[node name="VLine" type="Line2D" parent="Grid"]
|
||||||
|
points = PoolVector2Array( 0, 0, 0, 0 )
|
||||||
|
width = 1.0
|
||||||
|
default_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||||
|
|
||||||
|
[node name="HLine" type="Line2D" parent="Grid"]
|
||||||
|
points = PoolVector2Array( 0, 0, 0, 0 )
|
||||||
|
width = 1.0
|
||||||
|
default_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||||
|
|
||||||
|
[node name="Outlines" type="Line2D" parent="."]
|
||||||
|
points = PoolVector2Array( 0, 0, 2, 0, 2, 2, 0, 2, 0, 0 )
|
||||||
|
width = 2.0
|
||||||
|
default_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||||
|
|
||||||
|
[node name="Functions" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
[node name="Function" type="Line2D" parent="Functions"]
|
||||||
|
points = PoolVector2Array( 0, 0, 0, 0 )
|
||||||
|
width = 5.0
|
||||||
|
default_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||||
|
|
||||||
|
[node name="FunctionsTween" type="Tween" parent="."]
|
||||||
|
|
||||||
|
[node name="OutlinesTween" type="Tween" parent="."]
|
||||||
|
|
||||||
|
[node name="GridTween" type="Tween" parent="."]
|
||||||
|
|
||||||
|
[node name="PointData" parent="." instance=ExtResource( 2 )]
|
||||||
|
|
||||||
|
[node name="PointData" parent="PointData" index="0"]
|
||||||
|
visible = false
|
||||||
|
[connection signal="script_changed" from="." to="." method="_script_changed"]
|
||||||
|
|
||||||
|
[editable path="PointData"]
|
108
addons/easy_charts/LineChart2D/LineChart2D.tscn.depren
Normal file
108
addons/easy_charts/LineChart2D/LineChart2D.tscn.depren
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/easy_charts/LineChart2D/LineChart2D.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://addons/easy_charts/Utilities/Point/PointData.gd" type="Script" id=3]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id=1]
|
||||||
|
content_margin_left = 8.0
|
||||||
|
content_margin_right = 8.0
|
||||||
|
content_margin_top = 5.0
|
||||||
|
content_margin_bottom = 5.0
|
||||||
|
bg_color = Color( 1, 1, 1, 0 )
|
||||||
|
border_width_left = 2
|
||||||
|
border_width_top = 2
|
||||||
|
border_width_right = 2
|
||||||
|
border_width_bottom = 2
|
||||||
|
border_color = Color( 1, 1, 1, 1 )
|
||||||
|
corner_radius_top_left = 5
|
||||||
|
corner_radius_top_right = 5
|
||||||
|
corner_radius_bottom_right = 5
|
||||||
|
corner_radius_bottom_left = 5
|
||||||
|
corner_detail = 20
|
||||||
|
|
||||||
|
[node name="LineChart2D" type="Node2D"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
drawing_duration = 0.3
|
||||||
|
font_color = Color( 0.137255, 0.137255, 0.137255, 1 )
|
||||||
|
|
||||||
|
[node name="Grid" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
[node name="VLine" type="Line2D" parent="Grid"]
|
||||||
|
points = PoolVector2Array( 0, 0, 0, 0 )
|
||||||
|
width = 1.0
|
||||||
|
default_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||||
|
|
||||||
|
[node name="HLine" type="Line2D" parent="Grid"]
|
||||||
|
points = PoolVector2Array( 0, 0, 0, 0 )
|
||||||
|
width = 1.0
|
||||||
|
default_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||||
|
|
||||||
|
[node name="Outlines" type="Line2D" parent="."]
|
||||||
|
points = PoolVector2Array( 0, 0, 2, 0, 2, 2, 0, 2, 0, 0 )
|
||||||
|
width = 2.0
|
||||||
|
default_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||||
|
|
||||||
|
[node name="Functions" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
[node name="Function" type="Line2D" parent="Functions"]
|
||||||
|
points = PoolVector2Array( 0, 0, 0, 0 )
|
||||||
|
width = 2.0
|
||||||
|
default_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||||
|
|
||||||
|
[node name="FunctionsTween" type="Tween" parent="."]
|
||||||
|
|
||||||
|
[node name="OutlinesTween" type="Tween" parent="."]
|
||||||
|
|
||||||
|
[node name="GridTween" type="Tween" parent="."]
|
||||||
|
|
||||||
|
[node name="UI" type="CanvasLayer" parent="."]
|
||||||
|
|
||||||
|
[node name="PointData" type="PanelContainer" parent="UI"]
|
||||||
|
margin_right = 67.0
|
||||||
|
margin_bottom = 38.0
|
||||||
|
mouse_filter = 2
|
||||||
|
custom_styles/panel = SubResource( 1 )
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="PointData" type="VBoxContainer" parent="UI/PointData"]
|
||||||
|
margin_left = 8.0
|
||||||
|
margin_top = 5.0
|
||||||
|
margin_right = 59.0
|
||||||
|
margin_bottom = 36.0
|
||||||
|
custom_constants/separation = 3
|
||||||
|
alignment = 1
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Function" type="Label" parent="UI/PointData/PointData"]
|
||||||
|
margin_right = 51.0
|
||||||
|
margin_bottom = 14.0
|
||||||
|
align = 1
|
||||||
|
valign = 1
|
||||||
|
|
||||||
|
[node name="Value" type="HBoxContainer" parent="UI/PointData/PointData"]
|
||||||
|
margin_top = 17.0
|
||||||
|
margin_right = 51.0
|
||||||
|
margin_bottom = 31.0
|
||||||
|
|
||||||
|
[node name="x" type="Label" parent="UI/PointData/PointData/Value"]
|
||||||
|
margin_right = 39.0
|
||||||
|
margin_bottom = 14.0
|
||||||
|
custom_colors/font_color = Color( 1, 1, 1, 1 )
|
||||||
|
text = "Value:"
|
||||||
|
valign = 1
|
||||||
|
|
||||||
|
[node name="y" type="Label" parent="UI/PointData/PointData/Value"]
|
||||||
|
margin_left = 43.0
|
||||||
|
margin_right = 51.0
|
||||||
|
margin_bottom = 14.0
|
||||||
|
custom_colors/font_color = Color( 1, 1, 1, 1 )
|
||||||
|
text = "0"
|
||||||
|
valign = 1
|
10
addons/easy_charts/ScatterChart3D/ScatterChart3D.gd
Normal file
10
addons/easy_charts/ScatterChart3D/ScatterChart3D.gd
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
extends Spatial
|
||||||
|
|
||||||
|
onready var Point = $Chart/Point
|
||||||
|
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
# var p : MeshInstance = Point.duplicate()
|
||||||
|
# p.transform.origin = Vector3(1,0,1)
|
||||||
|
# add_child(p)
|
||||||
|
pass
|
41
addons/easy_charts/ScatterChart3D/ScatterChart3D.tscn
Normal file
41
addons/easy_charts/ScatterChart3D/ScatterChart3D.tscn
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
[gd_scene load_steps=7 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/easy_charts/ScatterChart3D/ScatterChart3D.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://d4hj068-433f5832-3c04-42db-9c2e-173a26a6970a.png" type="Texture" id=2]
|
||||||
|
|
||||||
|
[sub_resource type="SpatialMaterial" id=1]
|
||||||
|
flags_unshaded = true
|
||||||
|
albedo_texture = ExtResource( 2 )
|
||||||
|
|
||||||
|
[sub_resource type="PlaneMesh" id=2]
|
||||||
|
material = SubResource( 1 )
|
||||||
|
size = Vector2( 20, 20 )
|
||||||
|
|
||||||
|
[sub_resource type="SphereMesh" id=3]
|
||||||
|
|
||||||
|
[sub_resource type="SpatialMaterial" id=4]
|
||||||
|
albedo_color = Color( 0, 1, 0.156863, 1 )
|
||||||
|
|
||||||
|
[node name="ScatterChart3D" type="Spatial"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="MeshInstance" type="MeshInstance" parent="."]
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
|
||||||
|
mesh = SubResource( 2 )
|
||||||
|
material/0 = null
|
||||||
|
|
||||||
|
[node name="Chart" type="Spatial" parent="."]
|
||||||
|
|
||||||
|
[node name="Point" type="MeshInstance" parent="Chart"]
|
||||||
|
mesh = SubResource( 3 )
|
||||||
|
material/0 = SubResource( 4 )
|
||||||
|
|
||||||
|
[node name="Camera" type="Camera" parent="."]
|
||||||
|
transform = Transform( 0.707107, -0.40558, 0.579228, 0, 0.819152, 0.573577, -0.707107, -0.40558, 0.579228, 10, 15, 10 )
|
||||||
|
projection = 1
|
||||||
|
current = true
|
||||||
|
size = 30.0
|
||||||
|
near = 0.01
|
||||||
|
|
||||||
|
[node name="OmniLight" type="OmniLight" parent="."]
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 9, 0 )
|
40
addons/easy_charts/Utilities/ChartContainer.gd
Normal file
40
addons/easy_charts/Utilities/ChartContainer.gd
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
tool
|
||||||
|
extends Container
|
||||||
|
|
||||||
|
var LineChart = preload("LineChart/LineChart.tscn")
|
||||||
|
|
||||||
|
export (String,"None","LineChart","BoxChart") var chart_type : String setget set_type,get_type
|
||||||
|
var chart : Control setget set_chart,get_chart
|
||||||
|
var templates : Dictionary
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
set_chart(get_child(0))
|
||||||
|
var template_file : File = File.new()
|
||||||
|
template_file.open("res://addons/easy_charts/templates.json",File.READ)
|
||||||
|
templates = JSON.parse(template_file.get_as_text()).get_result()
|
||||||
|
template_file.close()
|
||||||
|
|
||||||
|
func set_type(type : String):
|
||||||
|
chart_type = type
|
||||||
|
var new_node
|
||||||
|
if get_children().size():
|
||||||
|
for child in get_children():
|
||||||
|
child.queue_free()
|
||||||
|
if Engine.editor_hint:
|
||||||
|
match type:
|
||||||
|
"LineChart":
|
||||||
|
new_node = LineChart.instance()
|
||||||
|
add_child(new_node)
|
||||||
|
new_node.set_owner(owner)
|
||||||
|
"None":
|
||||||
|
set_chart(null)
|
||||||
|
|
||||||
|
func get_type():
|
||||||
|
return chart_type
|
||||||
|
|
||||||
|
func set_chart(ch : Control):
|
||||||
|
chart = ch
|
||||||
|
|
||||||
|
func get_chart():
|
||||||
|
return chart
|
40
addons/easy_charts/Utilities/ChartContainer2D.gd
Normal file
40
addons/easy_charts/Utilities/ChartContainer2D.gd
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
tool
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
var LineChart = preload("LineChart2D/LineChart2D.tscn")
|
||||||
|
var ColumnChart = preload("BarChart2D/BarChart2D.tscn")
|
||||||
|
|
||||||
|
export (String,"None","LineChart2D","BarChart2D") var chart_type : String setget set_type,get_type
|
||||||
|
var chart : Node2D setget set_chart,get_chart
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
set_chart(get_child(0))
|
||||||
|
|
||||||
|
func set_type(type : String):
|
||||||
|
chart_type = type
|
||||||
|
var new_node
|
||||||
|
if get_children().size():
|
||||||
|
for child in get_children():
|
||||||
|
child.queue_free()
|
||||||
|
if Engine.editor_hint:
|
||||||
|
match type:
|
||||||
|
"LineChart2D":
|
||||||
|
new_node = LineChart.instance()
|
||||||
|
add_child(new_node)
|
||||||
|
new_node.set_owner(owner)
|
||||||
|
"ColumnChart2D":
|
||||||
|
new_node = ColumnChart.instance()
|
||||||
|
add_child(new_node)
|
||||||
|
new_node.set_owner(owner)
|
||||||
|
"None":
|
||||||
|
set_chart(null)
|
||||||
|
|
||||||
|
func get_type():
|
||||||
|
return chart_type
|
||||||
|
|
||||||
|
func set_chart(ch : Node2D):
|
||||||
|
chart = ch
|
||||||
|
|
||||||
|
func get_chart():
|
||||||
|
return chart
|
12
addons/easy_charts/Utilities/Legend/ColorLabel.tscn
Normal file
12
addons/easy_charts/Utilities/Legend/ColorLabel.tscn
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/easy_charts/ChartContainer.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[node name="Control" type="ColorRect"]
|
||||||
|
margin_right = 15.0
|
||||||
|
margin_bottom = 3.0
|
||||||
|
rect_min_size = Vector2( 15, 3 )
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
21
addons/easy_charts/Utilities/Legend/FunctionLegend.gd
Normal file
21
addons/easy_charts/Utilities/Legend/FunctionLegend.gd
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
extends VBoxContainer
|
||||||
|
|
||||||
|
onready var Function : Label = $Function
|
||||||
|
onready var FunctionColor : ColorRect = $Color
|
||||||
|
|
||||||
|
var text : String
|
||||||
|
var color : Color
|
||||||
|
var font_color : Color
|
||||||
|
var font : Font
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
Function.set("custom_fonts/font",font)
|
||||||
|
Function.set("custom_colors/font_color",font_color)
|
||||||
|
Function.set_text(text)
|
||||||
|
FunctionColor.set_frame_color(color)
|
||||||
|
|
||||||
|
func create_legend(text : String, color : Color, font : Font, font_color : Color):
|
||||||
|
self.text = text
|
||||||
|
self.color = color
|
||||||
|
self.font_color = font_color
|
||||||
|
self.font = font
|
28
addons/easy_charts/Utilities/Legend/FunctionLegend.tscn
Normal file
28
addons/easy_charts/Utilities/Legend/FunctionLegend.tscn
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/easy_charts/Utilities/Legend/FunctionLegend.gd" type="Script" id=2]
|
||||||
|
|
||||||
|
[node name="FunctionLegend" type="VBoxContainer"]
|
||||||
|
margin_right = 80.0
|
||||||
|
margin_bottom = 26.0
|
||||||
|
alignment = 1
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Function" type="Label" parent="."]
|
||||||
|
margin_top = 2.0
|
||||||
|
margin_right = 80.0
|
||||||
|
margin_bottom = 16.0
|
||||||
|
custom_colors/font_color = Color( 0.184314, 0.192157, 0.262745, 1 )
|
||||||
|
text = "Function"
|
||||||
|
align = 1
|
||||||
|
valign = 1
|
||||||
|
|
||||||
|
[node name="Color" type="ColorRect" parent="."]
|
||||||
|
margin_top = 20.0
|
||||||
|
margin_right = 80.0
|
||||||
|
margin_bottom = 23.0
|
||||||
|
rect_min_size = Vector2( 15, 3 )
|
||||||
|
color = Color( 0.184314, 0.192157, 0.262745, 1 )
|
80
addons/easy_charts/Utilities/Point/Point.gd
Normal file
80
addons/easy_charts/Utilities/Point/Point.gd
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
extends Control
|
||||||
|
class_name Point
|
||||||
|
|
||||||
|
const OFFSET : Vector2 = Vector2(13,13)
|
||||||
|
var point_value : Array setget set_value,get_value
|
||||||
|
var point_position : Vector2
|
||||||
|
var color : Color
|
||||||
|
var color_outline : Color
|
||||||
|
var function : String
|
||||||
|
|
||||||
|
var mouse_entered : bool = false
|
||||||
|
|
||||||
|
|
||||||
|
signal _mouse_entered()
|
||||||
|
signal _mouse_exited()
|
||||||
|
signal _point_pressed(point)
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
func _draw():
|
||||||
|
if mouse_entered:
|
||||||
|
draw_circle(OFFSET,7,color_outline)
|
||||||
|
draw_circle(OFFSET,5,color)
|
||||||
|
|
||||||
|
func create_point(color : Color, color_outline : Color, position : Vector2, value : Array, function : String):
|
||||||
|
self.color = color
|
||||||
|
self.color_outline = color_outline
|
||||||
|
self.point_position = position
|
||||||
|
self.rect_position = point_position - OFFSET
|
||||||
|
self.point_value = value
|
||||||
|
self.function = function
|
||||||
|
|
||||||
|
func _on_Point_mouse_entered():
|
||||||
|
mouse_entered = true
|
||||||
|
emit_signal("_mouse_entered")
|
||||||
|
update()
|
||||||
|
|
||||||
|
func _on_Point_mouse_exited():
|
||||||
|
mouse_entered = false
|
||||||
|
emit_signal("_mouse_exited")
|
||||||
|
update()
|
||||||
|
|
||||||
|
func format_value(v : Array, format_x : bool, format_y : bool):
|
||||||
|
var x : String = str(v[0])
|
||||||
|
var y : String = str(v[1])
|
||||||
|
|
||||||
|
if format_x:
|
||||||
|
x = format(v[1])
|
||||||
|
if format_y:
|
||||||
|
y = format(v[1])
|
||||||
|
|
||||||
|
return [x,y]
|
||||||
|
|
||||||
|
func format(n):
|
||||||
|
n = str(n)
|
||||||
|
var size = n.length()
|
||||||
|
var s
|
||||||
|
for i in range(size):
|
||||||
|
if((size - i) % 3 == 0 and i > 0):
|
||||||
|
s = str(s,",", n[i])
|
||||||
|
else:
|
||||||
|
s = str(s,n[i])
|
||||||
|
|
||||||
|
return s.replace("Null","")
|
||||||
|
|
||||||
|
|
||||||
|
func _on_Point_gui_input(event):
|
||||||
|
if event is InputEventMouseButton:
|
||||||
|
if event.is_pressed():
|
||||||
|
if event.button_index == 1:
|
||||||
|
emit_signal("_point_pressed",self)
|
||||||
|
|
||||||
|
func set_value( v : Array = [] ) :
|
||||||
|
point_value = v
|
||||||
|
|
||||||
|
func get_value() -> Array:
|
||||||
|
return point_value
|
17
addons/easy_charts/Utilities/Point/Point.tscn
Normal file
17
addons/easy_charts/Utilities/Point/Point.tscn
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/easy_charts/Utilities/Point/Point.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[node name="Point" type="Control"]
|
||||||
|
margin_left = -13.0
|
||||||
|
margin_top = -13.0
|
||||||
|
margin_right = 13.0
|
||||||
|
margin_bottom = 13.0
|
||||||
|
rect_min_size = Vector2( 16, 16 )
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
[connection signal="gui_input" from="." to="." method="_on_Point_gui_input"]
|
||||||
|
[connection signal="mouse_entered" from="." to="." method="_on_Point_mouse_entered"]
|
||||||
|
[connection signal="mouse_exited" from="." to="." method="_on_Point_mouse_exited"]
|
46
addons/easy_charts/Utilities/Point/PointData.gd
Normal file
46
addons/easy_charts/Utilities/Point/PointData.gd
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
extends PanelContainer
|
||||||
|
|
||||||
|
var value : String = ""
|
||||||
|
var position : Vector2 = Vector2()
|
||||||
|
|
||||||
|
var OFFSET : Vector2 = Vector2(15,35)
|
||||||
|
var GAP : Vector2 = Vector2(0,15)
|
||||||
|
|
||||||
|
onready var Data : Label = $PointData/Value/x
|
||||||
|
onready var Value : Label = $PointData/Value/y
|
||||||
|
onready var Function : Label = $PointData/Function
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
if get_global_mouse_position().y > OFFSET.y + GAP.y:
|
||||||
|
rect_position = get_global_mouse_position() - OFFSET - GAP
|
||||||
|
else:
|
||||||
|
rect_position = get_global_mouse_position() + GAP*5 - OFFSET
|
||||||
|
|
||||||
|
func update_datas(point : Control):
|
||||||
|
update_size()
|
||||||
|
|
||||||
|
get("custom_styles/panel").set("bg_color",point.color)
|
||||||
|
|
||||||
|
var font_color : Color
|
||||||
|
if point.color.g < 0.75:
|
||||||
|
font_color = Color(1,1,1,1)
|
||||||
|
else:
|
||||||
|
font_color = Color(0,0,0,1)
|
||||||
|
Data.set("custom_colors/font_color",font_color)
|
||||||
|
Value.set("custom_colors/font_color",font_color)
|
||||||
|
Function.set("custom_colors/font_color",font_color)
|
||||||
|
get("custom_styles/panel").set("border_color",font_color)
|
||||||
|
|
||||||
|
Data.set_text(point.point_value[0]+":")
|
||||||
|
Value.set_text(point.point_value[1])
|
||||||
|
Function.set_text(point.function)
|
||||||
|
update()
|
||||||
|
show()
|
||||||
|
|
||||||
|
func update_size():
|
||||||
|
OFFSET.x = get_size().x/2
|
||||||
|
OFFSET.y = get_size().y
|
||||||
|
GAP.y = OFFSET.y/3
|
68
addons/easy_charts/Utilities/Point/PointData.tscn
Normal file
68
addons/easy_charts/Utilities/Point/PointData.tscn
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
[gd_scene load_steps=3 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/easy_charts/Utilities/Point/PointData.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id=1]
|
||||||
|
content_margin_left = 8.0
|
||||||
|
content_margin_right = 8.0
|
||||||
|
content_margin_top = 5.0
|
||||||
|
content_margin_bottom = 5.0
|
||||||
|
bg_color = Color( 1, 1, 1, 0 )
|
||||||
|
border_width_left = 2
|
||||||
|
border_width_top = 2
|
||||||
|
border_width_right = 2
|
||||||
|
border_width_bottom = 2
|
||||||
|
border_color = Color( 1, 1, 1, 1 )
|
||||||
|
corner_radius_top_left = 5
|
||||||
|
corner_radius_top_right = 5
|
||||||
|
corner_radius_bottom_right = 5
|
||||||
|
corner_radius_bottom_left = 5
|
||||||
|
corner_detail = 20
|
||||||
|
|
||||||
|
[node name="PointData" type="CanvasLayer"]
|
||||||
|
|
||||||
|
[node name="PointData" type="PanelContainer" parent="."]
|
||||||
|
margin_right = 67.0
|
||||||
|
margin_bottom = 41.0
|
||||||
|
mouse_filter = 2
|
||||||
|
custom_styles/panel = SubResource( 1 )
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="PointData" type="VBoxContainer" parent="PointData"]
|
||||||
|
margin_left = 8.0
|
||||||
|
margin_top = 5.0
|
||||||
|
margin_right = 59.0
|
||||||
|
margin_bottom = 36.0
|
||||||
|
custom_constants/separation = 3
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Function" type="Label" parent="PointData/PointData"]
|
||||||
|
margin_right = 51.0
|
||||||
|
margin_bottom = 14.0
|
||||||
|
align = 1
|
||||||
|
valign = 1
|
||||||
|
|
||||||
|
[node name="Value" type="HBoxContainer" parent="PointData/PointData"]
|
||||||
|
margin_top = 17.0
|
||||||
|
margin_right = 51.0
|
||||||
|
margin_bottom = 31.0
|
||||||
|
|
||||||
|
[node name="x" type="Label" parent="PointData/PointData/Value"]
|
||||||
|
margin_right = 39.0
|
||||||
|
margin_bottom = 14.0
|
||||||
|
custom_colors/font_color = Color( 1, 1, 1, 1 )
|
||||||
|
text = "Value:"
|
||||||
|
valign = 1
|
||||||
|
|
||||||
|
[node name="y" type="Label" parent="PointData/PointData/Value"]
|
||||||
|
margin_left = 43.0
|
||||||
|
margin_right = 51.0
|
||||||
|
margin_bottom = 14.0
|
||||||
|
custom_colors/font_color = Color( 1, 1, 1, 1 )
|
||||||
|
text = "0"
|
||||||
|
valign = 1
|
BIN
addons/easy_charts/Utilities/Rect/Line-Graph1.png
Normal file
BIN
addons/easy_charts/Utilities/Rect/Line-Graph1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 70 KiB |
34
addons/easy_charts/Utilities/Rect/Line-Graph1.png.import
Normal file
34
addons/easy_charts/Utilities/Rect/Line-Graph1.png.import
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/Line-Graph1.png-cf75f72c04876dd893d0cb31b406bc73.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://addons/easy_charts/Utilities/Rect/Line-Graph1.png"
|
||||||
|
dest_files=[ "res://.import/Line-Graph1.png-cf75f72c04876dd893d0cb31b406bc73.stex" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
flags/repeat=0
|
||||||
|
flags/filter=true
|
||||||
|
flags/mipmaps=false
|
||||||
|
flags/anisotropic=false
|
||||||
|
flags/srgb=2
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
|
stream=false
|
||||||
|
size_limit=0
|
||||||
|
detect_3d=true
|
||||||
|
svg/scale=1.0
|
66
addons/easy_charts/Utilities/Rect/Rect.gd
Normal file
66
addons/easy_charts/Utilities/Rect/Rect.gd
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
extends Control
|
||||||
|
|
||||||
|
var OFFSET : Vector2 = Vector2()
|
||||||
|
var point_value : Array
|
||||||
|
var point_position : Vector2
|
||||||
|
var color : Color
|
||||||
|
var color_outline : Color
|
||||||
|
var function : String
|
||||||
|
|
||||||
|
var mouse_entered : bool = false
|
||||||
|
|
||||||
|
|
||||||
|
signal _mouse_entered()
|
||||||
|
signal _mouse_exited()
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
func _draw():
|
||||||
|
if mouse_entered:
|
||||||
|
draw_rect(Rect2(rect_position - OFFSET,rect_size),color_outline,true,12,true)
|
||||||
|
|
||||||
|
func create_point(color : Color, color_outline : Color, position : Vector2, size : Vector2, value : Array, function : String):
|
||||||
|
|
||||||
|
self.color = color
|
||||||
|
self.color_outline = color_outline
|
||||||
|
self.point_position = position
|
||||||
|
self.rect_position = point_position - OFFSET
|
||||||
|
self.rect_size = size
|
||||||
|
self.point_value = value
|
||||||
|
self.function = function
|
||||||
|
|
||||||
|
func format_value(v : Array, format_x : bool, format_y : bool):
|
||||||
|
var x : String = str(v[0])
|
||||||
|
var y : String = str(v[1])
|
||||||
|
|
||||||
|
if format_x:
|
||||||
|
x = format(v[1])
|
||||||
|
if format_y:
|
||||||
|
y = format(v[1])
|
||||||
|
|
||||||
|
return [x,y]
|
||||||
|
|
||||||
|
func format(n):
|
||||||
|
n = str(n)
|
||||||
|
var size = n.length()
|
||||||
|
var s
|
||||||
|
for i in range(size):
|
||||||
|
if((size - i) % 3 == 0 and i > 0):
|
||||||
|
s = str(s,",", n[i])
|
||||||
|
else:
|
||||||
|
s = str(s,n[i])
|
||||||
|
|
||||||
|
return s.replace("Null","")
|
||||||
|
|
||||||
|
func _on_Rect_mouse_entered():
|
||||||
|
mouse_entered = true
|
||||||
|
emit_signal("_mouse_entered")
|
||||||
|
update()
|
||||||
|
|
||||||
|
func _on_Rect_mouse_exited():
|
||||||
|
mouse_entered = false
|
||||||
|
emit_signal("_mouse_exited")
|
||||||
|
update()
|
11
addons/easy_charts/Utilities/Rect/Rect.tscn
Normal file
11
addons/easy_charts/Utilities/Rect/Rect.tscn
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/easy_charts/Utilities/Rect/Rect.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[node name="Rect" type="Control"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
[connection signal="mouse_entered" from="." to="." method="_on_Rect_mouse_entered"]
|
||||||
|
[connection signal="mouse_exited" from="." to="." method="_on_Rect_mouse_exited"]
|
155
addons/easy_charts/Utilities/icons/linechart.svg
Normal file
155
addons/easy_charts/Utilities/icons/linechart.svg
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="12"
|
||||||
|
height="12"
|
||||||
|
viewBox="0 0 3.1749999 3.1750001"
|
||||||
|
version="1.1"
|
||||||
|
id="svg8"
|
||||||
|
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
||||||
|
sodipodi:docname="linechart.svg">
|
||||||
|
<defs
|
||||||
|
id="defs2">
|
||||||
|
<linearGradient
|
||||||
|
id="linearGradient5569"
|
||||||
|
osb:paint="solid">
|
||||||
|
<stop
|
||||||
|
style="stop-color:#000000;stop-opacity:1;"
|
||||||
|
offset="0"
|
||||||
|
id="stop5567" />
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="45.254834"
|
||||||
|
inkscape:cx="7.2321717"
|
||||||
|
inkscape:cy="4.3383636"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="true"
|
||||||
|
inkscape:snap-bbox="true"
|
||||||
|
inkscape:snap-others="true"
|
||||||
|
inkscape:snap-nodes="true"
|
||||||
|
inkscape:bbox-nodes="true"
|
||||||
|
inkscape:bbox-paths="true"
|
||||||
|
inkscape:snap-bbox-edge-midpoints="true"
|
||||||
|
inkscape:snap-bbox-midpoints="true"
|
||||||
|
inkscape:snap-global="false"
|
||||||
|
inkscape:object-nodes="false"
|
||||||
|
inkscape:snap-grids="true"
|
||||||
|
inkscape:snap-to-guides="false"
|
||||||
|
inkscape:object-paths="false"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1001"
|
||||||
|
inkscape:window-x="2391"
|
||||||
|
inkscape:window-y="-9"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
units="px"
|
||||||
|
scale-x="1e-05">
|
||||||
|
<inkscape:grid
|
||||||
|
type="xygrid"
|
||||||
|
id="grid1377"
|
||||||
|
empspacing="12" />
|
||||||
|
</sodipodi:namedview>
|
||||||
|
<metadata
|
||||||
|
id="metadata5">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Livello 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-293.82497)">
|
||||||
|
<rect
|
||||||
|
style="fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:0.26458332;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect1486"
|
||||||
|
width="0.26458332"
|
||||||
|
height="0.26458332"
|
||||||
|
x="-1.0583333"
|
||||||
|
y="293.82498" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5b7f3;fill-opacity:1;stroke:none;stroke-width:0.26458332;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect1578"
|
||||||
|
width="0.26458332"
|
||||||
|
height="0.26458332"
|
||||||
|
x="-1.0583333"
|
||||||
|
y="294.08954" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:0.27538645;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect5539"
|
||||||
|
width="0.52916664"
|
||||||
|
height="3.4395685"
|
||||||
|
x="-0.26458332"
|
||||||
|
y="293.82498" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:0.27634826;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect5541"
|
||||||
|
width="3.175"
|
||||||
|
height="0.52916664"
|
||||||
|
x="1.3907751e-08"
|
||||||
|
y="296.73535" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5efac;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.29347834;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect7010"
|
||||||
|
width="1.3280054"
|
||||||
|
height="0.39521819"
|
||||||
|
x="264.53415"
|
||||||
|
y="142.6459"
|
||||||
|
transform="matrix(0.48573212,0.87410772,-0.89524404,0.44557615,0,0)"
|
||||||
|
ry="0.1976091" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5efac;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.29347831;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect7010-8"
|
||||||
|
width="1.3280054"
|
||||||
|
height="0.39521819"
|
||||||
|
x="262.32922"
|
||||||
|
y="146.91296"
|
||||||
|
transform="matrix(-0.49326555,0.86987878,0.89136123,0.45329367,0,0)"
|
||||||
|
ry="0.1976091" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5efac;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.29347828;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect7010-8-9"
|
||||||
|
width="1.3280054"
|
||||||
|
height="0.39521819"
|
||||||
|
x="261.59872"
|
||||||
|
y="146.90884"
|
||||||
|
transform="matrix(-0.49326555,0.86987878,0.89136123,0.45329367,0,0)"
|
||||||
|
ry="0.1976091" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5efac;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.29347825;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect7010-8-9-2"
|
||||||
|
width="1.3280054"
|
||||||
|
height="0.39521819"
|
||||||
|
x="263.42633"
|
||||||
|
y="143.44034"
|
||||||
|
transform="matrix(0.49326555,0.86987878,-0.89136123,0.45329367,0,0)"
|
||||||
|
ry="0.1976091" />
|
||||||
|
<path
|
||||||
|
style="fill:#a5efac;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.28821853;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="m 2.7247357,295.19899 a 0.45017607,0.44140657 0 0 0 -0.4505985,0.44164 0.45017607,0.44140657 0 0 0 0.4505985,0.44163 0.45017607,0.44140657 0 0 0 0.450061,-0.44163 0.45017607,0.44140657 0 0 0 -0.450061,-0.44164 z m 0,0.22824 a 0.2129211,0.21319639 0 0 1 0.2129321,0.2134 0.2129211,0.21319639 0 0 1 -0.2129321,0.21339 0.2129211,0.21319639 0 0 1 -0.2129319,-0.21339 0.2129211,0.21319639 0 0 1 0.2129319,-0.2134 z"
|
||||||
|
id="path7057"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 5.6 KiB |
34
addons/easy_charts/Utilities/icons/linechart.svg.import
Normal file
34
addons/easy_charts/Utilities/icons/linechart.svg.import
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/linechart.svg-1b22ec0a8537b638d716ea5c462d4141.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://addons/easy_charts/Utilities/icons/linechart.svg"
|
||||||
|
dest_files=[ "res://.import/linechart.svg-1b22ec0a8537b638d716ea5c462d4141.stex" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
flags/repeat=0
|
||||||
|
flags/filter=true
|
||||||
|
flags/mipmaps=false
|
||||||
|
flags/anisotropic=false
|
||||||
|
flags/srgb=2
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
|
stream=false
|
||||||
|
size_limit=0
|
||||||
|
detect_3d=false
|
||||||
|
svg/scale=1.0
|
155
addons/easy_charts/Utilities/icons/linechart2d.svg
Normal file
155
addons/easy_charts/Utilities/icons/linechart2d.svg
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="12"
|
||||||
|
height="12"
|
||||||
|
viewBox="0 0 3.1749999 3.1750001"
|
||||||
|
version="1.1"
|
||||||
|
id="svg8"
|
||||||
|
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
||||||
|
sodipodi:docname="linechart2d.svg">
|
||||||
|
<defs
|
||||||
|
id="defs2">
|
||||||
|
<linearGradient
|
||||||
|
id="linearGradient5569"
|
||||||
|
osb:paint="solid">
|
||||||
|
<stop
|
||||||
|
style="stop-color:#000000;stop-opacity:1;"
|
||||||
|
offset="0"
|
||||||
|
id="stop5567" />
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="45.254834"
|
||||||
|
inkscape:cx="7.2321717"
|
||||||
|
inkscape:cy="4.3383636"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="true"
|
||||||
|
inkscape:snap-bbox="true"
|
||||||
|
inkscape:snap-others="true"
|
||||||
|
inkscape:snap-nodes="true"
|
||||||
|
inkscape:bbox-nodes="true"
|
||||||
|
inkscape:bbox-paths="true"
|
||||||
|
inkscape:snap-bbox-edge-midpoints="true"
|
||||||
|
inkscape:snap-bbox-midpoints="true"
|
||||||
|
inkscape:snap-global="false"
|
||||||
|
inkscape:object-nodes="false"
|
||||||
|
inkscape:snap-grids="true"
|
||||||
|
inkscape:snap-to-guides="false"
|
||||||
|
inkscape:object-paths="false"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1001"
|
||||||
|
inkscape:window-x="2391"
|
||||||
|
inkscape:window-y="-9"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
units="px"
|
||||||
|
scale-x="1e-05">
|
||||||
|
<inkscape:grid
|
||||||
|
type="xygrid"
|
||||||
|
id="grid1377"
|
||||||
|
empspacing="12" />
|
||||||
|
</sodipodi:namedview>
|
||||||
|
<metadata
|
||||||
|
id="metadata5">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Livello 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-293.82497)">
|
||||||
|
<rect
|
||||||
|
style="fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:0.26458332;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect1486"
|
||||||
|
width="0.26458332"
|
||||||
|
height="0.26458332"
|
||||||
|
x="-1.0583333"
|
||||||
|
y="293.82498" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5b7f3;fill-opacity:1;stroke:none;stroke-width:0.26458332;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect1578"
|
||||||
|
width="0.26458332"
|
||||||
|
height="0.26458332"
|
||||||
|
x="-1.0583333"
|
||||||
|
y="294.08954" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5b7f3;fill-opacity:1;stroke:none;stroke-width:0.27538645;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect5539"
|
||||||
|
width="0.52916664"
|
||||||
|
height="3.4395685"
|
||||||
|
x="-0.26458332"
|
||||||
|
y="293.82498" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5b7f3;fill-opacity:1;stroke:none;stroke-width:0.27634826;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect5541"
|
||||||
|
width="3.175"
|
||||||
|
height="0.52916664"
|
||||||
|
x="1.3907751e-08"
|
||||||
|
y="296.73535" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5b7f3;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.29347834;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect7010"
|
||||||
|
width="1.3280054"
|
||||||
|
height="0.39521819"
|
||||||
|
x="264.53415"
|
||||||
|
y="142.6459"
|
||||||
|
transform="matrix(0.48573212,0.87410772,-0.89524404,0.44557615,0,0)"
|
||||||
|
ry="0.1976091" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5b7f3;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.29347831;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect7010-8"
|
||||||
|
width="1.3280054"
|
||||||
|
height="0.39521819"
|
||||||
|
x="262.32922"
|
||||||
|
y="146.91296"
|
||||||
|
transform="matrix(-0.49326555,0.86987878,0.89136123,0.45329367,0,0)"
|
||||||
|
ry="0.1976091" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5b7f3;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.29347828;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect7010-8-9"
|
||||||
|
width="1.3280054"
|
||||||
|
height="0.39521819"
|
||||||
|
x="261.59872"
|
||||||
|
y="146.90884"
|
||||||
|
transform="matrix(-0.49326555,0.86987878,0.89136123,0.45329367,0,0)"
|
||||||
|
ry="0.1976091" />
|
||||||
|
<rect
|
||||||
|
style="fill:#a5b7f3;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.29347825;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect7010-8-9-2"
|
||||||
|
width="1.3280054"
|
||||||
|
height="0.39521819"
|
||||||
|
x="263.42633"
|
||||||
|
y="143.44034"
|
||||||
|
transform="matrix(0.49326555,0.86987878,-0.89136123,0.45329367,0,0)"
|
||||||
|
ry="0.1976091" />
|
||||||
|
<path
|
||||||
|
style="fill:#a5b7f3;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.28821853;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="m 2.7247357,295.19899 a 0.45017607,0.44140657 0 0 0 -0.4505985,0.44164 0.45017607,0.44140657 0 0 0 0.4505985,0.44163 0.45017607,0.44140657 0 0 0 0.450061,-0.44163 0.45017607,0.44140657 0 0 0 -0.450061,-0.44164 z m 0,0.22824 a 0.2129211,0.21319639 0 0 1 0.2129321,0.2134 0.2129211,0.21319639 0 0 1 -0.2129321,0.21339 0.2129211,0.21319639 0 0 1 -0.2129319,-0.21339 0.2129211,0.21319639 0 0 1 0.2129319,-0.2134 z"
|
||||||
|
id="path7057"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 5.6 KiB |
34
addons/easy_charts/Utilities/icons/linechart2d.svg.import
Normal file
34
addons/easy_charts/Utilities/icons/linechart2d.svg.import
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/linechart2d.svg-af92a4d6767d218934fb7a6905401722.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://addons/easy_charts/Utilities/icons/linechart2d.svg"
|
||||||
|
dest_files=[ "res://.import/linechart2d.svg-af92a4d6767d218934fb7a6905401722.stex" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
flags/repeat=0
|
||||||
|
flags/filter=true
|
||||||
|
flags/mipmaps=false
|
||||||
|
flags/anisotropic=false
|
||||||
|
flags/srgb=2
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
|
stream=false
|
||||||
|
size_limit=0
|
||||||
|
detect_3d=true
|
||||||
|
svg/scale=1.0
|
21
addons/easy_charts/Utilities/utilities.gd
Normal file
21
addons/easy_charts/Utilities/utilities.gd
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
tool
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
var plugin_name : String = "Easy Charts"
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _print_message(message : String, type : int = 0):
|
||||||
|
match type:
|
||||||
|
0:
|
||||||
|
print("[%s] => %s" % [plugin_name, message])
|
||||||
|
1:
|
||||||
|
printerr("[%s] => %s" % [plugin_name, message])
|
||||||
|
|
||||||
|
func _load_templates() -> Dictionary:
|
||||||
|
var template_file : File = File.new()
|
||||||
|
template_file.open("res://addons/easy_charts/templates.json",File.READ)
|
||||||
|
var templates = JSON.parse(template_file.get_as_text()).get_result()
|
||||||
|
template_file.close()
|
||||||
|
return templates
|
10
addons/easy_charts/file.samples/datas.csv
Normal file
10
addons/easy_charts/file.samples/datas.csv
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
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
|
|
10
addons/easy_charts/file.samples/datas.csv.import
Normal file
10
addons/easy_charts/file.samples/datas.csv.import
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="csv"
|
||||||
|
type="TextFile"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://addons/easy_charts/file.samples/datas.csv"
|
||||||
|
[params]
|
||||||
|
|
5
addons/easy_charts/file.samples/datas2.csv
Normal file
5
addons/easy_charts/file.samples/datas2.csv
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
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
|
|
10
addons/easy_charts/file.samples/datas2.csv.import
Normal file
10
addons/easy_charts/file.samples/datas2.csv.import
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="csv"
|
||||||
|
type="TextFile"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://addons/easy_charts/file.samples/datas2.csv"
|
||||||
|
[params]
|
||||||
|
|
BIN
addons/easy_charts/icon.png
Normal file
BIN
addons/easy_charts/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 68 KiB |
34
addons/easy_charts/icon.png.import
Normal file
34
addons/easy_charts/icon.png.import
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/icon.png-85017c6eecaf83ace12c82c530e61e9d.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://addons/easy_charts/icon.png"
|
||||||
|
dest_files=[ "res://.import/icon.png-85017c6eecaf83ace12c82c530e61e9d.stex" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
flags/repeat=0
|
||||||
|
flags/filter=true
|
||||||
|
flags/mipmaps=false
|
||||||
|
flags/anisotropic=false
|
||||||
|
flags/srgb=2
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
|
stream=false
|
||||||
|
size_limit=0
|
||||||
|
detect_3d=true
|
||||||
|
svg/scale=1.0
|
7
addons/easy_charts/plugin.cfg
Normal file
7
addons/easy_charts/plugin.cfg
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[plugin]
|
||||||
|
|
||||||
|
name="EasyCharts"
|
||||||
|
description=""
|
||||||
|
author="Nicolò \"fenix\" Santilio"
|
||||||
|
version="1.0"
|
||||||
|
script="plugin.gd"
|
12
addons/easy_charts/plugin.gd
Normal file
12
addons/easy_charts/plugin.gd
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
tool
|
||||||
|
extends EditorPlugin
|
||||||
|
|
||||||
|
func _enter_tree():
|
||||||
|
add_autoload_singleton("Utilities","res://addons/easy_charts/Utilities/utilities.gd")
|
||||||
|
add_custom_type("ChartContainer", "Container", load("Utilities/ChartContainer.gd"), load("Utilities/icons/linechart.svg"))
|
||||||
|
add_custom_type("ChartContainer2D", "Node2D", load("Utilities/ChartContainer2D.gd"), load("Utilities/icons/linechart2d.svg"))
|
||||||
|
|
||||||
|
func _exit_tree():
|
||||||
|
remove_custom_type("ChartContainer")
|
||||||
|
remove_custom_type("ChartContainer2D")
|
||||||
|
remove_autoload_singleton("Utilities")
|
44
addons/easy_charts/templates.json
Normal file
44
addons/easy_charts/templates.json
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"default":
|
||||||
|
{
|
||||||
|
"function_colors" : ["#1e1e1e","#1e1e1e","#1e1e1e","#1e1e1e"],
|
||||||
|
"v_lines_color" : "#cacaca",
|
||||||
|
"h_lines_color" : "#cacaca",
|
||||||
|
"outline_color" : "#1e1e1e",
|
||||||
|
"font_color" : "#1e1e1e"
|
||||||
|
},
|
||||||
|
"clean":
|
||||||
|
{
|
||||||
|
"function_colors" : ["#f7aa29","#f4394a","#5a6b7b","#8fbf59","#504538","#B7A99A","#00D795","#FFECCC","#FF8981"],
|
||||||
|
"v_lines_color" : "#00000000",
|
||||||
|
"h_lines_color" : "#3cffffff",
|
||||||
|
"outline_color" : "#00000000",
|
||||||
|
"font_color" : "#3cffffff"
|
||||||
|
},
|
||||||
|
"gradient":
|
||||||
|
{
|
||||||
|
"function_colors" : ["#F7AA29","#B8A806","#79A117","#2C9433","#00854C","#006571","#2F4858","#2a364f","#27294a"],
|
||||||
|
"v_lines_color" : "#64ffffff",
|
||||||
|
"h_lines_color" : "#64ffffff",
|
||||||
|
"outline_color" : "#64ffffff",
|
||||||
|
"font_color" : "#64ffffff",
|
||||||
|
},
|
||||||
|
"minimal":
|
||||||
|
{
|
||||||
|
"function_colors" : ["#1e1e1e","#1e1e1e","#1e1e1e","#1e1e1e"],
|
||||||
|
"v_lines_color" : "#00000000",
|
||||||
|
"h_lines_color" : "#00000000",
|
||||||
|
"outline_color" : "#00000000",
|
||||||
|
"font_color" : "#00000000"
|
||||||
|
},
|
||||||
|
"invert":
|
||||||
|
{
|
||||||
|
"function_colors" : ["#ffffff","#ffffff","#ffffff","#ffffff"],
|
||||||
|
"v_lines_color" : "#3b3b3b",
|
||||||
|
"h_lines_color" : "#3b3b3b",
|
||||||
|
"outline_color" : "#ffffff",
|
||||||
|
"font_color" : "#ffffff"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user