Skip to content

Commit

Permalink
[jsroot] dev 27/11/2024 with TGraphPolar cahnges
Browse files Browse the repository at this point in the history
Support new 'R', 'G', 'D' draw option
Handle 'N' and 'O' draw option for TGraphPolargram
  • Loading branch information
linev committed Nov 28, 2024
1 parent ae892dc commit 7f3ae20
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 83 deletions.
125 changes: 84 additions & 41 deletions js/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 = '26/11/2024',
version_date = '27/11/2024',

/** @summary version id and date
* @desc Produced by concatenation of {@link version_id} and {@link version_date}
Expand Down Expand Up @@ -152479,12 +152479,13 @@ class TGraphPolargramPainter extends ObjectPainter {
/** @summary Create painter
* @param {object|string} dom - DOM element for drawing or element id
* @param {object} polargram - object to draw */
constructor(dom, polargram) {
super(dom, polargram);
constructor(dom, polargram, opt) {
super(dom, polargram, opt);
this.$polargram = true; // indicate that this is polargram
this.zoom_rmin = this.zoom_rmax = 0;
this.t0 = 0;
this.mult = 1;
this.decodeOptions(opt);
}

/** @summary Returns true if fixed coordinates are configured */
Expand All @@ -152493,6 +152494,21 @@ class TGraphPolargramPainter extends ObjectPainter {
return polar?.fRadian || polar?.fGrad || polar?.fDegree;
}

/** @summary Decode draw options */
decodeOptions(opt) {
const d = new DrawOptions(opt);

if (!this.options)
this.options = {};

Object.assign(this.options, {
NoLabels: d.check('N'),
OrthoLabels: d.check('O')
});

this.storeDrawOpt(opt);
}

/** @summary Set angles range displayed by the polargram */
setAnglesRange(tmin, tmax, set_obj) {
if (tmin >= tmax)
Expand Down Expand Up @@ -152528,7 +152544,6 @@ class TGraphPolargramPainter extends ObjectPainter {
format(radius) {
if (radius === Math.round(radius)) return radius.toString();
if (this.ndig > 10) return radius.toExponential(4);

return radius.toFixed((this.ndig > 0) ? this.ndig : 0);
}

Expand Down Expand Up @@ -152562,10 +152577,10 @@ class TGraphPolargramPainter extends ObjectPainter {
rect.szy = Math.round(0.5*h);
}

rect.width = 2*rect.szx;
rect.height = 2*rect.szy;
rect.x = Math.round(w/2 - rect.szx);
rect.y = Math.round(h/2 - rect.szy);
rect.width = 2 * rect.szx;
rect.height = 2 * rect.szy;
rect.x = Math.round(w / 2 - rect.szx);
rect.y = Math.round(h / 2 - rect.szy);

rect.hint_delta_x = rect.szx;
rect.hint_delta_y = rect.szy;
Expand Down Expand Up @@ -152621,6 +152636,44 @@ class TGraphPolargramPainter extends ObjectPainter {
}
}

/** @summary Draw polargram polar labels */
async drawPolarLabels(polar, nmajor) {
const fontsize = Math.round(polar.fPolarTextSize * this.szy * 2);

return this.startTextDrawingAsync(polar.fPolarLabelFont, fontsize)
.then(() => {
const lbls = (nmajor === 8) ? ['0', '#frac{#pi}{4}', '#frac{#pi}{2}', '#frac{3#pi}{4}', '#pi', '#frac{5#pi}{4}', '#frac{3#pi}{2}', '#frac{7#pi}{4}'] : ['0', '#frac{2#pi}{3}', '#frac{4#pi}{3}'],
aligns = [12, 11, 21, 31, 32, 33, 23, 13];

for (let n = 0; n < nmajor; ++n) {
const angle = -n*2*Math.PI/nmajor;
this.draw_g.append('svg:path')
.attr('d', `M0,0L${Math.round(this.szx*Math.cos(angle))},${Math.round(this.szy*Math.sin(angle))}`)
.call(this.lineatt.func);

let align = 12, rotate = 0;

if (this.options.OrthoLabels) {
rotate = -n/nmajor*360;
if ((rotate > -271) && (rotate < -91)) {
align = 32; rotate += 180;
}
} else {
const aindx = Math.round(16 - angle/Math.PI*4) % 8; // index in align table, here absolute angle is important
align = aligns[aindx];
}

this.drawText({ align, rotate,
x: Math.round((this.szx + fontsize)*Math.cos(angle)),
y: Math.round((this.szy + fontsize/this.szx*this.szy)*(Math.sin(angle))),
text: lbls[n],
color: this.getColor(polar.fPolarLabelColor), latex: 1 });
}

return this.finishTextDrawing();
});
}

/** @summary Redraw polargram */
async redraw() {
if (!this.isMainPainter())
Expand Down Expand Up @@ -152654,8 +152707,7 @@ class TGraphPolargramPainter extends ObjectPainter {

this.setAnglesRange(polar.fRwtmin, polar.fRwtmax);

const ticks = this.r.ticks(5),
fontsize = Math.round(polar.fPolarTextSize * this.szy * 2);
const ticks = this.r.ticks(5);
let nminor = Math.floor((polar.fNdivRad % 10000) / 100),
nmajor = polar.fNdivPol % 100;
if (nmajor !== 3)
Expand Down Expand Up @@ -152683,7 +152735,7 @@ class TGraphPolargramPainter extends ObjectPainter {
let exclude_last = false;
const pointer_events = this.isBatchMode() ? null : 'visibleFill';

if ((ticks[ticks.length-1] < polar.fRwrmax) && (this.zoom_rmin === this.zoom_rmax)) {
if ((ticks[ticks.length - 1] < polar.fRwrmax) && (this.zoom_rmin === this.zoom_rmax)) {
ticks.push(polar.fRwrmax);
exclude_last = true;
}
Expand Down Expand Up @@ -152727,32 +152779,12 @@ class TGraphPolargramPainter extends ObjectPainter {

return this.finishTextDrawing();
}).then(() => {
return this.startTextDrawingAsync(polar.fPolarLabelFont, fontsize);
}).then(() => {
lbls = (nmajor === 8) ? ['0', '#frac{#pi}{4}', '#frac{#pi}{2}', '#frac{3#pi}{4}', '#pi', '#frac{5#pi}{4}', '#frac{3#pi}{2}', '#frac{7#pi}{4}'] : ['0', '#frac{2#pi}{3}', '#frac{4#pi}{3}'];
const aligns = [12, 11, 21, 31, 32, 33, 23, 13];

for (let n = 0; n < nmajor; ++n) {
const angle = -n*2*Math.PI/nmajor;
this.draw_g.append('svg:path')
.attr('d', `M0,0L${Math.round(this.szx*Math.cos(angle))},${Math.round(this.szy*Math.sin(angle))}`)
.call(this.lineatt.func);

const aindx = Math.round(16 -angle/Math.PI*4) % 8; // index in align table, here absolute angle is important

this.drawText({ align: aligns[aindx],
x: Math.round((this.szx+fontsize)*Math.cos(angle)),
y: Math.round((this.szy + fontsize/this.szx*this.szy)*(Math.sin(angle))),
text: lbls[n],
color: this.getColor(polar.fPolarLabelColor), latex: 1 });
}

return this.finishTextDrawing();
return this.options.NoLabels ? true : this.drawPolarLabels(polar, nmajor);
}).then(() => {
nminor = Math.floor((polar.fNdivPol % 10000) / 100);

if (nminor > 1) {
for (let n = 0; n < nmajor*nminor; ++n) {
for (let n = 0; n < nmajor * nminor; ++n) {
if (n % nminor === 0) continue;
const angle = -n*2*Math.PI/nmajor/nminor;
this.draw_g.append('svg:path')
Expand Down Expand Up @@ -152794,15 +152826,15 @@ class TGraphPolargramPainter extends ObjectPainter {
}

/** @summary Draw TGraphPolargram */
static async draw(dom, polargram /* , opt */) {
static async draw(dom, polargram, opt) {
const main = getElementMainPainter(dom);
if (main) {
if (main.getObject() === polargram)
return main;
throw Error('Cannot superimpose TGraphPolargram with any other drawings');
}

const painter = new TGraphPolargramPainter(dom, polargram);
const painter = new TGraphPolargramPainter(dom, polargram, opt);
return ensureTCanvas(painter, false).then(() => {
painter.setAsMainPainter();
return painter.redraw();
Expand Down Expand Up @@ -152832,11 +152864,15 @@ class TGraphPolarPainter extends ObjectPainter {
err: d.check('E'),
fill: d.check('F'),
line: d.check('L'),
curve: d.check('C')
curve: d.check('C'),
radian: d.check('R'),
degree: d.check('D'),
grad: d.check('G'),
Axis: d.check('N') ? 'N' : ''
});

if (d.check('A'))
this._draw_axis = true;
if (d.check('O'))
this.options.Axis += 'O';

this.storeDrawOpt(opt);
}
Expand Down Expand Up @@ -152969,8 +153005,15 @@ class TGraphPolarPainter extends ObjectPainter {

/** @summary Create polargram object */
createPolargram(gr) {
if (!gr.fPolargram)
if (!gr.fPolargram) {
gr.fPolargram = create$1('TGraphPolargram');
if (this.options.radian)
gr.fPolargram.fRadian = true;
else if (this.options.degree)
gr.fPolargram.fDegree = true;
else if (this.options.grad)
gr.fPolargram.fGrad = true;
}

let rmin = gr.fY[0] || 0, rmax = rmin;
const has_err = gr.fEY?.length;
Expand Down Expand Up @@ -153124,7 +153167,7 @@ class TGraphPolarPainter extends ObjectPainter {

/** @summary Draw TGraphPolar */
static async draw(dom, graph, opt) {
const painter = new TGraphPolarPainter(dom, graph);
const painter = new TGraphPolarPainter(dom, graph, opt);
painter.decodeOptions(opt);

const main = painter.getMainPainter();
Expand All @@ -153137,7 +153180,7 @@ class TGraphPolarPainter extends ObjectPainter {
if (!main) {
// indicate that axis defined by this graph
painter._draw_axis = true;
pr = TGraphPolargramPainter.draw(dom, painter.createPolargram(graph));
pr = TGraphPolargramPainter.draw(dom, painter.createPolargram(graph), painter.options.Axis);
}

return pr.then(gram_painter => {
Expand Down
2 changes: 1 addition & 1 deletion js/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
1. Adjust histogram title drawing with native implementation
1. Improve float to string convertion when 'g' is specified
1. Support "same" option for first histogram, draw direcly on pad
1. Support different angle coordiantes in `TGraphPolargram`
1. Support different angle coordiantes in `TGraphPolargram`, handle 'N' and 'O' draw options
1. Fix - handle `TPave` NDC position also when fInit is not set
1. Fix - correctly position title according to gStyle->GetTitleAlign()
1. Fix - correctly handle tooltip events for `TGraphPolar`
Expand Down
2 changes: 1 addition & 1 deletion js/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 = '26/11/2024',
version_date = '27/11/2024',

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

0 comments on commit 7f3ae20

Please sign in to comment.