diff --git a/scipost_django/graphs/graphs/__init__.py b/scipost_django/graphs/graphs/__init__.py index 167df951cf3d02c4371b5239e8fce04a0f86d60f..137f60bda65371e769178cc748c5a03ba005162b 100644 --- a/scipost_django/graphs/graphs/__init__.py +++ b/scipost_django/graphs/graphs/__init__.py @@ -33,7 +33,7 @@ AVAILABLE_MPL_THEMES = { import geopandas as gpd world_map_file_URL = ( - "http://naturalearth.s3.amazonaws.com/50m_cultural/ne_50m_admin_0_countries.zip" + "http://naturalearth.s3.amazonaws.com/110m_cultural/ne_110m_admin_0_countries.zip" ) BASE_WORLD = gpd.read_file(world_map_file_URL) diff --git a/scipost_django/graphs/graphs/options.py b/scipost_django/graphs/graphs/options.py index 83f7d6c80544434e0dfa1ff6d9558aca363ad91a..dcffaa0ee1585e0896379905df048997dbe449b2 100644 --- a/scipost_django/graphs/graphs/options.py +++ b/scipost_django/graphs/graphs/options.py @@ -7,7 +7,7 @@ from django.forms import Field T = TypeVar("T") -Option = dict[str, T] +Options = dict[str, T] class BaseOptions: @@ -22,20 +22,25 @@ class BaseOptions: return [key for key in cls.__dict__.keys() if not key.startswith("__")] @classmethod - def get_option_fields(cls) -> Option[Field]: - option_fields: Option[Field] = {} - for option in dir(cls): - if option.startswith("__"): + def get_option_fields(cls) -> Options[Field]: + """ + Returns a dictionary of string keys and Field values, + mapping the options to their respective fields. + The keys are prefixed with the class prefix. + """ + options: Options[Field] = {} + for option_key in dir(cls): + if option_key.startswith("__"): continue - option_value = getattr(cls, option) + option_value = getattr(cls, option_key) if isinstance(option_value, Field): # Try to remove the prefix from the label if it is present if option_value.label is None: - option_value.label = cls.unprefixed(option).title() - option_fields[cls.prefix + option] = option_value + option_value.label = cls.unprefixed(option_key).title() + options[cls.prefix + option_key] = option_value - return option_fields + return options @classmethod def unprefixed(cls, key: str) -> str: @@ -44,7 +49,7 @@ class BaseOptions: return key @classmethod - def parse_prefixed_options(cls, options: Option[T]) -> Option[T]: + def parse_prefixed_options(cls, options: Options[T]) -> Options[T]: """ Returns a dictionary with only unprefixed and valid options. """ diff --git a/scipost_django/graphs/graphs/plotkind.py b/scipost_django/graphs/graphs/plotkind.py index 4d4914073ab7e2707e70649a3a414ee257b4438e..02b3817ef0247fe73d72ae7390280a82fda0f515 100644 --- a/scipost_django/graphs/graphs/plotkind.py +++ b/scipost_django/graphs/graphs/plotkind.py @@ -37,6 +37,7 @@ class PlotKind: @classmethod def get_name(cls) -> str: + """Get the name of the plot kind in title case""" return cls.name.title() def __str__(self): @@ -63,7 +64,7 @@ class PlotKind: """ fig = self.get_figure() ax = fig.add_subplot(111) - ax.set_title(f"{self.get_name().title()} plot of {plotter.model.__name__}") + ax.set_title(f"{self.get_name()} plot of {plotter.model.__name__}") x, y = self.get_data(plotter) ax.plot(x, y) @@ -200,4 +201,3 @@ class MapPlot(PlotKind): *group_by_country_count.values_list(plotter.country_key, "count") ) return countries, count - diff --git a/scipost_django/graphs/templates/graphs/plot.html b/scipost_django/graphs/templates/graphs/plot.html index 45b49a073647a39b8ef508a962cda1255b436d96..339a2fc3458b412be682dce220c9783e3bed31d6 100644 --- a/scipost_django/graphs/templates/graphs/plot.html +++ b/scipost_django/graphs/templates/graphs/plot.html @@ -1 +1,3 @@ -{{ plot_svg|safe }} +{% if plot_svg %} + {{ plot_svg|safe }} +{% endif %}