From d10c302be3cb6871394d1b459521b5b1f8204a78 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Fri, 24 Jan 2025 19:26:28 +0100
Subject: [PATCH] =?UTF-8?q?refactor(graphs):=20=F0=9F=9A=B8=20relabel=20an?=
 =?UTF-8?q?d=20reorient=20plot=20option=20fields?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 scipost_django/graphs/graphs/plotkind.py | 35 +++++++++++++++++-------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/scipost_django/graphs/graphs/plotkind.py b/scipost_django/graphs/graphs/plotkind.py
index fabfdde07..75263f078 100644
--- a/scipost_django/graphs/graphs/plotkind.py
+++ b/scipost_django/graphs/graphs/plotkind.py
@@ -388,7 +388,7 @@ class MapPlot(PlotKind):
     class Options(PlotKind.Options):
         prefix = "map_plot_"
         agg_func = forms.ChoiceField(
-            label="Aggregation function",
+            label="Aggregation",
             choices=[
                 ("count", "Count"),
                 ("sum", "Sum"),
@@ -396,18 +396,25 @@ class MapPlot(PlotKind):
             ],
             required=False,
             initial="count",
+            widget=forms.RadioSelect,
         )
         agg_value_key = forms.ChoiceField(
-            label="Agg Value key", required=False, choices=[]
+            label="Aggregated value",
+            required=False,
+            choices=[],
+            help_text="Ignored if aggregation method is Count",
         )
-        country_key = forms.ChoiceField(label="Country key", required=False, choices=[])
+        country_key = forms.ChoiceField(label="Country", required=False, choices=[])
 
     @classmethod
     def get_plot_options_form_layout_row_content(cls):
         return Layout(
             Div(Field("country_key"), css_class="col-12"),
-            Div(Field("agg_func"), css_class="col-6"),
-            Div(Field("agg_value_key"), css_class="col-6"),
+            Div(Field("agg_value_key"), css_class="col-12"),
+            Div(
+                Field("agg_func", css_class="d-flex flex-row gap-3"),
+                css_class="col-12",
+            ),
         )
 
 
@@ -540,13 +547,17 @@ class BarPlot(PlotKind):
             widget=forms.RadioSelect,
         )
         group_key = forms.ChoiceField(
-            label="Group by key", required=False, initial="id", choices=[]
+            label="Group by", required=False, initial="id", choices=[]
         )
         agg_value_key = forms.ChoiceField(
-            label="Agg Value key", required=False, initial="id", choices=[]
+            label="Aggregated value",
+            required=False,
+            initial="id",
+            choices=[],
+            help_text="Ignored if aggregation method is Count",
         )
         agg_func = forms.ChoiceField(
-            label="Aggregation function",
+            label="Aggregation",
             choices=[
                 ("count", "Count"),
                 ("sum", "Sum"),
@@ -554,6 +565,7 @@ class BarPlot(PlotKind):
             ],
             required=False,
             initial="count",
+            widget=forms.RadioSelect,
         )
         order_by = forms.ChoiceField(
             label="Order by",
@@ -580,8 +592,11 @@ class BarPlot(PlotKind):
                 css_class="col-12",
             ),
             Div(Field("group_key"), css_class="col-12"),
-            Div(Field("agg_func"), css_class="col-6"),
-            Div(Field("agg_value_key"), css_class="col-6"),
+            Div(Field("agg_value_key"), css_class="col-12"),
+            Div(
+                Field("agg_func", css_class="d-flex flex-row gap-3"),
+                css_class="col-12",
+            ),
             Div(
                 Div(
                     Div(Field("order_by"), css_class="col-6"),
-- 
GitLab