gmmoraesbr / flot

Automatically exported from code.google.com/p/flot
0 stars 0 forks source link

IE7/8 pie charts with one slice sometimes don't render #325

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In IE7 and 8, if you specify a pie chart with one slice taking up the whole
pie, sometimes the pie won't render at all (though the legend still will).

Assuming there's an element with an id of "holder" on the page, the
following script renders in IE7/8 as expected:

var data = [];
data[0] = { label: "One" , data: 1 };
$.plot($("#holder"), data, { series: { pie: { show: true } }});

But this variation does not:

var data = [];
data[0] = { label: "One" , data: 334 };
$.plot($("#holder"), data, { series: { pie: { show: true } }});

This also occurs using these values if there are multiple data series,
where all of the other series have value 0.

I traced the problem to this block in the plugin, inside drawSlice:

if (angle!=Math.PI*2)
  ctx.moveTo(0,0); // Center of the pie
else if ($.browser.msie)
  angle -= 0.0001;

For whatever reason it looks like there was an IE hack added if a slice
taking up the whole pie is drawn, reducing the angle slightly from 2 PI. 
However, the problem is the statement above: "angle!=Math.PI*2"  For some
values of data[0], 'angle' is different from 2 PI by one trillionth or so,
so in those cases the 'else if' with the IE hack doesn't get run.

Changing the if statement to something like

if (Math.abs(angle - Math.PI*2) > 0.000000001)

seems to work - the exact value of the tolerance is up for debate though.

Original issue reported on code.google.com by jparish9...@gmail.com on 19 Mar 2010 at 9:26

GoogleCodeExporter commented 8 years ago

Original comment by olau%iol...@gtempaccount.com on 22 Mar 2010 at 10:57

GoogleCodeExporter commented 8 years ago
Hi, I have a similar problem, I have a pie chart with only one slice but I can 
see it 
on IE but i cant on google chrome and it doesnt work with data: 1 like u said.

Did u solved this issue?

Original comment by cele...@gmail.com on 17 May 2010 at 9:29

GoogleCodeExporter commented 8 years ago
I'm not sure that this is an IE7/8 issue. Had the same/similar problem with a 
Firefox chart - one slice should have filled the entire pie but instead we saw 
the single slice with a white line/slice at the '12 O'Clock' position.

Modified the flot file to include the suggested 'if statement' and the problem 
was resolved.

Original comment by andrew.h...@gmail.com on 16 Jun 2010 at 11:41

GoogleCodeExporter commented 8 years ago
I encountered a similar problem that was specific to IE8 when using tilt value 
<= 0.8. In my case the angle adjustment of "0.001" (line #409) was not enough 
to get the single slice to render. Changing it to "0.1" fixed the issue (as did 
setting the tilt value to 1).

HTH,

Eric G.

Original comment by eric_gil...@yahoo.com on 29 Nov 2010 at 7:23

GoogleCodeExporter commented 8 years ago
Since Brian didn't react yet, I've fixed it now as per your suggestion. 
Floating points are dangerous.

Original comment by olau%iol...@gtempaccount.com on 15 Dec 2010 at 3:56