Skip to content

Commit

Permalink
feat: update choropleth map, add color scale options, add tick toggle…
Browse files Browse the repository at this point in the history
…, refactor, ruff fixes
  • Loading branch information
mutantsan committed Jan 23, 2025
1 parent f2ca0cf commit d618f4a
Show file tree
Hide file tree
Showing 22 changed files with 325 additions and 74 deletions.
5 changes: 0 additions & 5 deletions ckanext/charts/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def get_data(self, key: str) -> pd.DataFrame | None:
Returns:
The data if exists, otherwise None.
"""
pass

@abstractmethod
def set_data(self, key: str, data: pd.DataFrame):
Expand All @@ -46,7 +45,6 @@ def set_data(self, key: str, data: pd.DataFrame):
key: The cache key to store the data.
data: The data to be stored.
"""
pass

@abstractmethod
def invalidate(self, key: str) -> None:
Expand All @@ -55,7 +53,6 @@ def invalidate(self, key: str) -> None:
Args:
key: The cache key to invalidate.
"""
pass


class RedisCache(CacheStrategy):
Expand Down Expand Up @@ -151,7 +148,6 @@ def read_data(self, file: IO) -> pd.DataFrame | None:
Returns:
The data if exists, otherwise None.
"""
pass

def set_data(self, key: str, data: pd.DataFrame) -> None:
"""Store data to cache.
Expand All @@ -172,7 +168,6 @@ def write_data(self, file_path: str, data: pd.DataFrame) -> None:
file_path: The path to the file.
data: The data to be stored.
"""
pass

def invalidate(self, key: str) -> None:
"""Remove data from cache.
Expand Down
17 changes: 14 additions & 3 deletions ckanext/charts/chart_builders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class BaseChartForm(ABC):
name = ""

def __init__(
self, resource_id: str | None = None, dataframe: pd.DataFrame | None = None
self, resource_id: str | None = None, dataframe: pd.DataFrame | None = None,
) -> None:
if dataframe is not None:
self.df = dataframe
Expand Down Expand Up @@ -279,7 +279,7 @@ def get_validation_schema(self, for_show: bool = False) -> dict[str, Any]:
if "validators" in field
}
except KeyError:
raise ChartBuildError("Form field missing 'field_name' key")
raise ChartBuildError("Form field missing 'field_name' key") from None

return validation_schema

Expand Down Expand Up @@ -546,6 +546,7 @@ def split_data_field(self) -> dict[str, Any]:
"form_snippet": "chart_checkbox.html",
"group": "Data",
"validators": [
self.get_validator("chart_checkbox"),
self.get_validator("default")(False),
self.get_validator("boolean_validator"),
],
Expand All @@ -564,6 +565,8 @@ def skip_null_values_field(self) -> dict[str, Any]:
"form_snippet": "chart_checkbox.html",
"group": "Data",
"validators": [
self.get_validator("chart_checkbox"),
self.get_validator("default")(False),
self.get_validator("boolean_validator"),
],
"help_text": """Entries of the data with missing values will not be
Expand All @@ -578,6 +581,8 @@ def break_chart_field(self) -> dict[str, Any]:
"form_snippet": "chart_checkbox.html",
"group": "Data",
"validators": [
self.get_validator("chart_checkbox"),
self.get_validator("default")(False),
self.get_validator("boolean_validator"),
],
"help_text": "Break the graph at missing values",
Expand All @@ -591,6 +596,7 @@ def sort_x_field(self) -> dict[str, Any]:
"form_snippet": "chart_checkbox.html",
"group": "Data",
"validators": [
self.get_validator("chart_checkbox"),
self.get_validator("default")(False),
self.get_validator("boolean_validator"),
],
Expand All @@ -606,6 +612,7 @@ def sort_y_field(self) -> dict[str, Any]:
"form_snippet": "chart_checkbox.html",
"group": "Data",
"validators": [
self.get_validator("chart_checkbox"),
self.get_validator("default")(False),
self.get_validator("boolean_validator"),
],
Expand All @@ -621,6 +628,7 @@ def invert_x_field(self) -> dict[str, Any]:
"form_snippet": "chart_checkbox.html",
"group": "Data",
"validators": [
self.get_validator("chart_checkbox"),
self.get_validator("default")(False),
self.get_validator("boolean_validator"),
],
Expand All @@ -636,6 +644,7 @@ def invert_y_field(self) -> dict[str, Any]:
"form_snippet": "chart_checkbox.html",
"group": "Data",
"validators": [
self.get_validator("chart_checkbox"),
self.get_validator("default")(False),
self.get_validator("boolean_validator"),
],
Expand All @@ -651,6 +660,7 @@ def log_x_field(self) -> dict[str, Any]:
"form_snippet": "chart_checkbox.html",
"group": "Data",
"validators": [
self.get_validator("chart_checkbox"),
self.get_validator("default")(False),
self.get_validator("boolean_validator"),
],
Expand All @@ -666,6 +676,7 @@ def log_y_field(self) -> dict[str, Any]:
"form_snippet": "chart_checkbox.html",
"group": "Data",
"validators": [
self.get_validator("chart_checkbox"),
self.get_validator("default")(False),
self.get_validator("boolean_validator"),
],
Expand Down Expand Up @@ -720,7 +731,7 @@ def opacity_field(self) -> dict[str, Any]:
"default": 1,
}

def limit_field(self, default: int = 100, maximum: int = 10000) -> dict[str, Any]:
def limit_field(self, default: int = 1000, maximum: int = 10000) -> dict[str, Any]:
"""The limit field represent an amount of rows to show in the chart."""
return {
"field_name": "limit",
Expand Down
2 changes: 1 addition & 1 deletion ckanext/charts/chart_builders/chartjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def to_json(self) -> str:
try:
dates = pd.to_datetime(self.df[self.settings["x"]], unit="ns")
self.settings["years"] = list(
dates.dt.strftime(self.YEAR_DATETIME_FORMAT).unique()
dates.dt.strftime(self.YEAR_DATETIME_FORMAT).unique(),
)
except (ParserError, ValueError):
self.settings["years"] = []
Expand Down
1 change: 0 additions & 1 deletion ckanext/charts/chart_builders/observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pandas as pd
from typing import Any

from ckanext.charts import exception
from ckanext.charts.chart_builders.base import BaseChartBuilder, BaseChartForm


Expand Down
Loading

0 comments on commit d618f4a

Please sign in to comment.