Skip to content

Commit

Permalink
Support 'O' option for TGraphPolargram
Browse files Browse the repository at this point in the history
  • Loading branch information
linev committed Nov 27, 2024
1 parent ac883c7 commit e647424
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions modules/draw/TGraphPolarPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TGraphPolargramPainter extends ObjectPainter {
this.zoom_rmin = this.zoom_rmax = 0;
this.t0 = 0;
this.mult = 1;
this.options = { NoLabels: opt === 'N '}
this.decodeOptions(opt);
}

/** @summary Returns true if fixed coordinates are configured */
Expand All @@ -34,6 +34,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 @@ -176,9 +191,19 @@ class TGraphPolargramPainter extends ObjectPainter {
.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
let align = 12, rotate = 0;

this.drawText({ align: aligns[aindx],
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],
Expand Down Expand Up @@ -386,6 +411,9 @@ class TGraphPolarPainter extends ObjectPainter {
Axis: d.check('N') ? 'N' : ''
});

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

this.storeDrawOpt(opt);
}

Expand Down

0 comments on commit e647424

Please sign in to comment.