diff --git a/app/content/entities/line_chart/line_chart.gd b/app/content/entities/line_chart/line_chart.gd index 4db7a87..b8c8083 100644 --- a/app/content/entities/line_chart/line_chart.gd +++ b/app/content/entities/line_chart/line_chart.gd @@ -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" \ No newline at end of file diff --git a/app/content/ui/components/line_chart/line_chart.gd b/app/content/ui/components/line_chart/line_chart.gd index de81080..5a1e6a9 100644 --- a/app/content/ui/components/line_chart/line_chart.gd +++ b/app/content/ui/components/line_chart/line_chart.gd @@ -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() ) diff --git a/app/content/ui/components/line_chart/line_chart.tscn b/app/content/ui/components/line_chart/line_chart.tscn index ae95060..6cf4679 100644 --- a/app/content/ui/components/line_chart/line_chart.tscn +++ b/app/content/ui/components/line_chart/line_chart.tscn @@ -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) diff --git a/app/content/ui/components/line_chart/x_axis.tscn b/app/content/ui/components/line_chart/x_axis.tscn index 62c207d..71ae6c4 100644 --- a/app/content/ui/components/line_chart/x_axis.tscn +++ b/app/content/ui/components/line_chart/x_axis.tscn @@ -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 diff --git a/app/content/ui/components/line_chart/y_axis.gd b/app/content/ui/components/line_chart/y_axis.gd index 62cf8d4..0e195fe 100644 --- a/app/content/ui/components/line_chart/y_axis.gd +++ b/app/content/ui/components/line_chart/y_axis.gd @@ -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) diff --git a/app/content/ui/components/line_chart/y_axis.tscn b/app/content/ui/components/line_chart/y_axis.tscn index 27e0114..53ca4a2 100644 --- a/app/content/ui/components/line_chart/y_axis.tscn +++ b/app/content/ui/components/line_chart/y_axis.tscn @@ -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"