def _generate_device_plot(self, device_events): data_source = self._convert_events_to_datasource( device_events['events']) n_rows = device_events['n_rows'] if n_rows == 0: n_rows = 1 elif n_rows == 1: n_rows = 2 name = device_events['name'] plot = figure( title="{}".format(name), plot_height=20 * n_rows + 60, plot_width=1200, tools=self._tools, sizing_mode='stretch_both', # sizing_mode='scale_width', active_scroll='xwheel_zoom') plot.hbar(left='start', right='end', y='height', color='color', height=0.85, source=data_source, hover_fill_alpha=0.5, line_join='round', line_cap='round', hover_line_color='red') plot.x_range = Range1d(0, self._iteration_time, bounds="auto") plot.y_range = Range1d(0, n_rows) plot.yaxis.visible = False plot.ygrid.ticker = SingleIntervalTicker(interval=1) plot.ygrid.grid_line_color = None plot.ygrid.band_fill_alpha = 0.1 plot.ygrid.band_fill_color = "gray" button = Button(label=" Sync", width=20, button_type='primary', disabled=True) button.css_classes = ['xl-hidden'] button.js_on_click( CustomJS(args={ 'me': plot, }, code=self._js_update_ranges)) plot.x_range.js_on_change( 'start', CustomJS(args={ 'button': button, }, code=self._js_on_change_callback)) return plot, WidgetBox(button)
delta_6_months = date.today() + relativedelta(months=-6) delta_year = date.today() + relativedelta(years=-1) delta_5_year = date.today() + relativedelta(years=-5) dates = [delta_7_days, delta_month, delta_3_months, delta_6_months,delta_year, delta_5_year, date.today()] map_ints = map(lambda date: time.mktime(date.timetuple()) * 1000, dates) date_ints = [date_int for date_int in map_ints] tools_lst = "pan,wheel_zoom,box_zoom,reset" date_titles = ["week", "month", "3 months", "6 months", "1 year", "3 years"] text_input = TextInput(value="NFLX") text_input.css_classes = ["text-input"] button = Button(label="main") button2 = Button(label="submit") button2.css_classes = ["button"] output=Paragraph() radio_button_group = RadioButtonGroup( labels=["1w", "1m", "3m", "6m", "1y", "5y"], active=5) radio_button_group.css_classes = ["radio-button-group"] # str -> lst # Hard coded to specifically scrape the google website and returns a list of # the website titles from the google search results given a string to initate # the search query def web_scraper(day, month, year): lst = [] opener = urllib.request.build_opener() #use Mozilla because can't access chrome due to insufficient privileges #only use for google #opener.addheaders = [('User-agent', 'Mozilla/5.0')]
def timeline(self, device, max_x): data_source = self.make_datasource(device['events']) n_rows = device['n_rows'] if n_rows == 0: n_rows = 1 elif n_rows == 1: n_rows = 2 name = device['name'] tools = self.get_tools() p = figure( title="{}".format(name), plot_height=20 * n_rows + 60, plot_width=1200, tools=tools, sizing_mode='stretch_both', # sizing_mode='scale_width', active_scroll='xwheel_zoom') # p.js_on_event('tap', callback) # p.toolbar.logo = None # p.toolbar_location = None p.hbar(left='start', right='end', y='height', color='color', height=0.85, source=data_source, hover_fill_alpha=0.5, line_join='round', line_cap='round', hover_line_color='red') p.x_range = Range1d(0, max_x, bounds="auto") p.y_range = Range1d(0, n_rows) p.yaxis.visible = False p.ygrid.ticker = SingleIntervalTicker(interval=1) p.ygrid.grid_line_color = None p.ygrid.band_fill_alpha = 0.1 p.ygrid.band_fill_color = "gray" update_all_ranges = CustomJS(args={ 'me': p, }, code=""" console.log(me); var start = me.x_range.start; var end = me.x_range.end; console.log(start, end); for (var model_id in me.document._all_models) { model = me.document._all_models[model_id]; if (model.type=="Plot"){ console.log(model); model.x_range.set('start', start); model.x_range.set('end', end); } if (model.type=="Button"){ model.disabled = true; if (model.label == " Sync"){ model.css_classes = ['xl-hidden']; } } } """) # p.x_range.js_on_change('start',update_all_ranges) button = Button(label=" Sync", width=20, button_type='primary', disabled=True) button.css_classes = ['xl-hidden'] button.js_on_click(update_all_ranges) p.x_range.js_on_change( 'start', CustomJS(args={ 'button': button, }, code=""" console.log(button); button.disabled = false; button.css_classes = ['center-block', 'xl-sync']; """)) return p, WidgetBox(button)