1. Ralph Bean
  2. tw2.protovis.core

Commits

Ralph Bean  committed 1d49821

refactoring still

  • Participants
  • Parent commits 86b5fdc
  • Branches default

Comments (0)

Files changed (14)

File .gitignore

View file
 README.pdf
 dist
 *.egg
+*.egg*

File tw2/protovis/core/__init__.py

View file
 """
-This package contains the basic protovis widgets.
+This package contains the basic core protovis resources to be
+used by the widgets packaged in the following:
+
+    - tw2.protovis.conventional
+    - tw2.protovis.custom
+    - tw2.protovis.interaction
+    - tw2.protovis.hierarchies
+    - tw2.protovis.networks
+    - tw2.protovis.maps
+    - tw2.protovis.stats
+    - tw2.protovis.art
 
 Get this source from http://github.com/ralphbean/tw2.protovis
 
 Protovis itself can be found here:  http://vis.stanford.edu/protovis/
 """
 
-__basename__ = "protovis"
-__version__ = "3.2"
-
 from widgets import *

File tw2/protovis/core/defaults.py

View file
+
+__basename__ = "protovis"
+__version__ = "3.2"
+

File tw2/protovis/core/resources.py

View file
+
+import tw2.core as twc
+from tw2.protovis.core.defaults import __basename__, __version__
+modname = ".".join(__name__.split('.')[:-1])
+
+pv_js = twc.JSLink(
+    modname=modname, filename='static/%s/%s/protovis.js' % (
+        __basename__, __version__))
+

File tw2/protovis/core/templates/panel.html

View file
+<div xmlns:py="http://genshi.edgewall.org/" py:attrs="w.attrs">
+<script type="text/javascript">
+var vis = new pv.Panel()
+    .width($w.width)
+    .height($w.height);
+
+vis.add(pv.Rule)
+    .data(pv.range(0, 2, .5))
+    .bottom(function(d) { return d * 80 + .5} )
+    .add(pv.Label);
+
+var bar = vis.add(pv.Bar);
+bar.data([1, 1.2, 1.7, 1.5, .7, .3])
+    .width(20)
+    .bottom(0)
+    .height(function(d) {return d * 80})
+    .left(function() {return this.index * 25 + 25});
+
+vis.render();
+
+</script>
+</div>

File tw2/protovis/core/templates/panel.mak

View file
+<div style="text-align:center; overflow:hidden; background-color:${w.backgroundcolor}; width: ${w.width}; height: ${w.height};" id="${w.compound_id}"></div>

File tw2/protovis/core/templates/protovis.html

-<div style="text-align:center; overflow:hidden; background-color:$w.backgroundcolor; width: $w.width; height: $w.height;" id="$w.compound_id"></div>

File tw2/protovis/core/templates/protovis.mak

-<div style="text-align:center; overflow:hidden; background-color:${w.backgroundcolor}; width: ${w.width}; height: ${w.height};" id="${w.compound_id}"></div>

File tw2/protovis/core/widgets.py

View file
+"""
+TODO
+"""
+
+import tw2.core as twc
+
+import tw2.protovis.core.resources as res
+
+class PVPanel(twc.Widget):
+    template = "genshi:tw2.protovis.core.templates.panel"
+    resources = [res.pv_js]
+   
+    width = twc.Param('(string) widget width', default='150', attribute=True)
+    height = twc.Param('(string) widget height', default='150', attribute=True)
+

File tw2/protovis/core/widgets/__init__.py

-
-from tw2.jit.widgets.chart import (AreaChart, BarChart, PieChart)
-from tw2.jit.widgets.graph import (ForceDirectedGraph, RadialGraph)
-from tw2.jit.widgets.tree import (SpaceTree, HyperTree, Sunburst,
-                                  Icicle, TreeMap)

File tw2/protovis/core/widgets/chart.py

-import tw2.core as twc
-from tw2.jit.widgets.core import JitWidget
-
-class JitChart(JitWidget):
-    """ Baseclass common to all chart widgets """
-    type = twc.Param(
-        '(string) Stack style.  Possible values are ' + 
-        '"stacked", "stacked:gradient" to add gradients.',
-        default='stacked:gradient', attribute=True)
-
-    showLabels = twc.Param(
-        '(boolean) Display the slot names.', default=True, attribute=True)
-
-    labelOffset = twc.Param(
-        '(number) Adds margin between the label and the ' +
-        'default place where it should be drawn.',
-        default=3, attribute=True)
-
-class AreaChart(JitChart):
-    """ A visualization that displays stacked area charts.
-
-    See thejit API documentation on AreaChart:
-        http://thejit.org/static/v20/Docs/files/Visualizations/AreaChart-js.html
-    """
-
-    jitClassName = 'AreaChart'
-    
-    selectOnHover = twc.Param(
-        '(boolean) Add a mark to the hovered stack.',
-        default=True, attribute=True)
-    
-    filterOnClick = twc.Param(
-        '(boolean) Select the clicked stack and hide others.',
-        default=True, attribute=True)
-
-    restoreOnRightClick = twc.Param(
-        '(boolean) Show all stacks by right clicking.',
-        default=True, attribute=True)
-    
-    showAggregates = twc.Param(
-        '(boolean) Display the sum of the stack values.',
-        default=True, attribute=True)
-
-
-class BarChart(JitChart):
-    """ A visualization that displays stacked bar charts.
-
-    See thejit API documentation on BarChart:
-        http://thejit.org/static/v20/Docs/files/Visualizations/BarChart-js.html
-    """
-
-    jitClassName = 'BarChart'
-    
-    barsOffset = twc.Param(
-        '(number) Separation between bars.', default=0, attribute=True)
-
-    hoveredColor = twc.Param(
-        '(string) The color for a hovered bar stack.',
-        default='#9fd4ff', attribute=True)
-
-    orientation = twc.Param(
-        '(string) The direction of the bars.  ' + 
-        'Possible options are "vertical" and "horizontal".',
-        default='horizontal', attribute=True)
-    
-    showAggregates = twc.Param(
-        '(boolean) Display the sum of the stack values.',
-        default=True, attribute=True)
-
-
-class PieChart(JitChart):
-    """ A visualization that displays stacked pie charts.
-
-    See thejit API documentation on PieChart:
-        http://thejit.org/static/v20/Docs/files/Visualizations/PieChart-js.html
-    """
-
-    jitClassName = 'PieChart'
-    
-    sliceOffset = twc.Param(
-        '(number) Separation between slices.', default=0, attribute=True)
-
-    hoveredColor = twc.Param(
-        '(string) Sets the selected color for a hovered pie stack.',
-        default='#9fd4ff', attribute=True)
-
-    resizeLabels = twc.Param(
-        '(boolean|number) Resize the pie labels according to ' +
-        'their stacked values.  Set a number for resizeLabels ' +
-        'to set a font size minimum.',
-        default=False, attribute=True)
-
-    updateHeights = twc.Param(
-        '(boolean) Only for mono-valued (most common) pie ' +
-        'charts.  Resize the height of the pie slices ' +
-        'according to their current values.',
-        default=False, attribute=True)
-   

File tw2/protovis/core/widgets/core.py

-"""
-This file contains baseclasses for thejit widgets
- - JitWidget - contains parameters common to all jit widgets
- - JitTreeOrGraphWidget - contains parameters common to Tree and Graph Widgets
-"""
-
-import tw2.core as twc
-from tw2.core.resources import JSLink, CSSLink
-from tw2.core.resources import JSSymbol, JSFuncCall
-from tw2.core.resources import JSSource
-from tw2.core.resources import encoder
-from tw2.core.widgets import WidgetMeta
-from tw2.core.widgets import Widget
-
-from tw2.protovis import __basename__, __version__
-
-# TODO -- the tw2 devtools give me __name__ as tw2.jit.widgets but the resources are all in tw2.jit/static
-modname = ".".join(__name__.split('.')[:-1])
-modname = ""
-
-pv_js = JSLink(modname='tw2.protovis',
-               filename='%s/%s/protovis.js' % (__basename__, __version__))
-
-class PVMark(twc.Widget):
-    template = "tw2.protovis.templates.pvpanel"
-
-class PVPanel(twc.Widget):
-    template = "tw2.protovis.templates.pvpanel"
-    resources = [pv_js]
-   
-    # Internal twc Variables:
-    jitClassName = twc.Variable('Name of the Jit class for this widget')
-    jitSecondaryClassName = twc.Variable(
-        'Secondary Jit class for this widget', default=None)
-
-    injectInto = twc.Variable(
-        'name of the DOM element containing the canvas',
-        attribute=True, default=property(lambda s: s.compound_id))
-    config = twc.Variable( 'jsonified version of other attrs.', default={} )
-    # End internal twc Variables
-
-    # Start twc Params
-    postInitJSCallback = twc.Param(
-        'javascript to run after client-side initialization of the widget',
-        default=JSSymbol(src='(function(jitwidget){})'))
-    
-    data = twc.Param('python data to be jsonified and passed to the widget')
-    # End twc Params
-
-    # Start twc Attributes
-    backgroundcolor = twc.Param(
-        '(string) background color of the jit container div',
-        default='#3a3a3a', attribute=True)
-
-    width = twc.Param('(string) widget width', default='500', attribute=True)
-
-    height = twc.Param('(string) widget height', default='500', attribute=True)
-    
-    animate = twc.Param(
-        '(boolean) Whether to add animated transitions.',
-        default=True, attribute=True)
-    
-    duration = twc.Param(
-        '(number) Duration of the animation in milliseconds.',
-        default=1000, attribute=True)
-
-    fps = twc.Param(
-        '(number) Frames per second of the animation.',
-        default=45, attribute=True)
-    
-    offset = twc.Param(
-        '(number) Margin between the display and the canvas.',
-        default=25, attribute=True)
-
-    Canvas = twc.Param(
-        '(dict) Of the form Options.Canvas in the jit docs.', attribute=True,
-        default = {
-            'width' : False,
-            'height' : False,
-            'useCanvas' : False,
-            'withLabels' : True,
-            'background' : False
-        })
-
-    Label = twc.Param(
-        '(dict) Of the form Options.Label in the jit docs.', attribute=True,
-        default={
-            'overridable' : False,
-            'type': 'HTML',
-            'style' : ' ',
-            'size': 10,  
-            'family': 'sans-serif',
-            'textAlign' : 'center',
-            'textBaseline' : 'alphabetic',
-            'color': 'white',
-        })
-    Tips = twc.Param(
-        '(dict) Of the form of Options.Tips in the jit docs.', attribute=True,
-        default={
-            'enable' : False,  
-            'type' : 'auto',  
-            'offsetX' : 20,  
-            'offsetY' : 20,  
-            'onShow' : "(function() {})",
-            'onHide' : "(function() {})",
-        })
-    Events = twc.Param(
-        '(dict) Of the form Options.Events in the jit docs.', attribute=True,
-        default={
-            'enable': False,  
-            'type': 'auto',  
-            'onClick': '(function() {})',  
-            'onRightClick': '(function() {})',  
-            'onMouseMove': '(function() {})',  
-            'onMouseEnter': '(function() {})',  
-            'onMouseLeave': '(function() {})',  
-            'onDragStart': '(function() {})',  
-            'onDragMove': '(function() {})',  
-            'onDragCancel': '(function() {})',  
-            'onDragEnd': '(function() {})',  
-            'onTouchStart': '(function() {})',  
-            'onTouchMove': '(function() {})',  
-            'onTouchEnd': '(function() {})',  
-            'onTouchCancel': '(function() {})',  
-            'onMouseWheel': '(function() {})' 
-        })
-    # End twc attrs
-
-    def prepare(self):
-        super(JitWidget, self).prepare()
-        
-        composite_js_call = CompoundJSSource(
-            setupcall = JSFuncCall(
-                function='var jitwidget = setupTW2JitWidget',
-                args=[
-                    self.jitClassName,
-                    self.jitSecondaryClassName,
-                    self.attrs
-                ]),
-            loadcall = JSFuncCall(
-                function='jitwidget.loadJSON',
-                args=[self.data],),
-            postcall = JSSource(src=self.postInitJSCallback.src+'(jitwidget)')
-        )
-
-        self.resources.append(composite_js_call)
-
-
-    
-class JitTreeOrGraphWidget(JitWidget):
-    """ Baseclass common to all Tree and Graph JitWidgets """
-
-    # TODO - http://thejit.org/static/v20/Docs/files/Options/Options-Controller-js.html#Options.Controller
-    Navigation = twc.Param(
-        '(dict) Panning and zooming options for Graph/Tree visualziations.',
-        default={
-            'enable': False,
-            'type': 'auto',
-            'panning': False, #True, 'avoid nodes'  
-            'zooming': False
-        }, attribute=True)
- 
-    Node = twc.Param(
-        '(dict) Provides Node rendering options for ' +
-        'Tree and Graph based visualizations.',
-        default = {
-    #        'overridable': False,  
-    #        'type': 'circle',  
-            'color': '#ccb',  
-            'alpha': 1,  
-            'dim': 3,  
-            'height': 20,  
-            'width': 90,  
-            'autoHeight': False,  
-            'autoWidth': False,  
-            'lineWidth': 1,  
-            'transform': True,  
-            'align': "center",  
-            'angularWidth':1,  
-            'span':1,  
-            'CanvasStyles': {}  
-        }, attribute=True)
-
-    Edge = twc.Param(
-        "(dict) Provides Edge rendering options for " +
-        "Tree and Graph based visualizations.",
-        default = {
-    #        'overridable': False,
-    #        'type': 'line',  
-            'color': '#ccb',  
-            'lineWidth': 1,  
-            'dim':15,  
-            'alpha': 1,  
-            'CanvasStyles': {} 
-        }, attribute=True)
-
-    onBeforeCompute = twc.Param(
-        "(javascript) This method is called right before performing all " +
-        "computations and animations.  The selected Graph.Node " +
-        "is passed as parameter.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
-
-    onAfterCompute = twc.Param(
-        "(javascript) This method is triggered after all animations " +
-        "or computations ended.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
-
-    onCreateLabel = twc.Param(
-        "(javascript) This method receives a new label DIV element as " +
-        "first parameter, and the corresponding Graph.Node  as second " +
-        "parameter.  This method will only be called once for each label.  " +
-        "This method is useful when adding events or styles to the labels " +
-        "used by the JIT.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
-
-    onPlaceLabel = twc.Param(
-        "(javascript) This method receives a label DIV element as first " +
-        "parameter and the corresponding Graph.Node  as second parameter.  " +
-        "This method is called each time a label has been placed in the " +
-        "visualization, for example at each step of an animation, and thus " +
-        "it allows you to update the labels properties, such as size or " +
-        "position.  Note that onPlaceLabel will be triggered after updating " +
-        "the labels positions.  That means that, for example, the left and " +
-        "top css properties are already updated to match the nodes " +
-        "positions.  Width and height properties are not set however.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
-
-    onBeforePlotNode = twc.Param(
-        "(javascript) This method is triggered right before plotting " +
-        "each Graph.Node.  This method is useful for changing a node " +
-        "style right before plotting it.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
-
-    onAfterPlotNode = twc.Param(
-        "(javascript) This method is triggered right after plotting " +
-        "each Graph.Node.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
-
-    onBeforePlotLine = twc.Param(
-        "(javascript) This method is triggered right before plotting " +
-        "a Graph.Adjacence.  This method is useful for adding some " +
-        "styles to a particular edge before being plotted.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)
-
-    onAfterPlotLine = twc.Param(
-        "(javascript) This method is triggered right after plotting " +
-        "a Graph.Adjacence.",
-        default=JSSymbol(src="(function(node) {})"), attribute=True)

File tw2/protovis/core/widgets/graph.py

-import tw2.core as twc
-from tw2.core.resources import JSSymbol
-
-from tw2.jit.widgets.core import JitTreeOrGraphWidget
-from tw2.jit.widgets.core import jit_js
-
-class JitGraph(JitTreeOrGraphWidget):
-    """ Baseclass for graph widgets """
-    pass
-
-class RadialGraph(JitGraph):
-    """ A radial graph visualization with advanced animations.
-
-    See thejit API documentation on RadialGraph:
-        http://thejit.org/static/v20/Docs/files/Visualizations/RGraph-js.html
-    """
-
-    jitClassName = 'RGraph'
-
-    background = twc.Param(
-        '(dict) see sample.', default={},
-        attribute=True, request_local=False)
-   
-class ForceDirectedGraph(JitGraph):
-    """ A visualization that lays graphs using a Force-Directed layout algorithm.
-
-    See thejit API documentation on ForceDirectedGraph:
-        http://thejit.org/static/v20/Docs/files/Visualizations/ForceDirected-js.html
-    """
-
-    jitClassName = 'ForceDirected'
-    
-    iterations = twc.Param(
-        '(number) The number of iterations for the spring ' +
-        'layout simulation.  Depending on the browser\'s ' +
-        'speed you could set this to a more "interesting" ' +
-        'number, like 200.',
-        default=2, attribute=True, request_local=False)
-    
-    levelDistance = twc.Param(
-        '(number) The natural length desired for the edges.',
-        default=50, attribute=True, request_local=False)
-

File tw2/protovis/core/widgets/tree.py

-import tw2.core as twc
-from tw2.core.resources import JSSymbol, CSSLink
-
-from tw2.jit.widgets.core import JitTreeOrGraphWidget
-from tw2.jit.widgets.core import jit_js, jit_css, modname
-
-treemap_css = CSSLink(modname=modname, filename="static/css/Treemap.css")
-sunburst_css = CSSLink(modname=modname, filename="static/css/Sunburst.css")
-
-class JitTree(JitTreeOrGraphWidget):
-    """ Baseclass common to all jit tree widgets """
-    
-    constrained = twc.Param(
-        '(boolean) Whether to show the entire tree when loaded ' +
-        'or just the number of levels specified by levelsToShow.',
-        default=False, attribute=True)
-
-    levelsToShow = twc.Param(
-        '(number) The number of levels to show for a subtree.  This ' +
-        'number is relative to the selected node.',
-        default=3, attribute=True)
-
-
-class TreeMap(JitTree):
-    """ A squarified TreeMap visualization.
-
-    'Strip' and 'SliceAndDice' variations not yet supported.
-
-    See thejit API documentation on TreeMap:
-        http://thejit.org/static/v20/Docs/files/Visualizations/Treemap-js.html
-    """
-
-    def prepare(self):
-        super(TreeMap, self).prepare()
-        self.resources.extend([jit_css, treemap_css])
-    
-    jitClassName = 'TM'
-    jitSecondaryClassName = 'Squarified'
-
-    offset = twc.Param(
-        '(number) Margin between boxes.', default=2, attribute=True)
-    
-    cushion = twc.Param(
-        '(boolean) Cushion Gradients', default=False, attribute=True)
-
-    titleHeight = twc.Param(
-        '(number) The height of the title rectangle for non-leaf nodes.',
-        default=13, attribute=True)
-    
-    orientation = twc.Param(
-        '(string) Whether to set horizontal or vertical layout.  ' +
-        'Possible values are "h" or "v".', default='h', attribute=True)
-
-    titleHeight = twc.Param(
-        '(number) Separation between the center of the ' +
-        'canvas and each pie slice.', default=13, attribute=True)
-   
-    Events = twc.Param(
-        '(dict) Of the form Options.Events in the jit docs.',
-        default={
-            'enable': True,
-            'onClick': JSSymbol(src='(function(node) {if (node) {jitwidget.enter(node);}})'),
-            'onRightClick': JSSymbol(src='(function() {jitwidget.out();})'),
-        }, attribute=True)
-
-    # TODO - Node.Type 
-    #see http://thejit.org/static/v20/Docs/files/Visualizations/Treemap-js.html
-
-class Sunburst(JitTree):
-    """ A radial space filling tree visualization.
-
-    See thejit API documentation on Sunburst:
-        http://thejit.org/static/v20/Docs/files/Visualizations/Sunburst-js.html
-    """
-    def prepare(self):
-        super(Sunburst, self).prepare()
-        self.resources.extend([jit_css, sunburst_css])
-
-    jitClassName = 'Sunburst'
-
-    levelDistance = twc.Param(
-        '(number) Distance between levels.',
-        default=90, attribute=True, request_local=False)
-
-class HyperTree(JitTree):
-    """ A Hyperbolic Tree/Graph visualization.
-
-    See thejit API documentation on HyperTree:
-        http://thejit.org/static/v20/Docs/files/Visualizations/Hypertree-js.html
-    """
-
-    jitClassName = 'Hypertree'
-    
-    w = twc.Variable( 'width of the canvas.', default=500 )
-    h = twc.Variable( 'height of the canvas.', default=500 )
-    
-    def prepare(self):
-        super(HyperTree, self).prepare()
-        self.w = self.width
-        self.h = self.height
-
-    offset = twc.Param(
-        '(number) A number in the range [0, 1) that will be subtracted to ' +
-        'each node position to make a more compact HyperTree.  This will ' +
-        'avoid placing nodes too far from each other when there is a ' +
-        'selected node.',
-        default=0, attribute=True)
-
-class SpaceTree(JitTree):
-    """ A Tree layout with advanced contraction and expansion animations.
-
-    See thejit API documentation on SpaceTree:
-        http://thejit.org/static/v20/Docs/files/Visualizations/Spacetree-js.html
-    """
-
-    jitClassName = 'ST'
-   
-    transition = twc.Param(
-        '(javascript) Javascript to perform transition.',
-        default=JSSymbol(src='$jit.Trans.Quart.easeInOut'), attribute=True)
-
-    levelDistance = twc.Param(
-        '(number) The distance between two consecutive levels of the tree.',
-        default=30, attribute=True)
-
-    offsetX = twc.Param(
-        '(number) The x-offset distance from the' +
-        'selected node to the center of the canvas.',
-        default=0, attribute=True)
-
-    offsetY = twc.Param(
-        '(number) The y-offset distance from the' +
-        'selected node to the center of the canvas.',
-        default=0, attribute=True)
-
-class Icicle(JitTree):
-    """ Icicle space filling visualization.
-
-    See thejit API documentation on Icicle:
-        http://thejit.org/static/v20/Docs/files/Visualizations/Icicle-js.html
-    """
-
-    jitClassName = 'Icicle'
-    
-    offset = twc.Param('(number) Boxes offset', default=2, attribute=True)
-