mirror of
https://github.com/Relintai/pandemonium_engine_easy_charts.git
synced 2025-02-26 17:24:21 +01:00
Refactor (#54)
fix #48 fix #52 * Refactor so it works with the new data format. Restructured some functions in smaller pieces and changed it so they can work with data in the new format. Main way to use it will be with the new plot_function but old functions support is requiered through structure_datas (WIP) * structure_datas rework structure_datas structure the data to match the new format. * Add new plotting methods Also renamed identifiers array to the already existing y_labels and a fix to correctly calculate tics. * Add autoscale or user-defined range * Add color definition from plot_function call Introduction of a param_dic parameter on plot_function that allows for specific parameters definitions for that curve only without changing the full Chart. Also moved the label identier string to a parameter on this dicionary so it can be called without specifying a label name. * Fix representation of negative values Using negative numbers should now work on both axis. For this I created two new methods calcualte_interval_tics and calculate_number_integer_digits to avoid code repetition. I'd like to work more on this, since now the representation is correct but can look very weird for some values with a lot of empty space on the chart. * Correctly calculates tics for numbers between 0 and 1 Also some small fixes to update_function and delete_function. Changed the tic little line to point outside the chart instead of inside so it doesn't overlap with the grid line. * Correctly (almost) center axis labels Needs a little of research for the vertical centering since get_string_size doesn't behave as expected. * Add some style representation customization Width of the grid and function lines. Made drawing points for LineChart optional (especially useful when using a huge number of points to avoid overclustering). For this I had to rewrite the draw_lines function to work similar to draw_points using point_positions instead of information of the point nodes. The string position of the labels is correctly calculated now. It uses a new variable: label_displacement so it don't look too close to the axis and the border. Set some default values that make more sense to the instanciable scenes. * Fix clearing of data structures with multiple calls to plot_from_x * Fix show_x_values_as_labels Correctly sets the x position when show_x_values_as_labels is active. * Fix show_x_values_as_labels when the label is a String * restructure folder * refactor scatter_chart and line_chart * finish 1st refactoring * finish 1st refactoring * finish 1st refactoring * remove .tmp * fix min errors * refactor column chart * fix are_values_columns Co-authored-by: Jorge <63685920+JFerrerBeired@users.noreply.github.com>
This commit is contained in:
parent
7c73e92f8f
commit
462bb4f901
@ -76,7 +76,8 @@ export (String, FILE, "*.txt, *.csv, *.res") var source : String = "" setget set
|
||||
export (String) var delimiter : String = ";" setget set_delimiter
|
||||
|
||||
var origin_at_zero : bool = false setget set_origin_at_zero#, get_origin_at_zero
|
||||
var are_values_columns : bool = false setget set_are_values_columns#, get_are_values_columns
|
||||
var are_values_columns : bool = true setget set_are_values_columns#, get_are_values_columns
|
||||
|
||||
var show_x_values_as_labels : bool = false setget set_show_x_values_as_labels#, get_show_x_values_as_labels
|
||||
var labels_index : int = 0 setget set_labels_index#, get_labels_index
|
||||
var function_names_index : int = 0 setget set_function_names_index#, get_function_names_index
|
||||
@ -86,6 +87,8 @@ var use_height_as_radius : bool = false setget set_use_height_as_radius
|
||||
var radius : float = 150.0 setget _set_radius,get_radius
|
||||
|
||||
# for columns
|
||||
var function_line_width : int = 2
|
||||
|
||||
var column_width : float = 10 setget set_column_width
|
||||
var column_gap : float = 2 setget set_column_gap
|
||||
|
||||
@ -106,6 +109,8 @@ var font : Font setget set_font
|
||||
var bold_font : Font setget set_bold_font
|
||||
var font_color : Color = Color("#1e1e1e") setget set_font_color
|
||||
|
||||
var show_points := true
|
||||
|
||||
var use_template : bool = true setget set_use_template
|
||||
var template : int = 0 setget set_template
|
||||
|
||||
@ -133,6 +138,14 @@ var treshold_draw : Vector2
|
||||
var tic_length : int = 5 setget set_tic_length # Length of the bar indicating a tic
|
||||
var label_displacement : int = 4 setget set_label_displacement # Separation between the label and both the axis and the edge border
|
||||
|
||||
var property_list: Array = []
|
||||
|
||||
|
||||
|
||||
# ..........................................
|
||||
|
||||
|
||||
|
||||
# !! API v2
|
||||
static func instance(chart_type : int):
|
||||
var chart_t : String = ECUtilities.get_chart_type(chart_type)
|
||||
@ -160,6 +173,9 @@ func _get(property):
|
||||
return column_width
|
||||
"Chart_Properties/column_gap":
|
||||
return column_gap
|
||||
"Chart_Style/function_line_width":
|
||||
return function_line_width
|
||||
|
||||
|
||||
"Chart_Display/full_scale":
|
||||
return full_scale
|
||||
@ -233,6 +249,9 @@ func _set(property, value):
|
||||
"Chart_Properties/column_gap":
|
||||
column_gap = value
|
||||
return true
|
||||
"Chart_Style/function_line_width":
|
||||
function_line_width = value
|
||||
return true
|
||||
|
||||
"Chart_Display/full_scale":
|
||||
full_scale = value
|
||||
@ -299,6 +318,9 @@ func _set(property, value):
|
||||
invert_chart = value
|
||||
return true
|
||||
|
||||
func _init():
|
||||
build_property_list()
|
||||
|
||||
# .......................... Shared Functions and virtuals ........................
|
||||
|
||||
# Structure and Display a new plot if a dataset source is given
|
||||
@ -464,6 +486,10 @@ func clean_variables():
|
||||
y_labels.clear()
|
||||
|
||||
# .................. VIRTUAL FUNCTIONS .........................
|
||||
func build_property_list():
|
||||
pass
|
||||
|
||||
|
||||
func calculate_tics():
|
||||
pass
|
||||
|
||||
|
@ -15,13 +15,6 @@ var autoscale_x = true
|
||||
var autoscale_y = true
|
||||
|
||||
|
||||
var property_list: Array = []
|
||||
|
||||
|
||||
func _init():
|
||||
build_property_list()
|
||||
|
||||
|
||||
func build_property_list():
|
||||
property_list.clear()
|
||||
|
||||
@ -30,7 +23,7 @@ func build_property_list():
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_CATEGORY,
|
||||
"name": "ScatterChartBase",
|
||||
"name": get_name(),
|
||||
"type": TYPE_STRING
|
||||
})
|
||||
property_list.append(
|
||||
@ -117,6 +110,15 @@ func build_property_list():
|
||||
"name": "Chart_Display/y_decim",
|
||||
"type": TYPE_REAL
|
||||
})
|
||||
property_list.append(
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Display/show_points",
|
||||
"type": TYPE_BOOL
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
# Chart Style
|
||||
@ -233,6 +235,9 @@ func build_property_list():
|
||||
|
||||
func _set(property, value):
|
||||
match property:
|
||||
"Chart_Display/show_points":
|
||||
show_points = value
|
||||
return true
|
||||
"Chart_Display/autoscale_x":
|
||||
autoscale_x = value
|
||||
build_property_list()
|
||||
@ -259,6 +264,8 @@ func _set(property, value):
|
||||
|
||||
func _get(property):
|
||||
match property:
|
||||
"Chart_Display/show_points":
|
||||
return show_points
|
||||
"Chart_Display/autoscale_x":
|
||||
return autoscale_x
|
||||
"Chart_Display/autoscale_y":
|
||||
@ -540,7 +547,7 @@ func calculate_coordinates():
|
||||
|
||||
for function in y_labels.size():
|
||||
for val in x_datas[function].size():
|
||||
var value_x = (x_datas[function][val] - x_margin_min) * x_pass / h_dist if h_dist else 0 \
|
||||
var value_x = (int(x_datas[function][val]) - x_margin_min) * x_pass / h_dist if h_dist else 0 \
|
||||
if not show_x_values_as_labels else x_chors.find(String(x_datas[function][val])) * x_pass
|
||||
var value_y = (y_datas[function][val] - y_margin_min) * y_pass / v_dist if v_dist else 0
|
||||
|
||||
@ -585,6 +592,8 @@ func draw_chart_outlines():
|
||||
func draw_points():
|
||||
for function in point_values.size():
|
||||
var PointContainer : Control = Control.new()
|
||||
PointContainer.name = "PointContainer"
|
||||
|
||||
Points.add_child(PointContainer)
|
||||
|
||||
for function_point in point_values[function].size():
|
||||
|
@ -1,5 +1,5 @@
|
||||
tool
|
||||
extends Chart
|
||||
extends ScatterChartBase
|
||||
class_name ColumnChart
|
||||
|
||||
"""
|
||||
@ -19,348 +19,65 @@ values of more than one measured variable.
|
||||
|
||||
# ---------------------
|
||||
|
||||
func _get_property_list():
|
||||
return [
|
||||
# Chart Properties
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_CATEGORY,
|
||||
"name": "ColumnChart",
|
||||
"type": TYPE_STRING
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/are_values_columns",
|
||||
"type": TYPE_BOOL
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "-1,100,1",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/labels_index",
|
||||
"type": TYPE_INT
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/show_x_values_as_labels",
|
||||
"type": TYPE_BOOL
|
||||
},
|
||||
func build_property_list():
|
||||
.build_property_list()
|
||||
|
||||
property_list.append(
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "1,20,0.5",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/column_width",
|
||||
"type": TYPE_REAL
|
||||
},
|
||||
})
|
||||
property_list.append(
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "0,10,0.5",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Properties/column_gap",
|
||||
"type": TYPE_REAL
|
||||
},
|
||||
|
||||
# Chart Display
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "0.1,10",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Display/x_decim",
|
||||
"type": TYPE_REAL
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_RANGE,
|
||||
"hint_string": "0.001,1,0.001",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Display/y_decim",
|
||||
"type": TYPE_REAL
|
||||
},
|
||||
|
||||
# Chart Style
|
||||
{
|
||||
"hint": 24,
|
||||
"hint_string": "%d/%d:%s"%[TYPE_INT, PROPERTY_HINT_ENUM,
|
||||
PoolStringArray(Point.SHAPES.keys()).join(",")],
|
||||
"name": "Chart_Style/points_shape",
|
||||
"type": TYPE_ARRAY,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/function_colors",
|
||||
"type": TYPE_COLOR_ARRAY
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/box_color",
|
||||
"type": TYPE_COLOR
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/v_lines_color",
|
||||
"type": TYPE_COLOR
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/h_lines_color",
|
||||
"type": TYPE_COLOR
|
||||
},
|
||||
{
|
||||
"class_name": "Font",
|
||||
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||
"hint_string": "Font",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/font",
|
||||
"type": TYPE_OBJECT
|
||||
},
|
||||
{
|
||||
"class_name": "Font",
|
||||
"hint": PROPERTY_HINT_RESOURCE_TYPE,
|
||||
"hint_string": "Font",
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/bold_font",
|
||||
"type": TYPE_OBJECT
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/font_color",
|
||||
"type": TYPE_COLOR
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/use_template",
|
||||
"type": TYPE_BOOL
|
||||
},
|
||||
{
|
||||
"hint": PROPERTY_HINT_ENUM,
|
||||
"hint_string": PoolStringArray(ECUtilities.templates.keys()).join(","),
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Style/template",
|
||||
"type": TYPE_INT
|
||||
},
|
||||
|
||||
# Chart Modifiers
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Modifiers/invert_chart",
|
||||
"type": TYPE_BOOL
|
||||
},
|
||||
]
|
||||
|
||||
func build_chart():
|
||||
SIZE = get_size()
|
||||
origin = Vector2(OFFSET.x,SIZE.y-OFFSET.y)
|
||||
|
||||
func structure_data(database : Array):
|
||||
# @labels_index can be either a column or a row relative to x values
|
||||
are_values_columns = (invert_chart != are_values_columns)
|
||||
if are_values_columns:
|
||||
for row in database.size():
|
||||
var t_vals: Array
|
||||
for column in database[row].size():
|
||||
if column == labels_index:
|
||||
var x_data = database[row][column]
|
||||
if x_data.is_valid_float() or x_data.is_valid_integer():
|
||||
x_datas.append(x_data as float)
|
||||
else:
|
||||
x_datas.append(x_data)
|
||||
else:
|
||||
if row != 0:
|
||||
var y_data = database[row][column]
|
||||
if y_data.is_valid_float() or y_data.is_valid_integer():
|
||||
t_vals.append(y_data as float)
|
||||
else:
|
||||
t_vals.append(y_data.replace(",", ".") as float)
|
||||
else:
|
||||
y_labels.append(str(database[row][column]))
|
||||
if not t_vals.empty():
|
||||
y_datas.append(t_vals)
|
||||
x_label = str(x_datas.pop_front())
|
||||
else:
|
||||
for row in database.size():
|
||||
if row == labels_index:
|
||||
x_datas = (database[row])
|
||||
x_label = x_datas.pop_front() as String
|
||||
else:
|
||||
var values = database[row] as Array
|
||||
y_labels.append(values.pop_front() as String)
|
||||
y_datas.append(values)
|
||||
for data in y_datas:
|
||||
for value in data.size():
|
||||
data[value] = data[value] as float
|
||||
|
||||
# draw y labels
|
||||
var to_order: Array
|
||||
var to_order_min: Array
|
||||
for cluster in y_datas.size():
|
||||
# define x_chors and y_chors
|
||||
var ordered_cluster = y_datas[cluster].duplicate() as Array
|
||||
ordered_cluster.sort()
|
||||
var margin_max = ordered_cluster[ordered_cluster.size() - 1]
|
||||
var margin_min = ordered_cluster[0]
|
||||
to_order.append(margin_max)
|
||||
to_order_min.append(margin_min)
|
||||
|
||||
to_order.sort()
|
||||
to_order_min.sort()
|
||||
var margin = to_order.pop_back()
|
||||
if not origin_at_zero:
|
||||
y_margin_min = to_order_min.pop_front()
|
||||
v_dist = y_decim * pow(10.0, str(margin).length()-1) #* pow(10.0, (str(margin).length() - 2 if typeof(margin) == TYPE_INT else str(margin).length() - str(y_decim).length() ))
|
||||
var multi = 0
|
||||
var p = (v_dist * multi) + ((y_margin_min) if not origin_at_zero else 0)
|
||||
y_chors.append(p as String)
|
||||
while p < margin:
|
||||
multi += 1
|
||||
p = (v_dist * multi) + ((y_margin_min) if not origin_at_zero else 0)
|
||||
y_chors.append(p as String)
|
||||
|
||||
# draw x_labels
|
||||
if not show_x_values_as_labels:
|
||||
to_order.clear()
|
||||
to_order = x_datas.duplicate() as PoolIntArray
|
||||
to_order.sort()
|
||||
margin = to_order.pop_back()
|
||||
if not origin_at_zero:
|
||||
x_margin_min = to_order.pop_front()
|
||||
h_dist = x_decim * pow(10.0, str(margin).length() - 2)
|
||||
multi = 0
|
||||
p = (h_dist * multi) + ((x_margin_min) if not origin_at_zero else 0)
|
||||
x_labels.append(p as String)
|
||||
while p < margin:
|
||||
multi += 1
|
||||
p = (h_dist * multi) + ((x_margin_min) if not origin_at_zero else 0)
|
||||
x_labels.append(p as String)
|
||||
|
||||
OFFSET.x = (str(margin).length()) * font_size
|
||||
OFFSET.y = font_size * 2
|
||||
})
|
||||
|
||||
|
||||
func calculate_pass():
|
||||
if show_x_values_as_labels:
|
||||
x_chors = x_datas as PoolStringArray
|
||||
else:
|
||||
x_chors = x_labels
|
||||
func _get_property_list():
|
||||
property_list[0].name = "ColumnChart"
|
||||
return property_list
|
||||
|
||||
# calculate distance in pixel between 2 consecutive values/datas
|
||||
if not are_values_columns:
|
||||
x_pass = (SIZE.x - OFFSET.x*2 - (column_width) * ( y_datas.size()) - column_gap - column_width/2) / ((x_chors.size()-1) if x_chors.size()!=1 else 1)
|
||||
else:
|
||||
x_pass = (SIZE.x - OFFSET.x*2 - (column_width) * ( y_datas[0].size()+1 ) - column_gap - column_width/2) / (x_chors.size()-1)
|
||||
y_pass = (origin.y - ChartName.get_rect().size.y*2) / (y_chors.size() - 1)
|
||||
|
||||
func calculate_coordinates():
|
||||
x_coordinates.clear()
|
||||
y_coordinates.clear()
|
||||
point_values.clear()
|
||||
point_positions.clear()
|
||||
|
||||
for cluster in y_datas:
|
||||
var single_coordinates : Array
|
||||
for value in cluster.size():
|
||||
if origin_at_zero:
|
||||
single_coordinates.append((cluster[value]*y_pass)/v_dist)
|
||||
else:
|
||||
single_coordinates.append((cluster[value] - y_margin_min)*y_pass/v_dist)
|
||||
y_coordinates.append(single_coordinates)
|
||||
|
||||
if show_x_values_as_labels:
|
||||
for x in x_datas.size():
|
||||
x_coordinates.append(x_pass*x)
|
||||
else:
|
||||
for x in x_datas.size():
|
||||
if origin_at_zero:
|
||||
x_coordinates.append(x_pass*x)
|
||||
else:
|
||||
x_coordinates.append((x_datas[x] - x_margin_min)*x_pass/h_dist)
|
||||
|
||||
for f in functions:
|
||||
for _i in y_labels.size():
|
||||
point_values.append([])
|
||||
point_positions.append([])
|
||||
|
||||
for cluster in y_coordinates.size():
|
||||
for y in y_coordinates[cluster].size():
|
||||
if are_values_columns:
|
||||
point_positions[y].append(Vector2(OFFSET.x/2 + column_width/2 + (column_width + column_gap)*y + x_coordinates[cluster] + origin.x, origin.y-y_coordinates[cluster][y]))
|
||||
point_values[y].append([x_datas[cluster],y_datas[cluster][y]])
|
||||
else:
|
||||
point_values[cluster].append([x_datas[y],y_datas[cluster][y]])
|
||||
point_positions[cluster].append(Vector2(OFFSET.x/2 + column_width/2 + (column_width + column_gap)*cluster + x_coordinates[y]+origin.x,origin.y-y_coordinates[cluster][y]))
|
||||
for function in y_labels.size():
|
||||
for val in x_datas[function].size():
|
||||
var value_x: float = (int(x_datas[function][val]) - x_margin_min) * x_pass / h_dist if h_dist else 0 \
|
||||
if not show_x_values_as_labels else x_chors.find(String(x_datas[function][val])) * x_pass
|
||||
var value_y: float = (y_datas[function][val] - y_margin_min) * y_pass / v_dist if v_dist else 0
|
||||
var column_offset: float = column_width/2 + (column_width + column_gap)*function - (column_width + column_gap)*functions/2
|
||||
point_values[function].append([x_datas[function][val], y_datas[function][val]])
|
||||
point_positions[function].append(Vector2(value_x + origin.x + column_offset, origin.y - value_y))
|
||||
|
||||
func _draw():
|
||||
clean_points()
|
||||
|
||||
draw_grid()
|
||||
draw_chart_outlines()
|
||||
if show_points:
|
||||
draw_points()
|
||||
draw_columns()
|
||||
draw_treshold()
|
||||
|
||||
var defined_colors : bool = false
|
||||
if function_colors.size():
|
||||
defined_colors = true
|
||||
func draw_columns():
|
||||
for function in point_values.size():
|
||||
for function_point in range(0, point_values[function].size()):
|
||||
draw_line(
|
||||
Vector2(point_positions[function][function_point].x, origin.y),
|
||||
point_positions[function][function_point],
|
||||
function_colors[function],
|
||||
column_width,
|
||||
false)
|
||||
# draw_string(font, Vector2(point_positions[function][function_point].x, origin.y+10), y_labels[function_point], font_color)
|
||||
|
||||
for _function in point_values.size():
|
||||
var PointContainer : Control = Control.new()
|
||||
Points.add_child(PointContainer)
|
||||
|
||||
for function_point in point_values[_function].size():
|
||||
var point : Point = point_node.instance()
|
||||
point.connect("_point_pressed",self,"point_pressed")
|
||||
point.connect("_mouse_entered",self,"show_data")
|
||||
point.connect("_mouse_exited",self,"hide_data")
|
||||
|
||||
point.create_point(points_shape[_function], function_colors[_function],
|
||||
Color.white, point_positions[_function][function_point] + Vector2(0,7),
|
||||
point.format_value(point_values[_function][function_point], false, false),
|
||||
y_labels[_function] as String)
|
||||
PointContainer.add_child(point)
|
||||
point.rect_size.y = origin.y - point_positions[_function][function_point].y
|
||||
draw_line( Vector2(point_positions[_function][function_point].x, origin.y),
|
||||
point_positions[_function][function_point], function_colors[_function], column_width, true)
|
||||
# draw_string(font, Vector2(point_positions[_function][function_point].x, origin.y+10), y_labels[function_point], font_color)
|
||||
|
||||
func draw_grid():
|
||||
# ascisse
|
||||
for p in x_chors.size():
|
||||
var point : Vector2 = origin+Vector2((p)*x_pass,0)
|
||||
# v grid
|
||||
draw_line(point,point-Vector2(0,SIZE.y-OFFSET.y),v_lines_color,0.2,true)
|
||||
# ascisse
|
||||
draw_line(point-Vector2(0,5),point,v_lines_color,1,true)
|
||||
var calculated_gap : float
|
||||
if not are_values_columns:
|
||||
calculated_gap = ( y_datas.size() )
|
||||
else:
|
||||
calculated_gap = ( y_datas[0].size()+1 )
|
||||
draw_string(
|
||||
font,
|
||||
point + Vector2(-const_width/2*x_chors[p].length() + (column_width + column_gap) * functions, font_size),
|
||||
x_chors[p],
|
||||
font_color)
|
||||
|
||||
# ordinate
|
||||
for p in y_chors.size():
|
||||
var point : Vector2 = origin-Vector2(0,(p)*y_pass)
|
||||
# h grid
|
||||
draw_line(point,point+Vector2(SIZE.x-OFFSET.x,0),h_lines_color,0.2,true)
|
||||
# ordinate
|
||||
draw_line(point,point+Vector2(5,0),h_lines_color,1,true)
|
||||
draw_string(
|
||||
font,
|
||||
point - Vector2(y_chors[p].length() * const_width + font_size, -const_height),
|
||||
y_chors[p],
|
||||
font_color)
|
||||
|
||||
func draw_chart_outlines():
|
||||
# if boxed:
|
||||
draw_line(Vector2(origin.x,0),Vector2(SIZE.x,0),box_color,1,true)
|
||||
draw_line(Vector2(SIZE.x,0),Vector2(SIZE.x,origin.y),box_color,1,true)
|
||||
draw_line(Vector2(SIZE.x,origin.y),origin,box_color,1,true)
|
||||
draw_line(origin,Vector2(origin.x,0),box_color,1,true)
|
||||
|
@ -1,14 +1,7 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
<<<<<<<< HEAD:addons/easy_charts/ControlChart/ColumnChart/column_chart.tscn
|
||||
[ext_resource path="res://addons/easy_charts/Utilities/Point/point_data.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/easy_charts/ControlChart/ColumnChart/column_chart.gd" type="Script" id=2]
|
||||
|
||||
|
||||
========
|
||||
[ext_resource path="res://addons/easy_charts/utilities/containers/data_tooltip/data_tooltip.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/easy_charts/control_charts/ColumnChart/column_chart.gd" type="Script" id=2]
|
||||
>>>>>>>> dev:addons/easy_charts/control_charts/ColumnChart/column_chart.tscn
|
||||
|
||||
[sub_resource type="Theme" id=1]
|
||||
|
||||
@ -34,14 +27,16 @@ values of more than one measured variable."
|
||||
}
|
||||
Chart_Properties/are_values_columns = false
|
||||
Chart_Properties/labels_index = 0
|
||||
Chart_Properties/show_x_values_as_labels = true
|
||||
Chart_Properties/column_width = 2.0
|
||||
Chart_Properties/column_gap = 2.0
|
||||
Chart_Display/x_decim = 5.0
|
||||
Chart_Properties/show_x_values_as_labels = false
|
||||
Chart_Display/autoscale_x = true
|
||||
Chart_Display/x_decim = 1.0
|
||||
Chart_Display/autoscale_y = true
|
||||
Chart_Display/y_decim = 1.0
|
||||
Chart_Display/show_points = true
|
||||
Chart_Style/points_shape = [ 0 ]
|
||||
Chart_Style/function_colors = PoolColorArray( 0.117647, 0.117647, 0.117647, 1, 0.117647, 0.117647, 0.117647, 1, 0.117647, 0.117647, 0.117647, 1, 0.117647, 0.117647, 0.117647, 1 )
|
||||
Chart_Style/box_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||
Chart_Style/grid_lines_width = 1
|
||||
Chart_Style/v_lines_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||
Chart_Style/h_lines_color = Color( 0.792157, 0.792157, 0.792157, 1 )
|
||||
Chart_Style/font = null
|
||||
@ -49,7 +44,11 @@ Chart_Style/bold_font = null
|
||||
Chart_Style/font_color = Color( 0.117647, 0.117647, 0.117647, 1 )
|
||||
Chart_Style/use_template = true
|
||||
Chart_Style/template = 0
|
||||
Chart_Modifiers/treshold = Vector2( 0, 0 )
|
||||
Chart_Modifiers/only_disp_values = Vector2( 0, 0 )
|
||||
Chart_Modifiers/invert_chart = false
|
||||
Chart_Properties/column_width = 10.0
|
||||
Chart_Properties/column_gap = 2.0
|
||||
|
||||
[node name="Background" type="ColorRect" parent="."]
|
||||
visible = false
|
||||
@ -89,10 +88,11 @@ __meta__ = {
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="DataTooltip" parent="CanvasLayer" instance=ExtResource( 1 )]
|
||||
margin_left = -455.833
|
||||
margin_top = 690.354
|
||||
margin_right = -455.969
|
||||
margin_bottom = 691.154
|
||||
margin_left = -52.7918
|
||||
margin_top = -28.9529
|
||||
margin_right = -52.9281
|
||||
margin_bottom = -28.1529
|
||||
|
||||
|
||||
[node name="PointData" parent="CanvasLayer/DataTooltip" index="0"]
|
||||
margin_left = -593.381
|
||||
|
@ -14,21 +14,9 @@ class_name LineChart
|
||||
# In these cases they are known as run charts.
|
||||
# Source: Wikipedia
|
||||
|
||||
var show_points := true
|
||||
var function_line_width : int = 2
|
||||
|
||||
|
||||
func build_property_list():
|
||||
.build_property_list()
|
||||
|
||||
property_list.append(
|
||||
{
|
||||
"hint": PROPERTY_HINT_NONE,
|
||||
"usage": PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE,
|
||||
"name": "Chart_Display/show_points",
|
||||
"type": TYPE_BOOL
|
||||
})
|
||||
|
||||
#Find first element of Chart Display
|
||||
var position
|
||||
for i in property_list.size():
|
||||
@ -51,24 +39,6 @@ func _get_property_list():
|
||||
return property_list
|
||||
|
||||
|
||||
func _get(property):
|
||||
match property:
|
||||
"Chart_Display/show_points":
|
||||
return show_points
|
||||
"Chart_Style/function_line_width":
|
||||
return function_line_width
|
||||
|
||||
|
||||
func _set(property, value):
|
||||
match property:
|
||||
"Chart_Display/show_points":
|
||||
show_points = value
|
||||
return true
|
||||
"Chart_Style/function_line_width":
|
||||
function_line_width = value
|
||||
return true
|
||||
|
||||
|
||||
func _draw():
|
||||
draw_grid()
|
||||
draw_chart_outlines()
|
||||
|
@ -1,10 +1,6 @@
|
||||
Year;Column 1;Column 2;Column 3;Column 4
|
||||
2009;36200;27200;26200;17200
|
||||
2010;36600;27800;26600;17800
|
||||
2011;37500;28500;27500;18500
|
||||
2012;38700;29400;28700;19400
|
||||
2013;39600;30200;29600;10200
|
||||
2014;40500;30900;20500;10900
|
||||
2015;41200;31500;21200;11500
|
||||
2016;41803;31931;21803;11931
|
||||
2017;42600;32600;22600;12600
|
||||
Year;2009;2010;2011;2012;2013;2014;2015;2016;2017
|
||||
Column 1;36200;36600;37500;38700;39600;40500;41200;41803;42600
|
||||
Column 2;27200;27800;28500;29400;30200;30900;31500;31931;32600
|
||||
Column 3;26200;26600;27500;28700;29600;20500;21200;21803;22600
|
||||
Column 4;17200;17800;18500;19400;10200;10900;11500;11931;12600
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user