""" Samples of how to use tw2.jitEach class exposed in the widgets submodule has an accompanying Demo<class>widget here with some parameters filled out.The demos implemented here are what is displayed in the tw2.devtoolsWidgetBrowser."""fromwidgetsimportAreaChart,BarChart,StreamGraphfromwidgetsimportjsfromtw2.coreimportJSSymbolimportmathimportrandomclassDemoAreaChart(AreaChart):p_data=[{'x':i,'y':math.sin(i)+random.random()*.5+2}foriinmap(lambdax:x/10.0,range(100))]classDemoBarChart(BarChart):p_data=[random.random()foriinrange(10)]# The following are some data generation functions used by the streamgraph demodefwaves(n,m):deff(i,j):x=20*j/m-i/3ifx>0:return2*x*math.exp(x*-0.5)return0returnmap(lambdai:map(lambdaj:f(i,j),range(m)),range(n))deflayers(n,m):defbump(a):x=1.0/(.1+random.random())y=2.0*random.random()-0.5z=10.0/(0.1+random.random())foriinrange(m):w=(float(i)/m-y)*za[i]+=x*math.exp(-w*w)returnadeff(*args):a=[0]*mforiinrange(5):a=bump(a)returnareturnmap(f,range(n))classDemoStreamGraph(StreamGraph):defprepare(self):self.p_data=layers(20,400)super(DemoStreamGraph,self).prepare()