Skip to content

Commit

Permalink
Build with TPaveText border drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
linev committed Nov 22, 2024
1 parent f23d642 commit 5bc02fe
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 79 deletions.
153 changes: 75 additions & 78 deletions build/jsroot.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const version_id = 'dev',

/** @summary version date
* @desc Release date in format day/month/year like '14/04/2022' */
version_date = '21/11/2024',
version_date = '22/11/2024',

/** @summary version id and date
* @desc Produced by concatenation of {@link version_id} and {@link version_date}
Expand Down Expand Up @@ -63129,11 +63129,11 @@ class TAxisPainter extends ObjectPainter {
const gr_range = Math.abs(this.func.range()[1] - this.func.range()[0]);

// avoid black filling by middle-size
if ((handle.middle.length <= handle.major.length) || (handle.middle.length > gr_range/3.5))
if ((handle.middle.length <= handle.major.length) || (handle.middle.length > gr_range))
handle.minor = handle.middle = handle.major;
else if ((this.nticks3 > 1) && !this.log) {
handle.minor = this.produceTicks(handle.middle.length, this.nticks3);
if ((handle.minor.length <= handle.middle.length) || (handle.minor.length > gr_range/1.7))
if ((handle.minor.length <= handle.middle.length) || (handle.minor.length > gr_range))
handle.minor = handle.middle;
}
}
Expand Down Expand Up @@ -70619,7 +70619,7 @@ class TPadPainter extends ObjectPainter {

const mainid = this.selectDom().attr('id');

if (!this.isBatchMode() && !this.use_openui && !this.brlayout && mainid && isStr(mainid)) {
if (!this.isBatchMode() && !this.use_openui && !this.brlayout && mainid && isStr(mainid) && !getHPainter()) {
this.brlayout = new BrowserLayout(mainid, null, this);
this.brlayout.create(mainid, true);
this.setDom(this.brlayout.drawing_divid()); // need to create canvas
Expand Down Expand Up @@ -72588,13 +72588,8 @@ class TPavePainter extends ObjectPainter {
const h2 = Math.round(height/2), w2 = Math.round(width/2),
dpath = `l${w2},${-h2}l${w2},${h2}l${-w2},${h2}z`;

if ((brd > 1) && (pt.fShadowColor > 0) && (dx || dy) && !this.fillatt.empty() && !noborder) {
this.draw_g.append('svg:path')
.attr('d', 'M0,'+(h2+brd) + dpath)
.style('fill', this.getColor(pt.fShadowColor))
.style('stroke', this.getColor(pt.fShadowColor))
.style('stroke-width', '1px');
}
if (!this.fillatt.empty())
this.drawBorder(this.draw_g, width, height, dpath);

interactive_element = this.draw_g.append('svg:path')
.attr('d', 'M0,'+h2 +dpath)
Expand All @@ -72606,26 +72601,8 @@ class TPavePainter extends ObjectPainter {

return this.drawPaveText(w2, h2, arg, text_g);
} else {
// add shadow decoration before main rect
if ((brd > 1) && (pt.fShadowColor > 0) && !pt.fNpaves && (dx || dy) && !noborder) {
const scol = this.getColor(pt.fShadowColor);
let spath = '';

if ((dx < 0) && (dy < 0))
spath = `M0,0v${height-brd}h${-brd}v${-height}h${width}v${brd}z`;
else if ((dx < 0) && (dy > 0))
spath = `M0,${height}v${brd-height}h${-brd}v${height}h${width}v${-brd}z`;
else if ((dx > 0) && (dy < 0))
spath = `M${brd},0v${-brd}h${width}v${height}h${-brd}v${brd-height}z`;
else
spath = `M${width},${brd}h${brd}v${height}h${-width}v${-brd}h${width-brd}z`;

this.draw_g.append('svg:path')
.attr('d', spath)
.style('fill', scol)
.style('stroke', scol)
.style('stroke-width', '1px');
}
if (!pt.fNpaves)
this.drawBorder(this.draw_g, width, height);

if (pt.fNpaves) {
for (let n = pt.fNpaves-1; n > 0; --n) {
Expand Down Expand Up @@ -72669,6 +72646,45 @@ class TPavePainter extends ObjectPainter {
});
}

drawBorder(draw_g, width, height, diamond) {
const pt = this.getObject(),
opt = pt.fOption.toUpperCase(),
noborder = opt.indexOf('NB') >= 0,
dx = (opt.indexOf('L') >= 0) ? -1 : ((opt.indexOf('R') >= 0) ? 1 : 0),
dy = (opt.indexOf('T') >= 0) ? -1 : ((opt.indexOf('B') >= 0) ? 1 : 0);

if ((pt.fBorderSize < 2) || (pt.fShadowColor === 0) || (!dx && !dy) || noborder)
return;

const scol = this.getColor(pt.fShadowColor),
brd = pt.fBorderSize;

if (diamond) {
draw_g.append('svg:path')
.attr('d', `M0,${Math.round(height/2)+brd}${diamond}`)
.style('fill', scol)
.style('stroke', scol)
.style('stroke-width', '1px');
} else {
let spath = '';

if ((dx < 0) && (dy < 0))
spath = `M0,0v${height-brd-1}h${-brd+1}v${-height+2}h${width-2}v${brd-1}z`;
else if ((dx < 0) && (dy > 0))
spath = `M0,${height}v${brd+1-height}h${-brd+1}v${height-2}h${width-2}v${-brd+1}z`;
else if ((dx > 0) && (dy < 0))
spath = `M${brd+1},0v${-brd+1}h${width-2}v${height-2}h${-brd+1}v${brd+1-height}z`;
else
spath = `M${width},${brd+1}h${brd-1}v${height-2}h${-width+2}v${-brd+1}h${width-brd-2}z`;

draw_g.append('svg:path')
.attr('d', spath)
.style('fill', scol)
.style('stroke', scol)
.style('stroke-width', '1px');
}
}

/** @summary Fill option object used in TWebCanvas */
fillWebObjectOptions(res) {
const pave = this.getObject();
Expand Down Expand Up @@ -72918,25 +72934,31 @@ class TPavePainter extends ObjectPainter {
if (this.isTitle())
this.draw_g.style('display', !num_txt ? 'none' : null);

if (draw_header) {
const x = Math.round(width*0.25),
y = Math.round(-height*0.02),

return Promise.all(promises).then(() => this);
}).then(() => {

if (!draw_header)
return;

const x = Math.round(width*0.25),
y = Math.round(-pad_height*0.02),
w = Math.round(width*0.5),
h = Math.round(height*0.04),
lbl_g = text_g.append('svg:g');
h = Math.round(pad_height*0.04),
lbl_g = text_g.append('svg:g').attr('transform', makeTranslate(x,y));

lbl_g.append('svg:path')
.attr('d', `M${x},${y}h${w}v${h}h${-w}z`)
.call(this.fillatt.func)
.call(this.lineatt.func);
this.drawBorder(lbl_g, w, h);

promises.push(this.startTextDrawingAsync(this.textatt.font, h/1.5, lbl_g)
.then(() => this.drawText({ align: 22, x, y, width: w, height: h, text: pt.fLabel, color: this.textatt.color, draw_g: lbl_g }))
.then(() => promises.push(this.finishTextDrawing(lbl_g))));
}
lbl_g.append('svg:path')
.attr('d', `M${0},${0}h${w}v${h}h${-w}z`)
.call(this.fillatt.func)
.call(this.lineatt.func);

return Promise.all(promises).then(() => this);
});
return this.startTextDrawingAsync(this.textatt.font, 0.9*h, lbl_g)
.then(() => this.drawText({ align: 22, x: 0, y: 0, width: w, height: h, text: pt.fLabel, color: this.textatt.color, draw_g: lbl_g }))
.then(() => promises.push(this.finishTextDrawing(lbl_g)));

}).then(() => { return this; })
}

/** @summary Method used to convert value to string according specified format
Expand All @@ -72954,14 +72976,9 @@ class TPavePainter extends ObjectPainter {
return value.toFixed(0);
fmt = '14.7g';
break;
case 'last': fmt = this.lastformat; break;
}

const res = floatToString(value, fmt || '6.4g', true);

this.lastformat = res[1];

return res[0];
return floatToString(value, fmt || '6.4g');
}

/** @summary Draw TLegend object */
Expand Down Expand Up @@ -73607,7 +73624,6 @@ class TPavePainter extends ObjectPainter {
return `.${tv.length-id-1}f`;
}


/** @summary Fill function parameters */
fillFunctionStat(f1, dofit, ndim = 1) {
this._has_fit = false;
Expand Down Expand Up @@ -147427,7 +147443,6 @@ async function drawText$1() {

if ((text._typename === clTLatex) || annot) {
arg.latex = 1;
fact = 0.9;
} else if (text._typename === clTMathText) {
arg.latex = 2;
fact = 0.8;
Expand Down Expand Up @@ -155987,8 +156002,8 @@ class TGaxisPainter extends TAxisPainter {
});
}

/** @summary Fill TGaxis context */
fillContextMenu(menu) {
/** @summary Fill TGaxis context menu items */
fillContextMenuItems(menu) {
menu.addTAxisMenu(EAxisBits, this, this.getObject(), '');
}

Expand Down Expand Up @@ -157232,11 +157247,12 @@ class RAxisPainter extends RObjectPainter {
const gr_range = Math.abs(this.func.range()[1] - this.func.range()[0]);

// avoid black filling by middle-size
if ((handle.middle.length <= handle.major.length) || (handle.middle.length > gr_range/3.5))
if ((handle.middle.length <= handle.major.length) || (handle.middle.length > gr_range))
handle.minor = handle.middle = handle.major;
else if ((this.nticks3 > 1) && !this.log) {
handle.minor = this.produceTicks(handle.middle.length, this.nticks3);
if ((handle.minor.length <= handle.middle.length) || (handle.minor.length > gr_range/1.7)) handle.minor = handle.middle;
if ((handle.minor.length <= handle.middle.length) || (handle.minor.length > gr_range))
handle.minor = handle.middle;
}
}

Expand Down Expand Up @@ -160455,7 +160471,7 @@ class RPadPainter extends RObjectPainter {

const mainid = this.selectDom().attr('id');

if (!this.isBatchMode() && !this.use_openui && !this.brlayout && mainid && isStr(mainid)) {
if (!this.isBatchMode() && !this.use_openui && !this.brlayout && mainid && isStr(mainid) && !getHPainter()) {
this.brlayout = new BrowserLayout(mainid, null, this);
this.brlayout.create(mainid, true);
this.setDom(this.brlayout.drawing_divid()); // need to create canvas
Expand Down Expand Up @@ -162602,25 +162618,6 @@ class RHistStatsPainter extends RPavePainter {
return (this.stats_lines !== undefined);
}

/** @summary format float value as string
* @private */
format(value, fmt) {
if (!fmt) fmt = 'stat';

switch (fmt) {
case 'stat' : fmt = gStyle.fStatFormat; break;
case 'fit': fmt = gStyle.fFitFormat; break;
case 'entries': if ((Math.abs(value) < 1e9) && (Math.round(value) === value)) return value.toFixed(0); fmt = '14.7g'; break;
case 'last': fmt = this.lastformat; break;
}

const res = floatToString(value, fmt || '6.4g', true);

this.lastformat = res[1];

return res[0];
}

/** @summary Draw content */
async drawContent() {
if (this.fillStatistic())
Expand Down
2 changes: 1 addition & 1 deletion modules/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const version_id = 'dev',

/** @summary version date
* @desc Release date in format day/month/year like '14/04/2022' */
version_date = '21/11/2024',
version_date = '22/11/2024',

/** @summary version id and date
* @desc Produced by concatenation of {@link version_id} and {@link version_date}
Expand Down

0 comments on commit 5bc02fe

Please sign in to comment.