from bokeh.io import vform, HBox
from bokeh.models import CustomJS, ColumnDataSource, Slider
from bokeh.plotting import Figure, output_file, show, output_notebook
import numpy as np
import math

output_file("sinusoidal_tline_voltages_test.html")
#output_notebook()

zmin = -20.0
zmax = 0.0
numpnts = 500
twopi = 2.0*math.pi
freq_Hz = 100e6
velocity_mps = 2e8
wavelength_m = velocity_mps / freq_Hz

z = [((zmax-zmin)*i/numpnts + zmin) for i in range(0, numpnts)]
v_forward = [math.cos(twopi*zz/wavelength_m) for zz in z]

source = ColumnDataSource(data=dict(z=z, v_forward=v_forward), name='mycolumndatasource')

plot = Figure(plot_width=400, plot_height=400, y_range=(-2.1,2.1))
plot.line('z', 'v_forward', source=source, line_width=3, line_alpha=0.6)

def callback(source=source):
    data = source.get('data')
    f = cb_obj.get('value')
    z, v_forward = data['z'], data['v_forward']
    for i in range(len(z)):
        v_forward[i] = Math.cos(z[i]*f)
        #y[i] = Math.pow(x[i], f)
    source.trigger('change')

slider = Slider(start=0.1, end=4, value=1, step=.1, title="power",
                callback=CustomJS.from_py_func(callback))
slider2 = Slider(start=0.1, end=4, value=1, step=.1, title="power2",
                callback=CustomJS.from_py_func(callback))

# Use HBox to set the width of the slider. Without HBox the slider
# is the full width of the webpage
layout = vform(HBox(slider, width=300), HBox(slider2, width=300), plot)

show(layout)
