Hello,
I've been playing with the ArcPoint and got a nice PieChart working. I
have attached the bits so far (plus a few simple tests).
It seems to have some problems at very small zoom levels, IE around
10-15 pixel across (which is what I really need it for). Any idea what
is going on? (Is there anyway to turn on anti-aliasing?)
The name is a little bit of a misnomer, because unlike a "Point" object,
the diameter of the object is changed by the zoom level. I really need a
version where the diameter is not effected by the Zoom level (in the
same way a Point works).
Thanks for your help.
Tim Ansell
On Mon, 2007-08-27 at 13:21 +1000, Philip Peake wrote:
> Hi Tim,
> I have not seen a Pie Chart draw object per se, but the ArcPoint method
> was designed to be used in the creation of a pie chart.
> I created some of the initial code for ArcPoint in fc , but Chris made
> it work.
> The section you refer to ("# this is suitable for a pie chart") is just
> related to the bounding box size.
> I hope this helps :)
> Regards
> Phil.
<snip>
from FloatCanvas import Group
from ArcObject import ArcPoint
from math import *
class PieChart(Group):
def __init__(self, XY, Diameter, Amounts, InForeground = False):
if not isinstance(Amounts, (list, tuple)):
raise TypeError("Amount's must be a tuple of tuples with first value as numbers and values as Arc arguments")
for number, args in Amounts:
if not isinstance(number, (int, long, float)):
raise TypeError("Amount's keys must be a number not %r %s" % (number, type(number)))
if not isinstance(args, dict):
raise TypeError("Amount's values must be the arguments for each Arc not %r %s" % (args, type(args)))
# Convert to percentages
Total = sum(zip(*Amounts)[0])
Percentages = [(float(a)/Total, b) for a,b in Amounts]
ObjectList = []
CenterXY = XY
StartXY = XY+(0, Diameter)
total = 0
for percentage, args in Percentages:
total += percentage
radians = pi/2-2*pi*total
EndXY = CenterXY + (cos(radians)*Diameter, sin(radians)*Diameter)
if isinstance(args, dict):
ObjectList.append(ArcPoint(EndXY, StartXY, CenterXY, **args))
elif isinstance(args, (list, tuple)):
ObjectList.append(ArcPoint(EndXY, StartXY, CenterXY, *args))
StartXY = EndXY
Group.__init__(self, ObjectList, InForeground)
#!/usr/bin/env python
import wx
## import the installed version
#from wx.lib.floatcanvas import NavCanvas, FloatCanvas
## import a local version
import sys
sys.path.append("..")
import NavCanvas, FloatCanvas
import numpy as N
class DrawFrame(wx.Frame):
"""
A frame used for the FloatCanvas Demo
"""
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.CreateStatusBar()
# Add the Canvas
Canvas = NavCanvas.NavCanvas(self,-1,
size = (500,500),
Debug = 0,
BackgroundColor = "DARK SLATE BLUE",
).Canvas
self.Canvas = Canvas
PieBitsEqual = (
(10, {'LineColor':'Red', 'FillColor':'Red'}),
(10, {'LineColor':'Blue', 'FillColor':'Blue'}),
(10, {'LineColor':'Green', 'FillColor':'Green'}))
PieBitsT = (
(10, {'LineColor':'Red', 'FillColor':'Red'}),
( 5, {'LineColor':'Blue', 'FillColor':'Blue'}),
( 5, {'LineColor':'Green', 'FillColor':'Green'}))
from PieChart import PieChart
Pie1 = PieChart(N.array((-20, 0)), 10, PieBitsEqual)
Canvas.AddObject(Pie1)
Pie2 = PieChart(N.array(( 20, 0)), 10, PieBitsT)
Canvas.AddObject(Pie2)
FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove )
self.Show()
Canvas.ZoomToBB()
def OnMove(self, event):
"""
Updates the status bar with the world coordinates
"""
self.SetStatusText("%.2g, %.2g"%tuple(event.Coords))
app = wx.App(False)
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
app.MainLoop()
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas