# HG changeset patch # User Jeff Hammel # Date 1431473137 25200 # Node ID 69940819bc8afbc60625180fd1dcc75a805b1d28 # Parent 2a124febcd49f116d82df233877258321e48e190 allow for labels in an assenine way diff -r 2a124febcd49 -r 69940819bc8a numerics/bar.py --- a/numerics/bar.py Tue May 12 16:04:05 2015 -0700 +++ b/numerics/bar.py Tue May 12 16:25:37 2015 -0700 @@ -30,7 +30,7 @@ d3 = f.read() -def bar_chart(data, title=None): +def bar_chart(data, labels=None, title=None): """ create a bar chart @@ -38,10 +38,13 @@ - http://bokeh.pydata.org/en/latest/tutorial/solutions/gallery/olympics.html """ # TODO: abstract this to a plot class + if labels is None: + labels = data template = tempita.Template.from_filename(bar_template) bar_chart = template.substitute(title=title or '', d3=d3, + labels=json.dumps(labels), data=json.dumps(data)) return bar_chart @@ -67,13 +70,17 @@ data = parser.typed_data() # ensure a mapping is given - if len(data) != 1: - raise NotImplementedError("TODO") + if len(data) == 1: + data = data[0] + labels = None + elif len(data) ==2: + labels = data[0] + data = data[1] else: - data = data[0] + raise NotImplementedError('TODO') # generate bar chart - options.output.write(bar_chart(data, title=options.title)) + options.output.write(bar_chart(data, labels=labels, title=options.title)) if options.output != sys.stdout: # print URL of file diff -r 2a124febcd49 -r 69940819bc8a numerics/templates/bar.d3.html --- a/numerics/templates/bar.d3.html Tue May 12 16:04:05 2015 -0700 +++ b/numerics/templates/bar.d3.html Tue May 12 16:25:37 2015 -0700 @@ -21,8 +21,9 @@