From dfb87ef9f979ef35527770e6dbb7ff1c765ea3a0 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 19 Jan 2023 22:07:12 -0500 Subject: [PATCH] Update, fix ngl visualization --- config/plugins/visualizations/ngl/src/ngl.js | 34 ++++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/config/plugins/visualizations/ngl/src/ngl.js b/config/plugins/visualizations/ngl/src/ngl.js index b9d92f73bec..65dc0c67038 100644 --- a/config/plugins/visualizations/ngl/src/ngl.js +++ b/config/plugins/visualizations/ngl/src/ngl.js @@ -1,31 +1,37 @@ import * as ngl from "./viewer"; /** Get boolean as string */ -function asBoolean (value) { +function asBoolean(value) { return String(value).toLowerCase() == "true"; } +/* This should be part of the charts/viz standard lib */ +const slashCleanup = /(\/)+/g; +function prefixedDownloadUrl(root, path) { + return `${root}/${path}`.replace(slashCleanup, "/"); +} + window.bundleEntries = window.bundleEntries || {}; window.bundleEntries.load = function (options) { - var dataset = options.dataset, - settings = options.chart.settings, - stage = new ngl.Stage(options.target, { backgroundColor: settings.get("backcolor") }), - representation_parameters = {}, - stage_parameters = {}; - representation_parameters = { + const dataset = options.dataset; + const settings = options.chart.settings; + const stage = new ngl.Stage(options.target, { backgroundColor: settings.get("backcolor") }); + const representationParameters = { radius: settings.get("radius"), assembly: settings.get("assembly"), color: settings.get("colorscheme"), opacity: settings.get("opacity"), }; - stage_parameters = { ext: dataset.extension, defaultRepresentation: true }; - const safe_download_url = `${options.root}${dataset.download_url}`; + const stageParameters = { ext: dataset.extension, defaultRepresentation: true }; + try { - stage.loadFile(safe_download_url, stage_parameters).then(function (component) { - component.addRepresentation(settings.get("mode"), representation_parameters); - options.chart.state("ok", "Chart drawn."); - options.process.resolve(); - }); + stage + .loadFile(prefixedDownloadUrl(options.root, dataset.download_url), stageParameters) + .then(function (component) { + component.addRepresentation(settings.get("mode"), representationParameters); + options.chart.state("ok", "Chart drawn."); + options.process.resolve(); + }); } catch (e) { options.chart.state("failed", "Could not load PDB file."); options.process.resolve();