Skip to content

Commit

Permalink
update python module to match new command format
Browse files Browse the repository at this point in the history
  • Loading branch information
szym committed Feb 18, 2016
1 parent edc31ca commit a3b15ec
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def send(**command):
return False


def pane(panetype, win, title, content):
win = win or uid()
send(command='pane', type=panetype, id=win, title=title, content=content)
return win


def normalize(img, opts):
minval = opts.get('min')
if minval is None:
Expand All @@ -51,7 +57,6 @@ def to_rgb(img):

def image(img, **opts):
assert img.ndim == 2 or img.ndim == 3
win = opts.get('win') or uid()

if isinstance(img, list):
return images(img, opts)
Expand All @@ -61,10 +66,11 @@ def image(img, **opts):
pngbytes = png.encode(img.tostring(), img.shape[1], img.shape[0])
imgdata = 'data:image/png;base64,' + base64.b64encode(pngbytes).decode('ascii')

send(command='image', id=win, src=imgdata,
labels=opts.get('labels'),
width=opts.get('width'),
title=opts.get('title'))
return pane('image', opts.get('win'), opts.get('title'), content={
'src': imgdata,
'labels': opts.get('labels'),
'width': opts.get('width'),
})
return win


Expand All @@ -81,8 +87,6 @@ def plot(data, **opts):
labels: list of series names, first series is always the X-axis
see http://dygraphs.com/options.html for other supported options
"""
win = opts.get('win') or uid()

dataset = {}
if type(data).__module__ == numpy.__name__:
dataset = data.tolist()
Expand All @@ -98,6 +102,5 @@ def plot(data, **opts):
# Don't pass our options to dygraphs.
options.pop('win', None)

send(command='plot', id=win, title=opts.get('title'), options=options)
return win
return pane('plot', opts.get('win'), opts.get('title'), content=options)

0 comments on commit a3b15ec

Please sign in to comment.