Matt Gemmell

My new book CHANGER is out now!

An action-adventure novel — book 1 in the KESTREL series.

★★★★★ — Amazon

iPie

Source 1 min read

In development, a pie-chart control for Cocoa developers.
Pie chart screenshot
The class accepts an NSArray of NSNumbers as data. I'll 
probably change this to accept an NSDictionary instead, 
so that labels can be directly paired with their values. 
It automatically takes care of stripping out negative or 
zero values, and the pathological cases of either only one 
item of data, or none at all.



The chart has a six-colour cycle which repeats in sequence 
if there are more than six data items, or a delegate can 
specify colours (both stroke and fill) on an individual 
basis. The delegate can also request that slices be exploded 
outwards from the pie.



Either raw values or percentages can be shown, and/or the 
associated names for each data item, if any. These labels 
can be shown either inside or outside the pie. Drop-shadows 
can be enabled or disabled for labels and/or slices (Mac OS X 
10.3 or later only), and the drawing routines are clever enough 
to ensure shadows are cast correctly, with the first slice 
being "topmost", and so on. Stroke thickness for slices can be 
specified.



I'm considering adding the ability to display a legend 
automatically, something like Keynote. I've had the suggestion 
of making slices draggable (constrained to a straight line out 
from the center of the chart).



The chart will be centered (horizontally and vertically) within 
the available space, and will scale as its view is resized; the 
control is implemented as an NSCell/NSControl pair. The angular 
offset of the first slice can also be specified; this determines 
what starting position slices will be drawn from (in the screenshot, 
slices are drawn starting from 90°, or 12 o'clock).



Any comments, suggestions or feature requests will be gratefully 
received. Oh, and I've not forgotten about iCalendar; the code 
needs to be refactored to some extent before it's ready for 
distribution, but it will be released.