2020-05-14 02:36:45 +02:00
|
|
|
tool
|
2021-02-21 11:29:29 +01:00
|
|
|
extends ScatterChartBase
|
2020-11-09 18:16:36 +01:00
|
|
|
class_name LineChart
|
2020-05-14 02:36:45 +02:00
|
|
|
|
2020-10-05 17:44:20 +02:00
|
|
|
# [Linechart] - General purpose node for Line Charts
|
|
|
|
# A line chart or line plot or line graph or curve chart is a type of chart which
|
|
|
|
# displays information as a series of data points called 'markers'
|
|
|
|
# connected by straight line segments.
|
|
|
|
# It is a basic type of chart common in many fields. It is similar to a scatter plot
|
|
|
|
# except that the measurement points are ordered (typically by their x-axis value)
|
|
|
|
# and joined with straight line segments.
|
2020-10-05 18:12:23 +02:00
|
|
|
# A line chart is often used to visualize a trend in data over intervals of time -
|
|
|
|
# a time series - thus the line is often drawn chronologically.
|
2020-10-05 17:44:20 +02:00
|
|
|
# In these cases they are known as run charts.
|
|
|
|
# Source: Wikipedia
|
|
|
|
|
2021-03-25 03:06:55 +01:00
|
|
|
var show_points := true
|
|
|
|
var function_line_width : int = 2
|
|
|
|
|
|
|
|
|
|
|
|
func build_property_list():
|
|
|
|
.build_property_list()
|
|
|
|
|
|
|
|
property_list.append(
|
|
|
|
{
|
|
|
|
"hint": PROPERTY_HINT_NONE,
|
|
|
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
|
|
|
"name": "Chart_Display/show_points",
|
|
|
|
"type": TYPE_BOOL
|
|
|
|
})
|
|
|
|
|
|
|
|
#Find first element of Chart Display
|
|
|
|
var position
|
|
|
|
for i in property_list.size():
|
|
|
|
if property_list[i]["name"].find("Chart_Style") != -1: #Found
|
|
|
|
position = i
|
|
|
|
break
|
|
|
|
|
|
|
|
property_list.insert(position + 2, #I want it to be below point shape and function colors
|
|
|
|
{
|
|
|
|
"hint": PROPERTY_HINT_RANGE,
|
|
|
|
"hint_string": "1, 100, 1",
|
|
|
|
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
|
|
|
"name": "Chart_Style/function_line_width",
|
|
|
|
"type": TYPE_INT
|
|
|
|
})
|
|
|
|
|
2020-05-20 17:28:10 +02:00
|
|
|
|
2020-05-30 01:42:58 +02:00
|
|
|
func _get_property_list():
|
2021-03-02 20:18:31 +01:00
|
|
|
property_list[0].name = "LineChart"
|
|
|
|
return property_list
|
2020-10-05 17:44:20 +02:00
|
|
|
|
2020-10-05 18:12:23 +02:00
|
|
|
|
2021-03-25 03:06:55 +01:00
|
|
|
func _get(property):
|
|
|
|
match property:
|
|
|
|
"Chart_Display/show_points":
|
|
|
|
return show_points
|
|
|
|
"Chart_Style/function_line_width":
|
|
|
|
return function_line_width
|
|
|
|
|
|
|
|
|
|
|
|
func _set(property, value):
|
|
|
|
match property:
|
|
|
|
"Chart_Display/show_points":
|
|
|
|
show_points = value
|
|
|
|
return true
|
|
|
|
"Chart_Style/function_line_width":
|
|
|
|
function_line_width = value
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
2020-05-14 02:36:45 +02:00
|
|
|
func _draw():
|
2020-10-05 17:49:31 +02:00
|
|
|
clear_points()
|
|
|
|
draw_grid()
|
|
|
|
draw_chart_outlines()
|
2021-03-25 03:06:55 +01:00
|
|
|
if show_points:
|
|
|
|
draw_points()
|
2021-02-21 11:29:29 +01:00
|
|
|
draw_lines()
|
2020-12-30 15:30:42 +01:00
|
|
|
draw_treshold()
|
2020-05-14 02:36:45 +02:00
|
|
|
|
2020-12-30 15:30:42 +01:00
|
|
|
|
2021-02-21 11:29:29 +01:00
|
|
|
func draw_lines():
|
2021-03-25 03:06:55 +01:00
|
|
|
for function in point_values.size():
|
|
|
|
for function_point in range(1, point_values[function].size()):
|
2021-02-21 11:29:29 +01:00
|
|
|
draw_line(
|
2021-03-25 03:06:55 +01:00
|
|
|
point_positions[function][function_point - 1],
|
|
|
|
point_positions[function][function_point],
|
|
|
|
function_colors[function],
|
|
|
|
function_line_width,
|
|
|
|
false)
|