If you’ve read Joe Gregorio’s Sparklines in data: URIs in Python, then you know that he’s presented us with an incredibly compelling use for data: URIs. Namely, this is not an external file:
But we don’t have Python’s image library, so what are we to do?
What if I offered you a handful of code that could generate inline sparkgraphs without library code? Presenting Bumpspark.
def bumpspark( results )
white, red, grey = [0xFF,0xFF,0xFF], [0,0,0xFF], [0x99,0x99,0x99]
ibmp = results.inject([]) do |ary, r|
ary << [white]*15 << [white]*15
ary.last[r/9,4] = [(r > 50 and red or grey)]*4
ary
end.transpose.map do |px|
px.flatten!.pack("C#{px.length}x#{px.length%4}")
end.join
["BM", ibmp.length + 54, 0, 0, 54, 40,
results.length * 2, 15, 1, 24, 0, 0, 0, 0, 0, 0].
pack("A2ISSIIiiSSIIiiII") + ibmp
end
It’s got one known bug: graphs built from 16-element arrays get staticky. Free inky duck drawing to first patcher. (Keep reading.)
Great coats! jzp has dropped a ping version in the comments! MenTaL has a bump one with compression! Peewee graphics libs within!