Skip to content

Commit

Permalink
Declare and use prJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
linev committed Sep 2, 2024
1 parent a669adb commit bed074e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions modules/base/BasePainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { getColor } from './colors.mjs';

/** @summary Standard prefix for SVG file context as data url
* @private */
const prSVG = 'data:image/svg+xml;charset=utf-8,';
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
Expand Down Expand Up @@ -957,6 +961,6 @@ function convertDate(dt) {
return res || dt.toLocaleString('en-GB');
}

export { prSVG, getElementRect, getAbsPosInCanvas, getTDatime, convertDate,
export { prSVG, prJSON, getElementRect, getAbsPosInCanvas, getTDatime, convertDate,
DrawOptions, TRandom, floatToString, buildSvgCurve, compressSVG,
BasePainter, _loadJSDOM, makeTranslate, addHighlightStyle, svgToImage };
4 changes: 2 additions & 2 deletions modules/gpad/TPadPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { gStyle, settings, constants, browser, internals, BIT,
import { select as d3_select, rgb as d3_rgb } from '../d3.mjs';
import { ColorPalette, adoptRootColors, getColorPalette, getGrayColors, extendRootColors,
getRGBfromTColor, decodeWebCanvasColors } from '../base/colors.mjs';
import { prSVG, getElementRect, getAbsPosInCanvas, DrawOptions, compressSVG, makeTranslate,
import { prSVG, prJSON, getElementRect, getAbsPosInCanvas, DrawOptions, compressSVG, makeTranslate,
getTDatime, convertDate, svgToImage } from '../base/BasePainter.mjs';
import { ObjectPainter, selectActivePad, getActivePad } from '../base/ObjectPainter.mjs';
import { TAttLineHandler } from '../base/TAttLineHandler.mjs';
Expand Down Expand Up @@ -2234,7 +2234,7 @@ class TPadPainter extends ObjectPainter {
if (res)
this.getCanvPainter()?.sendWebsocket(`SAVE:${filename}:${res}`);
} else {
const prefix = (kind === 'svg') ? prSVG : (kind === 'json' ? 'data:application/json;charset=utf-8,' : '');
const prefix = (kind === 'svg') ? prSVG : (kind === 'json' ? prJSON : '');
saveFile(filename, prefix ? prefix + encodeURIComponent(imgdata) : imgdata);
}
});
Expand Down
4 changes: 2 additions & 2 deletions modules/gui/HierarchyPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { version, gStyle, httpRequest, create, createHttpRequest, loadScript, lo
import { select as d3_select } from '../d3.mjs';
import { openFile, kBaseClass, clTStreamerInfoList, clTDirectory, clTDirectoryFile, nameStreamerInfo, addUserStreamer } from '../io.mjs';
import { getRGBfromTColor } from '../base/colors.mjs';
import { BasePainter, getElementRect, _loadJSDOM, getTDatime, convertDate } from '../base/BasePainter.mjs';
import { prJSON, BasePainter, getElementRect, _loadJSDOM, getTDatime, convertDate } from '../base/BasePainter.mjs';
import { getElementMainPainter, getElementCanvPainter, cleanup, ObjectPainter } from '../base/ObjectPainter.mjs';
import { createMenu } from './menu.mjs';
import { getDrawSettings, getDrawHandle, canDrawHandle, addDrawFunc, draw, redraw } from '../draw.mjs';
Expand Down Expand Up @@ -3993,7 +3993,7 @@ async function drawInspector(dom, obj, opt) {
painter.storeAsJson = function() {
const json = toJSON(obj, 2),
fname = obj.fName || 'file';
saveFile(`${fname}.json`, 'data:application/json;charset=utf-8,' + encodeURIComponent(json));
saveFile(`${fname}.json`, prJSON + encodeURIComponent(json));
};
}
}
Expand Down

0 comments on commit bed074e

Please sign in to comment.