From 0ac359f39174d8b941161ec90de210db70357627 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 18 Dec 2015 22:55:33 +0100 Subject: [PATCH] analytics: Add graph thumbnails Thumbnails of graphs are very handy for the user to see certain events in the graph at one sight. Signed-off-by: Michael Tremer --- Makefile.am | 4 +++- src/templates/modules/graphs/preview.html | 2 ++ .../modules/graphs/thumbnail-bar.html | 7 +++++++ src/templates/modules/graphs/thumbnail.html | 2 ++ src/westferry/handlers/analytics.py | 5 +++-- src/westferry/ui/graphs.py | 18 ++++++++++++++++++ 6 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/templates/modules/graphs/thumbnail-bar.html create mode 100644 src/templates/modules/graphs/thumbnail.html diff --git a/Makefile.am b/Makefile.am index 292b076..70993a1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -138,7 +138,9 @@ templates_modules_graphsdir = $(templates_modulesdir)/graphs dist_templates_modules_graphs_DATA = \ src/templates/modules/graphs/box.html \ - src/templates/modules/graphs/preview.html + src/templates/modules/graphs/preview.html \ + src/templates/modules/graphs/thumbnail.html \ + src/templates/modules/graphs/thumbnail-bar.html templates_modules_menudir = $(templates_modulesdir)/menu diff --git a/src/templates/modules/graphs/preview.html b/src/templates/modules/graphs/preview.html index 21b957e..8706901 100644 --- a/src/templates/modules/graphs/preview.html +++ b/src/templates/modules/graphs/preview.html @@ -4,6 +4,8 @@ +{% module GraphThumbnailBar(graph) %} + {{ graph.title }} diff --git a/src/templates/modules/graphs/thumbnail-bar.html b/src/templates/modules/graphs/thumbnail-bar.html new file mode 100644 index 0000000..02eccd2 --- /dev/null +++ b/src/templates/modules/graphs/thumbnail-bar.html @@ -0,0 +1,7 @@ +
+ {% for interval in ("1h", "12h", "1d", "week", "month", "year") %} +
+ {% module GraphThumbnail(graph, interval=interval) %} +
+ {% end %} +
diff --git a/src/templates/modules/graphs/thumbnail.html b/src/templates/modules/graphs/thumbnail.html new file mode 100644 index 0000000..e84b861 --- /dev/null +++ b/src/templates/modules/graphs/thumbnail.html @@ -0,0 +1,2 @@ +{{ graph.title }} diff --git a/src/westferry/handlers/analytics.py b/src/westferry/handlers/analytics.py index 3b41265..6346fa8 100644 --- a/src/westferry/handlers/analytics.py +++ b/src/westferry/handlers/analytics.py @@ -319,9 +319,9 @@ class GraphExportHandler(base.BaseHandler): SUPPORTED_FORMATS = ("pdf", "png", "svg") - url = r"/graph/([\w\-]+)(?:/([\w\d\.]+))?\.(%s)" % "|".join(SUPPORTED_FORMATS) + url = r"/graph(/thumbnail)?/([\w\-]+)(?:/([\w\d\.]+))?\.(%s)" % "|".join(SUPPORTED_FORMATS) - def get(self, template_name, object_id, format): + def get(self, thumbnail, template_name, object_id, format): # Get the requested dimensions of the image height = self.get_argument_int("height", None) width = self.get_argument_int("width", None) @@ -340,6 +340,7 @@ class GraphExportHandler(base.BaseHandler): "interval" : interval, "height" : height, "width" : width, + "thumbnail" : bool(thumbnail), # Include the title in the PDF exports "with_title" : format == "pdf", diff --git a/src/westferry/ui/graphs.py b/src/westferry/ui/graphs.py index 1098c74..ab9b09e 100644 --- a/src/westferry/ui/graphs.py +++ b/src/westferry/ui/graphs.py @@ -118,6 +118,14 @@ class Graph(object): return self._make_url(url, **kwargs) + def make_thumbnail_url(self, **kwargs): + if self.object_id: + url = "/graph/thumbnail/%(template)s/%(object_id)s.%(format)s" + else: + url = "/graph/thumbnail/%(template)s.%(format)s" + + return self._make_url(url, **kwargs) + def make_url(self, **kwargs): if self.object_id: url = "/graph/%(template)s/%(object_id)s" @@ -139,3 +147,13 @@ class GraphBoxModule(base.BaseUIModule): class GraphBoxPreviewModule(base.BaseUIModule): def render(self, graph): return self.render_string("modules/graphs/preview.html", graph=graph) + + +class GraphThumbnailModule(base.BaseUIModule): + def render(self, graph, **kwargs): + return self.render_string("modules/graphs/thumbnail.html", graph=graph, args=kwargs) + + +class GraphThumbnailBarModule(base.BaseUIModule): + def render(self, graph): + return self.render_string("modules/graphs/thumbnail-bar.html", graph=graph) -- 2.39.2