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 = {
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)
......
......@@ -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.
"""
......
......@@ -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
{{ 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