Skip to content

Commit

Permalink
LLCAXCHZF-56/resolving conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
TomeCirun committed Jul 29, 2024
2 parents b88e5b6 + 91ea83c commit 1479552
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ckanext/charts/assets/js/charts-render-observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ckan.module("charts-render-observable", function ($, _) {
plot = Plot.dot(this.options.config.data, this.options.config.settings).plot();
break;
case "line":
plot = Plot.line(this.options.config.data, this.options.config.settings).plot();
plot = Plot.line(this.options.config.data, this.options.config.settings).plot(this.options.config.plot);
break;
case "pie":
plot = PieChart(this.options.config.data, this.options.config.settings);
Expand Down
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
11 changes: 10 additions & 1 deletion ckanext/charts/chart_builders/chartjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ def to_json(self) -> str:
datasets.append(dataset)

data["data"]["datasets"] = datasets

data["options"]["scales"] = {
"x": {
"reverse": self.settings.get("invert_x", False),
},
"y": {
"reverse": self.settings.get("invert_y", False),
},
}
return json.dumps(data)


Expand All @@ -153,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
6 changes: 6 additions & 0 deletions ckanext/charts/chart_builders/observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def to_json(self) -> str:
"type": "line",
"data": self.df.to_dict(orient="records"),
"settings": self.settings,
"plot": {
"x": {"reverse": self.settings.get("invert_x", False)},
"y": {"reverse": self.settings.get("invert_y", False)}
}
}
)

Expand All @@ -110,6 +114,8 @@ def get_form_fields(self):
self.x_axis_field(columns),
self.y_axis_field(columns),
self.more_info_button_field(),
self.invert_x_field(),
self.invert_y_field(),
self.sort_x_field(),
self.sort_y_field(),
self.limit_field(),
Expand Down
8 changes: 8 additions & 0 deletions ckanext/charts/chart_builders/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ def build_line_chart(self) -> Any:
if chart_title := self.settings.get("chart_title"):
fig.update_layout(title_text=chart_title)

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

if self.settings.get("invert_y", False):
fig.update_yaxes(autorange="reversed")

return fig.to_json()


Expand Down Expand Up @@ -182,6 +188,8 @@ def get_form_fields(self):
self.x_axis_field(columns),
self.plotly_y_multi_axis_field(columns, 2),
self.more_info_button_field(),
self.invert_x_field(),
self.invert_y_field(),
self.sort_x_field(),
self.sort_y_field(),
self.limit_field(),
Expand Down

0 comments on commit 1479552

Please sign in to comment.