add labels to y_axis

This commit is contained in:
Nitwel 2024-04-16 11:27:03 +02:00
parent 8ad2fb923d
commit 3b47e82543
6 changed files with 17 additions and 29 deletions

View File

@ -13,6 +13,11 @@ func _ready():
if HomeApi.has_connected() == false:
await HomeApi.on_connect
var stateInfo = await HomeApi.get_state(entity_id)
if stateInfo["attributes"]["friendly_name"] != null:
label.text = stateInfo["attributes"]["friendly_name"]
request_history()
timer.timeout.connect(request_history)
@ -35,6 +40,7 @@ func request_history():
)
line_chart.points.value = points
line_chart.y_axis_label.value = result.unit
func get_interface():
return "line_chart"

View File

@ -15,6 +15,8 @@ const STEPS = 5
var points = R.state([])
var show_dates = R.state(false)
var x_axis_label = R.state("X")
var y_axis_label = R.state("Y")
var minmax = R.computed(func(_arg):
if points.value.size() == 0:
@ -52,6 +54,7 @@ func _ready():
R.effect(func(_arg):
x_axis.minmax=Vector2(minmax.value[0].x, minmax.value[1].x)
y_axis.minmax=Vector2(minmax.value[0].y, minmax.value[1].y)
y_axis.label=y_axis_label.value
x_axis.queue_redraw()
y_axis.queue_redraw()
)

View File

@ -10,7 +10,7 @@ cull_mode = 2
shading_mode = 0
albedo_color = Color(0.109804, 0.721569, 0.262745, 1)
[sub_resource type="ArrayMesh" id="ArrayMesh_ww3lm"]
[sub_resource type="ArrayMesh" id="ArrayMesh_raxtd"]
_surfaces = [{
"aabb": AABB(-0.000587015, -0.000596339, 0.0005, 0.501171, 0.301189, 1e-05),
"format": 34359742465,
@ -43,7 +43,7 @@ script = ExtResource("1_n7fu8")
[node name="Line" type="MeshInstance3D" parent="."]
material_override = SubResource("StandardMaterial3D_20gpn")
mesh = SubResource("ArrayMesh_ww3lm")
mesh = SubResource("ArrayMesh_raxtd")
[node name="Plane" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.25, 0.15, -0.001)

View File

@ -1,7 +1,6 @@
[gd_scene load_steps=3 format=3 uid="uid://bb3shmvedk1oh"]
[gd_scene load_steps=2 format=3 uid="uid://bb3shmvedk1oh"]
[ext_resource type="Script" path="res://content/ui/components/line_chart/x_axis.gd" id="1_5fiu5"]
[ext_resource type="LabelSettings" uid="uid://bc8arfh1k2gd2" path="res://content/ui/components/line_chart/axis_label.tres" id="2_tapys"]
[node name="XAxis" type="Control"]
layout_mode = 3
@ -12,17 +11,7 @@ grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_5fiu5")
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_left = 4.0
offset_top = 43.0
offset_right = 123.0
offset_bottom = 93.0
text = "X Axis"
label_settings = ExtResource("2_tapys")
horizontal_alignment = 1
[node name="AxisLabels" type="Control" parent="."]
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
offset_right = 169.0
offset_bottom = 111.0

View File

@ -6,6 +6,7 @@ const HEIGHT = 3000
var minmax = Vector2(0, 100)
var axis_divisions = R.state(10.0)
var label = ""
var font_size = 80
var border_size = 10
@ -24,7 +25,7 @@ func _draw():
var font = get_theme_default_font()
var relative_i = inverse_lerp(HEIGHT, 0, i)
var text = str(round(lerp(minmax.x, minmax.y, relative_i) * 100) / 100)
var text = str(round(lerp(minmax.x, minmax.y, relative_i) * 100) / 100) + (" " + label) if label != "" else ""
var text_size = font.get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size + border_size)

View File

@ -4,16 +4,5 @@
[node name="YAxis" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
anchors_preset = 0
script = ExtResource("1_e83gd")
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_right = 40.0
offset_bottom = 20.0
theme_override_font_sizes/font_size = 50
text = "Y Axis"