Skip to content

Commit 02c8044

Browse files
committed
Correctly calculate pad ranges for TWebCanvas
One should apply log scales before sending to server
1 parent 93b8be6 commit 02c8044

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

modules/gpad/TPadPainter.mjs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,30 +1684,27 @@ class TPadPainter extends ObjectPainter {
16841684
if (!r.ranges || p.empty()) return true;
16851685

16861686
// calculate user range for full pad
1687-
const same = x => x,
1688-
direct_funcs = [same, Math.log10, x => Math.log10(x)/Math.log10(2)],
1689-
revert_funcs = [same, x => Math.pow(10, x), x => Math.pow(2, x)],
1690-
match = (v1, v0, range) => (Math.abs(v0-v1) < Math.abs(range)*1e-10) ? v0 : v1,
1687+
const log10 = (x,e) => (x<=0) ? e : Math.log10(x),
1688+
log2 = (x,e) => (x<=0) ? e : Math.log10(x)/Math.log10(2),
1689+
funcs = [ x => x, log10, log2 ],
16911690
frect = main.getFrameRect();
16921691

1693-
let func = direct_funcs[main.logx],
1694-
func2 = revert_funcs[main.logx],
1695-
k = (func(main.scale_xmax) - func(main.scale_xmin))/frect.width,
1696-
x1 = func(main.scale_xmin) - k*frect.x,
1697-
x2 = x1 + k*this.getPadWidth();
1692+
let func = funcs[main.logx] || log10;
1693+
r.ux1 = func(r.ux1, 0);
1694+
r.ux2 = func(r.ux2, 1);
16981695

1699-
r.px1 = match(func2(x1), r.px1, r.ux2-r.ux1);
1700-
r.px2 = match(func2(x2), r.px2, r.ux2-r.ux1);
1696+
let k = (r.ux1 - r.ux2)/frect.width;
1697+
r.px1 = r.ux1 - k*frect.x;
1698+
r.px2 = r.px1 + k*this.getPadWidth();
17011699

1702-
func = direct_funcs[main.logy];
1703-
func2 = revert_funcs[main.logy];
1700+
func = funcs[main.logy] || log10;
17041701

1705-
k = (func(main.scale_ymax) - func(main.scale_ymin))/frect.height;
1706-
let y2 = func(main.scale_ymax) + k*frect.y,
1707-
y1 = y2 - k*this.getPadHeight();
1702+
r.uy1 = func(r.uy1, 0);
1703+
r.uy2 = func(r.uy2, 1);
17081704

1709-
r.py1 = match(func2(y1), r.py1, r.uy2-r.uy1);
1710-
r.py2 = match(func2(y2), r.py2, r.uy2-r.uy1);
1705+
k = (r.uy2 - r.uy1)/frect.height;
1706+
r.py1 = r.uy1 - k*frect.y;
1707+
r.py2 = r.py1 + k*this.getPadHeight();
17111708

17121709
return true;
17131710
}

0 commit comments

Comments
 (0)