Created
January 14, 2009 19:26
-
-
Save chrisgemignani/47013 to your computer and use it in GitHub Desktop.
This file contains 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
size(520, 620) | |
from math import pi | |
data = [ | |
#Pattern,expedia.com,hotel-guides.us,travel.yahoo.com,travelocity.com,tripadvisor.com | |
['[x] hotel',0.02154,0.00903,0.35186,0.16603,0.45155], | |
['[x] hotel [x]',0.00000,0.00000,0.14872,0.26750,0.58378], | |
['[x] inn [x]',0.03185,0.00000,0.00000,0.24957,0.71859], | |
['hotel [x]',0.01385,0.02769,0.31154,0.23692,0.41000], | |
['hotel in [x]',0.03216,0.00000,0.53631,0.19191,0.23963], | |
['[x] resort',0.00000,0.00000,0.01746,0.18254,0.80000], | |
['[x] resort [x]',0.00000,0.00000,0.00000,0.24522,0.75478], | |
['[x] ticket',0.00000,0.84807,0.00000,0.15193,0.00000], | |
['[x] restaurant',0.00000,0.00000,0.00000,0.54745,0.45255], | |
['[x] motel',0.00000,0.00000,0.72564,0.11282,0.16154], | |
['map of [x]',0.00000,0.00000,0.00000,0.62821,0.37179], | |
['[x] map',0.00000,0.00000,0.03183,0.50663,0.46154], | |
['[x] inn',0.02727,0.00606,0.00000,0.26667,0.70000], | |
['[x] vacation',0.00635,0.15873,0.02222,0.22222,0.59048], | |
['trip [x]',0.00000,0.00000,0.00000,0.00000,1.00000], | |
['[x] restaurant [x]',0.00000,0.00000,0.00000,0.45714,0.54286], | |
['things to do in [x]',0.00000,0.00000,0.00000,0.41818,0.58182], | |
['[x] hotel in [x] [x]',0.00000,0.00000,0.37089,0.00000,0.62911], | |
['best [x]',0.04348,0.00000,0.04831,0.29469,0.61353], | |
['motel [x]',0.00000,0.00000,0.70732,0.08780,0.20488], | |
['cheap [x]',0.25824,0.00000,0.04396,0.47802,0.21978], | |
['[x] attraction',0.00000,0.00000,0.00000,0.34254,0.65746], | |
['[x] suite [x]',0.00000,0.00000,0.00000,0.00000,1.00000], | |
['[x] lodging',0.00000,0.00000,0.59639,0.10843,0.29518], | |
['[x] travel',0.06627,0.19277,0.00000,0.64458,0.09639], | |
] | |
colormode(HSB) | |
# hue sat brt alpha | |
grey = color(0.0, 0.0, 0.3, 0.5) | |
highlight = color(0.6, 0.5, 1.0, 0.8) | |
black = color(0,0, 0.3, 0.9, 1.0) | |
# constants | |
LABELWIDTH = 150 # width of row label | |
COLWIDTH = 75 # width of columns | |
LINEWIDTH = 470 # width of line to draw under each row | |
ROWHEIGHT = 22 # height of each row | |
MINLABEL = 0.2 # minimum size of circle for drawing a label | |
LABELSIZE = 10 # font size of labels on circles | |
CIRCLESCALE = 4000 # scale the size of the circles | |
font("Helvetica Neue") | |
fontsize(12) | |
fill(black) | |
translate(0,30) | |
align(CENTER) | |
text("Expedia", LABELWIDTH-50, 0, width=100) | |
text("Travelocity", LABELWIDTH+1*COLWIDTH-50, -15, width=100) | |
text("Hotel-Guides", LABELWIDTH+2*COLWIDTH-50, 0, width=100) | |
text("Yahoo! Travel", LABELWIDTH+3*COLWIDTH-50, -15, width=100) | |
text("TripAdvisor", LABELWIDTH+4*COLWIDTH-50, 0, width=100) | |
translate(0,30) | |
font("Helvetica Neue Light") | |
for row in data: | |
rowlabel, rowdata = row[0], row[1:] | |
rowmax = max(rowdata) | |
fill(black) | |
align(LEFT) | |
fontsize(12) | |
text(rowlabel, 10, 0, width=LABELWIDTH) | |
# draw a light grey line below each row | |
stroke(1.0, 0.0, 0.55) | |
strokewidth(0.2) | |
line(0, 5, LINEWIDTH, 5) | |
# save the current origin | |
push() | |
translate(LABELWIDTH, -6) | |
for column_num, val in enumerate(rowdata): | |
if val > 0.0: | |
r = (CIRCLESCALE*val / pi)**0.5 | |
# draw the shape | |
fill(grey) | |
if val == rowmax: | |
fill(highlight) | |
oval(-r/2,-r/2, r, r) | |
if val > MINLABEL: | |
fontsize(LABELSIZE) | |
fill(black) | |
text("%.1f%%" % (100*val),4-r/2,0,width=COLWIDTH) | |
# move over a row | |
translate(COLWIDTH, 0) | |
# restore the origin | |
pop() | |
# move down a row | |
translate(0, ROWHEIGHT) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment