DmitryBaranovskiy / g.raphael

Charts for Raphaël
http://g.raphaeljs.com/
1.52k stars 435 forks source link

y-axis rescale bug #192

Open aphofstede opened 11 years ago

aphofstede commented 11 years ago

See: http://jsfiddle.net/alexman/vpGyL/844/ If you change the chart height to 99 instead of 100, the y-axis will suddenly show 0-0.8 instead of 0-0.3. This is incorrect. If you stretch the y-axis by increasing the max-value var a bit, it will be ok again. A workaround I found is setting an axisystep of 4, however this is not ideal.

aphofstede commented 11 years ago

axisystep: 4 doesn't always work either; try setting trendline to [0.83,0.81,0.84,0.84,0.82,0.82,0.83,0.84,0.84,0.8,0.82,0.82]

aphofstede commented 11 years ago

The problem, i think, lies in snapEnds() I think, around line 760. There:

    if (t < to) {
      t = round((to + .5) * Math.pow(10, i)) / Math.pow(10, i);
    }

This will add 0.5 to the calculated max which is 0.8 there; resulting in a value of 1.3

aphofstede commented 11 years ago

This seems to fix it,

    if (t < to) {
      t = round((to + (.5 / Math.pow(10, i))) * Math.pow(10, i)) / Math.pow(10, i);
    }

    f = round((from - (i > 0 ? 0 : (.5 / Math.pow(10, i)))) * Math.pow(10, i)) / Math.pow(10, i);

but I see more +/-.5 "magic" going on, so perhaps the original coder should have a look.

xiaohwan commented 11 years ago

I actually removed snapEnds because weird behaviors it causes...or because it's magic feature I don't know yet.

On Wed, Aug 7, 2013 at 8:04 AM, Alexander Hofstede <notifications@github.com

wrote:

This seems to fix it,

if (t < to) {
  t = round((to + (.5 / Math.pow(10, i))) * Math.pow(10, i)) / Math.pow(10, i);
}

but I see more +/-.5 "magic" going on, so perhaps the original coder should have a look.

— Reply to this email directly or view it on GitHubhttps://github.com/DmitryBaranovskiy/g.raphael/issues/192#issuecomment-22257737 .