def __init__(self, image_views, sv_streamctrl): """Initialize a disabled pixels overlay. Args: image_views (ImageView): Associated streamvis image view instances. sv_streamctrl (StreamControl): A StreamControl instance of an application. """ self._detector_name = "" self._ju_handler = None self._sv_streamctrl = sv_streamctrl self._source = ColumnDataSource( dict(left=[], right=[], top=[], bottom=[])) glyph = Quad( left="left", right="right", top="top", bottom="bottom", line_alpha=0, fill_alpha=0, hatch_pattern="/", hatch_color="white", ) for image_view in image_views: image_view.plot.add_glyph(self._source, glyph)
def __init__(self, scheduler, **kwargs): self.scheduler = scheduler ps = [p for p in scheduler.plugins if isinstance(p, AllProgress)] if ps: self.plugin = ps[0] else: self.plugin = AllProgress(scheduler) self.source = ColumnDataSource(data=dict(name=[], left=[], right=[], center=[], color=[], percent=[], MB=[], text=[])) self.root = Plot(id='bk-nbytes-plot', x_range=DataRange1d(), y_range=DataRange1d(), toolbar_location=None, outline_line_color=None, **kwargs) self.root.add_glyph( self.source, Quad(top=1, bottom=0, left='left', right='right', fill_color='color', fill_alpha=1)) self.root.add_layout(LinearAxis(), 'left') self.root.add_layout(LinearAxis(), 'below') hover = HoverTool(point_policy="follow_mouse", tooltips=""" <div> <span style="font-size: 14px; font-weight: bold;">Name:</span> <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span> </div> <div> <span style="font-size: 14px; font-weight: bold;">Percent:</span> <span style="font-size: 10px; font-family: Monaco, monospace;">@percent</span> </div> <div> <span style="font-size: 14px; font-weight: bold;">MB:</span> <span style="font-size: 10px; font-family: Monaco, monospace;">@MB</span> </div> """) self.root.add_tools(hover)
def __init__(self, **kwargs): self.source = ColumnDataSource(data=dict( name=[], left=[], right=[], center=[], color=[], percent=[], MB=[], text=[], )) self.root = Plot(id="bk-nbytes-plot", x_range=DataRange1d(), y_range=DataRange1d(), toolbar_location=None, outline_line_color=None, **kwargs) self.root.add_glyph( self.source, Quad( top=1, bottom=0, left="left", right="right", fill_color="color", fill_alpha=1, ), ) self.root.add_layout(LinearAxis(), "left") self.root.add_layout(LinearAxis(), "below") hover = HoverTool( point_policy="follow_mouse", tooltips=""" <div> <span style="font-size: 14px; font-weight: bold;">Name:</span> <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span> </div> <div> <span style="font-size: 14px; font-weight: bold;">Percent:</span> <span style="font-size: 10px; font-family: Monaco, monospace;">@percent</span> </div> <div> <span style="font-size: 14px; font-weight: bold;">MB:</span> <span style="font-size: 10px; font-family: Monaco, monospace;">@MB</span> </div> """, ) self.root.add_tools(hover)
def pyramid(): xdr = DataRange1d() ydr = DataRange1d() plot = Plot(title=None, x_range=xdr, y_range=ydr, plot_width=600, plot_height=600) xaxis = LinearAxis() plot.add_layout(xaxis, 'below') yaxis = LinearAxis(ticker=SingleIntervalTicker(interval=5)) plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) male_quad = Quad(left="male", right=0, bottom="groups", top="shifted", fill_color="#3B8686") male_quad_glyph = plot.add_glyph(source_pyramid, male_quad) female_quad = Quad(left=0, right="female", bottom="groups", top="shifted", fill_color="#CFF09E") female_quad_glyph = plot.add_glyph(source_pyramid, female_quad) plot.add_layout( Legend(items=[ ("Male", [male_quad_glyph]), ("Female", [female_quad_glyph]), ])) return plot
def add_background_stripe(x, index): if divmod(index, 2)[1] == 1: color = self.ODD_BOX_ANNOTATION_COLOR else: color = self.EVEN_BOX_ANNOTATION_COLOR q = Quad(left=(x - self.dx // 2), bottom=0, right=(x + self.dx // 2), top=self.plot.y_range.end, line_color=None, fill_color=color, fill_alpha=0.2) self.plot.add_glyph(q)
def __init__(self, image_views, sv_metadata, sv_streamctrl): """Initialize a intensity ROI overlay. Args: image_views (ImageView): Associated streamvis image view instances. sv_metadata (MetadataHandler): A metadata handler to report metadata issues. sv_streamctrl (StreamControl): A StreamControl instance of an application. """ self._sv_metadata = sv_metadata self._sv_streamctrl = sv_streamctrl # ---- intensity ROIs self._source = ColumnDataSource( dict(left=[], right=[], bottom=[], top=[], text_x=[], text_y=[], text=[])) quad_glyph = Quad( left="left", right="right", bottom="bottom", top="top", fill_alpha=0, line_color="white", ) text_glyph = Text( x="text_x", y="text_y", text="text", text_align="right", text_baseline="top", text_color="white", ) for image_view in image_views: image_view.plot.add_glyph(self._source, quad_glyph) image_view.plot.add_glyph(self._source, text_glyph) # ---- toggle button toggle = CheckboxGroup(labels=["Intensity ROIs"], default_size=145) self.toggle = toggle
def get_hist(values, bins=15, width=DEF_WIDTH, title=None, js_on_event=None, **kwargs): hist_probs, edges = np.histogram(values, density=True, bins=bins) hist_counts, edges = np.histogram(values, density=False, bins=bins) source = ColumnDataSource( dict(left=edges[:-1], top=hist_probs, right=edges[1:], bottom=[0] * len(hist_probs), count=hist_counts)) hover = HoverTool(tooltips=[('Count', '@count')]) xdr = DataRange1d() ydr = DataRange1d() hist = figure(plot_width=width, toolbar_location=DEF_TOOL_LOC, tools=DEF_TOOLS + [hover], title=title, x_range=xdr, y_range=ydr, **kwargs) bars = Quad(top='top', bottom='bottom', left='left', right='right', fill_color="#036564", line_color="#033649") hist.add_glyph(source, bars) if js_on_event is not None: hist.js_on_event(js_on_event[0], js_on_event[1]) return hist
def __init__(self): """Initialize a progress bar widget. """ self._source = ColumnDataSource( dict(left=[0], right=[0], top=[1], bottom=[0], text_x=[0.5], text_y=[0.5], text=[""])) bar_glyph = Quad( left="left", right="right", top="top", bottom="bottom", fill_color="limegreen", line_alpha=0, ) text_glyph = Text( x="text_x", y="text_y", text="text", text_align="center", text_baseline="middle", text_font_style="bold", ) plot = Plot( plot_width=310, plot_height=40, x_range=Range1d(0, 1, bounds=(0, 1)), y_range=Range1d(0, 1, bounds=(0, 1)), toolbar_location=None, ) plot.add_glyph(self._source, bar_glyph) plot.add_glyph(self._source, text_glyph) self.widget = plot
def make_trace_figure(trace, tids): tooltips = [("Task:", "@name"), ("Start:", "@start"), ("Duration:", "@duration")] mint = min(trace['start']) maxt = max(trace['end']) plot = figure(width=1500, height=800, tooltips=tooltips, y_range=tids, x_range=(mint, maxt)) plot.xaxis.axis_label = "Time [s.]" plot.yaxis.axis_label = "Thread/rank" source = ColumnDataSource(trace) rect = plot.add_glyph( source, Quad(left='start', right='end', top='top', bottom='bottom', fill_color='color', line_color='color', fill_alpha=0.9, line_alpha=0.9)) ## Create filter text_input = TextInput(value="", title="Filter") def text_input_fn(attr, old, new): fil = text_input.value new_trace = trace[trace['name'].str.contains(fil)] print("Filtering using {}, originally {} rows, now {} rows".format( fil, trace.shape[0], new_trace.shape[0])) source.data = new_trace print("Done filtering") text_input.on_change('value', text_input_fn) print("Done preparing plot...") return text_input, plot
def add_as_zoom(self, image_view, line_color="red"): """Add an ImageView plot as a zoom view. Args: image_plot (ImageView): Associated streamvis image view instance. line_color (str, optional): Zoom border box color. Defaults to 'red'. """ # ---- add quad glyph of zoom area to the main plot area_source = ColumnDataSource( dict( left=[image_view.x_start], right=[image_view.x_end], bottom=[image_view.y_start], top=[image_view.y_end], )) area_rect = Quad( left="left", right="right", bottom="bottom", top="top", line_color=line_color, line_width=2, fill_alpha=0, ) self.plot.add_glyph(area_source, area_rect) x_range_cb = CustomJS(args=dict(source=area_source), code=js_move_zoom.format(start="left", end="right")) y_range_cb = CustomJS(args=dict(source=area_source), code=js_move_zoom.format(start="bottom", end="top")) image_view.plot.x_range.js_on_change("start", x_range_cb) image_view.plot.x_range.js_on_change("end", x_range_cb) image_view.plot.y_range.js_on_change("start", y_range_cb) image_view.plot.y_range.js_on_change("end", y_range_cb) self.zoom_views.append(image_view)
def __init__(self, nplots, plot_height=350, plot_width=700, lower=0, upper=1000, nbins=100): """Initialize histogram plots. Args: nplots (int): Number of histogram plots that will share common controls. plot_height (int, optional): Height of plot area in screen pixels. Defaults to 350. plot_width (int, optional): Width of plot area in screen pixels. Defaults to 700. lower (int, optional): Initial lower range of the bins. Defaults to 0. upper (int, optional): Initial upper range of the bins. Defaults to 1000. nbins (int, optional): Initial number of the bins. Defaults to 100. """ # Histogram plots self.plots = [] self._plot_sources = [] for ind in range(nplots): plot = Plot( x_range=DataRange1d(), y_range=DataRange1d(), plot_height=plot_height, plot_width=plot_width, toolbar_location="left", ) # ---- tools plot.toolbar.logo = None # share 'pan', 'boxzoom', and 'wheelzoom' tools between all plots if ind == 0: pantool = PanTool() boxzoomtool = BoxZoomTool() wheelzoomtool = WheelZoomTool() plot.add_tools(pantool, boxzoomtool, wheelzoomtool, SaveTool(), ResetTool()) # ---- axes plot.add_layout(LinearAxis(), place="below") plot.add_layout(LinearAxis(major_label_orientation="vertical"), place="left") # ---- grid lines plot.add_layout(Grid(dimension=0, ticker=BasicTicker())) plot.add_layout(Grid(dimension=1, ticker=BasicTicker())) # ---- quad (single bin) glyph plot_source = ColumnDataSource(dict(left=[], right=[], top=[])) plot.add_glyph( plot_source, Quad(left="left", right="right", top="top", bottom=0, fill_color="steelblue"), ) self.plots.append(plot) self._plot_sources.append(plot_source) self._counts = [] self._empty_counts() # Histogram controls # ---- histogram range toggle button def auto_toggle_callback(state): if state: # Automatic lower_spinner.disabled = True upper_spinner.disabled = True else: # Manual lower_spinner.disabled = False upper_spinner.disabled = False auto_toggle = CheckboxGroup(labels=["Auto Hist Range"], active=[0], default_size=145) auto_toggle.on_click(auto_toggle_callback) self.auto_toggle = auto_toggle # ---- histogram lower range def lower_spinner_callback(_attr, _old_value, new_value): self.upper_spinner.low = new_value + STEP self._empty_counts() lower_spinner = Spinner( title="Lower Range:", high=upper - STEP, value=lower, step=STEP, disabled=bool(auto_toggle.active), default_size=145, ) lower_spinner.on_change("value", lower_spinner_callback) self.lower_spinner = lower_spinner # ---- histogram upper range def upper_spinner_callback(_attr, _old_value, new_value): self.lower_spinner.high = new_value - STEP self._empty_counts() upper_spinner = Spinner( title="Upper Range:", low=lower + STEP, value=upper, step=STEP, disabled=bool(auto_toggle.active), default_size=145, ) upper_spinner.on_change("value", upper_spinner_callback) self.upper_spinner = upper_spinner # ---- histogram number of bins def nbins_spinner_callback(_attr, _old_value, _new_value): self._empty_counts() nbins_spinner = Spinner(title="Number of Bins:", low=1, value=nbins, default_size=145) nbins_spinner.on_change("value", nbins_spinner_callback) self.nbins_spinner = nbins_spinner # ---- histogram log10 of counts toggle button def log10counts_toggle_callback(state): self._empty_counts() for plot in self.plots: if state: plot.yaxis[0].axis_label = "log⏨(Counts)" else: plot.yaxis[0].axis_label = "Counts" log10counts_toggle = CheckboxGroup(labels=["log⏨(Counts)"], default_size=145) log10counts_toggle.on_click(log10counts_toggle_callback) self.log10counts_toggle = log10counts_toggle
h=0.4, url=dict(value="https://static.bokeh.org/logos/logo.png"), anchor="center")), ("line", Line(x="x", y="y", line_color="#F46D43")), ("multi_line", MultiLine(xs="xs", ys="ys", line_color="#8073AC", line_width=2)), ("multi_polygons", MultiPolygons(xs="xsss", ys="ysss", line_color="#8073AC", fill_color="#FB9A99", line_width=2)), ("patch", Patch(x="x", y="y", fill_color="#A6CEE3")), ("patches", Patches(xs="xs", ys="ys", fill_color="#FB9A99")), ("quad", Quad(left="x", right="xp01", top="y", bottom="ym01", fill_color="#B3DE69")), ("quadratic", Quadratic(x0="x", y0="y", x1="xp02", y1="y", cx="xp01", cy="yp01", line_color="#4DAF4A", line_width=3)), ("ray", Ray(x="x", y="y", length=45, angle=-0.7, line_color="#FB8072",
def get_plot(raw, today): dfs, cats = get_sources_and_categories(raw) # Some times first_day = raw.loc[0, 'timestamp'] one_week_ago = today - datetime.timedelta(weeks=1) two_weeks_ago = today - datetime.timedelta(weeks=2) one_week_forward = today + datetime.timedelta(weeks=1) # The ranges all_range = Range1d(start=first_day, end=today) month_range = Range1d(start=two_weeks_ago, end=one_week_forward) week_range = Range1d(start=one_week_ago, end=today) # Selection indicators highlight = Quad( left='start', right='end', bottom=0, top=12, fill_color='white', line_color=COLOR_PRIMARY_CONTRAST, fill_alpha=0.2, ) lowlight = Quad( left='start', right='end', bottom=0, top=12, fill_color=COLOR_PRIMARY, line_color=COLOR_PRIMARY_CONTRAST, fill_alpha=0.5, ) # Make the complete timeline plot all_plot = _make_base_plot(dfs, cats, all_range) detail_selection_source = ColumnDataSource({ 'start': [all_range.start, month_range.end], 'end': [month_range.start, all_range.end] }) all_plot.add_glyph(detail_selection_source, lowlight) # add a second axis to all_layout plot for presentation year_ticker = DatetimeTicker(desired_num_ticks=4) year_ticks = DatetimeTickFormatter( formats={ 'years': ["%Y"], 'months': ["%Y"], 'days': ["%Y"], 'hours': ["%Y"] } ) all_plot.add_layout( DatetimeAxis(formatter=year_ticks, ticker=year_ticker, **AXIS_PROPERTIES), 'below' ) # Make the detail plot detail_plot = _make_base_plot(dfs, cats, month_range) detail_plot.add_tools(PanTool(dimensions=['width'])) detail_plot.add_tools(WheelZoomTool(dimensions=['width'])) detail_plot.add_tools(ResetTool()) week_selection_source = ColumnDataSource({'start': [week_range.start], 'end': [week_range.end]}) detail_plot.add_glyph(week_selection_source, highlight) detail_code = """ // Update the month selection box on the all_data plot when month pans var detail_selection_data = detail_selection_source.get('data'); var detail_start = cb_obj.get('frame').get('x_range').get('start'); var detail_end = cb_obj.get('frame').get('x_range').get('end'); new_detail_selection = { 'start': [detail_selection_data['start'][0], detail_end], 'end': [detail_start, detail_selection_data['end'][1]] }; detail_selection_source.set('data', new_detail_selection); // Always make sure the week highlight box on detail is visible and centered var x = moment.duration(detail_end - detail_start).asWeeks() / 2.4; var start = moment(detail_start); var week_end = start.add(x, 'weeks').format('x'); $("#one_week_before").text(start.format('ddd, DD MMM YYYY')); var newStart = start.format('YYYY-MM-DD'); var week_start = start.add(6, 'days').format('x'); $("#today").text(start.format('ddd, DD MMM YYYY')); new_week_selection = { 'start': [week_start, ], 'end': [week_end, ] }; week_selection_source.set('data', new_week_selection); var url = '/timesheet/?start=' + newStart; $("#timesheet_submit").attr('href', url).addClass("mdl-button--colored"); """ detail_xrange_callback = CustomJS(args={}, code=detail_code) detail_xrange_callback.args['detail_selection_source'] = detail_selection_source detail_xrange_callback.args['week_selection_source'] = week_selection_source detail_plot.x_range.callback = detail_xrange_callback return all_plot, detail_plot
fill_alpha='qfillalpha',hatch_pattern='qhatch',source=ptree.leaf_cds,name='leaf_node')#,fill_alpha=0,line_alpha=0) #qglyph=Quad(left='nodebox_lefts',right='nodebox_rights',bottom='nodebox_bottoms',top='nodebox_tops',fill_color='qcolor',line_alpha=0,\ # hatch_pattern='qhatch')#,fill_alpha=0,line_alpha=0) #p1.add_glyph(ptree.leaf_cds,qglyph,name='leaf_node')#'leaf_node')#self.ntype) p1.x_range=Range1d(0,ptree.branch_edgecoords.boundbox.xmax,bounds='auto') ptree.leaf_cds.add(['normal' for _ in ptree.leaf_cds.data['gbacc']],'rpnl_tfstyle') ptree.leaf_cds.add(['4pt' for _ in ptree.leaf_cds.data['gbacc']],'rpnl_tfsize') #ptree.leaf_cds.add(['blank' for _ in ptree.leaf_cds.data['gbacc']],'rpnl_tfsize') textglyph=Text(x=1,y='nodebox_bottoms',text='gbacc',text_font_size='rpnl_tfsize')#,text_font_style='rpnl_tfstyle')#,text_font='Arial')#,text_align='center')#,name='leaf_node') p2.add_glyph(ptree.leaf_cds,textglyph) p2selquad=Quad(left=0,right=1,bottom='nodebox_bottoms',top='nodebox_tops',hatch_pattern="qhatch",hatch_alpha=0.5,fill_color=None,line_color=None) p2.add_glyph(ptree.leaf_cds,p2selquad) leafdict=ptree.leaf_cds.data.copy() eckeepers=[x is not None for x in leafdict['ecs']] ecdict={} for key in leafdict: ecdict[key]=[] for x,keepvalue in enumerate(eckeepers): if keepvalue: ecdict[key].append(leafdict[key][x]) ec_cds=ColumnDataSource(ecdict) ecqglyph=Quad(left=0,right=2,fill_color='blue',fill_alpha=0.5,line_alpha=0,bottom='nodebox_bottoms',top='nodebox_tops',hatch_pattern="qhatch",hatch_alpha=0.5) p2.add_glyph(ec_cds,ecqglyph,name='metadata')#'leaf_node')#self.ntype) pdbkeepers=[x is not None for x in leafdict['pdbids']]
x = np.linspace(-2, 2, N) y = x**2 source = ColumnDataSource(dict( left=x, top=y, right=x-x**3/10 + 0.3, bottom=y-x**2/10 + 0.5, ) ) plot = Plot( title=None, plot_width=300, plot_height=300, min_border=0, toolbar_location=None) glyph = Quad(left="left", right="right", top="top", bottom="bottom", fill_color="#b3de69") plot.add_glyph(source, glyph) xaxis = LinearAxis() plot.add_layout(xaxis, 'below') yaxis = LinearAxis() plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) curdoc().add_root(plot) show(plot)
def __init__(self, **kwargs): data = progress_quads(dict(all={}, memory={}, erred={}, released={})) self.source = ColumnDataSource(data=data) x_range = DataRange1d() y_range = Range1d(-8, 0) self.root = Plot(id='bk-task-progress-plot', x_range=x_range, y_range=y_range, toolbar_location=None, **kwargs) self.root.add_glyph( self.source, Quad(top='top', bottom='bottom', left='left', right='right', fill_color="#aaaaaa", line_color="#aaaaaa", fill_alpha=0.2)) self.root.add_glyph( self.source, Quad(top='top', bottom='bottom', left='left', right='released-loc', fill_color="color", line_color="color", fill_alpha=0.6)) self.root.add_glyph( self.source, Quad(top='top', bottom='bottom', left='released-loc', right='memory-loc', fill_color="color", line_color="color", fill_alpha=1.0)) self.root.add_glyph( self.source, Quad(top='top', bottom='bottom', left='erred-loc', right='erred-loc', fill_color='#000000', line_color='#000000', fill_alpha=0.3)) self.root.add_glyph( self.source, Text(text='show-name', y='bottom', x='left', x_offset=5, text_font_size=value('10pt'))) self.root.add_glyph( self.source, Text(text='done', y='bottom', x='right', x_offset=-5, text_align='right', text_font_size=value('10pt'))) hover = HoverTool(point_policy="follow_mouse", tooltips=""" <div> <span style="font-size: 14px; font-weight: bold;">Name:</span> <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span> </div> <div> <span style="font-size: 14px; font-weight: bold;">All:</span> <span style="font-size: 10px; font-family: Monaco, monospace;">@all</span> </div> <div> <span style="font-size: 14px; font-weight: bold;">Memory:</span> <span style="font-size: 10px; font-family: Monaco, monospace;">@memory</span> </div> <div> <span style="font-size: 14px; font-weight: bold;">Erred:</span> <span style="font-size: 10px; font-family: Monaco, monospace;">@erred</span> </div> """) self.root.add_tools(hover)
df = DataFrame( data=[(p.type, p.name, p.pretty_size, p.box.x0, p.box.y0, p.box.x0 + p.box.dx, p.box.y0 + p.box.dy) for p in result.get_boxes()], columns=['type', 'name', 'size', 'left', 'bottom', 'right', 'top']) source = ColumnDataSource(df) ''' Get most common file types Create a color mapper based on color types Create a Quad glyph with this color mapper ''' types = df.type.value_counts()[:len(palette)].index color_mapper = CategoricalColorMapper(palette=sample(palette, len(types)), factors=list(types)) glyph = Quad(fill_color={'field': 'type', 'transform': color_mapper}) ''' Make a boker.figure of requested size Add data/glyph Show the figure ''' plot = figure(title=title, plot_width=args.wide, plot_height=args.tall, toolbar_location=None, x_axis_location=None, y_axis_location=None, tooltips=[("Location", "@name"), ("Size", "@size")]) plot.add_glyph(source, glyph)