Skip to content

Commit

Permalink
LLCAXCHZF-54/implement option to invert x and y axes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomeCirun committed Jul 23, 2024
1 parent a100082 commit 0b84903
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
24 changes: 24 additions & 0 deletions ckanext/charts/chart_builders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,30 @@ def sort_y_field(self) -> dict[str, Any]:
],
}

def invert_x_field(self) -> dict[str, Any]:
return {
"field_name": "invert_x",
"label": "Invert X-axis",
"form_snippet": "chart_checkbox.html",
"group": "Data",
"validators": [
self.get_validator("default")(False),
self.get_validator("boolean_validator"),
],
}

def invert_y_field(self) -> dict[str, Any]:
return {
"field_name": "invert_y",
"label": "Invert Y-axis",
"form_snippet": "chart_checkbox.html",
"group": "Data",
"validators": [
self.get_validator("default")(False),
self.get_validator("boolean_validator"),
],
}

def log_x_field(self) -> dict[str, Any]:
return {
"field_name": "log_x",
Expand Down
13 changes: 12 additions & 1 deletion ckanext/charts/chart_builders/chartjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,16 @@ def to_json(self) -> str:
data: dict[str, Any] = {
"type": "line",
"data": {"labels": self.df[self.settings["x"]].to_list()},
"options": self.settings,
"options": {
"scales": {
"x": {
"reverse": self.settings.get("invert_x", False),
},
"y": {
"reverse": self.settings.get("invert_y", False),
}
}
}
}

datasets = []
Expand Down Expand Up @@ -151,6 +160,8 @@ def get_form_fields(self):
self.sort_x_field(),
self.sort_y_field(),
self.limit_field(),
self.invert_x_field(),
self.invert_y_field(),
self.filter_field(columns),
]

Expand Down

0 comments on commit 0b84903

Please sign in to comment.