Skip to content

Commit

Permalink
Merge pull request #17 from DataShades/SXLLCAXAAD-4
Browse files Browse the repository at this point in the history
SXLLCAXAAD-4 / add editable graph axes labels
  • Loading branch information
alexmorev authored Oct 30, 2024
2 parents c417d21 + af83cf5 commit eff933a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ckanext/charts/chart_builders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions ckanext/charts/chart_builders/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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),
]

Expand Down

0 comments on commit eff933a

Please sign in to comment.