mirror of
https://github.com/Relintai/pandemonium_engine_easy_charts.git
synced 2024-12-19 13:37:03 +01:00
Merge pull request #11 from eddex/fix/LineChart2D-not-loading
fix: LineChart2D now loads and shows the data as expected
This commit is contained in:
commit
64b0f9cfed
@ -3,14 +3,14 @@ extends Chart2D
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
[Linechart2D] - General purpose node for Line Charts
|
[Linechart2D] - General purpose node for Line Charts
|
||||||
A line chart or line plot or line graph or curve chart is a type of chart which
|
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'
|
displays information as a series of data points called 'markers'
|
||||||
connected by straight line segments.
|
connected by straight line segments.
|
||||||
It is a basic type of chart common in many fields. It is similar to a scatter plot
|
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)
|
except that the measurement points are ordered (typically by their x-axis value)
|
||||||
and joined with straight line segments.
|
and joined with straight line segments.
|
||||||
A line chart is often used to visualize a trend in data over intervals of time –
|
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.
|
a time series – thus the line is often drawn chronologically.
|
||||||
In these cases they are known as run charts.
|
In these cases they are known as run charts.
|
||||||
/ source : Wikipedia /
|
/ source : Wikipedia /
|
||||||
"""
|
"""
|
||||||
@ -36,7 +36,7 @@ var OFFSET : Vector2 = Vector2(0,0)
|
|||||||
#-------------------------------------------------------------------------#
|
#-------------------------------------------------------------------------#
|
||||||
var origin : Vector2
|
var origin : Vector2
|
||||||
|
|
||||||
# actual distance between x and y values
|
# actual distance between x and y values
|
||||||
var x_pass : float
|
var x_pass : float
|
||||||
var y_pass : float
|
var y_pass : float
|
||||||
|
|
||||||
@ -123,6 +123,7 @@ func _ready():
|
|||||||
|
|
||||||
func _get_children():
|
func _get_children():
|
||||||
OutlinesTween = $OutlinesTween
|
OutlinesTween = $OutlinesTween
|
||||||
|
FunctionsTween = $FunctionsTween
|
||||||
Functions = $Functions
|
Functions = $Functions
|
||||||
GridTween = $GridTween
|
GridTween = $GridTween
|
||||||
PointData = $PointData/PointData
|
PointData = $PointData/PointData
|
||||||
@ -139,7 +140,7 @@ func _set_size(size : Vector2):
|
|||||||
Outlines.set_point_position(2,Vector2(SIZE.x,origin.y))
|
Outlines.set_point_position(2,Vector2(SIZE.x,origin.y))
|
||||||
Outlines.set_point_position(3,origin)
|
Outlines.set_point_position(3,origin)
|
||||||
Outlines.set_point_position(4,Vector2(origin.x,0))
|
Outlines.set_point_position(4,Vector2(origin.x,0))
|
||||||
|
|
||||||
Grid.get_node("VLine").set_point_position(0,Vector2((OFFSET.x+SIZE.x)/2,0))
|
Grid.get_node("VLine").set_point_position(0,Vector2((OFFSET.x+SIZE.x)/2,0))
|
||||||
Grid.get_node("VLine").set_point_position(1,Vector2((OFFSET.x+SIZE.x)/2,origin.y))
|
Grid.get_node("VLine").set_point_position(1,Vector2((OFFSET.x+SIZE.x)/2,origin.y))
|
||||||
Grid.get_node("HLine").set_point_position(0,Vector2(origin.x,origin.y/2))
|
Grid.get_node("HLine").set_point_position(0,Vector2(origin.x,origin.y/2))
|
||||||
@ -165,12 +166,12 @@ func load_font():
|
|||||||
|
|
||||||
func _plot(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_values_index_ : int):
|
func _plot(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_values_index_ : int):
|
||||||
randomize()
|
randomize()
|
||||||
|
|
||||||
clear()
|
clear()
|
||||||
|
|
||||||
load_font()
|
load_font()
|
||||||
PointData.hide()
|
PointData.hide()
|
||||||
|
|
||||||
datas = read_datas(source_,delimiter_)
|
datas = read_datas(source_,delimiter_)
|
||||||
count_functions()
|
count_functions()
|
||||||
structure_datas(datas,are_values_columns_,x_values_index_)
|
structure_datas(datas,are_values_columns_,x_values_index_)
|
||||||
@ -179,18 +180,18 @@ func _plot(source_ : String, delimiter_ : String, are_values_columns_ : bool, x_
|
|||||||
calculate_coordinates()
|
calculate_coordinates()
|
||||||
calculate_colors()
|
calculate_colors()
|
||||||
draw_chart()
|
draw_chart()
|
||||||
|
|
||||||
create_legend()
|
create_legend()
|
||||||
emit_signal("chart_plotted", self)
|
emit_signal("chart_plotted", self)
|
||||||
|
|
||||||
func plot():
|
func plot():
|
||||||
randomize()
|
randomize()
|
||||||
|
|
||||||
clear()
|
clear()
|
||||||
|
|
||||||
load_font()
|
load_font()
|
||||||
PointData.hide()
|
PointData.hide()
|
||||||
|
|
||||||
if source == "" or source == null:
|
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)
|
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
|
return
|
||||||
@ -202,7 +203,7 @@ func plot():
|
|||||||
calculate_coordinates()
|
calculate_coordinates()
|
||||||
calculate_colors()
|
calculate_colors()
|
||||||
draw_chart()
|
draw_chart()
|
||||||
|
|
||||||
create_legend()
|
create_legend()
|
||||||
emit_signal("chart_plotted", self)
|
emit_signal("chart_plotted", self)
|
||||||
|
|
||||||
@ -279,7 +280,7 @@ func draw_function(f_index : int, function : Array):
|
|||||||
var line : Line2D = Line2D.new()
|
var line : Line2D = Line2D.new()
|
||||||
var backline : Line2D = Line2D.new()
|
var backline : Line2D = Line2D.new()
|
||||||
construct_line(line,backline,f_index,function)
|
construct_line(line,backline,f_index,function)
|
||||||
var pointv : Point
|
var pointv : Point
|
||||||
for point in function.size():
|
for point in function.size():
|
||||||
pointv = point_node.instance()
|
pointv = point_node.instance()
|
||||||
Functions.add_child(pointv)
|
Functions.add_child(pointv)
|
||||||
@ -358,7 +359,7 @@ func structure_datas(database : Array, are_values_columns : bool, x_values_index
|
|||||||
for data in y_datas:
|
for data in y_datas:
|
||||||
for value in data.size():
|
for value in data.size():
|
||||||
data[value] = data[value] as float
|
data[value] = data[value] as float
|
||||||
|
|
||||||
# draw y labels
|
# draw y labels
|
||||||
var to_order : Array
|
var to_order : Array
|
||||||
var to_order_min : Array
|
var to_order_min : Array
|
||||||
@ -371,7 +372,7 @@ func structure_datas(database : Array, are_values_columns : bool, x_values_index
|
|||||||
var margin_min = ordered_cluster[0]
|
var margin_min = ordered_cluster[0]
|
||||||
to_order.append(margin_max)
|
to_order.append(margin_max)
|
||||||
to_order_min.append(margin_min)
|
to_order_min.append(margin_min)
|
||||||
|
|
||||||
to_order.sort()
|
to_order.sort()
|
||||||
to_order_min.sort()
|
to_order_min.sort()
|
||||||
var margin = to_order.pop_back()
|
var margin = to_order.pop_back()
|
||||||
@ -385,12 +386,12 @@ func structure_datas(database : Array, are_values_columns : bool, x_values_index
|
|||||||
multi+=1
|
multi+=1
|
||||||
p = (v_dist*multi) + ((y_margin_min) if not origin_at_zero else 0)
|
p = (v_dist*multi) + ((y_margin_min) if not origin_at_zero else 0)
|
||||||
y_chors.append(p as String)
|
y_chors.append(p as String)
|
||||||
|
|
||||||
# draw x_labels
|
# draw x_labels
|
||||||
if not show_x_values_as_labels:
|
if not show_x_values_as_labels:
|
||||||
to_order.clear()
|
to_order.clear()
|
||||||
to_order = x_datas as PoolIntArray
|
to_order = x_datas as PoolIntArray
|
||||||
|
|
||||||
to_order.sort()
|
to_order.sort()
|
||||||
margin = to_order.pop_back()
|
margin = to_order.pop_back()
|
||||||
if not origin_at_zero:
|
if not origin_at_zero:
|
||||||
@ -415,7 +416,7 @@ func calculate_pass():
|
|||||||
x_chors = x_datas as PoolStringArray
|
x_chors = x_datas as PoolStringArray
|
||||||
else:
|
else:
|
||||||
x_chors = x_labels
|
x_chors = x_labels
|
||||||
|
|
||||||
# calculate distance in pixel between 2 consecutive values/datas
|
# calculate distance in pixel between 2 consecutive values/datas
|
||||||
x_pass = (SIZE.x - OFFSET.x) / (x_chors.size()-1)
|
x_pass = (SIZE.x - OFFSET.x) / (x_chors.size()-1)
|
||||||
y_pass = origin.y / (y_chors.size()-1)
|
y_pass = origin.y / (y_chors.size()-1)
|
||||||
@ -425,7 +426,7 @@ func calculate_coordinates():
|
|||||||
y_coordinates.clear()
|
y_coordinates.clear()
|
||||||
point_values.clear()
|
point_values.clear()
|
||||||
point_positions.clear()
|
point_positions.clear()
|
||||||
|
|
||||||
if invert_chart:
|
if invert_chart:
|
||||||
for column in y_datas[0].size():
|
for column in y_datas[0].size():
|
||||||
var single_coordinates : Array
|
var single_coordinates : Array
|
||||||
@ -444,7 +445,7 @@ func calculate_coordinates():
|
|||||||
else:
|
else:
|
||||||
single_coordinates.append((cluster[value] - y_margin_min)*y_pass/v_dist)
|
single_coordinates.append((cluster[value] - y_margin_min)*y_pass/v_dist)
|
||||||
y_coordinates.append(single_coordinates)
|
y_coordinates.append(single_coordinates)
|
||||||
|
|
||||||
if show_x_values_as_labels:
|
if show_x_values_as_labels:
|
||||||
for x in x_datas.size():
|
for x in x_datas.size():
|
||||||
x_coordinates.append(x_pass*x)
|
x_coordinates.append(x_pass*x)
|
||||||
@ -457,11 +458,11 @@ func calculate_coordinates():
|
|||||||
x_coordinates.append(x_datas[x]*x_pass/h_dist)
|
x_coordinates.append(x_datas[x]*x_pass/h_dist)
|
||||||
else:
|
else:
|
||||||
x_coordinates.append((x_datas[x] - x_margin_min)*x_pass/h_dist)
|
x_coordinates.append((x_datas[x] - x_margin_min)*x_pass/h_dist)
|
||||||
|
|
||||||
for f in functions:
|
for f in functions:
|
||||||
point_values.append([])
|
point_values.append([])
|
||||||
point_positions.append([])
|
point_positions.append([])
|
||||||
|
|
||||||
if invert_chart:
|
if invert_chart:
|
||||||
for function in y_coordinates.size():
|
for function in y_coordinates.size():
|
||||||
for function_value in y_coordinates[function].size():
|
for function_value in y_coordinates[function].size():
|
||||||
@ -553,7 +554,7 @@ func apply_template(template_name : int):
|
|||||||
box_color = Color(custom_template.outline_color)
|
box_color = Color(custom_template.outline_color)
|
||||||
font_color = Color(custom_template.font_color)
|
font_color = Color(custom_template.font_color)
|
||||||
property_list_changed_notify()
|
property_list_changed_notify()
|
||||||
|
|
||||||
if Engine.editor_hint:
|
if Engine.editor_hint:
|
||||||
_get_children()
|
_get_children()
|
||||||
Outlines.set_default_color(box_color)
|
Outlines.set_default_color(box_color)
|
||||||
|
Loading…
Reference in New Issue
Block a user