mirror of
https://github.com/Relintai/pandemonium_engine_easy_charts.git
synced 2024-11-14 10:17:24 +01:00
update v0.2.8
This commit is contained in:
parent
c1c6a3b0f9
commit
0cf6873d75
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
*.import
|
*.import
|
||||||
*.png
|
*.png
|
||||||
|
|
||||||
|
|
||||||
|
14
README.md
14
README.md
@ -1,4 +1,4 @@
|
|||||||
[![version](https://img.shields.io/badge/plugin%20version-0.2.5-blue)](https://github.com/fenix-hub/godot-engine.easy-charts)
|
[![version](https://img.shields.io/badge/plugin%20version-0.2.8-blue)](https://github.com/fenix-hub/godot-engine.easy-charts)
|
||||||
[![updates](https://img.shields.io/badge/plugin%20updates-on%20discord-purple)](https://discord.gg/JNrcucg)
|
[![updates](https://img.shields.io/badge/plugin%20updates-on%20discord-purple)](https://discord.gg/JNrcucg)
|
||||||
[![paypal](https://img.shields.io/badge/donations-PayPal-cyan)](https://paypal.me/NSantilio?locale.x=it_IT)
|
[![paypal](https://img.shields.io/badge/donations-PayPal-cyan)](https://paypal.me/NSantilio?locale.x=it_IT)
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ Check my **[Discord](https://discord.gg/KnJGY9S)** to stay updated on this repos
|
|||||||
A library of Charts plotted in Control, 2D and 3D nodes to visualize general purpose datasets.
|
A library of Charts plotted in Control, 2D and 3D nodes to visualize general purpose datasets.
|
||||||
|
|
||||||
Author: *"Nicolo (fenix) Santilio"*
|
Author: *"Nicolo (fenix) Santilio"*
|
||||||
Version: *0.2.5*
|
Version: *0.2.8*
|
||||||
Wiki: *[wip]*
|
Wiki: *[wip]*
|
||||||
Godot Version: *3.2stable*
|
Godot Version: *3.2stable*
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ However, adding custom templates is not yet recommended, since it would require
|
|||||||
```
|
```
|
||||||
|
|
||||||
# Available Charts and when to use them
|
# Available Charts and when to use them
|
||||||
This library offers a set of chart for each main Godot Node:
|
This library offers a set of charts for each main Godot Node:
|
||||||
- **Control Nodes:** "Control Charts" are fast Charts that can be plotted in a Control space, such as UIs or Control user interactable areas. They offer basic Control properties, such as Margins, size inheritance and control. No animations, no real time changes, just charts.
|
- **Control Nodes:** "Control Charts" are fast Charts that can be plotted in a Control space, such as UIs or Control user interactable areas. They offer basic Control properties, such as Margins, size inheritance and control. No animations, no real time changes, just charts.
|
||||||
- **2D Nodes:** "2D Charts" are a set of Charts which can be Used in 2D spaces. They offer additional tools, such as animations and real time changes in editor. They can be used to implement more aesthetic charts in 2D contexts.
|
- **2D Nodes:** "2D Charts" are a set of Charts which can be Used in 2D spaces. They offer additional tools, such as animations and real time changes in editor. They can be used to implement more aesthetic charts in 2D contexts.
|
||||||
- **[wip] 3D Nodes:** "3D Charts" are a set of Charts which can be Used in both 2D and 3D spaces. They offer the possibility to plot 3D datasets, which are common in machine learning contexts or just data analysis. A Camera Control will also be available, which can be used to move around the chart.
|
- **[wip] 3D Nodes:** "3D Charts" are a set of Charts which can be Used in both 2D and 3D spaces. They offer the possibility to plot 3D datasets, which are common in machine learning contexts or just data analysis. A Camera Control will also be available, which can be used to move around the chart.
|
||||||
@ -134,7 +134,7 @@ This library offers a set of chart for each main Godot Node:
|
|||||||
|
|
||||||
### Some Examples
|
### Some Examples
|
||||||
![example01](imgs/scatter.gif)
|
![example01](imgs/scatter.gif)
|
||||||
![example02](imgs/radar.png)
|
![example02](imgs/example02.png)
|
||||||
![example03](imgs/example03.gif)
|
![example03](imgs/example03.gif)
|
||||||
|
|
||||||
##### Some references for charts and plots
|
##### Some references for charts and plots
|
||||||
@ -150,8 +150,4 @@ I don't assume any responsibility for possible corruptions of your project. It i
|
|||||||
|
|
||||||
-----------------
|
-----------------
|
||||||
> This text file was created via [TextEditor Integration](https://github.com/fenix-hub/godot-engine.text-editor) inside Godot Engine's Editor.
|
> This text file was created via [TextEditor Integration](https://github.com/fenix-hub/godot-engine.text-editor) inside Godot Engine's Editor.
|
||||||
|
> This text file was pushed via [GitHub Integration](https://github.com/fenix-hub/godot-engine.github-integretion) inside Godot Engine's Editor.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,194 +16,137 @@ values of more than one measured variable.
|
|||||||
/ source : Wikipedia /
|
/ source : Wikipedia /
|
||||||
"""
|
"""
|
||||||
|
|
||||||
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 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
|
|
||||||
var h_dist : float
|
|
||||||
|
|
||||||
# quantization, representing the interval in which values will be displayed
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
var x_label : String
|
|
||||||
|
|
||||||
# database values
|
|
||||||
var x_datas : Array
|
|
||||||
var y_datas : Array
|
|
||||||
|
|
||||||
# labels displayed on chart
|
|
||||||
var x_labels : Array
|
|
||||||
var y_labels : Array
|
|
||||||
|
|
||||||
var x_margin_min : int = 0
|
|
||||||
var y_margin_min : int = 0
|
|
||||||
|
|
||||||
# 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 SIZE : Vector2 = Vector2()
|
|
||||||
export (String, FILE, "*.txt, *.csv") var source : String = ""
|
|
||||||
export (String) var delimiter : String = ";"
|
|
||||||
export (bool) var origin_at_zero : bool = true
|
|
||||||
|
|
||||||
export (bool) var are_values_columns : bool = false
|
func _get_property_list():
|
||||||
export (int,0,100) var x_values_index : int = 0
|
return [
|
||||||
export(bool) var show_x_values_as_labels : bool = true
|
# Chart Properties
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/are_values_columns",
|
||||||
|
"type": TYPE_BOOL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "-1,100,1",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/labels_index",
|
||||||
|
"type": TYPE_INT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/show_x_values_as_labels",
|
||||||
|
"type": TYPE_BOOL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "1,20,0.5",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/column_width",
|
||||||
|
"type": TYPE_REAL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "0,10,0.5",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/column_gap",
|
||||||
|
"type": TYPE_REAL
|
||||||
|
},
|
||||||
|
|
||||||
export (float,1,20,0.5) var column_width : float = 10
|
# Chart Display
|
||||||
export (float,0,10,0.5) var column_gap : float = 2
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "0.1,10",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Display/x_decim",
|
||||||
|
"type": TYPE_REAL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "0.1,10",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Display/y_decim",
|
||||||
|
"type": TYPE_REAL
|
||||||
|
},
|
||||||
|
|
||||||
export (float,0.1,10.0) var x_decim : float = 5.0
|
# Chart Style
|
||||||
export (float,0.1,10.0) var y_decim : float = 5.0
|
{
|
||||||
|
"hint": 24,
|
||||||
|
"hint_string": "%d/%d:%s"%[TYPE_INT, PROPERTY_HINT_ENUM,
|
||||||
|
PoolStringArray(PointShapes.keys()).join(",")],
|
||||||
|
"name": "Chart_Style/points_shape",
|
||||||
|
"type": TYPE_ARRAY,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/function_colors",
|
||||||
|
"type": TYPE_COLOR_ARRAY
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/box_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/v_lines_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/h_lines_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"class_name": "Font",
|
||||||
|
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||||
|
"hint_string": "Font",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/font",
|
||||||
|
"type": TYPE_OBJECT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"class_name": "Font",
|
||||||
|
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||||
|
"hint_string": "Font",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/bold_font",
|
||||||
|
"type": TYPE_OBJECT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/font_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_ENUM,
|
||||||
|
"hint_string": PoolStringArray(TemplatesNames.keys()).join(","),
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/template",
|
||||||
|
"type": TYPE_INT
|
||||||
|
},
|
||||||
|
|
||||||
export (point_shapes) var point_shape : int = 0
|
# Chart Modifiers
|
||||||
|
{
|
||||||
export (PoolColorArray) var function_colors = [Color("#1e1e1e")]
|
"hint": PROPERTY_HINT_NONE,
|
||||||
export (Color) var v_lines_color : Color = Color("#cacaca")
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
export (Color) var h_lines_color : Color = Color("#cacaca")
|
"name": "Chart_Modifiers/invert_chart",
|
||||||
|
"type": TYPE_BOOL
|
||||||
export (bool) var boxed : bool = true
|
},
|
||||||
export (Color) var box_color : Color = Color("#1e1e1e")
|
]
|
||||||
export (Font) var font : Font
|
|
||||||
export (Font) var bold_font : Font
|
|
||||||
export (Color) var font_color : Color = Color("#1e1e1e")
|
|
||||||
export (templates_names) var template : int = Chart.templates_names.Default setget apply_template
|
|
||||||
export (bool) var invert_chart : bool = false
|
|
||||||
|
|
||||||
var templates : Dictionary = {}
|
|
||||||
|
|
||||||
signal chart_plotted(chart)
|
|
||||||
signal point_pressed(point)
|
|
||||||
|
|
||||||
func _point_plotted():
|
|
||||||
pass
|
|
||||||
|
|
||||||
func _ready():
|
|
||||||
pass
|
|
||||||
|
|
||||||
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 _plot(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_values_index_ : int):
|
|
||||||
randomize()
|
|
||||||
|
|
||||||
|
|
||||||
load_font()
|
|
||||||
PointData.hide()
|
|
||||||
|
|
||||||
datas = read_datas(source_,delimiter_)
|
|
||||||
count_functions()
|
|
||||||
structure_datas(datas,are_values_columns_,x_values_index_)
|
|
||||||
build_chart()
|
|
||||||
calculate_pass()
|
|
||||||
calculate_coordinates()
|
|
||||||
calculate_colors()
|
|
||||||
create_legend()
|
|
||||||
emit_signal("chart_plotted")
|
|
||||||
|
|
||||||
func plot():
|
|
||||||
randomize()
|
|
||||||
|
|
||||||
|
|
||||||
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_index)
|
|
||||||
build_chart()
|
|
||||||
calculate_pass()
|
|
||||||
calculate_coordinates()
|
|
||||||
calculate_colors()
|
|
||||||
create_legend()
|
|
||||||
emit_signal("chart_plotted")
|
|
||||||
|
|
||||||
func clear_points():
|
|
||||||
if Points.get_children().size():
|
|
||||||
for function in Points.get_children():
|
|
||||||
function.queue_free()
|
|
||||||
for legend in Legend.get_children():
|
|
||||||
legend.queue_free()
|
|
||||||
|
|
||||||
func calculate_colors():
|
|
||||||
if function_colors.empty() or function_colors.size() < functions:
|
|
||||||
for function in functions:
|
|
||||||
function_colors.append(Color("#1e1e1e"))
|
|
||||||
|
|
||||||
func build_chart():
|
func build_chart():
|
||||||
SIZE = get_size()
|
SIZE = get_size()
|
||||||
origin = Vector2(OFFSET.x,SIZE.y-OFFSET.y)
|
origin = Vector2(OFFSET.x,SIZE.y-OFFSET.y)
|
||||||
|
|
||||||
func point_pressed(point : Point):
|
|
||||||
emit_signal("point_pressed",point)
|
|
||||||
|
|
||||||
func _enter_tree():
|
|
||||||
templates = Utilities._load_templates()
|
|
||||||
_ready()
|
|
||||||
|
|
||||||
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_index : int):
|
func structure_datas(database : Array, are_values_columns : bool, x_values_index : int):
|
||||||
# @x_values_index can be either a column or a row relative to x values
|
# @x_values_index can be either a column or a row relative to x values
|
||||||
# @y_values can be either a column or a row relative to y values
|
# @y_values can be either a column or a row relative to y values
|
||||||
@ -387,7 +330,7 @@ func _draw():
|
|||||||
point.connect("_mouse_entered",self,"show_data")
|
point.connect("_mouse_entered",self,"show_data")
|
||||||
point.connect("_mouse_exited",self,"hide_data")
|
point.connect("_mouse_exited",self,"hide_data")
|
||||||
|
|
||||||
point.create_point(point_shape, function_colors[function_point if invert_chart else _function],
|
point.create_point(points_shape[_function], function_colors[function_point if invert_chart else _function],
|
||||||
Color.white, point_positions[_function][function_point],
|
Color.white, point_positions[_function][function_point],
|
||||||
point.format_value(point_values[_function][function_point], false, false),
|
point.format_value(point_values[_function][function_point], false, false),
|
||||||
y_labels[function_point if invert_chart else _function] as String)
|
y_labels[function_point if invert_chart else _function] as String)
|
||||||
@ -421,50 +364,12 @@ func draw_grid():
|
|||||||
draw_string(font,point-Vector2(y_chors[p].length()*const_width+font_size,font_size/2),y_chors[p],font_color)
|
draw_string(font,point-Vector2(y_chors[p].length()*const_width+font_size,font_size/2),y_chors[p],font_color)
|
||||||
|
|
||||||
func draw_chart_outlines():
|
func draw_chart_outlines():
|
||||||
if boxed:
|
# if boxed:
|
||||||
draw_line(Vector2(origin.x,0),Vector2(SIZE.x,0),box_color,1,true)
|
draw_line(Vector2(origin.x,0),Vector2(SIZE.x,0),box_color,1,true)
|
||||||
draw_line(Vector2(SIZE.x,0),Vector2(SIZE.x,origin.y),box_color,1,true)
|
draw_line(Vector2(SIZE.x,0),Vector2(SIZE.x,origin.y),box_color,1,true)
|
||||||
draw_line(Vector2(SIZE.x,origin.y),origin,box_color,1,true)
|
draw_line(Vector2(SIZE.x,origin.y),origin,box_color,1,true)
|
||||||
draw_line(origin,Vector2(origin.x,0),box_color,1,true)
|
draw_line(origin,Vector2(origin.x,0),box_color,1,true)
|
||||||
|
|
||||||
func redraw():
|
|
||||||
build_chart()
|
|
||||||
calculate_pass()
|
|
||||||
calculate_coordinates()
|
|
||||||
update()
|
|
||||||
|
|
||||||
|
|
||||||
func show_data(point):
|
|
||||||
PointData.update_datas(point)
|
|
||||||
PointData.show()
|
|
||||||
|
|
||||||
func hide_data():
|
|
||||||
PointData.hide()
|
|
||||||
|
|
||||||
func set_legend(l : Array):
|
|
||||||
legend = l
|
|
||||||
|
|
||||||
func get_legend():
|
|
||||||
return legend
|
|
||||||
|
|
||||||
func invert_chart():
|
|
||||||
invert_chart = !invert_chart
|
|
||||||
count_functions()
|
|
||||||
redraw()
|
|
||||||
create_legend()
|
|
||||||
|
|
||||||
func count_functions():
|
|
||||||
if are_values_columns:
|
|
||||||
if not invert_chart:
|
|
||||||
functions = datas[0].size()-1
|
|
||||||
else:
|
|
||||||
functions = datas.size()-1
|
|
||||||
else:
|
|
||||||
if invert_chart:
|
|
||||||
functions = datas[0].size()-1
|
|
||||||
else:
|
|
||||||
functions = datas.size()-1
|
|
||||||
|
|
||||||
func create_legend():
|
func create_legend():
|
||||||
legend.clear()
|
legend.clear()
|
||||||
for function in functions:
|
for function in functions:
|
||||||
@ -482,15 +387,3 @@ func create_legend():
|
|||||||
function_legend.create_legend(f_name,function_colors[function],bold_font,font_color)
|
function_legend.create_legend(f_name,function_colors[function],bold_font,font_color)
|
||||||
legend.append(function_legend)
|
legend.append(function_legend)
|
||||||
|
|
||||||
func apply_template(template_name : int):
|
|
||||||
template = template_name
|
|
||||||
templates = Utilities._load_templates()
|
|
||||||
if template_name!=null:
|
|
||||||
var custom_template = templates.get(templates.keys()[template_name])
|
|
||||||
function_colors = custom_template.function_colors as PoolColorArray
|
|
||||||
v_lines_color = Color(custom_template.v_lines_color)
|
|
||||||
h_lines_color = Color(custom_template.h_lines_color)
|
|
||||||
box_color = Color(custom_template.outline_color)
|
|
||||||
font_color = Color(custom_template.font_color)
|
|
||||||
property_list_changed_notify()
|
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ export (float,0,10,0.5) var column_gap : float = 2
|
|||||||
|
|
||||||
export (float,0.1,10.0) var x_decim : float = 5.0
|
export (float,0.1,10.0) var x_decim : float = 5.0
|
||||||
export (float,0.1,10.0) var y_decim : float = 5.0
|
export (float,0.1,10.0) var y_decim : float = 5.0
|
||||||
export (point_shapes) var point_shape : int = 0
|
export (PointShapes) var point_shape : int = 0
|
||||||
export (PoolColorArray) var function_colors = [Color("#1e1e1e")]
|
export (PoolColorArray) var function_colors = [Color("#1e1e1e")]
|
||||||
export (Color) var v_lines_color : Color = Color("#cacaca")
|
export (Color) var v_lines_color : Color = Color("#cacaca")
|
||||||
export (Color) var h_lines_color : Color = Color("#cacaca")
|
export (Color) var h_lines_color : Color = Color("#cacaca")
|
||||||
@ -106,7 +106,7 @@ export (Color) var box_color : Color = Color("#1e1e1e")
|
|||||||
export (Font) var font : Font
|
export (Font) var font : Font
|
||||||
export (Font) var bold_font : Font
|
export (Font) var bold_font : Font
|
||||||
export (Color) var font_color : Color = Color("#1e1e1e")
|
export (Color) var font_color : Color = Color("#1e1e1e")
|
||||||
export (templates_names) var template : int = Chart.templates_names.Default setget apply_template
|
export (TemplatesNames) var template : int = Chart.TemplatesNames.Default setget apply_template
|
||||||
export (float,0.1,1) var drawing_duration : float = 0.5
|
export (float,0.1,1) var drawing_duration : float = 0.5
|
||||||
export (bool) var invert_chart : bool = false
|
export (bool) var invert_chart : bool = false
|
||||||
|
|
||||||
|
@ -15,172 +15,118 @@ In these cases they are known as run charts.
|
|||||||
/ source : Wikipedia /
|
/ source : Wikipedia /
|
||||||
"""
|
"""
|
||||||
|
|
||||||
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 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
|
|
||||||
var h_dist : float
|
|
||||||
|
|
||||||
# quantization, representing the interval in which values will be displayed
|
|
||||||
|
|
||||||
|
|
||||||
# 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 x_labels : Array
|
|
||||||
var y_labels : Array
|
|
||||||
|
|
||||||
var x_margin_min : int = 0
|
|
||||||
var y_margin_min : int = 0
|
|
||||||
|
|
||||||
# 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 SIZE : Vector2 = Vector2()
|
|
||||||
export (String, FILE, "*.txt, *.csv") var source : String = ""
|
|
||||||
export (String) var delimiter : String = ";"
|
|
||||||
export (bool) var origin_at_zero : bool = true
|
|
||||||
|
|
||||||
export (bool) var are_values_columns : bool = false
|
func _get_property_list():
|
||||||
export (int,0,100) var x_values_index : int = 0
|
return [
|
||||||
export(bool) var show_x_values_as_labels : bool = true
|
# Chart Properties
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/are_values_columns",
|
||||||
|
"type": TYPE_BOOL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "-1,100,1",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/labels_index",
|
||||||
|
"type": TYPE_INT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/show_x_values_as_labels",
|
||||||
|
"type": TYPE_BOOL
|
||||||
|
},
|
||||||
|
|
||||||
#export (float,1,20,0.5) var column_width : float = 10
|
# Chart Display
|
||||||
#export (float,0,10,0.5) var column_gap : float = 2
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "0.1,10",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Display/x_decim",
|
||||||
|
"type": TYPE_REAL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "0.1,10",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Display/y_decim",
|
||||||
|
"type": TYPE_REAL
|
||||||
|
},
|
||||||
|
|
||||||
export (float,0.1,10.0) var x_decim : float = 5.0
|
# Chart Style
|
||||||
export (float,0.1,10.0) var y_decim : float = 5.0
|
{
|
||||||
export (point_shapes) var point_shape : int = 0
|
"hint": 24,
|
||||||
export (PoolColorArray) var function_colors = [Color("#1e1e1e")]
|
"hint_string": "%d/%d:%s"%[TYPE_INT, PROPERTY_HINT_ENUM,
|
||||||
export (Color) var v_lines_color : Color = Color("#cacaca")
|
PoolStringArray(PointShapes.keys()).join(",")],
|
||||||
export (Color) var h_lines_color : Color = Color("#cacaca")
|
"name": "Chart_Style/points_shape",
|
||||||
|
"type": TYPE_ARRAY,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/function_colors",
|
||||||
|
"type": TYPE_COLOR_ARRAY
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/box_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/v_lines_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/h_lines_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"class_name": "Font",
|
||||||
|
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||||
|
"hint_string": "Font",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/font",
|
||||||
|
"type": TYPE_OBJECT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"class_name": "Font",
|
||||||
|
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||||
|
"hint_string": "Font",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/bold_font",
|
||||||
|
"type": TYPE_OBJECT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/font_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_ENUM,
|
||||||
|
"hint_string": PoolStringArray(TemplatesNames.keys()).join(","),
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/template",
|
||||||
|
"type": TYPE_INT
|
||||||
|
},
|
||||||
|
|
||||||
export (bool) var boxed : bool = true
|
# Chart Modifiers
|
||||||
export (Color) var box_color : Color = Color("#1e1e1e")
|
{
|
||||||
export (Font) var font : Font
|
"hint": PROPERTY_HINT_NONE,
|
||||||
export (Font) var bold_font : Font
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
export (Color) var font_color : Color = Color("#1e1e1e")
|
"name": "Chart_Modifiers/invert_chart",
|
||||||
export (templates_names) var template : int = Chart.templates_names.Default setget apply_template
|
"type": TYPE_BOOL
|
||||||
export (bool) var invert_chart : bool = false
|
},
|
||||||
|
]
|
||||||
|
|
||||||
var templates : Dictionary = {}
|
|
||||||
|
|
||||||
signal chart_plotted(chart)
|
|
||||||
signal point_pressed(point)
|
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
|
||||||
pass
|
|
||||||
|
|
||||||
func _plot(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_values_index_ : int, invert_chart_ : bool = false):
|
|
||||||
randomize()
|
|
||||||
|
|
||||||
load_font()
|
|
||||||
PointData.hide()
|
|
||||||
|
|
||||||
datas = read_datas(source_,delimiter_)
|
|
||||||
count_functions()
|
|
||||||
structure_datas(datas,are_values_columns_,x_values_index_)
|
|
||||||
build_chart()
|
|
||||||
calculate_pass()
|
|
||||||
calculate_coordinates()
|
|
||||||
calculate_colors()
|
|
||||||
create_legend()
|
|
||||||
emit_signal("chart_plotted")
|
|
||||||
|
|
||||||
func plot():
|
|
||||||
randomize()
|
|
||||||
|
|
||||||
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_index)
|
|
||||||
build_chart()
|
|
||||||
calculate_pass()
|
|
||||||
calculate_coordinates()
|
|
||||||
calculate_colors()
|
|
||||||
create_legend()
|
|
||||||
emit_signal("chart_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_index : int):
|
func structure_datas(database : Array, are_values_columns : bool, x_values_index : int):
|
||||||
# @x_values_index can be either a column or a row relative to x values
|
# @x_values_index can be either a column or a row relative to x values
|
||||||
@ -345,12 +291,6 @@ func calculate_coordinates():
|
|||||||
point_values[cluster].append([x_datas[y],y_datas[cluster][y]])
|
point_values[cluster].append([x_datas[y],y_datas[cluster][y]])
|
||||||
point_positions[cluster].append(Vector2(x_coordinates[y]+origin.x,origin.y-y_coordinates[cluster][y]))
|
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():
|
func _draw():
|
||||||
clear_points()
|
clear_points()
|
||||||
|
|
||||||
@ -371,7 +311,7 @@ func _draw():
|
|||||||
point.connect("_mouse_entered",self,"show_data")
|
point.connect("_mouse_entered",self,"show_data")
|
||||||
point.connect("_mouse_exited",self,"hide_data")
|
point.connect("_mouse_exited",self,"hide_data")
|
||||||
|
|
||||||
point.create_point(point_shape,function_colors[function_point if invert_chart else _function],
|
point.create_point(points_shape[_function], function_colors[function_point if invert_chart else _function],
|
||||||
Color.white, point_positions[_function][function_point],
|
Color.white, point_positions[_function][function_point],
|
||||||
point.format_value(point_values[_function][function_point], false, false),
|
point.format_value(point_values[_function][function_point], false, false),
|
||||||
y_labels[function_point if invert_chart else _function] as String)
|
y_labels[function_point if invert_chart else _function] as String)
|
||||||
@ -405,114 +345,3 @@ func draw_chart_outlines():
|
|||||||
draw_line(origin,Vector2(OFFSET.x,0),box_color,1,true)
|
draw_line(origin,Vector2(OFFSET.x,0),box_color,1,true)
|
||||||
draw_line(Vector2(OFFSET.x,0),Vector2(SIZE.x,0),box_color,1,true)
|
draw_line(Vector2(OFFSET.x,0),Vector2(SIZE.x,0),box_color,1,true)
|
||||||
draw_line(Vector2(SIZE.x,0),SIZE-Vector2(0,OFFSET.y),box_color,1,true)
|
draw_line(Vector2(SIZE.x,0),SIZE-Vector2(0,OFFSET.y),box_color,1,true)
|
||||||
|
|
||||||
func create_legend():
|
|
||||||
legend.clear()
|
|
||||||
for function in functions:
|
|
||||||
var function_legend = FunctionLegend.instance()
|
|
||||||
var f_name : String
|
|
||||||
if invert_chart:
|
|
||||||
f_name = x_datas[function] as String
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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_chart = !invert_chart
|
|
||||||
count_functions()
|
|
||||||
redraw()
|
|
||||||
create_legend()
|
|
||||||
|
|
||||||
func count_functions():
|
|
||||||
if are_values_columns:
|
|
||||||
if not invert_chart:
|
|
||||||
functions = datas[0].size()-1
|
|
||||||
else:
|
|
||||||
functions = datas.size()-1
|
|
||||||
else:
|
|
||||||
if invert_chart:
|
|
||||||
functions = datas[0].size()-1
|
|
||||||
else:
|
|
||||||
functions = datas.size()-1
|
|
||||||
|
|
||||||
func apply_template(template_name : int):
|
|
||||||
template = template_name
|
|
||||||
templates = Utilities._load_templates()
|
|
||||||
if template_name!=null:
|
|
||||||
var custom_template = templates.get(templates.keys()[template_name])
|
|
||||||
function_colors = custom_template.function_colors as PoolColorArray
|
|
||||||
v_lines_color = Color(custom_template.v_lines_color)
|
|
||||||
h_lines_color = Color(custom_template.h_lines_color)
|
|
||||||
box_color = Color(custom_template.outline_color)
|
|
||||||
font_color = Color(custom_template.font_color)
|
|
||||||
property_list_changed_notify()
|
|
||||||
|
|
||||||
func _enter_tree():
|
|
||||||
_ready()
|
|
||||||
|
@ -96,7 +96,7 @@ export(bool) var show_x_values_as_labels : bool = true
|
|||||||
|
|
||||||
export (float,0.1,10.0) var x_decim : float = 5.0
|
export (float,0.1,10.0) var x_decim : float = 5.0
|
||||||
export (float,0.1,10.0) var y_decim : float = 5.0
|
export (float,0.1,10.0) var y_decim : float = 5.0
|
||||||
export (point_shapes) var point_shape : int = 0
|
export (PointShapes) var point_shape : int = 0
|
||||||
export (PoolColorArray) var function_colors = [Color("#1e1e1e")]
|
export (PoolColorArray) var function_colors = [Color("#1e1e1e")]
|
||||||
export (Color) var v_lines_color : Color = Color("#cacaca")
|
export (Color) var v_lines_color : Color = Color("#cacaca")
|
||||||
export (Color) var h_lines_color : Color = Color("#cacaca")
|
export (Color) var h_lines_color : Color = Color("#cacaca")
|
||||||
@ -106,7 +106,7 @@ export (Color) var box_color : Color = Color("#1e1e1e")
|
|||||||
export (Font) var font : Font
|
export (Font) var font : Font
|
||||||
export (Font) var bold_font : Font
|
export (Font) var bold_font : Font
|
||||||
export (Color) var font_color : Color = Color("#1e1e1e")
|
export (Color) var font_color : Color = Color("#1e1e1e")
|
||||||
export (templates_names) var template : int = Chart.templates_names.Default setget apply_template
|
export (TemplatesNames) var template : int = Chart.TemplatesNames.Default setget apply_template
|
||||||
export (float,0.1,1) var drawing_duration : float = 0.5
|
export (float,0.1,1) var drawing_duration : float = 0.5
|
||||||
export (bool) var invert_chart : bool = false
|
export (bool) var invert_chart : bool = false
|
||||||
|
|
||||||
@ -562,3 +562,7 @@ func apply_template(template_name : int):
|
|||||||
|
|
||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
_ready()
|
_ready()
|
||||||
|
|
||||||
|
# Signal Repeaters
|
||||||
|
func point_pressed(point : Point) -> Point:
|
||||||
|
return point
|
||||||
|
@ -13,175 +13,116 @@ distinct correlations, trade-offs, and a multitude of other comparative measures
|
|||||||
/ source : Wikipedia /
|
/ source : Wikipedia /
|
||||||
"""
|
"""
|
||||||
|
|
||||||
onready var PointData = $PointData/PointData
|
func _get_property_list():
|
||||||
onready var Points = $Points
|
return [
|
||||||
onready var Legend = $Legend
|
# Chart Properties
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/are_values_columns",
|
||||||
|
"type": TYPE_BOOL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "-1,100,1",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/labels_index",
|
||||||
|
"type": TYPE_INT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "-1,100,1",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/function_names_index",
|
||||||
|
"type": TYPE_INT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/use_height_as_radius",
|
||||||
|
"type": TYPE_BOOL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "0,2000",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/radius",
|
||||||
|
"type": TYPE_REAL
|
||||||
|
},
|
||||||
|
|
||||||
var point_node : PackedScene = preload("../Utilities/Point/Point.tscn")
|
# Chart Display
|
||||||
var FunctionLegend : PackedScene = preload("../Utilities/Legend/FunctionLegend.tscn")
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "0.1,100",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Display/full_scale",
|
||||||
|
"type": TYPE_REAL
|
||||||
|
},
|
||||||
|
|
||||||
var font_size : float = 16
|
# Chart Style
|
||||||
var const_height : float = font_size/2*font_size/20
|
{
|
||||||
var const_width : float = font_size/2
|
"hint": 24,
|
||||||
|
"hint_string": "%d/%d:%s"%[TYPE_INT, PROPERTY_HINT_ENUM,
|
||||||
var OFFSET : Vector2 = Vector2(0,0)
|
PoolStringArray(PointShapes.keys()).join(",")],
|
||||||
|
"name": "Chart_Style/points_shape",
|
||||||
#-------------------------------------------------------------------------#
|
"type": TYPE_ARRAY,
|
||||||
var origin : Vector2
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE
|
||||||
|
},
|
||||||
# actual distance between x and y values
|
{
|
||||||
var x_pass : float
|
"hint": PROPERTY_HINT_NONE,
|
||||||
var y_pass : float
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/function_colors",
|
||||||
# vertical distance between y consecutive points used for intervals
|
"type": TYPE_COLOR_ARRAY
|
||||||
var v_dist : float
|
},
|
||||||
var h_dist : float
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
# quantization, representing the interval in which values will be displayed
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/outline_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
# define values on x an y axis
|
},
|
||||||
var x_chors : Array
|
{
|
||||||
var y_chors : Array
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
# actual coordinates of points (in pixel)
|
"name": "Chart_Style/grid_color",
|
||||||
var x_coordinates : Array
|
"type": TYPE_COLOR
|
||||||
var y_coordinates : Array
|
},
|
||||||
|
{
|
||||||
# datas contained in file
|
"class_name": "Font",
|
||||||
var datas : Array
|
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||||
|
"hint_string": "Font",
|
||||||
# amount of functions to represent
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
var functions : int = 0
|
"name": "Chart_Style/font",
|
||||||
|
"type": TYPE_OBJECT
|
||||||
|
},
|
||||||
# database values
|
{
|
||||||
var x_datas : Array
|
"class_name": "Font",
|
||||||
var y_datas : Array
|
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||||
|
"hint_string": "Font",
|
||||||
# labels displayed on chart
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
var x_label : String
|
"name": "Chart_Style/bold_font",
|
||||||
|
"type": TYPE_OBJECT
|
||||||
var x_labels : Array
|
},
|
||||||
var y_labels : Array
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
var x_margin_min : int = 0
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
var y_margin_min : int = 0
|
"name": "Chart_Style/font_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
# actual values of point, from the database
|
},
|
||||||
var point_values : Array
|
{
|
||||||
|
"hint": PROPERTY_HINT_ENUM,
|
||||||
# actual position of points in pixel
|
"hint_string": PoolStringArray(TemplatesNames.keys()).join(","),
|
||||||
var point_positions : Array
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/template",
|
||||||
var legend : Array setget set_legend,get_legend
|
"type": TYPE_INT
|
||||||
|
},
|
||||||
# ---------------------
|
{
|
||||||
var SIZE : Vector2 = Vector2()
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
export (String, FILE, "*.txt, *.csv") var source : String = "" setget set_source
|
"hint_string": "0,360",
|
||||||
export (String) var delimiter : String = ";"
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
#export (bool) var origin_at_zero : bool = true
|
"name": "Chart_Modifiers/rotation",
|
||||||
|
"type": TYPE_REAL
|
||||||
export (bool) var are_values_columns : bool = false
|
},
|
||||||
export (int,-1,100) var labels_index : int = 0
|
]
|
||||||
export (int,-1,100) var function_names_index : int = 0
|
|
||||||
#export(bool) var show_x_values_as_labels : bool = true
|
|
||||||
|
|
||||||
#export (float,1,20,0.5) var column_width : float = 10
|
|
||||||
#export (float,0,10,0.5) var column_gap : float = 2
|
|
||||||
export (bool) var use_height_as_radius : bool = false
|
|
||||||
export (float) var radius : float = 150.0
|
|
||||||
|
|
||||||
#export (float,0.1,10.0) var x_decim : float = 5.0
|
|
||||||
#export (float,0.1,10.0) var y_decim : float = 5.0
|
|
||||||
export (float,0.1,100) var full_scale : float = 1.0
|
|
||||||
|
|
||||||
export (point_shapes) var point_shape : int = 0
|
|
||||||
export (PoolColorArray) var function_colors = [Color("#1e1e1e")]
|
|
||||||
export (Color) var outline_color : Color = Color("#1e1e1e")
|
|
||||||
export (Color) var grid_color : Color = Color("#1e1e1e")
|
|
||||||
export (Font) var font : Font
|
|
||||||
export (Font) var bold_font : Font
|
|
||||||
export (Color) var font_color : Color = Color("#1e1e1e")
|
|
||||||
|
|
||||||
export (templates_names) var template : int = Chart.templates_names.Default setget apply_template
|
|
||||||
#export (bool) var invert_chart : bool = false
|
|
||||||
export (float,0,360) var rotation : float = 0
|
|
||||||
|
|
||||||
var templates : Dictionary = {}
|
|
||||||
|
|
||||||
signal chart_plotted(chart)
|
|
||||||
signal point_pressed(point)
|
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
|
||||||
pass
|
|
||||||
|
|
||||||
func _plot(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_values_index_ : int, invert_chart_ : bool = false):
|
|
||||||
randomize()
|
|
||||||
|
|
||||||
load_font()
|
|
||||||
PointData.hide()
|
|
||||||
|
|
||||||
datas = read_datas(source_,delimiter_)
|
|
||||||
structure_datas(datas,are_values_columns_,x_values_index_)
|
|
||||||
build_chart()
|
|
||||||
count_functions()
|
|
||||||
calculate_pass()
|
|
||||||
calculate_coordinates()
|
|
||||||
calculate_colors()
|
|
||||||
create_legend()
|
|
||||||
emit_signal("chart_plotted")
|
|
||||||
|
|
||||||
func plot():
|
|
||||||
randomize()
|
|
||||||
|
|
||||||
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)
|
|
||||||
structure_datas(datas,are_values_columns,labels_index)
|
|
||||||
build_chart()
|
|
||||||
count_functions()
|
|
||||||
calculate_pass()
|
|
||||||
calculate_coordinates()
|
|
||||||
calculate_colors()
|
|
||||||
create_legend()
|
|
||||||
emit_signal("chart_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 or data.empty():
|
|
||||||
content.erase(data)
|
|
||||||
return content
|
|
||||||
|
|
||||||
func structure_datas(database : Array, are_values_columns : bool, labels_index : int):
|
func structure_datas(database : Array, are_values_columns : bool, labels_index : int):
|
||||||
# @x_values_index can be either a column or a row relative to x values
|
# @x_values_index can be either a column or a row relative to x values
|
||||||
@ -251,8 +192,8 @@ func calculate_coordinates():
|
|||||||
var scalar_factor : float = (x_chors[chor] as float/x_chors.back() as float)
|
var scalar_factor : float = (x_chors[chor] as float/x_chors.back() as float)
|
||||||
for function in functions:
|
for function in functions:
|
||||||
var angle : float = ((2 * PI * function) / functions) - PI /2 + deg2rad(rotation)
|
var angle : float = ((2 * PI * function) / functions) - PI /2 + deg2rad(rotation)
|
||||||
var x_coordinate : float = (radius if not use_height_as_radius else SIZE.y/2) * scalar_factor * cos(angle) + origin.x
|
var x_coordinate : float = (radius if (not use_height_as_radius and radius<SIZE.y/2) else SIZE.y/2) * scalar_factor * cos(angle) + origin.x
|
||||||
var y_coordinate : float = (radius if not use_height_as_radius else SIZE.y/2) * scalar_factor * sin(angle) + origin.y
|
var y_coordinate : float = (radius if (not use_height_as_radius and radius<SIZE.y/2) else SIZE.y/2) * scalar_factor * sin(angle) + origin.y
|
||||||
inner_polyline.append(Vector2(x_coordinate, y_coordinate))
|
inner_polyline.append(Vector2(x_coordinate, y_coordinate))
|
||||||
inner_polyline.append(inner_polyline[0])
|
inner_polyline.append(inner_polyline[0])
|
||||||
radar_polygon.append(inner_polyline)
|
radar_polygon.append(inner_polyline)
|
||||||
@ -263,20 +204,14 @@ func calculate_coordinates():
|
|||||||
for data in datas.size():
|
for data in datas.size():
|
||||||
var scalar_factor : float = datas[data] /( x_chors.back() as float)
|
var scalar_factor : float = datas[data] /( x_chors.back() as float)
|
||||||
var angle : float = ((2 * PI * data) / datas.size()) - PI/2 + deg2rad(rotation)
|
var angle : float = ((2 * PI * data) / datas.size()) - PI/2 + deg2rad(rotation)
|
||||||
var x_coordinate : float = (radius if not use_height_as_radius else SIZE.y/2) * scalar_factor * cos(angle) + origin.x
|
var x_coordinate : float = (radius if (not use_height_as_radius and radius<SIZE.y/2) else SIZE.y/2) * scalar_factor * cos(angle) + origin.x
|
||||||
var y_coordinate : float = (radius if not use_height_as_radius else SIZE.y/2) * scalar_factor * sin(angle) + origin.y
|
var y_coordinate : float = (radius if (not use_height_as_radius and radius<SIZE.y/2) else SIZE.y/2) * scalar_factor * sin(angle) + origin.y
|
||||||
function_positions.append(Vector2(x_coordinate,y_coordinate))
|
function_positions.append(Vector2(x_coordinate,y_coordinate))
|
||||||
function_values.append([x_labels[data], datas[data]])
|
function_values.append([x_labels[data], datas[data]])
|
||||||
function_positions.append(function_positions[0])
|
function_positions.append(function_positions[0])
|
||||||
point_positions.append(function_positions)
|
point_positions.append(function_positions)
|
||||||
point_values.append(function_values)
|
point_values.append(function_values)
|
||||||
|
|
||||||
func redraw():
|
|
||||||
build_chart()
|
|
||||||
calculate_pass()
|
|
||||||
calculate_coordinates()
|
|
||||||
update()
|
|
||||||
|
|
||||||
func _draw():
|
func _draw():
|
||||||
if Engine.editor_hint:
|
if Engine.editor_hint:
|
||||||
return
|
return
|
||||||
@ -299,7 +234,7 @@ func _draw():
|
|||||||
point.connect("_mouse_entered",self,"show_data")
|
point.connect("_mouse_entered",self,"show_data")
|
||||||
point.connect("_mouse_exited",self,"hide_data")
|
point.connect("_mouse_exited",self,"hide_data")
|
||||||
|
|
||||||
point.create_point(point_shape, function_colors[_function],
|
point.create_point(points_shape[_function], function_colors[_function],
|
||||||
Color.white, point_positions[_function][function_point],
|
Color.white, point_positions[_function][function_point],
|
||||||
point.format_value(point_values[_function][function_point], false, false),
|
point.format_value(point_values[_function][function_point], false, false),
|
||||||
y_labels[_function])
|
y_labels[_function])
|
||||||
@ -319,59 +254,26 @@ func draw_grid():
|
|||||||
for label in x_labels.size():
|
for label in x_labels.size():
|
||||||
var point_array : PoolVector2Array = radar_polygon[radar_polygon.size()-1]
|
var point_array : PoolVector2Array = radar_polygon[radar_polygon.size()-1]
|
||||||
draw_line(origin, point_array[label], grid_color, 1, true)
|
draw_line(origin, point_array[label], grid_color, 1, true)
|
||||||
draw_string(font, point_array[label] - (Vector2(font.get_string_size(x_labels[label]).x/2,0) if point_array[label].x < origin.x else - Vector2(5,0)), x_labels[label], font_color)
|
|
||||||
|
|
||||||
|
|
||||||
|
if point_array[label].x != origin.x:
|
||||||
|
draw_string(font, point_array[label] - (Vector2(font.get_string_size(x_labels[label]).x+10,(5 if point_array[label].y <= origin.y else -10)) if point_array[label].x <= origin.x else - Vector2(10,(-5 if point_array[label].y <= origin.y else 10))), x_labels[label], font_color)
|
||||||
|
else:
|
||||||
|
draw_string(font, point_array[label] - (Vector2(font.get_string_size(x_labels[label]).x/2, 10) if point_array[label].y < origin.x else - Vector2(font.get_string_size(x_labels[label]).x/2, 5)), x_labels[label], font_color)
|
||||||
|
|
||||||
func create_legend():
|
func create_legend():
|
||||||
legend.clear()
|
pass
|
||||||
for function in functions:
|
# legend.clear()
|
||||||
var function_legend = FunctionLegend.instance()
|
# for function in functions:
|
||||||
var f_name : String = x_labels[function]
|
# var function_legend = FunctionLegend.instance()
|
||||||
var legend_font : Font
|
# var f_name : String = x_labels[function]
|
||||||
if font != null:
|
# var legend_font : Font
|
||||||
legend_font = font
|
# if font != null:
|
||||||
if bold_font != null:
|
# legend_font = font
|
||||||
legend_font = bold_font
|
# if bold_font != null:
|
||||||
function_legend.create_legend(f_name,function_colors[function],bold_font,font_color)
|
# legend_font = bold_font
|
||||||
legend.append(function_legend)
|
# function_legend.create_legend(f_name,function_colors[function],bold_font,font_color)
|
||||||
|
# legend.append(function_legend)
|
||||||
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 count_functions():
|
func count_functions():
|
||||||
self.functions = x_labels.size()
|
if x_labels.size():
|
||||||
|
functions = x_labels.size()
|
||||||
func apply_template(template_name : int):
|
|
||||||
template = template_name
|
|
||||||
templates = Utilities._load_templates()
|
|
||||||
if template_name!=null:
|
|
||||||
var custom_template = templates.get(templates.keys()[template_name])
|
|
||||||
function_colors = custom_template.function_colors as PoolColorArray
|
|
||||||
outline_color = Color(custom_template.outline_color)
|
|
||||||
grid_color = Color(custom_template.v_lines_color)
|
|
||||||
font_color = Color(custom_template.font_color)
|
|
||||||
property_list_changed_notify()
|
|
||||||
|
|
||||||
func _enter_tree():
|
|
||||||
_ready()
|
|
||||||
|
|
||||||
func set_source(source_file : String):
|
|
||||||
source = source_file
|
|
||||||
|
@ -13,172 +13,118 @@ the horizontal axis and the value of the other variable determining the position
|
|||||||
/ source : Wikipedia /
|
/ source : Wikipedia /
|
||||||
"""
|
"""
|
||||||
|
|
||||||
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 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
|
|
||||||
var h_dist : float
|
|
||||||
|
|
||||||
# quantization, representing the interval in which values will be displayed
|
|
||||||
|
|
||||||
|
|
||||||
# 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 x_labels : Array
|
|
||||||
var y_labels : Array
|
|
||||||
|
|
||||||
var x_margin_min : int = 0
|
|
||||||
var y_margin_min : int = 0
|
|
||||||
|
|
||||||
# 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 SIZE : Vector2 = Vector2()
|
|
||||||
export (String, FILE, "*.txt, *.csv") var source : String = ""
|
|
||||||
export (String) var delimiter : String = ";"
|
|
||||||
export (bool) var origin_at_zero : bool = true
|
|
||||||
|
|
||||||
export (bool) var are_values_columns : bool = false
|
func _get_property_list():
|
||||||
export (int,0,100) var x_values_index : int = 0
|
return [
|
||||||
export(bool) var show_x_values_as_labels : bool = true
|
# Chart Properties
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/are_values_columns",
|
||||||
|
"type": TYPE_BOOL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "-1,100,1",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/labels_index",
|
||||||
|
"type": TYPE_INT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Properties/show_x_values_as_labels",
|
||||||
|
"type": TYPE_BOOL
|
||||||
|
},
|
||||||
|
|
||||||
#export (float,1,20,0.5) var column_width : float = 10
|
# Chart Display
|
||||||
#export (float,0,10,0.5) var column_gap : float = 2
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "0.1,10",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Display/x_decim",
|
||||||
|
"type": TYPE_REAL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_RANGE,
|
||||||
|
"hint_string": "0.1,10",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Display/y_decim",
|
||||||
|
"type": TYPE_REAL
|
||||||
|
},
|
||||||
|
|
||||||
export (float,0.1,10.0) var x_decim : float = 5.0
|
# Chart Style
|
||||||
export (float,0.1,10.0) var y_decim : float = 5.0
|
{
|
||||||
export (point_shapes) var point_shape : int = 0
|
"hint": 24,
|
||||||
export (PoolColorArray) var function_colors = [Color("#1e1e1e")]
|
"hint_string": "%d/%d:%s"%[TYPE_INT, PROPERTY_HINT_ENUM,
|
||||||
export (Color) var v_lines_color : Color = Color("#cacaca")
|
PoolStringArray(PointShapes.keys()).join(",")],
|
||||||
export (Color) var h_lines_color : Color = Color("#cacaca")
|
"name": "Chart_Style/points_shape",
|
||||||
|
"type": TYPE_ARRAY,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/function_colors",
|
||||||
|
"type": TYPE_COLOR_ARRAY
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/box_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/v_lines_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/h_lines_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"class_name": "Font",
|
||||||
|
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||||
|
"hint_string": "Font",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/font",
|
||||||
|
"type": TYPE_OBJECT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"class_name": "Font",
|
||||||
|
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||||
|
"hint_string": "Font",
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/bold_font",
|
||||||
|
"type": TYPE_OBJECT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_NONE,
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/font_color",
|
||||||
|
"type": TYPE_COLOR
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hint": PROPERTY_HINT_ENUM,
|
||||||
|
"hint_string": PoolStringArray(TemplatesNames.keys()).join(","),
|
||||||
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
|
"name": "Chart_Style/template",
|
||||||
|
"type": TYPE_INT
|
||||||
|
},
|
||||||
|
|
||||||
export (bool) var boxed : bool = true
|
# Chart Modifiers
|
||||||
export (Color) var box_color : Color = Color("#1e1e1e")
|
{
|
||||||
export (Font) var font : Font
|
"hint": PROPERTY_HINT_NONE,
|
||||||
export (Font) var bold_font : Font
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||||
export (Color) var font_color : Color = Color("#1e1e1e")
|
"name": "Chart_Modifiers/invert_chart",
|
||||||
export (templates_names) var template : int = templates_names.Default setget apply_template
|
"type": TYPE_BOOL
|
||||||
export (bool) var invert_chart : bool = false
|
},
|
||||||
|
]
|
||||||
|
|
||||||
var templates : Dictionary = {}
|
|
||||||
|
|
||||||
signal chart_plotted(chart)
|
|
||||||
signal point_pressed(point)
|
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
|
||||||
pass
|
|
||||||
|
|
||||||
func _plot(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_values_index_ : int, invert_chart_ : bool = false):
|
|
||||||
randomize()
|
|
||||||
|
|
||||||
load_font()
|
|
||||||
PointData.hide()
|
|
||||||
|
|
||||||
datas = read_datas(source_,delimiter_)
|
|
||||||
count_functions()
|
|
||||||
structure_datas(datas,are_values_columns_,x_values_index_)
|
|
||||||
build_chart()
|
|
||||||
calculate_pass()
|
|
||||||
calculate_coordinates()
|
|
||||||
calculate_colors()
|
|
||||||
create_legend()
|
|
||||||
emit_signal("chart_plotted")
|
|
||||||
|
|
||||||
func plot():
|
|
||||||
randomize()
|
|
||||||
|
|
||||||
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_index)
|
|
||||||
build_chart()
|
|
||||||
calculate_pass()
|
|
||||||
calculate_coordinates()
|
|
||||||
calculate_colors()
|
|
||||||
create_legend()
|
|
||||||
emit_signal("chart_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_index : int):
|
func structure_datas(database : Array, are_values_columns : bool, x_values_index : int):
|
||||||
# @x_values_index can be either a column or a row relative to x values
|
# @x_values_index can be either a column or a row relative to x values
|
||||||
@ -343,12 +289,6 @@ func calculate_coordinates():
|
|||||||
point_values[cluster].append([x_datas[y],y_datas[cluster][y]])
|
point_values[cluster].append([x_datas[y],y_datas[cluster][y]])
|
||||||
point_positions[cluster].append(Vector2(x_coordinates[y]+origin.x,origin.y-y_coordinates[cluster][y]))
|
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():
|
func _draw():
|
||||||
clear_points()
|
clear_points()
|
||||||
|
|
||||||
@ -369,30 +309,13 @@ func _draw():
|
|||||||
point.connect("_mouse_entered",self,"show_data")
|
point.connect("_mouse_entered",self,"show_data")
|
||||||
point.connect("_mouse_exited",self,"hide_data")
|
point.connect("_mouse_exited",self,"hide_data")
|
||||||
|
|
||||||
point.create_point(point_shape, function_colors[function_point if invert_chart else _function],
|
point.create_point(points_shape[_function], function_colors[function_point if invert_chart else _function],
|
||||||
Color.white, point_positions[_function][function_point],
|
Color.white, point_positions[_function][function_point],
|
||||||
point.format_value(point_values[_function][function_point], false, false),
|
point.format_value(point_values[_function][function_point], false, false),
|
||||||
y_labels[function_point if invert_chart else _function] as String)
|
y_labels[function_point if invert_chart else _function] as String)
|
||||||
|
|
||||||
PointContainer.add_child(point)
|
PointContainer.add_child(point)
|
||||||
|
|
||||||
func create_legend():
|
|
||||||
legend.clear()
|
|
||||||
for function in functions:
|
|
||||||
var function_legend = FunctionLegend.instance()
|
|
||||||
var f_name : String
|
|
||||||
if invert_chart:
|
|
||||||
f_name = x_datas[function] as String
|
|
||||||
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():
|
func draw_grid():
|
||||||
# ascisse
|
# ascisse
|
||||||
for p in x_chors.size():
|
for p in x_chors.size():
|
||||||
@ -417,96 +340,3 @@ func draw_chart_outlines():
|
|||||||
draw_line(origin,Vector2(OFFSET.x,0),box_color,1,true)
|
draw_line(origin,Vector2(OFFSET.x,0),box_color,1,true)
|
||||||
draw_line(Vector2(OFFSET.x,0),Vector2(SIZE.x,0),box_color,1,true)
|
draw_line(Vector2(OFFSET.x,0),Vector2(SIZE.x,0),box_color,1,true)
|
||||||
draw_line(Vector2(SIZE.x,0),SIZE-Vector2(0,OFFSET.y),box_color,1,true)
|
draw_line(Vector2(SIZE.x,0),SIZE-Vector2(0,OFFSET.y),box_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_chart = !invert_chart
|
|
||||||
count_functions()
|
|
||||||
redraw()
|
|
||||||
create_legend()
|
|
||||||
|
|
||||||
func count_functions():
|
|
||||||
if are_values_columns:
|
|
||||||
if not invert_chart:
|
|
||||||
functions = datas[0].size()-1
|
|
||||||
else:
|
|
||||||
functions = datas.size()-1
|
|
||||||
else:
|
|
||||||
if invert_chart:
|
|
||||||
functions = datas[0].size()-1
|
|
||||||
else:
|
|
||||||
functions = datas.size()-1
|
|
||||||
|
|
||||||
func apply_template(template_name : int):
|
|
||||||
template = template_name
|
|
||||||
templates = Utilities._load_templates()
|
|
||||||
if template_name!=null:
|
|
||||||
var custom_template = templates.get(templates.keys()[template_name])
|
|
||||||
function_colors = custom_template.function_colors as PoolColorArray
|
|
||||||
v_lines_color = Color(custom_template.v_lines_color)
|
|
||||||
h_lines_color = Color(custom_template.h_lines_color)
|
|
||||||
box_color = Color(custom_template.outline_color)
|
|
||||||
font_color = Color(custom_template.font_color)
|
|
||||||
property_list_changed_notify()
|
|
||||||
|
|
||||||
func _enter_tree():
|
|
||||||
templates = Utilities._load_templates()
|
|
||||||
_ready()
|
|
||||||
|
@ -93,7 +93,7 @@ export(bool) var show_x_values_as_labels : bool = true
|
|||||||
|
|
||||||
export (float,0.1,10.0) var x_decim : float = 5.0
|
export (float,0.1,10.0) var x_decim : float = 5.0
|
||||||
export (float,0.1,10.0) var y_decim : float = 5.0
|
export (float,0.1,10.0) var y_decim : float = 5.0
|
||||||
export (point_shapes) var point_shape : int = 0
|
export (Array, PointShapes) var points_shape : Array = 0
|
||||||
export (PoolColorArray) var function_colors = [Color("#1e1e1e")] as PoolColorArray
|
export (PoolColorArray) var function_colors = [Color("#1e1e1e")] as PoolColorArray
|
||||||
export (Color) var v_lines_color : Color = Color("#cacaca")
|
export (Color) var v_lines_color : Color = Color("#cacaca")
|
||||||
export (Color) var h_lines_color : Color = Color("#cacaca")
|
export (Color) var h_lines_color : Color = Color("#cacaca")
|
||||||
@ -103,7 +103,7 @@ export (Color) var box_color : Color = Color("#1e1e1e")
|
|||||||
export (Font) var font : Font
|
export (Font) var font : Font
|
||||||
export (Font) var bold_font : Font
|
export (Font) var bold_font : Font
|
||||||
export (Color) var font_color : Color = Color("#1e1e1e")
|
export (Color) var font_color : Color = Color("#1e1e1e")
|
||||||
export (templates_names) var template : int = templates_names.Default setget apply_template
|
export (TemplatesNames) var template : int = TemplatesNames.Default setget apply_template
|
||||||
export (float,0.1,1) var drawing_duration : float = 0.5
|
export (float,0.1,1) var drawing_duration : float = 0.5
|
||||||
export (bool) var invert_chart : bool = false
|
export (bool) var invert_chart : bool = false
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ signal _point_pressed(point)
|
|||||||
func _ready():
|
func _ready():
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
func _draw():
|
func _draw():
|
||||||
if mouse_entered:
|
if mouse_entered:
|
||||||
draw_point(7,color_outline)
|
draw_point(7,color_outline)
|
||||||
@ -35,12 +34,12 @@ func draw_point(size : float, color : Color):
|
|||||||
SHAPES.DOT:
|
SHAPES.DOT:
|
||||||
draw_circle(OFFSET, size, color)
|
draw_circle(OFFSET, size, color)
|
||||||
SHAPES.TRIANGLE:
|
SHAPES.TRIANGLE:
|
||||||
size+=4
|
size+=6
|
||||||
draw_colored_polygon([
|
draw_colored_polygon([
|
||||||
OFFSET-Vector2(0,size/2), OFFSET+Vector2(1,1)*size/2, OFFSET-Vector2(1,-1)*size/2
|
OFFSET-Vector2(0,size/2), OFFSET+Vector2(1,1)*size/2, OFFSET-Vector2(1,-1)*size/2
|
||||||
], color,[],null,null,false)
|
], color,[],null,null,false)
|
||||||
SHAPES.SQUARE:
|
SHAPES.SQUARE:
|
||||||
size+=2
|
size+=4
|
||||||
draw_colored_polygon([
|
draw_colored_polygon([
|
||||||
OFFSET-Vector2(1,1)*size/2, OFFSET-Vector2(-1,1)*size/2, OFFSET+Vector2(1,1)*size/2, OFFSET-Vector2(1,-1)*size/2
|
OFFSET-Vector2(1,1)*size/2, OFFSET-Vector2(-1,1)*size/2, OFFSET+Vector2(1,1)*size/2, OFFSET-Vector2(1,-1)*size/2
|
||||||
], color,[],null,null,false)
|
], color,[],null,null,false)
|
||||||
@ -69,6 +68,12 @@ func _on_Point_mouse_exited():
|
|||||||
emit_signal("_mouse_exited")
|
emit_signal("_mouse_exited")
|
||||||
update()
|
update()
|
||||||
|
|
||||||
|
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 format_value(v : Array, format_x : bool, format_y : bool):
|
func format_value(v : Array, format_x : bool, format_y : bool):
|
||||||
var x : String = str(v[0])
|
var x : String = str(v[0])
|
||||||
var y : String = str(v[1])
|
var y : String = str(v[1])
|
||||||
@ -92,33 +97,27 @@ func format(n):
|
|||||||
|
|
||||||
return s.replace("Null","")
|
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 = [] ) :
|
func set_value( v : Array = [] ) :
|
||||||
point_value = v
|
point_value = v
|
||||||
|
|
||||||
func get_value() -> Array:
|
|
||||||
return point_value
|
|
||||||
|
|
||||||
func set_color_point( c : Color ):
|
func set_color_point( c : Color ):
|
||||||
color = c
|
color = c
|
||||||
|
|
||||||
func get_color_point() -> Color:
|
|
||||||
return color
|
|
||||||
|
|
||||||
func set_function( f : String ):
|
func set_function( f : String ):
|
||||||
function = f
|
function = f
|
||||||
|
|
||||||
func get_function() -> String:
|
|
||||||
return function
|
|
||||||
|
|
||||||
func set_shape(s : int):
|
func set_shape(s : int):
|
||||||
shape = s
|
shape = s
|
||||||
|
|
||||||
|
# Public Getters
|
||||||
|
func get_value() -> Array:
|
||||||
|
return point_value
|
||||||
|
|
||||||
|
func get_color_point() -> Color:
|
||||||
|
return color
|
||||||
|
|
||||||
|
func get_function() -> String:
|
||||||
|
return function
|
||||||
|
|
||||||
func get_shape() -> int:
|
func get_shape() -> int:
|
||||||
return shape
|
return shape
|
||||||
|
@ -1,5 +1,537 @@
|
|||||||
extends Control
|
extends Control
|
||||||
class_name Chart
|
class_name Chart
|
||||||
|
|
||||||
enum point_shapes { Dot, Triangle, Square, Cross }
|
# Signals ..................................
|
||||||
enum templates_names { Default, Clean, Gradient, Minimal, Invert }
|
signal chart_plotted(chart)
|
||||||
|
signal point_pressed(point)
|
||||||
|
|
||||||
|
# Onready Vars ............................
|
||||||
|
onready var PointData = $PointData/PointData
|
||||||
|
onready var Points = $Points
|
||||||
|
onready var Legend = $Legend
|
||||||
|
|
||||||
|
# Scenes and Reosurces ......................
|
||||||
|
var point_node : PackedScene = preload("../Point/Point.tscn")
|
||||||
|
var FunctionLegend : PackedScene = preload("../Legend/FunctionLegend.tscn")
|
||||||
|
|
||||||
|
# Enums .....................................
|
||||||
|
enum PointShapes { Dot, Triangle, Square, Cross }
|
||||||
|
enum TemplatesNames { Default, Clean, Gradient, Minimal, Invert }
|
||||||
|
|
||||||
|
# Shared Variables .........................
|
||||||
|
var SIZE : Vector2 = Vector2()
|
||||||
|
var OFFSET : Vector2 = Vector2(0,0)
|
||||||
|
var origin : Vector2
|
||||||
|
|
||||||
|
var font_size : float = 16
|
||||||
|
var const_height : float = font_size/2*font_size/20
|
||||||
|
var const_width : float = font_size/2
|
||||||
|
|
||||||
|
# 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
|
||||||
|
var h_dist : float
|
||||||
|
|
||||||
|
# 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 x_labels : Array
|
||||||
|
var y_labels : Array
|
||||||
|
|
||||||
|
var x_margin_min : int = 0
|
||||||
|
var y_margin_min : int = 0
|
||||||
|
|
||||||
|
# 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 templates : Dictionary = {}
|
||||||
|
|
||||||
|
# ................... Export Shared Variables ..................
|
||||||
|
export (String, FILE, "*.txt, *.csv") var source : String = "" setget set_source
|
||||||
|
export (String) var delimiter : String = ";" setget set_delimiter
|
||||||
|
|
||||||
|
var origin_at_zero : bool = true setget set_origin_at_zero#, get_origin_at_zero
|
||||||
|
var are_values_columns : bool = false setget set_are_values_columns#, get_are_values_columns
|
||||||
|
var show_x_values_as_labels : bool = true setget set_show_x_values_as_labels#, get_show_x_values_as_labels
|
||||||
|
var labels_index : int = 0 setget set_labels_index#, get_labels_index
|
||||||
|
var function_names_index : int = 0 setget set_function_names_index#, get_function_names_index
|
||||||
|
|
||||||
|
# for radar
|
||||||
|
var use_height_as_radius : bool = false setget set_use_height_as_radius
|
||||||
|
var radius : float = 150.0 setget _set_radius
|
||||||
|
|
||||||
|
# for columns
|
||||||
|
var column_width : float = 10 setget set_column_width
|
||||||
|
var column_gap : float = 2 setget set_column_gap
|
||||||
|
|
||||||
|
var full_scale : float = 1.0 setget set_full_scale
|
||||||
|
var x_decim : float = 5.0 setget set_x_decim
|
||||||
|
var y_decim : float = 5.0 setget set_y_decim
|
||||||
|
|
||||||
|
var points_shape : Array = [PointShapes.Dot] setget set_points_shape
|
||||||
|
var function_colors = [Color("#1e1e1e")] setget set_function_colors
|
||||||
|
var outline_color : Color = Color("#1e1e1e") setget set_outline_color
|
||||||
|
var box_color : Color = Color("#1e1e1e") setget set_box_color
|
||||||
|
var v_lines_color : Color = Color("#cacaca") setget set_v_lines_color
|
||||||
|
var h_lines_color : Color = Color("#cacaca") setget set_h_lines_color
|
||||||
|
var grid_color : Color = Color("#1e1e1e") setget set_grid_color
|
||||||
|
var font : Font setget set_font
|
||||||
|
var bold_font : Font setget set_bold_font
|
||||||
|
var font_color : Color = Color("#1e1e1e") setget set_font_color
|
||||||
|
|
||||||
|
var template : int = TemplatesNames.Default setget set_template
|
||||||
|
|
||||||
|
# modifiers
|
||||||
|
var rotation : float = 0 setget set_rotation
|
||||||
|
var invert_chart : bool = false setget set_invert_chart
|
||||||
|
|
||||||
|
# .......................... Properties Manager ....................................
|
||||||
|
func _get(property):
|
||||||
|
match property:
|
||||||
|
"Chart_Properties/origin_at_zero":
|
||||||
|
return origin_at_zero
|
||||||
|
"Chart_Properties/are_values_columns":
|
||||||
|
return are_values_columns
|
||||||
|
"Chart_Properties/show_x_values_as_labels":
|
||||||
|
return show_x_values_as_labels
|
||||||
|
"Chart_Properties/labels_index":
|
||||||
|
return labels_index
|
||||||
|
"Chart_Properties/function_names_index":
|
||||||
|
return function_names_index
|
||||||
|
"Chart_Properties/use_height_as_radius":
|
||||||
|
return use_height_as_radius
|
||||||
|
"Chart_Properties/radius":
|
||||||
|
return radius
|
||||||
|
"Chart_Properties/column_width":
|
||||||
|
return column_width
|
||||||
|
"Chart_Properties/column_gap":
|
||||||
|
return column_gap
|
||||||
|
|
||||||
|
"Chart_Display/full_scale":
|
||||||
|
return full_scale
|
||||||
|
"Chart_Display/x_decim":
|
||||||
|
return x_decim
|
||||||
|
"Chart_Display/y_decim":
|
||||||
|
return y_decim
|
||||||
|
|
||||||
|
"Chart_Style/points_shape":
|
||||||
|
return points_shape
|
||||||
|
"Chart_Style/function_colors":
|
||||||
|
return function_colors
|
||||||
|
"Chart_Style/template":
|
||||||
|
return template
|
||||||
|
"Chart_Style/outline_color":
|
||||||
|
return outline_color
|
||||||
|
"Chart_Style/grid_color":
|
||||||
|
return grid_color
|
||||||
|
"Chart_Style/box_color":
|
||||||
|
return box_color
|
||||||
|
"Chart_Style/v_lines_color":
|
||||||
|
return v_lines_color
|
||||||
|
"Chart_Style/h_lines_color":
|
||||||
|
return h_lines_color
|
||||||
|
"Chart_Style/font":
|
||||||
|
return font
|
||||||
|
"Chart_Style/bold_font":
|
||||||
|
return bold_font
|
||||||
|
"Chart_Style/font_color":
|
||||||
|
return font_color
|
||||||
|
|
||||||
|
"Chart_Modifiers/rotation":
|
||||||
|
return rotation
|
||||||
|
"Chart_Modifiers/invert_chart":
|
||||||
|
return invert_chart
|
||||||
|
|
||||||
|
func _set(property, value):
|
||||||
|
match property:
|
||||||
|
"Chart_Properties/origin_at_zero":
|
||||||
|
origin_at_zero = value
|
||||||
|
return true
|
||||||
|
"Chart_Properties/are_values_columns":
|
||||||
|
are_values_columns = value
|
||||||
|
return true
|
||||||
|
"Chart_Properties/show_x_values_as_labels":
|
||||||
|
show_x_values_as_labels = value
|
||||||
|
return true
|
||||||
|
"Chart_Properties/labels_index":
|
||||||
|
labels_index = value
|
||||||
|
return true
|
||||||
|
"Chart_Properties/function_names_index":
|
||||||
|
function_names_index = value
|
||||||
|
return true
|
||||||
|
"Chart_Properties/use_height_as_radius":
|
||||||
|
use_height_as_radius = value
|
||||||
|
return true
|
||||||
|
"Chart_Properties/radius":
|
||||||
|
radius = value
|
||||||
|
return true
|
||||||
|
"Chart_Properties/column_width":
|
||||||
|
column_width = value
|
||||||
|
return true
|
||||||
|
"Chart_Properties/column_gap":
|
||||||
|
column_width = value
|
||||||
|
return true
|
||||||
|
|
||||||
|
"Chart_Display/full_scale":
|
||||||
|
full_scale = value
|
||||||
|
return true
|
||||||
|
"Chart_Display/x_decim":
|
||||||
|
x_decim = value
|
||||||
|
return true
|
||||||
|
"Chart_Display/y_decim":
|
||||||
|
y_decim = value
|
||||||
|
return true
|
||||||
|
|
||||||
|
"Chart_Style/points_shape":
|
||||||
|
points_shape = value
|
||||||
|
return true
|
||||||
|
"Chart_Style/function_colors":
|
||||||
|
function_colors = value
|
||||||
|
return true
|
||||||
|
"Chart_Style/template":
|
||||||
|
template = value
|
||||||
|
apply_template(template)
|
||||||
|
return true
|
||||||
|
"Chart_Style/outline_color":
|
||||||
|
outline_color = value
|
||||||
|
return true
|
||||||
|
"Chart_Style/grid_color":
|
||||||
|
grid_color = value
|
||||||
|
return true
|
||||||
|
"Chart_Style/box_color":
|
||||||
|
box_color = value
|
||||||
|
return true
|
||||||
|
"Chart_Style/v_lines_color":
|
||||||
|
v_lines_color = value
|
||||||
|
return true
|
||||||
|
"Chart_Style/h_lines_color":
|
||||||
|
h_lines_color = value
|
||||||
|
return true
|
||||||
|
"Chart_Style/font":
|
||||||
|
font = value
|
||||||
|
return true
|
||||||
|
"Chart_Style/bold_font":
|
||||||
|
bold_font = value
|
||||||
|
return true
|
||||||
|
"Chart_Style/font_color":
|
||||||
|
font_color = value
|
||||||
|
apply_template(template)
|
||||||
|
return true
|
||||||
|
|
||||||
|
"Chart_Modifiers/rotation":
|
||||||
|
rotation = value
|
||||||
|
return true
|
||||||
|
"Chart_Modifiers/invert_chart":
|
||||||
|
invert_chart = value
|
||||||
|
return true
|
||||||
|
|
||||||
|
# .......................... Shared Functions and virtuals ........................
|
||||||
|
|
||||||
|
#func _plot(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_values_index_ : int, invert_chart_ : bool = false):
|
||||||
|
# randomize()
|
||||||
|
#
|
||||||
|
# load_font()
|
||||||
|
# PointData.hide()
|
||||||
|
#
|
||||||
|
# datas = read_datas(source_,delimiter_)
|
||||||
|
# structure_datas(datas,are_values_columns_,x_values_index_)
|
||||||
|
# build_chart()
|
||||||
|
# count_functions()
|
||||||
|
# calculate_pass()
|
||||||
|
# calculate_coordinates()
|
||||||
|
# calculate_colors()
|
||||||
|
# set_shapes()
|
||||||
|
# create_legend()
|
||||||
|
# emit_signal("chart_plotted")
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
templates = Utilities._load_templates()
|
||||||
|
|
||||||
|
func plot():
|
||||||
|
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)
|
||||||
|
structure_datas(datas,are_values_columns,labels_index)
|
||||||
|
build_chart()
|
||||||
|
count_functions()
|
||||||
|
calculate_pass()
|
||||||
|
calculate_coordinates()
|
||||||
|
calculate_colors()
|
||||||
|
set_shapes()
|
||||||
|
create_legend()
|
||||||
|
emit_signal("chart_plotted",self)
|
||||||
|
|
||||||
|
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 calculate_colors():
|
||||||
|
if function_colors.empty() or function_colors.size() < functions:
|
||||||
|
for function in functions:
|
||||||
|
function_colors.append(Color("#1e1e1e"))
|
||||||
|
|
||||||
|
func set_shapes():
|
||||||
|
if points_shape.empty() or points_shape.size() < functions:
|
||||||
|
for function in functions:
|
||||||
|
points_shape.append(PointShapes.Dot)
|
||||||
|
|
||||||
|
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 or data.empty():
|
||||||
|
content.erase(data)
|
||||||
|
return content
|
||||||
|
|
||||||
|
func count_functions():
|
||||||
|
if are_values_columns:
|
||||||
|
if not invert_chart:
|
||||||
|
functions = datas[0].size()-1
|
||||||
|
else:
|
||||||
|
functions = datas.size()-1
|
||||||
|
else:
|
||||||
|
if invert_chart:
|
||||||
|
functions = datas[0].size()-1
|
||||||
|
else:
|
||||||
|
functions = datas.size()-1
|
||||||
|
|
||||||
|
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 redraw():
|
||||||
|
build_chart()
|
||||||
|
calculate_pass()
|
||||||
|
calculate_coordinates()
|
||||||
|
update()
|
||||||
|
|
||||||
|
# .................. VIRTUAL FUNCTIONS .........................
|
||||||
|
func calculate_pass():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func calculate_coordinates():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func structure_datas(database : Array, are_values_columns : bool, labels_index : int):
|
||||||
|
pass
|
||||||
|
|
||||||
|
func build_chart():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func function_colors():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func create_legend():
|
||||||
|
pass
|
||||||
|
|
||||||
|
# ........................... Shared Setters & Getters ..............................
|
||||||
|
func apply_template(template_name : int):
|
||||||
|
if Engine.editor_hint:
|
||||||
|
set_template(template_name)
|
||||||
|
property_list_changed_notify()
|
||||||
|
|
||||||
|
# !!! API v2
|
||||||
|
func set_source(source_file : String, delim : String = ";"):
|
||||||
|
source = source_file
|
||||||
|
delimiter = delim
|
||||||
|
|
||||||
|
# !!! API v2
|
||||||
|
func set_indexes(lb : int = 0, function_names : int = 0):
|
||||||
|
labels_index = lb
|
||||||
|
function_names_index = function_names
|
||||||
|
|
||||||
|
# !!! API v2
|
||||||
|
func set_radius(use_height : bool = false, f : float = 0):
|
||||||
|
use_height_as_radius = use_height
|
||||||
|
radius = f
|
||||||
|
|
||||||
|
# !!! API v2
|
||||||
|
func set_chart_colors(f_colors : Array, o_color : Color, b_color : Color, g_color : Color, h_lines : Color, v_lines : Color):
|
||||||
|
function_colors = f_colors
|
||||||
|
outline_color = o_color
|
||||||
|
box_color = b_color
|
||||||
|
grid_color = g_color
|
||||||
|
h_lines_color = h_lines
|
||||||
|
v_lines_color = v_lines
|
||||||
|
|
||||||
|
# !!! API v2
|
||||||
|
func set_chart_fonts(normal_font : Font, bold_font : Font, f_color : Color):
|
||||||
|
font = normal_font
|
||||||
|
self.bold_font = bold_font
|
||||||
|
font_color = f_color
|
||||||
|
|
||||||
|
func set_delimiter(d : String):
|
||||||
|
d = delimiter
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_origin_at_zero(b : bool):
|
||||||
|
origin_at_zero = b
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_are_values_columns(b : bool):
|
||||||
|
are_values_columns = b
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_show_x_values_as_labels(b : bool):
|
||||||
|
show_x_values_as_labels = b
|
||||||
|
|
||||||
|
func set_labels_index(i : int):
|
||||||
|
labels_index = i
|
||||||
|
|
||||||
|
func set_function_names_index(i : int):
|
||||||
|
function_names_index = i
|
||||||
|
|
||||||
|
func set_use_height_as_radius(b : bool):
|
||||||
|
use_height_as_radius = b
|
||||||
|
|
||||||
|
func _set_radius(r : float):
|
||||||
|
radius = r
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_column_width(f : float):
|
||||||
|
column_width = f
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_column_gap(f : float):
|
||||||
|
column_gap = f
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_full_scale(f : float):
|
||||||
|
full_scale = f
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_x_decim(f : float):
|
||||||
|
x_decim = f
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_y_decim(f : float):
|
||||||
|
y_decim = f
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_points_shape(a : Array):
|
||||||
|
points_shape = a
|
||||||
|
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_function_colors(a : Array):
|
||||||
|
function_colors = a
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_outline_color(c : Color):
|
||||||
|
outline_color = c
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_box_color(c : Color):
|
||||||
|
box_color = c
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_grid_color(c : Color):
|
||||||
|
grid_color = c
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_v_lines_color(c : Color):
|
||||||
|
v_lines_color = c
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_h_lines_color(c : Color):
|
||||||
|
h_lines_color = c
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_font(f : Font):
|
||||||
|
font = f
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_bold_font(f : Font):
|
||||||
|
bold_font = f
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_font_color(c : Color):
|
||||||
|
font_color = c
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_template(template_name : int):
|
||||||
|
template = template_name
|
||||||
|
templates = Utilities.templates
|
||||||
|
if template_name!=null:
|
||||||
|
var custom_template = templates.get(templates.keys()[template_name])
|
||||||
|
function_colors = custom_template.function_colors as PoolColorArray
|
||||||
|
outline_color = Color(custom_template.outline_color)
|
||||||
|
box_color = Color(custom_template.outline_color)
|
||||||
|
grid_color = Color(custom_template.v_lines_color)
|
||||||
|
v_lines_color = Color(custom_template.v_lines_color)
|
||||||
|
h_lines_color = Color(custom_template.h_lines_color)
|
||||||
|
box_color = Color(custom_template.outline_color)
|
||||||
|
font_color = Color(custom_template.font_color)
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_rotation(f : float):
|
||||||
|
rotation = f
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_invert_chart(b : bool):
|
||||||
|
invert_chart = b
|
||||||
|
|
||||||
|
func set_legend(l : Array):
|
||||||
|
legend = l
|
||||||
|
|
||||||
|
func get_legend():
|
||||||
|
return legend
|
||||||
|
|
||||||
|
# ............................. Shared Signals ..............................
|
||||||
|
func point_pressed(point : Point):
|
||||||
|
emit_signal("point_pressed",point)
|
||||||
|
|
||||||
|
func show_data(point : Point):
|
||||||
|
PointData.update_datas(point)
|
||||||
|
PointData.show()
|
||||||
|
|
||||||
|
func hide_data():
|
||||||
|
PointData.hide()
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
extends Node2D
|
extends Node2D
|
||||||
class_name Chart2D
|
class_name Chart2D
|
||||||
|
|
||||||
enum point_shapes { Dot, Triangle, Square, Cross }
|
enum PointShapes { Dot, Triangle, Square, Cross }
|
||||||
enum templates_names { Default, Clean, Gradient, Minimal, Invert }
|
enum TemplatesNames { Default, Clean, Gradient, Minimal, Invert }
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
|
39
addons/easy_charts/Utilities/Scripts/ChartObject.gd
Normal file
39
addons/easy_charts/Utilities/Scripts/ChartObject.gd
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#extends Object
|
||||||
|
#class_name ChartObject
|
||||||
|
#
|
||||||
|
#"""
|
||||||
|
#[ChartObject] :: Class
|
||||||
|
#
|
||||||
|
#this class is used to store all the functions that Chart, Chart2D and Chart3D custom instances
|
||||||
|
#will share in-between.
|
||||||
|
#Chart classes will extend this class.
|
||||||
|
#"""
|
||||||
|
#
|
||||||
|
#enum PointShapes { Dot, Triangle, Square, Cross }
|
||||||
|
#enum TemplatesNames { Default, Clean, Gradient, Minimal, Invert }
|
||||||
|
#
|
||||||
|
#class Chart extends Control:
|
||||||
|
# var CHART_TYPE : String = "Chart"
|
||||||
|
# enum PointShapes { Dot, Triangle, Square, Cross }
|
||||||
|
# enum TemplatesNames { Default, Clean, Gradient, Minimal, Invert }
|
||||||
|
#
|
||||||
|
# export (PoolColorArray) var function_colors = [Color("#1e1e1e")]
|
||||||
|
# export (Array, PointShapes) var points_shape : Array = [PointShapes.Dot]
|
||||||
|
#
|
||||||
|
# var functions : int = 0
|
||||||
|
#
|
||||||
|
# func calculate_colors():
|
||||||
|
# if function_colors.empty() or function_colors.size() < functions:
|
||||||
|
# for function in functions:
|
||||||
|
# function_colors.append(Color("#1e1e1e"))
|
||||||
|
#
|
||||||
|
# func set_shapes():
|
||||||
|
# if points_shape.empty() or points_shape.size() < functions:
|
||||||
|
# for function in functions:
|
||||||
|
# points_shape.append(PointShapes.Dot)
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#class Chart2D extends Node2D:
|
||||||
|
# var CHART_TYPE : String = "Chart2D"
|
||||||
|
# enum PointShapes { Dot, Triangle, Square, Cross }
|
||||||
|
# enum TemplatesNames { Default, Clean, Gradient, Minimal, Invert }
|
@ -21,3 +21,6 @@ func _load_templates() -> Dictionary:
|
|||||||
var templates = JSON.parse(template_file.get_as_text()).get_result()
|
var templates = JSON.parse(template_file.get_as_text()).get_result()
|
||||||
template_file.close()
|
template_file.close()
|
||||||
return templates
|
return templates
|
||||||
|
|
||||||
|
func get_template(template_index : int):
|
||||||
|
return templates.get(templates.keys()[template_index])
|
||||||
|
@ -3,5 +3,5 @@
|
|||||||
name="EasyCharts"
|
name="EasyCharts"
|
||||||
description=""
|
description=""
|
||||||
author="Nicolò \"fenix\" Santilio"
|
author="Nicolò \"fenix\" Santilio"
|
||||||
version="0.2.1"
|
version="0.2.8"
|
||||||
script="plugin.gd"
|
script="plugin.gd"
|
||||||
|
@ -3,10 +3,12 @@ extends EditorPlugin
|
|||||||
|
|
||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
add_autoload_singleton("Utilities","res://addons/easy_charts/Utilities/Scripts/utilities.gd")
|
add_autoload_singleton("Utilities","res://addons/easy_charts/Utilities/Scripts/utilities.gd")
|
||||||
|
# add_custom_type("ChartObject","Node", load("res://addons/easy_charts/Utilities/Scripts/ChartObject.gd"), preload("Utilities/icons/linechart.svg"))
|
||||||
add_custom_type("Chart","Control", load("res://addons/easy_charts/Utilities/Scripts/Chart.gd"), preload("Utilities/icons/linechart.svg"))
|
add_custom_type("Chart","Control", load("res://addons/easy_charts/Utilities/Scripts/Chart.gd"), preload("Utilities/icons/linechart.svg"))
|
||||||
add_custom_type("Chart2D","Node2D", preload("Utilities/Scripts/Chart2D.gd"), preload("Utilities/icons/linechart2d.svg"))
|
add_custom_type("Chart2D","Node2D", preload("Utilities/Scripts/Chart2D.gd"), preload("Utilities/icons/linechart2d.svg"))
|
||||||
|
|
||||||
func _exit_tree():
|
func _exit_tree():
|
||||||
remove_custom_type("Chart")
|
remove_custom_type("Chart")
|
||||||
remove_custom_type("Chart2D")
|
remove_custom_type("Chart2D")
|
||||||
|
# remove_custom_type("ChartObject")
|
||||||
remove_autoload_singleton("Utilities")
|
remove_autoload_singleton("Utilities")
|
||||||
|
Loading…
Reference in New Issue
Block a user