Пример #1
0
    def populate_glyphs(self):
        self.plot.renderers = []
        self.plot.tools = []
        if self._show_counties:
            print "showing you the counties"
            #datasource = ColumnDataSource(county_data)
            #apatch = Patches(xs=county_xs, ys=county_ys, fill_color='white')
            #apatch = Patches(xs='xs', ys='ys', fill_color='colors', fill_alpha="alpha")
            apatch = Patches(xs='xs',
                             ys='ys',
                             fill_color='thecolors',
                             fill_alpha='alpha')
            self.plot.add_glyph(self.county_source, apatch, name='counties')

        if self._show_hotels:
            print "showing you the hotels"
            circle2 = Circle(x="lon",
                             y="lat",
                             size=10,
                             fill_color="fill2",
                             fill_alpha=1.0,
                             line_alpha=0.0)
            circle = Circle(x="lon",
                            y="lat",
                            size=10,
                            fill_color="fill",
                            fill_alpha=1.0,
                            line_color="black")
            #print "source is ", self.source['lon'], self.source['lat'], self.source['f1ll']
            self.plot.add_glyph(self.source,
                                circle,
                                nonselection_glyph=circle2,
                                name='hotels')
            #county_xs, county_ys = get_some_counties()

        rndr = self.plot.renderers[-1]
        pan = PanTool()
        wheel_zoom = WheelZoomTool()
        box_select = BoxSelectTool()
        box_select.renderers = [rndr]
        tooltips = "@name"
        tooltips = "<span class='tooltip-text'>@names</span>\n<br>"
        tooltips += "<span class='tooltip-text'>Reviews: @num_reviews</span>"
        hover = HoverTool(tooltips=tooltips, names=['hotels'])
        tap = TapTool(names=['hotels'])
        self.plot.add_tools(pan, wheel_zoom, box_select, hover, tap)
        overlay = BoxSelectionOverlay(tool=box_select)
        self.plot.add_layout(overlay)
def test_patches_hover_still_works_when_a_seleciton_is_preselcted(
        output_file_url, selenium):
    # This tests an edge case interaction when Patches (specifically) is used
    # with a tool that requires hit testing e.g. HitTool AND a selection is
    # pre-made on the data source driving it.
    plot = Plot(x_range=Range1d(0, 100), y_range=Range1d(0, 100), min_border=0)
    source = ColumnDataSource(
        dict(xs=[[0, 50, 50, 0], [50, 100, 100, 50]],
             ys=[[0, 0, 100, 100], [0, 0, 100, 100]],
             color=['pink', 'blue']))
    source.selected = {
        '0d': {
            'glyph': None,
            'indices': []
        },
        '1d': {
            'indices': [1]
        },
        '2d': {
            'indices': {}
        },
    }
    plot.add_glyph(source, Patches(xs='xs', ys='ys', fill_color='color'))
    plot.add_tools(HoverTool())
    plot.add_layout(LinearAxis(), 'below')
    plot.add_layout(LinearAxis(), 'left')
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Hover plot and test no error
    canvas = selenium.find_element_by_tag_name('canvas')
    actions = ActionChains(selenium)
    actions.move_to_element_with_offset(canvas, 100, 100)
    actions.perform()

    # If this assertion fails then there were likely errors on hover
    assert has_no_console_errors(selenium)
Пример #3
0
    rate=[
        unemployment[code] for code in us_counties if us_counties[code]
        ["state"] not in ["ak", "hi", "pr", "gu", "vi", "mp", "as"]
    ],
))

plot = Plot(min_border=0,
            border_fill_color="white",
            plot_width=1300,
            plot_height=700)
plot.title.text = "2009 Unemployment Data"
plot.toolbar_location = None

county_patches = Patches(xs="county_xs",
                         ys="county_ys",
                         fill_color=transform("rate", cmap),
                         fill_alpha=0.7,
                         line_color="white",
                         line_width=0.5)
plot.add_glyph(county_source, county_patches)

state_patches = Patches(xs="state_xs",
                        ys="state_ys",
                        fill_alpha=0.0,
                        line_color="#884444",
                        line_width=2)
plot.add_glyph(state_source, state_patches)

cbar = ColorBar(color_mapper=cmap, location=(0, 0))
plot.add_layout(cbar, 'left')

doc = Document()
def make_patches_plot(x_range, y_range, source):
    with make_plot(x_range, y_range, source) as plot:
        glyph = Patches(xs='xs', ys='ys', fill_color='value', fill_alpha=0.8, line_color='#CCCCCC', line_alpha=0.8)
        plot.add_glyph(source, glyph)
    return plot
Пример #5
0
                    plot_height=300,
                    min_border=0,
                    title="Hover and tap discontinuous patches.")

patches_dis_data = pd.DataFrame(
    {
        'xs': [[0, 49, 49, 0, NAN, 51, 89, 89, 51], [90, 100, 100, 90],
               [92, 98, 98, 92]],
        'ys': [[0, 0, 80, 80, NAN, 0, 0, 90, 90], [0, 0, 100, 100],
               [20, 20, 90, 90]],
        'value':
        ['I am one object split in two', 'I am wheat', 'I am steelblue'],
        'fill_color': ['firebrick', 'wheat', 'steelblue']
    }, )
plot_patches_dis = Plot(**PLOT_FORMATS)
plot_patches_dis.add_glyph(
    ColumnDataSource(patches_dis_data),
    Patches(
        xs='xs',
        ys='ys',
        fill_color='fill_color',
        line_color=value('wheat'),
    ))
plot_patches_dis.add_tools(HoverTool(tooltips='@value'))
plot_patches_dis.add_tools(TapTool())

filename = '2376_hover_on_discontinuous_patches.html'
output_file(filename, title='Discontinuous Patches', mode='relative-dev')
save(plot_patches_dis)
view(filename)
Пример #6
0
           y="y",
           w=0.4,
           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",
Пример #7
0
xpts = np.array([-.09, -.12, .0, .12, .09])
ypts = np.array([-.1, .02, .1, .02, -.1])

source = ColumnDataSource(
    dict(
        xs=[xpts * (1 + i / 10.0) + xx for i, xx in enumerate(x)],
        ys=[ypts * (1 + i / 10.0) + yy for i, yy in enumerate(y)],
    ))

plot = Plot(title=None,
            plot_width=300,
            plot_height=300,
            min_border=0,
            toolbar_location=None)

glyph = Patches(xs="xs", ys="ys", fill_color="#fb9a99")
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 plot_data(data_df, connections, year, geoSource_new):

    data_df_countries = data_df  #.drop_duplicates(subset=None, keep='first', inplace=True)
    connections_df = connections

    node_source = ColumnDataSource(
        data_df_countries[["country_id", "Country", "Longitude", "Latitude"]])
    edge_source = ColumnDataSource(connections_df[["start", "end"]])

    node_renderer = GlyphRenderer(data_source=node_source,
                                  glyph=node_glyph,
                                  selection_glyph=node_selection,
                                  nonselection_glyph=node_nonselection)

    ## Create edge_renderer
    edge_renderer = GlyphRenderer(data_source=edge_source,
                                  glyph=edge_glyph,
                                  hover_glyph=edge_hover,
                                  selection_glyph=edge_selection,
                                  nonselection_glyph=edge_nonselection)
    ## Create layout_provider
    graph_layout = dict(
        zip(data_df_countries.country_id.astype(str),
            zip(data_df_countries.Longitude, data_df_countries.Latitude)))
    layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

    ## Create graph renderer
    graph = GraphRenderer(edge_renderer=edge_renderer,
                          node_renderer=node_renderer,
                          layout_provider=layout_provider,
                          inspection_policy=NodesAndLinkedEdges(),
                          selection_policy=NodesAndLinkedEdges())

    plot = Plot(x_range=Range1d(-150, 150),
                y_range=Range1d(15, 75),
                plot_width=800,
                plot_height=600,
                background_fill_color=Set3_12[4],
                background_fill_alpha=0.2)

    plot.title.text = "Human Trafficing Visualization for " + str(year)

    # plot.add_glyph( geoSource_data, Patches(xs='xs', ys='ys', line_color='grey'
    #                      , line_width=.5, fill_color=Set3_12[6], fill_alpha=0.25))

    plot.add_glyph(
        geoSource_new,
        Patches(xs='xs',
                ys='ys',
                line_color='grey',
                line_width=.2,
                fill_color={
                    'field': 'Tier',
                    'transform': mapper2
                },
                fill_alpha=0.25))

    plot.renderers.append(graph)
    plot.add_layout(LinearAxis(axis_label="Latitude"), "below")
    plot.add_layout(LinearAxis(axis_label="Longitude"), "left")

    hover = HoverTool(
        show_arrow=True,  # tooltips=  # [("Country Involved: ", "@Country")],
        tooltips="""
                                <div>
                                    <div>
                                        <span style="font-size: 15px;">Country Information </span>
                                        <span style="font-size: 12px; color: #696;">@Destination_Country </span>
                                    </div>
                                </div>
                                """,
        renderers=[graph])
    hover_no_tooltips = HoverTool(tooltips=None, renderers=[graph])
    box_zoom = BoxZoomTool()

    plot.add_tools(hover, hover_no_tooltips, box_zoom, TapTool(),
                   BoxSelectTool(), ResetTool(), WheelZoomTool())
    plot.toolbar.active_inspect = [hover, hover_no_tooltips]
    plot.toolbar.active_drag = box_zoom
    plot.outline_line_color = "navy"
    plot.outline_line_alpha = 0.3
    plot.outline_line_width = 3
    plot.add_tile(STAMEN_TONER_LABELS)

    return plot
def plot_data(data_df, connections, year, geoSource_new, df):

    d_yr = df[df['Years'] == year]

    data_df_countries = d_yr.merge(data_df,
                                   left_on='Origin_Country',
                                   right_on='Country')
    #data_df_countries = node_dt #.drop_duplicates(subset=None, keep='first', inplace=True)
    connections_df = connections

    # node_source = ColumnDataSource(data_df_countries[["country_id","Country", "Longitude", "Latitude"]])

    node_source = ColumnDataSource(data_df_countries)
    edge_source = ColumnDataSource(connections_df[["start", "end"]])

    node_renderer = GlyphRenderer(data_source=node_source,
                                  glyph=node_glyph,
                                  selection_glyph=node_selection,
                                  nonselection_glyph=node_nonselection)

    ## Create edge_renderer
    edge_renderer = GlyphRenderer(data_source=edge_source,
                                  glyph=edge_glyph,
                                  hover_glyph=edge_hover,
                                  selection_glyph=edge_selection,
                                  nonselection_glyph=edge_nonselection)
    ## Create layout_provider
    graph_layout = dict(
        zip(data_df_countries.country_id.astype(str),
            zip(data_df_countries.Longitude, data_df_countries.Latitude)))
    layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

    ## Create graph renderer
    graph = GraphRenderer(edge_renderer=edge_renderer,
                          node_renderer=node_renderer,
                          layout_provider=layout_provider,
                          inspection_policy=NodesAndLinkedEdges(),
                          selection_policy=NodesAndLinkedEdges())

    plot = Plot(x_range=Range1d(-150, 150),
                y_range=Range1d(15, 75),
                plot_width=800,
                plot_height=600,
                background_fill_color=Set3_12[4],
                background_fill_alpha=0.2)

    plot.title.text = "Human Trafficing Visualization for " + str(year)

    plot.add_glyph(
        geoSource_new,
        Patches(xs='xs',
                ys='ys',
                line_color='grey',
                line_width=.2,
                fill_color={
                    'field': 'Tier',
                    'transform': mapper2
                },
                fill_alpha=0.40))

    plot.renderers.append(graph)
    plot.add_layout(LinearAxis(axis_label="Latitude"), "below")
    plot.add_layout(LinearAxis(axis_label="Longitude"), "left")

    # tooltips="""
    #                             <div>
    #                                 <div>
    #                                     <span style="font-size: 17px; font-weight: bold;">@desc</span>
    #                                     <span style="font-size: 15px; color: #966;">[$index]</span>
    #                                 </div>
    #                                 <div>
    #                                     <span style="font-size: 15px;">Country Involved</span>
    #                                     <span style="font-size: 10px; color: #696;">@Country</span>
    #                                 </div>
    #                             </div>
    #                             """,

    hover = HoverTool(
        show_arrow=True,  # tooltips=  # [("Country Involved: ", "@Country")],
        tooltips="""
                                <div>
                                    <div>
                                        <span style="font-size: 13px;">Country Info</span>
                                        <span style="font-size: 12px; color: #696;">@Destination_Country, @Type_Of_Trafficking</span>
                                    </div>
                                </div>
                                """,
        renderers=[node_renderer],
        name='Test')
    hover_no_tooltips = HoverTool(tooltips=None, renderers=[graph])
    box_zoom = BoxZoomTool()

    plot.add_tools(hover, hover_no_tooltips, box_zoom, TapTool(),
                   BoxSelectTool(), ResetTool(), WheelZoomTool())
    plot.toolbar.active_inspect = [hover, hover_no_tooltips]
    plot.toolbar.active_drag = box_zoom
    plot.outline_line_color = "navy"
    plot.outline_line_alpha = 0.3
    plot.outline_line_width = 1

    select_overlay = plot.select_one(BoxSelectTool).overlay

    select_overlay.fill_color = "firebrick"
    select_overlay.line_color = None

    zoom_overlay = plot.select_one(BoxZoomTool).overlay

    zoom_overlay.line_color = "olive"
    zoom_overlay.line_width = 3
    zoom_overlay.line_dash = "solid"
    zoom_overlay.fill_color = None

    plot.add_tile(STAMEN_TONER_LABELS)

    return plot
Пример #10
0
print("HERE?")

# Have to add the patches after the tiles
input_areas = p.patches('xs',
                        'ys',
                        source=geosource,
                        fill_color='red',
                        line_color='gray',
                        line_width=0.25,
                        fill_alpha=.3)

taptool = TapTool(renderers=[input_areas])
hovertool = HoverTool(renderers=[input_areas], tooltips=[('Site', '@name')])

selected_patches = Patches(fill_color="yellow",
                           fill_alpha=.8,
                           line_width=1,
                           line_color="green")
input_areas.selection_glyph = selected_patches

geosource.selected.on_change('indices', tapselect_handler)

print("HERE?")

# CustomJS(code="""
# // comment....
# console.log("Somewhere to stop!");
# """)

# Create hover tool
p.add_tools(taptool, hovertool)
Пример #11
0
renderer = p.patches('x',
                     'y',
                     source=source,
                     fill_color={
                         'field': 'veges',
                         'transform': color_mapper
                     },
                     selection_line_color="blue",
                     fill_alpha=0.7,
                     line_color="white",
                     line_width=0.5)

selected_patches = Patches(fill_color={
    'field': 'veges',
    'transform': color_mapper
},
                           fill_alpha=0.7,
                           line_color="white",
                           line_width=2)
nonselected_patches = Patches(fill_color={
    'field': 'veges',
    'transform': color_mapper
},
                              fill_alpha=0.3,
                              line_color="white",
                              line_width=0.5)

renderer.selection_glyph = selected_patches
renderer.nonselection_glyph = nonselected_patches

hover = p.select_one(HoverTool)