changeset 140:9acea302899a

preparing for d3
author Jeff Hammel <k0scist@gmail.com>
date Mon, 30 Mar 2015 10:45:47 -0700
parents ce0e1e5efe77
children 310290f95787
files numerics/bar.py
diffstat 1 files changed, 12 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/numerics/bar.py	Mon Mar 30 10:35:59 2015 -0700
+++ b/numerics/bar.py	Mon Mar 30 10:45:47 2015 -0700
@@ -7,20 +7,27 @@
 See:
 - http://bokeh.pydata.org/tutorial/solutions/gallery/olympics.html
 - http://bokeh.pydata.org/en/latest/tutorial/topical.html
-- 
+- https://gist.github.com/mbostock/7322386
 """
 
 # imports
 import argparse
+import os
 import sys
 import tempfile
 from .data import transpose
 from .manipulate import ManipulationParser
-from bokeh.plotting import figure, output_file, show, VBox
 from collections import OrderedDict
 
 __all__ = ['bar_chart', 'BarChartParser', 'main']
 
+# template info
+# TODO: own module
+here = os.path.dirname(os.path.abspath(__file__))
+templates = os.path.join(here, 'templates')
+template = os.path.join(here, 'bar.d3.html')
+d3 = os.path.join(here, 'javascript', 'd3.v3.min.js')
+
 
 def bar_chart(data, output, title=None):
     """
@@ -32,27 +39,6 @@
     # TODO:  abstract this to a plot class
 
 
-    # create a figure
-    p1 = figure(title=title,
-                tools="pan,wheel_zoom,box_zoom,reset,resize",
-                x_range=data[0]
-            )
-    # see https://github.com/bokeh/bokeh/blob/master/bokeh/plotting_helpers.py#L277
-    # for _known_tools
-
-
-    if not len(data) == 2:
-        raise NotImplementedError('TODO') # -> record TODO items
-
-    p1.rect(x=data[0], y=data[1], height=data[1], width=0.2)
-    show(VBox(p1))
-
-#    bar = Bar(data, tools="pan,wheel_zoom,box_zoom,reset,resize")
-#    bar.filename(output)
-#    bar.width(len(data)*50)
-#    bar.show()
-
-
 class BarChartParser(ManipulationParser):
     """command line options parser for bar charts"""
     # TODO: upstream to PlotParser
@@ -87,21 +73,12 @@
     data = parser.typed_data()
 
     # ensure a mapping is given
-    if len(data) == 1:
-        data.insert(0, range(len(data[-1])))
-    if len(data) != 2:
-        parser.error("A mapping is required")
-#    mapping = OrderedDict(transpose(data))
-
+    if len(data) != 1:
+        raise NotImplementedError("TODO")
 
     # generate bar chart
-    bar_chart(data, parser.plot_filename(), title=options.title)
-#    bar_chart(data, options.output, title=options.title)
+#    bar_chart(data, parser.plot_filename(), title=options.title)
 
-# BBB keeping this around for reference;
-# we should probably move to a better parsing system at some point
-# parse file
-#    data = pd.read_csv(options.input, header=None, names=options.columns, index_col=0)
 
 if __name__ == '__main__':
     main()