|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
poll - SVG
hi,
i am suppsoed to make a simple poll with SVG and python, can anybody help me?? i need some suggestions, and maybe some links where i can find code exmples, and so on ??? pllzzz, thanks, ain |
|
#2
|
||||
|
||||
|
Just a few things to check, really just for more spacific info on what you want here. By SVG you mean Scalable Vector Graphics right? I've never used this. But I'm assuming that you want something like the polls on Devshed? Or the little green lines on Google?
Mark. |
|
#3
|
|||
|
|||
|
yeah, youre right SVG is Scalar Vector Graphics. i want to make a poll which have three options like "yes" "no" and "dont know". i wants show results these results with diagram and i wants to write that code in python ??
hope its helps, ain |
|
#4
|
||||
|
||||
|
Ok, I think I know what you're getting at. But, before I have a go at this - using Python CGI - it would be great if you could post a link to something similar
. |
|
#5
|
|||
|
|||
|
something like this: http://www.sfgate.com/polls/
|
|
#6
|
||||
|
||||
|
If you can execute dynamic Pages then SVG is probably overkill. But, after messing around with it for a bit I didn't really come up with anything useful/relevent in that area... that is except a function for calculating the length of the precent bar:
Code:
def percentBar(votes, total, length):
#Takes the number of votes for this bar, the 'total' number of votes and
#the length of the bar and calculates the size of this bar to be drawn.
positiveSize = (votes / total) * length
#Returns a Tuple containing the actual percentage of votes and the length
#(as a float) of the two sides; if you're only interested in the positive
#side of the bar then ignore the third value in this Tuple.
return ((votes / total) * 100, positiveSize, length - positiveSize)
This was mainly due to not having PIL installed on my system anymore - though I will be changing that later today. Anyway, I'd suggest that you take a look at the PIL module, available from: http://www.pythonware.com/downloads/index.htm There is also an article on devshed regarding this (first link), though it doesn't really cover drawing shapes, so you might want to look here aswell (second link): http://www.devshed.com/c/a/Python/Imagine-Python/ http://www.pythonware.com/library/pil/handbook/ Have fun, Mark. Last edited by netytan : October 9th, 2004 at 08:38 AM. |
|
#7
|
||||
|
||||
|
Mark,
Just a small tweak: Code:
positiveSize = int((votes / float(total)) * length) The float to make sure you have a non-zero result when integers are passed and the int to round down positiveSize to the nearest pixel. grim ![]()
__________________
*** Experimental Python Markup CGI V2 *** |
|
#8
|
||||
|
||||
|
Thanks Grim! I don't know why I didn't think of that
. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > poll - SVG |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|