From a23c3a7f1ae34bea7d216b748f5a4a6cad1a31ed Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 2 Sep 2014 15:40:11 -0400 Subject: [PATCH 1/3] support templates. fixes #35 similar to previous PR, except now it integrates into the main yaml file instead of a separate graphTemplates.conf --- docs/configuration.rst | 27 +++++++++++++++++++++++++++ graphite_api/config.py | 3 +++ graphite_api/render/glyph.py | 7 ++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index f68926e..363c615 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -137,6 +137,33 @@ Extra sections .. _Graphite-Influxdb: https://github.com/vimeo/graphite-influxdb + +*templates* + + To define color/styling, of graphs, like so: + * values under the 'default' template key serve to override + the built-in defaults (see glyph.py). + * Other template keys provide further styling which will be used + via the http parameter ``template=``. + The defaults are used for unspecified values. + + Example:: + + templates: + default: + background: 'white' + foreground: 'black' + majorLine: 'rose' + minorLine: 'grey' + lineColors: [ 'blue','green','red','purple','brown','yellow','aqua','grey','magenta','pink','gold','rose' ] + fontName: 'Sans' + fontSize: 10 + fontBold: false + fontItalic: false + my_template: + background: 'pink' + + Custom location --------------- diff --git a/graphite_api/config.py b/graphite_api/config.py index c044e05..a10fe75 100644 --- a/graphite_api/config.py +++ b/graphite_api/config.py @@ -140,6 +140,9 @@ def configure(app): else: Sentry(app, dsn=config['sentry_dsn']) + if 'templates' in config: + app.config['templates'] = config['templates'] + app.wsgi_app = TrailingSlash(CORS(app.wsgi_app, config.get('allowed_origins'))) diff --git a/graphite_api/render/glyph.py b/graphite_api/render/glyph.py index 82cf7e5..e8445ac 100644 --- a/graphite_api/render/glyph.py +++ b/graphite_api/render/glyph.py @@ -56,7 +56,7 @@ 'darkgrey': (111, 111, 111), } -# This gets overriden by graphTemplates.conf +# This gets overriden by your graph templates defaultGraphOptions = dict( background='white', foreground='black', @@ -608,7 +608,12 @@ def encodeHeader(self, text): self.ctx.restore() def loadTemplate(self, template): + from ..app import app + conf = app.config.get('templates', {}) + opts = defaults = defaultGraphOptions + defaults.update(conf.get('defaults', {})) + opts.update(conf.get(template, {})) self.defaultBackground = opts.get('background', defaults['background']) self.defaultForeground = opts.get('foreground', defaults['foreground']) From ac7c08a7e72abc4ac71643373919e605056e635f Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 2 Sep 2014 17:01:02 -0400 Subject: [PATCH 2/3] remove all further mentions of graphTemplates.conf --- docs/api.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api.rst b/docs/api.rst index 4caed68..dded205 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1012,7 +1012,7 @@ template *Default: default* -Used to specify a template from ``graphTemplates.conf`` to use for default +Used to specify a template to use for default colors and graph styles. Example:: From b3f3ceeb73c421c6644bc6f738b5e8daae613f77 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 14 Dec 2014 00:28:51 -0500 Subject: [PATCH 3/3] fix: use lineColors like in graphite, and make it a list --- graphite_api/render/glyph.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/graphite_api/render/glyph.py b/graphite_api/render/glyph.py index e8445ac..1790c7e 100644 --- a/graphite_api/render/glyph.py +++ b/graphite_api/render/glyph.py @@ -62,8 +62,8 @@ foreground='black', majorline='rose', minorline='grey', - linecolors=('blue,green,red,purple,brown,yellow,aqua,grey,' - 'magenta,pink,gold,rose'), + lineColors=("blue", "green", "red", "purple", "brown", "yellow", "aqua", + "grey", "magenta", "pink", "gold", "rose"), fontname='Sans', fontsize=10, fontbold='false', @@ -622,8 +622,8 @@ def loadTemplate(self, template): self.defaultMinorGridLineColor = opts.get('minorline', defaults['minorline']) self.defaultColorList = [ - c.strip() for c in opts.get('linecolors', - defaults['linecolors']).split(',')] + c.strip() for c in opts.get('lineColors', + defaults['lineColors'])] fontName = opts.get('fontname', defaults['fontname']) fontSize = float(opts.get('fontsize', defaults['fontsize'])) fontBold = opts.get('fontbold', defaults['fontbold']).lower() == 'true'