Skip to content

Commit

Permalink
SXLLCAXAAD-4 / add editable second y-axis label
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmorev committed Nov 4, 2024
1 parent af83cf5 commit 08b12dd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
22 changes: 16 additions & 6 deletions ckanext/charts/chart_builders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,20 +302,30 @@ def chart_xlabel_field(self) -> dict[str, Any]:
"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]:
def chart_ylabel_left_field(self) -> dict[str, Any]:
return {
"field_name": "chart_ylabel",
"label": "Chart Y axe label",
"form_placeholder": "Y label",
"field_name": "chart_ylabel_left",
"label": "Chart Y axe left label",
"form_placeholder": "Left Y label",
"group": "Styles",
"validators": [
self.get_validator("ignore_empty"),
self.get_validator("unicode_safe"),
],
}

def chart_ylabel_right_field(self) -> dict[str, Any]:
return {
"field_name": "chart_ylabel_right",
"label": "Chart Y axe right label",
"form_placeholder": "Right Y label",
"group": "Styles",
"validators": [
self.get_validator("ignore_empty"),
# self.get_validator("default")(" "),
self.get_validator("unicode_safe"),
],
}
Expand Down
19 changes: 16 additions & 3 deletions ckanext/charts/chart_builders/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,23 @@ def build_line_chart(self) -> Any:
else:
fig.update_xaxes(title_text=self.settings["x"])

if chart_ylabel := self.settings.get("chart_ylabel"):
fig.update_yaxes(title_text=chart_ylabel)
if chart_ylabel_left := self.settings.get("chart_ylabel_left"):
fig.update_yaxes(title_text=chart_ylabel_left)
else:
fig.update_yaxes(title_text=self.settings["y"][0])

if len(self.settings["y"]) > 1:
if chart_ylabel_right := self.settings.get("chart_ylabel_right"):
fig.update_yaxes(
secondary_y=True,
title_text=chart_ylabel_right,
)
else:
fig.update_yaxes(
secondary_y=True,
title_text=self.settings["y"][1],
)

if self.settings.get("invert_x", False):
fig.update_xaxes(autorange="reversed")

Expand Down Expand Up @@ -233,7 +245,8 @@ def get_form_fields(self):
self.limit_field(maximum=1000000),
self.chart_title_field(),
self.chart_xlabel_field(),
self.chart_ylabel_field(),
self.chart_ylabel_left_field(),
self.chart_ylabel_right_field(),
self.filter_field(columns),
]

Expand Down

0 comments on commit 08b12dd

Please sign in to comment.