From 1df224e806517b0d110234ebaba053d5cbeb65a8 Mon Sep 17 00:00:00 2001 From: Beto Dealmeida Date: Mon, 2 Apr 2018 17:48:56 -0700 Subject: [PATCH] Expose metrics to JS (#4654) --- superset/assets/javascripts/modules/sandbox.js | 8 ++++++-- superset/viz.py | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/superset/assets/javascripts/modules/sandbox.js b/superset/assets/javascripts/modules/sandbox.js index 3439c0319f9f6..a139013d592b0 100644 --- a/superset/assets/javascripts/modules/sandbox.js +++ b/superset/assets/javascripts/modules/sandbox.js @@ -22,6 +22,10 @@ export default function sandboxedEval(code, context, opts) { Object.keys(sandboxContext).forEach(function (key) { sandbox[key] = sandboxContext[key]; }); - vm.runInNewContext(codeToEval, sandbox, opts); - return sandbox[resultKey]; + try { + vm.runInNewContext(codeToEval, sandbox, opts); + return sandbox[resultKey]; + } catch (error) { + return () => error; + } } diff --git a/superset/viz.py b/superset/viz.py index 5d98d5e60e55b..5a92cd3c59c17 100644 --- a/superset/viz.py +++ b/superset/viz.py @@ -2048,6 +2048,7 @@ def get_metrics(self): def get_properties(self, d): return { + 'metric': d.get(self.metric), 'radius': self.fixed_value if self.fixed_value else d.get(self.metric), 'cat_color': d.get(self.dim) if self.dim else None, 'position': d.get('spatial'),