Thread: poll - SVG

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    49
    Rep Power
    11

    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. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    49
    Rep Power
    11
    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
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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 .
    programming language development: www.netytan.com Hula

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    49
    Rep Power
    11
    something like this: http://www.sfgate.com/polls/
  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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 07:38 AM.
    programming language development: www.netytan.com Hula

  12. #7
  13. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    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
  14. #8
  15. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Thanks Grim! I don't know why I didn't think of that .
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo