[reportlab-users] Overlapping pie charts labels

Pierre Thevenet reportlab-users@reportlab.com
Fri, 13 Aug 2004 13:11:09 +0200 (CEST)


Hi,

I'm dynamically generating pie charts, and occasionally come across
overlapping labels (when two consecutive slices are too small).

As a workaround, I'm using the "popout" attribute, stepping it up
by 10 every time I have two or more consecutive slices below 5% :
(those values of 5% and 10 points are a rough guess and should depend on
the chart width and font size)

Here's a code snippet to (maybe) make it clearer :

pc = Pie()
pc.x = x
pc.y = y
pc.width = width
pc.height = height
pc.data=data
pc.labels=labels
num=len(data)
total=sum(data)
popote=0
for i in range(0,num):
	if data[i]*100/total < 5:
		j=i-1
		if j==-1:
			j=num-1
		if data[j]*100/total < 5:
			popote=popote+10
			pc.slices[i].popout=popote
	else:
		popote=0

It does seem to work well in most cases, but it is a bit of a dirty hack,
and doesn't work at all with 3D pie charts (mostly because they're not
round). So I'd like to know if anyone has found a simple, elegant and
efficient solution to this problem - or if it doesn't exist, what
workarounds did you use.

TIA,

Pierre