Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose metrics to JS #4654

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions superset/assets/javascripts/modules/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why returning a function that returns an error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function sandboxedEval returns a function (either to mutate the data or generate the tooltip). I'm being consistent here, and returning this ensures that the error is displayed in the tooltip (see second screenshot).

}
}
1 change: 1 addition & 0 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,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'),
Expand Down