SciPost Code Repository

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

add timeline plot and publication date plotter

parent cc331113
No related branches found
No related tags found
No related merge requests found
......@@ -65,3 +65,26 @@ class PlotKind:
x, y = self.get_data(plotter)
ax.plot(x, y)
return fig
class TimelinePlot(PlotKind):
name = "timeline"
def plot(self, plotter: "ModelFieldPlotter"):
fig = super().plot(plotter)
ax = fig.get_axes()[0]
ax.set_xlabel(plotter.date_key)
ax.set_ylabel(self.options.get("y_key", "id"))
return fig
def get_data(self, plotter: "ModelFieldPlotter", **kwargs):
y_key = self.options.get("y_key", "id")
x, y = zip(*plotter.get_queryset().values_list(plotter.date_key, y_key))
return x, y
class Options(BaseOptions):
prefix = PlotKind.Options.prefix
y_key = forms.CharField(label="Y-axis key", required=False, initial="id")
......@@ -4,7 +4,11 @@ __license__ = "AGPL v3"
from abc import ABC
from typing import TYPE_CHECKING, Any
from django import forms
from matplotlib.figure import Figure
from journals.models.journal import Journal
from journals.models.publication import Publication
from series.models import Collection
from .options import BaseOptions
......@@ -71,3 +75,28 @@ class ModelFieldPlotter(ABC):
fig.suptitle(options.get("title", None))
return fig
class PublicationDatePlotter(ModelFieldPlotter):
model = Publication
name = "Publication Date"
date_key = "publication_date"
class Options(BaseOptions):
prefix = ModelFieldPlotter.Options.prefix
journals = forms.ModelChoiceField(
queryset=Journal.objects.all().active(), required=False
)
collections = forms.ModelChoiceField(
queryset=Collection.objects.all(), required=False
)
def get_queryset(self):
qs = super().get_queryset()
if journal := self.options.get("journals", None):
qs = qs.for_journal(journal.name)
if collections := self.options.get("collections", None):
qs = qs.filter(collections__in=[collections])
return qs
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