diff --git a/ckanext/charts/chart_builders/base.py b/ckanext/charts/chart_builders/base.py index db8c8f2..cb61d1c 100644 --- a/ckanext/charts/chart_builders/base.py +++ b/ckanext/charts/chart_builders/base.py @@ -294,6 +294,32 @@ def chart_title_field(self) -> dict[str, Any]: ], } + def chart_xlabel_field(self) -> dict[str, Any]: + return { + "field_name": "chart_xlabel", + "label": "Chart X axe label", + "form_placeholder": "X label", + "group": "Styles", + "validators": [ + self.get_validator("ignore_empty"), + # self.get_validator("default")(" "), + self.get_validator("unicode_safe"), + ], + } + + def chart_ylabel_field(self) -> dict[str, Any]: + return { + "field_name": "chart_ylabel", + "label": "Chart Y axe label", + "form_placeholder": "Y label", + "group": "Styles", + "validators": [ + self.get_validator("ignore_empty"), + # self.get_validator("default")(" "), + self.get_validator("unicode_safe"), + ], + } + def description_field(self) -> dict[str, Any]: return { "field_name": "description", diff --git a/ckanext/charts/chart_builders/plotly.py b/ckanext/charts/chart_builders/plotly.py index b5e5bf4..532af75 100644 --- a/ckanext/charts/chart_builders/plotly.py +++ b/ckanext/charts/chart_builders/plotly.py @@ -96,6 +96,16 @@ def build_line_chart(self) -> Any: if chart_title := self.settings.get("chart_title"): fig.update_layout(title_text=chart_title) + if chart_xlabel := self.settings.get("chart_xlabel"): + fig.update_xaxes(title_text=chart_xlabel) + else: + fig.update_xaxes(title_text=self.settings["x"]) + + if chart_ylabel := self.settings.get("chart_ylabel"): + fig.update_yaxes(title_text=chart_ylabel) + else: + fig.update_yaxes(title_text=self.settings["y"][0]) + if self.settings.get("invert_x", False): fig.update_xaxes(autorange="reversed") @@ -222,6 +232,8 @@ def get_form_fields(self): self.split_data_field(), self.limit_field(maximum=1000000), self.chart_title_field(), + self.chart_xlabel_field(), + self.chart_ylabel_field(), self.filter_field(columns), ]