2021-12-29 07:53:36 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from django.utils.translation import gettext as _
|
|
|
|
|
|
|
|
import plotly.offline as plotly
|
|
|
|
import plotly.graph_objs as go
|
|
|
|
|
|
|
|
from reports import utils
|
|
|
|
|
|
|
|
|
2022-05-26 04:27:21 +00:00
|
|
|
def head_circumference_change(objects):
|
2021-12-29 07:53:36 +00:00
|
|
|
"""
|
|
|
|
Create a graph showing head_circumference over time.
|
|
|
|
:param objects: a QuerySet of Head Circumference instances.
|
2024-01-28 03:42:12 +00:00
|
|
|
:returns: a tuple of the graph's html and javascript.
|
2021-12-29 07:53:36 +00:00
|
|
|
"""
|
2022-02-10 00:00:30 +00:00
|
|
|
objects = objects.order_by("-date")
|
2021-12-29 07:53:36 +00:00
|
|
|
|
|
|
|
trace = go.Scatter(
|
2022-02-10 00:00:30 +00:00
|
|
|
name=_("Head Circumference"),
|
|
|
|
x=list(objects.values_list("date", flat=True)),
|
|
|
|
y=list(objects.values_list("head_circumference", flat=True)),
|
|
|
|
fill="tozeroy",
|
2021-12-29 07:53:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
layout_args = utils.default_graph_layout_options()
|
2022-02-10 00:00:30 +00:00
|
|
|
layout_args["barmode"] = "stack"
|
|
|
|
layout_args["title"] = _("<b>Head Circumference</b>")
|
|
|
|
layout_args["xaxis"]["title"] = _("Date")
|
|
|
|
layout_args["xaxis"]["rangeselector"] = utils.rangeselector_date()
|
|
|
|
layout_args["yaxis"]["title"] = _("Head Circumference")
|
2021-12-29 07:53:36 +00:00
|
|
|
|
2022-02-10 00:00:30 +00:00
|
|
|
fig = go.Figure({"data": [trace], "layout": go.Layout(**layout_args)})
|
|
|
|
output = plotly.plot(fig, output_type="div", include_plotlyjs=False)
|
2021-12-29 07:53:36 +00:00
|
|
|
return utils.split_graph_output(output)
|