Wed, 19 Dec 2007
TurboFlot 0.0.1
In an effort to clean up bodhi's metrics code a bit, I wrote a TurboFlot plugin that allows you to wield the jQuery plugin flot inside of TurboGears applications. The code is quite trivial -- it's essentially just a TurboGears JSON proxy to the jQuery flot plugin. Breaking this code out into it's own widget makes it really easy to generate shiny graphs in a Pythonic fashon, without having to write a line of javascript.

Check out the README to see the code for the example above.
To use TurboFlot in your own application, you just pass your data and graph options to the widget, and then throw it up to your template. Read the flot API documentation for details on all of the arguments. Here is a simple usage example:
flot = TurboFlot([
{
'data' : [[0, 3], [4, 8], [8, 5], [9, 13]],
'lines' : { 'show' : True, 'fill' : True }
}],
{
'grid' : { 'backgroundColor' : '#fffaff' },
'yaxis' : { 'max' : '850' }
}
)
Then, to display the widget in your template, you simply use:
${flot.display()}
The code for the widget itself is pretty simple. It just takes your data and graph options, encodes them as JSON and tosses them at flot.
class TurboFlot(Widget):
"""
A TurboGears Flot Widget.
"""
template = """
<div xmlns:py="http://purl.org/kid/ns#" id="turboflot"
style="width:${width};height:${height};">
<script>
$.plot($("#turboflot"), ${data}, ${options});
</script>
</div>
"""
params = ["data", "options", "height", "width"]
javascript = [JSLink('turboflot', 'excanvas.js'),
JSLink("turboflot", "jquery.js"),
JSLink("turboflot", "jquery.flot.js")]
def __init__(self, data, options={}, height="300px", width="600px"):
self.data = simplejson.dumps(data)
self.options = simplejson.dumps(options)
self.height = height
self.width = width
You can download the latest releases from the Python Package Index:
http://pypi.python.org/pypi/TurboFlotOr you can grab my latest development tree out of mercurial:
http://hg.lewk.org/TurboFlotAs always, patches are welcome :)
posted at: 20:21 | link | | 5 comments
Posted by Алексей at Fri Feb 15 18:27:13 2008
http://www.coloria.ru/Article/jquery-sozdanie-grafikov-ispolzuya-plagin-flot
Posted by belladf at Sun May 8 07:18:27 2011
Credit you - this is sheerest sympathetic !
<a href=http://naturalmedic.co.il/%d7%a7%d7%95%d7%a8%d7%a1_%d7%a0%d7%98%d7%95%d7%a8%d7%95%d7%a4%d7%aa%d7%99%d7%94>לימודי נטורופתיה</a>
Posted by Inrieqj at Fri Feb 17 22:49:46 2012
Существует такое что <a href=http://seobabai.ru/progon-sajta-obyavleniya-reklamy>система продвижения сайта </a> может значительно поднять свой доход в интернете
Posted by Carolina at Sat Nov 16 05:56:51 2013
По моему мнению Вы пошли ошибочным путём.
<a href=http://vk.com/opponents><img>http://s020.radikal.ru/i722/1311/18/a0f8fafc2779.jpg</img></a>
Posted by Giulia at Fri Dec 5 06:12:43 2014
Thank you for your article. I have the same pelborm with widgets. I have reviewed your source and wonder if it works if both small and big widgets will be placed on screen?