tw2.protovis.conventional

A bunch of cool widgets from protovis (under the 'conventional' heading in their examples page).

Get this source from http://github.com/ralphbean/tw2.protovis.conventional

Protovis itself can be found here: http://vis.stanford.edu/protovis/

AreaChart
  • pvcls
    • None
  • p_width
    • The width of the panel, in pixel.
  • p_height
    • The height of the panel, in pixels.
  • p_bottom
    • The bottom margin, in pixels.
  • p_top
    • The top margin, in pixels.
  • p_left
    • The left margin, in pixels.
  • p_right
    • The right margin, in pixels.
  • init_js
    • JSSymbol
  • p_color
    • Color of the area
class DemoAreaChart(AreaChart):
    p_data = [{'x': i, 'y' : math.sin(i) + random.random() * .5 + 2}
                for i in map(lambda x : x / 10.0, range(100))]
<%namespace name="tw" module="tw2.core.mako_util"/>
<div ${tw.attrs(attrs=w.attrs)}>
<script type="text/javascript+protovis">
${w.init_js.src}
var vis = new pv.Panel()
% for f in w._pv_prop_funcs:
	${f.src}
% endfor
% for a in w._adds:
${a.display()}
% endfor
vis.render();
</script>
</div>

BarChart
  • pvcls
    • None
  • p_width
    • The width of the panel, in pixel.
  • p_height
    • The height of the panel, in pixels.
  • p_bottom
    • The bottom margin, in pixels.
  • p_top
    • The top margin, in pixels.
  • p_left
    • The left margin, in pixels.
  • p_right
    • The right margin, in pixels.
  • init_js
    • JSSymbol
  • p_show_values
    • bool -- show values on bars
class DemoBarChart(BarChart):
    p_data = [random.random()*100 for i in range(10)]
    p_labels = ['label ' + str(i) for i in range(10)]
<%namespace name="tw" module="tw2.core.mako_util"/>
<div ${tw.attrs(attrs=w.attrs)}>
<script type="text/javascript+protovis">
${w.init_js.src}
var vis = new pv.Panel()
% for f in w._pv_prop_funcs:
	${f.src}
% endfor
% for a in w._adds:
${a.display()}
% endfor
vis.render();
</script>
</div>

ScatterPlot
  • pvcls
    • None
  • p_width
    • The width of the panel, in pixel.
  • p_height
    • The height of the panel, in pixels.
  • p_bottom
    • The bottom margin, in pixels.
  • p_top
    • The top margin, in pixels.
  • p_left
    • The left margin, in pixels.
  • p_right
    • The right margin, in pixels.
  • init_js
    • JSSymbol
class DemoScatterPlot(ScatterPlot):
    p_data = [{'x': i, 'y' : random.random(), 'z' : 10**(2*random.random())}
                for i in range(100)]
<%namespace name="tw" module="tw2.core.mako_util"/>
<div ${tw.attrs(attrs=w.attrs)}>
<script type="text/javascript+protovis">
${w.init_js.src}
var vis = new pv.Panel()
% for f in w._pv_prop_funcs:
	${f.src}
% endfor
% for a in w._adds:
${a.display()}
% endfor
vis.render();
</script>
</div>

PieChart
  • pvcls
    • None
  • p_width
    • The width of the panel, in pixel.
  • p_height
    • The height of the panel, in pixels.
  • p_bottom
    • The bottom margin, in pixels.
  • p_top
    • The top margin, in pixels.
  • p_left
    • The left margin, in pixels.
  • p_right
    • The right margin, in pixels.
  • init_js
    • JSSymbol
class DemoPieChart(PieChart):
    p_data = [random.random() for i in range(10)]
<%namespace name="tw" module="tw2.core.mako_util"/>
<div ${tw.attrs(attrs=w.attrs)}>
<script type="text/javascript+protovis">
${w.init_js.src}
var vis = new pv.Panel()
% for f in w._pv_prop_funcs:
	${f.src}
% endfor
% for a in w._adds:
${a.display()}
% endfor
vis.render();
</script>
</div>

LineChart
  • pvcls
    • None
  • p_width
    • The width of the panel, in pixel.
  • p_height
    • The height of the panel, in pixels.
  • p_bottom
    • The bottom margin, in pixels.
  • p_top
    • The top margin, in pixels.
  • p_left
    • The left margin, in pixels.
  • p_right
    • The right margin, in pixels.
  • init_js
    • JSSymbol
  • p_interpolate
    • How to interpolate between values. Linear interpolation ("linear") is the default, producing a straight line between points. For piecewise constant functions (i.e., step functions), either "step-before" or "step-after" can be specified. To draw a clockwise circular arc between points, specify "polar"; to draw a counter clockwise circular arc between points, specify "polar-reverse". To draw open uniform b-splines, specify "basis". To draw cardinal splines, specify "cardinal"; see also #tension.
  • p_line_width
    • Floating point.
  • p_time_series
    • Convert from "seconds since the epoch"?
  • p_time_series_format
    • strftime-type format for time strings. See http://vis.stanford.edu/protovis/jsdoc/symbols/pv.Format.date.html
class DemoLineChart(LineChart):
    class AutoRefreshingData(object):
        """ Helper class for DemoLineChart.  Refreshes its data dynamically. """
        def __iter__(self):
            n = 20.0
            T_scale = 1000.0
            now = int(time.time())
            tspan = range(now-100, now)
            funcs = [
                lambda t : math.sin(t/n),
                lambda t : abs(math.sin(t/n))**((t%(2*n))/n),
                lambda t : math.cos(t/(n+1))*1.5,
            ]
            funcs.append(
                lambda t : funcs[1](t) * funcs[2](t)
            )
            for i in range(len(funcs)):
                yield [ { 'x': t*1000.0, 'y' : funcs[i](float(t)) }
                       for t in tspan ]
        def __repr__(self):
            print "repr"
            return str(self)
        def __str__(self):
            return str([ele for ele in self])
        def __len__(self):
            return 4
    p_data = AutoRefreshingData()
    p_labels = ["billy", "bobby", "sally", "suzie"]
    p_time_series = True
    p_time_series_format = "%I:%M:%S"
<%namespace name="tw" module="tw2.core.mako_util"/>
<div ${tw.attrs(attrs=w.attrs)}>
<script type="text/javascript+protovis">
${w.init_js.src}
var vis = new pv.Panel()
% for f in w._pv_prop_funcs:
	${f.src}
% endfor
% for a in w._adds:
${a.display()}
% endfor
vis.render();
</script>
</div>

StackedAreaChart
  • pvcls
    • None
  • p_width
    • The width of the panel, in pixel.
  • p_height
    • The height of the panel, in pixels.
  • p_bottom
    • The bottom margin, in pixels.
  • p_top
    • The top margin, in pixels.
  • p_left
    • The left margin, in pixels.
  • p_right
    • The right margin, in pixels.
  • init_js
    • JSSymbol
  • p_time_series
    • Convert from "seconds since the epoch"?
  • p_time_series_format
    • strftime-type format for time strings. See http://vis.stanford.edu/protovis/jsdoc/symbols/pv.Format.date.html
class DemoStackedAreaChart(StackedAreaChart):
    class AutoRefreshingData(object):
        """ Helper class for DemoLineChart.  Refreshes its data dynamically. """
        def __iter__(self):
            n = 20.0
            T_scale = 1000.0
            now = int(time.time())
            tspan = range(now-100, now)
            funcs = [
                lambda t : math.sin(t/n),
                lambda t : abs(math.sin(t/n))**((t%(2*n))/n),
                lambda t : math.cos(t/(n+1))*1.5,
            ]
            funcs.append(
                lambda t : funcs[1](t) * funcs[2](t)
            )
            for i in range(len(funcs)):
                yield [ { 'x': t*1000.0, 'y' : abs(funcs[i](float(t))) }
                       for t in tspan ]
        def __repr__(self):
            print "repr"
            return str(self)
        def __str__(self):
            return str([ele for ele in self])
        def __len__(self):
            return 4
    p_data = AutoRefreshingData()
    p_labels = ["billy", "bobby", "sally", "suzie"]
    p_time_series = True
    p_time_series_format = "%I:%M:%S"
<%namespace name="tw" module="tw2.core.mako_util"/>
<div ${tw.attrs(attrs=w.attrs)}>
<script type="text/javascript+protovis">
${w.init_js.src}
var vis = new pv.Panel()
% for f in w._pv_prop_funcs:
	${f.src}
% endfor
% for a in w._adds:
${a.display()}
% endfor
vis.render();
</script>
</div>

GroupedBarChart
  • pvcls
    • None
  • p_width
    • The width of the panel, in pixel.
  • p_height
    • The height of the panel, in pixels.
  • p_bottom
    • The bottom margin, in pixels.
  • p_top
    • The top margin, in pixels.
  • p_left
    • The left margin, in pixels.
  • p_right
    • The right margin, in pixels.
  • init_js
    • JSSymbol
  • p_show_values
    • bool -- show values on bars
class DemoGroupedBarChart(GroupedBarChart):
    p_data = [
        [random.random() + 0.1 for j in range(4)] for i in range(3)]
    p_labels = ['DataSet1', 'Dataset2', 'Dataset3']
<%namespace name="tw" module="tw2.core.mako_util"/>
<div ${tw.attrs(attrs=w.attrs)}>
<script type="text/javascript+protovis">
${w.init_js.src}
var vis = new pv.Panel()
% for f in w._pv_prop_funcs:
	${f.src}
% endfor
% for a in w._adds:
${a.display()}
% endfor
vis.render();
</script>
</div>