Skip to content

Commit

Permalink
Build with axis labels align
Browse files Browse the repository at this point in the history
  • Loading branch information
linev committed Nov 28, 2024
1 parent 2226481 commit dd9af0e
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions build/jsroot.js
Original file line number Diff line number Diff line change
Expand Up @@ -62892,6 +62892,8 @@ class TAxisPainter extends ObjectPainter {
* Therefore one should distinguish when calculated coordinates used for axis drawing itself or for calculation of frame coordinates
* @private */
configureAxis(name, min, max, smin, smax, vertical, range, opts) {
const axis = this.getObject();

this.name = name;
this.full_min = min;
this.full_max = max;
Expand All @@ -62903,13 +62905,14 @@ class TAxisPainter extends ObjectPainter {
this.noexp_changed = opts.noexp_changed;
this.symlog = opts.symlog || false;
this.reverse = opts.reverse || false;
// special flag to change align of labels on vertical axis
// it is workaround shown in TGaxis docu
this.reverseAlign = this.vertical && this.reverse && this.is_gaxis && (axis.fX1 !== axis.fX2);
this.swap_side = opts.swap_side || false;
this.fixed_ticks = opts.fixed_ticks || null;
this.maxTickSize = opts.maxTickSize || 0;
this.value_axis = opts.value_axis ?? false; // use fMinimum/fMaximum from source object

const axis = this.getObject();

if (opts.time_scale || axis.fTimeDisplay) {
this.kind = kAxisTime;
this.timeoffset = getTimeOffset(axis);
Expand Down Expand Up @@ -63580,16 +63583,15 @@ class TAxisPainter extends ObjectPainter {
if (this.vertical) {
arg.x = fix_coord;
arg.y = pos;
arg.align = rotate_lbls ? ((side < 0) ? 23 : 20) : ((side < 0) ? 12 : 32);

arg.align = rotate_lbls ? (this.optionLeft || this.reverseAlign ? 23 : 21) : (this.optionLeft || this.reverseAlign ? 12 : 32);
if (this.cutLabels()) {
const gap = labelsFont.size * (rotate_lbls ? 1.5 : 0.6);
if ((pos < gap) || (pos > h - gap)) continue;
}
} else {
arg.x = pos;
arg.y = fix_coord;
arg.align = rotate_lbls ? ((side < 0) ? 12 : 32) : ((side < 0) ? 20 : 23);
arg.align = rotate_lbls ? ((side < 0) ? 12 : 32) : ((side < 0) ? 21 : 23);
if (this.log && !this.noexp && !this.vertical && arg.align === 23) {
arg.align = 21;
arg.y += labelsFont.size;
Expand Down Expand Up @@ -63676,7 +63678,8 @@ class TAxisPainter extends ObjectPainter {
const pad_w = pp?.getPadWidth() || scalingSize || w/0.8, // use factor 0.8 as ratio between frame and pad size
pad_h = pp?.getPadHeight() || scalingSize || h/0.8,
// if no external scaling size use scaling as in TGaxis.cxx:1448 - NDC axis length is in the scaling factor
tickScalingSize = scalingSize || (this.vertical ? h/pad_h*pad_w : w/pad_w*pad_h);
tickScalingSize = scalingSize || (this.vertical ? h/pad_h*pad_w : w/pad_w*pad_h),
bit_plus = axis.TestBit(EAxisBits.kTickPlus), bit_minus = axis.TestBit(EAxisBits.kTickMinus);

let tickSize = 0, titleColor, titleFontId, offset;

Expand All @@ -63685,22 +63688,31 @@ class TAxisPainter extends ObjectPainter {
if (this.is_gaxis) {
const optionSize = axis.fChopt.indexOf('S') >= 0;
this.optionUnlab = axis.fChopt.indexOf('U') >= 0;
this.optionMinus = (axis.fChopt.indexOf('-') >= 0) || axis.TestBit(EAxisBits.kTickMinus);
this.optionPlus = (axis.fChopt.indexOf('+') >= 0) || axis.TestBit(EAxisBits.kTickPlus);
this.optionMinus = (axis.fChopt.indexOf('-') >= 0) || bit_minus;
this.optionPlus = (axis.fChopt.indexOf('+') >= 0) || bit_plus;
this.optionNoopt = (axis.fChopt.indexOf('N') >= 0); // no ticks position optimization
this.optionInt = (axis.fChopt.indexOf('I') >= 0); // integer labels
this.optionText = (axis.fChopt.indexOf('T') >= 0); // text scaling?
this.optionLeft = (axis.fChopt.indexOf('L') >= 0); // left text align
this.optionRight = (axis.fChopt.indexOf('R') >= 0); // right text align
this.optionCenter = (axis.fChopt.indexOf('C') >= 0); // center text align
this.createAttLine({ attr: axis });
tickSize = optionSize ? axis.fTickSize : 0.03;
titleColor = this.getColor(axis.fTextColor);
titleFontId = axis.fTextFont;
offset = axis.fLabelOffset;
if ((this.vertical && axis.fY1 > axis.fY2 && !this.optionMinus) || (!this.vertical && axis.fX1 > axis.fX2))
// workaround for old reverse axes where offset is not properly working
if (this.reverse && (!this.vertical || (!this.optionMinus && (axis.fX1 !== axis.fX2))))
offset = -offset;
} else {
this.optionUnlab = false;
this.optionMinus = this.vertical ^ this.invert_side;
this.optionPlus = !this.optionMinus;
if (!bit_plus && !bit_minus) {
this.optionMinus = this.vertical ^ this.invert_side;
this.optionPlus = !this.optionMinus;
} else {
this.optionPlus = bit_plus;
this.optionMinus = bit_minus;
}
this.optionNoopt = false; // no ticks position optimization
this.optionInt = false; // integer labels
this.optionText = false;
Expand Down Expand Up @@ -66115,6 +66127,8 @@ class TFramePainter extends ObjectPainter {
let pr = Promise.resolve(true);

if (!disable_x_draw || !disable_y_draw || draw_grids) {
draw_vertical.optionLeft = draw_vertical.invert_side; // text align

const can_adjust_frame = !shrink_forbidden && settings.CanAdjustFrame,

pr1 = draw_horiz.drawAxis(layer, w, h,
Expand Down Expand Up @@ -66192,6 +66206,7 @@ class TFramePainter extends ObjectPainter {
}

if (draw_vertical) {
draw_vertical.optionLeft = draw_vertical.invert_side;
pr2 = draw_vertical.drawAxis(layer, w, h,
draw_vertical.invert_side ? `translate(${w})` : null,
pad?.fTicky ? w : 0, false,
Expand Down Expand Up @@ -73243,11 +73258,12 @@ class TPavePainter extends ObjectPainter {

this._palette_vertical = (palette.fX2NDC - palette.fX1NDC) < (palette.fY2NDC - palette.fY1NDC);

axis.fTickSize = 0.6 * s_width / width; // adjust axis ticks size
axis.fTickSize = 0.03; // adjust axis ticks size

if ((typeof zaxis?.fLabelOffset !== 'undefined') && !is_th3) {
axis.fBits = zaxis.fBits & ~EAxisBits.kTickMinus & ~EAxisBits.kTickPlus;
axis.fTitle = zaxis.fTitle;
axis.fTickSize = zaxis.fTickLength;
axis.fTitleSize = zaxis.fTitleSize;
axis.fTitleOffset = zaxis.fTitleOffset;
axis.fTextColor = zaxis.fTitleColor;
Expand Down Expand Up @@ -73288,11 +73304,13 @@ class TPavePainter extends ObjectPainter {

if (this._palette_vertical) {
this._swap_side = palette.fX2NDC < 0.5;
axis.fChopt = 'S+' + (this._swap_side ? 'R' : 'L'); // clearly configure text align
this.z_handle.configureAxis('zaxis', gzmin, gzmax, zmin, zmax, true, [0, s_height], { log, fixed_ticks: cjust ? levels : null, maxTickSize: Math.round(s_width*sizek), swap_side: this._swap_side, minposbin: main.gminposbin });
axis_transform = this._swap_side ? null : `translate(${s_width})`;
if (pad?.fTickz) axis_second = this._swap_side ? s_width : -s_width;
} else {
this._swap_side = palette.fY1NDC > 0.5;
axis.fChopt = 'S+';
this.z_handle.configureAxis('zaxis', gzmin, gzmax, zmin, zmax, false, [0, s_width], { log, fixed_ticks: cjust ? levels : null, maxTickSize: Math.round(s_height*sizek), swap_side: this._swap_side, minposbin: main.gminposbin });
axis_transform = this._swap_side ? null : `translate(0,${s_height})`;
if (pad?.fTickz) axis_second = this._swap_side ? s_height : -s_height;
Expand Down

0 comments on commit dd9af0e

Please sign in to comment.