Skip to content

Commit

Permalink
[jsroot] dev 6/04/2022
Browse files Browse the repository at this point in the history
Do not show title for online canvas
Exclude v6 support when using bundle
Let use modules with external applications
Export more functions from main.mjs
  • Loading branch information
linev committed Apr 7, 2022
1 parent 290f064 commit e505630
Show file tree
Hide file tree
Showing 14 changed files with 52,707 additions and 52,624 deletions.
105,217 changes: 52,631 additions & 52,586 deletions js/build/jsroot.js

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions js/files/draw.htm
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
loading ...
</div>

<script type='module'>
</body>

import { buildGUI, internals } from './jsrootsys/modules/gui.mjs';
<script type='module'>

internals.GetCachedHierarchy = function() { return "$$$h.json$$$"; }
internals.GetCachedObject = function() { return "$$$root.json$$$"; }
import { buildGUI, internals } from './jsrootsys/modules/gui.mjs';

buildGUI("drawGUI", "draw");
</script>
</body>
internals.getCachedHierarchy = function() { return "$$$h.json$$$"; }
internals.getCachedObject = function() { return "$$$root.json$$$"; }

buildGUI("drawGUI", "draw");
</script>

</html>
12 changes: 6 additions & 6 deletions js/files/online.htm
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
loading ...
</div>

<script type="module">
import { buildGUI, internals } from './jsrootsys/modules/gui.mjs';
</body>

internals.GetCachedHierarchy = function() { return "$$$h.json$$$"; }
<script type="module">
import { buildGUI, internals } from './jsrootsys/modules/gui.mjs';

buildGUI("onlineGUI", "online");
</script>
internals.getCachedHierarchy = function() { return "$$$h.json$$$"; }

</body>
buildGUI("onlineGUI", "online");
</script>

</html>
5 changes: 4 additions & 1 deletion js/modules/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let version_id = "modules";

/** @summary version date
* @desc Release date in format day/month/year like "19/11/2021" */
let version_date = "30/03/2022";
let version_date = "6/04/2022";

/** @summary version id and date
* @desc Produced by concatenation of {@link version_id} and {@link version_date}
Expand Down Expand Up @@ -35,6 +35,9 @@ if (src && (typeof src == "string")) {
source_fullpath = src;
source_dir = source_fullpath.slice(0, pos);
console.log(`Set jsroot source_dir to ${source_dir}, ${version}`);
} else {
console.log(`jsroot bundle, ${version}`);
internals.ignore_v6 = true;
}
}

Expand Down
7 changes: 5 additions & 2 deletions js/modules/draw.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,16 @@ function draw(dom, obj, opt) {
} else if (!handle.prereq && !handle.script) {
return Promise.reject(Error(`Prerequicities to load ${handle.func} are not specified`));
} else {
promise = _ensureJSROOT().then(v6 => {

let init_promise = internals.ignore_v6 ? Promise.resolve(true) : _ensureJSROOT().then(v6 => {
let pr = handle.prereq ? v6.require(handle.prereq) : Promise.resolve(true);
return pr.then(() => {
if (handle.script)
return loadScript(handle.script);
}).then(() => v6._complete_loading());
}).then(() => {
});

promise = init_promise.then(() => {
let func = findFunction(handle.func);

if (!func || (typeof func != 'function'))
Expand Down
2 changes: 1 addition & 1 deletion js/modules/geom/TGeoPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { ensureTCanvas } from '../gpad/TCanvasPainter.mjs';

import { geoCfg, geoBITS, ClonedNodes, testGeoBit, setGeoBit, toggleGeoBit, setInvisibleAll,
countNumShapes, getNodeKind, produceRenderOrder, createFlippedMesh,
createGeometry, projectGeometry, countGeometryFaces, createFrustum, createProjectionMatrix,
projectGeometry, countGeometryFaces, createFrustum, createProjectionMatrix,
getBoundingBox, provideObjectInfo, isSameStack, checkDuplicates, getObjectName, cleanupShape } from './geobase.mjs';

const _ENTIRE_SCENE = 0, _BLOOM_SCENE = 1;
Expand Down
2 changes: 1 addition & 1 deletion js/modules/gpad/RPadPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class RPadPainter extends RObjectPainter {

this.setTopPainter(); //assign canvas as top painter of that element

if (!isBatchMode())
if (!isBatchMode() && !this.online_canvas)
svg.append("svg:title").text("ROOT canvas");

frect = svg.append("svg:path").attr("class","canvas_fillrect");
Expand Down
2 changes: 1 addition & 1 deletion js/modules/gpad/TPadPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class TPadPainter extends ObjectPainter {
if (isBatchMode()) {
svg.attr("xmlns", "http://www.w3.org/2000/svg");
svg.attr("xmlns:xlink", "http://www.w3.org/1999/xlink");
} else {
} else if (!this.online_canvas) {
svg.append("svg:title").text("ROOT canvas");
}

Expand Down
2 changes: 1 addition & 1 deletion js/modules/gui.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function buildGUI(gui_element, gui_kind) {
return hpainter.initializeBrowser();
if (!drawing)
return;
let obj = null, func = internals.GetCachedObject || findFunction('GetCachedObject');
let obj = null, func = internals.getCachedObject || findFunction('GetCachedObject');
if (typeof func == 'function')
obj = parse(func());
if (obj) hpainter._cached_draw_object = obj;
Expand Down
39 changes: 28 additions & 11 deletions js/modules/gui/HierarchyPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2402,9 +2402,11 @@ class HierarchyPainter extends BasePainter {
if (typeof handle.expand == 'function')
_item._expand = handle.expand;
else if (typeof handle.expand == 'string') {
let v6 = await _ensureJSROOT();
await v6.require(handle.prereq);
await v6._complete_loading();
if (!internals.ignore_v6) {
let v6 = await _ensureJSROOT();
await v6.require(handle.prereq);
await v6._complete_loading();
}
_item._expand = handle.expand = findFunction(handle.expand);
} else if (typeof handle.get_expand == 'function') {
_item._expand = handle.expand = await handle.get_expand();
Expand Down Expand Up @@ -2653,7 +2655,7 @@ class HierarchyPainter extends BasePainter {
/** @summary method used to request object from the http server
* @returns {Promise} with requested object
* @private */
getOnlineItem(item, itemname, option) {
async getOnlineItem(item, itemname, option) {

let url = itemname, h_get = false, req = "", req_kind = "object", draw_handle = null;

Expand All @@ -2671,7 +2673,12 @@ class HierarchyPainter extends BasePainter {
req = 'h.json?compact=3';
item._expand = onlineHierarchy; // use proper expand function
} else if (item._make_request) {
func = findFunction(item._make_request);
if (item._module) {
let h = await this.importModule(item._module);
func = h[item._make_request];
} else {
func = findFunction(item._make_request);
}
} else if (draw_handle && draw_handle.make_request) {
func = draw_handle.make_request;
}
Expand All @@ -2680,11 +2687,14 @@ class HierarchyPainter extends BasePainter {
// ask to make request
let dreq = func(this, item, url, option);
// result can be simple string or object with req and kind fields
if (dreq!=null)
if (typeof dreq == 'string') req = dreq; else {
if (dreq) {
if (typeof dreq == 'string') {
req = dreq;
} else {
if ('req' in dreq) req = dreq.req;
if ('kind' in dreq) req_kind = dreq.kind;
}
}
}

if ((req.length == 0) && (item._kind.indexOf("ROOT.") != 0))
Expand All @@ -2698,7 +2708,8 @@ class HierarchyPainter extends BasePainter {
return Promise.resolve(obj);
}

if (req.length == 0) req = 'root.json.gz?compact=23';
if (req.length == 0)
req = 'root.json.gz?compact=23';

if (url.length > 0) url += "/";
url += req;
Expand Down Expand Up @@ -2750,15 +2761,17 @@ class HierarchyPainter extends BasePainter {

this.h._expand = onlineHierarchy;

let styles = [], scripts = [], v6_modules = [];
let styles = [], scripts = [], v6_modules = [], v7_imports = [];
this.forEachItem(item => {
if (item._childs !== undefined)
item._expand = onlineHierarchy;

if (item._autoload) {
let arr = item._autoload.split(";");
arr.forEach(name => {
if ((name.length > 3) && (name.lastIndexOf(".js") == name.length-3)) {
if ((name.length > 4) && (name.lastIndexOf(".mjs") == name.length-4)) {
v7_imports.push(this.importModule(name));
} else if ((name.length > 3) && (name.lastIndexOf(".js") == name.length-3)) {
if (!scripts.find(elem => elem == name)) scripts.push(name);
} else if ((name.length > 4) && (name.lastIndexOf(".css") == name.length-4)) {
if (!styles.find(elem => elem == name)) styles.push(name);
Expand All @@ -2771,6 +2784,7 @@ class HierarchyPainter extends BasePainter {

return this.loadScripts(scripts, v6_modules)
.then(() => loadScript(styles))
.then(() => Promise.all(v7_imports))
.then(() => {
this.forEachItem(item => {
if (!('_drawfunc' in item) || !('_kind' in item)) return;
Expand Down Expand Up @@ -3104,6 +3118,9 @@ class HierarchyPainter extends BasePainter {
if (!scripts?.length && !modules?.length)
return Promise.resolve(true);

if (internals.ignore_v6)
return loadScript(scripts);

return _ensureJSROOT().then(v6 => {
return v6.require(modules)
.then(() => loadScript(scripts))
Expand Down Expand Up @@ -3297,7 +3314,7 @@ class HierarchyPainter extends BasePainter {

let h0 = null;
if (this.is_online) {
let func = internals.GetCachedHierarchy || findFunction('GetCachedHierarchy');
let func = internals.getCachedHierarchy || findFunction('GetCachedHierarchy');
if (typeof func == 'function')
h0 = func();
if (typeof h0 !== 'object') h0 = "";
Expand Down
2 changes: 2 additions & 0 deletions js/modules/hist/bundle.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Plain histogram drawing without support of generic draw function

export { version, parse } from "../core.mjs";

export { cleanup } from "../base/ObjectPainter.mjs";
Expand Down
8 changes: 4 additions & 4 deletions js/modules/hist2d/THistPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ensureTCanvas } from '../gpad/TCanvasPainter.mjs';

const CoordSystem = { kCARTESIAN: 1, kPOLAR: 2, kCYLINDRICAL: 3, kSPHERICAL: 4, kRAPIDITY: 5 };

const createDefaultPalette = () => {
function createDefaultPalette() {
const hue2rgb = (p, q, t) => {
if (t < 0) t += 1;
if (t > 1) t -= 1;
Expand All @@ -38,16 +38,16 @@ const createDefaultPalette = () => {
palette.push(HLStoRGB(hue, 0.5, 1));
}
return new ColorPalette(palette);
};
}

const createGrayPalette = () => {
function createGrayPalette() {
let palette = [];
for (let i = 0; i < 50; ++i) {
const code = toHex((i+2)/60);
palette.push('#'+code+code+code);
}
return new ColorPalette(palette);
};
}

/** @summary Create color palette
* @private */
Expand Down
2 changes: 2 additions & 0 deletions js/modules/hist2d/bundle.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Only 2D histograms drawing without support of generic draw function

export { version, parse } from "../core.mjs";

export { cleanup } from "../base/ObjectPainter.mjs";
Expand Down
16 changes: 13 additions & 3 deletions js/modules/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@

export * from './core.mjs';

export { drawingJSON, cleanup, resize } from './base/ObjectPainter.mjs';
export { select as d3_select } from './d3.mjs';

export * from './base/BasePainter.mjs';

export * from './base/ObjectPainter.mjs';

export * from './hist/TH1Painter.mjs';

export * from './hist/TH2Painter.mjs';

export * from './hist/TH3Painter.mjs';

export { loadOpenui5, registerForResize } from './gui/utils.mjs';

export { draw, redraw, makeSVG, setDefaultDrawOpt } from './draw.mjs';
export { draw, redraw, makeSVG, addDrawFunc, setDefaultDrawOpt } from './draw.mjs';

export { openFile } from './io.mjs';

export { GridDisplay, FlexibleDisplay, CustomDisplay, BatchDisplay } from './gui/display.mjs';
export * from './gui/display.mjs';

export { HierarchyPainter, getHPainter } from './gui/HierarchyPainter.mjs';

Expand Down

0 comments on commit e505630

Please sign in to comment.