Skip to content

Commit

Permalink
[jsroot] support old jupyter lab code
Browse files Browse the repository at this point in the history
There sequence of parse, settings and draw calls was used.
Now these functions provided in JSRoot.core.js to correctly work.
After final v7 JSROOT release jupyter lab code will be adjusted
  • Loading branch information
linev committed Mar 30, 2022
1 parent e6f16d5 commit 7f36025
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions js/scripts/JSRoot.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,35 @@ exports.openFile = function(...args) {
return _sync().then(() => import('../modules/io.mjs')).then(handle => handle.openFile(...args));
}

exports.parse = function(json) {
if (typeof json == 'string')
json = JSON.parse(json);

if (json && typeof json == 'object')
json.$parse_workaround = true;
return json;
}

function test_parse_workaround(obj) {
if (obj && (typeof obj == 'object') && obj.$parse_workaround) {
delete obj.$parse_workaround;
if (JSROOT?.parse)
obj = JSROOT.parse(obj);
}
return obj;
}

exports.draw = function(dom, obj, opt) {
return _sync().then(() => import('../modules/draw.mjs')).then(handle => handle.draw(dom, test_parse_workaround(obj), opt));
}

exports.redraw = function(dom, obj, opt) {
return _sync().then(() => import('../modules/draw.mjs')).then(handle => handle.redraw(dom, test_parse_workaround(obj), opt));
}

let workaround_settings = {};

exports.settings = workaround_settings;

/** @summary Old v6 method to load JSROOT functionality
* @desc
Expand Down Expand Up @@ -294,11 +323,13 @@ if ((typeof globalThis !== "undefined") && !globalThis.JSROOT) {
globalThis.JSROOT._complete_loading = _sync;

let pr = Promise.all([import('../modules/core.mjs'), import('../modules/draw.mjs'), import('../modules/gui/HierarchyPainter.mjs')]).then(arr => {
Object.assign(globalThis.JSROOT, arr[0], arr[1]);

Object.assign(globalThis.JSROOT, arr[0], arr[1], arr[2]);

Object.assign(globalThis.JSROOT.settings, workaround_settings);

globalThis.JSROOT._ = arr[0].internals;

globalThis.JSROOT.HierarchyPainter = arr[2].HierarchyPainter;
getHPainter = arr[2].getHPainter;

globalThis.JSROOT.hpainter = getHPainter();
Expand Down

0 comments on commit 7f36025

Please sign in to comment.