Wrong logarithmic grid in the grid mode
I looked to recent code to understand, how it's supposed to look.
gint x1 = x;
if (base->non_linear)
{
x1 *= pow (1.02, x1);
if (x1 >= w)
break;
}
/* draw vertical line */
cairo_move_to (cr, w - 1 - x1 + 0.5, 0.5);
cairo_line_to (cr, w - 1 - x1 + 0.5, h - 1 + 0.5);
This makes it to expand towards past rather than shrink. It even uses different log base than for data map (1.04
). Even assuming there's some sort of decade - I couldn't deduce resonable value. Ideally - in order to map values from linear to visible space - equation has to be solved: x*x^2 = x1
for x
. I utterly failed to do so.
Last I tried is to use divide and conquer, there's awk example to play with:
echo 6 | awk '{ x1=$0; d=1; while(1){ d2 = log(x1/d) / log(1.04); print d2" "d" "(d+d2)/2; if (d2 > x1*2) d = (x1+d)/2; else if (d2-d>0.2 || d-d2>0.2) d = (d2+d)/2; else break } }'
Unfortunally, I can't get stability.
I could only get working this crude approximation:
- x1 *= pow (1.02, x1);
+ x1 = log (x1) / log (NONLINEAR_MODE_BASE);
Which made first tick 45px wide. Of course, there must be some decades with different tick detail level (it takes ~17px for 2x factor change).