From 348de0d431aadc91e8ae52d6daf84ffbad2794c3 Mon Sep 17 00:00:00 2001 From: Sergey Linev Date: Mon, 2 Sep 2024 15:54:22 +0200 Subject: [PATCH] Build with save json from inspector --- build/jsroot.js | 38 ++++++++++++++++++++++++++++++-------- changes.md | 2 +- modules/gui/utils.mjs | 2 +- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/build/jsroot.js b/build/jsroot.js index 20f7d5c63..a843cd073 100644 --- a/build/jsroot.js +++ b/build/jsroot.js @@ -10117,6 +10117,14 @@ function decodeWebCanvasColors(oper) { createRootColors(); +/** @summary Standard prefix for SVG file context as data url + * @private */ +const prSVG = 'data:image/svg+xml;charset=utf-8,', +/** @summary Standard prefix for JSON file context as data url + * @private */ + prJSON = 'data:application/json;charset=utf-8,'; + + /** @summary Returns visible rect of element * @param {object} elem - d3.select object with element * @param {string} [kind] - which size method is used @@ -10998,7 +11006,7 @@ async function svgToImage(svg, image_format, as_buffer) { }); svg = decodeURIComponent(svg); - const img_src = 'data:image/svg+xml;base64,' + btoa_func(svg); + const img_src = prSVG + btoa_func(svg); if (isNodeJs()) { return Promise.resolve().then(function () { return _rollup_plugin_ignore_empty_module_placeholder$1; }).then(async handle => { @@ -57577,7 +57585,7 @@ class PointsCreator { imgdata = '' + ``+ '', - dataUrl = 'data:image/svg+xml;charset=utf8,' + (isNodeJs() ? imgdata : encodeURIComponent(imgdata)); + dataUrl = prSVG + (isNodeJs() ? imgdata : encodeURIComponent(imgdata)); let promise; if (isNodeJs()) { @@ -60306,10 +60314,8 @@ let _saveFileFunc = null; * @private */ function getBinFileContent(content) { - const svg_prefix = 'data:image/svg+xml;charset=utf-8,'; - - if (content.indexOf(svg_prefix) === 0) - return decodeURIComponent(content.slice(svg_prefix.length)); + if (content.indexOf(prSVG) === 0) + return decodeURIComponent(content.slice(prSVG.length)); if (content.indexOf('data:image/') === 0) { const p = content.indexOf('base64,'); @@ -70453,7 +70459,7 @@ class TPadPainter extends ObjectPainter { if (res) this.getCanvPainter()?.sendWebsocket(`SAVE:${filename}:${res}`); } else { - const prefix = (kind === 'svg') ? 'data:image/svg+xml;charset=utf-8,' : (kind === 'json' ? 'data:application/json;charset=utf-8,' : ''); + const prefix = (kind === 'svg') ? prSVG : (kind === 'json' ? prJSON : ''); saveFile(filename, prefix ? prefix + encodeURIComponent(imgdata) : imgdata); } }); @@ -105766,6 +105772,12 @@ class HierarchyPainter extends BasePainter { d3btns.append('a').attr('class', 'h_button').text('collapse all') .attr('title', 'collapse all items in the browser').on('click', () => this.toggleOpenState(false)); + if (isFunc(this.storeAsJson)) { + d3btns.append('text').text(' | '); + d3btns.append('a').attr('class', 'h_button').text('json') + .attr('title', 'dump to json file').on('click', () => this.storeAsJson()); + } + if (isFunc(this.removeInspector)) { d3btns.append('text').text(' | '); d3btns.append('a').attr('class', 'h_button').text('remove') @@ -108336,6 +108348,14 @@ async function drawInspector(dom, obj, opt) { painter.removeInspector = function() { this.selectDom().remove(); }; + + if (!browser.qt5 && !browser.qt6 && !browser.cef3) { + painter.storeAsJson = function() { + const json = toJSON(obj, 2), + fname = obj.fName || 'file'; + saveFile(`${fname}.json`, prJSON + encodeURIComponent(json)); + }; + } } painter.fill_context = function(menu, hitem) { @@ -121467,7 +121487,7 @@ class RPadPainter extends RObjectPainter { if (res) this.getCanvPainter()?.sendWebsocket(`SAVE:${filename}:${res}`); } else - saveFile(filename, (kind !== 'svg') ? imgdata : 'data:image/svg+xml;charset=utf-8,'+encodeURIComponent(imgdata)); + saveFile(filename, (kind !== 'svg') ? imgdata : prSVG + encodeURIComponent(imgdata)); }); } @@ -127697,7 +127717,9 @@ exports.openFile = openFile; exports.parse = parse; exports.parseMulti = parseMulti; exports.postponePromise = postponePromise; +exports.prJSON = prJSON; exports.prROOT = prROOT; +exports.prSVG = prSVG; exports.readStyleFromURL = readStyleFromURL; exports.redraw = redraw; exports.registerForResize = registerForResize; diff --git a/changes.md b/changes.md index f4a4a88c7..a20a4af7a 100644 --- a/changes.md +++ b/changes.md @@ -22,7 +22,7 @@ 19. Support inject of ES6 modules via '&inject=path.mjs' 20. Using importmap for 'jsroot' in all major HTML files and in demos 21. Implement `settings.CutAxisLabels` flag to remove labels which may exceed graphical range -22. Let save canvas as JSON file from context menu +22. Let save canvas as JSON file from context menu, object as JSON from inspector 23. Fix - properly save zoomed ranges in drawingJSON() 24. Fix - properly redraw TMultuGraph 25. Fix - show empty bin in TProfile2D if it has entries #316 diff --git a/modules/gui/utils.mjs b/modules/gui/utils.mjs index df7b902de..f7c7dc0d0 100644 --- a/modules/gui/utils.mjs +++ b/modules/gui/utils.mjs @@ -1,6 +1,6 @@ import { settings, internals, browser, gStyle, isBatchMode, isNodeJs, isObject, isFunc, isStr, source_dir, atob_func, btoa_func } from '../core.mjs'; import { select as d3_select, pointer as d3_pointer, drag as d3_drag, color as d3_color } from '../d3.mjs'; -import { BasePainter } from '../base/BasePainter.mjs'; +import { prSVG, BasePainter } from '../base/BasePainter.mjs'; import { resize } from '../base/ObjectPainter.mjs'; import { getRootColors } from '../base/colors.mjs';