From 9116fbabcf8677da46c89e49a6d8cc8b8bf68ce4 Mon Sep 17 00:00:00 2001 From: Long Ouyang Date: Thu, 8 Dec 2016 13:48:35 -0800 Subject: [PATCH] More useful default rendering of distributions If viz.auto is available, use it. Otherwise, use util.serialize --- docs/webppl-editor.js | 9 +++++++-- src/index.js | 10 ++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/docs/webppl-editor.js b/docs/webppl-editor.js index 3f31491..c3b9e0d 100644 --- a/docs/webppl-editor.js +++ b/docs/webppl-editor.js @@ -42357,9 +42357,14 @@ var renderReturnValue = function (x) { return ''; } - if (x && x.score != undefined && x.sample != undefined) - // TODO: show something more useful by default? + if (x && x.score != undefined && x.sample != undefined) if (typeof viz == 'undefined') { return ''; + } else { + if (typeof viz.auto == 'function') { + viz.auto(x); + return; + } + } if (typeof x == 'function') return ''; diff --git a/src/index.js b/src/index.js index 48bc123..f666098 100644 --- a/src/index.js +++ b/src/index.js @@ -25,8 +25,14 @@ var renderReturnValue = function(x) { } if (x && (x.score != undefined) && (x.sample != undefined)) - // TODO: show something more useful by default? - return ''; + if (typeof viz == 'undefined') { + return util.serialize(x); + } else { + if (typeof viz.auto == 'function') { + viz.auto(x); + return; + } + } if (typeof x == 'function') return '';