Skip to content

Commit

Permalink
Let store JSON with and without line spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
linev committed Sep 2, 2024
1 parent c0e35e9 commit eafdc82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions modules/gpad/TCanvasPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ class TCanvasPainter extends TPadPainter {
}

/** @summary produce JSON for TCanvas, which can be used to display canvas once again */
produceJSON() {
produceJSON(spacing) {
const canv = this.getObject(),
fill0 = (canv.fFillStyle === 0),
axes = [], hists = [];
Expand Down Expand Up @@ -817,7 +817,7 @@ class TCanvasPainter extends TPadPainter {
// const fp = this.getFramePainter();
// fp?.setRootPadRange(this.getRootPad());

const res = toJSON(canv);
const res = toJSON(canv, spacing);

if (fill0) canv.fFillStyle = 0;

Expand Down
11 changes: 7 additions & 4 deletions modules/gpad/TPadPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,9 +1340,12 @@ class TPadPainter extends ObjectPainter {

const fname = this.this_pad_name || (this.iscan ? 'canvas' : 'pad');
menu.sub('Save as');
const formats = ['svg', 'png', 'jpeg', 'pdf', 'webp'];
if (this.iscan) formats.push('json');
formats.forEach(fmt => menu.add(`${fname}.${fmt}`, () => this.saveAs(fmt, this.iscan, `${fname}.${fmt}`)));
['svg', 'png', 'jpeg', 'pdf', 'webp'].forEach(fmt => menu.add(`${fname}.${fmt}`, () => this.saveAs(fmt, this.iscan, `${fname}.${fmt}`)));
if (this.iscan) {
menu.separator();
menu.add(`${fname}.json`, () => this.saveAs('json', true, `${fname}.json`), 'Produce JSON with line spacing');
menu.add(`${fname}0.json`, () => this.saveAs('json', false, `${fname}0.json`), 'Produce JSON without line spacing');
}
menu.endsub();

return true;
Expand Down Expand Up @@ -2252,7 +2255,7 @@ class TPadPainter extends ObjectPainter {
* @return {Promise} with created image */
async produceImage(full_canvas, file_format) {
if (file_format === 'json')
return isFunc(this.produceJSON) ? this.produceJSON() : '';
return isFunc(this.produceJSON) ? this.produceJSON(full_canvas ? 2 : 0) : '';

const use_frame = (full_canvas === 'frame'),
elem = use_frame ? this.getFrameSvg(this.this_pad_name) : (full_canvas ? this.getCanvSvg() : this.svg_this_pad()),
Expand Down

0 comments on commit eafdc82

Please sign in to comment.