Created
October 28, 2014 09:15
-
-
Save ykarikos/18a8bb926e90b33cce3c to your computer and use it in GitHub Desktop.
Transform Tech radar questionnaire input into svg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
from math import sin, cos | |
prefix = """<svg width="800" height="800" xmlns="http://www.w3.org/2000/svg" > | |
<g transform="translate(400,400)"> | |
<circle r="350" style="fill: rgb(190, 195, 230);"></circle> | |
</g> | |
<g transform="translate(400,400)"> | |
<circle r="280" style="fill: rgb(65, 175, 70);"></circle> | |
</g> | |
<g transform="translate(400,400)"> | |
<circle r="180" style="fill: rgb(38, 104, 38);"></circle> | |
</g> | |
<g> | |
""" | |
suffix = """ </g> | |
</svg> | |
""" | |
def getRadius(vote): | |
if vote < -2: | |
return 320 # 0.4 | |
if vote < -0.8: | |
return 280 | |
elif vote < 0: | |
return 240 | |
elif vote < 0.8: # 0.3 | |
return 200 | |
elif vote < 1.5: | |
return 170 | |
elif vote < 3: | |
return 140 | |
elif vote < 8: | |
return 90 | |
elif vote < 15: | |
return 40 | |
else: | |
return 0 | |
def radiusToCoordinates(radius, angle): | |
x = radius * cos(angle) | |
y = radius * sin(angle) | |
return (400-x, 400-y) | |
def createSvg(tech, coordinates): | |
line = "<text dx=\"%dpx\" dy=\"%dpx\" text-anhor=\"middle\">%s</text>" % (coordinates[0], coordinates[1], tech) | |
return line | |
techs = sys.stdin.readline().rstrip().split("\t") | |
votes = map(lambda x: float(x), sys.stdin.readline().rstrip().split("\t")) | |
data = sorted(zip(techs, votes), key=lambda t: t[1]) | |
print(prefix) | |
angle = 0 | |
for tech, vote in data: | |
radius = getRadius(vote) | |
coordinates = radiusToCoordinates(radius, angle) | |
angle = angle + 0.54 | |
print(createSvg(tech, coordinates)) | |
print(suffix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment