add tooltip

This commit is contained in:
fenix-hub 2022-01-09 17:00:25 +01:00
parent 5621f59e30
commit e48083802e
2 changed files with 151 additions and 0 deletions

View File

@ -0,0 +1,69 @@
tool
extends PanelContainer
class_name DataTooltip
var value : String = ""
var position : Vector2 = Vector2()
var OFFSET : Vector2 = Vector2(15,35)
var GAP : Vector2 = Vector2(0,15)
onready var Data : Label = $PointData/Value/x
onready var Value : Label = $PointData/Value/y
onready var Function : Label = $PointData/Function
func _ready():
hide()
func _process(delta):
if get_global_mouse_position().y > OFFSET.y + GAP.y:
rect_position = get_global_mouse_position() - OFFSET - GAP
else:
rect_position = get_global_mouse_position() + GAP*5 - OFFSET
func update_datas(point : Control):
update_size()
get("custom_styles/panel").set("bg_color",point.color)
var font_color : Color
if point.color.g < 0.75:
font_color = Color(1,1,1,1)
else:
font_color = Color(0,0,0,1)
Data.set("custom_colors/font_color",font_color)
Value.set("custom_colors/font_color",font_color)
Function.set("custom_colors/font_color",font_color)
get("custom_styles/panel").set("border_color",font_color)
Data.set_text(point.point_value[0]+":")
Value.set_text(point.point_value[1])
Function.set_text(point.function)
update()
show()
func update_slice_datas(slice : Slice):
update_size()
get("custom_styles/panel").set("bg_color",slice.color)
var font_color : Color
if slice.color.g < 0.75:
font_color = Color(1,1,1,1)
else:
font_color = Color(0,0,0,1)
Data.set("custom_colors/font_color",font_color)
Value.set("custom_colors/font_color",font_color)
Function.set("custom_colors/font_color",font_color)
get("custom_styles/panel").set("border_color",font_color)
Data.set_text(slice.x_value+":")
Value.set_text(slice.y_value)
Function.set_text(slice.function)
update()
show()
func update_size():
OFFSET.x = get_size().x/2
OFFSET.y = get_size().y
GAP.y = OFFSET.y/3

View File

@ -0,0 +1,82 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://addons/easy_charts/utilities/containers/data_tooltip/data_tooltip.gd" type="Script" id=1]
[sub_resource type="StyleBoxFlat" id=1]
content_margin_left = 10.0
content_margin_right = 10.0
content_margin_top = 5.0
content_margin_bottom = 5.0
bg_color = Color( 1, 1, 1, 0 )
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color( 1, 1, 1, 1 )
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
corner_detail = 20
[node name="DataTooltip" type="PanelContainer"]
visible = false
anchor_right = 0.0694688
anchor_bottom = 0.067
margin_left = -185.084
margin_top = 338.399
margin_right = -185.221
margin_bottom = 339.2
grow_horizontal = 2
mouse_filter = 2
custom_styles/panel = SubResource( 1 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": true
}
[node name="PointData" type="VBoxContainer" parent="."]
margin_left = 10.0
margin_top = 5.0
margin_right = 61.0
margin_bottom = 36.0
grow_horizontal = 2
size_flags_horizontal = 3
custom_constants/separation = 3
alignment = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Function" type="Label" parent="PointData"]
margin_right = 51.0
margin_bottom = 14.0
size_flags_horizontal = 3
align = 1
valign = 1
[node name="Value" type="HBoxContainer" parent="PointData"]
margin_top = 17.0
margin_right = 51.0
margin_bottom = 31.0
grow_horizontal = 2
size_flags_horizontal = 6
alignment = 1
[node name="x" type="Label" parent="PointData/Value"]
margin_right = 39.0
margin_bottom = 14.0
size_flags_horizontal = 3
custom_colors/font_color = Color( 1, 1, 1, 1 )
text = "Value:"
align = 2
valign = 1
[node name="y" type="Label" parent="PointData/Value"]
margin_left = 43.0
margin_right = 51.0
margin_bottom = 14.0
size_flags_horizontal = 3
custom_colors/font_color = Color( 1, 1, 1, 1 )
text = "0"
valign = 1