SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit f38c25f7 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

WIP improvements to graphs

parent b6b1b1da
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,7 @@ AVAILABLE_MPL_THEMES = { ...@@ -33,7 +33,7 @@ AVAILABLE_MPL_THEMES = {
import geopandas as gpd import geopandas as gpd
world_map_file_URL = ( 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) BASE_WORLD = gpd.read_file(world_map_file_URL)
......
...@@ -7,7 +7,7 @@ from django.forms import Field ...@@ -7,7 +7,7 @@ from django.forms import Field
T = TypeVar("T") T = TypeVar("T")
Option = dict[str, T] Options = dict[str, T]
class BaseOptions: class BaseOptions:
...@@ -22,20 +22,25 @@ class BaseOptions: ...@@ -22,20 +22,25 @@ class BaseOptions:
return [key for key in cls.__dict__.keys() if not key.startswith("__")] return [key for key in cls.__dict__.keys() if not key.startswith("__")]
@classmethod @classmethod
def get_option_fields(cls) -> Option[Field]: def get_option_fields(cls) -> Options[Field]:
option_fields: Option[Field] = {} """
for option in dir(cls): Returns a dictionary of string keys and Field values,
if option.startswith("__"): 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 continue
option_value = getattr(cls, option) option_value = getattr(cls, option_key)
if isinstance(option_value, Field): if isinstance(option_value, Field):
# Try to remove the prefix from the label if it is present # Try to remove the prefix from the label if it is present
if option_value.label is None: if option_value.label is None:
option_value.label = cls.unprefixed(option).title() option_value.label = cls.unprefixed(option_key).title()
option_fields[cls.prefix + option] = option_value options[cls.prefix + option_key] = option_value
return option_fields return options
@classmethod @classmethod
def unprefixed(cls, key: str) -> str: def unprefixed(cls, key: str) -> str:
...@@ -44,7 +49,7 @@ class BaseOptions: ...@@ -44,7 +49,7 @@ class BaseOptions:
return key return key
@classmethod @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. Returns a dictionary with only unprefixed and valid options.
""" """
......
...@@ -37,6 +37,7 @@ class PlotKind: ...@@ -37,6 +37,7 @@ class PlotKind:
@classmethod @classmethod
def get_name(cls) -> str: def get_name(cls) -> str:
"""Get the name of the plot kind in title case"""
return cls.name.title() return cls.name.title()
def __str__(self): def __str__(self):
...@@ -63,7 +64,7 @@ class PlotKind: ...@@ -63,7 +64,7 @@ class PlotKind:
""" """
fig = self.get_figure() fig = self.get_figure()
ax = fig.add_subplot(111) 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) x, y = self.get_data(plotter)
ax.plot(x, y) ax.plot(x, y)
...@@ -200,4 +201,3 @@ class MapPlot(PlotKind): ...@@ -200,4 +201,3 @@ class MapPlot(PlotKind):
*group_by_country_count.values_list(plotter.country_key, "count") *group_by_country_count.values_list(plotter.country_key, "count")
) )
return countries, count return countries, count
{{ plot_svg|safe }} {% if plot_svg %}
{{ plot_svg|safe }}
{% endif %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment