mirror of
https://github.com/Relintai/pandemonium_engine_easy_charts.git
synced 2025-01-17 14:47:24 +01:00
Correctly (almost) center axis labels
Needs a little of research for the vertical centering since get_string_size doesn't behave as expected.
This commit is contained in:
parent
2f1bf52e1d
commit
25e97a683e
@ -131,6 +131,8 @@ var treshold : Vector2 setget set_treshold
|
|||||||
# only used to draw treshold values
|
# only used to draw treshold values
|
||||||
var treshold_draw : Vector2
|
var treshold_draw : Vector2
|
||||||
|
|
||||||
|
var tic_length : int = 5 setget set_tic_length
|
||||||
|
|
||||||
# !! API v2
|
# !! API v2
|
||||||
static func instance(chart_type : int):
|
static func instance(chart_type : int):
|
||||||
var chart_t : String = Utilities.get_chart_type(chart_type)
|
var chart_t : String = Utilities.get_chart_type(chart_type)
|
||||||
@ -433,7 +435,6 @@ func load_font():
|
|||||||
var theme : Theme = Theme.new()
|
var theme : Theme = Theme.new()
|
||||||
theme.set_default_font(font)
|
theme.set_default_font(font)
|
||||||
set_theme(theme)
|
set_theme(theme)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
var lbl = Label.new()
|
var lbl = Label.new()
|
||||||
font = lbl.get_font("")
|
font = lbl.get_font("")
|
||||||
@ -630,6 +631,10 @@ func set_outline_color(c : Color):
|
|||||||
func set_box_color(c : Color):
|
func set_box_color(c : Color):
|
||||||
box_color = c
|
box_color = c
|
||||||
|
|
||||||
|
# ! API
|
||||||
|
func set_tic_length(i: int):
|
||||||
|
tic_length = i
|
||||||
|
|
||||||
# ! API
|
# ! API
|
||||||
func set_grid_color(c : Color):
|
func set_grid_color(c : Color):
|
||||||
grid_color = c
|
grid_color = c
|
||||||
|
@ -248,8 +248,6 @@ func _set(property, value):
|
|||||||
y_range[1] = value
|
y_range[1] = value
|
||||||
return true
|
return true
|
||||||
|
|
||||||
._set(property, value)
|
|
||||||
|
|
||||||
|
|
||||||
func _get(property):
|
func _get(property):
|
||||||
match property:
|
match property:
|
||||||
@ -266,8 +264,6 @@ func _get(property):
|
|||||||
"Chart_Display/max_y_range":
|
"Chart_Display/max_y_range":
|
||||||
return y_range[1]
|
return y_range[1]
|
||||||
|
|
||||||
._get(property)
|
|
||||||
|
|
||||||
|
|
||||||
func plot():
|
func plot():
|
||||||
# Overwrites the method on Chart to make a reusable piece to be used internally
|
# Overwrites the method on Chart to make a reusable piece to be used internally
|
||||||
@ -514,12 +510,12 @@ func calculate_tics():
|
|||||||
func build_chart():
|
func build_chart():
|
||||||
var longest_y_tic = 0
|
var longest_y_tic = 0
|
||||||
for y_tic in y_chors:
|
for y_tic in y_chors:
|
||||||
if y_tic.length() > longest_y_tic:
|
var length = font.get_string_size(y_tic).x
|
||||||
longest_y_tic = y_tic.length()
|
if length > longest_y_tic:
|
||||||
longest_y_tic += 1 #Necesary to show 1 digit numbers correctly until font_size is calculated dinamically
|
longest_y_tic = length
|
||||||
|
|
||||||
OFFSET.x = font_size * longest_y_tic
|
OFFSET.x = longest_y_tic + tic_length
|
||||||
OFFSET.y = font_size * 2
|
OFFSET.y = font_size * 2 #TODO: Change when get_string_size.y is correctly understood
|
||||||
|
|
||||||
SIZE = get_size() - Vector2(OFFSET.x, 0)
|
SIZE = get_size() - Vector2(OFFSET.x, 0)
|
||||||
origin = Vector2(OFFSET.x, SIZE.y - OFFSET.y)
|
origin = Vector2(OFFSET.x, SIZE.y - OFFSET.y)
|
||||||
@ -556,22 +552,32 @@ func draw_grid():
|
|||||||
# ascisse
|
# ascisse
|
||||||
for p in x_chors.size():
|
for p in x_chors.size():
|
||||||
var point : Vector2 = origin + Vector2(p * x_pass, 0)
|
var point : Vector2 = origin + Vector2(p * x_pass, 0)
|
||||||
|
var size_text : Vector2 = font.get_string_size(x_chors[p])
|
||||||
# v grid
|
# v grid
|
||||||
draw_line(point, point - Vector2(0, SIZE.y - OFFSET.y), v_lines_color, 0.2, true)
|
draw_line(point, point - Vector2(0, SIZE.y - OFFSET.y), v_lines_color, 0.2, true)
|
||||||
# ascisse
|
# ascisse
|
||||||
draw_line(point + Vector2(0, 5), point, v_lines_color, 1, true)
|
draw_line(point + Vector2(0, tic_length), point, v_lines_color, 1, true)
|
||||||
draw_string(font, point + Vector2(-const_width/2 * x_chors[p].length(),
|
draw_string(font, point + Vector2(-size_text.x / 2, size_text.y + tic_length),
|
||||||
font_size + const_height), x_chors[p], font_color)
|
x_chors[p], font_color)
|
||||||
|
|
||||||
# ordinate
|
# ordinate
|
||||||
for p in y_chors.size():
|
for p in y_chors.size():
|
||||||
var point : Vector2 = origin - Vector2(0, p * y_pass)
|
var point : Vector2 = origin - Vector2(0, p * y_pass)
|
||||||
|
var size_text : Vector2 = font.get_string_size(y_chors[p]) #TODO: Investigate into size_text.y being the same for all chars
|
||||||
|
# Apparently numbers are drawn on the upper side of the space, but the size
|
||||||
|
# return all ascent + descent, meaning that it doesn't get correctly centered
|
||||||
|
# vertically. Is this behaviour common to all fonts (i think it can't be
|
||||||
|
# asumed)? Can be taken into account from godot?
|
||||||
|
|
||||||
|
#TEMPORARY FIX: Substract the descent that is not used to represent numbers (at least in the default font)
|
||||||
|
size_text.y -= font.get_descent()
|
||||||
|
|
||||||
# h grid
|
# h grid
|
||||||
draw_line(point, point + Vector2(SIZE.x - OFFSET.x, 0), h_lines_color, 0.2, true)
|
draw_line(point, point + Vector2(SIZE.x - OFFSET.x, 0), h_lines_color, 0.2, true)
|
||||||
# ordinate
|
# ordinate
|
||||||
draw_line(point, point + Vector2(-5, 0), h_lines_color, 1, true)
|
draw_line(point, point + Vector2(-tic_length, 0), h_lines_color, 1, true)
|
||||||
draw_string(font, point - Vector2(y_chors[p].length() * const_width +
|
draw_string(font, point + Vector2(-size_text.x - tic_length, size_text.y / 2),
|
||||||
font_size, -const_height), y_chors[p], font_color)
|
y_chors[p], font_color)
|
||||||
|
|
||||||
|
|
||||||
func draw_chart_outlines():
|
func draw_chart_outlines():
|
||||||
@ -614,7 +620,7 @@ func draw_treshold():
|
|||||||
|
|
||||||
|
|
||||||
func calculate_position_significant_figure(number):
|
func calculate_position_significant_figure(number):
|
||||||
return floor(log(abs(number))/log(10) + 1) if number else 1
|
return floor(log(abs(number))/log(10) + 1) #If number = 0 Godot returns -#INF and it behaves correctly on the pow call on calculate_tics
|
||||||
|
|
||||||
|
|
||||||
func calculate_interval_tics(v_from:float, v_to:float, dist:float, chords:Array, include_first := true):
|
func calculate_interval_tics(v_from:float, v_to:float, dist:float, chords:Array, include_first := true):
|
||||||
|
Loading…
Reference in New Issue
Block a user