[reportlab-users] Re: [patch] value labels for PieChart

Gael Chardon gael.dev at 4now.net
Mon Sep 25 08:42:04 EDT 2006


Robin Becker a écrit :
> Gael Chardon wrote:
>> Hello,
>> herefater a little patch that add a new feature to PieChart class.
>> It optionally draw a value (typically the percent) on each slice.
>>
>> The idea:
>> - User sets percentFormat slice attribute to a string or a function ;
>> - Optionally user can set percentFontName, percentFontSize, 
>> percentFontColor.
>> - If percentFormat is a string then it is used to format the percent 
>> value (a float) that represent the slice.
>> - If percentFormat is callable, the function is called  for every 
>> slice with two arguments: the current slice value and the sum. The 
>> funcion should returns the string to draw.
>>
>> See sample4() in diff file
>>
>> Hope it helps.
> ......
> 
> I'm less happy about this patch. We already have a lot of labelling on 
> pie charts and nothing prevents the label text from being(or including) 
> a percentage. If what you want is really just another label that's 
> internal to the slice (and implicitly the ability to have both an 
> external and internal label) then that's a more acceptable kind of 
> patch. I don't think it acceptable to predetermine the textual value of 
> the label ie I might want to internally mark the slices with the actual 
> value (or a country flag etc etc) and perhaps have no external labels.
> 
> The labeling code is pretty disastrous already for which I apologize.
> 
> We probably need more general notions like annotate properties for each 
> wedge to allow you to do this sort of thing.

Ok, I understand your point of view.
Let me explain my needs with my "real life" example.
My application produces charts of "population" count per site, so I 
generate a barchart where the count value for each site is drawn using 
the BarChart.barLabelFormat, and the site name is drawn with the 
BarChart.categoryAxis.labels.
My idea was to reproduce this kind of chart with a PieChart, this way 
PieChart.labels will be the site name and percentFormat (yes this not a 
good name) will be used to draw the count value (percent and value).

Maybe an annotate or "inside label" properties is a better approach, but 
I think it is pretty useful to provide the current value and sum to the 
user formatting function.

I will send a more generic patch, but I need to modify my application 
first :)

Regards.

-- 
Gael Chardon



More information about the reportlab-users mailing list