From 4c43951e70aaa2e7265d3b3f3c4964c048b9328d Mon Sep 17 00:00:00 2001 From: Hop311 Date: Thu, 10 Aug 2023 12:00:54 +0100 Subject: PieChart data and image now come from c++ layer --- game/src/Game/Theme/PieChart/LayeredChart.gd | 28 -- game/src/Game/Theme/PieChart/LayeredChart.tscn | 249 ----------------- game/src/Game/Theme/PieChart/PieChart.gd | 355 ++++++++++++------------- game/src/Game/Theme/PieChart/PieChart.gdshader | 87 ------ game/src/Game/Theme/PieChart/PieChart.tscn | 117 +------- game/src/Game/Theme/PieChart/PieChartMat.tres | 21 -- game/src/Game/Theme/PieChart/chart_test.gd | 32 --- 7 files changed, 171 insertions(+), 718 deletions(-) delete mode 100644 game/src/Game/Theme/PieChart/LayeredChart.gd delete mode 100644 game/src/Game/Theme/PieChart/LayeredChart.tscn delete mode 100644 game/src/Game/Theme/PieChart/PieChart.gdshader delete mode 100644 game/src/Game/Theme/PieChart/PieChartMat.tres delete mode 100644 game/src/Game/Theme/PieChart/chart_test.gd (limited to 'game/src/Game/Theme/PieChart') diff --git a/game/src/Game/Theme/PieChart/LayeredChart.gd b/game/src/Game/Theme/PieChart/LayeredChart.gd deleted file mode 100644 index 7bc69c8..0000000 --- a/game/src/Game/Theme/PieChart/LayeredChart.gd +++ /dev/null @@ -1,28 +0,0 @@ -extends CenterContainer - -var overlapping_charts:Array = [] - -# Called when the node enters the scene tree for the first time. -func _ready(): - for child in get_children(): - if child is PieChart: - overlapping_charts.push_back(child) - -#Process mouse to select the appropriate tooltip for the slice -func _gui_input(event:InputEvent): - if event is InputEventMouse: - var pos = event.position - var handled:bool = false - var x = overlapping_charts.size() - #process the charts in reverse order (overlying charts first) - #as you can't actually make the inner chart(s) smaller with a centerContainer - for i in range(x): - var chart = overlapping_charts[x-(i+1)] - if not handled: - handled = chart.handleTooltip(pos) - else: - chart.RichTooltip.visible = false - -func _on_mouse_exited(): - for chart in overlapping_charts: - chart.RichTooltip.visible = false diff --git a/game/src/Game/Theme/PieChart/LayeredChart.tscn b/game/src/Game/Theme/PieChart/LayeredChart.tscn deleted file mode 100644 index 9382483..0000000 --- a/game/src/Game/Theme/PieChart/LayeredChart.tscn +++ /dev/null @@ -1,249 +0,0 @@ -[gd_scene load_steps=9 format=3 uid="uid://ct48qux7spi6u"] - -[ext_resource type="PackedScene" uid="uid://cr7p1k2xm7mum" path="res://src/Game/Theme/PieChart/PieChart.tscn" id="1_cdu1k"] -[ext_resource type="Script" path="res://src/Game/Theme/PieChart/LayeredChart.gd" id="1_wxoci"] - -[sub_resource type="Shader" id="Shader_ojesc"] -code = "shader_type canvas_item; - -// The center in UV coordinates, which will always -//be 0.5, the actual radius will be controlled by the control node -//const vec2 center = vec2(0.5,0.5); -uniform float radius = 0.4; - -//shadow -uniform vec2 shadow_displacement = vec2(0.75,0.75); -uniform float shadow_tightness = 10; -uniform float shadow_radius = 0.7; -uniform float shadow_thickness = 1.0; - -// Control of the slices -uniform float stopAngles[5]; -uniform vec3 colours[5]; - -// Trim -uniform vec3 trim_colour; -uniform float trim_size = 0.05; - -// The center is spotlighted by the gradient, -//control its size and falloff with these -uniform float gradient_falloff = 3.6; -uniform float gradient_base = 3.1; - -// control whether this is a donut instead of a pie chart -uniform bool donut = false; -uniform bool donut_inner_trim = false; -uniform float donut_inner_radius = 0.15; - -// get the polar coordinates of a pixel relative to the center -vec2 getPolar(vec2 UVin, vec2 center){ - vec2 relcoord = (UVin-center); - float dist = length(relcoord); - float theta = PI/2.0 + atan((relcoord.y)/(relcoord.x)); - if(UVin.x < 0.5){ - theta += PI; - } - return vec2(dist,theta); -} - -// from thebookofshaders, returns a gradient falloff -float parabola( float base, float x, float k ){ - return pow( base*x*(1.0-x), k ); -} - -float parabola_shadow(float base, float x){ - return base*x*x; -} - -void fragment() { - vec2 coords = getPolar(UV,vec2(0.5,0.5)); - float dist = coords.x; - float theta = coords.y; - - vec2 shadow_polar = getPolar(UV,vec2(0.0+shadow_displacement.x,0.0+shadow_displacement.y)); - float shadow_peak = radius+(radius-donut_inner_radius)/2.0; - float shadow_gradient = shadow_thickness+parabola_shadow(shadow_tightness*-10.0,shadow_polar.x+shadow_peak-shadow_radius); - - // inner hole of the donut => make it transparent - if(donut && dist <= donut_inner_radius){ - COLOR = vec4(0.1,0.1,0.1,shadow_gradient); - } - // inner trim - else if(donut && donut_inner_trim && dist <= donut_inner_radius + trim_size){ - COLOR = vec4(trim_colour,1.0); - } - // interior - else if(dist <= radius-trim_size){ - for(int i=0;i void: - slices[labelName] = SliceData.new(quantity,tooltip,colour) +# These functions are the interface a developer will use to update the piechart +# The piechart will only redraw once one of these has been triggered +func add_or_replace_label(labelName : String, quantity : float, tooltip : String, colour : Color = Color(0.0, 0.0, 0.0)) -> void: + _slices[labelName] = SliceData.new(quantity, tooltip, colour) + if _slice_order.find(labelName) == -1: + _slice_order.push_back(labelName) _recalculate() -func updateLabelQuantity(labelName:String,quantity:float) -> void: - if slices.has(labelName): - slices[labelName].quantity = quantity +func update_label_quantity(labelName : String, quantity : float) -> void: + if _slices.has(labelName): + _slices[labelName].quantity = quantity _recalculate() -func updateLabelColour(labelName:String,colour:Color) -> void: - if slices.has(labelName): - slices[labelName].colour = colour +func update_label_colour(labelName : String, colour : Color) -> void: + if _slices.has(labelName): + _slices[labelName].colour = colour _recalculate() -func updateLabelTooltip(labelName:String,tooltip:String) -> void: - if slices.has(labelName): - slices[labelName].tooltip = tooltip +func update_label_tooltip(labelName : String, tooltip : String) -> void: + if _slices.has(labelName): + _slices[labelName].tooltip = tooltip + +func remove_label(labelName : String) -> bool: + if _slices.erase(labelName): + var index := _slice_order.find(labelName) + if index == -1: + push_error("Slice in dictionary but not order list: ", labelName) + else: + _slice_order.remove_at(index) + _recalculate() + return true + return false -func RemoveLabel(labelName:String) -> bool: - var out = slices.erase(labelName) +func clear_slices() -> void: + _slices.clear() + _slice_order.clear() + +# Distribution dictionary of the form: +# { "