From 5d18535a3e8a38701d17fc86d922ab91dbd11941 Mon Sep 17 00:00:00 2001 From: fenix-hub Date: Sun, 22 Jan 2023 16:37:40 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20BarChart=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../easy_charts/examples/bar_chart/Control.gd | 52 +++++++++++++++++++ .../examples/bar_chart/Control.tscn | 49 +++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 addons/easy_charts/examples/bar_chart/Control.gd create mode 100644 addons/easy_charts/examples/bar_chart/Control.tscn diff --git a/addons/easy_charts/examples/bar_chart/Control.gd b/addons/easy_charts/examples/bar_chart/Control.gd new file mode 100644 index 0000000..17a1bf2 --- /dev/null +++ b/addons/easy_charts/examples/bar_chart/Control.gd @@ -0,0 +1,52 @@ +extends Control + +onready var chart: BarChart = $BarChart + +func _ready(): + # Let's create our @x values + var x: Array = ["Day 1", "Day 2", "Day 3", "Day 4", "Day 5"] + # And our y values. It can be an n-size array of arrays. + # NOTE: `x.size() == y.size()` or `x.size() == y[n].size()` + var y: Array = [ + [20, 10, -15, 30, 42], + [10, 1, -5, 20, 32] + ] + + # Add some labels for the x axis, we don't want to use our x values array + # they will be printed on the chart ticks instead of the value of the x axis. + var x_labels: Array = ArrayOperations.suffix(x, "s") + + # Let's customize the chart properties, which specify how the chart + # should look, plus some additional elements like labels, the scale, etc... + var cp: ChartProperties = ChartProperties.new() + cp.grid = true + cp.title = "Air Quality Monitoring" + cp.x_label = ("Days") + cp.x_scale = 20 + cp.y_label = ("Sensor values") + cp.y_scale = 10 + cp.points = false + cp.interactive = true # false by default, it allows the chart to create a tooltip to show point values + # and interecept clicks on the plot + + # Set the x_labels +# $LineChart.x_labels = x_labels + + # Plot our data + chart.plot(x, y, cp) + + # Uncommenting this line will show how real time data plotting works + set_process(false) + +func _process(delta: float): + # This function updates the values of chart x, y, and x_labels array + # and updaptes the plot + var new_val: String = "Day %s" % (chart.x.size() + 1) + chart.x.append(new_val) + chart.y[0].append(randi() % 40) + chart.y[1].append(randi() % 50) + chart.update() + + +func _on_CheckButton_pressed(): + set_process(not is_processing()) diff --git a/addons/easy_charts/examples/bar_chart/Control.tscn b/addons/easy_charts/examples/bar_chart/Control.tscn new file mode 100644 index 0000000..5d34b6e --- /dev/null +++ b/addons/easy_charts/examples/bar_chart/Control.tscn @@ -0,0 +1,49 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://addons/easy_charts/control_charts/BarChart/bar_chart.tscn" type="PackedScene" id=1] +[ext_resource path="res://addons/easy_charts/examples/bar_chart/Control.gd" type="Script" id=2] + +[sub_resource type="StyleBoxFlat" id=1] +content_margin_right = 5.0 +content_margin_bottom = 5.0 +draw_center = false +border_width_right = 2 +border_width_bottom = 2 +border_color = Color( 0, 0, 0, 1 ) + +[node name="Control" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": true +} + +[node name="BarChart" parent="." instance=ExtResource( 1 )] + +[node name="CheckButton" type="CheckButton" parent="."] +margin_right = 223.0 +margin_bottom = 40.0 +custom_colors/font_color_disabled = Color( 0, 0, 0, 1 ) +custom_colors/font_color_focus = Color( 0, 0, 0, 1 ) +custom_colors/font_color_hover_pressed = Color( 0, 0, 0, 1 ) +custom_colors/font_color = Color( 0, 0, 0, 1 ) +custom_colors/font_color_hover = Color( 0, 0, 0, 1 ) +custom_colors/font_color_pressed = Color( 0, 0, 0, 1 ) +text = "Start Relatime Plotting" + +[node name="Label" type="Label" parent="."] +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = -159.0 +margin_top = -19.0 +custom_colors/font_color = Color( 0, 0, 0, 1 ) +custom_styles/normal = SubResource( 1 ) +text = "Try to scale the window!" +__meta__ = { +"_edit_lock_": true +} + +[connection signal="pressed" from="CheckButton" to="." method="_on_CheckButton_pressed"]